annotate ater/dbits.c @ 45:349fb785a414

ater: add dset command for setting Dn bits
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Sep 2024 09:33:55 +0000
parents
children 40f781efdbe1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement the command for setting Dn bit patterns
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in data-mode TRAU-UL frames.
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdint.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdbool.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <osmocom/core/bits.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <osmocom/core/select.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <osmocom/isdn/i460_mux.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <osmocom/trau/trau_frame.h>
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "globals.h"
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "submux.h"
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 void cmd_set_dbits(int argc, char **argv)
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int nr;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct ater_subslot *at;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct osmo_trau_frame *fr;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unsigned d_offset;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char *bits;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (argc != 4) {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 usage: fprintf(stderr, "usage: %s 0|1|2|3 D-offset bits\n", argv[0]);
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (argv[1][0] < '0' || argv[1][0] > '3' || argv[1][1])
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 goto usage;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 nr = argv[1][0] - '0';
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 at = &subslots[nr];
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (!at->is_active) {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 fprintf(stderr, "error: subslot %d is not active\n", nr);
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (!at->is_data) {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fprintf(stderr, "error: subslot %d is not in data mode\n", nr);
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fr = &at->ul_frame;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 d_offset = atoi(argv[2]);
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (d_offset >= 252) {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 fprintf(stderr, "error: specified offset is out of range\n");
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 for (bits = argv[3]; *bits; bits++) {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (*bits < '0' || *bits > '1') {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fprintf(stderr, "error: invalid bit string argument\n");
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (d_offset >= 252) {
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 fprintf(stderr,
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 "error: given bit string extends past the end of Dn bits\n");
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return;
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 fr->d_bits[d_offset++] = *bits - '0';
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
349fb785a414 ater: add dset command for setting Dn bits
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }