Harald Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 1 | /* Encoding/Decoding routines for GSM System Information messages |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 2 | * according to 3GPP TS 44.018 Version 12.3.0 Release 12 |
| 3 | * |
| 4 | * (C) 2017-2018 Harald Welte <laforge@gnumonks.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 11 | */ |
Harald Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 12 | |
| 13 | module GSM_Types { |
| 14 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
Harald Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 17 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 18 | type integer GsmArfcn (0..1023); |
| 19 | type integer UmtsArfcn (0..16383); |
| 20 | type integer UmtsScramblingCode (0..511); |
| 21 | const integer GsmMaxFrameNumber := 26*51*2048; |
| 22 | type integer GsmFrameNumber (0..GsmMaxFrameNumber); |
| 23 | type integer GsmRxLev (0..63); |
| 24 | type integer GsmTsc (0..7) with { variant "FIELDLENGTH(8)" }; |
| 25 | type uint32_t GsmTmsi; |
| 26 | type OCT4 GprsTlli; |
| 27 | type hexstring GsmMcc length(3); |
| 28 | type hexstring GsmMnc length(2 .. 3); |
| 29 | type uint16_t GsmLac; |
| 30 | type uint16_t GsmCellId; |
Harald Welte | bdc5dbd | 2017-07-16 00:00:43 +0200 | [diff] [blame] | 31 | |
Vadim Yanitskiy | 1acc7bb | 2020-11-14 04:24:57 +0700 | [diff] [blame] | 32 | /* ARFCN with explicit band discrimination */ |
| 33 | type record GsmBandArfcn { |
| 34 | boolean pcs, |
Vadim Yanitskiy | 05a236a | 2020-11-14 04:58:30 +0700 | [diff] [blame] | 35 | boolean uplink, |
| 36 | BIT4 spare, |
Vadim Yanitskiy | 1acc7bb | 2020-11-14 04:24:57 +0700 | [diff] [blame] | 37 | GsmArfcn arfcn |
| 38 | } with { |
| 39 | variant (arfcn) "BYTEORDER(last)" |
| 40 | variant (arfcn) "FIELDLENGTH(10)" |
| 41 | }; |
| 42 | |
| 43 | template (value) GsmBandArfcn |
| 44 | ts_GsmBandArfcn(template (value) GsmArfcn arfcn, |
Vadim Yanitskiy | 05a236a | 2020-11-14 04:58:30 +0700 | [diff] [blame] | 45 | template (value) boolean pcs := false, |
| 46 | template (value) boolean uplink := false) := { |
Vadim Yanitskiy | 1acc7bb | 2020-11-14 04:24:57 +0700 | [diff] [blame] | 47 | pcs := pcs, |
Vadim Yanitskiy | 05a236a | 2020-11-14 04:58:30 +0700 | [diff] [blame] | 48 | uplink := uplink, |
| 49 | spare := '0000'B, |
Vadim Yanitskiy | 1acc7bb | 2020-11-14 04:24:57 +0700 | [diff] [blame] | 50 | arfcn := arfcn |
| 51 | }; |
| 52 | template GsmBandArfcn |
| 53 | tr_GsmBandArfcn(template (present) GsmArfcn arfcn, |
Vadim Yanitskiy | 05a236a | 2020-11-14 04:58:30 +0700 | [diff] [blame] | 54 | template (present) boolean pcs := ?, |
| 55 | template (present) boolean uplink := ?) := { |
Vadim Yanitskiy | 1acc7bb | 2020-11-14 04:24:57 +0700 | [diff] [blame] | 56 | pcs := pcs, |
Vadim Yanitskiy | 05a236a | 2020-11-14 04:58:30 +0700 | [diff] [blame] | 57 | uplink := uplink, |
Vadim Yanitskiy | 1acc7bb | 2020-11-14 04:24:57 +0700 | [diff] [blame] | 58 | spare := ?, |
| 59 | arfcn := arfcn |
| 60 | }; |
| 61 | |
Vadim Yanitskiy | 42d8bd5 | 2020-11-15 20:41:02 +0700 | [diff] [blame] | 62 | /* see enum 'gsm_phys_chan_config' in libosmocore */ |
| 63 | type enumerated PchanConfig { |
| 64 | GSM_PCHAN_NONE, |
| 65 | GSM_PCHAN_CCCH, |
| 66 | GSM_PCHAN_CCCH_SDCCH4, |
| 67 | GSM_PCHAN_CCCH_SDCCH4_CBCH, |
| 68 | GSM_PCHAN_SDCCH8, |
| 69 | GSM_PCHAN_SDCCH8_CBCH, |
| 70 | GSM_PCHAN_TCHF, |
| 71 | GSM_PCHAN_TCHH, |
| 72 | GSM_PCHAN_PDCH, |
| 73 | /* IPA style dynamic TCH/F+PDCH */ |
| 74 | GSM_PCHAN_TCHF_PDCH, |
| 75 | /* Osmocom style dynamic TCH/H+TCH/F+PDCH */ |
| 76 | GSM_PCHAN_TCHH_TCHF_PDCH |
| 77 | }; |
| 78 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 79 | type enumerated GprsCodingScheme { |
| 80 | CS1, CS2, CS3, CS4 |
| 81 | }; |
Harald Welte | 1dcc371 | 2017-08-01 00:05:52 +0200 | [diff] [blame] | 82 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 83 | function f_gprs_blocksize(GprsCodingScheme cs) return integer { |
| 84 | select (cs) { |
| 85 | case (CS1) { return 22 } |
| 86 | case (CS2) { return 32 } |
| 87 | case (CS3) { return 38 } |
| 88 | case (CS3) { return 52 } |
| 89 | case else { |
| 90 | setverdict(fail, "Invalid GPRS CS ", cs); |
| 91 | mtc.stop; |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 92 | } |
| 93 | } |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 94 | } |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 95 | |
Pau Espin Pedrol | bfd69f6 | 2020-10-22 18:06:07 +0200 | [diff] [blame] | 96 | const GprsTlli TLLI_UNUSED := 'FFFFFFFF'O; |
| 97 | function f_gen_tlli() return GprsTlli { |
| 98 | var GprsTlli tlli := f_rnd_octstring(4); |
| 99 | if (tlli == TLLI_UNUSED) { |
| 100 | tlli := 'EEEEEEEE'O; |
| 101 | } |
| 102 | return tlli; |
| 103 | } |
| 104 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 105 | /* 10.5.2.8 */ |
| 106 | type enumerated ChannelNeeded { |
| 107 | CHAN_NEED_ANY (0), |
| 108 | CHAN_NEED_SDCCH (1), |
| 109 | CHAN_NEED_TCH_F (2), |
| 110 | CHAN_NEED_TCH_H (3) |
| 111 | } with { variant "FIELDLENGTH(2)" }; |
| 112 | type record ChannelNeeded12 { |
| 113 | ChannelNeeded second, |
| 114 | ChannelNeeded first |
| 115 | } with { variant "" }; |
Harald Welte | d2e342f | 2017-07-16 07:34:13 +0200 | [diff] [blame] | 116 | |
Harald Welte | d2e342f | 2017-07-16 07:34:13 +0200 | [diff] [blame] | 117 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 118 | /* TS 48.058 9.3.1 Channel Number IE */ |
| 119 | type enumerated RslChanNr0 { |
| 120 | RSL_CHAN_NR_INVALID ('00000'B), |
| 121 | RSL_CHAN_NR_Bm_ACCH ('00001'B), |
| 122 | RSL_CHAN_NR_BCCH ('10000'B), |
| 123 | RSL_CHAN_NR_RACH ('10001'B), |
| 124 | RSL_CHAN_NR_PCH_AGCH ('10010'B), |
| 125 | RSL_CHAN_NR_OSMO_PDCH ('11000'B), |
| 126 | RSL_CHAN_NR_OSMO_CBCH4 ('11001'B), |
| 127 | RSL_CHAN_NR_OSMO_CBCH8 ('11010'B) |
| 128 | } with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" }; |
Harald Welte | 0c8d5c0 | 2017-07-16 18:53:58 +0200 | [diff] [blame] | 129 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 130 | type record RslChanNr2 { |
| 131 | BIT4 tag ('0001'B), |
| 132 | uint1_t sub_chan |
| 133 | } with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" }; |
Harald Welte | 0c8d5c0 | 2017-07-16 18:53:58 +0200 | [diff] [blame] | 134 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 135 | type record RslChanNr4 { |
| 136 | BIT3 tag ('001'B), |
| 137 | uint2_t sub_chan |
| 138 | } with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" }; |
Harald Welte | 0c8d5c0 | 2017-07-16 18:53:58 +0200 | [diff] [blame] | 139 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 140 | type record RslChanNr8 { |
| 141 | BIT2 tag ('01'B), |
| 142 | uint3_t sub_chan |
| 143 | } with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" }; |
Harald Welte | 0c8d5c0 | 2017-07-16 18:53:58 +0200 | [diff] [blame] | 144 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 145 | type union RslChanNrU { |
| 146 | RslChanNr0 ch0, |
| 147 | RslChanNr2 lm, |
| 148 | RslChanNr4 sdcch4, |
| 149 | RslChanNr8 sdcch8 |
| 150 | } with { |
| 151 | variant "TAG(lm, tag = '0001'B; |
| 152 | sdcch4, tag = '001'B; |
| 153 | sdcch8, tag = '01'B; |
| 154 | ch0, OTHERWISE)" |
| 155 | variant "FIELDLENGTH(5)" |
| 156 | variant "FIELDORDER(msb)" |
| 157 | }; |
Harald Welte | 0c8d5c0 | 2017-07-16 18:53:58 +0200 | [diff] [blame] | 158 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 159 | type record RslChannelNr { |
| 160 | RslChanNrU u, |
| 161 | uint3_t tn |
| 162 | } with { variant "FIELDLENGTH(8)" variant "FIELDORDER(msb)" }; |
Harald Welte | 0c8d5c0 | 2017-07-16 18:53:58 +0200 | [diff] [blame] | 163 | |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 164 | template RslChannelNr t_RslChanNr0(template uint3_t tn, template RslChanNr0 cht) := { |
| 165 | u := { ch0 := cht }, |
| 166 | tn := tn |
| 167 | } |
| 168 | |
| 169 | template RslChannelNr t_RslChanNr_RACH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_RACH); |
| 170 | template RslChannelNr t_RslChanNr_BCCH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_BCCH); |
| 171 | template RslChannelNr t_RslChanNr_PCH_AGCH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_PCH_AGCH); |
| 172 | template RslChannelNr t_RslChanNr_Bm(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_Bm_ACCH); |
| 173 | template RslChannelNr t_RslChanNr_PDCH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_OSMO_PDCH); |
| 174 | template RslChannelNr t_RslChanNr_CBCH4(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH4); |
| 175 | template RslChannelNr t_RslChanNr_CBCH8(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH8); |
| 176 | template RslChannelNr t_RslChanNr_Lm(template uint3_t tn, template uint1_t sub_slot) := { |
| 177 | u := { lm := { tag := '0001'B, sub_chan := sub_slot } }, |
| 178 | tn := tn |
| 179 | } |
| 180 | template RslChannelNr t_RslChanNr_SDCCH4(template uint3_t tn, template uint2_t sub_slot) := { |
| 181 | u := { sdcch4 := { tag := '001'B, sub_chan := sub_slot } }, |
| 182 | tn := tn |
| 183 | } |
| 184 | template RslChannelNr t_RslChanNr_SDCCH8(template uint3_t tn, template uint3_t sub_slot) := { |
| 185 | u := { sdcch8 := { tag := '01'B, sub_chan := sub_slot } }, |
| 186 | tn := tn |
| 187 | } |
| 188 | |
| 189 | template (value) RslChannelNr ts_RslChanNr0(uint3_t tn, RslChanNr0 cht) := { |
| 190 | u := { ch0 := cht }, |
| 191 | tn := tn |
| 192 | } |
| 193 | template (value) RslChannelNr ts_RslChanNr_RACH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_RACH); |
| 194 | template (value) RslChannelNr ts_RslChanNr_BCCH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_BCCH); |
| 195 | template (value) RslChannelNr ts_RslChanNr_PCH_AGCH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_PCH_AGCH); |
| 196 | template (value) RslChannelNr ts_RslChanNr_Bm(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_Bm_ACCH); |
| 197 | template (value) RslChannelNr ts_RslChanNr_PDCH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_OSMO_PDCH); |
| 198 | template (value) RslChannelNr ts_RslChanNr_CBCH4(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH4); |
| 199 | template (value) RslChannelNr ts_RslChanNr_CBCH8(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH8); |
| 200 | template (value) RslChannelNr ts_RslChanNr_Lm(uint3_t tn, uint1_t sub_slot) := { |
| 201 | u := { lm := { tag := '0001'B, sub_chan := sub_slot } }, |
| 202 | tn := tn |
| 203 | } |
| 204 | template (value) RslChannelNr ts_RslChanNr_SDCCH4(uint3_t tn, uint2_t sub_slot) := { |
| 205 | u := { sdcch4 := { tag := '001'B, sub_chan := sub_slot } }, |
| 206 | tn := tn |
| 207 | } |
| 208 | template (value) RslChannelNr ts_RslChanNr_SDCCH8(uint3_t tn, uint3_t sub_slot) := { |
| 209 | u := { sdcch8 := { tag := '01'B, sub_chan := sub_slot } }, |
| 210 | tn := tn |
| 211 | } |
| 212 | |
| 213 | /* TS 48.058 9.3.2 Link ID */ |
| 214 | type enumerated RslLinkIdC { |
| 215 | FACCH_SDCCH (0), |
| 216 | SACCH (1), |
| 217 | OSMO_PTCCH (2) /* Osmocom (trxcon) specific extension */ |
| 218 | } with { variant "FIELDLENGTH(2)" }; |
| 219 | |
| 220 | type enumerated RslSapi0Prio { |
| 221 | SAPI0_PRIO_NORMAL (0), |
| 222 | SAPI0_PRIO_HIGH (1), |
| 223 | SAPI0_PRIO_LOW (2) |
| 224 | } with { variant "FIELDLENGTH(2)" }; |
| 225 | |
| 226 | type uint3_t GsmSapi; |
| 227 | |
| 228 | type record RslLinkId { |
| 229 | RslLinkIdC c, |
| 230 | boolean na, |
| 231 | RslSapi0Prio prio, |
| 232 | GsmSapi sapi |
| 233 | } with { variant "" }; |
| 234 | |
| 235 | template RslLinkId tr_RslLinkId := { |
| 236 | c := ?, |
| 237 | na := ?, |
| 238 | prio := ?, |
| 239 | sapi := ? |
| 240 | }; |
| 241 | |
| 242 | template RslLinkId tr_RslLinkID_DCCH(template GsmSapi sapi) modifies tr_RslLinkId := { |
| 243 | c := FACCH_SDCCH, |
| 244 | na := false, |
| 245 | sapi := sapi |
| 246 | }; |
| 247 | |
| 248 | template RslLinkId tr_RslLinkID_SACCH(template GsmSapi sapi) modifies tr_RslLinkId := { |
| 249 | c := SACCH, |
| 250 | na := false, |
| 251 | sapi := sapi |
| 252 | }; |
| 253 | |
| 254 | template RslLinkId tr_RslLinkID_OSMO_PTCCH(template GsmSapi sapi) modifies tr_RslLinkId := { |
| 255 | c := OSMO_PTCCH, |
| 256 | na := false, |
| 257 | sapi := sapi |
| 258 | }; |
| 259 | |
| 260 | template (value) RslLinkId ts_RslLinkID_DCCH(GsmSapi sapi) := { |
| 261 | c := FACCH_SDCCH, |
| 262 | na := false, |
| 263 | prio := SAPI0_PRIO_NORMAL, |
| 264 | sapi := sapi |
| 265 | }; |
| 266 | |
| 267 | template (value) RslLinkId ts_RslLinkID_SACCH(GsmSapi sapi) := { |
| 268 | c := SACCH, |
| 269 | na := false, |
| 270 | prio := SAPI0_PRIO_NORMAL, |
| 271 | sapi := sapi |
| 272 | }; |
| 273 | |
| 274 | template (value) RslLinkId ts_RslLinkID_OSMO_PTCCH(GsmSapi sapi) := { |
| 275 | c := OSMO_PTCCH, |
| 276 | na := false, |
| 277 | prio := SAPI0_PRIO_NORMAL, |
| 278 | sapi := sapi |
| 279 | }; |
| 280 | |
| 281 | function f_hex_is_odd_length(hexstring digits) return bitstring { |
| 282 | if (lengthof(digits) rem 2 == 1) { |
| 283 | return '1'B; |
| 284 | } else { |
| 285 | return '0'B; |
Harald Welte | 0c8d5c0 | 2017-07-16 18:53:58 +0200 | [diff] [blame] | 286 | } |
Alexander Couzens | 5e6ae79 | 2020-09-11 19:49:22 +0200 | [diff] [blame] | 287 | } |
Harald Welte | 23b774e | 2018-02-05 09:14:34 +0100 | [diff] [blame] | 288 | |
Harald Welte | f097a8b | 2018-09-16 18:11:26 +0200 | [diff] [blame] | 289 | |
| 290 | /* TS 04.12 Section 3.3.1 Block type */ |
| 291 | type record CBCH_BlockType { |
| 292 | BIT1 spare, |
| 293 | BIT2 lpd, |
| 294 | boolean last_block, |
| 295 | uint4_t seq_nr |
| 296 | }; |
| 297 | template (value) CBCH_BlockType ts_CBCH_BlockType(template (value) uint4_t seq_nr, template (value) boolean last_block) := { |
| 298 | spare := '0'B, |
| 299 | lpd := '01'B, |
| 300 | last_block := last_block, |
| 301 | seq_nr := seq_nr |
| 302 | }; |
| 303 | template CBCH_BlockType tr_CBCH_BlockType(template uint4_t seq_nr := ?, template boolean last_block := ?) := { |
| 304 | spare := '0'B, |
| 305 | lpd := '01'B, |
| 306 | last_block := last_block, |
| 307 | seq_nr := seq_nr |
| 308 | }; |
| 309 | |
| 310 | /* TS 04.12 Section 3.3 */ |
| 311 | type record CBCH_Block { |
| 312 | CBCH_BlockType block_type, |
| 313 | OCT22 payload |
| 314 | }; |
| 315 | template (value) CBCH_Block ts_CBCH_Block(template (value) uint4_t seq_nr, template (value) boolean last_block, template (value) OCT22 payload) := { |
| 316 | block_type := ts_CBCH_BlockType(seq_nr, last_block), |
| 317 | payload := payload |
| 318 | }; |
| 319 | template CBCH_Block tr_CBCH_Block(template uint4_t seq_nr := ?, template boolean last_block := ?, template OCT22 payload := ?) := { |
| 320 | block_type := tr_CBCH_BlockType(seq_nr, last_block), |
| 321 | payload := payload |
| 322 | }; |
| 323 | |
| 324 | |
| 325 | external function enc_CBCH_Block(in CBCH_Block msg) return octetstring |
| 326 | with { extension "prototype(convert) encode(RAW)" }; |
| 327 | external function dec_CBCH_Block(in octetstring stream) return CBCH_Block |
| 328 | with { extension "prototype(convert) decode(RAW)" }; |
| 329 | |
| 330 | |
Harald Welte | 5377d2f | 2018-02-24 01:01:19 +0100 | [diff] [blame] | 331 | /* Convert RF signal level in dBm to RxLev (TS 45.008 Chapter 8.1.4) */ |
| 332 | function dbm2rxlev(integer dbm) return uint6_t { |
| 333 | var integer rxlev := dbm + 110; |
| 334 | if (rxlev > 63) { |
| 335 | rxlev := 63; |
| 336 | } else if (rxlev < 0) { |
| 337 | rxlev := 0; |
| 338 | } |
| 339 | return rxlev; |
| 340 | } |
| 341 | |
| 342 | function rxlev2dbm(uint6_t rxlev) return integer { |
| 343 | return -110 + rxlev; |
| 344 | } |
| 345 | |
| 346 | /* convert BER to RxQual value (TS 45.008 Chapter 8.2.4 */ |
| 347 | function ber2rxqual(float ber) return uint3_t { |
| 348 | if (ber < 0.2) { |
| 349 | return 0; |
| 350 | } else if (ber < 0.4) { |
| 351 | return 1; |
| 352 | } else if (ber < 0.8) { |
| 353 | return 2; |
| 354 | } else if (ber < 1.6) { |
| 355 | return 3; |
| 356 | } else if (ber < 3.2) { |
| 357 | return 4; |
| 358 | } else if (ber < 6.4) { |
| 359 | return 5; |
| 360 | } else if (ber < 12.8) { |
| 361 | return 6; |
| 362 | } else { |
| 363 | return 7; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /* convert RxQual to BER (TS 45.008 Chapter 8.2.4 */ |
| 368 | function rxqual2ber(uint3_t rxqual) return float { |
| 369 | select (rxqual) { |
| 370 | case (0) { return 0.14 } |
| 371 | case (1) { return 0.28 } |
| 372 | case (2) { return 0.57 } |
| 373 | case (3) { return 1.13 } |
| 374 | case (4) { return 2.26 } |
| 375 | case (5) { return 4.53 } |
| 376 | case (6) { return 9.05 } |
| 377 | case (7) { return 18.10 } |
| 378 | case else { return 1000.0 } |
| 379 | } |
| 380 | } |
| 381 | |
Harald Welte | 68e495b | 2018-02-25 00:05:57 +0100 | [diff] [blame] | 382 | const float GSM_FRAME_DURATION := 0.12/26.0; /* 4.615 ms */ |
| 383 | const float GSM51_MFRAME_DURATION := 51.0 * GSM_FRAME_DURATION; /* 235.365 ms */ |
| 384 | const float GSM51_MFRAMES_PER_SEC := 1.0 / GSM51_MFRAME_DURATION; /* 4.248 */ |
| 385 | |
| 386 | /* number of downlink CCCH blocks per second */ |
| 387 | function f_ccch_blocks_per_mframe(boolean combined_ccch) return integer { |
| 388 | if (not combined_ccch) { |
| 389 | /* 9 blocks per 51 multiframe */ |
| 390 | return 9; |
| 391 | } else { |
| 392 | /* 3 blocks per 51 multiframe */ |
| 393 | return 3; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /* this ignores any possible paging combining! */ |
| 398 | function f_pch_block_rate_est(boolean combined_ccch, integer bs_ag_blks_res) return float { |
| 399 | var integer ccch_per_mframe := f_ccch_blocks_per_mframe(combined_ccch); |
| 400 | var integer pch_per_mframe := ccch_per_mframe - bs_ag_blks_res; |
| 401 | return GSM51_MFRAMES_PER_SEC * int2float(pch_per_mframe); |
| 402 | } |
| 403 | |
| 404 | /* this ignores any possible imm.ass combining! */ |
| 405 | function f_agch_block_rate_est(boolean combined_ccch, integer bs_ag_blks_res) return float { |
| 406 | var integer ccch_per_mframe := f_ccch_blocks_per_mframe(combined_ccch); |
| 407 | return GSM51_MFRAMES_PER_SEC * int2float(bs_ag_blks_res); |
| 408 | } |
| 409 | |
Harald Welte | 262f122 | 2018-02-25 16:33:38 +0100 | [diff] [blame] | 410 | /* compute TC as per 45.002 6.3.1.3 */ |
| 411 | function f_gsm_compute_tc(integer fn) return integer { |
| 412 | return (fn / 51) mod 8; |
| 413 | } |
| 414 | |
Harald Welte | 557c9f8 | 2020-09-12 21:30:17 +0200 | [diff] [blame] | 415 | type hexstring GsmBcdString with { variant "HEXORDER(low)" }; |
| 416 | type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" }; |
| 417 | |
| 418 | /* 24.008 10.5.1.3 */ |
| 419 | type record LocationAreaIdentification { |
| 420 | BcdMccMnc mcc_mnc, |
| 421 | uint16_t lac |
| 422 | } with { variant "" }; |
Pau Espin Pedrol | 8bd54cf | 2021-01-08 17:11:03 +0100 | [diff] [blame] | 423 | template (value) LocationAreaIdentification ts_LAI(BcdMccMnc mcc_mnc, uint16_t lac) := { |
| 424 | mcc_mnc := mcc_mnc, |
| 425 | lac := lac |
| 426 | }; |
Harald Welte | 557c9f8 | 2020-09-12 21:30:17 +0200 | [diff] [blame] | 427 | |
| 428 | /* 24.008 10.5.5.15 */ |
| 429 | type record RoutingAreaIdentification { |
| 430 | LocationAreaIdentification lai, |
| 431 | uint8_t rac |
| 432 | } with { variant "" }; |
Pau Espin Pedrol | 8bd54cf | 2021-01-08 17:11:03 +0100 | [diff] [blame] | 433 | template (value) RoutingAreaIdentification ts_RAI(template (value) LocationAreaIdentification lai, uint8_t rac) := { |
| 434 | lai := lai, |
| 435 | rac := rac |
| 436 | }; |
Harald Welte | 557c9f8 | 2020-09-12 21:30:17 +0200 | [diff] [blame] | 437 | |
| 438 | external function enc_RoutingAreaIdentification(RoutingAreaIdentification rai) return octetstring |
| 439 | with { extension "prototype(convert)" extension "encode(RAW)" } |
| 440 | |
| 441 | /* TS 24.008 10.5.1.1 */ |
| 442 | type uint16_t CellIdentity; |
| 443 | |
Harald Welte | 5377d2f | 2018-02-24 01:01:19 +0100 | [diff] [blame] | 444 | |
Harald Welte | a082a69 | 2017-07-15 15:58:13 +0200 | [diff] [blame] | 445 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |