blob: 0639eef4dc71257b7b47fa2827a82047a55fa58d [file] [log] [blame]
Harald Welte56db5fd2017-07-14 18:25:59 +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) 2018 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 Welte56db5fd2017-07-14 18:25:59 +020012
13module GSM_SystemInformation {
14
15 import from General_Types all;
Harald Weltea082a692017-07-15 15:58:13 +020016 import from GSM_Types all;
Harald Weltef9764922017-08-20 22:47:44 +020017 import from GSM_RR_Types all;
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +020018 import from GSM_RestOctets all;
Harald Welte615bd542017-07-14 18:28:55 +020019 import from Osmocom_Types all;
Harald Welte56db5fd2017-07-14 18:25:59 +020020
Harald Welte56db5fd2017-07-14 18:25:59 +020021 type union ArfcnOrMaio {
22 uint12_t arfcn,
23 MaioHsn maio_hsn
24 } with { variant "" };
25
Harald Welte56db5fd2017-07-14 18:25:59 +020026 /* 24.008 10.5.1.1 */
Harald Welte484160b2017-07-28 13:30:24 +020027 type uint16_t SysinfoCellIdentity;
Harald Welte56db5fd2017-07-14 18:25:59 +020028
Harald Welte56db5fd2017-07-14 18:25:59 +020029 /* 44.018 10.5.2.1b */
30 type octetstring CellChannelDescription with { variant "FIELDLENGTH(16)" };
31
32 /* 44.018 10.5.2.3 */
Harald Welte82ccef72018-02-25 16:17:33 +010033 type enumerated CellOptions_DTX {
34 MS_MAY_USE_UL_DTX ('00'B),
35 MS_SHALL_USE_UL_DTX ('01'B),
36 MS_SHALL_NOT_USE_UL_DTX ('10'B)
37 } with { variant "FIELDLENGTH(2)" };
Harald Welte56db5fd2017-07-14 18:25:59 +020038 type record CellOptions {
39 boolean dn_ind,
40 boolean pwrc,
Harald Welte82ccef72018-02-25 16:17:33 +010041 CellOptions_DTX dtx,
42 uint4_t radio_link_tout_div4
Harald Welte56db5fd2017-07-14 18:25:59 +020043 } with { variant "" };
44
45 /* 44.018 10.5.2.3a */
46 type record CellOptionsSacch {
47 BIT1 dtx_ext,
48 boolean pwrc,
49 BIT2 dtx,
50 BIT4 radio_link_timeout
51 } with { variant "" };
52
53 /* 44.018 10.5.2.4 */
54 type record CellSelectionParameters {
Harald Welte82ccef72018-02-25 16:17:33 +010055 uint3_t cell_resel_hyst_2dB,
Harald Welte56db5fd2017-07-14 18:25:59 +020056 uint5_t ms_txpwr_max_cch,
Harald Welte82ccef72018-02-25 16:17:33 +010057 BIT1 acs,
Harald Welte56db5fd2017-07-14 18:25:59 +020058 boolean neci,
59 uint6_t rxlev_access_min
60 } with { variant "" };
61
Harald Welte56db5fd2017-07-14 18:25:59 +020062 /* 44.018 10.5.2.11 */
Harald Welte82ccef72018-02-25 16:17:33 +010063 type enumerated CtrlChanDesc_CC {
64 CCHAN_DESC_1CCCH_NOT_COMBINED ('000'B),
65 CCHAN_DESC_1CCCH_COMBINED ('001'B),
66 CCHAN_DESC_2CCCH_NOT_COMBINED ('010'B),
67 CCHAN_DESC_3CCCH_NOT_COMBINED ('100'B),
68 CCHAN_DESC_4CCCH_NOT_COMBINED ('110'B)
69 } with { variant "FIELDLENGTH(3)" };
70 type enumerated CBQ3 {
71 CBQ3_IU_MODE_NOT_SUPPORTED ('00'B),
72 CBQ3_IU_MODE_MS_BARRED ('01'B),
73 CBQ3_IU_MODE_NOT_BARRED ('10'B)
74 } with { variant "FIELDLENGTH(2)" };
Harald Welte56db5fd2017-07-14 18:25:59 +020075 type record ControlChannelDescription {
Harald Welte82ccef72018-02-25 16:17:33 +010076 boolean msc_r99,
Harald Welte56db5fd2017-07-14 18:25:59 +020077 boolean att,
78 uint3_t bs_ag_blks_res,
Harald Welte82ccef72018-02-25 16:17:33 +010079 CtrlChanDesc_CC ccch_conf,
Harald Welte56db5fd2017-07-14 18:25:59 +020080 boolean si22ind,
Harald Welte82ccef72018-02-25 16:17:33 +010081 CBQ3 cbq3,
Harald Welte56db5fd2017-07-14 18:25:59 +020082 BIT2 spare,
Harald Welte82ccef72018-02-25 16:17:33 +010083 uint3_t bs_pa_mfrms, /* off by 2 */
Harald Welte56db5fd2017-07-14 18:25:59 +020084 uint8_t t3212
85 } with { variant "" };
86
Harald Welte162b1602017-07-16 03:05:02 +020087 template ControlChannelDescription t_ControlChannelDescription := { ?, ?, ?, ?, ?, ?, '00'B, ?, ? };
88
Harald Welte56db5fd2017-07-14 18:25:59 +020089 /* 44.018 10.5.2.21 */
Harald Welted2e342f2017-07-16 07:34:13 +020090 type record MobileAllocationT {
Harald Welte56db5fd2017-07-14 18:25:59 +020091 OCT1 iei,
92 uint8_t len,
93 bitstring ma
94 } with { variant "" };
95
96 /* 44.018 10.5.2.22 */
97 type octetstring NeighbourCellDescription with { variant "FIELDLENGTH(16)" };
98
99 /* 44.018 10.5.2.22a */
100 type octetstring NeighbourCellDescription2 with { variant "FIELDLENGTH(16)" };
101
102 type bitstring AccessControlClass with { variant "FIELDLENGTH(16), BYTEORDER(last)" };
103
104 /* 44.018 10.5.2.29 */
Harald Welte82ccef72018-02-25 16:17:33 +0100105 type enumerated RachCtrlPar_MR {
106 RACH_MAX_RETRANS_1 ('00'B),
107 RACH_MAX_RETRANS_2 ('01'B),
108 RACH_MAX_RETRANS_4 ('10'B),
109 RACH_MAX_RETRANS_7 ('11'B)
110 } with { variant "FIELDLENGTH(2)" };
Harald Welte56db5fd2017-07-14 18:25:59 +0200111 type record RachControlParameters {
Harald Welte82ccef72018-02-25 16:17:33 +0100112 RachCtrlPar_MR max_retrans,
Harald Welte56db5fd2017-07-14 18:25:59 +0200113 BIT4 tx_integer,
114 boolean cell_barr_access,
Harald Welte82ccef72018-02-25 16:17:33 +0100115 boolean re_not_allowed,
116 AccessControlClass acc
117 } with { variant (acc) "FIELDLENGTH(16)" };
Harald Welte56db5fd2017-07-14 18:25:59 +0200118
Harald Welte56db5fd2017-07-14 18:25:59 +0200119 /* 44.018 9.1.31 */
120 type record SystemInformationType1 {
Harald Welte56db5fd2017-07-14 18:25:59 +0200121 CellChannelDescription cell_chan_desc,
122 RachControlParameters rach_control,
Vadim Yanitskiyb7bc2e62020-05-04 21:22:41 +0700123 RestOctets rest_octets length(0..1)
124 } with { variant "" };
Harald Welte56db5fd2017-07-14 18:25:59 +0200125
126 /* 44.018 9.1.32 */
127 type record SystemInformationType2 {
Harald Welte56db5fd2017-07-14 18:25:59 +0200128 NeighbourCellDescription bcch_freq_list,
129 BIT8 ncc_permitted,
130 RachControlParameters rach_control
131 } with { variant "" };
132
133 /* 44.018 9.1.33 */
134 type record SystemInformationType2bis {
Harald Welte56db5fd2017-07-14 18:25:59 +0200135 NeighbourCellDescription extd_bcch_freq_list,
136 RachControlParameters rach_control,
Vadim Yanitskiyb7bc2e62020-05-04 21:22:41 +0700137 RestOctets rest_octets length(0..1)
138 } with { variant "" };
Harald Welte56db5fd2017-07-14 18:25:59 +0200139
140 /* 44.018 9.1.34 */
141 type record SystemInformationType2ter {
Harald Welte56db5fd2017-07-14 18:25:59 +0200142 NeighbourCellDescription2 extd_bcch_freq_list,
Vadim Yanitskiyb7bc2e62020-05-04 21:22:41 +0700143 RestOctets rest_octets length(0..4)
144 } with { variant "" };
Harald Welte56db5fd2017-07-14 18:25:59 +0200145
146 /* 44.018 9.1.35 */
147 type record SystemInformationType3 {
Harald Welte484160b2017-07-28 13:30:24 +0200148 SysinfoCellIdentity cell_id,
Harald Welte56db5fd2017-07-14 18:25:59 +0200149 LocationAreaIdentification lai,
150 ControlChannelDescription ctrl_chan_desc,
151 CellOptions cell_options,
152 CellSelectionParameters cell_sel_par,
153 RachControlParameters rach_control,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200154 SI3RestOctets rest_octets
Vadim Yanitskiyb7bc2e62020-05-04 21:22:41 +0700155 } with { variant "" };
Harald Welte56db5fd2017-07-14 18:25:59 +0200156
Harald Welte162b1602017-07-16 03:05:02 +0200157 template SystemInformationType3 t_SI3 := {
158 cell_id := ?,
159 lai := ?,
160 ctrl_chan_desc := t_ControlChannelDescription,
161 cell_options := ?,
162 cell_sel_par := ?,
163 rach_control := ?,
164 rest_octets := ?
165 };
166
167
Harald Welte56db5fd2017-07-14 18:25:59 +0200168 /* 44.018 9.1.36 */
169 type record SystemInformationType4 {
Harald Welte56db5fd2017-07-14 18:25:59 +0200170 LocationAreaIdentification lai,
171 CellSelectionParameters cell_sel_par,
172 RachControlParameters rach_control,
Harald Weltead091b62017-07-16 21:03:17 +0200173 ChannelDescriptionTV cbch_chan_desc optional,
Harald Welted2e342f2017-07-16 07:34:13 +0200174 MobileAllocationT cbch_mobile_alloc optional,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200175 SI4RestOctets rest_octets /* see 10.5.2.35 */
Harald Welte56db5fd2017-07-14 18:25:59 +0200176 } with { variant "TAG(cbch_chan_desc, iei = '64'O; cbch_mobile_alloc, iei = '72'O)" };
177
178 /* 44.018 9.1.37 */
179 type record SystemInformationType5 {
Harald Welte56db5fd2017-07-14 18:25:59 +0200180 NeighbourCellDescription bcch_freq_list
181 } with { variant "" };
182
183 /* 44.018 9.1.38 */
184 type record SystemInformationType5bis {
Harald Welte56db5fd2017-07-14 18:25:59 +0200185 NeighbourCellDescription extd_bcch_freq_list
186 } with { variant "" };
187
188 /* 44.018 9.1.39 */
189 type record SystemInformationType5ter {
Harald Welte56db5fd2017-07-14 18:25:59 +0200190 NeighbourCellDescription2 extd_bcch_freq_list
191 } with { variant "" };
192
193 /* 44.018 9.1.40 */
194 type record SystemInformationType6 {
Harald Welte484160b2017-07-28 13:30:24 +0200195 SysinfoCellIdentity cell_id,
Harald Welte56db5fd2017-07-14 18:25:59 +0200196 LocationAreaIdentification lai,
197 CellOptionsSacch cell_options,
198 BIT8 ncc_permitted,
Vadim Yanitskiyb7bc2e62020-05-04 21:22:41 +0700199 RestOctets rest_octets length(0..7)
200 } with { variant "" };
Harald Welte56db5fd2017-07-14 18:25:59 +0200201
Harald Weltea4189182017-07-15 19:59:33 +0200202 type union SystemInformationUnion {
Harald Welte56db5fd2017-07-14 18:25:59 +0200203 SystemInformationType1 si1,
204 SystemInformationType2 si2,
205 SystemInformationType2bis si2bis,
206 SystemInformationType2ter si2ter,
207 SystemInformationType3 si3,
208 SystemInformationType4 si4,
209 SystemInformationType5 si5,
210 SystemInformationType5bis si5bis,
211 SystemInformationType5ter si5ter,
Harald Welte8c5b3252017-07-15 23:59:49 +0200212 SystemInformationType6 si6,
213 octetstring other
Harald Weltea4189182017-07-15 19:59:33 +0200214 } with { variant "" };
215
216 type record SystemInformation {
Harald Welted2e342f2017-07-16 07:34:13 +0200217 RrHeader header,
Harald Weltea4189182017-07-15 19:59:33 +0200218 SystemInformationUnion payload
219 } with { variant (payload) "CROSSTAG(si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
Harald Weltea082a692017-07-15 15:58:13 +0200220 si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
221 si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis;
222 si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter;
223 si3, header.message_type = SYSTEM_INFORMATION_TYPE_3;
224 si4, header.message_type = SYSTEM_INFORMATION_TYPE_4;
225 si5, header.message_type = SYSTEM_INFORMATION_TYPE_5;
226 si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis;
227 si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter;
228 si6, header.message_type = SYSTEM_INFORMATION_TYPE_6;
Harald Welte8c5b3252017-07-15 23:59:49 +0200229 other, OTHERWISE;
Harald Welte56db5fd2017-07-14 18:25:59 +0200230 )" };
231
Vadim Yanitskiy0217b052020-05-04 23:59:01 +0700232 external function enc_SystemInformationNoPad(in SystemInformation si) return octetstring
Harald Welte56db5fd2017-07-14 18:25:59 +0200233 with { extension "prototype(convert) encode(RAW)" };
234 external function dec_SystemInformation(in octetstring stream) return SystemInformation
235 with { extension "prototype(convert) decode(RAW)" };
236
Vadim Yanitskiy0217b052020-05-04 23:59:01 +0700237 /* Due to a buggy nature of TITAN's padding attributes, we have to apply padding manually. */
238 function enc_SystemInformation(in SystemInformation si) return octetstring
239 {
240 var octetstring si_enc := enc_SystemInformationNoPad(si);
241
242 /* Resulting message length depends on SI Type */
243 select (si.header.message_type) {
244 case (SYSTEM_INFORMATION_TYPE_5,
245 SYSTEM_INFORMATION_TYPE_5bis,
246 SYSTEM_INFORMATION_TYPE_5ter) {
247 /* SACCH: no Rest Octets, return 'as-is' */
248 return si_enc;
249 }
250 case (SYSTEM_INFORMATION_TYPE_6) {
251 /* SACCH: pad to 19 octets, leave room for L1/LAPDm headers */
252 return f_pad_oct(si_enc, 19, '2B'O);
253 }
254 case else {
255 /* BCCH: pad to 23 octets */
256 return f_pad_oct(si_enc, 23, '2B'O);
257 }
258 }
259 }
260
Harald Welte56db5fd2017-07-14 18:25:59 +0200261} with { encode "RAW"; variant "FIELDORDER(msb)" }