# HG changeset patch # User Mychaela Falconia # Date 1724821238 0 # Node ID 499d065ee591027e5b902c69cd225611e22e4143 # Parent f0b026615f3b2929366f7232fdff353990ad2550 new program itt-pcm-br (PCM bridge) diff -r f0b026615f3b -r 499d065ee591 .hgignore --- a/.hgignore Tue Aug 13 23:07:24 2024 +0000 +++ b/.hgignore Wed Aug 28 05:00:38 2024 +0000 @@ -6,3 +6,4 @@ ^abis/itt-abis-16$ ^ater/itt-ater-16$ ^pcm/itt-pcm-one$ +^pcm-br/itt-pcm-br$ diff -r f0b026615f3b -r 499d065ee591 pcm-br/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-br/Makefile Wed Aug 28 05:00:38 2024 +0000 @@ -0,0 +1,22 @@ +PROG= itt-pcm-br +OBJS= main.o record_ctrl.o showbuf.o user_cmd.o xconn.o +LIBUTIL=../libutil/libutil.a + +include ../config.defs + +CPPFLAGS=${OSMO_INCLUDE} +OSMO_LINK=${OSMO_LPATH} ${OSMO_RPATH} ${OSMO_LIBS} + +all: ${PROG} + +${OBJS}: globals.h + +${PROG}: ${OBJS} ${LIBUTIL} + ${CC} -o $@ ${OBJS} ${LIBUTIL} ${OSMO_LINK} + +install: + mkdir -p ${DESTDIR}${bindir} + install -c -m 755 ${PROG} ${DESTDIR}${bindir} + +clean: + rm -f *.o ${PROG} errs diff -r f0b026615f3b -r 499d065ee591 pcm-br/globals.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-br/globals.h Wed Aug 28 05:00:38 2024 +0000 @@ -0,0 +1,19 @@ +/* global vars and intermodule-linkage functions in itt-pcm-br */ + +#pragma once + +extern struct osmo_e1dp_client *g_client; +extern int tsa_fd, tsb_fd; +extern uint8_t readbuf_a[160], readbuf_b[160]; +extern FILE *rec_file_a, *rec_file_b; + +int tsa_fd_cb(struct osmo_fd *ofd, unsigned int what); +int tsb_fd_cb(struct osmo_fd *ofd, unsigned int what); + +void handle_user_cmd(int argc, char **argv); +void cmd_record_a_start(int argc, char **argv); +void cmd_record_a_stop(int argc, char **argv); +void cmd_record_b_start(int argc, char **argv); +void cmd_record_b_stop(int argc, char **argv); +void cmd_show_a(int argc, char **argv); +void cmd_show_b(int argc, char **argv); diff -r f0b026615f3b -r 499d065ee591 pcm-br/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-br/main.c Wed Aug 28 05:00:38 2024 +0000 @@ -0,0 +1,87 @@ +/* + * This C module is the main for itt-pcm-br, a program in the icE1 TRAU tester + * suite that bridges two different timeslots (two TRAU channels) on the A i/f. + * + * 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 +#include +#include + +#include "../libutil/open_ts.h" +#include "../libutil/stdin_handler.h" +#include "globals.h" + +struct osmo_e1dp_client *g_client; +int tsa_fd, tsb_fd; + +static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET; +static const char *timeslot_spec_a, *timeslot_spec_b; +static void *g_ctx; +static struct osmo_fd tsa_ofd, tsb_ofd, stdin_ofd; + +static void process_cmdline(int argc, char **argv) +{ + extern int optind; + extern char *optarg; + int c; + + while ((c = getopt(argc, argv, "p:")) != EOF) { + switch (c) { + case 'p': + e1d_socket_path = optarg; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [-p socket] intf:line:ts intf:line:ts\n", + argv[0]); + exit(1); + } + } + if (argc != optind + 2) + goto usage; + timeslot_spec_a = argv[optind]; + timeslot_spec_b = argv[optind+1]; +} + +int main(int argc, char **argv) +{ + process_cmdline(argc, argv); + g_ctx = talloc_named_const(NULL, 0, "g_ctx"); + OSMO_ASSERT(g_ctx); + osmo_init_logging2(g_ctx, NULL); + + g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path); + if (!g_client) { + fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n", + e1d_socket_path); + exit(1); + } + tsa_fd = open_e1d_ts(g_client, timeslot_spec_a); + tsb_fd = open_e1d_ts(g_client, timeslot_spec_b); + + osmo_fd_setup(&tsa_ofd, tsa_fd, OSMO_FD_READ, tsa_fd_cb, NULL, 0); + OSMO_ASSERT(osmo_fd_register(&tsa_ofd) == 0); + + osmo_fd_setup(&tsb_ofd, tsb_fd, OSMO_FD_READ, tsb_fd_cb, NULL, 0); + OSMO_ASSERT(osmo_fd_register(&tsb_ofd) == 0); + + osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb, + handle_user_cmd, 0); + OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0); + + while (1) { + osmo_select_main(0); + } +} diff -r f0b026615f3b -r 499d065ee591 pcm-br/record_ctrl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-br/record_ctrl.c Wed Aug 28 05:00:38 2024 +0000 @@ -0,0 +1,63 @@ +/* + * Here we implement stdin commands that control recording of E1 timeslot + * read stream. + */ + +#include +#include +#include +#include + +#include + +#include "globals.h" + +void cmd_record_a_start(int argc, char **argv) +{ + if (argc != 2) { + printf("error: record-a command needs 1 argument\n"); + return; + } + if (rec_file_a) { + printf("error: recording of ts A already in progress\n"); + return; + } + rec_file_a = fopen(argv[1], "w"); + if (!rec_file_a) + perror(argv[1]); +} + +void cmd_record_a_stop(int argc, char **argv) +{ + if (!rec_file_a) { + printf("error: no recording of ts A in progress\n"); + return; + } + fclose(rec_file_a); + rec_file_a = NULL; +} + +void cmd_record_b_start(int argc, char **argv) +{ + if (argc != 2) { + printf("error: record-b command needs 1 argument\n"); + return; + } + if (rec_file_b) { + printf("error: recording of ts B already in progress\n"); + return; + } + rec_file_b = fopen(argv[1], "w"); + if (!rec_file_b) + perror(argv[1]); +} + +void cmd_record_b_stop(int argc, char **argv) +{ + if (!rec_file_b) { + printf("error: no recording of ts B in progress\n"); + return; + } + fclose(rec_file_b); + rec_file_b = NULL; +} diff -r f0b026615f3b -r 499d065ee591 pcm-br/showbuf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-br/showbuf.c Wed Aug 28 05:00:38 2024 +0000 @@ -0,0 +1,37 @@ +/* + * Here we implement stdin commands that display current instantaneous + * state of each read channel. + */ + +#include +#include +#include +#include + +#include + +#include "globals.h" + +void cmd_show_a(int argc, char **argv) +{ + int i, j, off; + + off = 0; + for (i = 0; i < 10; i++) { + for (j = 0; j < 16; j++) + printf(" %02X", readbuf_a[off++]); + putchar('\n'); + } +} + +void cmd_show_b(int argc, char **argv) +{ + int i, j, off; + + off = 0; + for (i = 0; i < 10; i++) { + for (j = 0; j < 16; j++) + printf(" %02X", readbuf_b[off++]); + putchar('\n'); + } +} diff -r f0b026615f3b -r 499d065ee591 pcm-br/user_cmd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-br/user_cmd.c Wed Aug 28 05:00:38 2024 +0000 @@ -0,0 +1,42 @@ +/* + * In this module we handle user-issued stdin commands during + * itt-pcm-br running session. + */ + +#include +#include +#include +#include +#include + +#include + +#include "globals.h" + +static struct cmdtab { + char *cmd; + void (*func)(int argc, char **argv); +} cmdtab[] = { + {"record-a", cmd_record_a_start}, + {"record-a-stop", cmd_record_a_stop}, + {"record-b", cmd_record_b_start}, + {"record-b-stop", cmd_record_b_stop}, + {"show-a", cmd_show_a}, + {"show-b", cmd_show_b}, + /* table search terminator */ + {NULL, NULL} +}; + +void handle_user_cmd(int argc, char **argv) +{ + struct cmdtab *tp; + + for (tp = cmdtab; tp->cmd; tp++) + if (!strcmp(tp->cmd, argv[0])) + break; + if (!tp->func) { + printf("error: unknown or unimplemented command\n"); + return; + } + tp->func(argc, argv); +} diff -r f0b026615f3b -r 499d065ee591 pcm-br/xconn.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcm-br/xconn.c Wed Aug 28 05:00:38 2024 +0000 @@ -0,0 +1,52 @@ +/* + * The two functions in this module get called from Osmocom select loop + * whenever each timeslot data socket to osmo-e1d is ready for reading; + * the cross-connect of the two timeslots is implemented here. + */ + +#include +#include +#include +#include +#include + +#include + +#include "globals.h" + +uint8_t readbuf_a[160], readbuf_b[160]; +FILE *rec_file_a, *rec_file_b; + +int tsa_fd_cb(struct osmo_fd *ofd, unsigned int what) +{ + int rc; + + rc = read(tsa_fd, readbuf_a, 160); + if (rc != 160) { + fprintf(stderr, + "error: read from ts A returned %d instead of 160\n", + rc); + exit(1); + } + if (rec_file_a) + fwrite(readbuf_a, 1, 160, rec_file_a); + write(tsb_fd, readbuf_a, 160); + return 0; +} + +int tsb_fd_cb(struct osmo_fd *ofd, unsigned int what) +{ + int rc; + + rc = read(tsb_fd, readbuf_b, 160); + if (rc != 160) { + fprintf(stderr, + "error: read from ts B returned %d instead of 160\n", + rc); + exit(1); + } + if (rec_file_b) + fwrite(readbuf_b, 1, 160, rec_file_b); + write(tsa_fd, readbuf_b, 160); + return 0; +}