view frtest/dlcap-parse.c @ 581:e2d5cad04cbf

libgsmhr1 RxFE: store CN R0+LPC separately from speech In the original GSM 06.06 code the ECU for speech mode is entirely separate from the CN generator, maintaining separate state. (The main intertie between them is the speech vs CN state variable, distinguishing between speech and CN BFIs, in addition to the CN-specific function of distinguishing between initial and update SIDs.) In the present RxFE implementation I initially thought that we could use the same saved_frame buffer for both ECU and CN, overwriting just the first 4 params (R0 and LPC) when a valid SID comes in. However, I now realize it was a bad idea: the original code has a corner case (long sequence of speech-mode BFIs to put the ECU in state 6, then SID and CN-mode BFIs, then a good speech frame) that would be broken by that buffer reuse approach. We could eliminate this corner case by resetting the ECU state when passing through a CN insertion period, but doing so would needlessly increase the behavioral diffs between GSM 06.06 and our version. Solution: use a separate CN-specific buffer for CN R0+LPC parameters, and match the behavior of GSM 06.06 code in this regard.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Feb 2025 10:02:45 +0000
parents 251aed72925e
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),
 * 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 "../libgsmfr2/tw_gsmfr.h"

static void
process_record(lineno, fn_mod_104, status_words, tidsp_bytes)
	int lineno;
	unsigned fn_mod_104;
	uint16_t *status_words;
	uint8_t *tidsp_bytes;
{
	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));
	gsmfr_unpack_to_array(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;
	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);
	}
	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])) {
			/* also support parsing output from fc-vm2hex */
			if (linebuf[4] == '\n') {
				printf("#%d: fn=0 DSP %.4s\n", lineno, linebuf);
				continue;
			}
			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);
	}
	exit(0);
}