FreeCalypso > hg > gsm-codec-lib
view frtest/cvt-dlcap.c @ 160:eefef9f6d533
libgsmefr: randomize d1035pf params in no-data BFI case
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 15 Dec 2022 07:23:18 +0000 |
parents | be57e06bed84 |
children |
line wrap: on
line source
/* * This program reads a TCH/FS downlink capture produced with FreeCalypso tools * (fw version with TCH downlink sniffing feature and fc-shell tch record) * and converts it into our extended-libgsm binary format, to be further * fed to gsmfr-decode. */ #include <ctype.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> main(argc, argv) char **argv; { FILE *inf, *outf; char linebuf[128]; int lineno, rc; uint16_t status_words[3]; uint8_t tidsp_bytes[33], libgsm_bytes[33], bfi[2]; unsigned fn_mod_104; if (argc != 3) { fprintf(stderr, "usage: %s infile outfile\n", argv[0]); exit(1); } inf = fopen(argv[1], "r"); if (!inf) { perror(argv[1]); exit(1); } outf = fopen(argv[2], "w"); if (!outf) { perror(argv[2]); exit(1); } for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { /* support both old and new formats */ if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { rc = parse_dlcap_common(linebuf, status_words, tidsp_bytes); if (rc < 0) { invalid: fprintf(stderr, "error: %s is not in the expected format\n", argv[1]); exit(1); } fn_mod_104 = 0; /* won't have TAF */ } else if (!strncmp(linebuf, "FR ", 3)) { rc = parse_dlcap_common(linebuf + 3, status_words, tidsp_bytes); if (rc < 0) goto invalid; if (linebuf[84] != ' ') goto invalid; if (!isdigit(linebuf[85])) goto invalid; fn_mod_104 = strtoul(linebuf + 85, 0, 10); } else goto invalid; /* * Bit 15 of status word 0 is buffer validity flag, * bit 2 is BFI. */ if (!(status_words[0] & 0x8000) || (status_words[0] & 0x0004)) { bfi[0] = 0xBF; bfi[1] = fn_mod_104 == 60; fwrite(bfi, 1, 2, outf); } else { gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes); fwrite(libgsm_bytes, 1, 33, outf); } } exit(0); }