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