blob: 160ae39c3aa60c7b60a1ad74b7a605f86626a9fe [file] [log] [blame]
Harald Welte9419c8a2017-07-30 04:07:05 +02001/* Encoding/Decoding routines for GSM System Information messages
Harald Welte34b5a952019-05-27 11:54:11 +02002 * according to 3GPP TS 44.018 Version 12.3.0 Release 12
3 *
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
Harald Welte9419c8a2017-07-30 04:07:05 +020012
13module GSM_RR_Types {
14
15 import from General_Types all;
16 import from Osmocom_Types all;
17 import from GSM_Types all;
Vadim Yanitskiy150d6d12022-10-20 19:10:04 +070018 import from GSM_RestOctets all;
Harald Welte9419c8a2017-07-30 04:07:05 +020019 import from RLCMAC_CSN1_Types all;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +070020 import from MobileL3_CommonIE_Types all;
Vadim Yanitskiy27b38012020-09-01 05:14:46 +070021 import from MobileL3_RRM_Types all;
Harald Welte9419c8a2017-07-30 04:07:05 +020022
23 /* Table 10.4.1 of Section 10.4 / 3GPP TS 44.018 */
24 type enumerated RrMessageType {
25 ADDITIONAL_ASSIGNMENT ('00111011'B),
26 IMMEDIATE_ASSIGNMENT ('00111111'B),
27 IMMEDIATE_ASSIGNMENT_EXTENDED ('00111001'B),
28 IMMEDIATE_ASSIGNMENT_REJECT ('00111010'B),
29 IMMEDIATE_PACKET_ASSIGNMENT ('01101001'B),
30
31 CIPHERING_MODE_COMMAND ('00110101'B),
32 CIPHERING_MODE_COMPLETE ('00110010'B),
33
34 CONFIGURATION_CHANGE_COMMAND ('00110000'B),
35 CONFIGURATION_CHANGE_ACK ('00110001'B),
36 CONFIGURATION_CHANGE_REJECT ('00110011'B),
37
38 ASSIGNMENT_COMMAND ('00101110'B),
39 ASSIGNMENT_COMPLETE ('00101001'B),
40 ASSIGNMENT_FAILURE ('00101111'B),
41 HANDOVER_COMMAND ('00101011'B),
42 HANDOVER_COMPLETE ('00101100'B),
43 HANDOVER_FAILURE ('00101000'B),
44 PHYSICAL_INFORMATION ('00101101'B),
45
46 CHANNEL_RELEASE ('00001101'B),
47 PARTIAL_RELEASE ('00001010'B),
48 PARTIAL_RELEASE_COMPLETE ('00001111'B),
49
50 PAGING_REQUEST_TYPE_1 ('00100001'B),
51 PAGING_REQUEST_TYPE_2 ('00100010'B),
52 PAGING_REQUEST_TYPE_3 ('00100100'B),
53 PAGING_RESPONSE ('00100111'B),
54 NOTIFICATION_NCH ('00100000'B),
55 NOTIFICATION_RESPOSNE ('00100110'B),
56
57 SYSTEM_INFORMATION_TYPE_8 ('00011000'B),
58 SYSTEM_INFORMATION_TYPE_1 ('00011001'B),
59 SYSTEM_INFORMATION_TYPE_2 ('00011010'B),
60 SYSTEM_INFORMATION_TYPE_3 ('00011011'B),
61 SYSTEM_INFORMATION_TYPE_4 ('00011100'B),
62 SYSTEM_INFORMATION_TYPE_5 ('00011101'B),
63 SYSTEM_INFORMATION_TYPE_6 ('00011110'B),
64 SYSTEM_INFORMATION_TYPE_7 ('00011111'B),
65 SYSTEM_INFORMATION_TYPE_2bis ('00000010'B),
66 SYSTEM_INFORMATION_TYPE_2ter ('00000011'B),
67 SYSTEM_INFORMATION_TYPE_2quater ('00000111'B),
68 SYSTEM_INFORMATION_TYPE_5bis ('00000101'B),
69 SYSTEM_INFORMATION_TYPE_5ter ('00000110'B),
70 SYSTEM_INFORMATION_TYPE_9 ('00000100'B),
71 SYSTEM_INFORMATION_TYPE_13 ('00000000'B),
72
73 SYSTEM_INFORMATION_TYPE_16 ('00111101'B),
74 SYSTEM_INFORMATION_TYPE_17 ('00111110'B),
75
76 CHANNEL_MODE_MODIFY ('00010000'B),
77 RR_STATUS ('00010010'B),
78 CHANNEL_MODE_MODIFY_ACKNOWLEDGE ('00010111'B),
79 FREQUENCY_REDEFINITION ('00010100'B),
80 MEASUREMENT_REPORT ('00010101'B),
81 CLASSMARK_CHANGE ('00010110'B),
82 CLASSMARK_ENQUIRY ('00010011'B),
83 EXTENDED_MEASUREMENT_REPORT ('00110110'B),
84 EXTENDED_MEASUREMENT_ORDER ('00110111'B),
85 GPRS_SUSPENSION_REQUEST ('00110100'B),
86 //MBMS_ANNOUNCEMENT ('00010110'B), duplicate?
87 //SERVICE_INFORMATION ('00110110'B), duplicate?
88
89 APPLICATION_INFORMATION ('00111000'B),
90
91 SYSTEM_INFORMATION_TYPE_14 ('00000001'B),
92 SYSTEM_INFORMATION_TYPE_15 ('01000011'B),
93 SYSTEM_INFORMATION_TYPE_18 ('01000000'B),
94 SYSTEM_INFORMATION_TYPE_19 ('01000001'B),
95 SYSTEM_INFORMATION_TYPE_20 ('01000010'B),
96 SYSTEM_INFORMATION_TYPE_13alt ('01000100'B),
97 SYSTEM_INFORMATION_TYPE_2n ('01000101'B),
98 SYSTEM_INFORMATION_TYPE_21 ('01000110'B),
99 SYSTEM_INFORMATION_TYPE_22 ('01000111'B),
100 SYSTEM_INFORMATION_TYPE_23 ('01001111'B),
101
102 DTM_ASSIGNMENT_FAILURE ('01001000'B),
103 DTM_REJECT ('01001001'B),
104 DTM_REQUEST ('01001010'B),
105 PACKET_ASSIGNMENT ('01001011'B),
106 DTM_ASSIGNMENT_COMMAND ('01001100'B),
107 DTM_INFORMATION ('01001101'B),
108 PACKET_INFORMATION ('01001110'B),
109
110 UTRAN_CLASSMARK_CHANGE ('01100000'B),
111 CDMA2000_CLASSMARK_CHANGE ('01100010'B),
112 INTERSYS_TO_UTRAN_HO_CMD ('01100011'B),
113 INTERSYS_TO_CDMA2000_HO_CMD ('01100100'B),
114 GERAN_IU_MODE_CLASSMARK_CHG ('01100101'B),
115 INTERSYS_TO_EUTRAN_HO_CMD ('01100110'B)
116 } with { variant "FIELDLENGTH(8)" };
117
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +0200118 type enumerated RR_Cause {
119 GSM48_RR_CAUSE_NORMAL ('00'O),
120 GSM48_RR_CAUSE_ABNORMAL_UNSPEC ('01'O),
121 GSM48_RR_CAUSE_ABNORMAL_UNACCT ('02'O),
122 GSM48_RR_CAUSE_ABNORMAL_TIMER ('03'O),
123 GSM48_RR_CAUSE_ABNORMAL_NOACT ('04'O),
124 GSM48_RR_CAUSE_PREMPTIVE_REL ('05'O),
125 GSM48_RR_CAUSE_HNDOVER_IMP ('08'O),
126 GSM48_RR_CAUSE_CHAN_MODE_UNACCT ('09'O),
127 GSM48_RR_CAUSE_FREQ_NOT_IMPL ('0a'O),
128 GSM48_RR_CAUSE_CALL_CLEARED ('41'O),
129 GSM48_RR_CAUSE_SEMANT_INCORR ('5f'O),
130 GSM48_RR_CAUSE_INVALID_MAND_INF ('60'O),
131 GSM48_RR_CAUSE_MSG_TYPE_N ('61'O),
132 GSM48_RR_CAUSE_MSG_TYPE_N_COMPAT('62'O),
133 GSM48_RR_CAUSE_COND_IE_ERROR ('64'O),
134 GSM48_RR_CAUSE_NO_CELL_ALLOC_A ('65'O),
135 GSM48_RR_CAUSE_PROT_ERROR_UNSPC ('6f'O)
136 } with { variant "FIELDLENGTH(8)" };
137
Harald Welte9419c8a2017-07-30 04:07:05 +0200138 type octetstring RestOctets with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" };
Harald Welte9419c8a2017-07-30 04:07:05 +0200139
140 type record L2PseudoLength {
141 uint6_t l2_plen,
142 BIT2 zero_one
143 } with { variant "" };
144
Harald Weltef8df4cb2018-03-10 15:15:08 +0100145 template L2PseudoLength tr_L2Pseudolength(template uint6_t len) := {
146 l2_plen := len,
147 zero_one := '01'B
148 };
149
150 template (value) L2PseudoLength ts_L2Pseudolength(uint6_t len) := {
Harald Welte9419c8a2017-07-30 04:07:05 +0200151 l2_plen := len,
152 zero_one := '01'B
153 };
154
155 type record RrHeader {
156 L2PseudoLength l2_plen,
157 uint4_t skip_indicator,
158 uint4_t rr_protocol_discriminator,
159 RrMessageType message_type
160 } with { variant "" };
161
162 template RrHeader t_RrHeader(RrMessageType msg_type, template uint6_t len) := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100163 l2_plen := tr_L2Pseudolength(len),
Harald Welte9419c8a2017-07-30 04:07:05 +0200164 skip_indicator := 0,
165 rr_protocol_discriminator := 6,
166 message_type := msg_type
167 };
168
Harald Weltef8df4cb2018-03-10 15:15:08 +0100169 template (value) RrHeader ts_RrHeader(RrMessageType msg_type, uint6_t len) := {
170 l2_plen := ts_L2Pseudolength(len),
171 skip_indicator := 0,
172 rr_protocol_discriminator := 6,
173 message_type := msg_type
174 };
175
176
Harald Welte9419c8a2017-07-30 04:07:05 +0200177 type record RrL3Header {
178 uint4_t skip_indicator,
179 uint4_t rr_protocol_discriminator,
180 RrMessageType message_type
181 } with { variant "" };
182
Harald Weltecbc947f2018-02-22 00:26:55 +0100183 template RrL3Header t_RrL3Header(RrMessageType msg_type) := {
184 skip_indicator := 0,
185 rr_protocol_discriminator := 6,
186 message_type := msg_type
187 }
188
Pau Espin Pedrol0aad5962018-09-28 16:03:55 +0200189 /* TS 44.004 7.2.1 */
190 type record SacchL1Header {
191 uint2_t reserved,
192 boolean fpc,
193 uint5_t ms_power_lvl,
194 uint8_t actual_ta
195 } with { variant "FIELDORDER(msb)" };
196
Vadim Yanitskiy79da4ce2020-10-17 15:48:47 +0700197 external function enc_SacchL1Header(in SacchL1Header hdr) return octetstring
198 with { extension "prototype(convert) encode(RAW)" };
199 external function dec_SacchL1Header(in octetstring stream) return SacchL1Header
200 with { extension "prototype(convert) decode(RAW)" };
201
Vadim Yanitskiy68c4cff2022-07-30 23:45:02 +0700202 template (value) SacchL1Header
203 ts_SacchL1Header(uint5_t ms_power_lvl,
204 uint8_t actual_ta,
205 boolean fpc := false) := {
Pau Espin Pedrol0aad5962018-09-28 16:03:55 +0200206 reserved := 0,
207 fpc := fpc,
208 ms_power_lvl := ms_power_lvl,
209 actual_ta := actual_ta
210 };
211
Harald Welte9419c8a2017-07-30 04:07:05 +0200212 type record MaioHsn {
Vadim Yanitskiyff0072c2020-05-27 01:35:39 +0700213 uint6_t maio,
214 uint6_t hsn
Harald Welte9419c8a2017-07-30 04:07:05 +0200215 } with { variant "" };
216
Vadim Yanitskiy5bcd9192020-07-06 20:18:11 +0700217 /* It's more handy to pass HSN first, so the arguments' order is reversed. */
218 template (value) MaioHsn ts_HsnMaio(template (value) uint6_t hsn,
219 template (value) uint6_t maio) := {
220 maio := maio,
221 hsn := hsn
222 };
223 template MaioHsn tr_HsnMaio(template (present) uint6_t hsn,
224 template (present) uint6_t maio) := {
225 maio := maio,
226 hsn := hsn
227 };
228
Harald Welte9419c8a2017-07-30 04:07:05 +0200229 /* TS 24.008 10.5.1.2 */
230 type uint4_t CipheringKeySeqNr (0..7);
231
Harald Welte9419c8a2017-07-30 04:07:05 +0200232 /* TS 24.008 10.5.1.4 */
233 type enumerated MobileIdentityType {
234 MI_TYPE_NONE (0),
235 MI_TYPE_IMSI,
236 MI_TYPE_IMEI,
237 MI_TYPE_IMEISV,
238 MI_TYPE_TMSI,
239 MI_TYPE_TMGI
240 } with { variant "FIELDLENGTH(3)" };
241
Harald Welte9419c8a2017-07-30 04:07:05 +0200242 /* TS 24.008 10.5.1.5 */
243 type record MsClassmark1 {
244 BIT1 spare,
245 uint2_t rev_level,
246 boolean es_ind,
247 boolean a51,
248 uint3_t rf_pwr_cap
249 } with { variant "" };
250
251 /* TS 24.008 10.5.1.6 */
252 type record MsClassmark2 {
253 BIT1 spare,
254 uint2_t rev_level,
255 boolean es_ind,
256 boolean a51,
257 uint3_t rf_pwr_cap,
258 BIT1 spare1,
259 boolean ps_cap,
260 uint2_t ss_screen_ind,
261 boolean sm_cap,
262 boolean vbs,
263 boolean vgcs,
264 boolean fc,
265 boolean cm3,
266 BIT1 spare2,
267 boolean lcsva_cap,
268 boolean ucs2,
269 boolean solsa,
270 boolean cmsp,
271 boolean a53,
272 boolean a52
273 } with { variant "" };
274 type record MsClassmark2LV {
275 uint8_t len,
276 MsClassmark2 cm2
277 } with { variant (len) "LENGTHTO(cm2)" };
278
279
280 /* 44.018 10.5.2.5 */
281 type record ChannelDescription {
282 RslChannelNr chan_nr,
283 uint3_t tsc,
284 boolean h,
285 uint12_t arfcn optional,
286 MaioHsn maio_hsn optional
287 } with { variant (arfcn) "PRESENCE(h = false)"
288 variant (maio_hsn) "PRESENCE(h = true)" };
289
290 type record ChannelDescriptionTV {
291 OCT1 iei,
292 ChannelDescription v
293 } with { variant "" };
294
295 /* 10.5.2.21 */
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +0700296 type record MobileAllocationLV {
Harald Welte9419c8a2017-07-30 04:07:05 +0200297 uint8_t len,
Vadim Yanitskiy7d6eef32020-08-29 02:56:58 +0700298 bitstring ma length (0..64)
Vadim Yanitskiy3ddb3ab2020-07-20 04:29:53 +0700299 } with {
300 variant (len) "LENGTHTO(ma)"
Vadim Yanitskiye2a6fdf2020-07-23 04:53:02 +0700301 variant (ma) "BYTEORDER(first), BITORDER(msb)"
Vadim Yanitskiy3ddb3ab2020-07-20 04:29:53 +0700302 };
Harald Welte9419c8a2017-07-30 04:07:05 +0200303
Vadim Yanitskiy74e1f6b2020-08-25 03:59:45 +0700304 type record MobileAllocationTLV {
305 OCT1 iei ('72'O),
306 MobileAllocationLV v
307 } with { variant "" };
308
Harald Welte9419c8a2017-07-30 04:07:05 +0200309 /* 10.5.2.25a */
Harald Welte1b9b7702017-07-30 04:19:14 +0200310 type record PktChDesc0Ind {
311 uint6_t maio,
312 BIT1 ma_number_ind,
313 BIT1 change_mark1_valid,
314 BIT2 change_mark1
315 } with { variant "" };
316 type record PktChDesc0 {
317 BIT1 hopping,
318 BIT1 spare ('0'B),
319 uint10_t arfcn optional,
320 PktChDesc0Ind indirect optional
321 } with {
322 variant (arfcn) "PRESENCE(hopping = '0'B)"
323 variant (indirect) "PRESENCE(hopping = '1'B)"
324 };
325 type record PktChDesc1 {
326 uint6_t maio,
327 uint6_t hsn
328 } with { variant "" };
329 type record PacketChannelDescription {
330 uint5_t channel_Type_spare,
331 uint3_t tn,
332 uint3_t tsc,
333 BIT1 presence,
334 PktChDesc0 zero optional,
335 PktChDesc1 one optional
336 } with {
337 variant (zero) "PRESENCE(presence = '0'B)"
338 variant (one) "PRESENCE(presence = '1'B)"
339 };
Harald Welte9419c8a2017-07-30 04:07:05 +0200340
341 /* 10.5.2.25b */
342 type record DedicatedModeOrTbf {
343 BIT1 spare,
344 boolean tma,
345 boolean downlink,
346 boolean tbf
347 } with { variant "" };
348
349 /* 10.5.2.26 */
350 type enumerated PageMode {
351 PAGE_MODE_NORMAL,
352 PAGE_MODE_EXTENDED,
353 PAGE_MODE_REORGANIZATION,
354 PAGE_MODE_SAME_AS_BEFORE
355 } with { variant "FIELDLENGTH(4)" };
356
357 /* 10.5.2.30 */
358 type record RequestReference {
359 bitstring ra length(8),
360 uint5_t t1p,
361 uint6_t t3,
362 uint5_t t2
363 } with { variant "" };
364
365 template RequestReference t_RequestReference(template bitstring ra, template uint5_t t1p, template uint6_t t3, template uint5_t t2) := {
366 ra := ra,
367 t1p := t1p,
368 t3 := t3,
369 t2 := t2
370 }
371
372 /* compute the expected request reference for given RA + FN */
373 function f_compute_ReqRef(uint8_t ra, GsmFrameNumber fn) return RequestReference {
374 var RequestReference req_ref := { ra := int2bit(ra, 8) };
375 req_ref.t1p := (fn / 1326) mod 32;
376 req_ref.t2 := fn mod 26;
377 req_ref.t3 := fn mod 51;
378 return req_ref
379 }
Harald Weltee8d750e2018-06-10 21:41:35 +0200380 function tr_compute_ReqRef(template uint8_t ra, template GsmFrameNumber fn)
381 return template RequestReference {
382 var template RequestReference req_ref;
383 if (istemplatekind(ra, "?")) {
384 req_ref.ra := ?;
385 } else {
386 req_ref.ra := int2bit(valueof(ra), 8);
387 }
388 if (istemplatekind(fn, "?")) {
389 req_ref.t1p := ?;
390 req_ref.t2 := ?;
391 req_ref.t3 := ?;
392 } else {
393 var GsmFrameNumber fn_v := valueof(fn);
394 req_ref.t1p := (fn_v / 1326) mod 32;
395 req_ref.t2 := fn_v mod 26;
396 req_ref.t3 := fn_v mod 51;
397 }
398 return req_ref;
399 }
Harald Welte9419c8a2017-07-30 04:07:05 +0200400
401 /* 10.5.2.40 */
402 type integer TimingAdvance (0..219);
403
404 /* 10.5.2.43 */
405 type uint8_t WaitIndication;
406
407 /* 10.5.2.76 */
408 type record FeatureIndicator {
Vadim Yanitskiyc3cebd32020-05-22 02:43:22 +0700409 BIT2 peo_bcch_change_mark,
410 boolean cs_ir,
411 boolean ps_ir
412 } with {
413 variant (cs_ir) "FIELDLENGTH(1)"
414 variant (ps_ir) "FIELDLENGTH(1)"
415 };
Harald Welte9419c8a2017-07-30 04:07:05 +0200416
417 /* 24.008 10.5.5.6 */
418 type record DrxParameter {
419 uint8_t split_pg_cycle_code,
420 uint4_t drx_cycle_len_coeff,
421 boolean split_on_ccch,
422 uint3_t non_drx_timer
423 } with { variant "" };
424
Harald Weltecbc947f2018-02-22 00:26:55 +0100425 type record MeasurementResults {
426 BIT1 ba_used,
427 BIT1 dtx_used,
428 uint6_t rxlev_full_srv_cell,
429 BIT1 threeg_ba_used,
430 BIT1 meas_valid,
431 uint6_t rxlev_sub_srv_cell,
432 BIT1 si23_ba_used,
433 uint3_t rxqual_full_srv_cell,
434 uint3_t rxqual_sub_srv_cell,
435 uint3_t no_ncell_m,
436 NcellReports ncell_reports optional
437 } with { variant (no_ncell_m) "LENGTHTO(ncell_reports)"
438 variant (no_ncell_m) "UNIT(elements)"
Vadim Yanitskiy9cbb86f2021-11-04 18:50:22 +0300439 /* FIXME: pad to 16 octets */
Harald Weltecbc947f2018-02-22 00:26:55 +0100440 };
441
442 type record NcellReport {
443 uint6_t rxlev,
444 uint5_t bcch_freq,
445 uint6_t bsic
446 } with { variant ""};
447 type record of NcellReport NcellReports;
448
Harald Welte9419c8a2017-07-30 04:07:05 +0200449
Vadim Yanitskiy27b38012020-09-01 05:14:46 +0700450 /* 3GPP TS 44.018, section 9.1.2 (minimalistic implementation) */
451 type record AssignmentCommand {
452 ChannelDescription chan_desc,
453 PowerCommand_V power_cmd,
454 FrequencyList_TLV freq_list_at optional,
455 CellChannelDescription_TV cell_chan_desc optional,
456 /* TODO: Multislot Allocation IE */
457 ChannelMode_TV chan1_mode optional,
458 ChannelMode_TV chan2_mode optional,
459 /* TODO: Mode of Channel Set 3..8 IE */
460 MobileAllocationTLV mobile_allocation optional
461 /* TODO: more optional IEs... */
462 } with {
463 variant "TAG(
464 freq_list_at, elementIdentifier = '05'O;
465 cell_chan_desc, elementIdentifier = '62'O;
466 chan1_mode, elementIdentifier = '63'O;
467 chan2_mode, elementIdentifier = '11'O;
468 mobile_allocation, iei = '72'O;
469 )"
470 };
471
Vadim Yanitskiy5fec37c2020-09-02 17:19:47 +0700472 /* 3GPP TS 44.018, section 9.1.15 (minimalistic implementation) */
473 type record HandoverCommand {
474 CellDescriptionV cell_desc,
475 ChannelDescription chan_desc,
476 OCT1 ho_ref,
477 PowerCommandAndAccesstype_V power_cmd_acc_type,
478 FrequencyList_TLV freq_list_at optional,
479 CellChannelDescription_TV cell_chan_desc optional,
480 ChannelMode_TV chan1_mode optional,
481 ChannelMode_TV chan2_mode optional,
482 /* TODO: Mode of Channel Set 3..8 IE */
483 MobileAllocationTLV mobile_allocation optional
484 /* TODO: more optional IEs... */
485 } with {
486 variant "TAG(
487 freq_list_at, elementIdentifier = '05'O;
488 cell_chan_desc, elementIdentifier = '62'O;
489 chan1_mode, elementIdentifier = '63'O;
490 chan2_mode, elementIdentifier = '11'O;
491 mobile_allocation, iei = '72'O;
492 )"
493 };
494
495 /* 10.5.2.2 Cell Description IE */
496 type record CellDescriptionV {
497 uint3_t bcc, /* PLMN colour code */
498 uint3_t ncc, /* BS colour code */
499 uint10_t bcch_arfcn
500 } with { variant "FIELDORDER(lsb)" };
501
Vadim Yanitskiy27b38012020-09-01 05:14:46 +0700502
Harald Welte9419c8a2017-07-30 04:07:05 +0200503 /* 9.1.18 */
504 type record ImmediateAssignment {
505 DedicatedModeOrTbf ded_or_tbf,
506 PageMode page_mode,
507 ChannelDescription chan_desc optional,
508 PacketChannelDescription pkt_chan_desc optional,
509 RequestReference req_ref,
510 TimingAdvance timing_advance,
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +0700511 MobileAllocationLV mobile_allocation,
Harald Welte9419c8a2017-07-30 04:07:05 +0200512 /* TODO: starting time TLV */
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200513 IaRestOctets rest_octets
Harald Welte9419c8a2017-07-30 04:07:05 +0200514 } with { variant (chan_desc) "PRESENCE(ded_or_tbf.tbf = false)"
Vadim Yanitskiya4aacc22019-09-09 04:41:12 +0200515 variant (pkt_chan_desc) "PRESENCE(ded_or_tbf.tbf = true)" };
Harald Welte9419c8a2017-07-30 04:07:05 +0200516
517 /* 9.1.20 */
518 type record ReqRefWaitInd {
519 RequestReference req_ref,
520 WaitIndication wait_ind
521 } with { variant "" };
522 type record length(4) of ReqRefWaitInd ReqRefWaitInd4;
523 type record ImmediateAssignmentReject {
524 FeatureIndicator feature_ind,
525 PageMode page_mode,
Vadim Yanitskiy7ef121d2020-05-22 03:04:22 +0700526 ReqRefWaitInd4 payload,
527 IARRestOctets rest_octets
Harald Welte9419c8a2017-07-30 04:07:05 +0200528 } with { variant "" };
529
Harald Weltecbc947f2018-02-22 00:26:55 +0100530 /* 9.1.21 */
531 type record MeasurementReport {
532 MeasurementResults meas_res
533 } with { variant "" };
534
Harald Welte9419c8a2017-07-30 04:07:05 +0200535 /* 9.1.22 */
536 type record PagingRequestType1 {
537 ChannelNeeded12 chan_needed,
538 PageMode page_mode,
539 MobileIdentityLV mi1,
540 MobileIdentityTLV mi2 optional,
541 RestOctets rest_octets
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700542 } with { variant "TAG(mi2, elementIdentifier = '0010111'B)" };
Harald Welte9419c8a2017-07-30 04:07:05 +0200543
544 /* 9.1.23 */
545 type record PagingRequestType2 {
546 ChannelNeeded12 chan_needed,
547 PageMode page_mode,
548 GsmTmsi mi1,
549 GsmTmsi mi2,
550 MobileIdentityTLV mi3 optional,
551 RestOctets rest_octets
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700552 } with { variant "TAG(mi3, elementIdentifier = '0010111'B)" };
Harald Welte9419c8a2017-07-30 04:07:05 +0200553
554 /* 9.1.24 */
555 type record length(4) of GsmTmsi GsmTmsi4;
556 type record PagingRequestType3 {
557 ChannelNeeded12 chan_needed,
558 PageMode page_mode,
559 GsmTmsi4 mi,
560 RestOctets rest_octets
561 } with { variant "" };
562
Harald Welte9419c8a2017-07-30 04:07:05 +0200563 type union RrUnion {
564/*
565 SystemInformationType1 si1,
566 SystemInformationType2 si2,
567 SystemInformationType2bis si2bis,
568 SystemInformationType2ter si2ter,
Harald Welte82ccef72018-02-25 16:17:33 +0100569 SystemInformationType3 si3,
Harald Welte9419c8a2017-07-30 04:07:05 +0200570 SystemInformationType4 si4,
571 SystemInformationType5 si5,
572 SystemInformationType5bis si5bis,
573 SystemInformationType5ter si5ter,
574 SystemInformationType6 si6,
575*/
576 ImmediateAssignment imm_ass,
577 ImmediateAssignmentReject imm_ass_rej,
578 PagingRequestType1 pag_req_1,
579 PagingRequestType2 pag_req_2,
580 PagingRequestType3 pag_req_3,
581 octetstring other
582 } with { variant "" };
583
584 /* Special RR Message on BCCH / CCCH Dowlink */
585
586 type record GsmRrMessage {
587 RrHeader header,
588 RrUnion payload
589 } with { variant (payload) "CROSSTAG(
590/*
591 si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
592 si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
593 si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis;
594 si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter;
595 si3, header.message_type = SYSTEM_INFORMATION_TYPE_3;
596 si4, header.message_type = SYSTEM_INFORMATION_TYPE_4;
597 si5, header.message_type = SYSTEM_INFORMATION_TYPE_5;
598 si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis;
599 si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter;
600 si6, header.message_type = SYSTEM_INFORMATION_TYPE_6;
601*/
602 imm_ass, header.message_type = IMMEDIATE_ASSIGNMENT;
603 imm_ass_rej, header.message_type = IMMEDIATE_ASSIGNMENT_REJECT;
604 pag_req_1, header.message_type = PAGING_REQUEST_TYPE_1;
605 pag_req_2, header.message_type = PAGING_REQUEST_TYPE_2;
606 pag_req_3, header.message_type = PAGING_REQUEST_TYPE_3;
607 other, OTHERWISE;
Vadim Yanitskiya4aacc22019-09-09 04:41:12 +0200608 )"
609 /* Total message length: 184 = 23 * 8. Pad spare bits with '2B'O. */
610 variant "PADDING(184), PADDING_PATTERN('00101011'B)"
611 };
Harald Welte9419c8a2017-07-30 04:07:05 +0200612
613 external function enc_GsmRrMessage(in GsmRrMessage msg) return octetstring
614 with { extension "prototype(convert) encode(RAW)" };
615 external function dec_GsmRrMessage(in octetstring stream) return GsmRrMessage
616 with { extension "prototype(convert) decode(RAW)" };
617
618 /* Normal L3 Message on Dedicated Channel */
619
620 /* 9.1.25 Paging Response */
621 type record PagingResponse {
622 uint4_t spare_half_octet,
623 CipheringKeySeqNr cksn,
624 MsClassmark2LV cm2,
625 MobileIdentityLV mi,
626 uint8_t addl_upd_par optional
627 } with { variant "" };
628
629 type union RrL3Union {
Vadim Yanitskiy480c2ac2020-09-01 05:43:06 +0700630 PagingResponse paging_response,
631 MeasurementReport meas_rep,
632 AssignmentCommand ass_cmd,
Vadim Yanitskiy5fec37c2020-09-02 17:19:47 +0700633 HandoverCommand ho_cmd,
Vadim Yanitskiy480c2ac2020-09-01 05:43:06 +0700634 octetstring other
Harald Welte9419c8a2017-07-30 04:07:05 +0200635 };
636
637 type record GsmRrL3Message {
638 RrL3Header header,
639 RrL3Union payload
640 } with { variant (payload) "CROSSTAG(
641 paging_response, header.message_type = PAGING_RESPONSE;
Harald Weltecbc947f2018-02-22 00:26:55 +0100642 meas_rep, header.message_type = MEASUREMENT_REPORT;
Vadim Yanitskiy27b38012020-09-01 05:14:46 +0700643 ass_cmd, header.message_type = ASSIGNMENT_COMMAND;
Vadim Yanitskiy5fec37c2020-09-02 17:19:47 +0700644 ho_cmd, header.message_type = HANDOVER_COMMAND;
Harald Welte9419c8a2017-07-30 04:07:05 +0200645 other, OTHERWISE;
646 )" }
647
Harald Weltecbc947f2018-02-22 00:26:55 +0100648 external function enc_GsmRrL3Message(in GsmRrL3Message msg) return octetstring
649 with { extension "prototype(convert) encode(RAW)" };
650 external function dec_GsmRrL3Message(in octetstring stream) return GsmRrL3Message
651 with { extension "prototype(convert) decode(RAW)" };
652
653
Harald Weltee8d750e2018-06-10 21:41:35 +0200654 template (value) GsmRrMessage ts_IMM_ASS(uint8_t ra, GsmFrameNumber fn, TimingAdvance ta,
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +0700655 ChannelDescription ch_desc, MobileAllocationLV ma) := {
Harald Weltebae6be82020-08-21 12:42:18 +0200656 header := ts_RrHeader(IMMEDIATE_ASSIGNMENT, 0),
Harald Weltecbc947f2018-02-22 00:26:55 +0100657 payload := {
658 imm_ass := {
659 ded_or_tbf := {
660 spare := '0'B,
661 tma := false,
662 downlink := false,
663 tbf := false
664 },
665 page_mode := PAGE_MODE_NORMAL,
666 chan_desc := ch_desc,
667 pkt_chan_desc := omit,
668 req_ref := f_compute_ReqRef(ra, fn),
669 timing_advance := ta,
670 mobile_allocation := ma,
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200671 rest_octets := {
672 presence := '00'B, /* LL */
673 ll := {
Vadim Yanitskiyb021ed42020-04-27 23:25:13 +0700674 compressed_irat_ho_info_ind := '0'B /* L */
Vadim Yanitskiy9b2a3e82019-09-08 15:37:15 +0200675 },
676 lh := omit, hl := omit, hh := omit
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200677 }
Harald Weltecbc947f2018-02-22 00:26:55 +0100678 }
679 }
680 };
681
Harald Weltee8d750e2018-06-10 21:41:35 +0200682 template GsmRrMessage tr_IMM_ASS(template uint8_t ra := ?, template GsmFrameNumber fn := ?,
683 template TimingAdvance ta := ?,
684 template ChannelDescription ch_desc := ?,
Neels Hofmeyrb07b2952021-08-07 04:23:14 +0200685 template MobileAllocationLV ma := ?,
686 template PageMode page_mode := PAGE_MODE_NORMAL) := {
Vadim Yanitskiyd4205c32019-09-09 16:15:37 +0200687 header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?),
Harald Weltee8d750e2018-06-10 21:41:35 +0200688 payload := {
689 imm_ass := {
690 ded_or_tbf := {
691 spare := '0'B,
692 tma := false,
693 downlink := false,
694 tbf := false
695 },
Neels Hofmeyrb07b2952021-08-07 04:23:14 +0200696 page_mode := page_mode,
Harald Weltee8d750e2018-06-10 21:41:35 +0200697 chan_desc := ch_desc,
698 pkt_chan_desc := omit,
699 req_ref := tr_compute_ReqRef(ra, fn),
700 timing_advance := ta,
701 mobile_allocation := ma,
Vadim Yanitskiyf10bb452019-09-05 13:53:01 +0200702 rest_octets := ?
Harald Weltee8d750e2018-06-10 21:41:35 +0200703 }
704 }
705 };
706
Vadim Yanitskiy6edd4f52019-09-09 01:51:09 +0200707 /* TODO: implement send version of this template */
708 template GsmRrMessage tr_IMM_TBF_ASS(template boolean dl := ?,
709 template uint8_t ra := ?,
710 template GsmFrameNumber fn := ?,
711 template TimingAdvance ta := ?,
712 template PacketChannelDescription ch_desc := ?,
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +0700713 template MobileAllocationLV ma := ?,
Vadim Yanitskiy6edd4f52019-09-09 01:51:09 +0200714 template IaRestOctets rest := ?) := {
715 header := t_RrHeader(IMMEDIATE_ASSIGNMENT, ?),
716 payload := {
717 imm_ass := {
718 ded_or_tbf := {
719 spare := ?,
720 tma := ?,
721 downlink := dl,
722 tbf := true
723 },
724 page_mode := ?,
725 chan_desc := omit,
726 pkt_chan_desc := ch_desc,
727 req_ref := tr_compute_ReqRef(ra, fn),
728 timing_advance := ta,
Vadim Yanitskiycf1ed3f2020-07-20 04:01:43 +0700729 mobile_allocation := ma,
Vadim Yanitskiy6edd4f52019-09-09 01:51:09 +0200730 rest_octets := rest
731 }
732 }
733 };
Harald Weltee8d750e2018-06-10 21:41:35 +0200734
Vadim Yanitskiy9781ecb2020-03-28 03:59:41 +0700735 template GsmRrMessage tr_PAG_REQ1(template MobileIdentityLV mi1 := ?,
736 template MobileIdentityTLV mi2 := omit) := {
Pau Espin Pedrol88bf5372019-12-09 21:12:28 +0100737 header := t_RrHeader(PAGING_REQUEST_TYPE_1, ?),
738 payload := {
739 pag_req_1 := {
740 chan_needed := {
741 second := ?,
742 first := ?
743 },
744 page_mode := PAGE_MODE_NORMAL,
745 mi1 := mi1,
Vadim Yanitskiy9781ecb2020-03-28 03:59:41 +0700746 mi2 := mi2,
Pau Espin Pedrol88bf5372019-12-09 21:12:28 +0100747 rest_octets := ?
748 }
749 }
750 };
751
Vadim Yanitskiyf9e31d22021-11-06 18:43:28 +0300752 template (value) MeasurementResults
753 ts_MeasurementResults(template (value) uint6_t rxl_f := 63,
754 template (value) uint6_t rxl_s := 63,
755 template (value) uint3_t rxq_f := 0,
756 template (value) uint3_t rxq_s := 0,
757 boolean dtx_used := false,
758 boolean valid := true,
759 template (omit) NcellReports reps := omit) := {
760 ba_used := '0'B,
761 dtx_used := bool2bit(dtx_used),
762 rxlev_full_srv_cell := rxl_f,
763 threeg_ba_used := '0'B,
764 meas_valid := bool2bit(not valid),
765 rxlev_sub_srv_cell := rxl_s,
766 si23_ba_used := '0'B,
767 rxqual_full_srv_cell := rxq_f,
768 rxqual_sub_srv_cell := rxq_s,
769 no_ncell_m := 0,
770 ncell_reports := reps
771 };
772
Vadim Yanitskiybc8ebce2020-11-11 19:31:56 +0700773 template (value) GsmRrL3Message ts_MEAS_REP(boolean valid,
774 template (value) uint6_t rxl_f,
775 template (value) uint6_t rxl_s,
776 template (value) uint3_t rxq_f := 0,
777 template (value) uint3_t rxq_s := 0,
778 template (omit) NcellReports reps := omit) := {
Harald Weltecbc947f2018-02-22 00:26:55 +0100779 header := t_RrL3Header(MEASUREMENT_REPORT),
780 payload := {
781 meas_rep := {
782 meas_res := {
783 ba_used := '0'B,
784 dtx_used := '0'B,
785 rxlev_full_srv_cell := rxl_f,
786 threeg_ba_used := '0'B,
Harald Welteeb1e6812018-02-22 18:43:48 +0100787 meas_valid := bool2bit(not valid),
Harald Weltecbc947f2018-02-22 00:26:55 +0100788 rxlev_sub_srv_cell := rxl_s,
789 si23_ba_used := '0'B,
790 rxqual_full_srv_cell := rxq_f,
791 rxqual_sub_srv_cell := rxq_s,
792 no_ncell_m := 0,
793 ncell_reports := reps
794 }
795 }
796 }
797 };
798
Vadim Yanitskiy16e24aa2020-05-22 03:32:00 +0700799 template GsmRrMessage tr_IMM_ASS_REJ(template FeatureIndicator feature_ind := ?,
800 template ReqRefWaitInd4 rr_wi_list := ?,
801 template IARRestOctets rest_octets := ?) := {
802 header := t_RrHeader(IMMEDIATE_ASSIGNMENT_REJECT, ?),
803 payload := {
804 imm_ass_rej := {
805 feature_ind := feature_ind,
806 page_mode := ?,
807 payload := rr_wi_list,
808 rest_octets := rest_octets
809 }
810 }
811 };
812
813 template ReqRefWaitInd tr_ReqRefWaitInd(template RequestReference ref := ?,
814 template WaitIndication wi := ?) := {
815 req_ref := ref,
816 wait_ind := wi
817 };
818
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +0700819 template (value) ChannelDescription ts_ChanDescH0(template (value) RslChannelNr chan_nr,
820 template (value) uint12_t arfcn,
821 template (value) uint3_t tsc := 7) := {
822 chan_nr := chan_nr,
823 tsc := tsc,
824 h := false,
825 arfcn := arfcn,
826 maio_hsn := omit
827 }
Vadim Yanitskiyc3156ed2020-08-29 17:49:27 +0700828 template ChannelDescription tr_ChanDescH0(template (present) RslChannelNr chan_nr := ?,
829 template (present) uint12_t arfcn := ?,
830 template (present) uint3_t tsc := ?) := {
831 chan_nr := chan_nr,
832 tsc := tsc,
833 h := false,
834 arfcn := arfcn,
835 maio_hsn := omit
836 }
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +0700837
838 template (value) ChannelDescription ts_ChanDescH1(template (value) RslChannelNr chan_nr,
839 template (value) MaioHsn maio_hsn,
840 template (value) uint3_t tsc := 7) := {
841 chan_nr := chan_nr,
842 tsc := tsc,
843 h := true,
844 arfcn := omit,
845 maio_hsn := maio_hsn
846 }
Vadim Yanitskiyc3156ed2020-08-29 17:49:27 +0700847 template ChannelDescription tr_ChanDescH1(template (present) RslChannelNr chan_nr := ?,
848 template (present) MaioHsn maio_hsn := ?,
849 template (present) uint3_t tsc := ?) := {
850 chan_nr := chan_nr,
851 tsc := tsc,
852 h := true,
853 arfcn := omit,
854 maio_hsn := maio_hsn
855 }
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +0700856
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +0200857
858 /* Templates for the RR Channel Release message's "Cell selection indicator after release of all TCH and SDCCH" IE.
859 * See 3GPP TS 44.018 9.1.7 and 10.5.2.1e */
860
861 /* 3GPP TS 44.018 10.5.2.1e, Cell Selection Indicator after release of all TCH and SDCCH value part */
862 type record CellSelIndValue {
863 BIT3 discr,
864 CellSelIndValueEnum value_list,
865 BIT1 value_list_term ('0'B)
866 } with {
867 variant (value_list) "CROSSTAG(
868 gsm, discr='000'B;
869 utran_fdd, discr='001'B;
870 utran_tdd, discr='010'B;
871 eutran, discr='011'B;
872 )"
873 };
874
875 /* 3GPP TS 44.018 10.5.2.1e, Cell Selection Indicator after release of all TCH and SDCCH value part */
876 private type union CellSelIndValueEnum {
877 CellSelIndValue_GSM_Descrs gsm,
878 CellSelIndValue_UTRAN_Descrs utran_fdd,
879 CellSelIndValue_UTRAN_Descrs utran_tdd,
880 CellSelIndValue_EUTRAN_Descrs eutran
881 } with { variant "" };
882
883 type record of CellSelIndValue_GSM_Descr CellSelIndValue_GSM_Descrs;
884 /* 3GPP TS 44.018 10.5.2.1e, GSM Description struct */
885 type record CellSelIndValue_GSM_Descr {
886 BIT1 item_ind ('1'B),
887 BIT1 band_indicator,
888 uint10_t arfcn,
889 uint6_t bsic
890 } with {
891 variant "PRESENCE(item_ind = '1'B)"
892 };
893
894 type record of CellSelIndValue_UTRAN_Descr CellSelIndValue_UTRAN_Descrs;
895 /* 3GPP TS 44.018 10.5.2.1e, UTRAN {FDD,TDD} Description struct */
896 type record CellSelIndValue_UTRAN_Descr {
897 BIT1 item_ind ('1'B),
898 BIT1 bandwidth_presence,
899 uint3_t bandwidth optional,
900 uint14_t arfcn,
901 BIT1 cell_info_presence,
902 UTRAN_CellInfo cell_info optional
903 } with {
904 variant "PRESENCE(item_ind = '1'B)"
905 variant (bandwidth) "PRESENCE(bandwidth_presence = '1'B)"
906 variant (cell_info) "PRESENCE(cell_info_presence = '1'B)"
907 };
908 type record UTRAN_CellInfo {
909 BIT1 indic0,
910 uint5_t nr_of_cells,
911 // TODO: define cell_information_field
912 octetstring cell_information_field
913 } with { variant "" };
914
915 type record of CellSelIndValue_EUTRAN_Descr CellSelIndValue_EUTRAN_Descrs;
916 /* 3GPP TS 44.018 10.5.2.1e, E-UTRAN Description struct */
917 type record CellSelIndValue_EUTRAN_Descr {
918 BIT1 item_ind ('1'B),
919 uint16_t earfcn,
920 BIT1 meas_bw_presence,
921 uint3_t meas_bw optional,
922 BIT1 not_allowed_cells_presence,
923 // define not_allowed_cells
924 octetstring not_allowed_cells optional,
925 BIT1 target_pcid_presence,
926 uint9_t target_pcid optional
927 } with {
928 variant "PRESENCE(item_ind = '1'B)"
929 variant (meas_bw) "PRESENCE(meas_bw_presence = '1'B)"
930 variant (not_allowed_cells) "PRESENCE(not_allowed_cells_presence = '1'B)"
931 variant (target_pcid) "PRESENCE(target_pcid_presence = '1'B)"
932 };
933
934 template CellSelIndValue tr_CellSelIndValue_EUTRAN(
935 template CellSelIndValue_EUTRAN_Descrs cells := {})
936 := {
937 discr := '011'B,
938 value_list := {
939 eutran := cells
940 },
941 value_list_term := '0'B
942 };
943
944 template CellSelIndValue_EUTRAN_Descr tr_CellSelIndValue_EUTRAN_Descr(
945 template (present) uint16_t earfcn,
946 template (present) BIT1 meas_bw_presence := ?,
947 template uint3_t meas_bw := *)
948 := {
949 item_ind := '1'B,
950 earfcn := earfcn,
951 meas_bw_presence := meas_bw_presence,
952 meas_bw := meas_bw,
953 not_allowed_cells_presence := '0'B,
954 not_allowed_cells := omit,
955 target_pcid_presence := '0'B,
956 target_pcid := omit
957 };
958
959 external function enc_CellSelIndValue(in CellSelIndValue ro) return octetstring
960 with { extension "prototype(convert) encode(RAW)" };
961 external function dec_CellSelIndValue(in octetstring stream) return CellSelIndValue
962 with { extension "prototype(convert) decode(RAW)" };
963
Vadim Yanitskiye05d7162020-05-02 16:58:46 +0700964} with { encode "RAW" ; variant "FIELDORDER(msb)" }