FreeCalypso > hg > ice1-trau-tester
comparison ater8/main.c @ 42:ff94d7fc5891
new program itt-ater-8
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 19:02:42 +0000 |
parents | ater/main.c@1e375472d5a5 |
children |
comparison
equal
deleted
inserted
replaced
41:50a72d4ff498 | 42:ff94d7fc5891 |
---|---|
1 /* | |
2 * This C module is the main for itt-ater-8, a program in the icE1 TRAU tester | |
3 * suite that operates on a single E1 timeslot on the Ater interface. | |
4 * | |
5 * This code is based on osmo-e1d-pipe, | |
6 * (C) 2020-2022 by Harald Welte <laforge@osmocom.org>, | |
7 * SPDX-License-Identifier: GPL-2.0+ | |
8 */ | |
9 | |
10 #include <stdint.h> | |
11 #include <stdbool.h> | |
12 #include <stdio.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <unistd.h> | |
16 | |
17 #include <osmocom/core/talloc.h> | |
18 #include <osmocom/core/select.h> | |
19 #include <osmocom/core/application.h> | |
20 #include <osmocom/e1d/proto_clnt.h> | |
21 #include <osmocom/isdn/i460_mux.h> | |
22 | |
23 #include "../libutil/open_ts.h" | |
24 #include "../libutil/stdin_handler.h" | |
25 #include "globals.h" | |
26 #include "submux.h" | |
27 | |
28 void *g_ctx; | |
29 struct osmo_e1dp_client *g_client; | |
30 int ts_fd; | |
31 struct osmo_i460_timeslot i460_ts; | |
32 struct ater_subslot subslots[ATER_SUBSLOTS]; | |
33 | |
34 static const char *e1d_socket_path = E1DP_DEFAULT_SOCKET; | |
35 static const char *timeslot_spec; | |
36 static struct osmo_fd ts_ofd, stdin_ofd; | |
37 | |
38 static void process_cmdline(int argc, char **argv) | |
39 { | |
40 extern int optind; | |
41 extern char *optarg; | |
42 int c; | |
43 | |
44 while ((c = getopt(argc, argv, "p:")) != EOF) { | |
45 switch (c) { | |
46 case 'p': | |
47 e1d_socket_path = optarg; | |
48 continue; | |
49 default: | |
50 usage: | |
51 fprintf(stderr, "usage: %s [-p socket] intf:line:ts\n", | |
52 argv[0]); | |
53 exit(1); | |
54 } | |
55 } | |
56 if (argc != optind + 1) | |
57 goto usage; | |
58 timeslot_spec = argv[optind]; | |
59 } | |
60 | |
61 static void register_subslots(void) | |
62 { | |
63 int nr; | |
64 struct osmo_i460_schan_desc chd; | |
65 | |
66 memset(&chd, 0, sizeof chd); | |
67 chd.rate = OSMO_I460_RATE_8k; | |
68 chd.demux.num_bits = 160; | |
69 chd.demux.out_cb_bits = i460_rx_func; | |
70 | |
71 for (nr = 0; nr < ATER_SUBSLOTS; nr++) { | |
72 subslots[nr].nr = nr; | |
73 chd.demux.user_data = subslots + nr; | |
74 chd.mux.user_data = subslots + nr; | |
75 subslots[nr].schan = | |
76 osmo_i460_subchan_add(g_ctx, &i460_ts, &chd); | |
77 OSMO_ASSERT(subslots[nr].schan); | |
78 chd.bit_offset += 1; | |
79 } | |
80 } | |
81 | |
82 int main(int argc, char **argv) | |
83 { | |
84 process_cmdline(argc, argv); | |
85 g_ctx = talloc_named_const(NULL, 0, "g_ctx"); | |
86 OSMO_ASSERT(g_ctx); | |
87 osmo_init_logging2(g_ctx, NULL); | |
88 | |
89 g_client = osmo_e1dp_client_create(g_ctx, e1d_socket_path); | |
90 if (!g_client) { | |
91 fprintf(stderr, "error: cannot connect to osmo-e1d at %s\n", | |
92 e1d_socket_path); | |
93 exit(1); | |
94 } | |
95 ts_fd = open_e1d_ts(g_client, timeslot_spec); | |
96 | |
97 osmo_i460_ts_init(&i460_ts); | |
98 register_subslots(); | |
99 | |
100 osmo_fd_setup(&ts_ofd, ts_fd, OSMO_FD_READ, ts_fd_cb, NULL, 0); | |
101 OSMO_ASSERT(osmo_fd_register(&ts_ofd) == 0); | |
102 | |
103 osmo_fd_setup(&stdin_ofd, 0, OSMO_FD_READ, stdin_select_cb, | |
104 handle_user_cmd, 0); | |
105 OSMO_ASSERT(osmo_fd_register(&stdin_ofd) == 0); | |
106 | |
107 while (1) { | |
108 osmo_select_main(0); | |
109 } | |
110 } |