blob: 436273af99eee16a52d29331f91a32631ef15a58 [file] [log] [blame]
Harald Welte9419c8a2017-07-30 04:07:05 +02001/* Encoding/Decoding routines for GSM System Information messages
2 * according to 3GPP TS 44.018 Version 12.3.0 Release 12 */
3
4/* (C) 2017 by Harald Welte <laforge@gnumonks.org> */
5
6module GSM_RR_Types {
7
8 import from General_Types all;
9 import from Osmocom_Types all;
10 import from GSM_Types all;
11 import from RLCMAC_CSN1_Types all;
12
13 /* Table 10.4.1 of Section 10.4 / 3GPP TS 44.018 */
14 type enumerated RrMessageType {
15 ADDITIONAL_ASSIGNMENT ('00111011'B),
16 IMMEDIATE_ASSIGNMENT ('00111111'B),
17 IMMEDIATE_ASSIGNMENT_EXTENDED ('00111001'B),
18 IMMEDIATE_ASSIGNMENT_REJECT ('00111010'B),
19 IMMEDIATE_PACKET_ASSIGNMENT ('01101001'B),
20
21 CIPHERING_MODE_COMMAND ('00110101'B),
22 CIPHERING_MODE_COMPLETE ('00110010'B),
23
24 CONFIGURATION_CHANGE_COMMAND ('00110000'B),
25 CONFIGURATION_CHANGE_ACK ('00110001'B),
26 CONFIGURATION_CHANGE_REJECT ('00110011'B),
27
28 ASSIGNMENT_COMMAND ('00101110'B),
29 ASSIGNMENT_COMPLETE ('00101001'B),
30 ASSIGNMENT_FAILURE ('00101111'B),
31 HANDOVER_COMMAND ('00101011'B),
32 HANDOVER_COMPLETE ('00101100'B),
33 HANDOVER_FAILURE ('00101000'B),
34 PHYSICAL_INFORMATION ('00101101'B),
35
36 CHANNEL_RELEASE ('00001101'B),
37 PARTIAL_RELEASE ('00001010'B),
38 PARTIAL_RELEASE_COMPLETE ('00001111'B),
39
40 PAGING_REQUEST_TYPE_1 ('00100001'B),
41 PAGING_REQUEST_TYPE_2 ('00100010'B),
42 PAGING_REQUEST_TYPE_3 ('00100100'B),
43 PAGING_RESPONSE ('00100111'B),
44 NOTIFICATION_NCH ('00100000'B),
45 NOTIFICATION_RESPOSNE ('00100110'B),
46
47 SYSTEM_INFORMATION_TYPE_8 ('00011000'B),
48 SYSTEM_INFORMATION_TYPE_1 ('00011001'B),
49 SYSTEM_INFORMATION_TYPE_2 ('00011010'B),
50 SYSTEM_INFORMATION_TYPE_3 ('00011011'B),
51 SYSTEM_INFORMATION_TYPE_4 ('00011100'B),
52 SYSTEM_INFORMATION_TYPE_5 ('00011101'B),
53 SYSTEM_INFORMATION_TYPE_6 ('00011110'B),
54 SYSTEM_INFORMATION_TYPE_7 ('00011111'B),
55 SYSTEM_INFORMATION_TYPE_2bis ('00000010'B),
56 SYSTEM_INFORMATION_TYPE_2ter ('00000011'B),
57 SYSTEM_INFORMATION_TYPE_2quater ('00000111'B),
58 SYSTEM_INFORMATION_TYPE_5bis ('00000101'B),
59 SYSTEM_INFORMATION_TYPE_5ter ('00000110'B),
60 SYSTEM_INFORMATION_TYPE_9 ('00000100'B),
61 SYSTEM_INFORMATION_TYPE_13 ('00000000'B),
62
63 SYSTEM_INFORMATION_TYPE_16 ('00111101'B),
64 SYSTEM_INFORMATION_TYPE_17 ('00111110'B),
65
66 CHANNEL_MODE_MODIFY ('00010000'B),
67 RR_STATUS ('00010010'B),
68 CHANNEL_MODE_MODIFY_ACKNOWLEDGE ('00010111'B),
69 FREQUENCY_REDEFINITION ('00010100'B),
70 MEASUREMENT_REPORT ('00010101'B),
71 CLASSMARK_CHANGE ('00010110'B),
72 CLASSMARK_ENQUIRY ('00010011'B),
73 EXTENDED_MEASUREMENT_REPORT ('00110110'B),
74 EXTENDED_MEASUREMENT_ORDER ('00110111'B),
75 GPRS_SUSPENSION_REQUEST ('00110100'B),
76 //MBMS_ANNOUNCEMENT ('00010110'B), duplicate?
77 //SERVICE_INFORMATION ('00110110'B), duplicate?
78
79 APPLICATION_INFORMATION ('00111000'B),
80
81 SYSTEM_INFORMATION_TYPE_14 ('00000001'B),
82 SYSTEM_INFORMATION_TYPE_15 ('01000011'B),
83 SYSTEM_INFORMATION_TYPE_18 ('01000000'B),
84 SYSTEM_INFORMATION_TYPE_19 ('01000001'B),
85 SYSTEM_INFORMATION_TYPE_20 ('01000010'B),
86 SYSTEM_INFORMATION_TYPE_13alt ('01000100'B),
87 SYSTEM_INFORMATION_TYPE_2n ('01000101'B),
88 SYSTEM_INFORMATION_TYPE_21 ('01000110'B),
89 SYSTEM_INFORMATION_TYPE_22 ('01000111'B),
90 SYSTEM_INFORMATION_TYPE_23 ('01001111'B),
91
92 DTM_ASSIGNMENT_FAILURE ('01001000'B),
93 DTM_REJECT ('01001001'B),
94 DTM_REQUEST ('01001010'B),
95 PACKET_ASSIGNMENT ('01001011'B),
96 DTM_ASSIGNMENT_COMMAND ('01001100'B),
97 DTM_INFORMATION ('01001101'B),
98 PACKET_INFORMATION ('01001110'B),
99
100 UTRAN_CLASSMARK_CHANGE ('01100000'B),
101 CDMA2000_CLASSMARK_CHANGE ('01100010'B),
102 INTERSYS_TO_UTRAN_HO_CMD ('01100011'B),
103 INTERSYS_TO_CDMA2000_HO_CMD ('01100100'B),
104 GERAN_IU_MODE_CLASSMARK_CHG ('01100101'B),
105 INTERSYS_TO_EUTRAN_HO_CMD ('01100110'B)
106 } with { variant "FIELDLENGTH(8)" };
107
108 type octetstring RestOctets with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" };
109 type hexstring GsmBcdString with { variant "HEXORDER(low)" };
110 type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" };
111
112 type record L2PseudoLength {
113 uint6_t l2_plen,
114 BIT2 zero_one
115 } with { variant "" };
116
117 template L2PseudoLength t_L2Pseudolength(template uint6_t len) := {
118 l2_plen := len,
119 zero_one := '01'B
120 };
121
122 type record RrHeader {
123 L2PseudoLength l2_plen,
124 uint4_t skip_indicator,
125 uint4_t rr_protocol_discriminator,
126 RrMessageType message_type
127 } with { variant "" };
128
129 template RrHeader t_RrHeader(RrMessageType msg_type, template uint6_t len) := {
130 l2_plen := t_L2Pseudolength(len),
131 skip_indicator := 0,
132 rr_protocol_discriminator := 6,
133 message_type := msg_type
134 };
135
136 type record RrL3Header {
137 uint4_t skip_indicator,
138 uint4_t rr_protocol_discriminator,
139 RrMessageType message_type
140 } with { variant "" };
141
142 type record MaioHsn {
143 } with { variant "" };
144
145 /* TS 24.008 10.5.1.1 */
146 type uint16_t CellIdentity;
147
148 /* TS 24.008 10.5.1.2 */
149 type uint4_t CipheringKeySeqNr (0..7);
150
151 /* 24.008 10.5.1.3 */
152 type record LocationAreaIdentification {
153 BcdMccMnc mcc_mnc,
154 uint16_t lac
155 } with { variant "" };
156
157 /* TS 24.008 10.5.1.4 */
158 type enumerated MobileIdentityType {
159 MI_TYPE_NONE (0),
160 MI_TYPE_IMSI,
161 MI_TYPE_IMEI,
162 MI_TYPE_IMEISV,
163 MI_TYPE_TMSI,
164 MI_TYPE_TMGI
165 } with { variant "FIELDLENGTH(3)" };
166
167 type record MobileIdentityBCD {
168 MobileIdentityType mi_type (MI_TYPE_IMSI, MI_TYPE_IMEI, MI_TYPE_IMEISV),
169 boolean odd,
170 hexstring digits
171 } with { variant "FIELDORDER(lsb)" };
172
173 type record MobileIdentityTMSI {
174 BIT4 pad ('1111'B),
175 boolean odd (false),
176 MobileIdentityType mi_type (MI_TYPE_TMSI),
177 GsmTmsi tmsi
178 } with { variant "FIELDORDER(lsb)" };
179
180 type record MobileIdentityNone {
181 BIT4 pad ('1111'B),
182 boolean odd (false),
183 MobileIdentityType mi_type (MI_TYPE_NONE)
184 } with { variant "FIELDORDER(lsb)" };
185
186 type union MobileIdentity {
187 MobileIdentityBCD imsi,
188 MobileIdentityBCD imei,
189 MobileIdentityBCD imeisv,
190 MobileIdentityTMSI tmsi,
191 MobileIdentityNone unused
192 } with { variant "TAG(imsi, mi_type = MI_TYPE_IMSI;
193 imei, mi_type = MI_TYPE_IMEI;
194 imeisv, mi_type = MI_TYPE_IMEISV;
195 tmsi, mi_type = MI_TYPE_TMSI;
196 unused, mi_type = MI_TYPE_NONE)"
197 variant "FIELDORDER(lsb)"
198 };
199
200 type record MobileIdentityLV {
201 uint8_t len,
202 MobileIdentity mi
203 } with { variant (len) "LENGTHTO(mi)" };
204
205 type record MobileIdentityTLV {
206 uint8_t tag,
207 uint8_t len,
208 MobileIdentity mi
209 } with { variant (len) "LENGTHTO(mi)" };
210
211 /* TS 24.008 10.5.1.5 */
212 type record MsClassmark1 {
213 BIT1 spare,
214 uint2_t rev_level,
215 boolean es_ind,
216 boolean a51,
217 uint3_t rf_pwr_cap
218 } with { variant "" };
219
220 /* TS 24.008 10.5.1.6 */
221 type record MsClassmark2 {
222 BIT1 spare,
223 uint2_t rev_level,
224 boolean es_ind,
225 boolean a51,
226 uint3_t rf_pwr_cap,
227 BIT1 spare1,
228 boolean ps_cap,
229 uint2_t ss_screen_ind,
230 boolean sm_cap,
231 boolean vbs,
232 boolean vgcs,
233 boolean fc,
234 boolean cm3,
235 BIT1 spare2,
236 boolean lcsva_cap,
237 boolean ucs2,
238 boolean solsa,
239 boolean cmsp,
240 boolean a53,
241 boolean a52
242 } with { variant "" };
243 type record MsClassmark2LV {
244 uint8_t len,
245 MsClassmark2 cm2
246 } with { variant (len) "LENGTHTO(cm2)" };
247
248
249 /* 44.018 10.5.2.5 */
250 type record ChannelDescription {
251 RslChannelNr chan_nr,
252 uint3_t tsc,
253 boolean h,
254 uint12_t arfcn optional,
255 MaioHsn maio_hsn optional
256 } with { variant (arfcn) "PRESENCE(h = false)"
257 variant (maio_hsn) "PRESENCE(h = true)" };
258
259 type record ChannelDescriptionTV {
260 OCT1 iei,
261 ChannelDescription v
262 } with { variant "" };
263
264 /* 10.5.2.21 */
265 type record MobileAllocation {
266 uint8_t len,
267 bitstring ma
268 } with { variant (len) "LENGTHTO(ma)" };
269
270 /* 10.5.2.25a */
271 type OCT3 PacketChannelDescription;
272
273 /* 10.5.2.25b */
274 type record DedicatedModeOrTbf {
275 BIT1 spare,
276 boolean tma,
277 boolean downlink,
278 boolean tbf
279 } with { variant "" };
280
281 /* 10.5.2.26 */
282 type enumerated PageMode {
283 PAGE_MODE_NORMAL,
284 PAGE_MODE_EXTENDED,
285 PAGE_MODE_REORGANIZATION,
286 PAGE_MODE_SAME_AS_BEFORE
287 } with { variant "FIELDLENGTH(4)" };
288
289 /* 10.5.2.30 */
290 type record RequestReference {
291 bitstring ra length(8),
292 uint5_t t1p,
293 uint6_t t3,
294 uint5_t t2
295 } with { variant "" };
296
297 template RequestReference t_RequestReference(template bitstring ra, template uint5_t t1p, template uint6_t t3, template uint5_t t2) := {
298 ra := ra,
299 t1p := t1p,
300 t3 := t3,
301 t2 := t2
302 }
303
304 /* compute the expected request reference for given RA + FN */
305 function f_compute_ReqRef(uint8_t ra, GsmFrameNumber fn) return RequestReference {
306 var RequestReference req_ref := { ra := int2bit(ra, 8) };
307 req_ref.t1p := (fn / 1326) mod 32;
308 req_ref.t2 := fn mod 26;
309 req_ref.t3 := fn mod 51;
310 return req_ref
311 }
312
313 /* 10.5.2.40 */
314 type integer TimingAdvance (0..219);
315
316 /* 10.5.2.43 */
317 type uint8_t WaitIndication;
318
319 /* 10.5.2.76 */
320 type record FeatureIndicator {
321 BIT2 spare,
322 boolean cs_ir,
323 boolean ps_ir
324 } with { variant "" };
325
326 /* 24.008 10.5.5.6 */
327 type record DrxParameter {
328 uint8_t split_pg_cycle_code,
329 uint4_t drx_cycle_len_coeff,
330 boolean split_on_ccch,
331 uint3_t non_drx_timer
332 } with { variant "" };
333
334 /* 24.008 10.5.5.15 */
335 type record RoutingAreaIdentification {
336 LocationAreaIdentification lai,
337 uint8_t rac
338 } with { variant "" };
339
340 /* 44.018 10.5.2.16 */
341 type record IaRestOctHL {
342 uint6_t freq_par_len,
343 BIT2 padding ('00'B) optional,
344 uint6_t maio optional,
345 octetstring mobile_allocation optional
346 } with {
347 variant (freq_par_len) "LENGTHTO(mobile_allocation,maio,padding)"
348/*
349 variant (padding) "PRESENCE(freq_par_len != 0)"
350 variant (maio) "PRESENCE(freq_par_len != 0)"
351 variant (mobile_allocation) "PRESENCE(freq_par_len != 0)"
352*/
353 };
354 type record IaRestOctHH {
355 BIT2 presence,
356 PacketUlAssign ul optional,
357 PacketDlAssign dl optional
358 } with {
359 variant (ul) "PRESENCE(presence = '00'B)"
360 variant (dl) "PRESENCE(presence = '01'B)"
361 };
362 type record PacketUlAssignDyn {
363 uint5_t tfi_assignment,
364 BIT1 polling,
365 BIT1 spare ('0'B),
366 uint3_t usf,
367 BIT1 usf_granularity,
368 BIT1 p0_present,
369 uint4_t p0 optional,
370 BIT1 pr_mode optional,
371 ChCodingCommand ch_coding_cmd,
372 BIT1 tlli_block_chan_coding,
373 BIT1 alpha_present,
374 uint4_t alpha optional,
375 uint5_t gamma,
376 BIT1 ta_index_present,
377 uint4_t ta_index optional,
378 BIT1 tbf_starting_time_present,
379 uint16_t tbf_starting_time optional
380 } with {
381 variant (p0) "PRESENCE(p0_present = '1'B)"
382 variant (pr_mode) "PRESENCE(p0_present = '1'B)"
383 variant (alpha) "PRESENCE(alpha_present = '1'B)"
384 variant (ta_index) "PRESENCE(ta_index_present = '1'B)"
385 variant (tbf_starting_time) "PRESENCE(tbf_starting_time_present = '1'B)"
386 };
387 type record PacketUlAssignSgl {
388 BIT1 alpha_present,
389 uint4_t alpha optional,
390 uint5_t gamma,
391 BIT2 padding ('01'B),
392 uint16_t tbf_starting_time
393 /* TODO: P0 / PR_MODE */
394 } with {
395 variant (alpha) "PRESENCE(alpha_present = '1'B)"
396 };
397 type record PacketUlAssign {
398 BIT1 presence,
399 PacketUlAssignDyn dynamic optional,
400 PacketUlAssignSgl single optional
401 /* TODO: Estended RA, PFI */
402 } with {
403 variant (dynamic) "PRESENCE(presence = '1'B)"
404 variant (single) "PRESENCE(presence = '0'B)"
405 };
406 type record PacketDlAssG1 {
407 uint5_t tfi_assignment,
408 BIT1 rlc_mode,
409 BIT1 alpha_present,
410 uint4_t alpha optional,
411 uint5_t gamma,
412 BIT1 polling,
413 BIT1 ta_valid
414 } with { variant "" };
415 type record PacketDlAssign {
416 GprsTlli tlli,
417 BIT1 group1_present,
418 PacketDlAssG1 group1 optional,
419 BIT1 ta_index_present,
420 uint4_t ta_index optional,
421 BIT1 tbf_starting_time_present,
422 uint16_t tbf_starting_time optional,
423 BIT1 p0_present,
424 uint4_t p0 optional,
425 BIT1 pr_mode optional
426 /* TODO: EGPRS window size, etc. */
427 } with {
428 variant (group1) "PRESENCE(group1_present = '1'B)"
429 variant (ta_index) "PRESENCE(ta_index_present = '1'B)"
430 variant (tbf_starting_time) "PRESENCE(tbf_starting_time_present = '1'B)"
431 variant (p0) "PRESENCE(p0_present = '1'B)"
432 variant (pr_mode) "PRESENCE(p0_present = '1'B)"
433 };
434 type record IaRestOctLL {
435 BIT1 compressed_irat_ho_info_ind
436 } with { variant "" };
437 type octetstring EgprsUlAss; /* TODO */
438 type octetstring MblkDlAss; /* TODO */
439 type record IaRestOctLH {
440 BIT2 presence,
441 EgprsUlAss egprs_ul optional,
442 MblkDlAss multiblock_dl_ass optional
443 } with {
444 variant (egprs_ul) "PRESENCE(presence = '00'B)"
445 variant (multiblock_dl_ass) "PRESENCE(presence = '01'B)"
446 };
447 type record IaRestOctets {
448 BIT2 presence,
449 IaRestOctLL ll optional,
450 IaRestOctLH lh optional,
451 IaRestOctHL hl optional,
452 IaRestOctHH hh optional
453 } with {
454 variant (ll) "PRESENCE(presence = '00'B)"
455 variant (lh) "PRESENCE(presence = '01'B)"
456 variant (hl) "PRESENCE(presence = '10'B)"
457 variant (hh) "PRESENCE(presence = '11'B)"
458 };
459
460
461 /* 9.1.18 */
462 type record ImmediateAssignment {
463 DedicatedModeOrTbf ded_or_tbf,
464 PageMode page_mode,
465 ChannelDescription chan_desc optional,
466 PacketChannelDescription pkt_chan_desc optional,
467 RequestReference req_ref,
468 TimingAdvance timing_advance,
469 MobileAllocation mobile_allocation,
470 /* TODO: starting time TLV */
471 IaRestOctets rest_octets
472 } with { variant (chan_desc) "PRESENCE(ded_or_tbf.tbf = false)"
473 variant (pkt_chan_desc) "PRESENCE(ded_or_tbf.tbf = true)" };
474
475 /* 9.1.20 */
476 type record ReqRefWaitInd {
477 RequestReference req_ref,
478 WaitIndication wait_ind
479 } with { variant "" };
480 type record length(4) of ReqRefWaitInd ReqRefWaitInd4;
481 type record ImmediateAssignmentReject {
482 FeatureIndicator feature_ind,
483 PageMode page_mode,
484 ReqRefWaitInd4 payload
485 } with { variant "" };
486
487 /* 9.1.22 */
488 type record PagingRequestType1 {
489 ChannelNeeded12 chan_needed,
490 PageMode page_mode,
491 MobileIdentityLV mi1,
492 MobileIdentityTLV mi2 optional,
493 RestOctets rest_octets
494 } with { variant "TAG(mi2, tag = 23)" };
495
496 /* 9.1.23 */
497 type record PagingRequestType2 {
498 ChannelNeeded12 chan_needed,
499 PageMode page_mode,
500 GsmTmsi mi1,
501 GsmTmsi mi2,
502 MobileIdentityTLV mi3 optional,
503 RestOctets rest_octets
504 } with { variant "TAG(mi3, tag = 23)" };
505
506 /* 9.1.24 */
507 type record length(4) of GsmTmsi GsmTmsi4;
508 type record PagingRequestType3 {
509 ChannelNeeded12 chan_needed,
510 PageMode page_mode,
511 GsmTmsi4 mi,
512 RestOctets rest_octets
513 } with { variant "" };
514
515
516 type union RrUnion {
517/*
518 SystemInformationType1 si1,
519 SystemInformationType2 si2,
520 SystemInformationType2bis si2bis,
521 SystemInformationType2ter si2ter,
522 SystemInformationType3 si3,
523 SystemInformationType4 si4,
524 SystemInformationType5 si5,
525 SystemInformationType5bis si5bis,
526 SystemInformationType5ter si5ter,
527 SystemInformationType6 si6,
528*/
529 ImmediateAssignment imm_ass,
530 ImmediateAssignmentReject imm_ass_rej,
531 PagingRequestType1 pag_req_1,
532 PagingRequestType2 pag_req_2,
533 PagingRequestType3 pag_req_3,
534 octetstring other
535 } with { variant "" };
536
537 /* Special RR Message on BCCH / CCCH Dowlink */
538
539 type record GsmRrMessage {
540 RrHeader header,
541 RrUnion payload
542 } with { variant (payload) "CROSSTAG(
543/*
544 si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
545 si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
546 si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis;
547 si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter;
548 si3, header.message_type = SYSTEM_INFORMATION_TYPE_3;
549 si4, header.message_type = SYSTEM_INFORMATION_TYPE_4;
550 si5, header.message_type = SYSTEM_INFORMATION_TYPE_5;
551 si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis;
552 si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter;
553 si6, header.message_type = SYSTEM_INFORMATION_TYPE_6;
554*/
555 imm_ass, header.message_type = IMMEDIATE_ASSIGNMENT;
556 imm_ass_rej, header.message_type = IMMEDIATE_ASSIGNMENT_REJECT;
557 pag_req_1, header.message_type = PAGING_REQUEST_TYPE_1;
558 pag_req_2, header.message_type = PAGING_REQUEST_TYPE_2;
559 pag_req_3, header.message_type = PAGING_REQUEST_TYPE_3;
560 other, OTHERWISE;
561 )" };
562
563 external function enc_GsmRrMessage(in GsmRrMessage msg) return octetstring
564 with { extension "prototype(convert) encode(RAW)" };
565 external function dec_GsmRrMessage(in octetstring stream) return GsmRrMessage
566 with { extension "prototype(convert) decode(RAW)" };
567
568 /* Normal L3 Message on Dedicated Channel */
569
570 /* 9.1.25 Paging Response */
571 type record PagingResponse {
572 uint4_t spare_half_octet,
573 CipheringKeySeqNr cksn,
574 MsClassmark2LV cm2,
575 MobileIdentityLV mi,
576 uint8_t addl_upd_par optional
577 } with { variant "" };
578
579 type union RrL3Union {
580 PagingResponse paging_response,
581 octetstring other
582 };
583
584 type record GsmRrL3Message {
585 RrL3Header header,
586 RrL3Union payload
587 } with { variant (payload) "CROSSTAG(
588 paging_response, header.message_type = PAGING_RESPONSE;
589
590 other, OTHERWISE;
591 )" }
592
593} with { encode "RAW" ; variant "FIELDORDER(msb)" }