FreeCalypso > hg > ice1-trau-tester
annotate abis/main.c @ 31:cd7448724d74
top Makefile: add abis program subdir
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 13 Aug 2024 21:44:30 +0000 |
parents | 5dd30224b70a |
children | 94f11dc0d474 |
rev | line source |
---|---|
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
2 * This C module is the main for itt-abis-16, a test program for collecting |
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
3 * TRAU-UL captures from an E1 BTS. This program operates on a single E1 |
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
4 * timeslot on Abis and treats it as consisting of four 16 kbit/s subslots. |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * This code is based on osmo-e1d-pipe, |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * (C) 2020-2022 by Harald Welte <laforge@osmocom.org>, |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * SPDX-License-Identifier: GPL-2.0+ |
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 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdint.h> |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdbool.h> |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdio.h> |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <stdlib.h> |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
15 #include <string.h> |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <unistd.h> |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include <osmocom/core/talloc.h> |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include <osmocom/core/select.h> |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include <osmocom/core/application.h> |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include <osmocom/e1d/proto_clnt.h> |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
22 #include <osmocom/isdn/i460_mux.h> |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 #include "../libutil/open_ts.h" |
5
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
25 #include "../libutil/stdin_handler.h" |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 #include "globals.h" |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
27 #include "submux.h" |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
28 #include "dl_frames.h" |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
30 void *g_ctx; |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 struct osmo_e1dp_client *g_client; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int ts_fd; |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
33 struct osmo_i460_timeslot i460_ts; |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
34 struct abis_subslot subslots[ABIS_SUBSLOTS]; |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 static const char *timeslot_spec; |
5
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
38 static struct osmo_fd ts_ofd, stdin_ofd; |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 static void process_cmdline(int argc, char **argv) |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 extern int optind; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 extern char *optarg; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 int c; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 while ((c = getopt(argc, argv, "p:")) != EOF) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 switch (c) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 case 'p': |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 e1d_socket_path = optarg; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 continue; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 default: |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 usage: |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n", |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 argv[0]); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 exit(1); |
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 if (argc != optind + 1) |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 goto usage; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 timeslot_spec = argv[optind]; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
63 static void register_subslots(void) |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
64 { |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
65 int nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
66 struct osmo_i460_schan_desc chd; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
67 |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
68 memset(&chd, 0, sizeof chd); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
69 chd.rate = OSMO_I460_RATE_16k; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
70 chd.demux.num_bits = 320; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
71 chd.demux.out_cb_bits = i460_rx_func; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
72 |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
73 for (nr = 0; nr < ABIS_SUBSLOTS; nr++) { |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
74 subslots[nr].nr = nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
75 chd.demux.user_data = subslots + nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
76 chd.mux.user_data = subslots + nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
77 subslots[nr].schan = |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
78 osmo_i460_subchan_add(g_ctx, &i460_ts, &chd); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
79 OSMO_ASSERT(subslots[nr].schan); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
80 chd.bit_offset += 2; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
81 } |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
82 } |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
83 |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 int main(int argc, char **argv) |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 process_cmdline(argc, argv); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 g_ctx = talloc_named_const(NULL, 0, "g_ctx"); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 OSMO_ASSERT(g_ctx); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 osmo_init_logging2(g_ctx, NULL); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 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
|
92 if (!g_client) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 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
|
94 e1d_socket_path); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 exit(1); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 ts_fd = open_e1d_ts(g_client, timeslot_spec); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
99 osmo_i460_ts_init(&i460_ts); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
100 register_subslots(); |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
101 init_canned_dl_frames(); |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
102 |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
5
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
106 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
|
107 handle_user_cmd, 0); |
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
108 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0); |
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
109 |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 while (1) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 osmo_select_main(0); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |