annotate pcm-br/main.c @ 38:f7a1a2765e21

README: update for current state
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 29 Aug 2024 19:42:22 +0000
parents 499d065ee591
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
2 * This C module is the main for itt-pcm-br, a program in the icE1 TRAU tester
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
3 * suite that bridges two different timeslots (two TRAU channels) on the A i/f.
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * This code is based on osmo-e1d-pipe,
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * (C) 2020-2022 by Harald Welte <laforge@osmocom.org>,
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * SPDX-License-Identifier: GPL-2.0+
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdbool.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdio.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <unistd.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <osmocom/core/talloc.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <osmocom/core/select.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include <osmocom/core/application.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include <osmocom/e1d/proto_clnt.h>
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "../libutil/open_ts.h"
5
7233c10af3ad pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
22 #include "../libutil/stdin_handler.h"
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include "globals.h"
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct osmo_e1dp_client *g_client;
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
26 int tsa_fd, tsb_fd;
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET;
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
29 static const char *timeslot_spec_a, *timeslot_spec_b;
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static void *g_ctx;
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
31 static struct osmo_fd tsa_ofd, tsb_ofd, stdin_ofd;
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static void process_cmdline(int argc, char **argv)
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 extern int optind;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 extern char *optarg;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 int c;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 while ((c = getopt(argc, argv, "p:")) != EOF) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 switch (c) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 case 'p':
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 e1d_socket_path = optarg;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 continue;
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 default:
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 usage:
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
46 fprintf(stderr,
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
47 "usage: %s [-p socket] intf:line:ts intf:line:ts\n",
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 argv[0]);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
52 if (argc != optind + 2)
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 goto usage;
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
54 timeslot_spec_a = argv[optind];
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
55 timeslot_spec_b = argv[optind+1];
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 int main(int argc, char **argv)
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 process_cmdline(argc, argv);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 g_ctx = talloc_named_const(NULL, 0, "g_ctx");
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 OSMO_ASSERT(g_ctx);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 osmo_init_logging2(g_ctx, NULL);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (!g_client) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n",
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 e1d_socket_path);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 exit(1);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
71 tsa_fd = open_e1d_ts(g_client, timeslot_spec_a);
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
72 tsb_fd = open_e1d_ts(g_client, timeslot_spec_b);
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
35
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
74 osmo_fd_setup(&tsa_ofd, tsa_fd, OSMO_FD_READ, tsa_fd_cb, NULL, 0);
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
75 OSMO_ASSERT(osmo_fd_register(&tsa_ofd) == 0);
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
76
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
77 osmo_fd_setup(&tsb_ofd, tsb_fd, OSMO_FD_READ, tsb_fd_cb, NULL, 0);
499d065ee591 new program itt-pcm-br (PCM bridge)
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
78 OSMO_ASSERT(osmo_fd_register(&tsb_ofd) == 0);
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
5
7233c10af3ad pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
80 osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb,
7233c10af3ad pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
81 handle_user_cmd, 0);
7233c10af3ad pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
82 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0);
7233c10af3ad pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
83
2
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 while (1) {
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 osmo_select_main(0);
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
c03ec046471f pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }