FreeCalypso > hg > e1-fake-trau
comparison libutil/open_ts.c @ 1:e5527fc2050b
libutil: copy from ice1-trau-tester
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 29 Aug 2024 12:58:56 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:06c795d4781d | 1:e5527fc2050b |
|---|---|
| 1 /* | |
| 2 * The function in this common module is responsible for parsing the | |
| 3 * user-supplied E1 timeslot specification and then opening that ts | |
| 4 * in osmo-e1d. | |
| 5 * | |
| 6 * This code is based on osmo-e1d-pipe, | |
| 7 * (C) 2020-2022 by Harald Welte <laforge@osmocom.org>, | |
| 8 * SPDX-License-Identifier: GPL-2.0+ | |
| 9 */ | |
| 10 | |
| 11 #include <ctype.h> | |
| 12 #include <stdint.h> | |
| 13 #include <stdbool.h> | |
| 14 #include <stdio.h> | |
| 15 #include <stdlib.h> | |
| 16 | |
| 17 #include <osmocom/e1d/proto_clnt.h> | |
| 18 | |
| 19 #include "open_ts.h" | |
| 20 | |
| 21 static int parse_component(const char *str, const char **outp, uint8_t *var) | |
| 22 { | |
| 23 if (!isdigit(*str)) | |
| 24 return -1; | |
| 25 *var = atoi(str); | |
| 26 while (isdigit(*str)) | |
| 27 str++; | |
| 28 *outp = str; | |
| 29 return 0; | |
| 30 } | |
| 31 | |
| 32 int open_e1d_ts(struct osmo_e1dp_client *e1_client, const char *ts_spec) | |
| 33 { | |
| 34 uint8_t intf_nr, line_nr, ts_nr; | |
| 35 const char *cp; | |
| 36 int fd; | |
| 37 | |
| 38 if (parse_component(ts_spec, &cp, &intf_nr) < 0) { | |
| 39 inv_syntax: fprintf(stderr, "error: invalid timeslot spec \"%s\"\n", | |
| 40 ts_spec); | |
| 41 exit(1); | |
| 42 } | |
| 43 if (*cp++ != ':') | |
| 44 goto inv_syntax; | |
| 45 if (parse_component(cp, &cp, &line_nr) < 0) | |
| 46 goto inv_syntax; | |
| 47 if (*cp++ != ':') | |
| 48 goto inv_syntax; | |
| 49 if (parse_component(cp, &cp, &ts_nr) < 0) | |
| 50 goto inv_syntax; | |
| 51 if (*cp) | |
| 52 goto inv_syntax; | |
| 53 fd = osmo_e1dp_client_ts_open(e1_client, intf_nr, line_nr, ts_nr, | |
| 54 E1DP_TSMODE_RAW, 160); | |
| 55 if (fd < 0) { | |
| 56 fprintf(stderr, "error: failed to open E1 ts %s\n", ts_spec); | |
| 57 exit(1); | |
| 58 } | |
| 59 return fd; | |
| 60 } |
