comparison efrtest/dlcap-parse.c @ 162:b98aebd94d1f

gsmefr-dlcap-parse utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 15 Dec 2022 23:47:12 +0000
parents efrtest/dlcap-gsmx.c@5efc377326da
children
comparison
equal deleted inserted replaced
161:fe5aceaf51e0 162:b98aebd94d1f
1 /*
2 * This program reads a TCH/EFS 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 "../libgsmefr/gsm_efr.h"
15
16 static void
17 process_record(lineno, fn_mod_104, status_words, tidsp_bytes)
18 int lineno;
19 unsigned fn_mod_104;
20 uint16_t *status_words;
21 uint8_t *tidsp_bytes;
22 {
23 uint8_t efr_bytes[EFR_RTP_FRAME_LEN];
24 int16_t params[EFR_NUM_PARAMS];
25 int i, j, n;
26
27 printf("#%d: fn=%u DSP %04X %04X %04X\n", lineno, fn_mod_104,
28 status_words[0], status_words[1], status_words[2]);
29 efr_tidsp_to_std(tidsp_bytes, efr_bytes);
30 fputs(" bits ", stdout);
31 for (i = 0; i < 33; i++)
32 printf("%02X", tidsp_bytes[i]);
33 printf(" SID=%d\n", EFR_sid_classify(efr_bytes));
34 printf(" rept-bits %u %u %u %u\n", (tidsp_bytes[23] & 0x38) >> 3,
35 tidsp_bytes[23] & 7, (tidsp_bytes[24] & 0xE0) >> 5,
36 (tidsp_bytes[24] & 0x1C) >> 2);
37 EFR_frame2params(efr_bytes, params);
38 fputs(" LPC", stdout);
39 n = 0;
40 for (i = 0; i < 5; i++)
41 printf(" %d", params[n++]);
42 putchar('\n');
43 for (i = 0; i < 4; i++) {
44 putchar(' ');
45 for (j = 0; j < 13; j++)
46 printf(" %d", params[n++]);
47 putchar('\n');
48 }
49 }
50
51 main(argc, argv)
52 char **argv;
53 {
54 FILE *inf;
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 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
71 /* support both old and new formats */
72 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) &&
73 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) {
74 rc = parse_dlcap_common(linebuf, status_words,
75 tidsp_bytes);
76 if (rc < 0) {
77 invalid: fprintf(stderr,
78 "error: %s is not in the expected format\n",
79 argv[1]);
80 exit(1);
81 }
82 fn_mod_104 = 0; /* won't have TAF */
83 } else if (!strncmp(linebuf, "EFR ", 4)) {
84 rc = parse_dlcap_common(linebuf + 4, status_words,
85 tidsp_bytes);
86 if (rc < 0)
87 goto invalid;
88 if (linebuf[85] != ' ')
89 goto invalid;
90 if (!isdigit(linebuf[86]))
91 goto invalid;
92 fn_mod_104 = strtoul(linebuf + 86, 0, 10);
93 } else
94 goto invalid;
95 process_record(lineno, fn_mod_104, status_words, tidsp_bytes);
96 }
97 exit(0);
98 }