FreeCalypso > hg > ice1-trau-tester
annotate abis/main.c @ 36:e4a0b4a61649
top Makefile: add pcm-br
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Aug 2024 05:02:29 +0000 |
parents | 94f11dc0d474 |
children |
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> |
32
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
23 #include <osmocom/trau/trau_sync.h> |
2
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 #include "../libutil/open_ts.h" |
5
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
26 #include "../libutil/stdin_handler.h" |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #include "globals.h" |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
28 #include "submux.h" |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
29 #include "dl_frames.h" |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
19
1e375472d5a5
ater: implement TRAU frame output
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
31 void *g_ctx; |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 struct osmo_e1dp_client *g_client; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 int ts_fd; |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
34 struct osmo_i460_timeslot i460_ts; |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
35 struct abis_subslot subslots[ABIS_SUBSLOTS]; |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 static const char *timeslot_spec; |
5
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
39 static struct osmo_fd ts_ofd, stdin_ofd; |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 static void process_cmdline(int argc, char **argv) |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 extern int optind; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 extern char *optarg; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 int c; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 while ((c = getopt(argc, argv, "p:")) != EOF) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 switch (c) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 case 'p': |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 e1d_socket_path = optarg; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 continue; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 default: |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 usage: |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 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
|
55 argv[0]); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 exit(1); |
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 } |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (argc != optind + 1) |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 goto usage; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 timeslot_spec = argv[optind]; |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
64 static void register_subslots(void) |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
65 { |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
66 int nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
67 struct osmo_i460_schan_desc chd; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
68 |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
69 memset(&chd, 0, sizeof chd); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
70 chd.rate = OSMO_I460_RATE_16k; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
71 chd.demux.num_bits = 320; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
72 chd.demux.out_cb_bits = i460_rx_func; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
73 |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
74 for (nr = 0; nr < ABIS_SUBSLOTS; nr++) { |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
75 subslots[nr].nr = nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
76 chd.demux.user_data = subslots + nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
77 chd.mux.user_data = subslots + nr; |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
78 subslots[nr].schan = |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
79 osmo_i460_subchan_add(g_ctx, &i460_ts, &chd); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
80 OSMO_ASSERT(subslots[nr].schan); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
81 chd.bit_offset += 2; |
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 } |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
84 |
32
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
85 static void setup_rx_sync(void) |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
86 { |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
87 int nr; |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
88 |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
89 for (nr = 0; nr < ABIS_SUBSLOTS; nr++) { |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
90 subslots[nr].sync = osmo_trau_sync_alloc(g_ctx, "TRAU-UL-sync", |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
91 sync_rx_func, OSMO_TRAU_SYNCP_16_FR_EFR, |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
92 subslots + nr); |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
93 OSMO_ASSERT(subslots[nr].sync); |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
94 } |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
95 } |
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
96 |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 int main(int argc, char **argv) |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 process_cmdline(argc, argv); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 g_ctx = talloc_named_const(NULL, 0, "g_ctx"); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 OSMO_ASSERT(g_ctx); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 osmo_init_logging2(g_ctx, NULL); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 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
|
105 if (!g_client) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 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
|
107 e1d_socket_path); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 exit(1); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 ts_fd = open_e1d_ts(g_client, timeslot_spec); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
112 osmo_i460_ts_init(&i460_ts); |
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
113 register_subslots(); |
32
94f11dc0d474
abis: Rx osmo_trau_sync hooked in
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
114 setup_rx_sync(); |
30
5dd30224b70a
abis: starting new program
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
115 init_canned_dl_frames(); |
16
4ffe22f5b4b5
ater: initial osmo_i460 framework
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
116 |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 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
|
118 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
5
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
120 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
|
121 handle_user_cmd, 0); |
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
122 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0); |
7233c10af3ad
pcm: hook in stdin select mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
123 |
2
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 while (1) { |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 osmo_select_main(0); |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 } |
c03ec046471f
pcm: initial version compiles and links
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |