blob: 134edbd65484559785d80a8a78d08d3332575e39 [file] [log] [blame]
Harald Weltea082a692017-07-15 15:58:13 +02001/* Encoding/Decoding routines for GSM System Information messages
Harald Welte34b5a952019-05-27 11:54:11 +02002 * 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 Weltea082a692017-07-15 15:58:13 +020012
13module GSM_Types {
14
Alexander Couzens5e6ae792020-09-11 19:49:22 +020015import from General_Types all;
16import from Osmocom_Types all;
Pau Espin Pedrol38554622021-02-05 15:57:59 +010017import from Misc_Helpers all;
Harald Weltea082a692017-07-15 15:58:13 +020018
Alexander Couzens5e6ae792020-09-11 19:49:22 +020019type integer GsmArfcn (0..1023);
20type integer UmtsArfcn (0..16383);
21type integer UmtsScramblingCode (0..511);
22const integer GsmMaxFrameNumber := 26*51*2048;
23type integer GsmFrameNumber (0..GsmMaxFrameNumber);
24type integer GsmRxLev (0..63);
25type integer GsmTsc (0..7) with { variant "FIELDLENGTH(8)" };
26type uint32_t GsmTmsi;
27type OCT4 GprsTlli;
28type hexstring GsmMcc length(3);
29type hexstring GsmMnc length(2 .. 3);
30type uint16_t GsmLac;
31type uint16_t GsmCellId;
Harald Weltebdc5dbd2017-07-16 00:00:43 +020032
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +070033/* ARFCN with explicit band discrimination */
34type record GsmBandArfcn {
35 boolean pcs,
Vadim Yanitskiy05a236a2020-11-14 04:58:30 +070036 boolean uplink,
37 BIT4 spare,
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +070038 GsmArfcn arfcn
39} with {
40 variant (arfcn) "BYTEORDER(last)"
41 variant (arfcn) "FIELDLENGTH(10)"
42};
43
44template (value) GsmBandArfcn
45ts_GsmBandArfcn(template (value) GsmArfcn arfcn,
Vadim Yanitskiy05a236a2020-11-14 04:58:30 +070046 template (value) boolean pcs := false,
47 template (value) boolean uplink := false) := {
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +070048 pcs := pcs,
Vadim Yanitskiy05a236a2020-11-14 04:58:30 +070049 uplink := uplink,
50 spare := '0000'B,
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +070051 arfcn := arfcn
52};
53template GsmBandArfcn
54tr_GsmBandArfcn(template (present) GsmArfcn arfcn,
Vadim Yanitskiy05a236a2020-11-14 04:58:30 +070055 template (present) boolean pcs := ?,
56 template (present) boolean uplink := ?) := {
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +070057 pcs := pcs,
Vadim Yanitskiy05a236a2020-11-14 04:58:30 +070058 uplink := uplink,
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +070059 spare := ?,
60 arfcn := arfcn
61};
62
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +070063/* see enum 'gsm_phys_chan_config' in libosmocore */
64type 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 Couzens5e6ae792020-09-11 19:49:22 +020080type enumerated GprsCodingScheme {
81 CS1, CS2, CS3, CS4
82};
Harald Welte1dcc3712017-08-01 00:05:52 +020083
Alexander Couzens5e6ae792020-09-11 19:49:22 +020084function 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 Welte060e27a2018-03-03 20:38:19 +010090 }
Pau Espin Pedrol38554622021-02-05 15:57:59 +010091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
92 log2str("Invalid GPRS CS ", cs));
93 return 0;
Alexander Couzens5e6ae792020-09-11 19:49:22 +020094}
Harald Welte060e27a2018-03-03 20:38:19 +010095
Pau Espin Pedrolbfd69f62020-10-22 18:06:07 +020096const GprsTlli TLLI_UNUSED := 'FFFFFFFF'O;
97function 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 Couzens5e6ae792020-09-11 19:49:22 +0200105/* 10.5.2.8 */
106type 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)" };
112type record ChannelNeeded12 {
113 ChannelNeeded second,
114 ChannelNeeded first
115} with { variant "" };
Harald Welted2e342f2017-07-16 07:34:13 +0200116
Harald Welted2e342f2017-07-16 07:34:13 +0200117
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200118/* TS 48.058 9.3.1 Channel Number IE */
119type 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 Hofmeyr9c3b82f2021-05-27 00:38:59 +0200127 RSL_CHAN_NR_OSMO_CBCH8 ('11010'B),
128 RSL_CHAN_NR_OSMO_VAMOS_Bm_ACCH ('11101'B)
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200129} with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" };
Harald Welte0c8d5c02017-07-16 18:53:58 +0200130
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200131type record RslChanNr2 {
Neels Hofmeyr9c3b82f2021-05-27 00:38:59 +0200132 BIT4 tag ('0001'B, '1111'B),
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200133 uint1_t sub_chan
134} with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" };
Harald Welte0c8d5c02017-07-16 18:53:58 +0200135
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200136type record RslChanNr4 {
137 BIT3 tag ('001'B),
138 uint2_t sub_chan
139} with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" };
Harald Welte0c8d5c02017-07-16 18:53:58 +0200140
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200141type record RslChanNr8 {
142 BIT2 tag ('01'B),
143 uint3_t sub_chan
144} with { variant "FIELDLENGTH(5)" variant "FIELDORDER(msb)" };
Harald Welte0c8d5c02017-07-16 18:53:58 +0200145
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200146type union RslChanNrU {
147 RslChanNr0 ch0,
148 RslChanNr2 lm,
149 RslChanNr4 sdcch4,
150 RslChanNr8 sdcch8
151} with {
152 variant "TAG(lm, tag = '0001'B;
Neels Hofmeyr9c3b82f2021-05-27 00:38:59 +0200153 lm, tag = '1111'B;
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200154 sdcch4, tag = '001'B;
155 sdcch8, tag = '01'B;
156 ch0, OTHERWISE)"
157 variant "FIELDLENGTH(5)"
158 variant "FIELDORDER(msb)"
159};
Harald Welte0c8d5c02017-07-16 18:53:58 +0200160
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200161type record RslChannelNr {
162 RslChanNrU u,
163 uint3_t tn
164} with { variant "FIELDLENGTH(8)" variant "FIELDORDER(msb)" };
Harald Welte0c8d5c02017-07-16 18:53:58 +0200165
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200166template RslChannelNr t_RslChanNr0(template uint3_t tn, template RslChanNr0 cht) := {
167 u := { ch0 := cht },
168 tn := tn
169}
170
171template RslChannelNr t_RslChanNr_RACH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_RACH);
172template RslChannelNr t_RslChanNr_BCCH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_BCCH);
173template RslChannelNr t_RslChanNr_PCH_AGCH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_PCH_AGCH);
174template RslChannelNr t_RslChanNr_Bm(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_Bm_ACCH);
175template RslChannelNr t_RslChanNr_PDCH(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_OSMO_PDCH);
176template RslChannelNr t_RslChanNr_CBCH4(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH4);
177template RslChannelNr t_RslChanNr_CBCH8(template uint3_t tn) := t_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH8);
178template 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}
182template 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}
186template 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 Hofmeyr9c3b82f2021-05-27 00:38:59 +0200190template 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
195template 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 Couzens5e6ae792020-09-11 19:49:22 +0200199
200template (value) RslChannelNr ts_RslChanNr0(uint3_t tn, RslChanNr0 cht) := {
201 u := { ch0 := cht },
202 tn := tn
203}
204template (value) RslChannelNr ts_RslChanNr_RACH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_RACH);
205template (value) RslChannelNr ts_RslChanNr_BCCH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_BCCH);
206template (value) RslChannelNr ts_RslChanNr_PCH_AGCH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_PCH_AGCH);
207template (value) RslChannelNr ts_RslChanNr_Bm(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_Bm_ACCH);
208template (value) RslChannelNr ts_RslChanNr_PDCH(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_OSMO_PDCH);
209template (value) RslChannelNr ts_RslChanNr_CBCH4(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH4);
210template (value) RslChannelNr ts_RslChanNr_CBCH8(uint3_t tn) := ts_RslChanNr0(tn, RSL_CHAN_NR_OSMO_CBCH8);
211template (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}
215template (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}
219template (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 Hofmeyr9c3b82f2021-05-27 00:38:59 +0200223template (value) RslChannelNr ts_RslChanNr_Osmo_VAMOS_Bm(uint3_t tn) := {
224 u := { ch0 := RSL_CHAN_NR_OSMO_VAMOS_Bm_ACCH },
225 tn := tn
226}
227template (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 Couzens5e6ae792020-09-11 19:49:22 +0200232
233/* TS 48.058 9.3.2 Link ID */
234type enumerated RslLinkIdC {
235 FACCH_SDCCH (0),
236 SACCH (1),
237 OSMO_PTCCH (2) /* Osmocom (trxcon) specific extension */
238} with { variant "FIELDLENGTH(2)" };
239
240type enumerated RslSapi0Prio {
241 SAPI0_PRIO_NORMAL (0),
242 SAPI0_PRIO_HIGH (1),
243 SAPI0_PRIO_LOW (2)
244} with { variant "FIELDLENGTH(2)" };
245
246type uint3_t GsmSapi;
247
248type record RslLinkId {
249 RslLinkIdC c,
250 boolean na,
251 RslSapi0Prio prio,
252 GsmSapi sapi
253} with { variant "" };
254
255template RslLinkId tr_RslLinkId := {
256 c := ?,
257 na := ?,
258 prio := ?,
259 sapi := ?
260};
261
262template RslLinkId tr_RslLinkID_DCCH(template GsmSapi sapi) modifies tr_RslLinkId := {
263 c := FACCH_SDCCH,
264 na := false,
265 sapi := sapi
266};
267
268template RslLinkId tr_RslLinkID_SACCH(template GsmSapi sapi) modifies tr_RslLinkId := {
269 c := SACCH,
270 na := false,
271 sapi := sapi
272};
273
274template RslLinkId tr_RslLinkID_OSMO_PTCCH(template GsmSapi sapi) modifies tr_RslLinkId := {
275 c := OSMO_PTCCH,
276 na := false,
277 sapi := sapi
278};
279
280template (value) RslLinkId ts_RslLinkID_DCCH(GsmSapi sapi) := {
281 c := FACCH_SDCCH,
282 na := false,
283 prio := SAPI0_PRIO_NORMAL,
284 sapi := sapi
285};
286
287template (value) RslLinkId ts_RslLinkID_SACCH(GsmSapi sapi) := {
288 c := SACCH,
289 na := false,
290 prio := SAPI0_PRIO_NORMAL,
291 sapi := sapi
292};
293
294template (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
301function 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 Welte0c8d5c02017-07-16 18:53:58 +0200306 }
Alexander Couzens5e6ae792020-09-11 19:49:22 +0200307}
Harald Welte23b774e2018-02-05 09:14:34 +0100308
Harald Weltef097a8b2018-09-16 18:11:26 +0200309
310/* TS 04.12 Section 3.3.1 Block type */
311type record CBCH_BlockType {
312 BIT1 spare,
313 BIT2 lpd,
314 boolean last_block,
315 uint4_t seq_nr
316};
317template (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};
323template 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 */
331type record CBCH_Block {
332 CBCH_BlockType block_type,
333 OCT22 payload
334};
335template (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};
339template 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
345external function enc_CBCH_Block(in CBCH_Block msg) return octetstring
346 with { extension "prototype(convert) encode(RAW)" };
347external function dec_CBCH_Block(in octetstring stream) return CBCH_Block
348 with { extension "prototype(convert) decode(RAW)" };
349
350
Harald Welte5377d2f2018-02-24 01:01:19 +0100351/* Convert RF signal level in dBm to RxLev (TS 45.008 Chapter 8.1.4) */
352function 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
362function 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 */
367function 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 */
388function 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 Welte68e495b2018-02-25 00:05:57 +0100402const float GSM_FRAME_DURATION := 0.12/26.0; /* 4.615 ms */
403const float GSM51_MFRAME_DURATION := 51.0 * GSM_FRAME_DURATION; /* 235.365 ms */
404const float GSM51_MFRAMES_PER_SEC := 1.0 / GSM51_MFRAME_DURATION; /* 4.248 */
405
406/* number of downlink CCCH blocks per second */
407function 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! */
418function 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! */
425function 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 Welte262f1222018-02-25 16:33:38 +0100430/* compute TC as per 45.002 6.3.1.3 */
431function f_gsm_compute_tc(integer fn) return integer {
432 return (fn / 51) mod 8;
433}
434
Harald Welte557c9f82020-09-12 21:30:17 +0200435type hexstring GsmBcdString with { variant "HEXORDER(low)" };
436type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" };
437
Vadim Yanitskiy7a92d5f2023-02-08 00:27:12 +0700438/* Compute BcdMccMnc from a pair of GsmMcc/GsmMnc values */
439function f_enc_BcdMccMnc(GsmMcc mcc, GsmMnc mnc) return BcdMccMnc {
440 if (lengthof(mnc) == 2) {
441 mnc := mnc[0] & mnc[1] & 'F'H;
442 }
Vadim Yanitskiye9858ef2023-02-08 04:23:51 +0700443 /* 3GPP TS 24.008, Figure 10.5.13
444 * | MCC digit 2 | MCC digit 1 | octet 1
445 * | MNC digit 3 | MCC digit 3 | octet 2
446 * | MNC digit 2 | MNC digit 1 | octet 3 */
447 return mcc[1] & mcc[0] & mnc[2] & mcc[2] & mnc[1] & mnc[0];
Vadim Yanitskiy7a92d5f2023-02-08 00:27:12 +0700448}
449
Pau Espin Pedrol0637ba02021-01-22 18:36:12 +0100450/* Compute BcdMccMnc from integer values */
Vadim Yanitskiy7a92d5f2023-02-08 00:27:12 +0700451function f_enc_BcdMccMnc_int(uint16_t mcc, uint16_t mnc, boolean mnc_3_digits) return BcdMccMnc {
452 var hexstring mcc_str := str2hex(int2str(mcc));
453 var hexstring mnc_str := str2hex(int2str(mnc));
Pau Espin Pedrol0637ba02021-01-22 18:36:12 +0100454 if (mnc_3_digits == true) {
Vadim Yanitskiy7a92d5f2023-02-08 00:27:12 +0700455 return f_enc_BcdMccMnc(mcc_str[0] & mcc_str[1] & mcc_str[2],
456 mnc_str[0] & mnc_str[1] & mnc_str[2]);
Pau Espin Pedrol0637ba02021-01-22 18:36:12 +0100457 } else {
Vadim Yanitskiy7a92d5f2023-02-08 00:27:12 +0700458 return f_enc_BcdMccMnc(mcc_str[0] & mcc_str[1] & mcc_str[2],
459 mnc_str[0] & mnc_str[1]);
Pau Espin Pedrol0637ba02021-01-22 18:36:12 +0100460 }
461}
462
Harald Welte557c9f82020-09-12 21:30:17 +0200463/* 24.008 10.5.1.3 */
464type record LocationAreaIdentification {
465 BcdMccMnc mcc_mnc,
466 uint16_t lac
467} with { variant "" };
Pau Espin Pedrol8bd54cf2021-01-08 17:11:03 +0100468template (value) LocationAreaIdentification ts_LAI(BcdMccMnc mcc_mnc, uint16_t lac) := {
469 mcc_mnc := mcc_mnc,
470 lac := lac
471};
Harald Welte557c9f82020-09-12 21:30:17 +0200472
473/* 24.008 10.5.5.15 */
474type record RoutingAreaIdentification {
475 LocationAreaIdentification lai,
476 uint8_t rac
477} with { variant "" };
Pau Espin Pedrol8bd54cf2021-01-08 17:11:03 +0100478template (value) RoutingAreaIdentification ts_RAI(template (value) LocationAreaIdentification lai, uint8_t rac) := {
479 lai := lai,
480 rac := rac
481};
Harald Welte557c9f82020-09-12 21:30:17 +0200482
483external function enc_RoutingAreaIdentification(RoutingAreaIdentification rai) return octetstring
484with { extension "prototype(convert)" extension "encode(RAW)" }
485
486/* TS 24.008 10.5.1.1 */
487type uint16_t CellIdentity;
488
Harald Welte5377d2f2018-02-24 01:01:19 +0100489
Harald Weltea082a692017-07-15 15:58:13 +0200490} with { encode "RAW"; variant "FIELDORDER(msb)" }