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