FreeCalypso > hg > ice1-trau-tester
comparison abis/main.c @ 30:5dd30224b70a
abis: starting new program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 13 Aug 2024 21:38:55 +0000 |
parents | ater/main.c@1e375472d5a5 |
children | 94f11dc0d474 |
comparison
equal
deleted
inserted
replaced
29:1dda11905e85 | 30:5dd30224b70a |
---|---|
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 | |
24 #include "../libutil/open_ts.h" | |
25 #include "../libutil/stdin_handler.h" | |
26 #include "globals.h" | |
27 #include "submux.h" | |
28 #include "dl_frames.h" | |
29 | |
30 void *g_ctx; | |
31 struct osmo_e1dp_client *g_client; | |
32 int ts_fd; | |
33 struct osmo_i460_timeslot i460_ts; | |
34 struct abis_subslot subslots[ABIS_SUBSLOTS]; | |
35 | |
36 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET; | |
37 static const char *timeslot_spec; | |
38 static struct osmo_fd ts_ofd, stdin_ofd; | |
39 | |
40 static void process_cmdline(int argc, char **argv) | |
41 { | |
42 extern int optind; | |
43 extern char *optarg; | |
44 int c; | |
45 | |
46 while ((c = getopt(argc, argv, "p:")) != EOF) { | |
47 switch (c) { | |
48 case 'p': | |
49 e1d_socket_path = optarg; | |
50 continue; | |
51 default: | |
52 usage: | |
53 fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n", | |
54 argv[0]); | |
55 exit(1); | |
56 } | |
57 } | |
58 if (argc != optind + 1) | |
59 goto usage; | |
60 timeslot_spec = argv[optind]; | |
61 } | |
62 | |
63 static void register_subslots(void) | |
64 { | |
65 int nr; | |
66 struct osmo_i460_schan_desc chd; | |
67 | |
68 memset(&chd, 0, sizeof chd); | |
69 chd.rate = OSMO_I460_RATE_16k; | |
70 chd.demux.num_bits = 320; | |
71 chd.demux.out_cb_bits = i460_rx_func; | |
72 | |
73 for (nr = 0; nr < ABIS_SUBSLOTS; nr++) { | |
74 subslots[nr].nr = nr; | |
75 chd.demux.user_data = subslots + nr; | |
76 chd.mux.user_data = subslots + nr; | |
77 subslots[nr].schan = | |
78 osmo_i460_subchan_add(g_ctx, &i460_ts, &chd); | |
79 OSMO_ASSERT(subslots[nr].schan); | |
80 chd.bit_offset += 2; | |
81 } | |
82 } | |
83 | |
84 int main(int argc, char **argv) | |
85 { | |
86 process_cmdline(argc, argv); | |
87 g_ctx = talloc_named_const(NULL, 0, "g_ctx"); | |
88 OSMO_ASSERT(g_ctx); | |
89 osmo_init_logging2(g_ctx, NULL); | |
90 | |
91 g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path); | |
92 if (!g_client) { | |
93 fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n", | |
94 e1d_socket_path); | |
95 exit(1); | |
96 } | |
97 ts_fd = open_e1d_ts(g_client, timeslot_spec); | |
98 | |
99 osmo_i460_ts_init(&i460_ts); | |
100 register_subslots(); | |
101 init_canned_dl_frames(); | |
102 | |
103 osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0); | |
104 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0); | |
105 | |
106 osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb, | |
107 handle_user_cmd, 0); | |
108 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0); | |
109 | |
110 while (1) { | |
111 osmo_select_main(0); | |
112 } | |
113 } |