FreeCalypso > hg > gsm-net-reveng
annotate v110/v110-dump8.c @ 72:afebef67e8d4 default tip
tmo/CSD-tests: document Experiment 7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Nov 2024 02:53:59 +0000 |
parents | 796cc2d94204 |
children |
rev | line source |
---|---|
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
2 * This program reads a 64 kbit/s timeslot recording file, examines it |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
3 * as V.110 with 8 kbit/s intermediate rate, locates 80-bit V.110 frames |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
4 * and dumps them in a mostly raw form. |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
7 #include <sys/types.h> |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
8 #include <sys/file.h> |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
9 #include <sys/stat.h> |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
10 #include <sys/mman.h> |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdint.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <string.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <strings.h> |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
16 #include <unistd.h> |
28
9bcdb091c24d
trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
17 |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
18 static const uint8_t *filebuf; |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
19 static unsigned total_size; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static void |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
22 read_ts_file(filename) |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
23 char *filename; |
2
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
24 { |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
25 int fd; |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
26 struct stat st; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
28 fd = open(filename, O_RDONLY); |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
29 if (fd < 0) { |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
30 perror(filename); |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
31 exit(1); |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
32 } |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
33 fstat(fd, &st); |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
34 if (!S_ISREG(st.st_mode)) { |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
35 fprintf(stderr, "error: %s is not a regular file\n", filename); |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
36 exit(1); |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
37 } |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
38 total_size = st.st_size; |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
39 if (total_size < 80) { |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
40 fprintf(stderr, "error: %s is too short\n", filename); |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
41 exit(1); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
43 filebuf = mmap(NULL, total_size, PROT_READ, MAP_PRIVATE, fd, 0); |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
44 if (filebuf == MAP_FAILED) { |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
45 perror("mmap"); |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
46 exit(1); |
2
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
47 } |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
48 close(fd); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 static int |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
52 check_sync(pos) |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
53 unsigned pos; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 { |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
55 const uint8_t *cand = filebuf + pos; |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
56 unsigned n; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
58 for (n = 0; n < 8; n++) { |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
59 if (cand[n] & 0x80) |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
62 for (n = 1; n < 10; n++) { |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
63 if (!(cand[n * 8] & 0x80)) |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 return 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
69 static unsigned |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
70 extract_data_byte(pos) |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
71 unsigned pos; |
28
9bcdb091c24d
trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
72 { |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
73 const uint8_t *src = filebuf + pos; |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
74 unsigned accum; |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
75 unsigned n; |
28
9bcdb091c24d
trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
76 |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
77 accum = 0; |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
78 for (n = 0; n < 8; n++) { |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
79 accum <<= 1; |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
80 if (*src & 0x80) |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
81 accum |= 1; |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
82 src++; |
28
9bcdb091c24d
trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
83 } |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
84 return accum; |
28
9bcdb091c24d
trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
85 } |
9bcdb091c24d
trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
86 |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 static void |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
88 process_frame(pos) |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
89 unsigned pos; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 { |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
91 unsigned nb; |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
92 |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
93 printf("Frame at 0x%x:", pos); |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
94 pos += 8; |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
95 for (nb = 0; nb < 9; nb++) { |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
96 printf(" %02X", extract_data_byte(pos)); |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
97 pos += 8; |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
98 } |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
99 putchar('\n'); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 static void |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
103 process_filebuf() |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 { |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
105 unsigned p, endp; |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
106 int sync = 0, match; |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
107 |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
108 endp = total_size - 80; |
40
796cc2d94204
new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
109 for (p = 0; p <= endp; ) { |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
110 match = check_sync(p); |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
111 if (match != sync) { |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
112 printf("# %s frame sync at file offset 0x%x\n", |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
113 match ? "Acquired" : "Lost", p); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
115 if (match) { |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
116 process_frame(p); |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
117 p += 80; |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
118 } else |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
119 p++; |
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
120 sync = match; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 main(argc, argv) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 char **argv; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 { |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
127 if (argc != 2) { |
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
128 fprintf(stderr, "usage: %s binfile\n", argv[0]); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 exit(1); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 } |
39
957c20852c7c
new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
131 read_ts_file(argv[1]); |
27
f508dacf2cf9
trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
132 process_filebuf(); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 exit(0); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 } |