comparison d144/atrau-parse.c @ 57:fe3cdbbc96f9

d144: new program atrau-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 17:45:29 +0000
parents
children a7ede064f883
comparison
equal deleted inserted replaced
56:b32b644b7d96 57:fe3cdbbc96f9
1 /*
2 * This program reads a binary file containing a capture of 64 kbit/s output
3 * of a TRAU in 14.4 kbit/s data mode. Per GSM specs this output is supposed
4 * to contain A-TRAU frames of TS 48.020 chapter 11 (RAA' function);
5 * this program looks for such frames and parses them.
6 */
7
8 #include <sys/types.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12
13 static void
14 decode_ra2(ts_bytes, frame_bits)
15 uint8_t *ts_bytes, *frame_bits;
16 {
17 uint8_t *ip, *op;
18 unsigned n;
19
20 ip = ts_bytes;
21 op = frame_bits;
22 for (n = 0; n < 160; n++) {
23 *op++ = (*ip & 0x80) >> 7;
24 *op++ = (*ip & 0x40) >> 6;
25 ip++;
26 }
27 }
28
29 static int
30 check_sync_zeros(frame_bits)
31 uint8_t *frame_bits;
32 {
33 int i;
34
35 for (i = 0; i < 16; i++) {
36 if (frame_bits[i])
37 return 0;
38 }
39 return 1;
40 }
41
42 static unsigned
43 gather_nibble(bits)
44 uint8_t *bits;
45 {
46 unsigned n, acc;
47
48 acc = 0;
49 for (n = 0; n < 4; n++) {
50 acc <<= 1;
51 acc |= *bits++;
52 }
53 return acc;
54 }
55
56 static void
57 dump_subframe(bits)
58 uint8_t *bits;
59 {
60 unsigned n, d;
61
62 printf(" %u ", *bits++);
63 for (n = 0; n < 9; n++) {
64 d = gather_nibble(bits);
65 printf("%x", d);
66 bits += 4;
67 }
68 putchar('\n');
69 }
70
71 static void
72 dump_frame(frame_bits)
73 uint8_t *frame_bits;
74 {
75 unsigned n;
76
77 if (!check_sync_zeros(frame_bits))
78 printf(" Bad sync bits!\n");
79 printf(" C1-C5: %u%u%u%u%u\n", frame_bits[17], frame_bits[18],
80 frame_bits[19], frame_bits[20], frame_bits[21]);
81 printf(" M1=%u M2=%u\n", frame_bits[22], frame_bits[23]);
82 for (n = 0; n < 8; n++)
83 dump_subframe(frame_bits + 24 + n * 37);
84 }
85
86 main(argc, argv)
87 char **argv;
88 {
89 FILE *binf;
90 uint8_t frame_in[160], frame_bits[320];
91 u_long file_offset;
92 int cc;
93
94 if (argc != 2) {
95 fprintf(stderr, "usage: %s capture.bin\n", argv[0]);
96 exit(1);
97 }
98 binf = fopen(argv[1], "r");
99 if (!binf) {
100 perror(argv[1]);
101 exit(1);
102 }
103 for (file_offset = 0; ; file_offset += 160) {
104 cc = fread(frame_in, 1, 160, binf);
105 if (cc <= 0)
106 break;
107 if (cc != 160) {
108 fprintf(stderr,
109 "error: %s is not a multiple of 160 bytes\n",
110 argv[1]);
111 exit(1);
112 }
113 printf("Frame at 0x%lx:\n", file_offset);
114 decode_ra2(frame_in, frame_bits);
115 dump_frame(frame_bits);
116 }
117 exit(0);
118 }