changeset 57:fe3cdbbc96f9

d144: new program atrau-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 17:45:29 +0000
parents b32b644b7d96
children a7ede064f883
files .hgignore d144/Makefile d144/atrau-parse.c
diffstat 3 files changed, 123 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Sep 25 07:42:04 2024 +0000
+++ b/.hgignore	Wed Sep 25 17:45:29 2024 +0000
@@ -2,6 +2,7 @@
 
 \.[oa]$
 
+^d144/atrau-parse$
 ^d144/d144-ul-input\.asc$
 ^d144/d144-ul-input\.bin$
 ^d144/edata-input-compile$
--- a/d144/Makefile	Wed Sep 25 07:42:04 2024 +0000
+++ b/d144/Makefile	Wed Sep 25 17:45:29 2024 +0000
@@ -1,10 +1,13 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	edata-input-compile edata-input-decomp
+PROGS=	atrau-parse edata-input-compile edata-input-decomp
 DATA=	d144-ul-input.bin d144-ul-input.asc
 
 all:	${PROGS} ${DATA}
 
+atrau-parse:	atrau-parse.c
+	${CC} ${CFLAGS} -o $@ $@.c
+
 edata-input-compile:	edata-input-compile.c
 	${CC} ${CFLAGS} -o $@ $@.c
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/d144/atrau-parse.c	Wed Sep 25 17:45:29 2024 +0000
@@ -0,0 +1,118 @@
+/*
+ * This program reads a binary file containing a capture of 64 kbit/s output
+ * of a TRAU in 14.4 kbit/s data mode.  Per GSM specs this output is supposed
+ * to contain A-TRAU frames of TS 48.020 chapter 11 (RAA' function);
+ * this program looks for such frames and parses them.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+static void
+decode_ra2(ts_bytes, frame_bits)
+	uint8_t *ts_bytes, *frame_bits;
+{
+	uint8_t *ip, *op;
+	unsigned n;
+
+	ip = ts_bytes;
+	op = frame_bits;
+	for (n = 0; n < 160; n++) {
+		*op++ = (*ip & 0x80) >> 7;
+		*op++ = (*ip & 0x40) >> 6;
+		ip++;
+	}
+}
+
+static int
+check_sync_zeros(frame_bits)
+	uint8_t *frame_bits;
+{
+	int i;
+
+	for (i = 0; i < 16; i++) {
+		if (frame_bits[i])
+			return 0;
+	}
+	return 1;
+}
+
+static unsigned
+gather_nibble(bits)
+	uint8_t *bits;
+{
+	unsigned n, acc;
+
+	acc = 0;
+	for (n = 0; n < 4; n++) {
+		acc <<= 1;
+		acc |= *bits++;
+	}
+	return acc;
+}
+
+static void
+dump_subframe(bits)
+	uint8_t *bits;
+{
+	unsigned n, d;
+
+	printf("  %u ", *bits++);
+	for (n = 0; n < 9; n++) {
+		d = gather_nibble(bits);
+		printf("%x", d);
+		bits += 4;
+	}
+	putchar('\n');
+}
+
+static void
+dump_frame(frame_bits)
+	uint8_t *frame_bits;
+{
+	unsigned n;
+
+	if (!check_sync_zeros(frame_bits))
+		printf("  Bad sync bits!\n");
+	printf("  C1-C5: %u%u%u%u%u\n", frame_bits[17], frame_bits[18],
+		frame_bits[19], frame_bits[20], frame_bits[21]);
+	printf("  M1=%u M2=%u\n", frame_bits[22], frame_bits[23]);
+	for (n = 0; n < 8; n++)
+		dump_subframe(frame_bits + 24 + n * 37);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *binf;
+	uint8_t frame_in[160], frame_bits[320];
+	u_long file_offset;
+	int cc;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s capture.bin\n", argv[0]);
+		exit(1);
+	}
+	binf = fopen(argv[1], "r");
+	if (!binf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	for (file_offset = 0; ; file_offset += 160) {
+		cc = fread(frame_in, 1, 160, binf);
+		if (cc <= 0)
+			break;
+		if (cc != 160) {
+			fprintf(stderr,
+				"error: %s is not a multiple of 160 bytes\n",
+				argv[1]);
+			exit(1);
+		}
+		printf("Frame at 0x%lx:\n", file_offset);
+		decode_ra2(frame_in, frame_bits);
+		dump_frame(frame_bits);
+	}
+	exit(0);
+}