FreeCalypso > hg > gsm-net-reveng
annotate trau-ul-prep/etsi-bit-rd.c @ 56:b32b644b7d96
d144/nokia-tcsm2-atrau.bin: captured A-TRAU output from
Nokia TCSM2, fed with ul-input from Ater
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 25 Sep 2024 07:42:04 +0000 |
parents | 8957383370c5 |
children |
rev | line source |
---|---|
22
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement utility functions for reading ETSI *.cod |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * and *.dec files in either LE or BE format. |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <gsm_efr.h> |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "etsi.h" |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs) |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 FILE *inf; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 uint8_t *bitvec; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 unsigned nwords; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char *filename_for_errs; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int cc; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned n, upper; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cc = fread(file_bytes, 2, nwords, inf); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (cc == 0) |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return 0; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (cc != nwords) { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error: short read from %s\n", |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 filename_for_errs); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(1); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 sp = file_bytes; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 for (n = 0; n < nwords; n++) { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (big_endian) { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 upper = sp[0]; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 bitvec[n] = sp[1]; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } else { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 bitvec[n] = sp[0]; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 upper = sp[1]; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (upper) { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 fprintf(stderr, |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 "error in %s: non-zero in what should be %s upper byte\n", |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 filename_for_errs, big_endian ? "BE" : "LE"); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 exit(1); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 sp += 2; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return 1; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 void |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 bits2frame(input_bits, frame, filename_for_errs, frame_no) |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 uint8_t *input_bits, *frame; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 char *filename_for_errs; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 unsigned frame_no; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 uint8_t bits[248], *sp, *dp; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 unsigned nb, byte, mask; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 bits[0] = 1; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 bits[1] = 1; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 bits[2] = 0; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 bits[3] = 0; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 bcopy(input_bits, bits + 4, 244); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 sp = bits; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 dp = frame; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 byte = 0; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 for (mask = 0x80; mask; mask >>= 1) { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (*sp > 1) { |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fprintf(stderr, |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 "error in %s frame #%u: data bit > 1\n", |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 filename_for_errs, frame_no); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 exit(1); |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (*sp) |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 byte |= mask; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 sp++; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 *dp++ = byte; |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
8957383370c5
trau-ul-prep: implement efrdec2tsrc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |