comparison efrtest/dlcap-gsmx.c @ 140:5efc377326da

gsmefr-dlcap-gsmx: EFR counterpart to gsmfr-cvt-dlcap
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 13 Dec 2022 07:14:41 +0000
parents frtest/cvt-dlcap.c@be57e06bed84
children 3bbb16015a79
comparison
equal deleted inserted replaced
139:be57e06bed84 140:5efc377326da
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 * and converts it into our extended-libgsm binary format, to be further
5 * fed to gsmefr-decode.
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
15 main(argc, argv)
16 char **argv;
17 {
18 FILE *inf, *outf;
19 char linebuf[128];
20 int lineno, rc;
21 uint16_t status_words[3];
22 uint8_t tidsp_bytes[33], efr_bytes[31], bfi[2];
23 unsigned fn_mod_104;
24
25 if (argc != 3) {
26 fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
27 exit(1);
28 }
29 inf = fopen(argv[1], "r");
30 if (!inf) {
31 perror(argv[1]);
32 exit(1);
33 }
34 outf = fopen(argv[2], "w");
35 if (!outf) {
36 perror(argv[2]);
37 exit(1);
38 }
39 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) {
40 /* support both old and new formats */
41 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) &&
42 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) {
43 rc = parse_dlcap_common(linebuf, status_words,
44 tidsp_bytes);
45 if (rc < 0) {
46 invalid: fprintf(stderr,
47 "error: %s is not in the expected format\n",
48 argv[1]);
49 exit(1);
50 }
51 fn_mod_104 = 0; /* won't have TAF */
52 } else if (!strncmp(linebuf, "EFR ", 4)) {
53 rc = parse_dlcap_common(linebuf + 4, status_words,
54 tidsp_bytes);
55 if (rc < 0)
56 goto invalid;
57 if (linebuf[85] != ' ')
58 goto invalid;
59 if (!isdigit(linebuf[86]))
60 goto invalid;
61 fn_mod_104 = strtoul(linebuf + 86, 0, 10);
62 } else
63 goto invalid;
64 /*
65 * Bit 15 of status word 0 is buffer validity flag,
66 * bit 2 is BFI.
67 */
68 if (!(status_words[0] & 0x8000) || (status_words[0] & 0x0004)) {
69 bfi[0] = 0xBF;
70 bfi[1] = fn_mod_104 == 60;
71 fwrite(bfi, 1, 2, outf);
72 } else {
73 efr_tidsp_to_std(tidsp_bytes, efr_bytes);
74 fwrite(efr_bytes, 1, 31, outf);
75 }
76 }
77 exit(0);
78 }