annotate ater/activate.c @ 52:626180a15857 default tip

ater play-d144: emit E-data frames manually, osmo_trau_frame_encode() is currently broken for this frame type
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 06:40:43 +0000
parents 40f781efdbe1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement the operation of activating a new TRAU channel
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * on a sub-timeslot.
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdint.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdbool.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <osmocom/core/select.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <osmocom/isdn/i460_mux.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <osmocom/trau/trau_frame.h>
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "globals.h"
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "submux.h"
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "read_file.h"
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "out_frame.h"
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 void cmd_activate(int argc, char **argv)
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int nr, rc;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 bool is_efr, dtxd;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct ater_subslot *at;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 uint8_t *init_frame;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned init_frame_count;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (argc < 4 || argc > 5) {
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 usage: fprintf(stderr,
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 "usage: %s 0|1|2|3 fr|efr initial-frame.tul [dtxd]\n",
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 argv[0]);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 goto usage;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 nr = argv[1][0] - '0';
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (!strcmp(argv[2], "fr"))
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 is_efr = false;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 else if (!strcmp(argv[2], "efr"))
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 is_efr = true;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 else
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 goto usage;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (argv[4]) {
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (strcmp(argv[4], "dtxd"))
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 goto usage;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 dtxd = true;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 } else
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 dtxd = false;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 at = &subslots[nr];
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (at->is_active) {
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr, "error: subslot %d is already active\n", nr);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 rc = read_binary_file(argv[3], is_efr, &init_frame, &init_frame_count);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (rc < 0)
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return; /* error msg already printed */
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (init_frame_count != 1) {
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 free(init_frame);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr, "error: %s contains more than one frame\n",
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 argv[3]);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 /* good to proceed now */
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 at->is_active = true;
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
68 at->is_data = false;
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
69 at->is_data_144 = false;
24
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 at->is_efr = is_efr;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 init_trau_ul_frame(nr);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 at->ul_frame.c_bits[16] = dtxd;
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 trau_frame_from_record(init_frame, is_efr, &at->ul_frame);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 free(init_frame);
f49e57b0d1a2 ater: implement activ command
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
76
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
77 void cmd_activate_csd(int argc, char **argv)
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
78 {
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
79 int nr;
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
80 bool ir_16k, is_144, is_hr;
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
81 struct ater_subslot *at;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
82
47
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
83 if (argc < 3 || argc > 4) {
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
84 usage: fprintf(stderr, "usage: %s 0|1|2|3 8|16|14.4 [hr]\n", argv[0]);
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
85 return;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
86 }
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
87 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
88 goto usage;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
89 nr = argv[1][0] - '0';
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
90 if (!strcmp(argv[2], "8")) {
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
91 is_144 = false;
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
92 ir_16k = false;
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
93 } else if (!strcmp(argv[2], "16")) {
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
94 is_144 = false;
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
95 ir_16k = true;
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
96 } else if (!strcmp(argv[2], "14.4")) {
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
97 is_144 = true;
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
98 ir_16k = true;
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
99 } else
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
100 goto usage;
47
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
101 if (argv[3]) {
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
102 if (strcmp(argv[3], "hr"))
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
103 goto usage;
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
104 is_hr = true;
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
105 } else
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
106 is_hr = false;
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
107 if (is_hr && (is_144 || ir_16k)) {
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
108 fprintf(stderr, "error: HR above 8 kbit/s is impossible\n");
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
109 return;
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
110 }
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
111
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
112 at = &subslots[nr];
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
113 if (at->is_active) {
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
114 fprintf(stderr, "error: subslot %d is already active\n", nr);
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
115 return;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
116 }
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
117
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
118 /* good to proceed now */
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
119 at->is_active = true;
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
120 at->is_data = true;
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
121 at->is_data_144 = is_144;
47
13fffc41f989 ater: add support for HR-data-16k TRAU-UL frame output
Mychaela Falconia <falcon@freecalypso.org>
parents: 44
diff changeset
122 at->is_hr_data = is_hr;
49
40f781efdbe1 ater: beginning of D144 mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
123 at->d144_edata = false;
44
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
124 init_trau_ul_frame_csd(nr, ir_16k);
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
125 }
16715bd149e0 ater: add support for data mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
126
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
127 void cmd_deact(int argc, char **argv)
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
128 {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
129 int nr;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
130 struct ater_subslot *at;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
131
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
132 if (argc != 2) {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
133 usage: fprintf(stderr, "usage: %s 0|1|2|3\n", argv[0]);
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
134 return;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
135 }
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
136 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
137 goto usage;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
138 nr = argv[1][0] - '0';
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
139 at = &subslots[nr];
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
140 if (!at->is_active) {
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
141 fprintf(stderr, "error: subslot %d is not active\n", nr);
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
142 return;
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
143 }
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
144 at->is_active = false;
26
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
145 if (at->play_buffer) {
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
146 free(at->play_buffer);
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
147 at->play_buffer = NULL;
237687e2be6c ater: implement play internals
Mychaela Falconia <falcon@freecalypso.org>
parents: 25
diff changeset
148 }
25
45411b72b6b3 ater: implement deact command
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
149 }