FreeCalypso > hg > vband-misc
annotate hr-sid/sidgen.c @ 45:5c82f2e56d56
hr-sid: hack created
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 09 Jun 2024 08:57:28 +0000 |
parents | |
children |
rev | line source |
---|---|
45
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program generates a sequence of GSM-HR codec frames in raw packed |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * format (aka TS 101 318) that aims to reverse-engineer the logic of |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * the SID detector in TI Calypso DSP, and maybe later in historical |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * E1 BTS implementations too. |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static const uint8_t perfect_sid[14] = { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 0x11, 0x22, 0x33, 0x44, 0xFF, 0xFF, 0xFF, |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 }; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static void |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 clear_bit(buf, num) |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 uint8_t *buf; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned num; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned nbyte = num / 8; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned nbit = num % 8; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 unsigned mask = 0x80 >> nbit; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 buf[nbyte] &= ~mask; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 static void |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 corrupt_class1_bit(buf, num) |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 uint8_t *buf; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 unsigned num; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 clear_bit(buf, num + 36); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 static void |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 corrupt_class2_bit(buf, num) |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 uint8_t *buf; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 unsigned num; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (num < 8) |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 clear_bit(buf, num + 81); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 else |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 clear_bit(buf, (num - 8) + 98); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 main(argc, argv) |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 char **argv; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 FILE *outf; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 uint8_t class1[14], class2[14]; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 unsigned n1, n2; |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (argc != 2) { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 fprintf(stderr, "usage: %s outfile\n", argv[0]); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 exit(1); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 outf = fopen(argv[1], "w"); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (!outf) { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 perror(argv[1]); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 exit(1); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 bcopy(perfect_sid, class1, 14); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 for (n1 = 0; n1 < 20; n1++) { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 bcopy(class1, class2, 14); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 for (n2 = 0; n2 < 17; n2++) { |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 fwrite(class2, 1, 14, outf); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 corrupt_class2_bit(class2, n2); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 fwrite(class2, 1, 14, outf); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 corrupt_class1_bit(class1, n1); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 fclose(outf); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(0); |
5c82f2e56d56
hr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |