annotate efrtest/dlcap-parse.c @ 537:f9eefb61fb2f

frtest: new program gsmfr-decode-tw5
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 21 Sep 2024 23:31:25 +0000
parents b98aebd94d1f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
140
5efc377326da gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents: 139
diff changeset
2 * This program reads a TCH/EFS 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>
162
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
14 #include "../libgsmefr/gsm_efr.h"
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
15
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
16 static void
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
17 process_record(lineno, fn_mod_104, status_words, tidsp_bytes)
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
18 int lineno;
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
19 unsigned fn_mod_104;
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
20 uint16_t *status_words;
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
21 uint8_t *tidsp_bytes;
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
22 {
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
23 uint8_t efr_bytes[EFR_RTP_FRAME_LEN];
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
24 int16_t params[EFR_NUM_PARAMS];
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
25 int i, j, n;
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
26
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
27 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
28 status_words[0], status_words[1], status_words[2]);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
29 efr_tidsp_to_std(tidsp_bytes, efr_bytes);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
30 fputs(" bits ", stdout);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
31 for (i = 0; i < 33; i++)
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
32 printf("%02X", tidsp_bytes[i]);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
33 printf(" SID=%d\n", EFR_sid_classify(efr_bytes));
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
34 printf(" rept-bits %u %u %u %u\n", (tidsp_bytes[23] & 0x38) >> 3,
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
35 tidsp_bytes[23] & 7, (tidsp_bytes[24] & 0xE0) >> 5,
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
36 (tidsp_bytes[24] & 0x1C) >> 2);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
37 EFR_frame2params(efr_bytes, params);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
38 fputs(" LPC", stdout);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
39 n = 0;
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
40 for (i = 0; i < 5; i++)
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
41 printf(" %d", params[n++]);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
42 putchar('\n');
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
43 for (i = 0; i < 4; i++) {
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
44 putchar(' ');
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
45 for (j = 0; j < 13; j++)
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
46 printf(" %d", params[n++]);
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
47 putchar('\n');
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
48 }
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
49 }
19
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 main(argc, argv)
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 char **argv;
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
162
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
54 FILE *inf;
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 }
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 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
71 /* 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
72 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
73 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) {
139
be57e06bed84 factor out common part of gsmfr-cvt-dlcap, in prep for EFR
Mychaela Falconia <falcon@freecalypso.org>
parents: 137
diff changeset
74 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
75 tidsp_bytes);
b7ea278390eb gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
76 if (rc < 0) {
19
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 invalid: fprintf(stderr,
137
b7ea278390eb gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
78 "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
79 argv[1]);
19
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 exit(1);
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
137
b7ea278390eb gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
82 fn_mod_104 = 0; /* won't have TAF */
140
5efc377326da gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents: 139
diff changeset
83 } else if (!strncmp(linebuf, "EFR ", 4)) {
5efc377326da gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents: 139
diff changeset
84 rc = parse_dlcap_common(linebuf + 4, 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)
b7ea278390eb gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
87 goto invalid;
140
5efc377326da gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents: 139
diff changeset
88 if (linebuf[85] != ' ')
137
b7ea278390eb gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
89 goto invalid;
140
5efc377326da gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents: 139
diff changeset
90 if (!isdigit(linebuf[86]))
19
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 goto invalid;
140
5efc377326da gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents: 139
diff changeset
92 fn_mod_104 = strtoul(linebuf + 86, 0, 10);
137
b7ea278390eb gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
93 } else
b7ea278390eb gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
94 goto invalid;
162
b98aebd94d1f gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents: 140
diff changeset
95 process_record(lineno, fn_mod_104, status_words, tidsp_bytes);
19
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 exit(0);
7960744ba19c frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }