annotate trau-decode/trau-hr-dump.c @ 57:fe3cdbbc96f9

d144: new program atrau-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 17:45:29 +0000
parents 61181373875d
children
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
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
3 * of the eight 8 kbit/s subslots (selected), looks for the sync pattern of
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
4 * GSM 08.61, decodes each frame as HRv1 speech and dumps everything it
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
5 * decodes.
0
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
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
8 #include <sys/types.h>
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
9 #include <sys/file.h>
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
10 #include <sys/stat.h>
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdint.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <string.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <strings.h>
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
16 #include <unistd.h>
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
17 #include "gsmhr_unpack.h"
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
18 #include "osmo_bits.h"
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
19
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
20 /*
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
21 * EFR TRAU parity (also used for HR)
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
22 *
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
23 * g(x) = x^3 + x^1 + 1
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
24 */
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
25 static const struct osmo_crc8gen_code gsm0860_efr_crc3 = {
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
26 .bits = 3,
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
27 .poly = 0x3,
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
28 .init = 0x0,
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
29 .remainder = 0x7,
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
30 };
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
32 static uint8_t *filebuf;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
33 static unsigned total_size;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 static void
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
36 read_ts_file(filename, subslot_arg)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
37 char *filename, *subslot_arg;
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
38 {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
39 FILE *inf;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
40 struct stat st;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
41 int subslot, right_shift;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
42 unsigned n;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
43 uint8_t *dp;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
44 int b;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
46 inf = fopen(filename, "r");
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
47 if (!inf) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
48 perror(filename);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
49 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
50 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
51 fstat(fileno(inf), &st);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
52 if (!S_ISREG(st.st_mode)) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
53 fprintf(stderr, "error: %s is not a regular file\n", filename);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
54 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
55 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
56 total_size = st.st_size;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
57 if (total_size < 160) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
58 fprintf(stderr, "error: %s is too short\n", filename);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
59 exit(1);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
61 filebuf = malloc(total_size);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
62 if (!filebuf) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
63 perror("malloc of file size");
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
64 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
65 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
66 subslot = atoi(subslot_arg);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
67 if (subslot < 0 || subslot > 7) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
68 fprintf(stderr, "error: invalid subslot argument\n");
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
69 exit(1);
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
70 }
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
71 right_shift = 7 - subslot;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
72 dp = filebuf;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
73 for (n = 0; n < total_size; n++) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
74 b = getc(inf);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
75 if (b < 0) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
76 fprintf(stderr,
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
77 "error: getc() returned EOF contrary to st_size\n");
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
78 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
79 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
80 *dp++ = (b >> right_shift) & 1;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
81 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
82 fclose(inf);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 static int
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
86 check_sync(pos)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
87 unsigned pos;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
89 uint8_t *cand = filebuf + pos;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
90 unsigned n;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
92 for (n = 0; n < 8; n++) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
93 if (cand[n])
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 return 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
96 if (!cand[8])
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
97 return 0;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
98 if (cand[16])
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
99 return 0;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
100 if (!cand[17])
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
101 return 0;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
102 for (n = 3; n < 20; n++) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
103 if (!cand[n * 8])
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 return 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
109 static int
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
110 bit_parity(bits, nbits)
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
111 ubit_t *bits;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
112 unsigned nbits;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
113 {
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
114 unsigned n, sum;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
115
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
116 sum = 0;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
117 for (n = 0; n < nbits; n++)
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
118 sum += bits[n];
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
119 return sum & 1;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
120 }
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
121
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
122 static void
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
123 bits2bytes(bits, bytes, nbytes)
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
124 ubit_t *bits;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
125 uint8_t *bytes;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
126 unsigned nbytes;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
127 {
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
128 unsigned n, m, acc;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
129
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
130 for (n = 0; n < nbytes; n++) {
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
131 acc = 0;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
132 for (m = 0; m < 8; m++) {
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
133 acc <<= 1;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
134 acc |= *bits++;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
135 }
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
136 *bytes++ = acc;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
137 }
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
138 }
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
139
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 static void
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
141 process_frame(pos)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
142 unsigned pos;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 {
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
144 ubit_t *frame = filebuf + pos;
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
145 ubit_t xc_bits[6], dbits[112];
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
146 uint8_t hr_bytes[14];
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
147 int16_t params[18];
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
148 int crc_stat;
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
149
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
150 printf("Frame at 0x%x:\n", pos);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
151 printf(" C1-C4: %u%u%u%u OP %s\n", frame[9], frame[10], frame[11],
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
152 frame[12], bit_parity(frame + 9, 5) ? "good" : "bad");
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
153 bcopy(frame + 14, xc_bits, 2);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
154 bcopy(frame + 18, xc_bits + 2, 4);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
155 printf(" XC1-XC5: %u%u%u%u%u OP %s\n", xc_bits[0], xc_bits[1],
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
156 xc_bits[2], xc_bits[3], xc_bits[4],
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
157 bit_parity(xc_bits, 6) ? "good" : "bad");
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
158 bcopy(frame + 22, dbits, 2);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
159 bcopy(frame + 25, dbits + 2, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
160 bcopy(frame + 33, dbits + 9, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
161 bcopy(frame + 41, dbits + 16, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
162 bcopy(frame + 49, dbits + 23, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
163 bcopy(frame + 57, dbits + 30, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
164 bcopy(frame + 65, dbits + 37, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
165 bcopy(frame + 76, dbits + 44, 4);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
166 bcopy(frame + 81, dbits + 48, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
167 bcopy(frame + 89, dbits + 55, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
168 bcopy(frame + 97, dbits + 62, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
169 bcopy(frame + 105, dbits + 69, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
170 bcopy(frame + 113, dbits + 76, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
171 bcopy(frame + 121, dbits + 83, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
172 bcopy(frame + 129, dbits + 90, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
173 bcopy(frame + 137, dbits + 97, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
174 bcopy(frame + 145, dbits + 104, 7);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
175 dbits[111] = frame[153];
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
176 crc_stat = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, dbits, 44,
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
177 frame + 73);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
178 printf(" CRC %s\n", crc_stat ? "bad" : "good");
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
179 bits2bytes(dbits, hr_bytes, 14);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
180 gsmhr_unpack_ts101318(hr_bytes, params);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
181 printf(" R0=%02x LPC=%03x,%03x,%02x Int=%x Mode=%x\n", params[0],
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
182 params[1], params[2], params[3], params[4], params[5]);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
183 printf(params[5] ? " s1=%02x,%03x,%02x" : " s1=%02x,%02x,%02x",
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
184 params[6], params[7], params[8]);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
185 printf(params[5] ? " s2=%x,%03x,%02x" : " s2=%02x,%02x,%02x",
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
186 params[9], params[10], params[11]);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
187 printf(params[5] ? " s3=%x,%03x,%02x" : " s3=%02x,%02x,%02x",
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
188 params[12], params[13], params[14]);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
189 printf(params[5] ? " s4=%x,%03x,%02x\n" : " s4=%02x,%02x,%02x\n",
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
190 params[15], params[16], params[17]);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
191 printf(" C6-C9: %u%u%u%u\n", frame[154], frame[155], frame[156],
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
192 frame[157]);
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
193 printf(" T1=%u T2=%u\n", frame[158], frame[159]);
0
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
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
197 process_filebuf()
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
199 unsigned p, endp;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
200 int sync = 0, match;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
201
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
202 endp = total_size - 160;
42
61181373875d trau-hr-dump: off-by-one error in file end limit
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
203 for (p = 0; p <= endp; ) {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
204 match = check_sync(p);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
205 if (match != sync) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
206 printf("# %s frame sync at file offset 0x%x\n",
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
207 match ? "Acquired" : "Lost", p);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
209 if (match) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
210 process_frame(p);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
211 if (!filebuf[p+158] && !filebuf[p+159]) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
212 printf(
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
213 "# both T bits equal 0, shifting frame alignment\n");
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
214 p += 158;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
215 } else
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
216 p += 160;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
217 } else
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
218 p++;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
219 sync = match;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 main(argc, argv)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 char **argv;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 if (argc != 3) {
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 fprintf(stderr, "usage: %s binfile subslot\n", argv[0]);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 exit(1);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 }
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
230 read_ts_file(argv[1], argv[2]);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
231 process_filebuf();
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 exit(0);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 }