# HG changeset patch # User Mychaela Falconia # Date 1719127731 0 # Node ID 570252e226301cec3bfb2082d82ac77adebe2ba8 # Parent 76b593a6265cb8b5ebc6f278ca10587b82a2ee48 libutil: timeslot opening function diff -r 76b593a6265c -r 570252e22630 libutil/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/Makefile Sun Jun 23 07:28:51 2024 +0000 @@ -0,0 +1,15 @@ +OBJS= open_ts.o +LIB= libutil.a + +include ../config.defs + +CPPFLAGS=${OSMO_INCLUDE} + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r 76b593a6265c -r 570252e22630 libutil/open_ts.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/open_ts.c Sun Jun 23 07:28:51 2024 +0000 @@ -0,0 +1,60 @@ +/* + * The function in this common module is responsible for parsing the + * user-supplied E1 timeslot specification and then opening that ts + * in osmo-e1d. + * + * This code is based on osmo-e1d-pipe, + * (C) 2020-2022 by Harald Welte , + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +#include + +#include "open_ts.h" + +static int parse_component(const char *str, const char **outp, uint8_t *var) +{ + if (!isdigit(*str)) + return -1; + *var = atoi(str); + while (isdigit(*str)) + str++; + *outp = str; + return 0; +} + +int open_e1d_ts(struct osmo_e1dp_client *e1_client, const char *ts_spec) +{ + uint8_t intf_nr, line_nr, ts_nr; + const char *cp; + int fd; + + if (parse_component(ts_spec, &cp, &intf_nr) < 0) { +inv_syntax: fprintf(stderr, "error: invalid timeslot spec \"%s\"\n", + ts_spec); + exit(1); + } + if (*cp++ != ':') + goto inv_syntax; + if (parse_component(cp, &cp, &line_nr) < 0) + goto inv_syntax; + if (*cp++ != ':') + goto inv_syntax; + if (parse_component(cp, &cp, &ts_nr) < 0) + goto inv_syntax; + if (*cp) + goto inv_syntax; + fd = osmo_e1dp_client_ts_open(e1_client, intf_nr, line_nr, ts_nr, + E1DP_TSMODE_RAW, 160); + if (fd < 0) { + fprintf(stderr, "error: failed to open E1 ts %s\n", ts_spec); + exit(1); + } + return fd; +} diff -r 76b593a6265c -r 570252e22630 libutil/open_ts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libutil/open_ts.h Sun Jun 23 07:28:51 2024 +0000 @@ -0,0 +1,3 @@ +#pragma once + +int open_e1d_ts(struct osmo_e1dp_client *e1_client, const char *ts_spec);