blob: a97225c522d6b92492d432299394fba5d6d1ec35 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gsm_04_08.h
2 * GSM TS 04.08 definitions. */
3
Sylvain Munaut12ba7782014-06-16 10:13:40 +02004#pragma once
Harald Welteec8b4502010-02-20 20:34:29 +01005
6#include <stdint.h>
Maxfe65fa72016-05-10 17:17:05 +02007#include <stdbool.h>
Harald Welteec8b4502010-02-20 20:34:29 +01008
Maxfb348ee2016-03-30 21:14:53 +02009#include <osmocom/core/utils.h>
Ruben Undheim720ac4a2016-05-27 22:03:59 +020010#include <osmocom/core/endian.h>
11
Harald Welteec8b4502010-02-20 20:34:29 +010012struct gsm_lchan;
13
Andreas Eversberg014cb872010-07-12 09:11:00 +020014/* Chapter 10.5.1.5 */
Harald Welteec8b4502010-02-20 20:34:29 +010015struct gsm48_classmark1 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +010016#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +020017 uint8_t pwr_lev:3,
Harald Welteec8b4502010-02-20 20:34:29 +010018 a5_1:1,
Andreas Eversberg014cb872010-07-12 09:11:00 +020019 es_ind:1,
20 rev_lev:2,
21 spare:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +010022#elif OSMO_IS_BIG_ENDIAN
23/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
24 uint8_t spare:1, rev_lev:2, es_ind:1, a5_1:1, pwr_lev:3;
25#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +020026} __attribute__ ((packed));
27
28/* Chapter 10.5.1.6 */
29struct gsm48_classmark2 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +010030#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +020031 uint8_t pwr_lev:3,
32 a5_1:1,
33 es_ind:1,
34 rev_lev:2,
35 spare:1;
36 uint8_t fc:1,
37 vgcs:1,
38 vbs:1,
39 sm_cap:1,
40 ss_scr:2,
41 ps_cap:1,
42 spare2:1;
43 uint8_t a5_2:1,
44 a5_3:1,
45 cmsp:1,
46 solsa:1,
47 spare3:1,
48 lcsva_cap:1,
49 spare4:1,
50 cm3:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +010051#elif OSMO_IS_BIG_ENDIAN
52/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
53 uint8_t spare:1, rev_lev:2, es_ind:1, a5_1:1, pwr_lev:3;
54 uint8_t spare2:1, ps_cap:1, ss_scr:2, sm_cap:1, vbs:1, vgcs:1, fc:1;
55 uint8_t cm3:1, spare4:1, lcsva_cap:1, spare3:1, solsa:1, cmsp:1, a5_3:1, a5_2:1;
56#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +020057} __attribute__ ((packed));
58
59/* Chapter 10.5.2.1b.3 */
Ruben Undheim720ac4a2016-05-27 22:03:59 +020060#if OSMO_IS_LITTLE_ENDIAN == 1
Andreas Eversberg014cb872010-07-12 09:11:00 +020061struct gsm48_range_1024 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +010062#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +020063 uint8_t w1_hi:2,
64 f0:1,
65 form_id:5;
66 uint8_t w1_lo;
67 uint8_t w2_hi;
68 uint8_t w3_hi:7,
69 w2_lo:1;
70 uint8_t w4_hi:6,
71 w3_lo:2;
72 uint8_t w5_hi:6,
73 w4_lo:2;
74 uint8_t w6_hi:6,
75 w5_lo:2;
76 uint8_t w7_hi:6,
77 w6_lo:2;
78 uint8_t w8_hi:6,
79 w7_lo:2;
80 uint8_t w9:7,
81 w8_lo:1;
82 uint8_t w11_hi:1,
83 w10:7;
84 uint8_t w12_hi:2,
85 w11_lo:6;
86 uint8_t w13_hi:3,
87 w12_lo:5;
88 uint8_t w14_hi:4,
89 w13_lo:4;
90 uint8_t w15_hi:5,
91 w14_lo:3;
92 uint8_t w16:6,
93 w15_lo:2;
Neels Hofmeyrb2600392018-11-16 00:20:39 +010094#elif OSMO_IS_BIG_ENDIAN
95/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
96 uint8_t form_id:5, f0:1, w1_hi:2;
97 uint8_t w1_lo;
98 uint8_t w2_hi;
99 uint8_t w2_lo:1, w3_hi:7;
100 uint8_t w3_lo:2, w4_hi:6;
101 uint8_t w4_lo:2, w5_hi:6;
102 uint8_t w5_lo:2, w6_hi:6;
103 uint8_t w6_lo:2, w7_hi:6;
104 uint8_t w7_lo:2, w8_hi:6;
105 uint8_t w8_lo:1, w9:7;
106 uint8_t w10:7, w11_hi:1;
107 uint8_t w11_lo:6, w12_hi:2;
108 uint8_t w12_lo:5, w13_hi:3;
109 uint8_t w13_lo:4, w14_hi:4;
110 uint8_t w14_lo:3, w15_hi:5;
111 uint8_t w15_lo:2, w16:6;
112#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200113} __attribute__ ((packed));
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200114#else
115struct gsm48_range_1024 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100116#if OSMO_IS_LITTLE_ENDIAN
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200117 uint8_t form_id:5,
118 f0:1,
119 w1_hi:2;
120 uint8_t w1_lo;
121 uint8_t w2_hi;
122 uint8_t w2_lo:1,
123 w3_hi:7;
124 uint8_t w3_lo:2,
125 w4_hi:6;
126 uint8_t w4_lo:2,
127 w5_hi:6;
128 uint8_t w5_lo:2,
129 w6_hi:6;
130 uint8_t w6_lo:2,
131 w7_hi:6;
132 uint8_t w7_lo:2,
133 w8_hi:6;
134 uint8_t w8_lo:1,
135 w9:7;
136 uint8_t w10:7,
137 w11_hi:1;
138 uint8_t w11_lo:6,
139 w12_hi:2;
140 uint8_t w12_lo:5,
141 w13_hi:3;
142 uint8_t w13_lo:4,
143 w14_hi:4;
144 uint8_t w14_lo:3,
145 w15_hi:5;
146 uint8_t w15_lo:2,
147 w16:6;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100148#elif OSMO_IS_BIG_ENDIAN
149/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
150 uint8_t w1_hi:2, f0:1, form_id:5;
151 uint8_t w1_lo;
152 uint8_t w2_hi;
153 uint8_t w3_hi:7, w2_lo:1;
154 uint8_t w4_hi:6, w3_lo:2;
155 uint8_t w5_hi:6, w4_lo:2;
156 uint8_t w6_hi:6, w5_lo:2;
157 uint8_t w7_hi:6, w6_lo:2;
158 uint8_t w8_hi:6, w7_lo:2;
159 uint8_t w9:7, w8_lo:1;
160 uint8_t w11_hi:1, w10:7;
161 uint8_t w12_hi:2, w11_lo:6;
162 uint8_t w13_hi:3, w12_lo:5;
163 uint8_t w14_hi:4, w13_lo:4;
164 uint8_t w15_hi:5, w14_lo:3;
165 uint8_t w16:6, w15_lo:2;
166#endif
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200167} __attribute__ ((packed));
168#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200169
170/* Chapter 10.5.2.1b.4 */
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200171#if OSMO_IS_LITTLE_ENDIAN == 1
Andreas Eversberg014cb872010-07-12 09:11:00 +0200172struct gsm48_range_512 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100173#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200174 uint8_t orig_arfcn_hi:1,
175 form_id:7;
176 uint8_t orig_arfcn_mid;
177 uint8_t w1_hi:7,
178 orig_arfcn_lo:1;
179 uint8_t w2_hi:6,
180 w1_lo:2;
181 uint8_t w3_hi:6,
182 w2_lo:2;
183 uint8_t w4_hi:6,
184 w3_lo:2;
185 uint8_t w5:7,
186 w4_lo:1;
187 uint8_t w7_hi:1,
188 w6:7;
189 uint8_t w8_hi:2,
190 w7_lo:6;
191 uint8_t w9_hi:4,
192 w8_lo:4;
193 uint8_t w10:6,
194 w9_lo:2;
195 uint8_t w12_hi:2,
196 w11:6;
197 uint8_t w13_hi:4,
198 w12_lo:4;
199 uint8_t w14:6,
200 w13_lo:2;
201 uint8_t w16_hi:2,
202 w15:6;
203 uint8_t w17:5,
204 w16_lo:3;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100205#elif OSMO_IS_BIG_ENDIAN
206/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
207 uint8_t form_id:7, orig_arfcn_hi:1;
208 uint8_t orig_arfcn_mid;
209 uint8_t orig_arfcn_lo:1, w1_hi:7;
210 uint8_t w1_lo:2, w2_hi:6;
211 uint8_t w2_lo:2, w3_hi:6;
212 uint8_t w3_lo:2, w4_hi:6;
213 uint8_t w4_lo:1, w5:7;
214 uint8_t w6:7, w7_hi:1;
215 uint8_t w7_lo:6, w8_hi:2;
216 uint8_t w8_lo:4, w9_hi:4;
217 uint8_t w9_lo:2, w10:6;
218 uint8_t w11:6, w12_hi:2;
219 uint8_t w12_lo:4, w13_hi:4;
220 uint8_t w13_lo:2, w14:6;
221 uint8_t w15:6, w16_hi:2;
222 uint8_t w16_lo:3, w17:5;
223#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200224} __attribute__ ((packed));
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200225#else
226struct gsm48_range_512 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100227#if OSMO_IS_LITTLE_ENDIAN
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200228 uint8_t form_id:7,
229 orig_arfcn_hi:1;
230 uint8_t orig_arfcn_mid;
231 uint8_t orig_arfcn_lo:1,
232 w1_hi:7;
233 uint8_t w1_lo:2,
234 w2_hi:6;
235 uint8_t w2_lo:2,
236 w3_hi:6;
237 uint8_t w3_lo:2,
238 w4_hi:6;
239 uint8_t w4_lo:1,
240 w5:7;
241 uint8_t w6:7,
242 w7_hi:1;
243 uint8_t w7_lo:6,
244 w8_hi:2;
245 uint8_t w8_lo:4,
246 w9_hi:4;
247 uint8_t w9_lo:2,
248 w10:6;
249 uint8_t w11:6,
250 w12_hi:2;
251 uint8_t w12_lo:4,
252 w13_hi:4;
253 uint8_t w13_lo:2,
254 w14:6;
255 uint8_t w15:6,
256 w16_hi:2;
257 uint8_t w16_lo:3,
258 w17:5;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100259#elif OSMO_IS_BIG_ENDIAN
260/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
261 uint8_t orig_arfcn_hi:1, form_id:7;
262 uint8_t orig_arfcn_mid;
263 uint8_t w1_hi:7, orig_arfcn_lo:1;
264 uint8_t w2_hi:6, w1_lo:2;
265 uint8_t w3_hi:6, w2_lo:2;
266 uint8_t w4_hi:6, w3_lo:2;
267 uint8_t w5:7, w4_lo:1;
268 uint8_t w7_hi:1, w6:7;
269 uint8_t w8_hi:2, w7_lo:6;
270 uint8_t w9_hi:4, w8_lo:4;
271 uint8_t w10:6, w9_lo:2;
272 uint8_t w12_hi:2, w11:6;
273 uint8_t w13_hi:4, w12_lo:4;
274 uint8_t w14:6, w13_lo:2;
275 uint8_t w16_hi:2, w15:6;
276 uint8_t w17:5, w16_lo:3;
277#endif
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200278} __attribute__ ((packed));
279#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200280
281/* Chapter 10.5.2.1b.5 */
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200282#if OSMO_IS_LITTLE_ENDIAN == 1
Andreas Eversberg014cb872010-07-12 09:11:00 +0200283struct gsm48_range_256 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100284#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200285 uint8_t orig_arfcn_hi:1,
286 form_id:7;
287 uint8_t orig_arfcn_mid;
288 uint8_t w1_hi:7,
289 orig_arfcn_lo:1;
290 uint8_t w2:7,
291 w1_lo:1;
292 uint8_t w4_hi:1,
293 w3:7;
294 uint8_t w5_hi:3,
295 w4_lo:5;
296 uint8_t w6_hi:5,
297 w5_lo:3;
298 uint8_t w8_hi:1,
299 w7:6,
300 w6_lo:1;
301 uint8_t w9_hi:4,
302 w8_lo:4;
303 uint8_t w11_hi:2,
304 w10:5,
305 w9_lo:1;
306 uint8_t w12:5,
307 w11_lo:3;
308 uint8_t w14_hi:3,
309 w13:5;
310 uint8_t w16_hi:1,
311 w15:5,
312 w14_lo:2;
313 uint8_t w18_hi:1,
314 w17:4,
315 w16_lo:3;
316 uint8_t w20_hi:1,
317 w19:4,
318 w18_lo:3;
319 uint8_t spare:1,
320 w21:4,
321 w20_lo:3;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100322#elif OSMO_IS_BIG_ENDIAN
323/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
324 uint8_t form_id:7, orig_arfcn_hi:1;
325 uint8_t orig_arfcn_mid;
326 uint8_t orig_arfcn_lo:1, w1_hi:7;
327 uint8_t w1_lo:1, w2:7;
328 uint8_t w3:7, w4_hi:1;
329 uint8_t w4_lo:5, w5_hi:3;
330 uint8_t w5_lo:3, w6_hi:5;
331 uint8_t w6_lo:1, w7:6, w8_hi:1;
332 uint8_t w8_lo:4, w9_hi:4;
333 uint8_t w9_lo:1, w10:5, w11_hi:2;
334 uint8_t w11_lo:3, w12:5;
335 uint8_t w13:5, w14_hi:3;
336 uint8_t w14_lo:2, w15:5, w16_hi:1;
337 uint8_t w16_lo:3, w17:4, w18_hi:1;
338 uint8_t w18_lo:3, w19:4, w20_hi:1;
339 uint8_t w20_lo:3, w21:4, spare:1;
340#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200341} __attribute__ ((packed));
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200342#else
343struct gsm48_range_256 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100344#if OSMO_IS_LITTLE_ENDIAN
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200345 uint8_t form_id:7,
346 orig_arfcn_hi:1;
347 uint8_t orig_arfcn_mid;
348 uint8_t orig_arfcn_lo:1,
349 w1_hi:7;
350 uint8_t w1_lo:1,
351 w2:7;
352 uint8_t w3:7,
353 w4_hi:1;
354 uint8_t w4_lo:5,
355 w5_hi:3;
356 uint8_t w5_lo:3,
357 w6_hi:5;
358 uint8_t w6_lo:1,
359 w7:6,
360 w8_hi:1;
361 uint8_t w8_lo:4,
362 w9_hi:4;
363 uint8_t w9_lo:1,
364 w10:5,
365 w11_hi:2;
366 uint8_t w11_lo:3,
367 w12:5;
368 uint8_t w13:5,
369 w14_hi:3;
370 uint8_t w14_lo:2,
371 w15:5,
372 w16_hi:1;
373 uint8_t w16_lo:3,
374 w17:4,
375 w18_hi:1;
376 uint8_t w18_lo:3,
377 w19:4,
378 w20_hi:1;
379 uint8_t w20_lo:3,
380 w21:4,
381 spare:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100382#elif OSMO_IS_BIG_ENDIAN
383/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
384 uint8_t orig_arfcn_hi:1, form_id:7;
385 uint8_t orig_arfcn_mid;
386 uint8_t w1_hi:7, orig_arfcn_lo:1;
387 uint8_t w2:7, w1_lo:1;
388 uint8_t w4_hi:1, w3:7;
389 uint8_t w5_hi:3, w4_lo:5;
390 uint8_t w6_hi:5, w5_lo:3;
391 uint8_t w8_hi:1, w7:6, w6_lo:1;
392 uint8_t w9_hi:4, w8_lo:4;
393 uint8_t w11_hi:2, w10:5, w9_lo:1;
394 uint8_t w12:5, w11_lo:3;
395 uint8_t w14_hi:3, w13:5;
396 uint8_t w16_hi:1, w15:5, w14_lo:2;
397 uint8_t w18_hi:1, w17:4, w16_lo:3;
398 uint8_t w20_hi:1, w19:4, w18_lo:3;
399 uint8_t spare:1, w21:4, w20_lo:3;
400#endif
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200401} __attribute__ ((packed));
402#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200403
404/* Chapter 10.5.2.1b.6 */
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200405#if OSMO_IS_LITTLE_ENDIAN == 1
Andreas Eversberg014cb872010-07-12 09:11:00 +0200406struct gsm48_range_128 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100407#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200408 uint8_t orig_arfcn_hi:1,
409 form_id:7;
410 uint8_t orig_arfcn_mid;
411 uint8_t w1:7,
412 orig_arfcn_lo:1;
413 uint8_t w3_hi:2,
414 w2:6;
415 uint8_t w4_hi:4,
416 w3_lo:4;
417 uint8_t w6_hi:2,
418 w5:5,
419 w4_lo:1;
420 uint8_t w7:5,
421 w6_lo:3;
422 uint8_t w9:4,
423 w8:4;
424 uint8_t w11:4,
425 w10:4;
426 uint8_t w13:4,
427 w12:4;
428 uint8_t w15:4,
429 w14:4;
430 uint8_t w18_hi:2,
431 w17:3,
432 w16:3;
433 uint8_t w21_hi:1,
434 w20:3,
435 w19:3,
436 w18_lo:1;
437 uint8_t w23:3,
438 w22:3,
439 w21_lo:2;
440 uint8_t w26_hi:2,
441 w25:3,
442 w24:3;
443 uint8_t spare:1,
444 w28:3,
445 w27:3,
446 w26_lo:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100447#elif OSMO_IS_BIG_ENDIAN
448/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
449 uint8_t form_id:7, orig_arfcn_hi:1;
450 uint8_t orig_arfcn_mid;
451 uint8_t orig_arfcn_lo:1, w1:7;
452 uint8_t w2:6, w3_hi:2;
453 uint8_t w3_lo:4, w4_hi:4;
454 uint8_t w4_lo:1, w5:5, w6_hi:2;
455 uint8_t w6_lo:3, w7:5;
456 uint8_t w8:4, w9:4;
457 uint8_t w10:4, w11:4;
458 uint8_t w12:4, w13:4;
459 uint8_t w14:4, w15:4;
460 uint8_t w16:3, w17:3, w18_hi:2;
461 uint8_t w18_lo:1, w19:3, w20:3, w21_hi:1;
462 uint8_t w21_lo:2, w22:3, w23:3;
463 uint8_t w24:3, w25:3, w26_hi:2;
464 uint8_t w26_lo:1, w27:3, w28:3, spare:1;
465#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200466} __attribute__ ((packed));
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200467#else
468struct gsm48_range_128 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100469#if OSMO_IS_LITTLE_ENDIAN
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200470 uint8_t form_id:7,
471 orig_arfcn_hi:1;
472 uint8_t orig_arfcn_mid;
473 uint8_t orig_arfcn_lo:1,
474 w1:7;
475 uint8_t w2:6,
476 w3_hi:2;
477 uint8_t w3_lo:4,
478 w4_hi:4;
479 uint8_t w4_lo:1,
480 w5:5,
481 w6_hi:2;
482 uint8_t w6_lo:3,
483 w7:5;
484 uint8_t w8:4,
485 w9:4;
486 uint8_t w10:4,
487 w11:4;
488 uint8_t w12:4,
489 w13:4;
490 uint8_t w14:4,
491 w15:4;
492 uint8_t w16:3,
493 w17:3,
494 w18_hi:2;
495 uint8_t w18_lo:1,
496 w19:3,
497 w20:3,
498 w21_hi:1;
499 uint8_t w21_lo:2,
500 w22:3,
501 w23:3;
502 uint8_t w24:3,
503 w25:3,
504 w26_hi:2;
505 uint8_t w26_lo:1,
506 w27:3,
507 w28:3,
508 spare:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100509#elif OSMO_IS_BIG_ENDIAN
510/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
511 uint8_t orig_arfcn_hi:1, form_id:7;
512 uint8_t orig_arfcn_mid;
513 uint8_t w1:7, orig_arfcn_lo:1;
514 uint8_t w3_hi:2, w2:6;
515 uint8_t w4_hi:4, w3_lo:4;
516 uint8_t w6_hi:2, w5:5, w4_lo:1;
517 uint8_t w7:5, w6_lo:3;
518 uint8_t w9:4, w8:4;
519 uint8_t w11:4, w10:4;
520 uint8_t w13:4, w12:4;
521 uint8_t w15:4, w14:4;
522 uint8_t w18_hi:2, w17:3, w16:3;
523 uint8_t w21_hi:1, w20:3, w19:3, w18_lo:1;
524 uint8_t w23:3, w22:3, w21_lo:2;
525 uint8_t w26_hi:2, w25:3, w24:3;
526 uint8_t spare:1, w28:3, w27:3, w26_lo:1;
527#endif
Ruben Undheim720ac4a2016-05-27 22:03:59 +0200528} __attribute__ ((packed));
529#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200530
531/* Chapter 10.5.2.1b.7 */
532struct gsm48_var_bit {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100533#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200534 uint8_t orig_arfcn_hi:1,
535 form_id:7;
536 uint8_t orig_arfcn_mid;
537 uint8_t rrfcn1_7:7,
538 orig_arfcn_lo:1;
539 uint8_t rrfcn8_111[13];
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100540#elif OSMO_IS_BIG_ENDIAN
541/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
542 uint8_t form_id:7, orig_arfcn_hi:1;
543 uint8_t orig_arfcn_mid;
544 uint8_t orig_arfcn_lo:1, rrfcn1_7:7;
545 uint8_t rrfcn8_111[13];
546#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100547} __attribute__ ((packed));
548
549/* Chapter 10.5.2.5 */
550struct gsm48_chan_desc {
551 uint8_t chan_nr;
552 union {
553 struct {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100554#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100555 uint8_t maio_high:4,
556 h:1,
557 tsc:3;
558 uint8_t hsn:6,
559 maio_low:2;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100560#elif OSMO_IS_BIG_ENDIAN
561/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
562 uint8_t tsc:3, h:1, maio_high:4;
563 uint8_t maio_low:2, hsn:6;
564#endif
Andreas Eversberg4b332d72012-02-07 20:02:17 +0100565 } __attribute__ ((packed)) h1;
Harald Welteec8b4502010-02-20 20:34:29 +0100566 struct {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100567#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100568 uint8_t arfcn_high:2,
569 spare:2,
570 h:1,
571 tsc:3;
572 uint8_t arfcn_low;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100573#elif OSMO_IS_BIG_ENDIAN
574/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
575 uint8_t tsc:3, h:1, spare:2, arfcn_high:2;
576 uint8_t arfcn_low;
577#endif
Andreas Eversberg4b332d72012-02-07 20:02:17 +0100578 } __attribute__ ((packed)) h0;
579 } __attribute__ ((packed));
Harald Welteec8b4502010-02-20 20:34:29 +0100580} __attribute__ ((packed));
581
Andreas Eversberg014cb872010-07-12 09:11:00 +0200582/* Chapter 10.5.2.20 */
583struct gsm48_meas_res {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100584#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200585 uint8_t rxlev_full:6,
586 dtx_used:1,
587 ba_used:1;
588 uint8_t rxlev_sub:6,
589 meas_valid:1,
590 spare:1;
591 uint8_t no_nc_n_hi:1,
592 rxqual_sub:3,
593 rxqual_full:3,
594 spare2:1;
595 uint8_t rxlev_nc1:6,
596 no_nc_n_lo:2;
597 uint8_t bsic_nc1_hi:3,
598 bcch_f_nc1:5;
599 uint8_t rxlev_nc2_hi:5,
600 bsic_nc1_lo:3;
601 uint8_t bsic_nc2_hi:2,
602 bcch_f_nc2:5,
603 rxlev_nc2_lo:1;
604 uint8_t rxlev_nc3_hi:4,
605 bsic_nc2_lo:4;
606 uint8_t bsic_nc3_hi:1,
607 bcch_f_nc3:5,
608 rxlev_nc3_lo:2;
609 uint8_t rxlev_nc4_hi:3,
610 bsic_nc3_lo:5;
611 uint8_t bcch_f_nc4:5,
612 rxlev_nc4_lo:3;
613 uint8_t rxlev_nc5_hi:2,
614 bsic_nc4:6;
615 uint8_t bcch_f_nc5_hi:4,
616 rxlev_nc5_lo:4;
617 uint8_t rxlev_nc6_hi:1,
618 bsic_nc5:6,
619 bcch_f_nc5_lo:1;
620 uint8_t bcch_f_nc6_hi:3,
621 rxlev_nc6_lo:5;
622 uint8_t bsic_nc6:6,
623 bcch_f_nc6_lo:2;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100624#elif OSMO_IS_BIG_ENDIAN
625/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
626 uint8_t ba_used:1, dtx_used:1, rxlev_full:6;
627 uint8_t spare:1, meas_valid:1, rxlev_sub:6;
628 uint8_t spare2:1, rxqual_full:3, rxqual_sub:3, no_nc_n_hi:1;
629 uint8_t no_nc_n_lo:2, rxlev_nc1:6;
630 uint8_t bcch_f_nc1:5, bsic_nc1_hi:3;
631 uint8_t bsic_nc1_lo:3, rxlev_nc2_hi:5;
632 uint8_t rxlev_nc2_lo:1, bcch_f_nc2:5, bsic_nc2_hi:2;
633 uint8_t bsic_nc2_lo:4, rxlev_nc3_hi:4;
634 uint8_t rxlev_nc3_lo:2, bcch_f_nc3:5, bsic_nc3_hi:1;
635 uint8_t bsic_nc3_lo:5, rxlev_nc4_hi:3;
636 uint8_t rxlev_nc4_lo:3, bcch_f_nc4:5;
637 uint8_t bsic_nc4:6, rxlev_nc5_hi:2;
638 uint8_t rxlev_nc5_lo:4, bcch_f_nc5_hi:4;
639 uint8_t bcch_f_nc5_lo:1, bsic_nc5:6, rxlev_nc6_hi:1;
640 uint8_t rxlev_nc6_lo:5, bcch_f_nc6_hi:3;
641 uint8_t bcch_f_nc6_lo:2, bsic_nc6:6;
642#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200643} __attribute__ ((packed));
644
Harald Welteec8b4502010-02-20 20:34:29 +0100645/* Chapter 10.5.2.21aa */
646struct gsm48_multi_rate_conf {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100647#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100648 uint8_t smod : 2,
649 spare: 1,
650 icmi : 1,
651 nscb : 1,
652 ver : 3;
653 uint8_t m4_75 : 1,
654 m5_15 : 1,
655 m5_90 : 1,
656 m6_70 : 1,
657 m7_40 : 1,
658 m7_95 : 1,
659 m10_2 : 1,
660 m12_2 : 1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100661#elif OSMO_IS_BIG_ENDIAN
662/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
663 uint8_t ver:3, nscb:1, icmi:1, spare:1, smod:2;
664 uint8_t m12_2:1, m10_2:1, m7_95:1, m7_40:1, m6_70:1, m5_90:1, m5_15:1, m4_75:1;
665#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100666} __attribute__((packed));
667
Andreas Eversberg014cb872010-07-12 09:11:00 +0200668/* Chapter 10.5.2.28(a) */
669struct gsm48_power_cmd {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100670#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200671 uint8_t power_level:5,
672 spare:2,
673 atc:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100674#elif OSMO_IS_BIG_ENDIAN
675/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
676 uint8_t atc:1, spare:2, power_level:5;
677#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200678} __attribute__((packed));
679
680/* Chapter 10.5.2.29 */
681struct gsm48_rach_control {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100682#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200683 uint8_t re :1,
684 cell_bar :1,
685 tx_integer :4,
686 max_trans :2;
Stefan Sperling18595152018-02-06 13:20:23 +0100687 uint8_t t2; /* ACC 8-15 barred flags */
688 uint8_t t3; /* ACC 0-7 barred flags */
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100689#elif OSMO_IS_BIG_ENDIAN
690/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
691 uint8_t max_trans:2, tx_integer:4, cell_bar:1, re:1;
692 uint8_t t2;
693 uint8_t t3;
694#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200695} __attribute__ ((packed));
696
Stefan Sperling18595152018-02-06 13:20:23 +0100697/*
698 * Mark an Access Control Class as barred.
699 * \param[in] rach_control A Rach Control Information Element.
700 * \param[in] acc Access Control Class number (0 - 15) which shall be barred.
701 */
702static inline void gsm48_barr_acc(struct gsm48_rach_control *rach_control, unsigned int acc)
703{
704 OSMO_ASSERT(acc >= 0 && acc <= 15);
705 if (acc >= 8)
706 rach_control->t2 |= (1 << (acc - 8));
707 else
708 rach_control->t3 |= (1 << (acc));
709}
710
711/*
712 * Mark an Access Control Class as allowed.
713 * \param[in] rach_control A Rach Control Information Element.
714 * \param[in] acc Access Control Class number (0 - 15) which shall be allowed.
715 */
716static inline void gsm48_allow_acc(struct gsm48_rach_control *rach_control, unsigned int acc)
717{
718 OSMO_ASSERT(acc >= 0 && acc <= 15);
719 if (acc >= 8)
720 rach_control->t2 &= ~(1 << (acc - 8));
721 else
722 rach_control->t3 &= ~(1 << (acc));
723}
724
725/*
726 * Indicate whether an Access Control Class is barred.
727 * \param[in] rach_control A Rach Control Information Element.
728 * \param[in] acc Access Control Class number (0 - 15).
729 * \returns true if the Access Control class is barred, false otherwise
730 */
731static inline bool gsm48_acc_is_barred(struct gsm48_rach_control *rach_control, unsigned int acc)
732{
733 OSMO_ASSERT(acc >= 0 && acc <= 15);
734 if (acc >= 8)
735 return (rach_control->t2 & (1 << (acc - 8))) != 0;
736 return (rach_control->t3 & (1 << (acc))) != 0;
737}
Andreas Eversberg014cb872010-07-12 09:11:00 +0200738
Harald Welteec8b4502010-02-20 20:34:29 +0100739/* Chapter 10.5.2.30 */
740struct gsm48_req_ref {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100741#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100742 uint8_t ra;
743 uint8_t t3_high:3,
Andreas Eversberg93364fc2010-06-25 02:50:06 +0200744 t1:5;
Harald Welteec8b4502010-02-20 20:34:29 +0100745 uint8_t t2:5,
746 t3_low:3;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100747#elif OSMO_IS_BIG_ENDIAN
748/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
749 uint8_t ra;
750 uint8_t t1:5, t3_high:3;
751 uint8_t t3_low:3, t2:5;
752#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100753} __attribute__ ((packed));
754
Andreas Eversberg014cb872010-07-12 09:11:00 +0200755/* Chapter 10.5.2.38 */
756struct gsm48_start_time {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100757#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200758 uint8_t t3_high:3,
759 t1:5;
760 uint8_t t2:5,
761 t3_low:3;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100762#elif OSMO_IS_BIG_ENDIAN
763/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
764 uint8_t t1:5, t3_high:3;
765 uint8_t t3_low:3, t2:5;
766#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200767} __attribute__ ((packed));
768
769/* Chapter 10.5.2.39 */
770struct gsm48_sync_ind {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100771#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +0200772 uint8_t si:2,
773 rot:1,
774 nci:1,
775 sync_ie:4;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100776#elif OSMO_IS_BIG_ENDIAN
777/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
778 uint8_t sync_ie:4, nci:1, rot:1, si:2;
779#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +0200780} __attribute__((packed));
781
Harald Welteec8b4502010-02-20 20:34:29 +0100782/*
783 * Chapter 9.1.5/9.1.6
784 *
785 * For 9.1.6 the chan_desc has the meaning of 10.5.2.5a
786 */
787struct gsm48_chan_mode_modify {
788 struct gsm48_chan_desc chan_desc;
789 uint8_t mode;
790} __attribute__ ((packed));
791
792enum gsm48_chan_mode {
793 GSM48_CMODE_SIGN = 0x00,
794 GSM48_CMODE_SPEECH_V1 = 0x01,
795 GSM48_CMODE_SPEECH_EFR = 0x21,
796 GSM48_CMODE_SPEECH_AMR = 0x41,
797 GSM48_CMODE_DATA_14k5 = 0x0f,
798 GSM48_CMODE_DATA_12k0 = 0x03,
799 GSM48_CMODE_DATA_6k0 = 0x0b,
Bhaskar31e844b2013-05-16 17:06:35 +0530800 GSM48_CMODE_DATA_3k6 = 0x13,
Harald Welteec8b4502010-02-20 20:34:29 +0100801};
802
Maxfb348ee2016-03-30 21:14:53 +0200803extern const struct value_string gsm48_chan_mode_names[];
Philipp Maier5796a212018-07-12 17:48:26 +0200804static inline const char *gsm48_chan_mode_name(enum gsm48_chan_mode val)
805{ return get_value_string(gsm48_chan_mode_names, val); }
Maxfb348ee2016-03-30 21:14:53 +0200806
Harald Welteec8b4502010-02-20 20:34:29 +0100807/* Chapter 9.1.2 */
808struct gsm48_ass_cmd {
809 /* Semantic is from 10.5.2.5a */
810 struct gsm48_chan_desc chan_desc;
811 uint8_t power_command;
812 uint8_t data[0];
813} __attribute__((packed));
814
Andreas Eversbergfa832012010-09-01 23:37:07 +0200815/* Chapter 9.1.13 */
816struct gsm48_frq_redef {
817 /* Semantic is from 10.5.2.5a */
818 struct gsm48_chan_desc chan_desc;
819 uint8_t mob_alloc_len;
820 uint8_t mob_alloc[0];
821} __attribute__((packed));
822
Harald Welte548e3712017-07-10 22:32:08 +0200823/* Chapter 9.1.13b GPRS suspension request */
824struct gsm48_gprs_susp_req {
825 uint32_t tlli;
826 uint8_t ra_id[6];
827 uint8_t cause;
828 uint8_t options[0];
829} __attribute__ ((packed));
830
Harald Welteec8b4502010-02-20 20:34:29 +0100831/* Chapter 10.5.2.2 */
832struct gsm48_cell_desc {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100833#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100834 uint8_t bcc:3,
835 ncc:3,
836 arfcn_hi:2;
837 uint8_t arfcn_lo;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100838#elif OSMO_IS_BIG_ENDIAN
839/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
840 uint8_t arfcn_hi:2, ncc:3, bcc:3;
841 uint8_t arfcn_lo;
842#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100843} __attribute__((packed));
844
845/* Chapter 9.1.15 */
846struct gsm48_ho_cmd {
847 struct gsm48_cell_desc cell_desc;
848 struct gsm48_chan_desc chan_desc;
849 uint8_t ho_ref;
850 uint8_t power_command;
851 uint8_t data[0];
852} __attribute__((packed));
853
854/* Chapter 9.1.18 */
855struct gsm48_imm_ass {
856 uint8_t l2_plen;
857 uint8_t proto_discr;
858 uint8_t msg_type;
859 uint8_t page_mode;
860 struct gsm48_chan_desc chan_desc;
861 struct gsm48_req_ref req_ref;
862 uint8_t timing_advance;
863 uint8_t mob_alloc_len;
864 uint8_t mob_alloc[0];
865} __attribute__ ((packed));
866
Holger Hans Peter Freyther5dcef3c2010-05-15 22:35:25 +0800867/* Chapter 9.1.25 */
868struct gsm48_pag_resp {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100869#if OSMO_IS_LITTLE_ENDIAN
Holger Hans Peter Freyther5dcef3c2010-05-15 22:35:25 +0800870 uint8_t spare:4,
871 key_seq:4;
872 uint32_t classmark2;
873 uint8_t mi_len;
874 uint8_t mi[0];
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100875#elif OSMO_IS_BIG_ENDIAN
876/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
877 uint8_t key_seq:4, spare:4;
878 uint32_t classmark2;
879 uint8_t mi_len;
880 uint8_t mi[0];
881#endif
Holger Hans Peter Freyther5dcef3c2010-05-15 22:35:25 +0800882} __attribute__ ((packed));
883
Harald Welteec8b4502010-02-20 20:34:29 +0100884/* Chapter 10.5.1.3 */
885struct gsm48_loc_area_id {
886 uint8_t digits[3]; /* BCD! */
887 uint16_t lac;
888} __attribute__ ((packed));
889
890/* Section 9.2.2 */
891struct gsm48_auth_req {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100892#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100893 uint8_t key_seq:4,
894 spare:4;
895 uint8_t rand[16];
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100896#elif OSMO_IS_BIG_ENDIAN
897/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
898 uint8_t spare:4, key_seq:4;
899 uint8_t rand[16];
900#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100901} __attribute__ ((packed));
902
Sylvain Munautd005eab2010-06-10 13:30:50 +0200903/* Section 9.2.3 */
904struct gsm48_auth_resp {
905 uint8_t sres[4];
906} __attribute__ ((packed));
907
Harald Welteec8b4502010-02-20 20:34:29 +0100908/* Section 9.2.15 */
909struct gsm48_loc_upd_req {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100910#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100911 uint8_t type:4,
912 key_seq:4;
913 struct gsm48_loc_area_id lai;
914 struct gsm48_classmark1 classmark1;
915 uint8_t mi_len;
916 uint8_t mi[0];
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100917#elif OSMO_IS_BIG_ENDIAN
918/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
919 uint8_t key_seq:4, type:4;
920 struct gsm48_loc_area_id lai;
921 struct gsm48_classmark1 classmark1;
922 uint8_t mi_len;
923 uint8_t mi[0];
924#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100925} __attribute__ ((packed));
926
927/* Section 10.1 */
928struct gsm48_hdr {
929 uint8_t proto_discr;
930 uint8_t msg_type;
931 uint8_t data[0];
932} __attribute__ ((packed));
933
934/* Section 9.1.3x System information Type header */
935struct gsm48_system_information_type_header {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100936#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100937 uint8_t l2_plen;
938 uint8_t rr_protocol_discriminator :4,
939 skip_indicator:4;
940 uint8_t system_information;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100941#elif OSMO_IS_BIG_ENDIAN
942/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
943 uint8_t l2_plen;
944 uint8_t skip_indicator:4, rr_protocol_discriminator:4;
945 uint8_t system_information;
946#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100947} __attribute__ ((packed));
948
Harald Welteec8b4502010-02-20 20:34:29 +0100949/* Section 10.5.2.4 Cell Selection Parameters */
950struct gsm48_cell_sel_par {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100951#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100952 uint8_t ms_txpwr_max_ccch:5, /* GSM 05.08 MS-TXPWR-MAX-CCCH */
953 cell_resel_hyst:3; /* GSM 05.08 CELL-RESELECT-HYSTERESIS */
954 uint8_t rxlev_acc_min:6, /* GSM 05.08 RXLEV-ACCESS-MIN */
955 neci:1,
956 acs:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100957#elif OSMO_IS_BIG_ENDIAN
958/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
959 uint8_t cell_resel_hyst:3, ms_txpwr_max_ccch:5;
960 uint8_t acs:1, neci:1, rxlev_acc_min:6;
961#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100962} __attribute__ ((packed));
963
Neels Hofmeyrd1c2fc62017-02-21 14:51:40 +0100964/* 3GPP TS 44.018 Section 10.5.2.11 Control Channel Description */
Harald Welteec8b4502010-02-20 20:34:29 +0100965struct gsm48_control_channel_descr {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100966#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100967 uint8_t ccch_conf :3,
968 bs_ag_blks_res :3,
969 att :1,
Neels Hofmeyrd1c2fc62017-02-21 14:51:40 +0100970 mscr :1;
Harald Welteec8b4502010-02-20 20:34:29 +0100971 uint8_t bs_pa_mfrms : 3,
Neels Hofmeyrd1c2fc62017-02-21 14:51:40 +0100972 spare_1 :2,
973 cbq3 :2,
974 spare_2 :1;
Harald Welteec8b4502010-02-20 20:34:29 +0100975 uint8_t t3212;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100976#elif OSMO_IS_BIG_ENDIAN
977/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
978 uint8_t mscr:1, att:1, bs_ag_blks_res:3, ccch_conf:3;
979 uint8_t spare_2:1, cbq3:2, spare_1:2, bs_pa_mfrms:3;
980 uint8_t t3212;
981#endif
Harald Welteec8b4502010-02-20 20:34:29 +0100982} __attribute__ ((packed));
983
Maxfe65fa72016-05-10 17:17:05 +0200984enum gsm48_dtx_mode {
985 GSM48_DTX_MAY_BE_USED,
986 GSM48_DTX_SHALL_BE_USED,
987 GSM48_DTX_SHALL_NOT_BE_USED
988};
989
990/* Cell Options for SI6, SACCH (10.5.2.3a.2) or SI3, BCCH (Table 10.5.2.3.1),
991 3GPP TS 44.018 */
Harald Welteec8b4502010-02-20 20:34:29 +0100992struct gsm48_cell_options {
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100993#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +0100994 uint8_t radio_link_timeout:4,
995 dtx:2,
996 pwrc:1,
Maxfe65fa72016-05-10 17:17:05 +0200997 /* either DN-IND or top bit of DTX IND */
998 d:1;
Neels Hofmeyrb2600392018-11-16 00:20:39 +0100999#elif OSMO_IS_BIG_ENDIAN
1000/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1001 uint8_t d:1, pwrc:1, dtx:2, radio_link_timeout:4;
1002#endif
Harald Welteec8b4502010-02-20 20:34:29 +01001003} __attribute__ ((packed));
1004
1005/* Section 9.2.9 CM service request */
1006struct gsm48_service_request {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001007#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +01001008 uint8_t cm_service_type : 4,
1009 cipher_key_seq : 4;
1010 /* length + 3 bytes */
1011 uint32_t classmark;
1012 uint8_t mi_len;
1013 uint8_t mi[0];
1014 /* optional priority level */
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001015#elif OSMO_IS_BIG_ENDIAN
1016/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1017 uint8_t cipher_key_seq:4, cm_service_type:4;
1018 uint32_t classmark;
1019 uint8_t mi_len;
1020 uint8_t mi[0];
1021#endif
Harald Welteec8b4502010-02-20 20:34:29 +01001022} __attribute__ ((packed));
1023
1024/* Section 9.1.31 System information Type 1 */
1025struct gsm48_system_information_type_1 {
1026 struct gsm48_system_information_type_header header;
1027 uint8_t cell_channel_description[16];
1028 struct gsm48_rach_control rach_control;
1029 uint8_t rest_octets[0]; /* NCH position on the CCCH */
1030} __attribute__ ((packed));
1031
1032/* Section 9.1.32 System information Type 2 */
1033struct gsm48_system_information_type_2 {
1034 struct gsm48_system_information_type_header header;
1035 uint8_t bcch_frequency_list[16];
1036 uint8_t ncc_permitted;
1037 struct gsm48_rach_control rach_control;
1038} __attribute__ ((packed));
1039
Andreas Eversberg014cb872010-07-12 09:11:00 +02001040/* Section 9.1.33 System information Type 2bis */
1041struct gsm48_system_information_type_2bis {
1042 struct gsm48_system_information_type_header header;
1043 uint8_t bcch_frequency_list[16];
1044 struct gsm48_rach_control rach_control;
1045 uint8_t rest_octets[0];
1046} __attribute__ ((packed));
1047
1048/* Section 9.1.34 System information Type 2ter */
1049struct gsm48_system_information_type_2ter {
1050 struct gsm48_system_information_type_header header;
1051 uint8_t ext_bcch_frequency_list[16];
1052 uint8_t rest_octets[0];
1053} __attribute__ ((packed));
1054
Maxe859aec2016-03-11 12:24:04 +01001055/* Section 9.1.34a System information Type 2quater */
1056struct gsm48_system_information_type_2quater {
1057 struct gsm48_system_information_type_header header;
1058 uint8_t rest_octets[0];
1059} __attribute__ ((packed));
1060
Harald Welteec8b4502010-02-20 20:34:29 +01001061/* Section 9.1.35 System information Type 3 */
1062struct gsm48_system_information_type_3 {
1063 struct gsm48_system_information_type_header header;
1064 uint16_t cell_identity;
1065 struct gsm48_loc_area_id lai;
1066 struct gsm48_control_channel_descr control_channel_desc;
1067 struct gsm48_cell_options cell_options;
1068 struct gsm48_cell_sel_par cell_sel_par;
1069 struct gsm48_rach_control rach_control;
1070 uint8_t rest_octets[0];
1071} __attribute__ ((packed));
1072
1073/* Section 9.1.36 System information Type 4 */
1074struct gsm48_system_information_type_4 {
1075 struct gsm48_system_information_type_header header;
1076 struct gsm48_loc_area_id lai;
1077 struct gsm48_cell_sel_par cell_sel_par;
1078 struct gsm48_rach_control rach_control;
1079 /* optional CBCH conditional CBCH... followed by
1080 mandantory SI 4 Reset Octets
1081 */
1082 uint8_t data[0];
1083} __attribute__ ((packed));
1084
1085/* Section 9.1.37 System information Type 5 */
1086struct gsm48_system_information_type_5 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001087#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +01001088 uint8_t rr_protocol_discriminator :4,
1089 skip_indicator:4;
1090 uint8_t system_information;
1091 uint8_t bcch_frequency_list[16];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001092#elif OSMO_IS_BIG_ENDIAN
1093/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1094 uint8_t skip_indicator:4, rr_protocol_discriminator:4;
1095 uint8_t system_information;
1096 uint8_t bcch_frequency_list[16];
1097#endif
Harald Welteec8b4502010-02-20 20:34:29 +01001098} __attribute__ ((packed));
1099
Andreas Eversberg014cb872010-07-12 09:11:00 +02001100/* Section 9.1.38 System information Type 5bis */
1101struct gsm48_system_information_type_5bis {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001102#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +02001103 uint8_t rr_protocol_discriminator :4,
1104 skip_indicator:4;
1105 uint8_t system_information;
1106 uint8_t bcch_frequency_list[16];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001107#elif OSMO_IS_BIG_ENDIAN
1108/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1109 uint8_t skip_indicator:4, rr_protocol_discriminator:4;
1110 uint8_t system_information;
1111 uint8_t bcch_frequency_list[16];
1112#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +02001113} __attribute__ ((packed));
1114
1115/* Section 9.1.39 System information Type 5ter */
1116struct gsm48_system_information_type_5ter {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001117#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +02001118 uint8_t rr_protocol_discriminator :4,
1119 skip_indicator:4;
1120 uint8_t system_information;
1121 uint8_t bcch_frequency_list[16];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001122#elif OSMO_IS_BIG_ENDIAN
1123/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1124 uint8_t skip_indicator:4, rr_protocol_discriminator:4;
1125 uint8_t system_information;
1126 uint8_t bcch_frequency_list[16];
1127#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +02001128} __attribute__ ((packed));
1129
Harald Welteec8b4502010-02-20 20:34:29 +01001130/* Section 9.1.40 System information Type 6 */
1131struct gsm48_system_information_type_6 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001132#if OSMO_IS_LITTLE_ENDIAN
Harald Welteec8b4502010-02-20 20:34:29 +01001133 uint8_t rr_protocol_discriminator :4,
1134 skip_indicator:4;
1135 uint8_t system_information;
1136 uint16_t cell_identity;
1137 struct gsm48_loc_area_id lai;
1138 struct gsm48_cell_options cell_options;
1139 uint8_t ncc_permitted;
1140 uint8_t rest_octets[0];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001141#elif OSMO_IS_BIG_ENDIAN
1142/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1143 uint8_t skip_indicator:4, rr_protocol_discriminator:4;
1144 uint8_t system_information;
1145 uint16_t cell_identity;
1146 struct gsm48_loc_area_id lai;
1147 struct gsm48_cell_options cell_options;
1148 uint8_t ncc_permitted;
1149 uint8_t rest_octets[0];
1150#endif
Harald Welteec8b4502010-02-20 20:34:29 +01001151} __attribute__ ((packed));
1152
1153/* Section 9.1.43a System Information type 13 */
1154struct gsm48_system_information_type_13 {
1155 struct gsm48_system_information_type_header header;
1156 uint8_t rest_octets[0];
1157} __attribute__ ((packed));
1158
1159/* Section 9.2.12 IMSI Detach Indication */
1160struct gsm48_imsi_detach_ind {
1161 struct gsm48_classmark1 classmark1;
1162 uint8_t mi_len;
1163 uint8_t mi[0];
1164} __attribute__ ((packed));
1165
Andreas Eversberg014cb872010-07-12 09:11:00 +02001166/* Section 9.1.1 */
1167struct gsm48_add_ass {
1168 /* Semantic is from 10.5.2.5 */
1169 struct gsm48_chan_desc chan_desc;
1170 uint8_t data[0];
1171} __attribute__((packed));
1172
1173/* Section 9.1.3 */
1174struct gsm48_ass_cpl {
1175 uint8_t rr_cause;
1176} __attribute__((packed));
1177
1178/* Section 9.1.4 */
1179struct gsm48_ass_fail {
1180 uint8_t rr_cause;
1181} __attribute__((packed));
1182
Andreas Eversbergfa832012010-09-01 23:37:07 +02001183/* Section 9.1.3 */
1184struct gsm48_ho_cpl {
1185 uint8_t rr_cause;
1186 uint8_t data[0];
1187} __attribute__((packed));
1188
1189/* Section 9.1.4 */
1190struct gsm48_ho_fail {
1191 uint8_t rr_cause;
1192} __attribute__((packed));
1193
Andreas Eversberg014cb872010-07-12 09:11:00 +02001194/* Section 9.1.7 */
1195struct gsm48_chan_rel {
1196 uint8_t rr_cause;
1197 uint8_t data[0];
1198} __attribute__((packed));
1199
1200/* Section 9.1.9 */
1201struct gsm48_cip_mode_cmd {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001202#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +02001203 uint8_t sc:1,
1204 alg_id:3,
Sylvain Munaut77b6f6c2010-09-17 13:55:45 +02001205 cr:1,
1206 spare:3;
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001207#elif OSMO_IS_BIG_ENDIAN
1208/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1209 uint8_t spare:3, cr:1, alg_id:3, sc:1;
1210#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +02001211} __attribute__((packed));
1212
1213/* Section 9.1.11 */
1214struct gsm48_cm_change {
1215 uint8_t cm2_len;
1216 struct gsm48_classmark2 cm2;
1217 uint8_t data[0];
1218} __attribute__((packed));
1219
1220/* Section 9.1.19 */
1221struct gsm48_imm_ass_ext {
1222 uint8_t l2_plen;
1223 uint8_t proto_discr;
1224 uint8_t msg_type;
1225 uint8_t page_mode;
1226 struct gsm48_chan_desc chan_desc1;
1227 struct gsm48_req_ref req_ref1;
1228 uint8_t timing_advance1;
1229 struct gsm48_chan_desc chan_desc2;
1230 struct gsm48_req_ref req_ref2;
1231 uint8_t timing_advance2;
1232 uint8_t mob_alloc_len;
1233 uint8_t mob_alloc[0];
1234} __attribute__ ((packed));
1235
1236/* Section 9.1.20 */
1237struct gsm48_imm_ass_rej {
1238 uint8_t l2_plen;
1239 uint8_t proto_discr;
1240 uint8_t msg_type;
1241 uint8_t page_mode;
1242 struct gsm48_req_ref req_ref1;
1243 uint8_t wait_ind1;
1244 struct gsm48_req_ref req_ref2;
1245 uint8_t wait_ind2;
1246 struct gsm48_req_ref req_ref3;
1247 uint8_t wait_ind3;
1248 struct gsm48_req_ref req_ref4;
1249 uint8_t wait_ind4;
1250 uint8_t rest[0];
1251} __attribute__ ((packed));
1252
1253/* Section 9.1.22 */
1254struct gsm48_paging1 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001255#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +02001256 uint8_t l2_plen;
1257 uint8_t proto_discr;
1258 uint8_t msg_type;
1259 uint8_t pag_mode:2,
1260 spare:2,
1261 cneed1:2,
1262 cneed2:2;
1263 uint8_t data[0];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001264#elif OSMO_IS_BIG_ENDIAN
1265/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1266 uint8_t l2_plen;
1267 uint8_t proto_discr;
1268 uint8_t msg_type;
1269 uint8_t cneed2:2, cneed1:2, spare:2, pag_mode:2;
1270 uint8_t data[0];
1271#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +02001272} __attribute__((packed));
1273
1274/* Section 9.1.23 */
1275struct gsm48_paging2 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001276#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +02001277 uint8_t l2_plen;
1278 uint8_t proto_discr;
1279 uint8_t msg_type;
1280 uint8_t pag_mode:2,
1281 spare:2,
1282 cneed1:2,
1283 cneed2:2;
1284 uint32_t tmsi1;
1285 uint32_t tmsi2;
1286 uint8_t data[0];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001287#elif OSMO_IS_BIG_ENDIAN
1288/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1289 uint8_t l2_plen;
1290 uint8_t proto_discr;
1291 uint8_t msg_type;
1292 uint8_t cneed2:2, cneed1:2, spare:2, pag_mode:2;
1293 uint32_t tmsi1;
1294 uint32_t tmsi2;
1295 uint8_t data[0];
1296#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +02001297} __attribute__((packed));
1298
1299/* Section 9.1.24 */
1300struct gsm48_paging3 {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001301#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +02001302 uint8_t l2_plen;
1303 uint8_t proto_discr;
1304 uint8_t msg_type;
1305 uint8_t pag_mode:2,
1306 spare:2,
1307 cneed1:2,
1308 cneed2:2;
1309 uint32_t tmsi1;
1310 uint32_t tmsi2;
1311 uint32_t tmsi3;
1312 uint32_t tmsi4;
1313 uint8_t cneed3:2,
1314 cneed4:2,
1315 spare2:4;
1316 uint8_t rest[0];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001317#elif OSMO_IS_BIG_ENDIAN
1318/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1319 uint8_t l2_plen;
1320 uint8_t proto_discr;
1321 uint8_t msg_type;
1322 uint8_t cneed2:2, cneed1:2, spare:2, pag_mode:2;
1323 uint32_t tmsi1;
1324 uint32_t tmsi2;
1325 uint32_t tmsi3;
1326 uint32_t tmsi4;
1327 uint8_t spare2:4, cneed4:2, cneed3:2;
1328 uint8_t rest[0];
1329#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +02001330} __attribute__((packed));
1331
1332/* Section 9.1.25 */
1333struct gsm48_pag_rsp {
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001334#if OSMO_IS_LITTLE_ENDIAN
Andreas Eversberg014cb872010-07-12 09:11:00 +02001335 uint8_t key_seq:3,
1336 spare:5;
1337 uint8_t cm2_len;
1338 struct gsm48_classmark2 cm2;
1339 uint8_t data[0];
Neels Hofmeyrb2600392018-11-16 00:20:39 +01001340#elif OSMO_IS_BIG_ENDIAN
1341/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
1342 uint8_t spare:5, key_seq:3;
1343 uint8_t cm2_len;
1344 struct gsm48_classmark2 cm2;
1345 uint8_t data[0];
1346#endif
Andreas Eversberg014cb872010-07-12 09:11:00 +02001347} __attribute__((packed));
1348
1349/* Section 9.1.29 */
1350struct gsm48_rr_status {
1351 uint8_t rr_cause;
1352} __attribute__((packed));
1353
Harald Welte3f066dd2017-05-29 15:59:03 +02001354/* Section 10.2 + GSM 04.07 12.2.3.1.1 + 3GPP TS 24.007 11.2.3.1.1 */
Harald Welteec8b4502010-02-20 20:34:29 +01001355#define GSM48_PDISC_GROUP_CC 0x00
1356#define GSM48_PDISC_BCAST_CC 0x01
Harald Welte3f066dd2017-05-29 15:59:03 +02001357#define GSM48_PDISC_PDSS1 0x02 /* 04.07 only */
Harald Welteec8b4502010-02-20 20:34:29 +01001358#define GSM48_PDISC_CC 0x03
Harald Welte3f066dd2017-05-29 15:59:03 +02001359#define GSM48_PDISC_PDSS2 0x04 /* 04.07 only */
1360#define GSM48_PDISC_GTTP 0x04 /* 24.007 only */
Harald Welteec8b4502010-02-20 20:34:29 +01001361#define GSM48_PDISC_MM 0x05
1362#define GSM48_PDISC_RR 0x06
1363#define GSM48_PDISC_MM_GPRS 0x08
1364#define GSM48_PDISC_SMS 0x09
1365#define GSM48_PDISC_SM_GPRS 0x0a
1366#define GSM48_PDISC_NC_SS 0x0b
1367#define GSM48_PDISC_LOC 0x0c
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001368#define GSM48_PDISC_EXTEND 0x0e
Harald Welte3f066dd2017-05-29 15:59:03 +02001369#define GSM48_PDISC_TEST 0x0f /* as per 11.10, 04.14 */
Harald Welteec8b4502010-02-20 20:34:29 +01001370#define GSM48_PDISC_MASK 0x0f
Harald Welteec8b4502010-02-20 20:34:29 +01001371
Neels Hofmeyrdbd994c2017-03-09 23:07:02 +01001372extern const struct value_string gsm48_pdisc_names[];
1373static inline const char *gsm48_pdisc_name(uint8_t val)
1374{ return get_value_string(gsm48_pdisc_names, val); }
1375
Maxfdca25d2016-07-05 16:06:28 +02001376bool gsm48_hdr_gmm_cipherable(const struct gsm48_hdr *hdr);
1377
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001378static inline uint8_t gsm48_hdr_pdisc(const struct gsm48_hdr *hdr)
1379{
1380 /*
1381 * 3GPP TS 24.007 version 12.0.0 Release 12,
1382 * 11.2.3.1.1 Protocol discriminator
1383 */
1384 uint8_t pdisc = hdr->proto_discr & GSM48_PDISC_MASK;
1385 if (pdisc == GSM48_PDISC_EXTEND)
1386 return hdr->proto_discr;
1387 return pdisc;
1388}
1389
Neels Hofmeyrda7bf4d2016-03-14 16:06:48 +01001390static inline uint8_t gsm48_hdr_trans_id(const struct gsm48_hdr *hdr)
1391{
1392 /*
1393 * 3GPP TS 24.007 version 12.0.0 Release 12,
1394 * 11.2.3.1.3 Transaction identifier
1395 */
1396 return (hdr->proto_discr & 0xf0) >> 4;
1397}
1398
Maxda34bf02016-07-17 16:37:56 +02001399#define GSM48_TA_INVALID 220
1400
Neels Hofmeyr87e45502017-06-20 00:17:59 +02001401/*! Check if TA is valid according to 3GPP TS 44.018 ยง 10.5.2.40
Maxedb57e72016-07-14 11:35:17 +02001402 * \param[in] ta Timing Advance value
1403 * \returns true if ta is valid, false otherwise
1404 * Note: Rules for GSM400 band are ignored as it's not implemented in practice.
1405 */
1406static inline bool gsm48_ta_is_valid(uint8_t ta)
1407{
1408 return (ta < 64);
1409}
1410
Neels Hofmeyrda7bf4d2016-03-14 16:06:48 +01001411static inline uint8_t gsm48_hdr_trans_id_flip_ti(const struct gsm48_hdr *hdr)
1412{
1413 return gsm48_hdr_trans_id(hdr) ^ 0x08;
1414}
1415
1416static inline uint8_t gsm48_hdr_trans_id_no_ti(const struct gsm48_hdr *hdr)
1417{
1418 return gsm48_hdr_trans_id(hdr) & 0x07;
1419}
1420
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001421static inline uint8_t gsm48_hdr_msg_type_r98(const struct gsm48_hdr *hdr)
1422{
1423 /*
1424 * 3GPP TS 24.007 version 12.0.0 Release 12,
1425 * 11.2.3.2.1 Message type octet (when accessing Release 98 and older
1426 * networks only)
1427 */
1428 switch (gsm48_hdr_pdisc(hdr)) {
1429 case GSM48_PDISC_MM:
1430 case GSM48_PDISC_CC:
1431 case GSM48_PDISC_NC_SS:
1432 case GSM48_PDISC_GROUP_CC:
1433 case GSM48_PDISC_BCAST_CC:
1434 case GSM48_PDISC_LOC:
Harald Welte143aed72018-02-03 21:14:47 +01001435 return hdr->msg_type & 0x3f;
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001436 default:
1437 return hdr->msg_type;
1438 }
1439}
1440
1441static inline uint8_t gsm48_hdr_msg_type_r99(const struct gsm48_hdr *hdr)
1442{
1443 /*
1444 * 3GPP TS 24.007 version 12.0.0 Release 12,
1445 * 11.2.3.2.2 Message type octet (when accessing Release 99 and newer
1446 * networks)
1447 */
1448 switch (gsm48_hdr_pdisc(hdr)) {
1449 case GSM48_PDISC_MM:
1450 case GSM48_PDISC_CC:
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001451 case GSM48_PDISC_NC_SS:
Harald Weltef1076ed2018-02-03 21:16:45 +01001452 return hdr->msg_type & 0x3f;
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001453 case GSM48_PDISC_GROUP_CC:
1454 case GSM48_PDISC_BCAST_CC:
1455 case GSM48_PDISC_LOC:
Harald Welte143aed72018-02-03 21:14:47 +01001456 return hdr->msg_type & 0x3f;
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001457 default:
1458 return hdr->msg_type;
1459 }
1460}
1461
Maxfe65fa72016-05-10 17:17:05 +02001462void gsm48_set_dtx(struct gsm48_cell_options *op, enum gsm48_dtx_mode full,
1463 enum gsm48_dtx_mode half, bool is_bcch);
1464
Neels Hofmeyrc656fae2016-03-14 16:06:47 +01001465#define gsm48_hdr_msg_type gsm48_hdr_msg_type_r99
Neels Hofmeyr282e9082016-03-14 16:06:46 +01001466
Harald Welteec8b4502010-02-20 20:34:29 +01001467/* Section 10.4 */
1468#define GSM48_MT_RR_INIT_REQ 0x3c
1469#define GSM48_MT_RR_ADD_ASS 0x3b
1470#define GSM48_MT_RR_IMM_ASS 0x3f
1471#define GSM48_MT_RR_IMM_ASS_EXT 0x39
1472#define GSM48_MT_RR_IMM_ASS_REJ 0x3a
Philipp72e43f02016-10-27 13:35:20 +02001473#define GSM48_MT_RR_DTM_ASS_FAIL 0x48
1474#define GSM48_MT_RR_DTM_REJECT 0x49
1475#define GSM48_MT_RR_DTM_REQUEST 0x4A
1476#define GSM48_MT_RR_PACKET_ASS 0x4B
Harald Welteec8b4502010-02-20 20:34:29 +01001477
1478#define GSM48_MT_RR_CIPH_M_CMD 0x35
1479#define GSM48_MT_RR_CIPH_M_COMPL 0x32
1480
1481#define GSM48_MT_RR_CFG_CHG_CMD 0x30
1482#define GSM48_MT_RR_CFG_CHG_ACK 0x31
1483#define GSM48_MT_RR_CFG_CHG_REJ 0x33
1484
1485#define GSM48_MT_RR_ASS_CMD 0x2e
1486#define GSM48_MT_RR_ASS_COMPL 0x29
1487#define GSM48_MT_RR_ASS_FAIL 0x2f
1488#define GSM48_MT_RR_HANDO_CMD 0x2b
1489#define GSM48_MT_RR_HANDO_COMPL 0x2c
1490#define GSM48_MT_RR_HANDO_FAIL 0x28
1491#define GSM48_MT_RR_HANDO_INFO 0x2d
Philipp72e43f02016-10-27 13:35:20 +02001492#define GSM48_MT_RR_HANDO_INFO 0x2d
1493#define GSM48_MT_RR_DTM_ASS_CMD 0x4c
Harald Welteec8b4502010-02-20 20:34:29 +01001494
1495#define GSM48_MT_RR_CELL_CHG_ORDER 0x08
1496#define GSM48_MT_RR_PDCH_ASS_CMD 0x23
1497
1498#define GSM48_MT_RR_CHAN_REL 0x0d
1499#define GSM48_MT_RR_PART_REL 0x0a
1500#define GSM48_MT_RR_PART_REL_COMP 0x0f
1501
1502#define GSM48_MT_RR_PAG_REQ_1 0x21
1503#define GSM48_MT_RR_PAG_REQ_2 0x22
1504#define GSM48_MT_RR_PAG_REQ_3 0x24
1505#define GSM48_MT_RR_PAG_RESP 0x27
1506#define GSM48_MT_RR_NOTIF_NCH 0x20
Philipp72e43f02016-10-27 13:35:20 +02001507#define GSM48_MT_RR_NOTIF_FACCH 0x25 /* (Reserved) */
Harald Welteec8b4502010-02-20 20:34:29 +01001508#define GSM48_MT_RR_NOTIF_RESP 0x26
Philipp72e43f02016-10-27 13:35:20 +02001509#define GSM48_MT_RR_PACKET_NOTIF 0x4e
Philipp349784c2016-10-10 15:03:23 +02001510#define GSM48_MT_RR_UTRAN_CLSM_CHG 0x60
1511#define GSM48_MT_RR_CDMA2K_CLSM_CHG 0x62
1512#define GSM48_MT_RR_IS_TO_UTRAN_HANDO 0x63
1513#define GSM48_MT_RR_IS_TO_CDMA2K_HANDO 0x64
1514
Harald Welteec8b4502010-02-20 20:34:29 +01001515#define GSM48_MT_RR_SYSINFO_8 0x18
1516#define GSM48_MT_RR_SYSINFO_1 0x19
1517#define GSM48_MT_RR_SYSINFO_2 0x1a
1518#define GSM48_MT_RR_SYSINFO_3 0x1b
1519#define GSM48_MT_RR_SYSINFO_4 0x1c
1520#define GSM48_MT_RR_SYSINFO_5 0x1d
1521#define GSM48_MT_RR_SYSINFO_6 0x1e
1522#define GSM48_MT_RR_SYSINFO_7 0x1f
1523
1524#define GSM48_MT_RR_SYSINFO_2bis 0x02
1525#define GSM48_MT_RR_SYSINFO_2ter 0x03
Maxe859aec2016-03-11 12:24:04 +01001526#define GSM48_MT_RR_SYSINFO_2quater 0x07
Harald Welteec8b4502010-02-20 20:34:29 +01001527#define GSM48_MT_RR_SYSINFO_5bis 0x05
1528#define GSM48_MT_RR_SYSINFO_5ter 0x06
1529#define GSM48_MT_RR_SYSINFO_9 0x04
1530#define GSM48_MT_RR_SYSINFO_13 0x00
1531
1532#define GSM48_MT_RR_SYSINFO_16 0x3d
1533#define GSM48_MT_RR_SYSINFO_17 0x3e
1534
Philipp72e43f02016-10-27 13:35:20 +02001535#define GSM48_MT_RR_SYSINFO_18 0x40
1536#define GSM48_MT_RR_SYSINFO_19 0x41
1537#define GSM48_MT_RR_SYSINFO_20 0x42
1538
Harald Welteec8b4502010-02-20 20:34:29 +01001539#define GSM48_MT_RR_CHAN_MODE_MODIF 0x10
1540#define GSM48_MT_RR_STATUS 0x12
1541#define GSM48_MT_RR_CHAN_MODE_MODIF_ACK 0x17
1542#define GSM48_MT_RR_FREQ_REDEF 0x14
1543#define GSM48_MT_RR_MEAS_REP 0x15
1544#define GSM48_MT_RR_CLSM_CHG 0x16
1545#define GSM48_MT_RR_CLSM_ENQ 0x13
1546#define GSM48_MT_RR_EXT_MEAS_REP 0x36
1547#define GSM48_MT_RR_EXT_MEAS_REP_ORD 0x37
1548#define GSM48_MT_RR_GPRS_SUSP_REQ 0x34
Philipp72e43f02016-10-27 13:35:20 +02001549#define GSM48_MT_RR_DTM_INFO 0x4d
Harald Welteec8b4502010-02-20 20:34:29 +01001550
Bhaskare6b45d82013-05-16 17:11:51 +05301551#define GSM48_MT_RR_VGCS_UPL_GRANT 0x09
Harald Welteec8b4502010-02-20 20:34:29 +01001552#define GSM48_MT_RR_UPLINK_RELEASE 0x0e
1553#define GSM48_MT_RR_UPLINK_FREE 0x0c
1554#define GSM48_MT_RR_UPLINK_BUSY 0x2a
1555#define GSM48_MT_RR_TALKER_IND 0x11
1556
1557#define GSM48_MT_RR_APP_INFO 0x38
1558
1559/* Table 10.2/3GPP TS 04.08 */
1560#define GSM48_MT_MM_IMSI_DETACH_IND 0x01
1561#define GSM48_MT_MM_LOC_UPD_ACCEPT 0x02
1562#define GSM48_MT_MM_LOC_UPD_REJECT 0x04
1563#define GSM48_MT_MM_LOC_UPD_REQUEST 0x08
1564
1565#define GSM48_MT_MM_AUTH_REJ 0x11
1566#define GSM48_MT_MM_AUTH_REQ 0x12
1567#define GSM48_MT_MM_AUTH_RESP 0x14
Neels Hofmeyr55a43b82017-02-02 20:27:55 +01001568#define GSM48_MT_MM_AUTH_FAIL 0x1c
Harald Welteec8b4502010-02-20 20:34:29 +01001569#define GSM48_MT_MM_ID_REQ 0x18
1570#define GSM48_MT_MM_ID_RESP 0x19
1571#define GSM48_MT_MM_TMSI_REALL_CMD 0x1a
1572#define GSM48_MT_MM_TMSI_REALL_COMPL 0x1b
1573
1574#define GSM48_MT_MM_CM_SERV_ACC 0x21
1575#define GSM48_MT_MM_CM_SERV_REJ 0x22
1576#define GSM48_MT_MM_CM_SERV_ABORT 0x23
1577#define GSM48_MT_MM_CM_SERV_REQ 0x24
1578#define GSM48_MT_MM_CM_SERV_PROMPT 0x25
1579#define GSM48_MT_MM_CM_REEST_REQ 0x28
1580#define GSM48_MT_MM_ABORT 0x29
1581
1582#define GSM48_MT_MM_NULL 0x30
1583#define GSM48_MT_MM_STATUS 0x31
1584#define GSM48_MT_MM_INFO 0x32
1585
1586/* Table 10.3/3GPP TS 04.08 */
1587#define GSM48_MT_CC_ALERTING 0x01
1588#define GSM48_MT_CC_CALL_CONF 0x08
1589#define GSM48_MT_CC_CALL_PROC 0x02
1590#define GSM48_MT_CC_CONNECT 0x07
1591#define GSM48_MT_CC_CONNECT_ACK 0x0f
1592#define GSM48_MT_CC_EMERG_SETUP 0x0e
1593#define GSM48_MT_CC_PROGRESS 0x03
1594#define GSM48_MT_CC_ESTAB 0x04
1595#define GSM48_MT_CC_ESTAB_CONF 0x06
1596#define GSM48_MT_CC_RECALL 0x0b
1597#define GSM48_MT_CC_START_CC 0x09
1598#define GSM48_MT_CC_SETUP 0x05
1599
1600#define GSM48_MT_CC_MODIFY 0x17
1601#define GSM48_MT_CC_MODIFY_COMPL 0x1f
1602#define GSM48_MT_CC_MODIFY_REJECT 0x13
1603#define GSM48_MT_CC_USER_INFO 0x10
1604#define GSM48_MT_CC_HOLD 0x18
1605#define GSM48_MT_CC_HOLD_ACK 0x19
1606#define GSM48_MT_CC_HOLD_REJ 0x1a
1607#define GSM48_MT_CC_RETR 0x1c
1608#define GSM48_MT_CC_RETR_ACK 0x1d
1609#define GSM48_MT_CC_RETR_REJ 0x1e
1610
1611#define GSM48_MT_CC_DISCONNECT 0x25
1612#define GSM48_MT_CC_RELEASE 0x2d
1613#define GSM48_MT_CC_RELEASE_COMPL 0x2a
1614
1615#define GSM48_MT_CC_CONG_CTRL 0x39
1616#define GSM48_MT_CC_NOTIFY 0x3e
1617#define GSM48_MT_CC_STATUS 0x3d
1618#define GSM48_MT_CC_STATUS_ENQ 0x34
1619#define GSM48_MT_CC_START_DTMF 0x35
1620#define GSM48_MT_CC_STOP_DTMF 0x31
1621#define GSM48_MT_CC_STOP_DTMF_ACK 0x32
1622#define GSM48_MT_CC_START_DTMF_ACK 0x36
1623#define GSM48_MT_CC_START_DTMF_REJ 0x37
1624#define GSM48_MT_CC_FACILITY 0x3a
1625
Neels Hofmeyr00ab9ed2017-03-09 23:27:56 +01001626extern const struct value_string gsm48_rr_msgtype_names[];
1627extern const struct value_string gsm48_mm_msgtype_names[];
1628extern const struct value_string gsm48_cc_msgtype_names[];
1629const char *gsm48_pdisc_msgtype_name(uint8_t pdisc, uint8_t msg_type);
1630
Harald Welteec8b4502010-02-20 20:34:29 +01001631/* FIXME: Table 10.4 / 10.4a (GPRS) */
1632
Andreas Eversberg014cb872010-07-12 09:11:00 +02001633/* Section 10.5.3.3 CM service type */
1634#define GSM48_CMSERV_MO_CALL_PACKET 1
1635#define GSM48_CMSERV_EMERGENCY 2
1636#define GSM48_CMSERV_SMS 4
1637#define GSM48_CMSERV_SUP_SERV 8
1638#define GSM48_CMSERV_VGCS 9
1639#define GSM48_CMSERV_VBS 10
1640#define GSM48_CMSERV_LOC_SERV 11
1641
Harald Welteec8b4502010-02-20 20:34:29 +01001642/* Section 10.5.2.26, Table 10.5.64 */
1643#define GSM48_PM_MASK 0x03
1644#define GSM48_PM_NORMAL 0x00
1645#define GSM48_PM_EXTENDED 0x01
1646#define GSM48_PM_REORG 0x02
1647#define GSM48_PM_SAME 0x03
1648
1649/* Chapter 10.5.3.5 / Table 10.5.93 */
1650#define GSM48_LUPD_NORMAL 0x0
1651#define GSM48_LUPD_PERIODIC 0x1
1652#define GSM48_LUPD_IMSI_ATT 0x2
1653#define GSM48_LUPD_RESERVED 0x3
1654
1655/* Table 10.5.4 */
1656#define GSM_MI_TYPE_MASK 0x07
1657#define GSM_MI_TYPE_NONE 0x00
1658#define GSM_MI_TYPE_IMSI 0x01
1659#define GSM_MI_TYPE_IMEI 0x02
1660#define GSM_MI_TYPE_IMEISV 0x03
1661#define GSM_MI_TYPE_TMSI 0x04
1662#define GSM_MI_ODD 0x08
1663
Andreas Eversberg014cb872010-07-12 09:11:00 +02001664#define GSM48_IE_MOBILE_ID 0x17 /* 10.5.1.4 */
Harald Welteec8b4502010-02-20 20:34:29 +01001665#define GSM48_IE_NAME_LONG 0x43 /* 10.5.3.5a */
1666#define GSM48_IE_NAME_SHORT 0x45 /* 10.5.3.5a */
1667#define GSM48_IE_UTC 0x46 /* 10.5.3.8 */
1668#define GSM48_IE_NET_TIME_TZ 0x47 /* 10.5.3.9 */
1669#define GSM48_IE_LSA_IDENT 0x48 /* 10.5.3.11 */
Jacob Erlbeck1c3f0882013-09-16 10:29:57 +02001670#define GSM48_IE_NET_DST 0x49 /* 10.5.3.12 [24.008] */
Harald Welteec8b4502010-02-20 20:34:29 +01001671
1672#define GSM48_IE_BEARER_CAP 0x04 /* 10.5.4.5 */
1673#define GSM48_IE_CAUSE 0x08 /* 10.5.4.11 */
1674#define GSM48_IE_CC_CAP 0x15 /* 10.5.4.5a */
1675#define GSM48_IE_ALERT 0x19 /* 10.5.4.26 */
1676#define GSM48_IE_FACILITY 0x1c /* 10.5.4.15 */
1677#define GSM48_IE_PROGR_IND 0x1e /* 10.5.4.21 */
1678#define GSM48_IE_AUX_STATUS 0x24 /* 10.5.4.4 */
1679#define GSM48_IE_NOTIFY 0x27 /* 10.5.4.20 */
1680#define GSM48_IE_KPD_FACILITY 0x2c /* 10.5.4.17 */
1681#define GSM48_IE_SIGNAL 0x34 /* 10.5.4.23 */
1682#define GSM48_IE_CONN_BCD 0x4c /* 10.5.4.13 */
1683#define GSM48_IE_CONN_SUB 0x4d /* 10.5.4.14 */
1684#define GSM48_IE_CALLING_BCD 0x5c /* 10.5.4.9 */
1685#define GSM48_IE_CALLING_SUB 0x5d /* 10.5.4.10 */
1686#define GSM48_IE_CALLED_BCD 0x5e /* 10.5.4.7 */
1687#define GSM48_IE_CALLED_SUB 0x6d /* 10.5.4.8 */
1688#define GSM48_IE_REDIR_BCD 0x74 /* 10.5.4.21a */
1689#define GSM48_IE_REDIR_SUB 0x75 /* 10.5.4.21b */
1690#define GSM48_IE_LOWL_COMPAT 0x7c /* 10.5.4.18 */
1691#define GSM48_IE_HIGHL_COMPAT 0x7d /* 10.5.4.16 */
1692#define GSM48_IE_USER_USER 0x7e /* 10.5.4.25 */
1693#define GSM48_IE_SS_VERS 0x7f /* 10.5.4.24 */
1694#define GSM48_IE_MORE_DATA 0xa0 /* 10.5.4.19 */
1695#define GSM48_IE_CLIR_SUPP 0xa1 /* 10.5.4.11a */
1696#define GSM48_IE_CLIR_INVOC 0xa2 /* 10.5.4.11b */
1697#define GSM48_IE_REV_C_SETUP 0xa3 /* 10.5.4.22a */
1698#define GSM48_IE_REPEAT_CIR 0xd1 /* 10.5.4.22 */
1699#define GSM48_IE_REPEAT_SEQ 0xd3 /* 10.5.4.22 */
1700
1701/* Section 10.5.4.11 / Table 10.5.122 */
1702#define GSM48_CAUSE_CS_GSM 0x60
1703
1704/* Section 9.1.2 / Table 9.3 */
Andreas Eversberg014cb872010-07-12 09:11:00 +02001705/* RR elements */
1706#define GSM48_IE_VGCS_TARGET 0x01
1707//#define GSM48_IE_VGCS_T_MODE_I 0x01
1708#define GSM48_IE_FRQSHORT_AFTER 0x02
1709#define GSM48_IE_MUL_RATE_CFG 0x03 /* 10.5.2.21aa */
1710#define GSM48_IE_FREQ_L_AFTER 0x05
Harald Welteec8b4502010-02-20 20:34:29 +01001711#define GSM48_IE_MSLOT_DESC 0x10
Harald Welteec8b4502010-02-20 20:34:29 +01001712#define GSM48_IE_CHANMODE_2 0x11
Andreas Eversberg014cb872010-07-12 09:11:00 +02001713#define GSM48_IE_FRQSHORT_BEFORE 0x12
1714//#define GSM48_IE_FRQSHORT_BEFOR 0x12
Harald Welteec8b4502010-02-20 20:34:29 +01001715#define GSM48_IE_CHANMODE_3 0x13
1716#define GSM48_IE_CHANMODE_4 0x14
1717#define GSM48_IE_CHANMODE_5 0x15
1718#define GSM48_IE_CHANMODE_6 0x16
1719#define GSM48_IE_CHANMODE_7 0x17
1720#define GSM48_IE_CHANMODE_8 0x18
1721#define GSM48_IE_CHANDESC_2 0x64
Harald Welte639f74b2010-06-15 09:32:14 +02001722#define GSM48_IE_MA_AFTER 0x72
1723#define GSM48_IE_START_TIME 0x7c
1724#define GSM48_IE_FREQ_L_BEFORE 0x19
Andreas Eversberg014cb872010-07-12 09:11:00 +02001725//#define GSM48_IE_FRQLIST_BEFORE 0x19
Harald Welte639f74b2010-06-15 09:32:14 +02001726#define GSM48_IE_CH_DESC_1_BEFORE 0x1c
Andreas Eversberg014cb872010-07-12 09:11:00 +02001727//#define GSM48_IE_CHDES_1_BEFORE 0x1c
Harald Welte639f74b2010-06-15 09:32:14 +02001728#define GSM48_IE_CH_DESC_2_BEFORE 0x1d
Andreas Eversberg014cb872010-07-12 09:11:00 +02001729//#define GSM48_IE_CHDES_2_BEFORE 0x1d
Harald Welte639f74b2010-06-15 09:32:14 +02001730#define GSM48_IE_F_CH_SEQ_BEFORE 0x1e
Andreas Eversberg014cb872010-07-12 09:11:00 +02001731//#define GSM48_IE_FRQSEQ_BEFORE 0x1e
1732#define GSM48_IE_CLASSMARK3 0x20
Harald Welte639f74b2010-06-15 09:32:14 +02001733#define GSM48_IE_MA_BEFORE 0x21
Andreas Eversberg014cb872010-07-12 09:11:00 +02001734#define GSM48_IE_RR_PACKET_UL 0x22
1735#define GSM48_IE_RR_PACKET_DL 0x23
1736#define GSM48_IE_CELL_CH_DESC 0x62
1737#define GSM48_IE_CHANMODE_1 0x63
1738#define GSM48_IE_CHDES_2_AFTER 0x64
1739#define GSM48_IE_MODE_SEC_CH 0x66
1740#define GSM48_IE_F_CH_SEQ_AFTER 0x69
1741#define GSM48_IE_MA_AFTER 0x72
1742#define GSM48_IE_BA_RANGE 0x73
1743#define GSM48_IE_GROUP_CHDES 0x74
1744#define GSM48_IE_BA_LIST_PREF 0x75
1745#define GSM48_IE_MOB_OVSERV_DIF 0x77
1746#define GSM48_IE_REALTIME_DIFF 0x7b
1747#define GSM48_IE_START_TIME 0x7c
1748#define GSM48_IE_TIMING_ADVANCE 0x7d
1749#define GSM48_IE_GROUP_CIP_SEQ 0x80
1750#define GSM48_IE_CIP_MODE_SET 0x90
1751#define GSM48_IE_GPRS_RESUMPT 0xc0
1752#define GSM48_IE_SYNC_IND 0xd0
1753/* System Information 4 (types are equal IEs above) */
1754#define GSM48_IE_CBCH_CHAN_DESC 0x64
1755#define GSM48_IE_CBCH_MOB_AL 0x72
Harald Welte639f74b2010-06-15 09:32:14 +02001756
Andreas Eversberg014cb872010-07-12 09:11:00 +02001757/* Additional MM elements */
1758#define GSM48_IE_LOCATION_AREA 0x13
Harald Welte82f94ef2016-05-05 23:33:27 +02001759#define GSM48_IE_AUTN 0x20
Neels Hofmeyr55a43b82017-02-02 20:27:55 +01001760#define GSM48_IE_AUTH_RES_EXT 0x21
1761#define GSM48_IE_AUTS 0x22
Andreas Eversberg014cb872010-07-12 09:11:00 +02001762#define GSM48_IE_PRIORITY_LEV 0x80
1763#define GSM48_IE_FOLLOW_ON_PROC 0xa1
1764#define GSM48_IE_CTS_PERMISSION 0xa2
Harald Welteec8b4502010-02-20 20:34:29 +01001765
Keith05d32782018-05-28 14:08:10 +02001766/* Section 10.5.4.21 / Table 10.5.127 */
1767
1768enum gsm48_progress_desc {
1769 GSM48_PROGR_NOT_E2E = 0x00,
1770 GSM48_PROGR_DEST_NOT_PLMN = 0x02,
1771 GSM48_PROGR_ORIG_NOT_PLMN = 0x03,
1772 GSM48_PROGR_RETURNED = 0x04,
1773 GSM48_PROGR_IN_BAND_AVAIL = 0x08,
1774 GSM48_PROGR_CALL_E2E = 0x20,
1775 GSM48_PROGR_QUEUEING = 0x40,
1776};
1777
Harald Welteec8b4502010-02-20 20:34:29 +01001778/* Section 10.5.4.23 / Table 10.5.130 */
1779enum gsm48_signal_val {
1780 GSM48_SIGNAL_DIALTONE = 0x00,
1781 GSM48_SIGNAL_RINGBACK = 0x01,
1782 GSM48_SIGNAL_INTERCEPT = 0x02,
1783 GSM48_SIGNAL_NET_CONG = 0x03,
1784 GSM48_SIGNAL_BUSY = 0x04,
1785 GSM48_SIGNAL_CONFIRM = 0x05,
1786 GSM48_SIGNAL_ANSWER = 0x06,
1787 GSM48_SIGNAL_CALL_WAIT = 0x07,
1788 GSM48_SIGNAL_OFF_HOOK = 0x08,
1789 GSM48_SIGNAL_OFF = 0x3f,
1790 GSM48_SIGNAL_ALERT_OFF = 0x4f,
1791};
1792
Keithadfa1992018-05-25 15:24:06 +02001793/* Section 10.5.4.11 / Table 10.5.122 */
1794enum gsm48_cause_coding {
1795 GSM48_CAUSE_CODING_CCITT_Q931 = 0x00,
1796 GSM48_CAUSE_CODING_RESERVED = 0x01,
1797 GSM48_CAUSE_CODING_NATIONAL = 0x02,
1798 GSM48_CAUSE_CODING_GSM = 0x03,
1799};
1800
Harald Welteec8b4502010-02-20 20:34:29 +01001801enum gsm48_cause_loc {
1802 GSM48_CAUSE_LOC_USER = 0x00,
1803 GSM48_CAUSE_LOC_PRN_S_LU = 0x01,
1804 GSM48_CAUSE_LOC_PUN_S_LU = 0x02,
1805 GSM48_CAUSE_LOC_TRANS_NET = 0x03,
1806 GSM48_CAUSE_LOC_PUN_S_RU = 0x04,
1807 GSM48_CAUSE_LOC_PRN_S_RU = 0x05,
1808 /* not defined */
1809 GSM48_CAUSE_LOC_INN_NET = 0x07,
1810 GSM48_CAUSE_LOC_NET_BEYOND = 0x0a,
1811};
1812
1813/* Section 10.5.2.31 RR Cause / Table 10.5.70 */
1814enum gsm48_rr_cause {
1815 GSM48_RR_CAUSE_NORMAL = 0x00,
1816 GSM48_RR_CAUSE_ABNORMAL_UNSPEC = 0x01,
1817 GSM48_RR_CAUSE_ABNORMAL_UNACCT = 0x02,
1818 GSM48_RR_CAUSE_ABNORMAL_TIMER = 0x03,
1819 GSM48_RR_CAUSE_ABNORMAL_NOACT = 0x04,
1820 GSM48_RR_CAUSE_PREMPTIVE_REL = 0x05,
Andreas Eversbergc8cac642013-06-19 20:58:59 +02001821 GSM48_RR_CAUSE_HNDOVER_IMP = 0x08,
1822 GSM48_RR_CAUSE_CHAN_MODE_UNACCT = 0x09,
1823 GSM48_RR_CAUSE_FREQ_NOT_IMPL = 0x0a,
Harald Welteec8b4502010-02-20 20:34:29 +01001824 GSM48_RR_CAUSE_CALL_CLEARED = 0x41,
1825 GSM48_RR_CAUSE_SEMANT_INCORR = 0x5f,
1826 GSM48_RR_CAUSE_INVALID_MAND_INF = 0x60,
1827 GSM48_RR_CAUSE_MSG_TYPE_N = 0x61,
1828 GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT= 0x62,
1829 GSM48_RR_CAUSE_COND_IE_ERROR = 0x64,
1830 GSM48_RR_CAUSE_NO_CELL_ALLOC_A = 0x65,
1831 GSM48_RR_CAUSE_PROT_ERROR_UNSPC = 0x6f,
1832};
1833
1834/* Section 10.5.4.11 CC Cause / Table 10.5.123 */
1835enum gsm48_cc_cause {
1836 GSM48_CC_CAUSE_UNASSIGNED_NR = 1,
1837 GSM48_CC_CAUSE_NO_ROUTE = 3,
1838 GSM48_CC_CAUSE_CHAN_UNACCEPT = 6,
1839 GSM48_CC_CAUSE_OP_DET_BARRING = 8,
1840 GSM48_CC_CAUSE_NORM_CALL_CLEAR = 16,
1841 GSM48_CC_CAUSE_USER_BUSY = 17,
1842 GSM48_CC_CAUSE_USER_NOTRESPOND = 18,
1843 GSM48_CC_CAUSE_USER_ALERTING_NA = 19,
1844 GSM48_CC_CAUSE_CALL_REJECTED = 21,
1845 GSM48_CC_CAUSE_NUMBER_CHANGED = 22,
1846 GSM48_CC_CAUSE_PRE_EMPTION = 25,
1847 GSM48_CC_CAUSE_NONSE_USER_CLR = 26,
1848 GSM48_CC_CAUSE_DEST_OOO = 27,
1849 GSM48_CC_CAUSE_INV_NR_FORMAT = 28,
1850 GSM48_CC_CAUSE_FACILITY_REJ = 29,
1851 GSM48_CC_CAUSE_RESP_STATUS_INQ = 30,
1852 GSM48_CC_CAUSE_NORMAL_UNSPEC = 31,
1853 GSM48_CC_CAUSE_NO_CIRCUIT_CHAN = 34,
1854 GSM48_CC_CAUSE_NETWORK_OOO = 38,
1855 GSM48_CC_CAUSE_TEMP_FAILURE = 41,
1856 GSM48_CC_CAUSE_SWITCH_CONG = 42,
1857 GSM48_CC_CAUSE_ACC_INF_DISCARD = 43,
1858 GSM48_CC_CAUSE_REQ_CHAN_UNAVAIL = 44,
1859 GSM48_CC_CAUSE_RESOURCE_UNAVAIL = 47,
1860 GSM48_CC_CAUSE_QOS_UNAVAIL = 49,
1861 GSM48_CC_CAUSE_REQ_FAC_NOT_SUBSC= 50,
1862 GSM48_CC_CAUSE_INC_BARRED_CUG = 55,
1863 GSM48_CC_CAUSE_BEARER_CAP_UNAUTH= 57,
1864 GSM48_CC_CAUSE_BEARER_CA_UNAVAIL= 58,
1865 GSM48_CC_CAUSE_SERV_OPT_UNAVAIL = 63,
1866 GSM48_CC_CAUSE_BEARERSERV_UNIMPL= 65,
1867 GSM48_CC_CAUSE_ACM_GE_ACM_MAX = 68,
1868 GSM48_CC_CAUSE_REQ_FAC_NOTIMPL = 69,
1869 GSM48_CC_CAUSE_RESTR_BCAP_AVAIL = 70,
1870 GSM48_CC_CAUSE_SERV_OPT_UNIMPL = 79,
1871 GSM48_CC_CAUSE_INVAL_TRANS_ID = 81,
1872 GSM48_CC_CAUSE_USER_NOT_IN_CUG = 87,
1873 GSM48_CC_CAUSE_INCOMPAT_DEST = 88,
1874 GSM48_CC_CAUSE_INVAL_TRANS_NET = 91,
1875 GSM48_CC_CAUSE_SEMANTIC_INCORR = 95,
1876 GSM48_CC_CAUSE_INVAL_MAND_INF = 96,
1877 GSM48_CC_CAUSE_MSGTYPE_NOTEXIST = 97,
1878 GSM48_CC_CAUSE_MSGTYPE_INCOMPAT = 98,
1879 GSM48_CC_CAUSE_IE_NOTEXIST = 99,
1880 GSM48_CC_CAUSE_COND_IE_ERR = 100,
1881 GSM48_CC_CAUSE_MSG_INCOMP_STATE = 101,
1882 GSM48_CC_CAUSE_RECOVERY_TIMER = 102,
1883 GSM48_CC_CAUSE_PROTO_ERR = 111,
1884 GSM48_CC_CAUSE_INTERWORKING = 127,
1885};
1886
Keith3cdaa8d2018-08-31 20:09:18 +02001887extern const struct value_string gsm48_cc_cause_names[];
1888static inline const char *gsm48_cc_cause_name(enum gsm48_cc_cause val)
1889{ return get_value_string(gsm48_cc_cause_names, val); }
1890
Harald Welteec8b4502010-02-20 20:34:29 +01001891/* Annex G, GSM specific cause values for mobility management */
1892enum gsm48_reject_value {
1893 GSM48_REJECT_IMSI_UNKNOWN_IN_HLR = 2,
1894 GSM48_REJECT_ILLEGAL_MS = 3,
1895 GSM48_REJECT_IMSI_UNKNOWN_IN_VLR = 4,
1896 GSM48_REJECT_IMEI_NOT_ACCEPTED = 5,
1897 GSM48_REJECT_ILLEGAL_ME = 6,
1898 GSM48_REJECT_PLMN_NOT_ALLOWED = 11,
1899 GSM48_REJECT_LOC_NOT_ALLOWED = 12,
1900 GSM48_REJECT_ROAMING_NOT_ALLOWED = 13,
1901 GSM48_REJECT_NETWORK_FAILURE = 17,
Neels Hofmeyr55a43b82017-02-02 20:27:55 +01001902 GSM48_REJECT_SYNCH_FAILURE = 21,
Harald Welteec8b4502010-02-20 20:34:29 +01001903 GSM48_REJECT_CONGESTION = 22,
1904 GSM48_REJECT_SRV_OPT_NOT_SUPPORTED = 32,
1905 GSM48_REJECT_RQD_SRV_OPT_NOT_SUPPORTED = 33,
1906 GSM48_REJECT_SRV_OPT_TMP_OUT_OF_ORDER = 34,
1907 GSM48_REJECT_CALL_CAN_NOT_BE_IDENTIFIED = 38,
1908 GSM48_REJECT_INCORRECT_MESSAGE = 95,
1909 GSM48_REJECT_INVALID_MANDANTORY_INF = 96,
1910 GSM48_REJECT_MSG_TYPE_NOT_IMPLEMENTED = 97,
1911 GSM48_REJECT_MSG_TYPE_NOT_COMPATIBLE = 98,
1912 GSM48_REJECT_INF_ELEME_NOT_IMPLEMENTED = 99,
1913 GSM48_REJECT_CONDTIONAL_IE_ERROR = 100,
1914 GSM48_REJECT_MSG_NOT_COMPATIBLE = 101,
1915 GSM48_REJECT_PROTOCOL_ERROR = 111,
1916
1917 /* according to G.6 Additional cause codes for GMM */
1918 GSM48_REJECT_GPRS_NOT_ALLOWED = 7,
1919 GSM48_REJECT_SERVICES_NOT_ALLOWED = 8,
1920 GSM48_REJECT_MS_IDENTITY_NOT_DERVIVABLE = 9,
1921 GSM48_REJECT_IMPLICITLY_DETACHED = 10,
1922 GSM48_REJECT_GPRS_NOT_ALLOWED_IN_PLMN = 14,
1923 GSM48_REJECT_MSC_TMP_NOT_REACHABLE = 16,
1924};
1925
Neels Hofmeyraead2412018-04-06 04:31:00 +02001926extern const struct value_string gsm48_reject_value_names[];
1927static inline const char *gsm48_reject_value_name(enum gsm48_reject_value val)
1928{ return get_value_string(gsm48_reject_value_names, val); }
1929
Harald Welteec8b4502010-02-20 20:34:29 +01001930enum chreq_type {
1931 CHREQ_T_EMERG_CALL,
1932 CHREQ_T_CALL_REEST_TCH_F,
1933 CHREQ_T_CALL_REEST_TCH_H,
1934 CHREQ_T_CALL_REEST_TCH_H_DBL,
1935 CHREQ_T_SDCCH,
1936 CHREQ_T_TCH_F,
1937 CHREQ_T_VOICE_CALL_TCH_H,
1938 CHREQ_T_DATA_CALL_TCH_H,
1939 CHREQ_T_LOCATION_UPD,
1940 CHREQ_T_PAG_R_ANY_NECI0,
1941 CHREQ_T_PAG_R_ANY_NECI1,
1942 CHREQ_T_PAG_R_TCH_F,
1943 CHREQ_T_PAG_R_TCH_FH,
1944 CHREQ_T_LMU,
1945 CHREQ_T_RESERVED_SDCCH,
1946 CHREQ_T_RESERVED_IGNORE,
Alexander Couzensf48e8a82016-12-05 15:57:42 +01001947 CHREQ_T_PDCH_ONE_PHASE,
1948 CHREQ_T_PDCH_TWO_PHASE,
Alexander Couzens953f9292017-03-14 13:47:29 +01001949 _NUM_CHREQ_T,
Harald Welteec8b4502010-02-20 20:34:29 +01001950};
1951
1952/* Chapter 11.3 */
1953#define GSM48_T301 180, 0
1954#define GSM48_T303 30, 0
1955#define GSM48_T305 30, 0
1956#define GSM48_T306 30, 0
Harald Weltee50b0092018-01-27 09:40:34 +01001957#define GSM48_T308 10, 0 /* no spec default */
Harald Weltecd827102018-01-27 09:43:03 +01001958#define GSM48_T310 30, 0 /* no spec default */
Harald Weltee50b0092018-01-27 09:40:34 +01001959#define GSM48_T313 30, 0 /* no spec default */
Harald Welteec8b4502010-02-20 20:34:29 +01001960#define GSM48_T323 30, 0
Harald Weltee50b0092018-01-27 09:40:34 +01001961#define GSM48_T331 30, 0 /* no spec default */
1962#define GSM48_T333 30, 0 /* no spec default */
1963#define GSM48_T334 25, 0 /* min 15s */
1964#define GSM48_T338 30, 0 /* no spec default */
Andreas Eversberg014cb872010-07-12 09:11:00 +02001965#define GSM48_T303_MS 30, 0
1966#define GSM48_T305_MS 30, 0
1967#define GSM48_T308_MS 30, 0
1968#define GSM48_T310_MS 30, 0
1969#define GSM48_T313_MS 30, 0
1970#define GSM48_T323_MS 30, 0
1971#define GSM48_T332_MS 30, 0
1972#define GSM48_T335_MS 30, 0
Harald Welteec8b4502010-02-20 20:34:29 +01001973
1974/* Chapter 5.1.2.2 */
1975#define GSM_CSTATE_NULL 0
1976#define GSM_CSTATE_INITIATED 1
Andreas Eversberg1ef041f2010-04-09 07:52:12 +02001977#define GSM_CSTATE_MM_CONNECTION_PEND 2 /* see 10.5.4.6 */
Harald Welteec8b4502010-02-20 20:34:29 +01001978#define GSM_CSTATE_MO_CALL_PROC 3
1979#define GSM_CSTATE_CALL_DELIVERED 4
1980#define GSM_CSTATE_CALL_PRESENT 6
1981#define GSM_CSTATE_CALL_RECEIVED 7
1982#define GSM_CSTATE_CONNECT_REQUEST 8
1983#define GSM_CSTATE_MO_TERM_CALL_CONF 9
1984#define GSM_CSTATE_ACTIVE 10
1985#define GSM_CSTATE_DISCONNECT_REQ 12
1986#define GSM_CSTATE_DISCONNECT_IND 12
1987#define GSM_CSTATE_RELEASE_REQ 19
1988#define GSM_CSTATE_MO_ORIG_MODIFY 26
1989#define GSM_CSTATE_MO_TERM_MODIFY 27
1990#define GSM_CSTATE_CONNECT_IND 28
1991
1992#define SBIT(a) (1 << a)
1993#define ALL_STATES 0xffffffff
1994
1995/* Table 10.5.3/3GPP TS 04.08: Location Area Identification information element */
1996#define GSM_LAC_RESERVED_DETACHED 0x0
1997#define GSM_LAC_RESERVED_ALL_BTS 0xfffe
1998
1999/* GSM 04.08 Bearer Capability: Information Transfer Capability */
2000enum gsm48_bcap_itcap {
2001 GSM48_BCAP_ITCAP_SPEECH = 0,
2002 GSM48_BCAP_ITCAP_UNR_DIG_INF = 1,
2003 GSM48_BCAP_ITCAP_3k1_AUDIO = 2,
2004 GSM48_BCAP_ITCAP_FAX_G3 = 3,
2005 GSM48_BCAP_ITCAP_OTHER = 5,
2006 GSM48_BCAP_ITCAP_RESERVED = 7,
2007};
2008
2009/* GSM 04.08 Bearer Capability: Transfer Mode */
2010enum gsm48_bcap_tmod {
2011 GSM48_BCAP_TMOD_CIRCUIT = 0,
2012 GSM48_BCAP_TMOD_PACKET = 1,
2013};
2014
2015/* GSM 04.08 Bearer Capability: Coding Standard */
2016enum gsm48_bcap_coding {
2017 GSM48_BCAP_CODING_GSM_STD = 0,
2018};
2019
2020/* GSM 04.08 Bearer Capability: Radio Channel Requirements */
2021enum gsm48_bcap_rrq {
2022 GSM48_BCAP_RRQ_FR_ONLY = 1,
2023 GSM48_BCAP_RRQ_DUAL_HR = 2,
2024 GSM48_BCAP_RRQ_DUAL_FR = 3,
2025};
2026
Harald Weltec8a0b932012-08-24 21:27:26 +02002027/* GSM 04.08 Bearer Capability: Rate Adaption */
2028enum gsm48_bcap_ra {
2029 GSM48_BCAP_RA_NONE = 0,
2030 GSM48_BCAP_RA_V110_X30 = 1,
2031 GSM48_BCAP_RA_X31 = 2,
2032 GSM48_BCAP_RA_OTHER = 3,
2033};
2034
2035/* GSM 04.08 Bearer Capability: Signalling access protocol */
2036enum gsm48_bcap_sig_access {
2037 GSM48_BCAP_SA_I440_I450 = 1,
2038 GSM48_BCAP_SA_X21 = 2,
2039 GSM48_BCAP_SA_X28_DP_IN = 3,
2040 GSM48_BCAP_SA_X28_DP_UN = 4,
2041 GSM48_BCAP_SA_X28_NDP = 5,
2042 GSM48_BCAP_SA_X32 = 6,
2043};
2044
2045/* GSM 04.08 Bearer Capability: User Rate */
2046enum gsm48_bcap_user_rate {
2047 GSM48_BCAP_UR_300 = 1,
2048 GSM48_BCAP_UR_1200 = 2,
2049 GSM48_BCAP_UR_2400 = 3,
2050 GSM48_BCAP_UR_4800 = 4,
2051 GSM48_BCAP_UR_9600 = 5,
2052 GSM48_BCAP_UR_12000 = 6,
2053 GSM48_BCAP_UR_1200_75 = 7,
2054};
2055
2056/* GSM 04.08 Bearer Capability: Parity */
2057enum gsm48_bcap_parity {
2058 GSM48_BCAP_PAR_ODD = 0,
2059 GSM48_BCAP_PAR_EVEN = 2,
2060 GSM48_BCAP_PAR_NONE = 3,
2061 GSM48_BCAP_PAR_ZERO = 4,
2062 GSM48_BCAP_PAR_ONE = 5,
2063};
2064
2065/* GSM 04.08 Bearer Capability: Intermediate Rate */
2066enum gsm48_bcap_interm_rate {
2067 GSM48_BCAP_IR_8k = 2,
2068 GSM48_BCAP_IR_16k = 3,
2069};
2070
2071/* GSM 04.08 Bearer Capability: Transparency */
2072enum gsm48_bcap_transp {
2073 GSM48_BCAP_TR_TRANSP = 0,
2074 GSM48_BCAP_TR_RLP = 1,
2075 GSM48_BCAP_TR_TR_PREF = 2,
2076 GSM48_BCAP_TR_RLP_PREF = 3,
2077};
2078
2079/* GSM 04.08 Bearer Capability: Modem Type */
2080enum gsm48_bcap_modem_type {
2081 GSM48_BCAP_MT_NONE = 0,
2082 GSM48_BCAP_MT_V21 = 1,
2083 GSM48_BCAP_MT_V22 = 2,
2084 GSM48_BCAP_MT_V22bis = 3,
2085 GSM48_BCAP_MT_V23 = 4,
2086 GSM48_BCAP_MT_V26ter = 5,
2087 GSM48_BCAP_MT_V32 = 6,
2088 GSM48_BCAP_MT_UNDEF = 7,
2089 GSM48_BCAP_MT_AUTO_1 = 8,
2090};
2091
Neels Hofmeyr87e45502017-06-20 00:17:59 +02002092/*! GSM 04.08 Bearer Capability: Speech Version Indication
Philipp Maier3d9191e2017-05-31 17:22:03 +02002093 * (See also 3GPP TS 24.008, Table 10.5.103) */
Harald Welte30a8ec42012-08-24 23:00:05 +02002094enum gsm48_bcap_speech_ver {
Philipp Maiera9e193b2017-06-16 16:47:06 +02002095 GSM48_BCAP_SV_FR = 0, /*!< GSM FR V1 (GSM FR) */
2096 GSM48_BCAP_SV_HR = 1, /*!< GSM HR V1 (GSM HR) */
2097 GSM48_BCAP_SV_EFR = 2, /*!< GSM FR V2 (GSM EFR) */
2098 GSM48_BCAP_SV_AMR_F = 4, /*!< GSM FR V3 (FR AMR) */
2099 GSM48_BCAP_SV_AMR_H = 5, /*!< GSM HR V3 (HR_AMR) */
Philipp Maier3d9191e2017-05-31 17:22:03 +02002100 GSM48_BCAP_SV_AMR_OFW = 6, /*!< GSM FR V4 (OFR AMR-WB) */
2101 GSM48_BCAP_SV_AMR_OHW = 7, /*!< GSM HR V4 (OHR AMR-WB) */
2102 GSM48_BCAP_SV_AMR_FW = 8, /*!< GSM FR V5 (FR AMR-WB) */
2103 GSM48_BCAP_SV_AMR_OH = 11, /*!< GSM HR V6 (OHR AMR) */
Harald Welte30a8ec42012-08-24 23:00:05 +02002104};
2105
Harald Welteec8b4502010-02-20 20:34:29 +01002106#define GSM48_TMSI_LEN 5
2107#define GSM48_MID_TMSI_LEN (GSM48_TMSI_LEN + 2)
2108#define GSM48_MI_SIZE 32
2109
Maxff2eeda2018-01-04 18:43:44 +01002110/* 3GPP TS 24.008 ยง 10.5.5.15 Routing area identification */
Harald Weltea1c4f762010-05-01 11:59:42 +02002111struct gsm48_ra_id {
2112 uint8_t digits[3]; /* MCC + MNC BCD digits */
2113 uint16_t lac; /* Location Area Code */
2114 uint8_t rac; /* Routing Area Code */
2115} __attribute__ ((packed));
2116
Harald Welteb5503132011-05-24 15:01:53 +02002117#define GSM48_CELL_CHAN_DESC_SIZE 16
Harald Weltea1c4f762010-05-01 11:59:42 +02002118
Harald Welteb5503132011-05-24 15:01:53 +02002119#define GSM_MACBLOCK_LEN 23
2120#define GSM_MACBLOCK_PADDING 0x2b
Harald Welte55478082018-02-09 22:39:29 +01002121
2122/* Table 10.5.118 / 3GPP TS 24.008 Section 10.5.4.7 */
2123enum gsm48_type_of_number {
2124 GSM48_TON_UNKNOWN = 0,
2125 GSM48_TON_INTERNATIONAL = 1,
2126 GSM48_TON_NATIONAL = 2,
2127 GSM48_TON_NET_SPEC = 3,
2128 GSM48_TON_SHORT_CODE = 4,
2129 /* reserved */
2130};
2131
2132/* Table 10.5.118 / 3GPP TS 24.008 Section 10.5.4.7 */
2133enum gsm48_numbering_plan {
2134 GSM48_NPI_UNKNOWN = 0,
2135 GSM48_NPI_ISDN_E164 = 1,
2136 GSM48_NPI_DATA_X121 = 3,
2137 GSM48_NPI_TELEX_F69 = 4,
2138 GSM48_NPI_NATIONAL = 8,
2139 GSM48_NPI_PRIVATE = 9,
2140 GSM48_NPI_CTS = 11,
2141 /* reserved */
2142};