comparison ft16/main.c @ 2:5c18cd38c8ad

ft16: import from ice1-trau-tester/abis
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 29 Aug 2024 13:07:16 +0000
parents
children adcdbb2e30fe
comparison
equal deleted inserted replaced
1:e5527fc2050b 2:5c18cd38c8ad
1 /*
2 * This C module is the main for itt-abis-16, a test program for collecting
3 * TRAU-UL captures from an E1 BTS. This program operates on a single E1
4 * timeslot on Abis and treats it as consisting of four 16 kbit/s subslots.
5 *
6 * This code is based on osmo-e1d-pipe,
7 * (C) 2020-2022 by Harald Welte <laforge@osmocom.org>,
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <unistd.h>
17
18 #include <osmocom/core/talloc.h>
19 #include <osmocom/core/select.h>
20 #include <osmocom/core/application.h>
21 #include <osmocom/e1d/proto_clnt.h>
22 #include <osmocom/isdn/i460_mux.h>
23 #include <osmocom/trau/trau_sync.h>
24
25 #include "../libutil/open_ts.h"
26 #include "../libutil/stdin_handler.h"
27 #include "globals.h"
28 #include "submux.h"
29 #include "dl_frames.h"
30
31 void *g_ctx;
32 struct osmo_e1dp_client *g_client;
33 int ts_fd;
34 struct osmo_i460_timeslot i460_ts;
35 struct abis_subslot subslots[ABIS_SUBSLOTS];
36
37 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET;
38 static const char *timeslot_spec;
39 static struct osmo_fd ts_ofd, stdin_ofd;
40
41 static void process_cmdline(int argc, char **argv)
42 {
43 extern int optind;
44 extern char *optarg;
45 int c;
46
47 while ((c = getopt(argc, argv, "p:")) != EOF) {
48 switch (c) {
49 case 'p':
50 e1d_socket_path = optarg;
51 continue;
52 default:
53 usage:
54 fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n",
55 argv[0]);
56 exit(1);
57 }
58 }
59 if (argc != optind + 1)
60 goto usage;
61 timeslot_spec = argv[optind];
62 }
63
64 static void register_subslots(void)
65 {
66 int nr;
67 struct osmo_i460_schan_desc chd;
68
69 memset(&chd, 0, sizeof chd);
70 chd.rate = OSMO_I460_RATE_16k;
71 chd.demux.num_bits = 320;
72 chd.demux.out_cb_bits = i460_rx_func;
73
74 for (nr = 0; nr < ABIS_SUBSLOTS; nr++) {
75 subslots[nr].nr = nr;
76 chd.demux.user_data = subslots + nr;
77 chd.mux.user_data = subslots + nr;
78 subslots[nr].schan =
79 osmo_i460_subchan_add(g_ctx, &i460_ts, &chd);
80 OSMO_ASSERT(subslots[nr].schan);
81 chd.bit_offset += 2;
82 }
83 }
84
85 static void setup_rx_sync(void)
86 {
87 int nr;
88
89 for (nr = 0; nr < ABIS_SUBSLOTS; nr++) {
90 subslots[nr].sync = osmo_trau_sync_alloc(g_ctx, "TRAU-UL-sync",
91 sync_rx_func, OSMO_TRAU_SYNCP_16_FR_EFR,
92 subslots + nr);
93 OSMO_ASSERT(subslots[nr].sync);
94 }
95 }
96
97 int main(int argc, char **argv)
98 {
99 process_cmdline(argc, argv);
100 g_ctx = talloc_named_const(NULL, 0, "g_ctx");
101 OSMO_ASSERT(g_ctx);
102 osmo_init_logging2(g_ctx, NULL);
103
104 g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path);
105 if (!g_client) {
106 fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n",
107 e1d_socket_path);
108 exit(1);
109 }
110 ts_fd = open_e1d_ts(g_client, timeslot_spec);
111
112 osmo_i460_ts_init(&i460_ts);
113 register_subslots();
114 setup_rx_sync();
115 init_canned_dl_frames();
116
117 osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0);
118 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0);
119
120 osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb,
121 handle_user_cmd, 0);
122 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0);
123
124 while (1) {
125 osmo_select_main(0);
126 }
127 }