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