blob: 51f687bfdffc25823302d3d518ccd3797d6f5fab [file] [log] [blame]
Harald Welte56db5fd2017-07-14 18:25:59 +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_SystemInformation {
7
8 import from General_Types all;
Harald Weltea082a692017-07-15 15:58:13 +02009 import from GSM_Types all;
Harald Welte615bd542017-07-14 18:28:55 +020010 import from Osmocom_Types all;
Harald Welte56db5fd2017-07-14 18:25:59 +020011
12 type record L2PseudoLength {
13 uint6_t l2_plen,
14 BIT2 zero_one
15 } with { variant "" };
16
17 template L2PseudoLength t_L2Pseudolength(uint6_t len) := {
18 l2_plen := len,
19 zero_one := '01'B
20 };
21
22 type octetstring RestOctets with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" };
23
24 type record MaioHsn {
25 } with { variant "" };
26
27 type union ArfcnOrMaio {
28 uint12_t arfcn,
29 MaioHsn maio_hsn
30 } with { variant "" };
31
32 type record SystemInformationHeader {
33 L2PseudoLength l2_plen,
34 uint4_t skip_indicator,
35 uint4_t rr_protocol_discriminator,
Harald Weltea082a692017-07-15 15:58:13 +020036 RrMessageType message_type
Harald Welte56db5fd2017-07-14 18:25:59 +020037 } with { variant "" };
38
Harald Weltea082a692017-07-15 15:58:13 +020039 template SystemInformationHeader t_SiHeader(RrMessageType msg_type, uint6_t len) := {
Harald Welte56db5fd2017-07-14 18:25:59 +020040 l2_plen := t_L2Pseudolength(len),
41 rr_protocol_discriminator := 6,
42 message_type := msg_type
43 };
44
45 external function enc_SystemInformationHeader(in SystemInformationHeader si) return octetstring
46 with { extension "prototype(convert) encode(RAW)" };
47 external function dec_SystemInformationHeader(in octetstring stream) return SystemInformationHeader
48 with { extension "prototype(convert) decode(RAW)" };
49
50 type hexstring GsmBcdString with { variant "HEXORDER(low)" };
51 type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" };
52
53 /* 24.008 10.5.1.1 */
54 type uint16_t CellIdentity;
55
56 /* 24.008 10.5.1.3 */
57 type record LocationAreaIdentification {
58 BcdMccMnc mcc_mnc,
59 uint16_t lac
60 } with { variant "" };
61
62 /* 44.018 10.5.2.1b */
63 type octetstring CellChannelDescription with { variant "FIELDLENGTH(16)" };
64
65 /* 44.018 10.5.2.3 */
66 type record CellOptions {
67 boolean dn_ind,
68 boolean pwrc,
69 BIT2 dtx,
70 BIT4 radio_link_timeout
71 } with { variant "" };
72
73 /* 44.018 10.5.2.3a */
74 type record CellOptionsSacch {
75 BIT1 dtx_ext,
76 boolean pwrc,
77 BIT2 dtx,
78 BIT4 radio_link_timeout
79 } with { variant "" };
80
81 /* 44.018 10.5.2.4 */
82 type record CellSelectionParameters {
83 uint3_t cell_resel_hyst,
84 uint5_t ms_txpwr_max_cch,
85 boolean acs,
86 boolean neci,
87 uint6_t rxlev_access_min
88 } with { variant "" };
89
90 /* 44.018 10.5.2.5 */
91 type record ChannelDescription {
92 OCT1 iei,
93 BIT5 chan_type_tdma_offset,
94 uint3_t tn,
95 uint3_t tsc,
96 boolean h,
97 uint12_t arfcn optional,
98 MaioHsn maio_hsn optional
99 } with { variant (arfcn) "PRESENCE(h = true)"
100 variant (maio_hsn) "PRESENCE(h = false)" };
101
102 /* 44.018 10.5.2.11 */
103 type record ControlChannelDescription {
104 boolean mscrr,
105 boolean att,
106 uint3_t bs_ag_blks_res,
107 uint3_t ccch_conf,
108 boolean si22ind,
109 uint2_t cbq3,
110 BIT2 spare,
111 uint3_t bs_pa_mfrms,
112 uint8_t t3212
113 } with { variant "" };
114
115 /* 44.018 10.5.2.21 */
116 type record MobileAllocation {
117 OCT1 iei,
118 uint8_t len,
119 bitstring ma
120 } with { variant "" };
121
122 /* 44.018 10.5.2.22 */
123 type octetstring NeighbourCellDescription with { variant "FIELDLENGTH(16)" };
124
125 /* 44.018 10.5.2.22a */
126 type octetstring NeighbourCellDescription2 with { variant "FIELDLENGTH(16)" };
127
128 type bitstring AccessControlClass with { variant "FIELDLENGTH(16), BYTEORDER(last)" };
129
130 /* 44.018 10.5.2.29 */
131 type record RachControlParameters {
132 BIT2 max_retrans,
133 BIT4 tx_integer,
134 boolean cell_barr_access,
135 boolean re,
136 AccessControlClass ac
137 } with { variant (ac) "FIELDLENGTH(16)" };
138
139 /* 44.018 10.5.2.32 */
140 type RestOctets Si1RestOctets with { variant "FIELDLENGTH(1)" };
141 type RestOctets Si3RestOctets with { variant "FIELDLENGTH(4)" };
142
143 /* 44.018 9.1.31 */
144 type record SystemInformationType1 {
Harald Weltea4189182017-07-15 19:59:33 +0200145 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200146 CellChannelDescription cell_chan_desc,
147 RachControlParameters rach_control,
148 Si1RestOctets rest_octets
149 } with { variant "" };
150
151 /* 44.018 9.1.32 */
152 type record SystemInformationType2 {
Harald Weltea4189182017-07-15 19:59:33 +0200153 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200154 NeighbourCellDescription bcch_freq_list,
155 BIT8 ncc_permitted,
156 RachControlParameters rach_control
157 } with { variant "" };
158
159 /* 44.018 9.1.33 */
160 type record SystemInformationType2bis {
Harald Weltea4189182017-07-15 19:59:33 +0200161 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200162 NeighbourCellDescription extd_bcch_freq_list,
163 RachControlParameters rach_control,
164 OCT1 rest_octets
165 } with { variant "" };
166
167 /* 44.018 9.1.34 */
168 type record SystemInformationType2ter {
Harald Weltea4189182017-07-15 19:59:33 +0200169 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200170 NeighbourCellDescription2 extd_bcch_freq_list,
171 RachControlParameters rach_control,
172 OCT4 rest_octets
173 } with { variant "" };
174
175 /* 44.018 9.1.35 */
176 type record SystemInformationType3 {
Harald Weltea4189182017-07-15 19:59:33 +0200177 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200178 CellIdentity cell_id,
179 LocationAreaIdentification lai,
180 ControlChannelDescription ctrl_chan_desc,
181 CellOptions cell_options,
182 CellSelectionParameters cell_sel_par,
183 RachControlParameters rach_control,
184 Si3RestOctets rest_octets
185 } with { variant "" };
186
187 /* 44.018 9.1.36 */
188 type record SystemInformationType4 {
Harald Weltea4189182017-07-15 19:59:33 +0200189 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200190 LocationAreaIdentification lai,
191 CellSelectionParameters cell_sel_par,
192 RachControlParameters rach_control,
193 ChannelDescription cbch_chan_desc optional,
194 MobileAllocation cbch_mobile_alloc optional,
195 RestOctets rest_octets
196 } with { variant "TAG(cbch_chan_desc, iei = '64'O; cbch_mobile_alloc, iei = '72'O)" };
197
198 /* 44.018 9.1.37 */
199 type record SystemInformationType5 {
200 SystemInformationHeader header,
201 NeighbourCellDescription bcch_freq_list
202 } with { variant "" };
203
204 /* 44.018 9.1.38 */
205 type record SystemInformationType5bis {
Harald Weltea4189182017-07-15 19:59:33 +0200206 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200207 NeighbourCellDescription extd_bcch_freq_list
208 } with { variant "" };
209
210 /* 44.018 9.1.39 */
211 type record SystemInformationType5ter {
Harald Weltea4189182017-07-15 19:59:33 +0200212 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200213 NeighbourCellDescription2 extd_bcch_freq_list
214 } with { variant "" };
215
216 /* 44.018 9.1.40 */
217 type record SystemInformationType6 {
Harald Weltea4189182017-07-15 19:59:33 +0200218 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200219 CellIdentity cell_id,
220 LocationAreaIdentification lai,
221 CellOptionsSacch cell_options,
222 BIT8 ncc_permitted,
223 OCT7 rest_octets
224 } with { variant "" };
225
Harald Weltea4189182017-07-15 19:59:33 +0200226 type union SystemInformationUnion {
Harald Welte56db5fd2017-07-14 18:25:59 +0200227 SystemInformationType1 si1,
228 SystemInformationType2 si2,
229 SystemInformationType2bis si2bis,
230 SystemInformationType2ter si2ter,
231 SystemInformationType3 si3,
232 SystemInformationType4 si4,
233 SystemInformationType5 si5,
234 SystemInformationType5bis si5bis,
235 SystemInformationType5ter si5ter,
236 SystemInformationType6 si6
Harald Weltea4189182017-07-15 19:59:33 +0200237 } with { variant "" };
238
239 type record SystemInformation {
240 SystemInformationHeader header,
241 SystemInformationUnion payload
242 } with { variant (payload) "CROSSTAG(si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
Harald Weltea082a692017-07-15 15:58:13 +0200243 si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
244 si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis;
245 si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter;
246 si3, header.message_type = SYSTEM_INFORMATION_TYPE_3;
247 si4, header.message_type = SYSTEM_INFORMATION_TYPE_4;
248 si5, header.message_type = SYSTEM_INFORMATION_TYPE_5;
249 si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis;
250 si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter;
251 si6, header.message_type = SYSTEM_INFORMATION_TYPE_6;
Harald Welte56db5fd2017-07-14 18:25:59 +0200252 )" };
253
254 external function enc_SystemInformation(in SystemInformation si) return octetstring
255 with { extension "prototype(convert) encode(RAW)" };
256 external function dec_SystemInformation(in octetstring stream) return SystemInformation
257 with { extension "prototype(convert) decode(RAW)" };
258
259} with { encode "RAW"; variant "FIELDORDER(msb)" }