FreeCalypso > hg > gsm-codec-lib
annotate frtest/dlcap-parse.c @ 272:19db59c9dc07
libgsmfr2: integrate table.c from libgsm
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Apr 2024 02:36:08 +0000 |
parents | 5fe0b3eb35c1 |
children | 251aed72925e |
rev | line source |
---|---|
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
2 * This program reads a TCH/FS downlink capture produced with FreeCalypso tools |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
3 * (fw version with TCH downlink sniffing feature and fc-shell tch record), |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
4 * parses the frame bits according to our current understanding, and dumps |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
5 * everything in human-readable form for further analysis. |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <ctype.h> |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
139
be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
10 #include <stdint.h> |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
12 #include <string.h> |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
13 #include <strings.h> |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
14 #include <gsm.h> |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
15 #include "../libgsmfrp/gsm_fr_preproc.h" |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
16 |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
17 static void |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
18 process_record(lineno, fn_mod_104, status_words, tidsp_bytes, dummy_state) |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
19 int lineno; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
20 unsigned fn_mod_104; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
21 uint16_t *status_words; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
22 uint8_t *tidsp_bytes; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
23 gsm dummy_state; |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
24 { |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
25 uint8_t libgsm_bytes[33]; |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
26 int16_t params[76]; |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
27 int i, j, n; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
28 |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
29 printf("#%d: fn=%u DSP %04X %04X %04X\n", lineno, fn_mod_104, |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
30 status_words[0], status_words[1], status_words[2]); |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
31 gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes); |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
32 fputs(" bits ", stdout); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
33 for (i = 0; i < 33; i++) |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
34 printf("%02X", tidsp_bytes[i]); |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
35 printf(" SID=%d\n", gsmfr_preproc_sid_classify(libgsm_bytes)); |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
36 gsm_explode(dummy_state, libgsm_bytes, params); |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
37 fputs(" FR", stdout); |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
38 n = 0; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
39 for (i = 0; i < 8; i++) |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
40 printf(" %d", params[n++]); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
41 putchar('\n'); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
42 for (i = 0; i < 4; i++) { |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
43 putchar(' '); |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
44 for (j = 0; j < 17; j++) |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
45 printf(" %d", params[n++]); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
46 putchar('\n'); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
47 } |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
48 } |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 main(argc, argv) |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 char **argv; |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 { |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
53 FILE *inf; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
54 gsm dummy_state; |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 char linebuf[128]; |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
56 int lineno, rc; |
139
be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
57 uint16_t status_words[3]; |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
58 uint8_t tidsp_bytes[33]; |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
59 unsigned fn_mod_104; |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
61 if (argc != 2) { |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
62 fprintf(stderr, "usage: %s dlcap-file\n", argv[0]); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 inf = fopen(argv[1], "r"); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!inf) { |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 perror(argv[1]); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
70 dummy_state = gsm_create(); |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
71 if (!dummy_state) { |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
72 fprintf(stderr, "gsm_create() failed!\n"); |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
73 exit(1); |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
74 } |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
76 /* support both old and new formats */ |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
77 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
78 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { |
178
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
79 /* also support parsing output from fc-vm2hex */ |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
80 if (linebuf[4] == '\n') { |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
81 printf("#%d: fn=0 DSP %.4s\n", lineno, linebuf); |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
82 continue; |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
83 } |
139
be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
84 rc = parse_dlcap_common(linebuf, status_words, |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
85 tidsp_bytes); |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
86 if (rc < 0) { |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 invalid: fprintf(stderr, |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
88 "error: %s is not in the expected format\n", |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
89 argv[1]); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
92 fn_mod_104 = 0; /* won't have TAF */ |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
93 } else if (!strncmp(linebuf, "FR ", 3)) { |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
94 rc = parse_dlcap_common(linebuf + 3, status_words, |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
95 tidsp_bytes); |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
96 if (rc < 0) |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
97 goto invalid; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
98 if (linebuf[84] != ' ') |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
99 goto invalid; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
100 if (!isdigit(linebuf[85])) |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 goto invalid; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
102 fn_mod_104 = strtoul(linebuf + 85, 0, 10); |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
103 } else |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
104 goto invalid; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
105 process_record(lineno, fn_mod_104, status_words, tidsp_bytes, |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
106 dummy_state); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 exit(0); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |