FreeCalypso > hg > gsm-net-reveng
changeset 27:f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 18 Aug 2024 06:26:23 +0000 |
parents | f80e64139670 |
children | 9bcdb091c24d |
files | .hgignore trau-decode/Makefile trau-decode/dump-1bit.c trau-decode/trau-sync8.c |
diffstat | 4 files changed, 206 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon Jun 24 01:50:02 2024 +0000 +++ b/.hgignore Sun Aug 18 06:26:23 2024 +0000 @@ -4,8 +4,10 @@ ^tfo/find-is-hdr$ +^trau-decode/dump-1bit$ ^trau-decode/trau-extr$ ^trau-decode/trau-parse$ +^trau-decode/trau-sync8$ ^trau-files/.*\.dump$ ^trau-files/.*\.gsmx$
--- a/trau-decode/Makefile Mon Jun 24 01:50:02 2024 +0000 +++ b/trau-decode/Makefile Sun Aug 18 06:26:23 2024 +0000 @@ -1,14 +1,20 @@ CC= gcc CFLAGS= -O2 -PROGS= trau-extr trau-parse +PROGS= dump-1bit trau-extr trau-parse trau-sync8 all: ${PROGS} +dump-1bit: dump-1bit.c + ${CC} ${CFLAGS} -o $@ $@.c + trau-extr: extr-fr.o extr-efr.o extr-main.o ${CC} ${CFLAGS} -o $@ $^ -lgsmfr2 trau-parse: crc8gen.o parse-fr.o parse-efr.o parse-main.o ${CC} ${CFLAGS} -o $@ $^ -lgsmfr2 -lgsmefr +trau-sync8: trau-sync8.c + ${CC} ${CFLAGS} -o $@ $@.c + clean: rm -f *.o ${PROGS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trau-decode/dump-1bit.c Sun Aug 18 06:26:23 2024 +0000 @@ -0,0 +1,47 @@ +/* + * This program reads a 64 kbit/s timeslot recording file, focuses on one + * bit out of the eight (a single 8 kbit/s subslot) and prints a dump + * that shows just this one bit out of each byte. It is an aid for + * development and debugging of frame sync tools for 8 kbit/s submultiplexing. + */ + +#include <stdio.h> +#include <stdlib.h> + +main(argc, argv) + char **argv; +{ + FILE *inf; + int subslot, right_shift; + unsigned file_offset, mod16; + int inb; + + if (argc != 3) { + fprintf(stderr, "usage: %s binfile subslot\n", argv[0]); + exit(1); + } + inf = fopen(argv[1], "r"); + if (!inf) { + perror(argv[1]); + exit(1); + } + subslot = atoi(argv[2]); + if (subslot < 0 || subslot > 7) { + fprintf(stderr, "error: invalid subslot argument\n"); + exit(1); + } + right_shift = 7 - subslot; + for (file_offset = 0; ; file_offset++) { + inb = getc(inf); + if (inb < 0) + break; + mod16 = file_offset & 15; + if (mod16 == 0) + printf("%08X:", file_offset); + if (mod16 == 0 || mod16 == 4 || mod16 == 8 || mod16 == 12) + putchar(' '); + printf(" %u", (inb >> right_shift) & 1); + if (mod16 == 15) + putchar('\n'); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trau-decode/trau-sync8.c Sun Aug 18 06:26:23 2024 +0000 @@ -0,0 +1,150 @@ +/* + * This program reads a 64 kbit/s timeslot recording file, examines one + * of the eight 8 kbit/s subslots (selected), looks for the sync pattern of + * GSM 08.61 (HRv1 speech or HR data), and dumps each synced frame + * as a hex line. + */ + +#include <sys/types.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> + +static uint8_t *filebuf; +static unsigned total_size; + +static void +read_ts_file(filename, subslot_arg) + char *filename, *subslot_arg; +{ + FILE *inf; + struct stat st; + int subslot, right_shift; + unsigned n; + uint8_t *dp; + int b; + + inf = fopen(filename, "r"); + if (!inf) { + perror(filename); + exit(1); + } + fstat(fileno(inf), &st); + if (!S_ISREG(st.st_mode)) { + fprintf(stderr, "error: %s is not a regular file\n", filename); + exit(1); + } + total_size = st.st_size; + if (total_size < 160) { + fprintf(stderr, "error: %s is too short\n", filename); + exit(1); + } + filebuf = malloc(total_size); + if (!filebuf) { + perror("malloc of file size"); + exit(1); + } + subslot = atoi(subslot_arg); + if (subslot < 0 || subslot > 7) { + fprintf(stderr, "error: invalid subslot argument\n"); + exit(1); + } + right_shift = 7 - subslot; + dp = filebuf; + for (n = 0; n < total_size; n++) { + b = getc(inf); + if (b < 0) { + fprintf(stderr, + "error: getc() returned EOF contrary to st_size\n"); + exit(1); + } + *dp++ = (b >> right_shift) & 1; + } + fclose(inf); +} + +static int +check_sync(pos) + unsigned pos; +{ + uint8_t *cand = filebuf + pos; + unsigned n; + + for (n = 0; n < 8; n++) { + if (cand[n]) + return 0; + } + if (!cand[8]) + return 0; + if (cand[16]) + return 0; + if (!cand[17]) + return 0; + for (n = 3; n < 20; n++) { + if (!cand[n * 8]) + return 0; + } + return 1; +} + +static void +process_frame(pos) + unsigned pos; +{ + uint8_t *sp = filebuf + pos; + unsigned n, m, d; + + for (n = 0; n < 40; n++) { + d = 0; + for (m = 0; m < 4; m++) { + d <<= 1; + d |= *sp++; + } + printf("%x", d); + } + putchar('\n'); +} + +static void +process_filebuf() +{ + unsigned p, endp; + int sync = 0, match; + + endp = total_size - 160; + for (p = 0; p < endp; ) { + match = check_sync(p); + if (match != sync) { + printf("# %s frame sync at file offset 0x%x\n", + match ? "Acquired" : "Lost", p); + } + if (match) { + process_frame(p); + if (!filebuf[p+158] && !filebuf[p+159]) { + printf( + "# both T bits equal 0, shifting frame alignment\n"); + p += 158; + } else + p += 160; + } else + p++; + sync = match; + } +} + +main(argc, argv) + char **argv; +{ + if (argc != 3) { + fprintf(stderr, "usage: %s binfile subslot\n", argv[0]); + exit(1); + } + read_ts_file(argv[1], argv[2]); + process_filebuf(); + exit(0); +}