# HG changeset patch # User Mychaela Falconia # Date 1717923448 0 # Node ID 5c82f2e56d56cdcd0abdb39bb70e199f53c1ed18 # Parent 0b1c4960e5e917e5ee06e809b0419e66a4f774e8 hr-sid: hack created diff -r 0b1c4960e5e9 -r 5c82f2e56d56 .hgignore --- a/.hgignore Sun Jun 09 06:00:43 2024 +0000 +++ b/.hgignore Sun Jun 09 08:57:28 2024 +0000 @@ -5,6 +5,7 @@ \.inc$ \.gsm$ \.gsmx$ +\.hrpf$ \.robe$ \.[au]l$ \.tch$ @@ -25,6 +26,7 @@ ^dmw/dmw-[au]law\. ^efr-sid/mk-sid-test$ +^hr-sid/sidgen$ ^pcma2efr/all-outputs\. ^pcma2efr/comb-diff$ diff -r 0b1c4960e5e9 -r 5c82f2e56d56 hr-sid/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hr-sid/Makefile Sun Jun 09 08:57:28 2024 +0000 @@ -0,0 +1,15 @@ +CC= gcc +CFLAGS= -O2 +PROG= sidgen +OUTPUT= hr-sid-test.hrpf + +all: ${PROG} ${OUTPUT} + +${PROG}: ${PROG}.o + ${CC} ${CFLAGS} -o $@ $^ + +${OUTPUT}: ${PROG} + ./${PROG} ${OUTPUT} + +clean: + rm -f ${PROG} *.o *.hrpf diff -r 0b1c4960e5e9 -r 5c82f2e56d56 hr-sid/sidgen.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hr-sid/sidgen.c Sun Jun 09 08:57:28 2024 +0000 @@ -0,0 +1,78 @@ +/* + * This program generates a sequence of GSM-HR codec frames in raw packed + * format (aka TS 101 318) that aims to reverse-engineer the logic of + * the SID detector in TI Calypso DSP, and maybe later in historical + * E1 BTS implementations too. + */ + +#include +#include +#include +#include +#include + +static const uint8_t perfect_sid[14] = { + 0x11, 0x22, 0x33, 0x44, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static void +clear_bit(buf, num) + uint8_t *buf; + unsigned num; +{ + unsigned nbyte = num / 8; + unsigned nbit = num % 8; + unsigned mask = 0x80 >> nbit; + + buf[nbyte] &= ~mask; +} + +static void +corrupt_class1_bit(buf, num) + uint8_t *buf; + unsigned num; +{ + clear_bit(buf, num + 36); +} + +static void +corrupt_class2_bit(buf, num) + uint8_t *buf; + unsigned num; +{ + if (num < 8) + clear_bit(buf, num + 81); + else + clear_bit(buf, (num - 8) + 98); +} + +main(argc, argv) + char **argv; +{ + FILE *outf; + uint8_t class1[14], class2[14]; + unsigned n1, n2; + + if (argc != 2) { + fprintf(stderr, "usage: %s outfile\n", argv[0]); + exit(1); + } + outf = fopen(argv[1], "w"); + if (!outf) { + perror(argv[1]); + exit(1); + } + bcopy(perfect_sid, class1, 14); + for (n1 = 0; n1 < 20; n1++) { + bcopy(class1, class2, 14); + for (n2 = 0; n2 < 17; n2++) { + fwrite(class2, 1, 14, outf); + corrupt_class2_bit(class2, n2); + } + fwrite(class2, 1, 14, outf); + corrupt_class1_bit(class1, n1); + } + fclose(outf); + exit(0); +}