Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 1 | /* 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 | |
| 6 | module GSM_SystemInformation { |
| 7 | |
| 8 | import from General_Types all; |
Harald Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 9 | import from GSM_Types all; |
Harald Welte | 615bd54 | 2017-07-14 18:28:55 +0200 | [diff] [blame] | 10 | import from Osmocom_Types all; |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 11 | |
| 12 | type record L2PseudoLength { |
| 13 | uint6_t l2_plen, |
| 14 | BIT2 zero_one |
| 15 | } with { variant "" }; |
| 16 | |
Harald Welte | 162b160 | 2017-07-16 03:05:02 +0200 | [diff] [blame^] | 17 | template L2PseudoLength t_L2Pseudolength(template uint6_t len) := { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 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 Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 36 | RrMessageType message_type |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 37 | } with { variant "" }; |
| 38 | |
Harald Welte | 162b160 | 2017-07-16 03:05:02 +0200 | [diff] [blame^] | 39 | template SystemInformationHeader t_SiHeader(RrMessageType msg_type, template uint6_t len) := { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 40 | l2_plen := t_L2Pseudolength(len), |
Harald Welte | 162b160 | 2017-07-16 03:05:02 +0200 | [diff] [blame^] | 41 | skip_indicator := 0, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 42 | rr_protocol_discriminator := 6, |
| 43 | message_type := msg_type |
| 44 | }; |
| 45 | |
| 46 | external function enc_SystemInformationHeader(in SystemInformationHeader si) return octetstring |
| 47 | with { extension "prototype(convert) encode(RAW)" }; |
| 48 | external function dec_SystemInformationHeader(in octetstring stream) return SystemInformationHeader |
| 49 | with { extension "prototype(convert) decode(RAW)" }; |
| 50 | |
| 51 | type hexstring GsmBcdString with { variant "HEXORDER(low)" }; |
| 52 | type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" }; |
| 53 | |
| 54 | /* 24.008 10.5.1.1 */ |
| 55 | type uint16_t CellIdentity; |
| 56 | |
| 57 | /* 24.008 10.5.1.3 */ |
| 58 | type record LocationAreaIdentification { |
| 59 | BcdMccMnc mcc_mnc, |
| 60 | uint16_t lac |
| 61 | } with { variant "" }; |
| 62 | |
| 63 | /* 44.018 10.5.2.1b */ |
| 64 | type octetstring CellChannelDescription with { variant "FIELDLENGTH(16)" }; |
| 65 | |
| 66 | /* 44.018 10.5.2.3 */ |
| 67 | type record CellOptions { |
| 68 | boolean dn_ind, |
| 69 | boolean pwrc, |
| 70 | BIT2 dtx, |
| 71 | BIT4 radio_link_timeout |
| 72 | } with { variant "" }; |
| 73 | |
| 74 | /* 44.018 10.5.2.3a */ |
| 75 | type record CellOptionsSacch { |
| 76 | BIT1 dtx_ext, |
| 77 | boolean pwrc, |
| 78 | BIT2 dtx, |
| 79 | BIT4 radio_link_timeout |
| 80 | } with { variant "" }; |
| 81 | |
| 82 | /* 44.018 10.5.2.4 */ |
| 83 | type record CellSelectionParameters { |
| 84 | uint3_t cell_resel_hyst, |
| 85 | uint5_t ms_txpwr_max_cch, |
| 86 | boolean acs, |
| 87 | boolean neci, |
| 88 | uint6_t rxlev_access_min |
| 89 | } with { variant "" }; |
| 90 | |
| 91 | /* 44.018 10.5.2.5 */ |
| 92 | type record ChannelDescription { |
| 93 | OCT1 iei, |
| 94 | BIT5 chan_type_tdma_offset, |
| 95 | uint3_t tn, |
| 96 | uint3_t tsc, |
| 97 | boolean h, |
| 98 | uint12_t arfcn optional, |
| 99 | MaioHsn maio_hsn optional |
| 100 | } with { variant (arfcn) "PRESENCE(h = true)" |
| 101 | variant (maio_hsn) "PRESENCE(h = false)" }; |
| 102 | |
| 103 | /* 44.018 10.5.2.11 */ |
| 104 | type record ControlChannelDescription { |
| 105 | boolean mscrr, |
| 106 | boolean att, |
| 107 | uint3_t bs_ag_blks_res, |
| 108 | uint3_t ccch_conf, |
| 109 | boolean si22ind, |
| 110 | uint2_t cbq3, |
| 111 | BIT2 spare, |
| 112 | uint3_t bs_pa_mfrms, |
| 113 | uint8_t t3212 |
| 114 | } with { variant "" }; |
| 115 | |
Harald Welte | 162b160 | 2017-07-16 03:05:02 +0200 | [diff] [blame^] | 116 | template ControlChannelDescription t_ControlChannelDescription := { ?, ?, ?, ?, ?, ?, '00'B, ?, ? }; |
| 117 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 118 | /* 44.018 10.5.2.21 */ |
| 119 | type record MobileAllocation { |
| 120 | OCT1 iei, |
| 121 | uint8_t len, |
| 122 | bitstring ma |
| 123 | } with { variant "" }; |
| 124 | |
| 125 | /* 44.018 10.5.2.22 */ |
| 126 | type octetstring NeighbourCellDescription with { variant "FIELDLENGTH(16)" }; |
| 127 | |
| 128 | /* 44.018 10.5.2.22a */ |
| 129 | type octetstring NeighbourCellDescription2 with { variant "FIELDLENGTH(16)" }; |
| 130 | |
| 131 | type bitstring AccessControlClass with { variant "FIELDLENGTH(16), BYTEORDER(last)" }; |
| 132 | |
| 133 | /* 44.018 10.5.2.29 */ |
| 134 | type record RachControlParameters { |
| 135 | BIT2 max_retrans, |
| 136 | BIT4 tx_integer, |
| 137 | boolean cell_barr_access, |
| 138 | boolean re, |
| 139 | AccessControlClass ac |
| 140 | } with { variant (ac) "FIELDLENGTH(16)" }; |
| 141 | |
| 142 | /* 44.018 10.5.2.32 */ |
| 143 | type RestOctets Si1RestOctets with { variant "FIELDLENGTH(1)" }; |
| 144 | type RestOctets Si3RestOctets with { variant "FIELDLENGTH(4)" }; |
| 145 | |
| 146 | /* 44.018 9.1.31 */ |
| 147 | type record SystemInformationType1 { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 148 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 149 | CellChannelDescription cell_chan_desc, |
| 150 | RachControlParameters rach_control, |
| 151 | Si1RestOctets rest_octets |
| 152 | } with { variant "" }; |
| 153 | |
| 154 | /* 44.018 9.1.32 */ |
| 155 | type record SystemInformationType2 { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 156 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 157 | NeighbourCellDescription bcch_freq_list, |
| 158 | BIT8 ncc_permitted, |
| 159 | RachControlParameters rach_control |
| 160 | } with { variant "" }; |
| 161 | |
| 162 | /* 44.018 9.1.33 */ |
| 163 | type record SystemInformationType2bis { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 164 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 165 | NeighbourCellDescription extd_bcch_freq_list, |
| 166 | RachControlParameters rach_control, |
| 167 | OCT1 rest_octets |
| 168 | } with { variant "" }; |
| 169 | |
| 170 | /* 44.018 9.1.34 */ |
| 171 | type record SystemInformationType2ter { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 172 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 173 | NeighbourCellDescription2 extd_bcch_freq_list, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 174 | OCT4 rest_octets |
| 175 | } with { variant "" }; |
| 176 | |
| 177 | /* 44.018 9.1.35 */ |
| 178 | type record SystemInformationType3 { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 179 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 180 | CellIdentity cell_id, |
| 181 | LocationAreaIdentification lai, |
| 182 | ControlChannelDescription ctrl_chan_desc, |
| 183 | CellOptions cell_options, |
| 184 | CellSelectionParameters cell_sel_par, |
| 185 | RachControlParameters rach_control, |
| 186 | Si3RestOctets rest_octets |
| 187 | } with { variant "" }; |
| 188 | |
Harald Welte | 162b160 | 2017-07-16 03:05:02 +0200 | [diff] [blame^] | 189 | template SystemInformationType3 t_SI3 := { |
| 190 | cell_id := ?, |
| 191 | lai := ?, |
| 192 | ctrl_chan_desc := t_ControlChannelDescription, |
| 193 | cell_options := ?, |
| 194 | cell_sel_par := ?, |
| 195 | rach_control := ?, |
| 196 | rest_octets := ? |
| 197 | }; |
| 198 | |
| 199 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 200 | /* 44.018 9.1.36 */ |
| 201 | type record SystemInformationType4 { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 202 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 203 | LocationAreaIdentification lai, |
| 204 | CellSelectionParameters cell_sel_par, |
| 205 | RachControlParameters rach_control, |
| 206 | ChannelDescription cbch_chan_desc optional, |
| 207 | MobileAllocation cbch_mobile_alloc optional, |
| 208 | RestOctets rest_octets |
| 209 | } with { variant "TAG(cbch_chan_desc, iei = '64'O; cbch_mobile_alloc, iei = '72'O)" }; |
| 210 | |
| 211 | /* 44.018 9.1.37 */ |
| 212 | type record SystemInformationType5 { |
| 213 | SystemInformationHeader header, |
| 214 | NeighbourCellDescription bcch_freq_list |
| 215 | } with { variant "" }; |
| 216 | |
| 217 | /* 44.018 9.1.38 */ |
| 218 | type record SystemInformationType5bis { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 219 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 220 | NeighbourCellDescription extd_bcch_freq_list |
| 221 | } with { variant "" }; |
| 222 | |
| 223 | /* 44.018 9.1.39 */ |
| 224 | type record SystemInformationType5ter { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 225 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 226 | NeighbourCellDescription2 extd_bcch_freq_list |
| 227 | } with { variant "" }; |
| 228 | |
| 229 | /* 44.018 9.1.40 */ |
| 230 | type record SystemInformationType6 { |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 231 | //SystemInformationHeader header, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 232 | CellIdentity cell_id, |
| 233 | LocationAreaIdentification lai, |
| 234 | CellOptionsSacch cell_options, |
| 235 | BIT8 ncc_permitted, |
| 236 | OCT7 rest_octets |
| 237 | } with { variant "" }; |
| 238 | |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 239 | type union SystemInformationUnion { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 240 | SystemInformationType1 si1, |
| 241 | SystemInformationType2 si2, |
| 242 | SystemInformationType2bis si2bis, |
| 243 | SystemInformationType2ter si2ter, |
| 244 | SystemInformationType3 si3, |
| 245 | SystemInformationType4 si4, |
| 246 | SystemInformationType5 si5, |
| 247 | SystemInformationType5bis si5bis, |
| 248 | SystemInformationType5ter si5ter, |
Harald Welte | 8c5b325 | 2017-07-15 23:59:49 +0200 | [diff] [blame] | 249 | SystemInformationType6 si6, |
| 250 | octetstring other |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 251 | } with { variant "" }; |
| 252 | |
| 253 | type record SystemInformation { |
| 254 | SystemInformationHeader header, |
| 255 | SystemInformationUnion payload |
| 256 | } with { variant (payload) "CROSSTAG(si1, header.message_type = SYSTEM_INFORMATION_TYPE_1; |
Harald Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 257 | si2, header.message_type = SYSTEM_INFORMATION_TYPE_2; |
| 258 | si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis; |
| 259 | si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter; |
| 260 | si3, header.message_type = SYSTEM_INFORMATION_TYPE_3; |
| 261 | si4, header.message_type = SYSTEM_INFORMATION_TYPE_4; |
| 262 | si5, header.message_type = SYSTEM_INFORMATION_TYPE_5; |
| 263 | si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis; |
| 264 | si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter; |
| 265 | si6, header.message_type = SYSTEM_INFORMATION_TYPE_6; |
Harald Welte | 8c5b325 | 2017-07-15 23:59:49 +0200 | [diff] [blame] | 266 | other, OTHERWISE; |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 267 | )" }; |
| 268 | |
| 269 | external function enc_SystemInformation(in SystemInformation si) return octetstring |
| 270 | with { extension "prototype(convert) encode(RAW)" }; |
| 271 | external function dec_SystemInformation(in octetstring stream) return SystemInformation |
| 272 | with { extension "prototype(convert) decode(RAW)" }; |
| 273 | |
| 274 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |