comparison ater/activate.c @ 24:f49e57b0d1a2

ater: implement activ command
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 24 Jun 2024 18:48:36 +0000
parents
children 45411b72b6b3
comparison
equal deleted inserted replaced
23:0d70444b5070 24:f49e57b0d1a2
1 /*
2 * Here we implement the operation of activating a new TRAU channel
3 * on a sub-timeslot.
4 */
5
6 #include <stdint.h>
7 #include <stdbool.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include <osmocom/core/select.h>
13 #include <osmocom/isdn/i460_mux.h>
14 #include <osmocom/trau/trau_frame.h>
15
16 #include "globals.h"
17 #include "submux.h"
18 #include "read_file.h"
19 #include "out_frame.h"
20
21 void cmd_activate(int argc, char **argv)
22 {
23 int nr, rc;
24 bool is_efr, dtxd;
25 struct ater_subslot *at;
26 uint8_t *init_frame;
27 unsigned init_frame_count;
28
29 if (argc < 4 || argc > 5) {
30 usage: fprintf(stderr,
31 "usage: %s 0|1|2|3 fr|efr initial-frame.tul [dtxd]\n",
32 argv[0]);
33 return;
34 }
35 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
36 goto usage;
37 nr = argv[1][0] - '0';
38 if (!strcmp(argv[2], "fr"))
39 is_efr = false;
40 else if (!strcmp(argv[2], "efr"))
41 is_efr = true;
42 else
43 goto usage;
44 if (argv[4]) {
45 if (strcmp(argv[4], "dtxd"))
46 goto usage;
47 dtxd = true;
48 } else
49 dtxd = false;
50
51 at = &subslots[nr];
52 if (at->is_active) {
53 fprintf(stderr, "error: subslot %d is already active\n", nr);
54 return;
55 }
56 rc = read_binary_file(argv[3], is_efr, &init_frame, &init_frame_count);
57 if (rc < 0)
58 return; /* error msg already printed */
59 if (init_frame_count != 1) {
60 free(init_frame);
61 fprintf(stderr, "error: %s contains more than one frame\n",
62 argv[3]);
63 return;
64 }
65
66 /* good to proceed now */
67 at->is_active = true;
68 at->is_efr = is_efr;
69 init_trau_ul_frame(nr);
70 at->ul_frame.c_bits[16] = dtxd;
71 trau_frame_from_record(init_frame, is_efr, &at->ul_frame);
72 free(init_frame);
73 }