FreeCalypso > hg > gsm-codec-lib
annotate efrtest/dlcap-gsmx.c @ 556:18aca50d68df default tip
doc/Calypso-TCH-downlink: update for FR1 BFI-with-data
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 11 Oct 2024 01:54:00 +0000 |
parents | 6e39fc0134da |
children |
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 |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * (fw version with TCH downlink sniffing feature and fc-shell tch record) |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * and converts it into our extended-libgsm binary format, to be further |
163
3bbb16015a79
gsmefr-dlcap-gsmx: logic change for updated understanding of DSP flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
5 * fed to gsmefr-decode or other tools. |
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> |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 main(argc, argv) |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char **argv; |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 FILE *inf, *outf; |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char linebuf[128]; |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
20 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
|
21 uint16_t status_words[3]; |
140
5efc377326da
gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
22 uint8_t tidsp_bytes[33], efr_bytes[31], bfi[2]; |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
23 unsigned fn_mod_104; |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (argc != 3) { |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 inf = fopen(argv[1], "r"); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (!inf) { |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 perror(argv[1]); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 outf = fopen(argv[2], "w"); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (!outf) { |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 perror(argv[2]); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 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
|
40 /* 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
|
41 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
|
42 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
|
43 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
|
44 tidsp_bytes); |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
45 if (rc < 0) { |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 invalid: fprintf(stderr, |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
47 "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
|
48 argv[1]); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
51 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
|
52 } 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
|
53 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
|
54 tidsp_bytes); |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
55 if (rc < 0) |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
56 goto invalid; |
140
5efc377326da
gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
57 if (linebuf[85] != ' ') |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
58 goto invalid; |
140
5efc377326da
gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
59 if (!isdigit(linebuf[86])) |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 goto invalid; |
140
5efc377326da
gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
61 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
|
62 } else |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
63 goto invalid; |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
64 /* |
179
6e39fc0134da
[e]frtest/dlcap-gsmx.c: fix comment pointing to description of DSP flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
65 * DSP flags are documented in the TCH-tap-modes article |
6e39fc0134da
[e]frtest/dlcap-gsmx.c: fix comment pointing to description of DSP flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
66 * in freecalypso-docs. |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
67 */ |
163
3bbb16015a79
gsmefr-dlcap-gsmx: logic change for updated understanding of DSP flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
68 if ((status_words[0] & 0xC204) == 0xC000) { |
3bbb16015a79
gsmefr-dlcap-gsmx: logic change for updated understanding of DSP flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
69 efr_tidsp_to_std(tidsp_bytes, efr_bytes); |
3bbb16015a79
gsmefr-dlcap-gsmx: logic change for updated understanding of DSP flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
70 fwrite(efr_bytes, 1, 31, outf); |
3bbb16015a79
gsmefr-dlcap-gsmx: logic change for updated understanding of DSP flags
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
71 } else { |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
72 bfi[0] = 0xBF; |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
73 bfi[1] = fn_mod_104 == 60; |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
74 fwrite(bfi, 1, 2, outf); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(0); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |