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 | 615bd54 | 2017-07-14 18:28:55 +0200 | [diff] [blame^] | 9 | import from Osmocom_Types all; |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 10 | |
| 11 | type record L2PseudoLength { |
| 12 | uint6_t l2_plen, |
| 13 | BIT2 zero_one |
| 14 | } with { variant "" }; |
| 15 | |
| 16 | template L2PseudoLength t_L2Pseudolength(uint6_t len) := { |
| 17 | l2_plen := len, |
| 18 | zero_one := '01'B |
| 19 | }; |
| 20 | |
| 21 | type octetstring RestOctets with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" }; |
| 22 | |
| 23 | type record MaioHsn { |
| 24 | } with { variant "" }; |
| 25 | |
| 26 | type union ArfcnOrMaio { |
| 27 | uint12_t arfcn, |
| 28 | MaioHsn maio_hsn |
| 29 | } with { variant "" }; |
| 30 | |
| 31 | type record SystemInformationHeader { |
| 32 | L2PseudoLength l2_plen, |
| 33 | uint4_t skip_indicator, |
| 34 | uint4_t rr_protocol_discriminator, |
| 35 | OCT1 message_type |
| 36 | } with { variant "" }; |
| 37 | |
| 38 | template SystemInformationHeader t_SiHeader(OCT1 msg_type, uint6_t len) := { |
| 39 | l2_plen := t_L2Pseudolength(len), |
| 40 | rr_protocol_discriminator := 6, |
| 41 | message_type := msg_type |
| 42 | }; |
| 43 | |
| 44 | external function enc_SystemInformationHeader(in SystemInformationHeader si) return octetstring |
| 45 | with { extension "prototype(convert) encode(RAW)" }; |
| 46 | external function dec_SystemInformationHeader(in octetstring stream) return SystemInformationHeader |
| 47 | with { extension "prototype(convert) decode(RAW)" }; |
| 48 | |
| 49 | type hexstring GsmBcdString with { variant "HEXORDER(low)" }; |
| 50 | type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" }; |
| 51 | |
| 52 | /* 24.008 10.5.1.1 */ |
| 53 | type uint16_t CellIdentity; |
| 54 | |
| 55 | /* 24.008 10.5.1.3 */ |
| 56 | type record LocationAreaIdentification { |
| 57 | BcdMccMnc mcc_mnc, |
| 58 | uint16_t lac |
| 59 | } with { variant "" }; |
| 60 | |
| 61 | /* 44.018 10.5.2.1b */ |
| 62 | type octetstring CellChannelDescription with { variant "FIELDLENGTH(16)" }; |
| 63 | |
| 64 | /* 44.018 10.5.2.3 */ |
| 65 | type record CellOptions { |
| 66 | boolean dn_ind, |
| 67 | boolean pwrc, |
| 68 | BIT2 dtx, |
| 69 | BIT4 radio_link_timeout |
| 70 | } with { variant "" }; |
| 71 | |
| 72 | /* 44.018 10.5.2.3a */ |
| 73 | type record CellOptionsSacch { |
| 74 | BIT1 dtx_ext, |
| 75 | boolean pwrc, |
| 76 | BIT2 dtx, |
| 77 | BIT4 radio_link_timeout |
| 78 | } with { variant "" }; |
| 79 | |
| 80 | /* 44.018 10.5.2.4 */ |
| 81 | type record CellSelectionParameters { |
| 82 | uint3_t cell_resel_hyst, |
| 83 | uint5_t ms_txpwr_max_cch, |
| 84 | boolean acs, |
| 85 | boolean neci, |
| 86 | uint6_t rxlev_access_min |
| 87 | } with { variant "" }; |
| 88 | |
| 89 | /* 44.018 10.5.2.5 */ |
| 90 | type record ChannelDescription { |
| 91 | OCT1 iei, |
| 92 | BIT5 chan_type_tdma_offset, |
| 93 | uint3_t tn, |
| 94 | uint3_t tsc, |
| 95 | boolean h, |
| 96 | uint12_t arfcn optional, |
| 97 | MaioHsn maio_hsn optional |
| 98 | } with { variant (arfcn) "PRESENCE(h = true)" |
| 99 | variant (maio_hsn) "PRESENCE(h = false)" }; |
| 100 | |
| 101 | /* 44.018 10.5.2.11 */ |
| 102 | type record ControlChannelDescription { |
| 103 | boolean mscrr, |
| 104 | boolean att, |
| 105 | uint3_t bs_ag_blks_res, |
| 106 | uint3_t ccch_conf, |
| 107 | boolean si22ind, |
| 108 | uint2_t cbq3, |
| 109 | BIT2 spare, |
| 110 | uint3_t bs_pa_mfrms, |
| 111 | uint8_t t3212 |
| 112 | } with { variant "" }; |
| 113 | |
| 114 | /* 44.018 10.5.2.21 */ |
| 115 | type record MobileAllocation { |
| 116 | OCT1 iei, |
| 117 | uint8_t len, |
| 118 | bitstring ma |
| 119 | } with { variant "" }; |
| 120 | |
| 121 | /* 44.018 10.5.2.22 */ |
| 122 | type octetstring NeighbourCellDescription with { variant "FIELDLENGTH(16)" }; |
| 123 | |
| 124 | /* 44.018 10.5.2.22a */ |
| 125 | type octetstring NeighbourCellDescription2 with { variant "FIELDLENGTH(16)" }; |
| 126 | |
| 127 | type bitstring AccessControlClass with { variant "FIELDLENGTH(16), BYTEORDER(last)" }; |
| 128 | |
| 129 | /* 44.018 10.5.2.29 */ |
| 130 | type record RachControlParameters { |
| 131 | BIT2 max_retrans, |
| 132 | BIT4 tx_integer, |
| 133 | boolean cell_barr_access, |
| 134 | boolean re, |
| 135 | AccessControlClass ac |
| 136 | } with { variant (ac) "FIELDLENGTH(16)" }; |
| 137 | |
| 138 | /* 44.018 10.5.2.32 */ |
| 139 | type RestOctets Si1RestOctets with { variant "FIELDLENGTH(1)" }; |
| 140 | type RestOctets Si3RestOctets with { variant "FIELDLENGTH(4)" }; |
| 141 | |
| 142 | /* 44.018 9.1.31 */ |
| 143 | type record SystemInformationType1 { |
| 144 | SystemInformationHeader header, |
| 145 | CellChannelDescription cell_chan_desc, |
| 146 | RachControlParameters rach_control, |
| 147 | Si1RestOctets rest_octets |
| 148 | } with { variant "" }; |
| 149 | |
| 150 | /* 44.018 9.1.32 */ |
| 151 | type record SystemInformationType2 { |
| 152 | SystemInformationHeader header, |
| 153 | NeighbourCellDescription bcch_freq_list, |
| 154 | BIT8 ncc_permitted, |
| 155 | RachControlParameters rach_control |
| 156 | } with { variant "" }; |
| 157 | |
| 158 | /* 44.018 9.1.33 */ |
| 159 | type record SystemInformationType2bis { |
| 160 | SystemInformationHeader header, |
| 161 | NeighbourCellDescription extd_bcch_freq_list, |
| 162 | RachControlParameters rach_control, |
| 163 | OCT1 rest_octets |
| 164 | } with { variant "" }; |
| 165 | |
| 166 | /* 44.018 9.1.34 */ |
| 167 | type record SystemInformationType2ter { |
| 168 | SystemInformationHeader header, |
| 169 | NeighbourCellDescription2 extd_bcch_freq_list, |
| 170 | RachControlParameters rach_control, |
| 171 | OCT4 rest_octets |
| 172 | } with { variant "" }; |
| 173 | |
| 174 | /* 44.018 9.1.35 */ |
| 175 | type record SystemInformationType3 { |
| 176 | SystemInformationHeader header, |
| 177 | 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 { |
| 188 | SystemInformationHeader header, |
| 189 | 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 { |
| 205 | SystemInformationHeader header, |
| 206 | NeighbourCellDescription extd_bcch_freq_list |
| 207 | } with { variant "" }; |
| 208 | |
| 209 | /* 44.018 9.1.39 */ |
| 210 | type record SystemInformationType5ter { |
| 211 | SystemInformationHeader header, |
| 212 | NeighbourCellDescription2 extd_bcch_freq_list |
| 213 | } with { variant "" }; |
| 214 | |
| 215 | /* 44.018 9.1.40 */ |
| 216 | type record SystemInformationType6 { |
| 217 | SystemInformationHeader header, |
| 218 | CellIdentity cell_id, |
| 219 | LocationAreaIdentification lai, |
| 220 | CellOptionsSacch cell_options, |
| 221 | BIT8 ncc_permitted, |
| 222 | OCT7 rest_octets |
| 223 | } with { variant "" }; |
| 224 | |
| 225 | |
| 226 | type union SystemInformation { |
| 227 | 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 |
| 237 | } with { variant "TAG(si1, header.message_type = '19'O; |
| 238 | si2, header.message_type = '1A'O; |
| 239 | si2bis, header.message_type = '02'O; |
| 240 | si2ter, header.message_type = '03'O; |
| 241 | si3, header.message_type = '1B'O; |
| 242 | si4, header.message_type = '1C'O; |
| 243 | si5, header.message_type = '1D'O; |
| 244 | si5bis, header.message_type = '05'O; |
| 245 | si5ter, header.message_type = '06'O; |
| 246 | si6, header.message_type = '1E'O; |
| 247 | )" }; |
| 248 | |
| 249 | external function enc_SystemInformation(in SystemInformation si) return octetstring |
| 250 | with { extension "prototype(convert) encode(RAW)" }; |
| 251 | external function dec_SystemInformation(in octetstring stream) return SystemInformation |
| 252 | with { extension "prototype(convert) decode(RAW)" }; |
| 253 | |
| 254 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |