annotate libutil/open_ts.c @ 5:3604828b2f54

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