annotate trau-decode/parse-main.c @ 38:d7674c80426c

trau-parse: add decoding of data frames
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Sep 2024 19:50:29 +0000
parents 4d1732e4a143
children 95acde708ce2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a 64 kbit/s timeslot recording file, examines one
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * of the four 16 kbit/s subslots (selected), looks for GSM 08.60 TRAU
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * frames, and dumps whatever it finds.
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static unsigned file_offset;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static enum {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 HUNT_FOR_0,
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 HUNT_FOUND_0,
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 GOT_8_ZEROS,
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 SYNCED
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 } state;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static unsigned hunt_for_0_count, frame_pos_count;
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
22 static uint8_t in_frame_2bit[160], frame_bits[320], d_bits[260];
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static void
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unpack_dibits()
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int i, inb;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 uint8_t *op;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 op = frame_bits;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 for (i = 0; i < 160; i++) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 inb = in_frame_2bit[i];
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (inb & 2)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *op++ = 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 else
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 *op++ = 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (inb & 1)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 *op++ = 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 else
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 *op++ = 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 static unsigned
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 bits_to_num(bits, nbits)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 uint8_t *bits;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 unsigned nbits;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 unsigned accum;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 unsigned n;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 accum = 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 for (n = 0; n < nbits; n++) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 accum <<= 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (*bits)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 accum |= 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 bits++;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return accum;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 static void
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
63 collect_d_bits()
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
64 {
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
65 bcopy(frame_bits + 33, d_bits, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
66 bcopy(frame_bits + 49, d_bits + 15, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
67 bcopy(frame_bits + 65, d_bits + 30, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
68 bcopy(frame_bits + 81, d_bits + 45, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
69 bcopy(frame_bits + 97, d_bits + 60, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
70 bcopy(frame_bits + 113, d_bits + 75, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
71 bcopy(frame_bits + 129, d_bits + 90, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
72 bcopy(frame_bits + 145, d_bits + 105, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
73 bcopy(frame_bits + 161, d_bits + 120, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
74 bcopy(frame_bits + 177, d_bits + 135, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
75 bcopy(frame_bits + 193, d_bits + 150, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
76 bcopy(frame_bits + 209, d_bits + 165, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
77 bcopy(frame_bits + 225, d_bits + 180, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
78 bcopy(frame_bits + 241, d_bits + 195, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
79 bcopy(frame_bits + 257, d_bits + 210, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
80 bcopy(frame_bits + 273, d_bits + 225, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
81 bcopy(frame_bits + 289, d_bits + 240, 15);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
82 bcopy(frame_bits + 305, d_bits + 255, 5);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
83 }
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
84
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
85 static void
38
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
86 print_data_subframe(nf, bits)
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
87 uint8_t *bits;
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
88 {
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
89 unsigned nb;
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
90
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
91 printf(" Data frame %d:", nf);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
92 for (nb = 0; nb < 9; nb++) {
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
93 printf(" %02X", bits_to_num(bits, 8));
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
94 bits += 8;
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
95 }
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
96 putchar('\n');
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
97 }
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
98
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
99 static void
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
100 print_data_frame()
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
101 {
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
102 print_data_subframe(0, frame_bits + 4 * 8);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
103 print_data_subframe(1, frame_bits + 13 * 8);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
104 print_data_subframe(2, frame_bits + 22 * 8);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
105 print_data_subframe(3, frame_bits + 31 * 8);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
106 }
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
107
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
108 static void
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 process_frame()
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 unsigned c1_5, c6_11;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
10
4d1732e4a143 trau-parse: frame offsets were reported off by one byte
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
113 printf("Frame at 0x%x:\n", file_offset - 159);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 printf(" C1-C5: %u%u%u%u%u", frame_bits[17], frame_bits[18],
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 frame_bits[19], frame_bits[20], frame_bits[21]);
1
b0dcd48a1c8a trau-parse: initial bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
116 c1_5 = bits_to_num(frame_bits + 17, 5);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 switch (c1_5) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 case 0x02:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 fputs(" (FR UL)", stdout);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 break;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 case 0x1C:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 fputs(" (FR DL)", stdout);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 break;
1
b0dcd48a1c8a trau-parse: initial bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
124 case 0x1A:
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 fputs(" (EFR)", stdout);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 break;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 case 0x10:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 fputs(" (idle UL)", stdout);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 break;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 case 0x0E:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 fputs(" (idle DL)", stdout);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 break;
38
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
133 case 0x08:
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
134 fputs(" (data UL)", stdout);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
135 break;
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
136 case 0x16:
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
137 fputs(" (data DL)", stdout);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
138 break;
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
139 case 0x14:
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
140 fputs(" (D144 sync)", stdout);
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
141 break;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 putchar('\n');
1
b0dcd48a1c8a trau-parse: initial bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
144 c6_11 = bits_to_num(frame_bits + 22, 6);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 printf(" C6-C11: %u\n", c6_11);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 printf(" C12=%u C13=%u C14=%u C15=%u\n", frame_bits[28],
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 frame_bits[29], frame_bits[30], frame_bits[31]);
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
148 switch (c1_5) {
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
149 case 0x02:
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
150 case 0x1C:
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
151 collect_d_bits();
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
152 print_fr_frame(d_bits);
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
153 break;
4
d9c095357c32 trau-parse: check and report EFR CRC
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
154 case 0x1A:
d9c095357c32 trau-parse: check and report EFR CRC
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
155 collect_d_bits();
d9c095357c32 trau-parse: check and report EFR CRC
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
156 check_efr_crc(d_bits);
5
bf5c9fb431b8 trau-parse: implement EFR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
157 print_efr_frame(d_bits);
4
d9c095357c32 trau-parse: check and report EFR CRC
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
158 break;
38
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
159 case 0x08:
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
160 case 0x16:
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
161 case 0x14:
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
162 print_data_frame();
d7674c80426c trau-parse: add decoding of data frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
163 return;
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
164 }
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 printf(" C16=%u C17=%u C18=%u C19=%u C20=%u C21=%u\n",
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 frame_bits[310], frame_bits[311], frame_bits[312],
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 frame_bits[313], frame_bits[314], frame_bits[315]);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 printf(" T1=%u T2=%u T3=%u T4=%u\n", frame_bits[316], frame_bits[317],
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 frame_bits[318], frame_bits[319]);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 static int
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 check_sync_zeros()
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 int i;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 for (i = 0; i < 16; i++) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 if (frame_bits[i])
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 return 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 return 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 static int
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 check_sync_ones()
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 int i;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 for (i = 1; i < 20; i++) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 if (!frame_bits[i*16])
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 return 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 return 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 static void
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 check_sync()
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 if (check_sync_zeros() && check_sync_ones())
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 printf("Bad frame sync, returning to hunt state\n");
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 state = HUNT_FOR_0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 static void
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 byte_input(inb)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 switch (state) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 case HUNT_FOR_0:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 if (inb != 0)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 state = HUNT_FOUND_0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 hunt_for_0_count = 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 case HUNT_FOUND_0:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 if (inb != 0) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 state = HUNT_FOR_0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 hunt_for_0_count++;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 if (hunt_for_0_count >= 8)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 state = GOT_8_ZEROS;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 case GOT_8_ZEROS:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 if (inb & 2) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 printf("Found frame sync at file offset 0x%x\n",
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 file_offset - 8);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 bzero(in_frame_2bit, 8);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 in_frame_2bit[8] = inb;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 frame_pos_count = 9;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 state = SYNCED;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 if (inb != 0)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 state = HUNT_FOR_0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 case SYNCED:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 in_frame_2bit[frame_pos_count++] = inb;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 if (frame_pos_count < 160)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 frame_pos_count = 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 unpack_dibits();
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 process_frame();
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 check_sync();
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 return;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 default:
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 fprintf(stderr, "BUG: bad sync state\n");
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 abort();
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 main(argc, argv)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 char **argv;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 FILE *inf;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 int subslot, right_shift;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 int inb;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 if (argc != 3) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 fprintf(stderr, "usage: %s binfile subslot\n", argv[0]);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 exit(1);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 inf = fopen(argv[1], "r");
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 if (!inf) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 perror(argv[1]);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 exit(1);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 subslot = atoi(argv[2]);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 if (subslot < 0 || subslot > 3) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 fprintf(stderr, "error: invalid subslot argument\n");
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 exit(1);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 right_shift = (3 - subslot) * 2;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 state = HUNT_FOR_0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 for (file_offset = 0; ; file_offset++) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 inb = getc(inf);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 if (inb < 0)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 break;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 inb >>= right_shift;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 inb &= 3;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 byte_input(inb);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 exit(0);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 }