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 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 12 | type union ArfcnOrMaio { |
| 13 | uint12_t arfcn, |
| 14 | MaioHsn maio_hsn |
| 15 | } with { variant "" }; |
| 16 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 17 | /* 24.008 10.5.1.1 */ |
| 18 | type uint16_t CellIdentity; |
| 19 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 20 | /* 44.018 10.5.2.1b */ |
| 21 | type octetstring CellChannelDescription with { variant "FIELDLENGTH(16)" }; |
| 22 | |
| 23 | /* 44.018 10.5.2.3 */ |
| 24 | type record CellOptions { |
| 25 | boolean dn_ind, |
| 26 | boolean pwrc, |
| 27 | BIT2 dtx, |
| 28 | BIT4 radio_link_timeout |
| 29 | } with { variant "" }; |
| 30 | |
| 31 | /* 44.018 10.5.2.3a */ |
| 32 | type record CellOptionsSacch { |
| 33 | BIT1 dtx_ext, |
| 34 | boolean pwrc, |
| 35 | BIT2 dtx, |
| 36 | BIT4 radio_link_timeout |
| 37 | } with { variant "" }; |
| 38 | |
| 39 | /* 44.018 10.5.2.4 */ |
| 40 | type record CellSelectionParameters { |
| 41 | uint3_t cell_resel_hyst, |
| 42 | uint5_t ms_txpwr_max_cch, |
| 43 | boolean acs, |
| 44 | boolean neci, |
| 45 | uint6_t rxlev_access_min |
| 46 | } with { variant "" }; |
| 47 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 48 | /* 44.018 10.5.2.11 */ |
| 49 | type record ControlChannelDescription { |
| 50 | boolean mscrr, |
| 51 | boolean att, |
| 52 | uint3_t bs_ag_blks_res, |
| 53 | uint3_t ccch_conf, |
| 54 | boolean si22ind, |
| 55 | uint2_t cbq3, |
| 56 | BIT2 spare, |
| 57 | uint3_t bs_pa_mfrms, |
| 58 | uint8_t t3212 |
| 59 | } with { variant "" }; |
| 60 | |
Harald Welte | 162b160 | 2017-07-16 03:05:02 +0200 | [diff] [blame] | 61 | template ControlChannelDescription t_ControlChannelDescription := { ?, ?, ?, ?, ?, ?, '00'B, ?, ? }; |
| 62 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 63 | /* 44.018 10.5.2.21 */ |
Harald Welte | d2e342f | 2017-07-16 07:34:13 +0200 | [diff] [blame] | 64 | type record MobileAllocationT { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 65 | OCT1 iei, |
| 66 | uint8_t len, |
| 67 | bitstring ma |
| 68 | } with { variant "" }; |
| 69 | |
| 70 | /* 44.018 10.5.2.22 */ |
| 71 | type octetstring NeighbourCellDescription with { variant "FIELDLENGTH(16)" }; |
| 72 | |
| 73 | /* 44.018 10.5.2.22a */ |
| 74 | type octetstring NeighbourCellDescription2 with { variant "FIELDLENGTH(16)" }; |
| 75 | |
| 76 | type bitstring AccessControlClass with { variant "FIELDLENGTH(16), BYTEORDER(last)" }; |
| 77 | |
| 78 | /* 44.018 10.5.2.29 */ |
| 79 | type record RachControlParameters { |
| 80 | BIT2 max_retrans, |
| 81 | BIT4 tx_integer, |
| 82 | boolean cell_barr_access, |
| 83 | boolean re, |
| 84 | AccessControlClass ac |
| 85 | } with { variant (ac) "FIELDLENGTH(16)" }; |
| 86 | |
| 87 | /* 44.018 10.5.2.32 */ |
| 88 | type RestOctets Si1RestOctets with { variant "FIELDLENGTH(1)" }; |
| 89 | type RestOctets Si3RestOctets with { variant "FIELDLENGTH(4)" }; |
| 90 | |
| 91 | /* 44.018 9.1.31 */ |
| 92 | type record SystemInformationType1 { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 93 | CellChannelDescription cell_chan_desc, |
| 94 | RachControlParameters rach_control, |
| 95 | Si1RestOctets rest_octets |
| 96 | } with { variant "" }; |
| 97 | |
| 98 | /* 44.018 9.1.32 */ |
| 99 | type record SystemInformationType2 { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 100 | NeighbourCellDescription bcch_freq_list, |
| 101 | BIT8 ncc_permitted, |
| 102 | RachControlParameters rach_control |
| 103 | } with { variant "" }; |
| 104 | |
| 105 | /* 44.018 9.1.33 */ |
| 106 | type record SystemInformationType2bis { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 107 | NeighbourCellDescription extd_bcch_freq_list, |
| 108 | RachControlParameters rach_control, |
| 109 | OCT1 rest_octets |
| 110 | } with { variant "" }; |
| 111 | |
| 112 | /* 44.018 9.1.34 */ |
| 113 | type record SystemInformationType2ter { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 114 | NeighbourCellDescription2 extd_bcch_freq_list, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 115 | OCT4 rest_octets |
| 116 | } with { variant "" }; |
| 117 | |
| 118 | /* 44.018 9.1.35 */ |
| 119 | type record SystemInformationType3 { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 120 | CellIdentity cell_id, |
| 121 | LocationAreaIdentification lai, |
| 122 | ControlChannelDescription ctrl_chan_desc, |
| 123 | CellOptions cell_options, |
| 124 | CellSelectionParameters cell_sel_par, |
| 125 | RachControlParameters rach_control, |
| 126 | Si3RestOctets rest_octets |
| 127 | } with { variant "" }; |
| 128 | |
Harald Welte | 162b160 | 2017-07-16 03:05:02 +0200 | [diff] [blame] | 129 | template SystemInformationType3 t_SI3 := { |
| 130 | cell_id := ?, |
| 131 | lai := ?, |
| 132 | ctrl_chan_desc := t_ControlChannelDescription, |
| 133 | cell_options := ?, |
| 134 | cell_sel_par := ?, |
| 135 | rach_control := ?, |
| 136 | rest_octets := ? |
| 137 | }; |
| 138 | |
| 139 | |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 140 | /* 44.018 9.1.36 */ |
| 141 | type record SystemInformationType4 { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 142 | LocationAreaIdentification lai, |
| 143 | CellSelectionParameters cell_sel_par, |
| 144 | RachControlParameters rach_control, |
| 145 | ChannelDescription cbch_chan_desc optional, |
Harald Welte | d2e342f | 2017-07-16 07:34:13 +0200 | [diff] [blame] | 146 | MobileAllocationT cbch_mobile_alloc optional, |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 147 | RestOctets rest_octets |
| 148 | } with { variant "TAG(cbch_chan_desc, iei = '64'O; cbch_mobile_alloc, iei = '72'O)" }; |
| 149 | |
| 150 | /* 44.018 9.1.37 */ |
| 151 | type record SystemInformationType5 { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 152 | NeighbourCellDescription bcch_freq_list |
| 153 | } with { variant "" }; |
| 154 | |
| 155 | /* 44.018 9.1.38 */ |
| 156 | type record SystemInformationType5bis { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 157 | NeighbourCellDescription extd_bcch_freq_list |
| 158 | } with { variant "" }; |
| 159 | |
| 160 | /* 44.018 9.1.39 */ |
| 161 | type record SystemInformationType5ter { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 162 | NeighbourCellDescription2 extd_bcch_freq_list |
| 163 | } with { variant "" }; |
| 164 | |
| 165 | /* 44.018 9.1.40 */ |
| 166 | type record SystemInformationType6 { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 167 | CellIdentity cell_id, |
| 168 | LocationAreaIdentification lai, |
| 169 | CellOptionsSacch cell_options, |
| 170 | BIT8 ncc_permitted, |
| 171 | OCT7 rest_octets |
| 172 | } with { variant "" }; |
| 173 | |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 174 | type union SystemInformationUnion { |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 175 | SystemInformationType1 si1, |
| 176 | SystemInformationType2 si2, |
| 177 | SystemInformationType2bis si2bis, |
| 178 | SystemInformationType2ter si2ter, |
| 179 | SystemInformationType3 si3, |
| 180 | SystemInformationType4 si4, |
| 181 | SystemInformationType5 si5, |
| 182 | SystemInformationType5bis si5bis, |
| 183 | SystemInformationType5ter si5ter, |
Harald Welte | 8c5b325 | 2017-07-15 23:59:49 +0200 | [diff] [blame] | 184 | SystemInformationType6 si6, |
| 185 | octetstring other |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 186 | } with { variant "" }; |
| 187 | |
| 188 | type record SystemInformation { |
Harald Welte | d2e342f | 2017-07-16 07:34:13 +0200 | [diff] [blame] | 189 | RrHeader header, |
Harald Welte | a418918 | 2017-07-15 19:59:33 +0200 | [diff] [blame] | 190 | SystemInformationUnion payload |
| 191 | } with { variant (payload) "CROSSTAG(si1, header.message_type = SYSTEM_INFORMATION_TYPE_1; |
Harald Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 192 | si2, header.message_type = SYSTEM_INFORMATION_TYPE_2; |
| 193 | si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis; |
| 194 | si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter; |
| 195 | si3, header.message_type = SYSTEM_INFORMATION_TYPE_3; |
| 196 | si4, header.message_type = SYSTEM_INFORMATION_TYPE_4; |
| 197 | si5, header.message_type = SYSTEM_INFORMATION_TYPE_5; |
| 198 | si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis; |
| 199 | si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter; |
| 200 | si6, header.message_type = SYSTEM_INFORMATION_TYPE_6; |
Harald Welte | 8c5b325 | 2017-07-15 23:59:49 +0200 | [diff] [blame] | 201 | other, OTHERWISE; |
Harald Welte | 56db5fd | 2017-07-14 18:25:59 +0200 | [diff] [blame] | 202 | )" }; |
| 203 | |
| 204 | external function enc_SystemInformation(in SystemInformation si) return octetstring |
| 205 | with { extension "prototype(convert) encode(RAW)" }; |
| 206 | external function dec_SystemInformation(in octetstring stream) return SystemInformation |
| 207 | with { extension "prototype(convert) decode(RAW)" }; |
| 208 | |
| 209 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |