FreeCalypso > hg > gsm-net-reveng
diff trau-decode/trau-hr-dump.c @ 74:e78c6b1ecb91
trau-decode: refactor trau-hr-dump
The desire is to create a companion program that will read hex lines
representing TRAU-8k frames and then decode those frames in exactly
the same way how we currently decode frames read from binary capture
files. Hence the decoder portion of trau-hr-dump needs to be
factored out.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 08 Feb 2025 03:00:31 +0000 |
parents | 06f241846c67 |
children |
line wrap: on
line diff
--- a/trau-decode/trau-hr-dump.c Sat Feb 08 01:13:54 2025 +0000 +++ b/trau-decode/trau-hr-dump.c Sat Feb 08 03:00:31 2025 +0000 @@ -14,20 +14,6 @@ #include <string.h> #include <strings.h> #include <unistd.h> -#include "gsmhr_unpack.h" -#include "osmo_bits.h" - -/* - * EFR TRAU parity (also used for HR) - * - * g(x) = x^3 + x^1 + 1 - */ -static const struct osmo_crc8gen_code gsm0860_efr_crc3 = { - .bits = 3, - .poly = 0x3, - .init = 0x0, - .remainder = 0x7, -}; static uint8_t *filebuf; static unsigned total_size; @@ -107,40 +93,9 @@ return 1; } -static int -bit_parity(bits, nbits) - ubit_t *bits; - unsigned nbits; -{ - unsigned n, sum; - - sum = 0; - for (n = 0; n < nbits; n++) - sum += bits[n]; - return sum & 1; -} - -static void -bits2bytes(bits, bytes, nbytes) - ubit_t *bits; - uint8_t *bytes; - unsigned nbytes; -{ - unsigned n, m, acc; - - for (n = 0; n < nbytes; n++) { - acc = 0; - for (m = 0; m < 8; m++) { - acc <<= 1; - acc |= *bits++; - } - *bytes++ = acc; - } -} - static void dump_raw_frame(frame_bits) - ubit_t *frame_bits; + uint8_t *frame_bits; { uint8_t *sp = frame_bits; unsigned n, m, d; @@ -160,58 +115,12 @@ process_frame(pos) unsigned pos; { - ubit_t *frame = filebuf + pos; - ubit_t xc_bits[6], dbits[112]; - uint8_t hr_bytes[14]; - int16_t params[18]; - int crc_stat; + uint8_t *frame = filebuf + pos; printf("Frame at 0x%x:\n", pos); if (include_raw) dump_raw_frame(frame); - printf(" C1-C4: %u%u%u%u OP %s\n", frame[9], frame[10], frame[11], - frame[12], bit_parity(frame + 9, 5) ? "good" : "bad"); - bcopy(frame + 14, xc_bits, 2); - bcopy(frame + 18, xc_bits + 2, 4); - printf(" XC1-XC5: %u%u%u%u%u OP %s\n", xc_bits[0], xc_bits[1], - xc_bits[2], xc_bits[3], xc_bits[4], - bit_parity(xc_bits, 6) ? "good" : "bad"); - bcopy(frame + 22, dbits, 2); - bcopy(frame + 25, dbits + 2, 7); - bcopy(frame + 33, dbits + 9, 7); - bcopy(frame + 41, dbits + 16, 7); - bcopy(frame + 49, dbits + 23, 7); - bcopy(frame + 57, dbits + 30, 7); - bcopy(frame + 65, dbits + 37, 7); - bcopy(frame + 76, dbits + 44, 4); - bcopy(frame + 81, dbits + 48, 7); - bcopy(frame + 89, dbits + 55, 7); - bcopy(frame + 97, dbits + 62, 7); - bcopy(frame + 105, dbits + 69, 7); - bcopy(frame + 113, dbits + 76, 7); - bcopy(frame + 121, dbits + 83, 7); - bcopy(frame + 129, dbits + 90, 7); - bcopy(frame + 137, dbits + 97, 7); - bcopy(frame + 145, dbits + 104, 7); - dbits[111] = frame[153]; - crc_stat = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, dbits, 44, - frame + 73); - printf(" CRC %s\n", crc_stat ? "bad" : "good"); - bits2bytes(dbits, hr_bytes, 14); - gsmhr_unpack_ts101318(hr_bytes, params); - printf(" R0=%02x LPC=%03x,%03x,%02x Int=%x Mode=%x\n", params[0], - params[1], params[2], params[3], params[4], params[5]); - printf(params[5] ? " s1=%02x,%03x,%02x" : " s1=%02x,%02x,%02x", - params[6], params[7], params[8]); - printf(params[5] ? " s2=%x,%03x,%02x" : " s2=%02x,%02x,%02x", - params[9], params[10], params[11]); - printf(params[5] ? " s3=%x,%03x,%02x" : " s3=%02x,%02x,%02x", - params[12], params[13], params[14]); - printf(params[5] ? " s4=%x,%03x,%02x\n" : " s4=%02x,%02x,%02x\n", - params[15], params[16], params[17]); - printf(" C6-C9: %u%u%u%u\n", frame[154], frame[155], frame[156], - frame[157]); - printf(" T1=%u T2=%u\n", frame[158], frame[159]); + print_gsmhr_frame(frame); } static void