blob: 86cba2a77995b82d2098c3ce1fb4a3aeaa6aaf4e [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,
Harald Welte56db5fd2017-07-14 18:25:59 +0200171 OCT4 rest_octets
172 } with { variant "" };
173
174 /* 44.018 9.1.35 */
175 type record SystemInformationType3 {
Harald Weltea4189182017-07-15 19:59:33 +0200176 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200177 CellIdentity cell_id,
178 LocationAreaIdentification lai,
179 ControlChannelDescription ctrl_chan_desc,
180 CellOptions cell_options,
181 CellSelectionParameters cell_sel_par,
182 RachControlParameters rach_control,
183 Si3RestOctets rest_octets
184 } with { variant "" };
185
186 /* 44.018 9.1.36 */
187 type record SystemInformationType4 {
Harald Weltea4189182017-07-15 19:59:33 +0200188 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200189 LocationAreaIdentification lai,
190 CellSelectionParameters cell_sel_par,
191 RachControlParameters rach_control,
192 ChannelDescription cbch_chan_desc optional,
193 MobileAllocation cbch_mobile_alloc optional,
194 RestOctets rest_octets
195 } with { variant "TAG(cbch_chan_desc, iei = '64'O; cbch_mobile_alloc, iei = '72'O)" };
196
197 /* 44.018 9.1.37 */
198 type record SystemInformationType5 {
199 SystemInformationHeader header,
200 NeighbourCellDescription bcch_freq_list
201 } with { variant "" };
202
203 /* 44.018 9.1.38 */
204 type record SystemInformationType5bis {
Harald Weltea4189182017-07-15 19:59:33 +0200205 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200206 NeighbourCellDescription extd_bcch_freq_list
207 } with { variant "" };
208
209 /* 44.018 9.1.39 */
210 type record SystemInformationType5ter {
Harald Weltea4189182017-07-15 19:59:33 +0200211 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200212 NeighbourCellDescription2 extd_bcch_freq_list
213 } with { variant "" };
214
215 /* 44.018 9.1.40 */
216 type record SystemInformationType6 {
Harald Weltea4189182017-07-15 19:59:33 +0200217 //SystemInformationHeader header,
Harald Welte56db5fd2017-07-14 18:25:59 +0200218 CellIdentity cell_id,
219 LocationAreaIdentification lai,
220 CellOptionsSacch cell_options,
221 BIT8 ncc_permitted,
222 OCT7 rest_octets
223 } with { variant "" };
224
Harald Weltea4189182017-07-15 19:59:33 +0200225 type union SystemInformationUnion {
Harald Welte56db5fd2017-07-14 18:25:59 +0200226 SystemInformationType1 si1,
227 SystemInformationType2 si2,
228 SystemInformationType2bis si2bis,
229 SystemInformationType2ter si2ter,
230 SystemInformationType3 si3,
231 SystemInformationType4 si4,
232 SystemInformationType5 si5,
233 SystemInformationType5bis si5bis,
234 SystemInformationType5ter si5ter,
Harald Welte8c5b3252017-07-15 23:59:49 +0200235 SystemInformationType6 si6,
236 octetstring other
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 Welte8c5b3252017-07-15 23:59:49 +0200252 other, OTHERWISE;
Harald Welte56db5fd2017-07-14 18:25:59 +0200253 )" };
254
255 external function enc_SystemInformation(in SystemInformation si) return octetstring
256 with { extension "prototype(convert) encode(RAW)" };
257 external function dec_SystemInformation(in octetstring stream) return SystemInformation
258 with { extension "prototype(convert) decode(RAW)" };
259
260} with { encode "RAW"; variant "FIELDORDER(msb)" }