FreeCalypso > hg > gsm-net-reveng
annotate trau-ul-compile/trau-ul-decomp.c @ 33:e828468b0afd
doc/TFO-xform/Theory: article written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 31 Aug 2024 20:45:25 +0000 |
parents | f80e64139670 |
children |
rev | line source |
---|---|
26
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a *.tul binary file and disassembles it back |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * to ASCII form. It is intended for checking the correctness of |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * trau-ul-compile, and also for sanity checks during actual TRAU |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * testing with these tools. |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <tw_gsmfr.h> |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <gsm_efr.h> |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 main(argc, argv) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char **argv; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 FILE *binf, *outf; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned frame_index; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 uint8_t frame[34]; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int16_t params[GSMFR_NUM_PARAMS]; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int rc, i, j, n; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (argc < 2 || argc > 3) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fprintf(stderr, "usage: %s input.tul [output.tsrc]\n", |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 argv[0]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(1); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 binf = fopen(argv[1], "r"); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (!binf) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 perror(argv[1]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (argc > 2) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 outf = fopen(argv[2], "w"); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (!outf) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 perror(argv[2]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 exit(1); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } else |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 outf = stdout; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 for (frame_index = 0; ; frame_index++) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 rc = fread(frame, 1, 34, binf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (!rc) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 break; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (rc != 34) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 inv_input: fprintf(stderr, "error: %s is not in expected format\n", |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 argv[1]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 exit(1); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 switch (frame[0] & 0xF0) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 case 0xC0: |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(outf, "# input frame %u\nFrame_EFR {\n", |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 frame_index); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (frame_index % 24 == 23) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 fputs("\t# TAF position\n", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 fprintf(outf, "\tBFI %u\n", frame[33] >> 7); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 EFR_frame2params(frame, params); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 n = 0; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fputs("\tLPC", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 for (i = 0; i < 5; i++) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fprintf(outf, " %d", params[n++]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 putc('\n', outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 for (i = 0; i < 4; i++) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 fputs("\tsf", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 for (j = 0; j < 13; j++) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(outf, " %d", params[n++]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 putc('\n', outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 fprintf(outf, "\tSID %u\n", frame[33] & 3); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fputs("}\n\n", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 break; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 case 0xD0: |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 fprintf(outf, "# input frame %u\nFrame_FR {\n", |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 frame_index); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (frame_index % 24 == 23) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fputs("\t# TAF position\n", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 fprintf(outf, "\tBFI %u\n", frame[33] >> 7); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 gsmfr_unpack_to_array(frame, params); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 n = 0; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fputs("\tLARc", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 for (i = 0; i < 8; i++) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 fprintf(outf, " %d", params[n++]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 putc('\n', outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 for (i = 0; i < 4; i++) { |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 fputs("\tsf", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 for (j = 0; j < 17; j++) |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 fprintf(outf, " %d", params[n++]); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 putc('\n', outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 fprintf(outf, "\tSID %u\n", frame[33] & 3); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 fputs("}\n\n", outf); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 break; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 default: |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 goto inv_input; |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 exit(0); |
f80e64139670
trau-ul-decomp program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |