FreeCalypso > hg > gsm-codec-lib
changeset 167:80c93ef82a51
gsmfr-dlcap-parse utility written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Dec 2022 08:38:36 +0000 |
parents | 500f3e93964f |
children | 486e19acc66f |
files | .hgignore frtest/Makefile frtest/dlcap-parse.c |
diffstat | 3 files changed, 110 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Dec 16 08:23:32 2022 +0000 +++ b/.hgignore Fri Dec 16 08:38:36 2022 +0000 @@ -27,6 +27,7 @@ ^frtest/gsmfr-decode$ ^frtest/gsmfr-decode-r$ ^frtest/gsmfr-dlcap-gsmx$ +^frtest/gsmfr-dlcap-parse$ ^frtest/gsmfr-encode$ ^frtest/gsmfr-encode-r$ ^frtest/gsmfr-hand-test$
--- a/frtest/Makefile Fri Dec 16 08:23:32 2022 +0000 +++ b/frtest/Makefile Fri Dec 16 08:38:36 2022 +0000 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -PROGS= gsmfr-decode gsmfr-decode-r gsmfr-dlcap-gsmx gsmfr-encode \ - gsmfr-encode-r gsmfr-hand-test gsmfr-max-out gsmfr-preproc +PROGS= gsmfr-decode gsmfr-decode-r gsmfr-dlcap-gsmx gsmfr-dlcap-parse \ + gsmfr-encode gsmfr-encode-r gsmfr-hand-test gsmfr-max-out gsmfr-preproc LIBPP= ../libgsmfrp/libgsmfrp.a LIBTEST=../libtest/libtest.a LIBDEC= ${LIBTEST} ${LIBPP} @@ -18,6 +18,9 @@ gsmfr-dlcap-gsmx: dlcap-gsmx.o tidsp.o ${LIBTEST} ${CC} ${CFLAGS} -o $@ dlcap-gsmx.o tidsp.o ${LIBTEST} +gsmfr-dlcap-parse: dlcap-parse.o tidsp.o ${LIBDEC} + ${CC} ${CFLAGS} -o $@ dlcap-parse.o tidsp.o ${LIBDEC} -lgsm + gsmfr-encode: encode.o ${LIBTEST} ${CC} ${CFLAGS} -o $@ encode.o ${LIBTEST} -lgsm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frtest/dlcap-parse.c Fri Dec 16 08:38:36 2022 +0000 @@ -0,0 +1,104 @@ +/* + * This program reads a TCH/FS downlink capture produced with FreeCalypso tools + * (fw version with TCH downlink sniffing feature and fc-shell tch record), + * parses the frame bits according to our current understanding, and dumps + * everything in human-readable form for further analysis. + */ + +#include <ctype.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <gsm.h> +#include "../libgsmfrp/gsm_fr_preproc.h" + +static void +process_record(lineno, fn_mod_104, status_words, tidsp_bytes, dummy_state) + int lineno; + unsigned fn_mod_104; + uint16_t *status_words; + uint8_t *tidsp_bytes; + gsm dummy_state; +{ + uint8_t libgsm_bytes[33]; + int16_t params[76]; + int i, j, n; + + printf("#%d: fn=%u DSP %04X %04X %04X\n", lineno, fn_mod_104, + status_words[0], status_words[1], status_words[2]); + gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes); + fputs(" bits ", stdout); + for (i = 0; i < 33; i++) + printf("%02X", tidsp_bytes[i]); + printf(" SID=%d\n", gsmfr_preproc_sid_classify(libgsm_bytes)); + gsm_explode(dummy_state, libgsm_bytes, params); + fputs(" FR", stdout); + n = 0; + for (i = 0; i < 8; i++) + printf(" %d", params[n++]); + putchar('\n'); + for (i = 0; i < 4; i++) { + putchar(' '); + for (j = 0; j < 17; j++) + printf(" %d", params[n++]); + putchar('\n'); + } +} + +main(argc, argv) + char **argv; +{ + FILE *inf; + gsm dummy_state; + char linebuf[128]; + int lineno, rc; + uint16_t status_words[3]; + uint8_t tidsp_bytes[33]; + unsigned fn_mod_104; + + if (argc != 2) { + fprintf(stderr, "usage: %s dlcap-file\n", argv[0]); + exit(1); + } + inf = fopen(argv[1], "r"); + if (!inf) { + perror(argv[1]); + exit(1); + } + dummy_state = gsm_create(); + if (!dummy_state) { + fprintf(stderr, "gsm_create() failed!\n"); + 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; + process_record(lineno, fn_mod_104, status_words, tidsp_bytes, + dummy_state); + } + exit(0); +}