libosmogsm  0.9.6-9.20170220git32ee5af8.fc28
Osmocom GSM library
gsm_04_08.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include <stdbool.h>
5 
6 #include <osmocom/core/utils.h>
7 #include <osmocom/core/endian.h>
8 
9 /* GSM TS 04.08 definitions */
10 struct gsm_lchan;
11 
12 /* Chapter 10.5.1.5 */
14  uint8_t pwr_lev:3,
15  a5_1:1,
16  es_ind:1,
17  rev_lev:2,
18  spare:1;
19 } __attribute__ ((packed));
20 
21 /* Chapter 10.5.1.6 */
23  uint8_t pwr_lev:3,
24  a5_1:1,
25  es_ind:1,
26  rev_lev:2,
27  spare:1;
28  uint8_t fc:1,
29  vgcs:1,
30  vbs:1,
31  sm_cap:1,
32  ss_scr:2,
33  ps_cap:1,
34  spare2:1;
35  uint8_t a5_2:1,
36  a5_3:1,
37  cmsp:1,
38  solsa:1,
39  spare3:1,
40  lcsva_cap:1,
41  spare4:1,
42  cm3:1;
43 } __attribute__ ((packed));
44 
45 /* Chapter 10.5.2.1b.3 */
46 #if OSMO_IS_LITTLE_ENDIAN == 1
47 struct gsm48_range_1024 {
48  uint8_t w1_hi:2,
49  f0:1,
50  form_id:5;
51  uint8_t w1_lo;
52  uint8_t w2_hi;
53  uint8_t w3_hi:7,
54  w2_lo:1;
55  uint8_t w4_hi:6,
56  w3_lo:2;
57  uint8_t w5_hi:6,
58  w4_lo:2;
59  uint8_t w6_hi:6,
60  w5_lo:2;
61  uint8_t w7_hi:6,
62  w6_lo:2;
63  uint8_t w8_hi:6,
64  w7_lo:2;
65  uint8_t w9:7,
66  w8_lo:1;
67  uint8_t w11_hi:1,
68  w10:7;
69  uint8_t w12_hi:2,
70  w11_lo:6;
71  uint8_t w13_hi:3,
72  w12_lo:5;
73  uint8_t w14_hi:4,
74  w13_lo:4;
75  uint8_t w15_hi:5,
76  w14_lo:3;
77  uint8_t w16:6,
78  w15_lo:2;
79 } __attribute__ ((packed));
80 #else
82  uint8_t form_id:5,
83  f0:1,
84  w1_hi:2;
85  uint8_t w1_lo;
86  uint8_t w2_hi;
87  uint8_t w2_lo:1,
88  w3_hi:7;
89  uint8_t w3_lo:2,
90  w4_hi:6;
91  uint8_t w4_lo:2,
92  w5_hi:6;
93  uint8_t w5_lo:2,
94  w6_hi:6;
95  uint8_t w6_lo:2,
96  w7_hi:6;
97  uint8_t w7_lo:2,
98  w8_hi:6;
99  uint8_t w8_lo:1,
100  w9:7;
101  uint8_t w10:7,
102  w11_hi:1;
103  uint8_t w11_lo:6,
104  w12_hi:2;
105  uint8_t w12_lo:5,
106  w13_hi:3;
107  uint8_t w13_lo:4,
108  w14_hi:4;
109  uint8_t w14_lo:3,
110  w15_hi:5;
111  uint8_t w15_lo:2,
112  w16:6;
113 } __attribute__ ((packed));
114 #endif
115 
116 /* Chapter 10.5.2.1b.4 */
117 #if OSMO_IS_LITTLE_ENDIAN == 1
118 struct gsm48_range_512 {
119  uint8_t orig_arfcn_hi:1,
120  form_id:7;
121  uint8_t orig_arfcn_mid;
122  uint8_t w1_hi:7,
123  orig_arfcn_lo:1;
124  uint8_t w2_hi:6,
125  w1_lo:2;
126  uint8_t w3_hi:6,
127  w2_lo:2;
128  uint8_t w4_hi:6,
129  w3_lo:2;
130  uint8_t w5:7,
131  w4_lo:1;
132  uint8_t w7_hi:1,
133  w6:7;
134  uint8_t w8_hi:2,
135  w7_lo:6;
136  uint8_t w9_hi:4,
137  w8_lo:4;
138  uint8_t w10:6,
139  w9_lo:2;
140  uint8_t w12_hi:2,
141  w11:6;
142  uint8_t w13_hi:4,
143  w12_lo:4;
144  uint8_t w14:6,
145  w13_lo:2;
146  uint8_t w16_hi:2,
147  w15:6;
148  uint8_t w17:5,
149  w16_lo:3;
150 } __attribute__ ((packed));
151 #else
153  uint8_t form_id:7,
154  orig_arfcn_hi:1;
155  uint8_t orig_arfcn_mid;
156  uint8_t orig_arfcn_lo:1,
157  w1_hi:7;
158  uint8_t w1_lo:2,
159  w2_hi:6;
160  uint8_t w2_lo:2,
161  w3_hi:6;
162  uint8_t w3_lo:2,
163  w4_hi:6;
164  uint8_t w4_lo:1,
165  w5:7;
166  uint8_t w6:7,
167  w7_hi:1;
168  uint8_t w7_lo:6,
169  w8_hi:2;
170  uint8_t w8_lo:4,
171  w9_hi:4;
172  uint8_t w9_lo:2,
173  w10:6;
174  uint8_t w11:6,
175  w12_hi:2;
176  uint8_t w12_lo:4,
177  w13_hi:4;
178  uint8_t w13_lo:2,
179  w14:6;
180  uint8_t w15:6,
181  w16_hi:2;
182  uint8_t w16_lo:3,
183  w17:5;
184 } __attribute__ ((packed));
185 #endif
186 
187 /* Chapter 10.5.2.1b.5 */
188 #if OSMO_IS_LITTLE_ENDIAN == 1
189 struct gsm48_range_256 {
190  uint8_t orig_arfcn_hi:1,
191  form_id:7;
192  uint8_t orig_arfcn_mid;
193  uint8_t w1_hi:7,
194  orig_arfcn_lo:1;
195  uint8_t w2:7,
196  w1_lo:1;
197  uint8_t w4_hi:1,
198  w3:7;
199  uint8_t w5_hi:3,
200  w4_lo:5;
201  uint8_t w6_hi:5,
202  w5_lo:3;
203  uint8_t w8_hi:1,
204  w7:6,
205  w6_lo:1;
206  uint8_t w9_hi:4,
207  w8_lo:4;
208  uint8_t w11_hi:2,
209  w10:5,
210  w9_lo:1;
211  uint8_t w12:5,
212  w11_lo:3;
213  uint8_t w14_hi:3,
214  w13:5;
215  uint8_t w16_hi:1,
216  w15:5,
217  w14_lo:2;
218  uint8_t w18_hi:1,
219  w17:4,
220  w16_lo:3;
221  uint8_t w20_hi:1,
222  w19:4,
223  w18_lo:3;
224  uint8_t spare:1,
225  w21:4,
226  w20_lo:3;
227 } __attribute__ ((packed));
228 #else
230  uint8_t form_id:7,
231  orig_arfcn_hi:1;
232  uint8_t orig_arfcn_mid;
233  uint8_t orig_arfcn_lo:1,
234  w1_hi:7;
235  uint8_t w1_lo:1,
236  w2:7;
237  uint8_t w3:7,
238  w4_hi:1;
239  uint8_t w4_lo:5,
240  w5_hi:3;
241  uint8_t w5_lo:3,
242  w6_hi:5;
243  uint8_t w6_lo:1,
244  w7:6,
245  w8_hi:1;
246  uint8_t w8_lo:4,
247  w9_hi:4;
248  uint8_t w9_lo:1,
249  w10:5,
250  w11_hi:2;
251  uint8_t w11_lo:3,
252  w12:5;
253  uint8_t w13:5,
254  w14_hi:3;
255  uint8_t w14_lo:2,
256  w15:5,
257  w16_hi:1;
258  uint8_t w16_lo:3,
259  w17:4,
260  w18_hi:1;
261  uint8_t w18_lo:3,
262  w19:4,
263  w20_hi:1;
264  uint8_t w20_lo:3,
265  w21:4,
266  spare:1;
267 } __attribute__ ((packed));
268 #endif
269 
270 /* Chapter 10.5.2.1b.6 */
271 #if OSMO_IS_LITTLE_ENDIAN == 1
272 struct gsm48_range_128 {
273  uint8_t orig_arfcn_hi:1,
274  form_id:7;
275  uint8_t orig_arfcn_mid;
276  uint8_t w1:7,
277  orig_arfcn_lo:1;
278  uint8_t w3_hi:2,
279  w2:6;
280  uint8_t w4_hi:4,
281  w3_lo:4;
282  uint8_t w6_hi:2,
283  w5:5,
284  w4_lo:1;
285  uint8_t w7:5,
286  w6_lo:3;
287  uint8_t w9:4,
288  w8:4;
289  uint8_t w11:4,
290  w10:4;
291  uint8_t w13:4,
292  w12:4;
293  uint8_t w15:4,
294  w14:4;
295  uint8_t w18_hi:2,
296  w17:3,
297  w16:3;
298  uint8_t w21_hi:1,
299  w20:3,
300  w19:3,
301  w18_lo:1;
302  uint8_t w23:3,
303  w22:3,
304  w21_lo:2;
305  uint8_t w26_hi:2,
306  w25:3,
307  w24:3;
308  uint8_t spare:1,
309  w28:3,
310  w27:3,
311  w26_lo:1;
312 } __attribute__ ((packed));
313 #else
315  uint8_t form_id:7,
316  orig_arfcn_hi:1;
317  uint8_t orig_arfcn_mid;
318  uint8_t orig_arfcn_lo:1,
319  w1:7;
320  uint8_t w2:6,
321  w3_hi:2;
322  uint8_t w3_lo:4,
323  w4_hi:4;
324  uint8_t w4_lo:1,
325  w5:5,
326  w6_hi:2;
327  uint8_t w6_lo:3,
328  w7:5;
329  uint8_t w8:4,
330  w9:4;
331  uint8_t w10:4,
332  w11:4;
333  uint8_t w12:4,
334  w13:4;
335  uint8_t w14:4,
336  w15:4;
337  uint8_t w16:3,
338  w17:3,
339  w18_hi:2;
340  uint8_t w18_lo:1,
341  w19:3,
342  w20:3,
343  w21_hi:1;
344  uint8_t w21_lo:2,
345  w22:3,
346  w23:3;
347  uint8_t w24:3,
348  w25:3,
349  w26_hi:2;
350  uint8_t w26_lo:1,
351  w27:3,
352  w28:3,
353  spare:1;
354 } __attribute__ ((packed));
355 #endif
356 
357 /* Chapter 10.5.2.1b.7 */
359  uint8_t orig_arfcn_hi:1,
360  form_id:7;
361  uint8_t orig_arfcn_mid;
362  uint8_t rrfcn1_7:7,
363  orig_arfcn_lo:1;
364  uint8_t rrfcn8_111[13];
365 } __attribute__ ((packed));
366 
367 /* Chapter 10.5.2.5 */
369  uint8_t chan_nr;
370  union {
371  struct {
372  uint8_t maio_high:4,
373  h:1,
374  tsc:3;
375  uint8_t hsn:6,
376  maio_low:2;
377  } __attribute__ ((packed)) h1;
378  struct {
379  uint8_t arfcn_high:2,
380  spare:2,
381  h:1,
382  tsc:3;
383  uint8_t arfcn_low;
384  } __attribute__ ((packed)) h0;
385  } __attribute__ ((packed));
386 } __attribute__ ((packed));
387 
388 /* Chapter 10.5.2.20 */
390  uint8_t rxlev_full:6,
391  dtx_used:1,
392  ba_used:1;
393  uint8_t rxlev_sub:6,
394  meas_valid:1,
395  spare:1;
396  uint8_t no_nc_n_hi:1,
397  rxqual_sub:3,
398  rxqual_full:3,
399  spare2:1;
400  uint8_t rxlev_nc1:6,
401  no_nc_n_lo:2;
402  uint8_t bsic_nc1_hi:3,
403  bcch_f_nc1:5;
404  uint8_t rxlev_nc2_hi:5,
405  bsic_nc1_lo:3;
406  uint8_t bsic_nc2_hi:2,
407  bcch_f_nc2:5,
408  rxlev_nc2_lo:1;
409  uint8_t rxlev_nc3_hi:4,
410  bsic_nc2_lo:4;
411  uint8_t bsic_nc3_hi:1,
412  bcch_f_nc3:5,
413  rxlev_nc3_lo:2;
414  uint8_t rxlev_nc4_hi:3,
415  bsic_nc3_lo:5;
416  uint8_t bcch_f_nc4:5,
417  rxlev_nc4_lo:3;
418  uint8_t rxlev_nc5_hi:2,
419  bsic_nc4:6;
420  uint8_t bcch_f_nc5_hi:4,
421  rxlev_nc5_lo:4;
422  uint8_t rxlev_nc6_hi:1,
423  bsic_nc5:6,
424  bcch_f_nc5_lo:1;
425  uint8_t bcch_f_nc6_hi:3,
426  rxlev_nc6_lo:5;
427  uint8_t bsic_nc6:6,
428  bcch_f_nc6_lo:2;
429 } __attribute__ ((packed));
430 
431 /* Chapter 10.5.2.21aa */
433  uint8_t smod : 2,
434  spare: 1,
435  icmi : 1,
436  nscb : 1,
437  ver : 3;
438  uint8_t m4_75 : 1,
439  m5_15 : 1,
440  m5_90 : 1,
441  m6_70 : 1,
442  m7_40 : 1,
443  m7_95 : 1,
444  m10_2 : 1,
445  m12_2 : 1;
446 } __attribute__((packed));
447 
448 /* Chapter 10.5.2.28(a) */
450  uint8_t power_level:5,
451  spare:2,
452  atc:1;
453 } __attribute__((packed));
454 
455 /* Chapter 10.5.2.29 */
457  uint8_t re :1,
458  cell_bar :1,
459  tx_integer :4,
460  max_trans :2;
461  uint8_t t2;
462  uint8_t t3;
463 } __attribute__ ((packed));
464 
465 
466 /* Chapter 10.5.2.30 */
468  uint8_t ra;
469  uint8_t t3_high:3,
470  t1:5;
471  uint8_t t2:5,
472  t3_low:3;
473 } __attribute__ ((packed));
474 
475 /* Chapter 10.5.2.38 */
477  uint8_t t3_high:3,
478  t1:5;
479  uint8_t t2:5,
480  t3_low:3;
481 } __attribute__ ((packed));
482 
483 /* Chapter 10.5.2.39 */
485  uint8_t si:2,
486  rot:1,
487  nci:1,
488  sync_ie:4;
489 } __attribute__((packed));
490 
491 /*
492  * Chapter 9.1.5/9.1.6
493  *
494  * For 9.1.6 the chan_desc has the meaning of 10.5.2.5a
495  */
497  struct gsm48_chan_desc chan_desc;
498  uint8_t mode;
499 } __attribute__ ((packed));
500 
501 enum gsm48_chan_mode {
502  GSM48_CMODE_SIGN = 0x00,
503  GSM48_CMODE_SPEECH_V1 = 0x01,
504  GSM48_CMODE_SPEECH_EFR = 0x21,
505  GSM48_CMODE_SPEECH_AMR = 0x41,
506  GSM48_CMODE_DATA_14k5 = 0x0f,
507  GSM48_CMODE_DATA_12k0 = 0x03,
508  GSM48_CMODE_DATA_6k0 = 0x0b,
509  GSM48_CMODE_DATA_3k6 = 0x13,
510 };
511 
512 extern const struct value_string gsm48_chan_mode_names[];
513 
514 /* Chapter 9.1.2 */
516  /* Semantic is from 10.5.2.5a */
517  struct gsm48_chan_desc chan_desc;
518  uint8_t power_command;
519  uint8_t data[0];
520 } __attribute__((packed));
521 
522 /* Chapter 9.1.13 */
524  /* Semantic is from 10.5.2.5a */
525  struct gsm48_chan_desc chan_desc;
526  uint8_t mob_alloc_len;
527  uint8_t mob_alloc[0];
528 } __attribute__((packed));
529 
530 /* Chapter 10.5.2.2 */
532  uint8_t bcc:3,
533  ncc:3,
534  arfcn_hi:2;
535  uint8_t arfcn_lo;
536 } __attribute__((packed));
537 
538 /* Chapter 9.1.15 */
539 struct gsm48_ho_cmd {
540  struct gsm48_cell_desc cell_desc;
541  struct gsm48_chan_desc chan_desc;
542  uint8_t ho_ref;
543  uint8_t power_command;
544  uint8_t data[0];
545 } __attribute__((packed));
546 
547 /* Chapter 9.1.18 */
549  uint8_t l2_plen;
550  uint8_t proto_discr;
551  uint8_t msg_type;
552  uint8_t page_mode;
553  struct gsm48_chan_desc chan_desc;
554  struct gsm48_req_ref req_ref;
555  uint8_t timing_advance;
556  uint8_t mob_alloc_len;
557  uint8_t mob_alloc[0];
558 } __attribute__ ((packed));
559 
560 /* Chapter 9.1.25 */
562  uint8_t spare:4,
563  key_seq:4;
564  uint32_t classmark2;
565  uint8_t mi_len;
566  uint8_t mi[0];
567 } __attribute__ ((packed));
568 
569 /* Chapter 10.5.1.3 */
571  uint8_t digits[3]; /* BCD! */
572  uint16_t lac;
573 } __attribute__ ((packed));
574 
575 /* Section 9.2.2 */
577  uint8_t key_seq:4,
578  spare:4;
579  uint8_t rand[16];
580 } __attribute__ ((packed));
581 
582 /* Section 9.2.3 */
584  uint8_t sres[4];
585 } __attribute__ ((packed));
586 
587 /* Section 9.2.15 */
589  uint8_t type:4,
590  key_seq:4;
591  struct gsm48_loc_area_id lai;
592  struct gsm48_classmark1 classmark1;
593  uint8_t mi_len;
594  uint8_t mi[0];
595 } __attribute__ ((packed));
596 
597 /* Section 10.1 */
598 struct gsm48_hdr {
599  uint8_t proto_discr;
600  uint8_t msg_type;
601  uint8_t data[0];
602 } __attribute__ ((packed));
603 
604 /* Section 9.1.3x System information Type header */
606  uint8_t l2_plen;
607  uint8_t rr_protocol_discriminator :4,
608  skip_indicator:4;
609  uint8_t system_information;
610 } __attribute__ ((packed));
611 
612 /* Section 10.5.2.4 Cell Selection Parameters */
614  uint8_t ms_txpwr_max_ccch:5, /* GSM 05.08 MS-TXPWR-MAX-CCCH */
615  cell_resel_hyst:3; /* GSM 05.08 CELL-RESELECT-HYSTERESIS */
616  uint8_t rxlev_acc_min:6, /* GSM 05.08 RXLEV-ACCESS-MIN */
617  neci:1,
618  acs:1;
619 } __attribute__ ((packed));
620 
621 /* Section 10.5.2.11 Control Channel Description , Figure 10.5.33 */
623  uint8_t ccch_conf :3,
624  bs_ag_blks_res :3,
625  att :1,
626  spare1 :1;
627  uint8_t bs_pa_mfrms : 3,
628  spare2 :5;
629  uint8_t t3212;
630 } __attribute__ ((packed));
631 
632 enum gsm48_dtx_mode {
633  GSM48_DTX_MAY_BE_USED,
634  GSM48_DTX_SHALL_BE_USED,
635  GSM48_DTX_SHALL_NOT_BE_USED
636 };
637 
638 /* Cell Options for SI6, SACCH (10.5.2.3a.2) or SI3, BCCH (Table 10.5.2.3.1),
639  3GPP TS 44.018 */
641  uint8_t radio_link_timeout:4,
642  dtx:2,
643  pwrc:1,
644  /* either DN-IND or top bit of DTX IND */
645  d:1;
646 } __attribute__ ((packed));
647 
648 /* Section 9.2.9 CM service request */
650  uint8_t cm_service_type : 4,
651  cipher_key_seq : 4;
652  /* length + 3 bytes */
653  uint32_t classmark;
654  uint8_t mi_len;
655  uint8_t mi[0];
656  /* optional priority level */
657 } __attribute__ ((packed));
658 
659 /* Section 9.1.31 System information Type 1 */
662  uint8_t cell_channel_description[16];
663  struct gsm48_rach_control rach_control;
664  uint8_t rest_octets[0]; /* NCH position on the CCCH */
665 } __attribute__ ((packed));
666 
667 /* Section 9.1.32 System information Type 2 */
670  uint8_t bcch_frequency_list[16];
671  uint8_t ncc_permitted;
672  struct gsm48_rach_control rach_control;
673 } __attribute__ ((packed));
674 
675 /* Section 9.1.33 System information Type 2bis */
678  uint8_t bcch_frequency_list[16];
679  struct gsm48_rach_control rach_control;
680  uint8_t rest_octets[0];
681 } __attribute__ ((packed));
682 
683 /* Section 9.1.34 System information Type 2ter */
686  uint8_t ext_bcch_frequency_list[16];
687  uint8_t rest_octets[0];
688 } __attribute__ ((packed));
689 
690 /* Section 9.1.34a System information Type 2quater */
693  uint8_t rest_octets[0];
694 } __attribute__ ((packed));
695 
696 /* Section 9.1.35 System information Type 3 */
699  uint16_t cell_identity;
700  struct gsm48_loc_area_id lai;
701  struct gsm48_control_channel_descr control_channel_desc;
702  struct gsm48_cell_options cell_options;
703  struct gsm48_cell_sel_par cell_sel_par;
704  struct gsm48_rach_control rach_control;
705  uint8_t rest_octets[0];
706 } __attribute__ ((packed));
707 
708 /* Section 9.1.36 System information Type 4 */
711  struct gsm48_loc_area_id lai;
712  struct gsm48_cell_sel_par cell_sel_par;
713  struct gsm48_rach_control rach_control;
714  /* optional CBCH conditional CBCH... followed by
715  mandantory SI 4 Reset Octets
716  */
717  uint8_t data[0];
718 } __attribute__ ((packed));
719 
720 /* Section 9.1.37 System information Type 5 */
722  uint8_t rr_protocol_discriminator :4,
723  skip_indicator:4;
724  uint8_t system_information;
725  uint8_t bcch_frequency_list[16];
726 } __attribute__ ((packed));
727 
728 /* Section 9.1.38 System information Type 5bis */
730  uint8_t rr_protocol_discriminator :4,
731  skip_indicator:4;
732  uint8_t system_information;
733  uint8_t bcch_frequency_list[16];
734 } __attribute__ ((packed));
735 
736 /* Section 9.1.39 System information Type 5ter */
738  uint8_t rr_protocol_discriminator :4,
739  skip_indicator:4;
740  uint8_t system_information;
741  uint8_t bcch_frequency_list[16];
742 } __attribute__ ((packed));
743 
744 /* Section 9.1.40 System information Type 6 */
746  uint8_t rr_protocol_discriminator :4,
747  skip_indicator:4;
748  uint8_t system_information;
749  uint16_t cell_identity;
750  struct gsm48_loc_area_id lai;
751  struct gsm48_cell_options cell_options;
752  uint8_t ncc_permitted;
753  uint8_t rest_octets[0];
754 } __attribute__ ((packed));
755 
756 /* Section 9.1.43a System Information type 13 */
759  uint8_t rest_octets[0];
760 } __attribute__ ((packed));
761 
762 /* Section 9.2.12 IMSI Detach Indication */
764  struct gsm48_classmark1 classmark1;
765  uint8_t mi_len;
766  uint8_t mi[0];
767 } __attribute__ ((packed));
768 
769 /* Section 9.1.1 */
771  /* Semantic is from 10.5.2.5 */
772  struct gsm48_chan_desc chan_desc;
773  uint8_t data[0];
774 } __attribute__((packed));
775 
776 /* Section 9.1.3 */
778  uint8_t rr_cause;
779 } __attribute__((packed));
780 
781 /* Section 9.1.4 */
783  uint8_t rr_cause;
784 } __attribute__((packed));
785 
786 /* Section 9.1.3 */
787 struct gsm48_ho_cpl {
788  uint8_t rr_cause;
789  uint8_t data[0];
790 } __attribute__((packed));
791 
792 /* Section 9.1.4 */
794  uint8_t rr_cause;
795 } __attribute__((packed));
796 
797 /* Section 9.1.7 */
799  uint8_t rr_cause;
800  uint8_t data[0];
801 } __attribute__((packed));
802 
803 /* Section 9.1.9 */
805  uint8_t sc:1,
806  alg_id:3,
807  cr:1,
808  spare:3;
809 } __attribute__((packed));
810 
811 /* Section 9.1.11 */
813  uint8_t cm2_len;
814  struct gsm48_classmark2 cm2;
815  uint8_t data[0];
816 } __attribute__((packed));
817 
818 /* Section 9.1.19 */
820  uint8_t l2_plen;
821  uint8_t proto_discr;
822  uint8_t msg_type;
823  uint8_t page_mode;
824  struct gsm48_chan_desc chan_desc1;
825  struct gsm48_req_ref req_ref1;
826  uint8_t timing_advance1;
827  struct gsm48_chan_desc chan_desc2;
828  struct gsm48_req_ref req_ref2;
829  uint8_t timing_advance2;
830  uint8_t mob_alloc_len;
831  uint8_t mob_alloc[0];
832 } __attribute__ ((packed));
833 
834 /* Section 9.1.20 */
836  uint8_t l2_plen;
837  uint8_t proto_discr;
838  uint8_t msg_type;
839  uint8_t page_mode;
840  struct gsm48_req_ref req_ref1;
841  uint8_t wait_ind1;
842  struct gsm48_req_ref req_ref2;
843  uint8_t wait_ind2;
844  struct gsm48_req_ref req_ref3;
845  uint8_t wait_ind3;
846  struct gsm48_req_ref req_ref4;
847  uint8_t wait_ind4;
848  uint8_t rest[0];
849 } __attribute__ ((packed));
850 
851 /* Section 9.1.22 */
853  uint8_t l2_plen;
854  uint8_t proto_discr;
855  uint8_t msg_type;
856  uint8_t pag_mode:2,
857  spare:2,
858  cneed1:2,
859  cneed2:2;
860  uint8_t data[0];
861 } __attribute__((packed));
862 
863 /* Section 9.1.23 */
865  uint8_t l2_plen;
866  uint8_t proto_discr;
867  uint8_t msg_type;
868  uint8_t pag_mode:2,
869  spare:2,
870  cneed1:2,
871  cneed2:2;
872  uint32_t tmsi1;
873  uint32_t tmsi2;
874  uint8_t data[0];
875 } __attribute__((packed));
876 
877 /* Section 9.1.24 */
879  uint8_t l2_plen;
880  uint8_t proto_discr;
881  uint8_t msg_type;
882  uint8_t pag_mode:2,
883  spare:2,
884  cneed1:2,
885  cneed2:2;
886  uint32_t tmsi1;
887  uint32_t tmsi2;
888  uint32_t tmsi3;
889  uint32_t tmsi4;
890  uint8_t cneed3:2,
891  cneed4:2,
892  spare2:4;
893  uint8_t rest[0];
894 } __attribute__((packed));
895 
896 /* Section 9.1.25 */
898  uint8_t key_seq:3,
899  spare:5;
900  uint8_t cm2_len;
901  struct gsm48_classmark2 cm2;
902  uint8_t data[0];
903 } __attribute__((packed));
904 
905 /* Section 9.1.29 */
907  uint8_t rr_cause;
908 } __attribute__((packed));
909 
910 /* Section 10.2 + GSM 04.07 12.2.3.1.1 */
911 #define GSM48_PDISC_GROUP_CC 0x00
912 #define GSM48_PDISC_BCAST_CC 0x01
913 #define GSM48_PDISC_PDSS1 0x02
914 #define GSM48_PDISC_CC 0x03
915 #define GSM48_PDISC_PDSS2 0x04
916 #define GSM48_PDISC_MM 0x05
917 #define GSM48_PDISC_RR 0x06
918 #define GSM48_PDISC_MM_GPRS 0x08
919 #define GSM48_PDISC_SMS 0x09
920 #define GSM48_PDISC_SM_GPRS 0x0a
921 #define GSM48_PDISC_NC_SS 0x0b
922 #define GSM48_PDISC_LOC 0x0c
923 #define GSM48_PDISC_EXTEND 0x0e
924 #define GSM48_PDISC_MASK 0x0f
925 #define GSM48_PDISC_USSD 0x11
926 
927 bool gsm48_hdr_gmm_cipherable(const struct gsm48_hdr *hdr);
928 
929 static inline uint8_t gsm48_hdr_pdisc(const struct gsm48_hdr *hdr)
930 {
931  /*
932  * 3GPP TS 24.007 version 12.0.0 Release 12,
933  * 11.2.3.1.1 Protocol discriminator
934  */
935  uint8_t pdisc = hdr->proto_discr & GSM48_PDISC_MASK;
936  if (pdisc == GSM48_PDISC_EXTEND)
937  return hdr->proto_discr;
938  return pdisc;
939 }
940 
941 static inline uint8_t gsm48_hdr_trans_id(const struct gsm48_hdr *hdr)
942 {
943  /*
944  * 3GPP TS 24.007 version 12.0.0 Release 12,
945  * 11.2.3.1.3 Transaction identifier
946  */
947  return (hdr->proto_discr & 0xf0) >> 4;
948 }
949 
950 #define GSM48_TA_INVALID 220
951 
957 static inline bool gsm48_ta_is_valid(uint8_t ta)
958 {
959  return (ta < 64);
960 }
961 
962 static inline uint8_t gsm48_hdr_trans_id_flip_ti(const struct gsm48_hdr *hdr)
963 {
964  return gsm48_hdr_trans_id(hdr) ^ 0x08;
965 }
966 
967 static inline uint8_t gsm48_hdr_trans_id_no_ti(const struct gsm48_hdr *hdr)
968 {
969  return gsm48_hdr_trans_id(hdr) & 0x07;
970 }
971 
972 static inline uint8_t gsm48_hdr_msg_type_r98(const struct gsm48_hdr *hdr)
973 {
974  /*
975  * 3GPP TS 24.007 version 12.0.0 Release 12,
976  * 11.2.3.2.1 Message type octet (when accessing Release 98 and older
977  * networks only)
978  */
979  switch (gsm48_hdr_pdisc(hdr)) {
980  case GSM48_PDISC_MM:
981  case GSM48_PDISC_CC:
982  case GSM48_PDISC_NC_SS:
983  case GSM48_PDISC_GROUP_CC:
984  case GSM48_PDISC_BCAST_CC:
985  case GSM48_PDISC_LOC:
986  return hdr->msg_type & 0xbf;
987  default:
988  return hdr->msg_type;
989  }
990 }
991 
992 static inline uint8_t gsm48_hdr_msg_type_r99(const struct gsm48_hdr *hdr)
993 {
994  /*
995  * 3GPP TS 24.007 version 12.0.0 Release 12,
996  * 11.2.3.2.2 Message type octet (when accessing Release 99 and newer
997  * networks)
998  */
999  switch (gsm48_hdr_pdisc(hdr)) {
1000  case GSM48_PDISC_MM:
1001  case GSM48_PDISC_CC:
1002  return hdr->msg_type & 0x3f;
1003  case GSM48_PDISC_NC_SS:
1004  case GSM48_PDISC_GROUP_CC:
1005  case GSM48_PDISC_BCAST_CC:
1006  case GSM48_PDISC_LOC:
1007  return hdr->msg_type & 0xbf;
1008  default:
1009  return hdr->msg_type;
1010  }
1011 }
1012 
1013 void gsm48_set_dtx(struct gsm48_cell_options *op, enum gsm48_dtx_mode full,
1014  enum gsm48_dtx_mode half, bool is_bcch);
1015 
1016 #define gsm48_hdr_msg_type gsm48_hdr_msg_type_r99
1017 
1018 /* Section 10.4 */
1019 #define GSM48_MT_RR_INIT_REQ 0x3c
1020 #define GSM48_MT_RR_ADD_ASS 0x3b
1021 #define GSM48_MT_RR_IMM_ASS 0x3f
1022 #define GSM48_MT_RR_IMM_ASS_EXT 0x39
1023 #define GSM48_MT_RR_IMM_ASS_REJ 0x3a
1024 #define GSM48_MT_RR_DTM_ASS_FAIL 0x48
1025 #define GSM48_MT_RR_DTM_REJECT 0x49
1026 #define GSM48_MT_RR_DTM_REQUEST 0x4A
1027 #define GSM48_MT_RR_PACKET_ASS 0x4B
1028 
1029 #define GSM48_MT_RR_CIPH_M_CMD 0x35
1030 #define GSM48_MT_RR_CIPH_M_COMPL 0x32
1031 
1032 #define GSM48_MT_RR_CFG_CHG_CMD 0x30
1033 #define GSM48_MT_RR_CFG_CHG_ACK 0x31
1034 #define GSM48_MT_RR_CFG_CHG_REJ 0x33
1035 
1036 #define GSM48_MT_RR_ASS_CMD 0x2e
1037 #define GSM48_MT_RR_ASS_COMPL 0x29
1038 #define GSM48_MT_RR_ASS_FAIL 0x2f
1039 #define GSM48_MT_RR_HANDO_CMD 0x2b
1040 #define GSM48_MT_RR_HANDO_COMPL 0x2c
1041 #define GSM48_MT_RR_HANDO_FAIL 0x28
1042 #define GSM48_MT_RR_HANDO_INFO 0x2d
1043 #define GSM48_MT_RR_HANDO_INFO 0x2d
1044 #define GSM48_MT_RR_DTM_ASS_CMD 0x4c
1045 
1046 #define GSM48_MT_RR_CELL_CHG_ORDER 0x08
1047 #define GSM48_MT_RR_PDCH_ASS_CMD 0x23
1048 
1049 #define GSM48_MT_RR_CHAN_REL 0x0d
1050 #define GSM48_MT_RR_PART_REL 0x0a
1051 #define GSM48_MT_RR_PART_REL_COMP 0x0f
1052 
1053 #define GSM48_MT_RR_PAG_REQ_1 0x21
1054 #define GSM48_MT_RR_PAG_REQ_2 0x22
1055 #define GSM48_MT_RR_PAG_REQ_3 0x24
1056 #define GSM48_MT_RR_PAG_RESP 0x27
1057 #define GSM48_MT_RR_NOTIF_NCH 0x20
1058 #define GSM48_MT_RR_NOTIF_FACCH 0x25 /* (Reserved) */
1059 #define GSM48_MT_RR_NOTIF_RESP 0x26
1060 #define GSM48_MT_RR_PACKET_NOTIF 0x4e
1061 #define GSM48_MT_RR_UTRAN_CLSM_CHG 0x60
1062 #define GSM48_MT_RR_CDMA2K_CLSM_CHG 0x62
1063 #define GSM48_MT_RR_IS_TO_UTRAN_HANDO 0x63
1064 #define GSM48_MT_RR_IS_TO_CDMA2K_HANDO 0x64
1065 
1066 #define GSM48_MT_RR_SYSINFO_8 0x18
1067 #define GSM48_MT_RR_SYSINFO_1 0x19
1068 #define GSM48_MT_RR_SYSINFO_2 0x1a
1069 #define GSM48_MT_RR_SYSINFO_3 0x1b
1070 #define GSM48_MT_RR_SYSINFO_4 0x1c
1071 #define GSM48_MT_RR_SYSINFO_5 0x1d
1072 #define GSM48_MT_RR_SYSINFO_6 0x1e
1073 #define GSM48_MT_RR_SYSINFO_7 0x1f
1074 
1075 #define GSM48_MT_RR_SYSINFO_2bis 0x02
1076 #define GSM48_MT_RR_SYSINFO_2ter 0x03
1077 #define GSM48_MT_RR_SYSINFO_2quater 0x07
1078 #define GSM48_MT_RR_SYSINFO_5bis 0x05
1079 #define GSM48_MT_RR_SYSINFO_5ter 0x06
1080 #define GSM48_MT_RR_SYSINFO_9 0x04
1081 #define GSM48_MT_RR_SYSINFO_13 0x00
1082 
1083 #define GSM48_MT_RR_SYSINFO_16 0x3d
1084 #define GSM48_MT_RR_SYSINFO_17 0x3e
1085 
1086 #define GSM48_MT_RR_SYSINFO_18 0x40
1087 #define GSM48_MT_RR_SYSINFO_19 0x41
1088 #define GSM48_MT_RR_SYSINFO_20 0x42
1089 
1090 #define GSM48_MT_RR_CHAN_MODE_MODIF 0x10
1091 #define GSM48_MT_RR_STATUS 0x12
1092 #define GSM48_MT_RR_CHAN_MODE_MODIF_ACK 0x17
1093 #define GSM48_MT_RR_FREQ_REDEF 0x14
1094 #define GSM48_MT_RR_MEAS_REP 0x15
1095 #define GSM48_MT_RR_CLSM_CHG 0x16
1096 #define GSM48_MT_RR_CLSM_ENQ 0x13
1097 #define GSM48_MT_RR_EXT_MEAS_REP 0x36
1098 #define GSM48_MT_RR_EXT_MEAS_REP_ORD 0x37
1099 #define GSM48_MT_RR_GPRS_SUSP_REQ 0x34
1100 #define GSM48_MT_RR_DTM_INFO 0x4d
1101 
1102 #define GSM48_MT_RR_VGCS_UPL_GRANT 0x09
1103 #define GSM48_MT_RR_UPLINK_RELEASE 0x0e
1104 #define GSM48_MT_RR_UPLINK_FREE 0x0c
1105 #define GSM48_MT_RR_UPLINK_BUSY 0x2a
1106 #define GSM48_MT_RR_TALKER_IND 0x11
1107 
1108 #define GSM48_MT_RR_APP_INFO 0x38
1109 
1110 /* Table 10.2/3GPP TS 04.08 */
1111 #define GSM48_MT_MM_IMSI_DETACH_IND 0x01
1112 #define GSM48_MT_MM_LOC_UPD_ACCEPT 0x02
1113 #define GSM48_MT_MM_LOC_UPD_REJECT 0x04
1114 #define GSM48_MT_MM_LOC_UPD_REQUEST 0x08
1115 
1116 #define GSM48_MT_MM_AUTH_REJ 0x11
1117 #define GSM48_MT_MM_AUTH_REQ 0x12
1118 #define GSM48_MT_MM_AUTH_RESP 0x14
1119 #define GSM48_MT_MM_AUTH_FAIL 0x1c
1120 #define GSM48_MT_MM_ID_REQ 0x18
1121 #define GSM48_MT_MM_ID_RESP 0x19
1122 #define GSM48_MT_MM_TMSI_REALL_CMD 0x1a
1123 #define GSM48_MT_MM_TMSI_REALL_COMPL 0x1b
1124 
1125 #define GSM48_MT_MM_CM_SERV_ACC 0x21
1126 #define GSM48_MT_MM_CM_SERV_REJ 0x22
1127 #define GSM48_MT_MM_CM_SERV_ABORT 0x23
1128 #define GSM48_MT_MM_CM_SERV_REQ 0x24
1129 #define GSM48_MT_MM_CM_SERV_PROMPT 0x25
1130 #define GSM48_MT_MM_CM_REEST_REQ 0x28
1131 #define GSM48_MT_MM_ABORT 0x29
1132 
1133 #define GSM48_MT_MM_NULL 0x30
1134 #define GSM48_MT_MM_STATUS 0x31
1135 #define GSM48_MT_MM_INFO 0x32
1136 
1137 /* Table 10.3/3GPP TS 04.08 */
1138 #define GSM48_MT_CC_ALERTING 0x01
1139 #define GSM48_MT_CC_CALL_CONF 0x08
1140 #define GSM48_MT_CC_CALL_PROC 0x02
1141 #define GSM48_MT_CC_CONNECT 0x07
1142 #define GSM48_MT_CC_CONNECT_ACK 0x0f
1143 #define GSM48_MT_CC_EMERG_SETUP 0x0e
1144 #define GSM48_MT_CC_PROGRESS 0x03
1145 #define GSM48_MT_CC_ESTAB 0x04
1146 #define GSM48_MT_CC_ESTAB_CONF 0x06
1147 #define GSM48_MT_CC_RECALL 0x0b
1148 #define GSM48_MT_CC_START_CC 0x09
1149 #define GSM48_MT_CC_SETUP 0x05
1150 
1151 #define GSM48_MT_CC_MODIFY 0x17
1152 #define GSM48_MT_CC_MODIFY_COMPL 0x1f
1153 #define GSM48_MT_CC_MODIFY_REJECT 0x13
1154 #define GSM48_MT_CC_USER_INFO 0x10
1155 #define GSM48_MT_CC_HOLD 0x18
1156 #define GSM48_MT_CC_HOLD_ACK 0x19
1157 #define GSM48_MT_CC_HOLD_REJ 0x1a
1158 #define GSM48_MT_CC_RETR 0x1c
1159 #define GSM48_MT_CC_RETR_ACK 0x1d
1160 #define GSM48_MT_CC_RETR_REJ 0x1e
1161 
1162 #define GSM48_MT_CC_DISCONNECT 0x25
1163 #define GSM48_MT_CC_RELEASE 0x2d
1164 #define GSM48_MT_CC_RELEASE_COMPL 0x2a
1165 
1166 #define GSM48_MT_CC_CONG_CTRL 0x39
1167 #define GSM48_MT_CC_NOTIFY 0x3e
1168 #define GSM48_MT_CC_STATUS 0x3d
1169 #define GSM48_MT_CC_STATUS_ENQ 0x34
1170 #define GSM48_MT_CC_START_DTMF 0x35
1171 #define GSM48_MT_CC_STOP_DTMF 0x31
1172 #define GSM48_MT_CC_STOP_DTMF_ACK 0x32
1173 #define GSM48_MT_CC_START_DTMF_ACK 0x36
1174 #define GSM48_MT_CC_START_DTMF_REJ 0x37
1175 #define GSM48_MT_CC_FACILITY 0x3a
1176 
1177 /* FIXME: Table 10.4 / 10.4a (GPRS) */
1178 
1179 /* Section 10.5.3.3 CM service type */
1180 #define GSM48_CMSERV_MO_CALL_PACKET 1
1181 #define GSM48_CMSERV_EMERGENCY 2
1182 #define GSM48_CMSERV_SMS 4
1183 #define GSM48_CMSERV_SUP_SERV 8
1184 #define GSM48_CMSERV_VGCS 9
1185 #define GSM48_CMSERV_VBS 10
1186 #define GSM48_CMSERV_LOC_SERV 11
1187 
1188 /* Section 10.5.2.26, Table 10.5.64 */
1189 #define GSM48_PM_MASK 0x03
1190 #define GSM48_PM_NORMAL 0x00
1191 #define GSM48_PM_EXTENDED 0x01
1192 #define GSM48_PM_REORG 0x02
1193 #define GSM48_PM_SAME 0x03
1194 
1195 /* Chapter 10.5.3.5 / Table 10.5.93 */
1196 #define GSM48_LUPD_NORMAL 0x0
1197 #define GSM48_LUPD_PERIODIC 0x1
1198 #define GSM48_LUPD_IMSI_ATT 0x2
1199 #define GSM48_LUPD_RESERVED 0x3
1200 
1201 /* Table 10.5.4 */
1202 #define GSM_MI_TYPE_MASK 0x07
1203 #define GSM_MI_TYPE_NONE 0x00
1204 #define GSM_MI_TYPE_IMSI 0x01
1205 #define GSM_MI_TYPE_IMEI 0x02
1206 #define GSM_MI_TYPE_IMEISV 0x03
1207 #define GSM_MI_TYPE_TMSI 0x04
1208 #define GSM_MI_ODD 0x08
1209 
1210 #define GSM48_IE_MOBILE_ID 0x17 /* 10.5.1.4 */
1211 #define GSM48_IE_NAME_LONG 0x43 /* 10.5.3.5a */
1212 #define GSM48_IE_NAME_SHORT 0x45 /* 10.5.3.5a */
1213 #define GSM48_IE_UTC 0x46 /* 10.5.3.8 */
1214 #define GSM48_IE_NET_TIME_TZ 0x47 /* 10.5.3.9 */
1215 #define GSM48_IE_LSA_IDENT 0x48 /* 10.5.3.11 */
1216 #define GSM48_IE_NET_DST 0x49 /* 10.5.3.12 [24.008] */
1217 
1218 #define GSM48_IE_BEARER_CAP 0x04 /* 10.5.4.5 */
1219 #define GSM48_IE_CAUSE 0x08 /* 10.5.4.11 */
1220 #define GSM48_IE_CC_CAP 0x15 /* 10.5.4.5a */
1221 #define GSM48_IE_ALERT 0x19 /* 10.5.4.26 */
1222 #define GSM48_IE_FACILITY 0x1c /* 10.5.4.15 */
1223 #define GSM48_IE_PROGR_IND 0x1e /* 10.5.4.21 */
1224 #define GSM48_IE_AUX_STATUS 0x24 /* 10.5.4.4 */
1225 #define GSM48_IE_NOTIFY 0x27 /* 10.5.4.20 */
1226 #define GSM48_IE_KPD_FACILITY 0x2c /* 10.5.4.17 */
1227 #define GSM48_IE_SIGNAL 0x34 /* 10.5.4.23 */
1228 #define GSM48_IE_CONN_BCD 0x4c /* 10.5.4.13 */
1229 #define GSM48_IE_CONN_SUB 0x4d /* 10.5.4.14 */
1230 #define GSM48_IE_CALLING_BCD 0x5c /* 10.5.4.9 */
1231 #define GSM48_IE_CALLING_SUB 0x5d /* 10.5.4.10 */
1232 #define GSM48_IE_CALLED_BCD 0x5e /* 10.5.4.7 */
1233 #define GSM48_IE_CALLED_SUB 0x6d /* 10.5.4.8 */
1234 #define GSM48_IE_REDIR_BCD 0x74 /* 10.5.4.21a */
1235 #define GSM48_IE_REDIR_SUB 0x75 /* 10.5.4.21b */
1236 #define GSM48_IE_LOWL_COMPAT 0x7c /* 10.5.4.18 */
1237 #define GSM48_IE_HIGHL_COMPAT 0x7d /* 10.5.4.16 */
1238 #define GSM48_IE_USER_USER 0x7e /* 10.5.4.25 */
1239 #define GSM48_IE_SS_VERS 0x7f /* 10.5.4.24 */
1240 #define GSM48_IE_MORE_DATA 0xa0 /* 10.5.4.19 */
1241 #define GSM48_IE_CLIR_SUPP 0xa1 /* 10.5.4.11a */
1242 #define GSM48_IE_CLIR_INVOC 0xa2 /* 10.5.4.11b */
1243 #define GSM48_IE_REV_C_SETUP 0xa3 /* 10.5.4.22a */
1244 #define GSM48_IE_REPEAT_CIR 0xd1 /* 10.5.4.22 */
1245 #define GSM48_IE_REPEAT_SEQ 0xd3 /* 10.5.4.22 */
1246 
1247 /* Section 10.5.4.11 / Table 10.5.122 */
1248 #define GSM48_CAUSE_CS_GSM 0x60
1249 
1250 /* Section 9.1.2 / Table 9.3 */
1251 /* RR elements */
1252 #define GSM48_IE_VGCS_TARGET 0x01
1253 //#define GSM48_IE_VGCS_T_MODE_I 0x01
1254 #define GSM48_IE_FRQSHORT_AFTER 0x02
1255 #define GSM48_IE_MUL_RATE_CFG 0x03 /* 10.5.2.21aa */
1256 #define GSM48_IE_FREQ_L_AFTER 0x05
1257 #define GSM48_IE_MSLOT_DESC 0x10
1258 #define GSM48_IE_CHANMODE_2 0x11
1259 #define GSM48_IE_FRQSHORT_BEFORE 0x12
1260 //#define GSM48_IE_FRQSHORT_BEFOR 0x12
1261 #define GSM48_IE_CHANMODE_3 0x13
1262 #define GSM48_IE_CHANMODE_4 0x14
1263 #define GSM48_IE_CHANMODE_5 0x15
1264 #define GSM48_IE_CHANMODE_6 0x16
1265 #define GSM48_IE_CHANMODE_7 0x17
1266 #define GSM48_IE_CHANMODE_8 0x18
1267 #define GSM48_IE_CHANDESC_2 0x64
1268 #define GSM48_IE_MA_AFTER 0x72
1269 #define GSM48_IE_START_TIME 0x7c
1270 #define GSM48_IE_FREQ_L_BEFORE 0x19
1271 //#define GSM48_IE_FRQLIST_BEFORE 0x19
1272 #define GSM48_IE_CH_DESC_1_BEFORE 0x1c
1273 //#define GSM48_IE_CHDES_1_BEFORE 0x1c
1274 #define GSM48_IE_CH_DESC_2_BEFORE 0x1d
1275 //#define GSM48_IE_CHDES_2_BEFORE 0x1d
1276 #define GSM48_IE_F_CH_SEQ_BEFORE 0x1e
1277 //#define GSM48_IE_FRQSEQ_BEFORE 0x1e
1278 #define GSM48_IE_CLASSMARK3 0x20
1279 #define GSM48_IE_MA_BEFORE 0x21
1280 #define GSM48_IE_RR_PACKET_UL 0x22
1281 #define GSM48_IE_RR_PACKET_DL 0x23
1282 #define GSM48_IE_CELL_CH_DESC 0x62
1283 #define GSM48_IE_CHANMODE_1 0x63
1284 #define GSM48_IE_CHDES_2_AFTER 0x64
1285 #define GSM48_IE_MODE_SEC_CH 0x66
1286 #define GSM48_IE_F_CH_SEQ_AFTER 0x69
1287 #define GSM48_IE_MA_AFTER 0x72
1288 #define GSM48_IE_BA_RANGE 0x73
1289 #define GSM48_IE_GROUP_CHDES 0x74
1290 #define GSM48_IE_BA_LIST_PREF 0x75
1291 #define GSM48_IE_MOB_OVSERV_DIF 0x77
1292 #define GSM48_IE_REALTIME_DIFF 0x7b
1293 #define GSM48_IE_START_TIME 0x7c
1294 #define GSM48_IE_TIMING_ADVANCE 0x7d
1295 #define GSM48_IE_GROUP_CIP_SEQ 0x80
1296 #define GSM48_IE_CIP_MODE_SET 0x90
1297 #define GSM48_IE_GPRS_RESUMPT 0xc0
1298 #define GSM48_IE_SYNC_IND 0xd0
1299 /* System Information 4 (types are equal IEs above) */
1300 #define GSM48_IE_CBCH_CHAN_DESC 0x64
1301 #define GSM48_IE_CBCH_MOB_AL 0x72
1302 
1303 /* Additional MM elements */
1304 #define GSM48_IE_LOCATION_AREA 0x13
1305 #define GSM48_IE_AUTN 0x20
1306 #define GSM48_IE_AUTH_RES_EXT 0x21
1307 #define GSM48_IE_AUTS 0x22
1308 #define GSM48_IE_PRIORITY_LEV 0x80
1309 #define GSM48_IE_FOLLOW_ON_PROC 0xa1
1310 #define GSM48_IE_CTS_PERMISSION 0xa2
1311 
1312 /* Section 10.5.4.23 / Table 10.5.130 */
1313 enum gsm48_signal_val {
1314  GSM48_SIGNAL_DIALTONE = 0x00,
1315  GSM48_SIGNAL_RINGBACK = 0x01,
1316  GSM48_SIGNAL_INTERCEPT = 0x02,
1317  GSM48_SIGNAL_NET_CONG = 0x03,
1318  GSM48_SIGNAL_BUSY = 0x04,
1319  GSM48_SIGNAL_CONFIRM = 0x05,
1320  GSM48_SIGNAL_ANSWER = 0x06,
1321  GSM48_SIGNAL_CALL_WAIT = 0x07,
1322  GSM48_SIGNAL_OFF_HOOK = 0x08,
1323  GSM48_SIGNAL_OFF = 0x3f,
1324  GSM48_SIGNAL_ALERT_OFF = 0x4f,
1325 };
1326 
1327 enum gsm48_cause_loc {
1328  GSM48_CAUSE_LOC_USER = 0x00,
1329  GSM48_CAUSE_LOC_PRN_S_LU = 0x01,
1330  GSM48_CAUSE_LOC_PUN_S_LU = 0x02,
1331  GSM48_CAUSE_LOC_TRANS_NET = 0x03,
1332  GSM48_CAUSE_LOC_PUN_S_RU = 0x04,
1333  GSM48_CAUSE_LOC_PRN_S_RU = 0x05,
1334  /* not defined */
1335  GSM48_CAUSE_LOC_INN_NET = 0x07,
1336  GSM48_CAUSE_LOC_NET_BEYOND = 0x0a,
1337 };
1338 
1339 /* Section 10.5.2.31 RR Cause / Table 10.5.70 */
1340 enum gsm48_rr_cause {
1341  GSM48_RR_CAUSE_NORMAL = 0x00,
1342  GSM48_RR_CAUSE_ABNORMAL_UNSPEC = 0x01,
1343  GSM48_RR_CAUSE_ABNORMAL_UNACCT = 0x02,
1344  GSM48_RR_CAUSE_ABNORMAL_TIMER = 0x03,
1345  GSM48_RR_CAUSE_ABNORMAL_NOACT = 0x04,
1346  GSM48_RR_CAUSE_PREMPTIVE_REL = 0x05,
1347  GSM48_RR_CAUSE_HNDOVER_IMP = 0x08,
1348  GSM48_RR_CAUSE_CHAN_MODE_UNACCT = 0x09,
1349  GSM48_RR_CAUSE_FREQ_NOT_IMPL = 0x0a,
1350  GSM48_RR_CAUSE_CALL_CLEARED = 0x41,
1351  GSM48_RR_CAUSE_SEMANT_INCORR = 0x5f,
1352  GSM48_RR_CAUSE_INVALID_MAND_INF = 0x60,
1353  GSM48_RR_CAUSE_MSG_TYPE_N = 0x61,
1354  GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT= 0x62,
1355  GSM48_RR_CAUSE_COND_IE_ERROR = 0x64,
1356  GSM48_RR_CAUSE_NO_CELL_ALLOC_A = 0x65,
1357  GSM48_RR_CAUSE_PROT_ERROR_UNSPC = 0x6f,
1358 };
1359 
1360 /* Section 10.5.4.11 CC Cause / Table 10.5.123 */
1361 enum gsm48_cc_cause {
1362  GSM48_CC_CAUSE_UNASSIGNED_NR = 1,
1363  GSM48_CC_CAUSE_NO_ROUTE = 3,
1364  GSM48_CC_CAUSE_CHAN_UNACCEPT = 6,
1365  GSM48_CC_CAUSE_OP_DET_BARRING = 8,
1366  GSM48_CC_CAUSE_NORM_CALL_CLEAR = 16,
1367  GSM48_CC_CAUSE_USER_BUSY = 17,
1368  GSM48_CC_CAUSE_USER_NOTRESPOND = 18,
1369  GSM48_CC_CAUSE_USER_ALERTING_NA = 19,
1370  GSM48_CC_CAUSE_CALL_REJECTED = 21,
1371  GSM48_CC_CAUSE_NUMBER_CHANGED = 22,
1372  GSM48_CC_CAUSE_PRE_EMPTION = 25,
1373  GSM48_CC_CAUSE_NONSE_USER_CLR = 26,
1374  GSM48_CC_CAUSE_DEST_OOO = 27,
1375  GSM48_CC_CAUSE_INV_NR_FORMAT = 28,
1376  GSM48_CC_CAUSE_FACILITY_REJ = 29,
1377  GSM48_CC_CAUSE_RESP_STATUS_INQ = 30,
1378  GSM48_CC_CAUSE_NORMAL_UNSPEC = 31,
1379  GSM48_CC_CAUSE_NO_CIRCUIT_CHAN = 34,
1380  GSM48_CC_CAUSE_NETWORK_OOO = 38,
1381  GSM48_CC_CAUSE_TEMP_FAILURE = 41,
1382  GSM48_CC_CAUSE_SWITCH_CONG = 42,
1383  GSM48_CC_CAUSE_ACC_INF_DISCARD = 43,
1384  GSM48_CC_CAUSE_REQ_CHAN_UNAVAIL = 44,
1385  GSM48_CC_CAUSE_RESOURCE_UNAVAIL = 47,
1386  GSM48_CC_CAUSE_QOS_UNAVAIL = 49,
1387  GSM48_CC_CAUSE_REQ_FAC_NOT_SUBSC= 50,
1388  GSM48_CC_CAUSE_INC_BARRED_CUG = 55,
1389  GSM48_CC_CAUSE_BEARER_CAP_UNAUTH= 57,
1390  GSM48_CC_CAUSE_BEARER_CA_UNAVAIL= 58,
1391  GSM48_CC_CAUSE_SERV_OPT_UNAVAIL = 63,
1392  GSM48_CC_CAUSE_BEARERSERV_UNIMPL= 65,
1393  GSM48_CC_CAUSE_ACM_GE_ACM_MAX = 68,
1394  GSM48_CC_CAUSE_REQ_FAC_NOTIMPL = 69,
1395  GSM48_CC_CAUSE_RESTR_BCAP_AVAIL = 70,
1396  GSM48_CC_CAUSE_SERV_OPT_UNIMPL = 79,
1397  GSM48_CC_CAUSE_INVAL_TRANS_ID = 81,
1398  GSM48_CC_CAUSE_USER_NOT_IN_CUG = 87,
1399  GSM48_CC_CAUSE_INCOMPAT_DEST = 88,
1400  GSM48_CC_CAUSE_INVAL_TRANS_NET = 91,
1401  GSM48_CC_CAUSE_SEMANTIC_INCORR = 95,
1402  GSM48_CC_CAUSE_INVAL_MAND_INF = 96,
1403  GSM48_CC_CAUSE_MSGTYPE_NOTEXIST = 97,
1404  GSM48_CC_CAUSE_MSGTYPE_INCOMPAT = 98,
1405  GSM48_CC_CAUSE_IE_NOTEXIST = 99,
1406  GSM48_CC_CAUSE_COND_IE_ERR = 100,
1407  GSM48_CC_CAUSE_MSG_INCOMP_STATE = 101,
1408  GSM48_CC_CAUSE_RECOVERY_TIMER = 102,
1409  GSM48_CC_CAUSE_PROTO_ERR = 111,
1410  GSM48_CC_CAUSE_INTERWORKING = 127,
1411 };
1412 
1413 /* Annex G, GSM specific cause values for mobility management */
1414 enum gsm48_reject_value {
1415  GSM48_REJECT_IMSI_UNKNOWN_IN_HLR = 2,
1416  GSM48_REJECT_ILLEGAL_MS = 3,
1417  GSM48_REJECT_IMSI_UNKNOWN_IN_VLR = 4,
1418  GSM48_REJECT_IMEI_NOT_ACCEPTED = 5,
1419  GSM48_REJECT_ILLEGAL_ME = 6,
1420  GSM48_REJECT_PLMN_NOT_ALLOWED = 11,
1421  GSM48_REJECT_LOC_NOT_ALLOWED = 12,
1422  GSM48_REJECT_ROAMING_NOT_ALLOWED = 13,
1423  GSM48_REJECT_NETWORK_FAILURE = 17,
1424  GSM48_REJECT_SYNCH_FAILURE = 21,
1425  GSM48_REJECT_CONGESTION = 22,
1426  GSM48_REJECT_SRV_OPT_NOT_SUPPORTED = 32,
1427  GSM48_REJECT_RQD_SRV_OPT_NOT_SUPPORTED = 33,
1428  GSM48_REJECT_SRV_OPT_TMP_OUT_OF_ORDER = 34,
1429  GSM48_REJECT_CALL_CAN_NOT_BE_IDENTIFIED = 38,
1430  GSM48_REJECT_INCORRECT_MESSAGE = 95,
1431  GSM48_REJECT_INVALID_MANDANTORY_INF = 96,
1432  GSM48_REJECT_MSG_TYPE_NOT_IMPLEMENTED = 97,
1433  GSM48_REJECT_MSG_TYPE_NOT_COMPATIBLE = 98,
1434  GSM48_REJECT_INF_ELEME_NOT_IMPLEMENTED = 99,
1435  GSM48_REJECT_CONDTIONAL_IE_ERROR = 100,
1436  GSM48_REJECT_MSG_NOT_COMPATIBLE = 101,
1437  GSM48_REJECT_PROTOCOL_ERROR = 111,
1438 
1439  /* according to G.6 Additional cause codes for GMM */
1440  GSM48_REJECT_GPRS_NOT_ALLOWED = 7,
1441  GSM48_REJECT_SERVICES_NOT_ALLOWED = 8,
1442  GSM48_REJECT_MS_IDENTITY_NOT_DERVIVABLE = 9,
1443  GSM48_REJECT_IMPLICITLY_DETACHED = 10,
1444  GSM48_REJECT_GPRS_NOT_ALLOWED_IN_PLMN = 14,
1445  GSM48_REJECT_MSC_TMP_NOT_REACHABLE = 16,
1446 };
1447 
1448 enum chreq_type {
1449  CHREQ_T_EMERG_CALL,
1450  CHREQ_T_CALL_REEST_TCH_F,
1451  CHREQ_T_CALL_REEST_TCH_H,
1452  CHREQ_T_CALL_REEST_TCH_H_DBL,
1453  CHREQ_T_SDCCH,
1454  CHREQ_T_TCH_F,
1455  CHREQ_T_VOICE_CALL_TCH_H,
1456  CHREQ_T_DATA_CALL_TCH_H,
1457  CHREQ_T_LOCATION_UPD,
1458  CHREQ_T_PAG_R_ANY_NECI0,
1459  CHREQ_T_PAG_R_ANY_NECI1,
1460  CHREQ_T_PAG_R_TCH_F,
1461  CHREQ_T_PAG_R_TCH_FH,
1462  CHREQ_T_LMU,
1463  CHREQ_T_RESERVED_SDCCH,
1464  CHREQ_T_RESERVED_IGNORE,
1465 };
1466 
1467 /* Chapter 11.3 */
1468 #define GSM48_T301 180, 0
1469 #define GSM48_T303 30, 0
1470 #define GSM48_T305 30, 0
1471 #define GSM48_T306 30, 0
1472 #define GSM48_T308 10, 0
1473 #define GSM48_T310 180, 0
1474 #define GSM48_T313 30, 0
1475 #define GSM48_T323 30, 0
1476 #define GSM48_T331 30, 0
1477 #define GSM48_T333 30, 0
1478 #define GSM48_T334 25, 0 /* min 15 */
1479 #define GSM48_T338 30, 0
1480 #define GSM48_T303_MS 30, 0
1481 #define GSM48_T305_MS 30, 0
1482 #define GSM48_T308_MS 30, 0
1483 #define GSM48_T310_MS 30, 0
1484 #define GSM48_T313_MS 30, 0
1485 #define GSM48_T323_MS 30, 0
1486 #define GSM48_T332_MS 30, 0
1487 #define GSM48_T335_MS 30, 0
1488 
1489 /* Chapter 5.1.2.2 */
1490 #define GSM_CSTATE_NULL 0
1491 #define GSM_CSTATE_INITIATED 1
1492 #define GSM_CSTATE_MM_CONNECTION_PEND 2 /* see 10.5.4.6 */
1493 #define GSM_CSTATE_MO_CALL_PROC 3
1494 #define GSM_CSTATE_CALL_DELIVERED 4
1495 #define GSM_CSTATE_CALL_PRESENT 6
1496 #define GSM_CSTATE_CALL_RECEIVED 7
1497 #define GSM_CSTATE_CONNECT_REQUEST 8
1498 #define GSM_CSTATE_MO_TERM_CALL_CONF 9
1499 #define GSM_CSTATE_ACTIVE 10
1500 #define GSM_CSTATE_DISCONNECT_REQ 12
1501 #define GSM_CSTATE_DISCONNECT_IND 12
1502 #define GSM_CSTATE_RELEASE_REQ 19
1503 #define GSM_CSTATE_MO_ORIG_MODIFY 26
1504 #define GSM_CSTATE_MO_TERM_MODIFY 27
1505 #define GSM_CSTATE_CONNECT_IND 28
1506 
1507 #define SBIT(a) (1 << a)
1508 #define ALL_STATES 0xffffffff
1509 
1510 /* Table 10.5.3/3GPP TS 04.08: Location Area Identification information element */
1511 #define GSM_LAC_RESERVED_DETACHED 0x0
1512 #define GSM_LAC_RESERVED_ALL_BTS 0xfffe
1513 
1514 /* GSM 04.08 Bearer Capability: Information Transfer Capability */
1515 enum gsm48_bcap_itcap {
1516  GSM48_BCAP_ITCAP_SPEECH = 0,
1517  GSM48_BCAP_ITCAP_UNR_DIG_INF = 1,
1518  GSM48_BCAP_ITCAP_3k1_AUDIO = 2,
1519  GSM48_BCAP_ITCAP_FAX_G3 = 3,
1520  GSM48_BCAP_ITCAP_OTHER = 5,
1521  GSM48_BCAP_ITCAP_RESERVED = 7,
1522 };
1523 
1524 /* GSM 04.08 Bearer Capability: Transfer Mode */
1525 enum gsm48_bcap_tmod {
1526  GSM48_BCAP_TMOD_CIRCUIT = 0,
1527  GSM48_BCAP_TMOD_PACKET = 1,
1528 };
1529 
1530 /* GSM 04.08 Bearer Capability: Coding Standard */
1531 enum gsm48_bcap_coding {
1532  GSM48_BCAP_CODING_GSM_STD = 0,
1533 };
1534 
1535 /* GSM 04.08 Bearer Capability: Radio Channel Requirements */
1536 enum gsm48_bcap_rrq {
1537  GSM48_BCAP_RRQ_FR_ONLY = 1,
1538  GSM48_BCAP_RRQ_DUAL_HR = 2,
1539  GSM48_BCAP_RRQ_DUAL_FR = 3,
1540 };
1541 
1542 /* GSM 04.08 Bearer Capability: Rate Adaption */
1543 enum gsm48_bcap_ra {
1544  GSM48_BCAP_RA_NONE = 0,
1545  GSM48_BCAP_RA_V110_X30 = 1,
1546  GSM48_BCAP_RA_X31 = 2,
1547  GSM48_BCAP_RA_OTHER = 3,
1548 };
1549 
1550 /* GSM 04.08 Bearer Capability: Signalling access protocol */
1551 enum gsm48_bcap_sig_access {
1552  GSM48_BCAP_SA_I440_I450 = 1,
1553  GSM48_BCAP_SA_X21 = 2,
1554  GSM48_BCAP_SA_X28_DP_IN = 3,
1555  GSM48_BCAP_SA_X28_DP_UN = 4,
1556  GSM48_BCAP_SA_X28_NDP = 5,
1557  GSM48_BCAP_SA_X32 = 6,
1558 };
1559 
1560 /* GSM 04.08 Bearer Capability: User Rate */
1561 enum gsm48_bcap_user_rate {
1562  GSM48_BCAP_UR_300 = 1,
1563  GSM48_BCAP_UR_1200 = 2,
1564  GSM48_BCAP_UR_2400 = 3,
1565  GSM48_BCAP_UR_4800 = 4,
1566  GSM48_BCAP_UR_9600 = 5,
1567  GSM48_BCAP_UR_12000 = 6,
1568  GSM48_BCAP_UR_1200_75 = 7,
1569 };
1570 
1571 /* GSM 04.08 Bearer Capability: Parity */
1572 enum gsm48_bcap_parity {
1573  GSM48_BCAP_PAR_ODD = 0,
1574  GSM48_BCAP_PAR_EVEN = 2,
1575  GSM48_BCAP_PAR_NONE = 3,
1576  GSM48_BCAP_PAR_ZERO = 4,
1577  GSM48_BCAP_PAR_ONE = 5,
1578 };
1579 
1580 /* GSM 04.08 Bearer Capability: Intermediate Rate */
1581 enum gsm48_bcap_interm_rate {
1582  GSM48_BCAP_IR_8k = 2,
1583  GSM48_BCAP_IR_16k = 3,
1584 };
1585 
1586 /* GSM 04.08 Bearer Capability: Transparency */
1587 enum gsm48_bcap_transp {
1588  GSM48_BCAP_TR_TRANSP = 0,
1589  GSM48_BCAP_TR_RLP = 1,
1590  GSM48_BCAP_TR_TR_PREF = 2,
1591  GSM48_BCAP_TR_RLP_PREF = 3,
1592 };
1593 
1594 /* GSM 04.08 Bearer Capability: Modem Type */
1595 enum gsm48_bcap_modem_type {
1596  GSM48_BCAP_MT_NONE = 0,
1597  GSM48_BCAP_MT_V21 = 1,
1598  GSM48_BCAP_MT_V22 = 2,
1599  GSM48_BCAP_MT_V22bis = 3,
1600  GSM48_BCAP_MT_V23 = 4,
1601  GSM48_BCAP_MT_V26ter = 5,
1602  GSM48_BCAP_MT_V32 = 6,
1603  GSM48_BCAP_MT_UNDEF = 7,
1604  GSM48_BCAP_MT_AUTO_1 = 8,
1605 };
1606 
1607 /* GSM 04.08 Bearer Capability: Speech Version Indication */
1608 enum gsm48_bcap_speech_ver {
1609  GSM48_BCAP_SV_FR = 0,
1610  GSM48_BCAP_SV_HR = 1,
1611  GSM48_BCAP_SV_EFR = 2,
1612  GSM48_BCAP_SV_AMR_F = 4,
1613  GSM48_BCAP_SV_AMR_H = 5,
1614 };
1615 
1616 #define GSM48_TMSI_LEN 5
1617 #define GSM48_MID_TMSI_LEN (GSM48_TMSI_LEN + 2)
1618 #define GSM48_MI_SIZE 32
1619 
1620 /* Chapter 10.4.4.15 */
1621 struct gsm48_ra_id {
1622  uint8_t digits[3]; /* MCC + MNC BCD digits */
1623  uint16_t lac; /* Location Area Code */
1624  uint8_t rac; /* Routing Area Code */
1625 } __attribute__ ((packed));
1626 
1627 #define GSM48_CELL_CHAN_DESC_SIZE 16
1628 
1629 #define GSM_MACBLOCK_LEN 23
1630 #define GSM_MACBLOCK_PADDING 0x2b
Definition: gsm_04_08.h:515
Definition: gsm_04_08.h:804
Definition: gsm_04_08.h:777
Definition: gsm_04_08.h:598
Definition: gsm_04_08.h:539
Definition: gsm_04_08.h:906
Definition: gsm_04_08.h:476
Definition: gsm_04_08.h:745
Definition: gsm_04_08.h:691
Definition: gsm_04_08.h:605
Definition: gsm_04_08.h:649
Definition: gsm_04_08.h:358
Definition: gsm_04_08.h:878
Definition: gsm_04_08.h:456
Definition: gsm_04_08.h:721
Definition: gsm_04_08.h:684
Definition: gsm_04_08.h:523
Definition: gsm_04_08.h:22
Definition: gsm_04_08.h:229
Definition: gsm_04_08.h:1621
Definition: gsm_04_08.h:737
Definition: gsm_04_08.h:613
Definition: gsm_04_08.h:852
Definition: gsm_04_08.h:793
Definition: gsm_04_08.h:798
uint8_t data[0]
actual payload data
Definition: gsm_08_58.h:443
Definition: gsm_04_08.h:548
Definition: gsm_04_08.h:467
Definition: gsm_04_08.h:389
Definition: gsm_04_08.h:588
Definition: gsm_04_08.h:668
Definition: gsm_04_08.h:152
Definition: gsm_04_08.h:570
Definition: gsm_04_08.h:709
Definition: gsm_04_08.h:13
Definition: gsm_04_08.h:864
Definition: gsm_04_08.h:787
Definition: gsm_04_08.h:449
Definition: gsm_04_08.h:782
Definition: gsm_04_08.h:81
Definition: gsm_04_08.h:660
Definition: gsm_04_08.h:770
Definition: gsm_04_08.h:576
Definition: gsm_04_08.h:697
Definition: gsm_04_08.h:622
Definition: gsm_04_08.h:583
Definition: gsm_04_08.h:314
Definition: gsm_04_08.h:484
Definition: gsm_04_08.h:561
Definition: gsm_04_08.h:496
Definition: gsm_04_08.h:757
Definition: gsm_04_08.h:729
Definition: gsm_04_08.h:897
Definition: gsm_04_08.h:432
Definition: gsm_04_08.h:676
Definition: gsm_04_08.h:763
Definition: gsm_04_08.h:819
Definition: gsm_04_08.h:640
Definition: gsm_04_08.h:531
Definition: gsm_04_08.h:368
Definition: gsm_04_08.h:812
Definition: gsm_04_08.h:835