forked from E3V3A/gsm-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchan_detect.c
More file actions
139 lines (116 loc) · 1.93 KB
/
chan_detect.c
File metadata and controls
139 lines (116 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include "chan_detect.h"
uint8_t bcch_detect(uint32_t fn, uint8_t combined, uint8_t *subchan)
{
uint8_t type = UNKNOWN;
uint8_t fn_mod = fn % 51;
uint8_t sacch_sub = ((fn % 102) >= 51) ? 2 : 0;
*subchan = 0;
switch (fn_mod) {
/* FCCH */
case 0:
case 10:
case 20:
case 30:
case 40:
break;
/* SCH */
case 1:
case 11:
case 21:
case 31:
case 41:
break;
/* IDLE */
case 50:
break;
/* BCCH */
case 2:
case 6:
type = BCCH;
break;
/* CCCH */
case 12:
case 16:
type = CCCH;
break;
/* CCCH/SDCCH */
case 22:
type = SDCCH;
*subchan = 0;
break;
case 26:
type = SDCCH;
*subchan = 1;
break;
case 32:
type = SDCCH;
*subchan = 2;
break;
case 36:
type = SDCCH;
*subchan = 3;
break;
/* CCCH/SACCH */
case 42:
type = SACCH;
*subchan = 0 + sacch_sub;
break;
case 46:
type = SACCH;
*subchan = 1 + sacch_sub;
break;
/* burst in the middle */
default:
break;
}
if (!combined) {
if ((type == SDCCH) || (type == SACCH))
type = CCCH;
}
return type;
}
uint8_t xcch_detect(uint32_t fn, uint8_t *subchan)
{
uint8_t type = UNKNOWN;
uint8_t fn_mod = fn % 51;
uint8_t msg_mod = fn_mod % 4;
uint8_t sacch_sub = ((fn % 102) >= 51) ? 4 : 0;
*subchan = 0;
/* IDLE */
if (fn_mod > 47)
return type;
/* burst in the middle */
if (msg_mod)
return type;
/* XCCH */
if (fn_mod < 32) {
type = SDCCH;
*subchan = fn_mod / 4;
} else {
type = SACCH;
*subchan = (fn_mod - 32) / 4 + sacch_sub;
}
return type;
}
uint8_t chan_detect(uint32_t fn, uint8_t ts, uint8_t combined, uint8_t *subchan)
{
uint8_t type;
uint8_t sub;
if (ts == 0) {
type = bcch_detect(fn, combined, &sub);
} else {
type = xcch_detect(fn, &sub);
}
if (type & BCCH)
fprintf(stderr, "BCCH");
if (type & CCCH)
fprintf(stderr, "CCCH");
if (type & SDCCH)
fprintf(stderr, "SDCCH");
if (type & SACCH)
fprintf(stderr, "SACCH");
if (subchan)
*subchan = sub;
return type;
}