Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 1 | /* Common L3 helper functions in TTCN-3 |
| 2 | * (C) 2018 Harald Welte <laforge@gnumonks.org> |
| 3 | * contributions by sysmocom - s.f.m.c. GmbH |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Released under the terms of GNU General Public License, Version 2 or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | */ |
| 11 | |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 12 | module L3_Common { |
| 13 | |
| 14 | import from Osmocom_Types all; |
| 15 | import from General_Types all; |
Harald Welte | 5a4fa04 | 2018-02-16 20:59:21 +0100 | [diff] [blame] | 16 | import from MobileL3_GMM_SM_Types all; |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 17 | |
| 18 | type record AuthVector { |
| 19 | OCT16 rand, |
| 20 | OCT4 sres, |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 21 | OCT8 kc, |
| 22 | OCT16 ik, |
| 23 | OCT16 ck, |
| 24 | OCT16 autn, |
Alexander Couzens | 387f7f3 | 2018-09-04 18:10:59 +0200 | [diff] [blame] | 25 | OCT8 res, |
| 26 | /* auts is usally calculated from autn + rand on the MS. |
| 27 | * To simplify the test case, auts is generated instead calculated here. |
| 28 | */ |
| 29 | OCT14 auts |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 32 | function f_gen_auth_vec_2g() return AuthVector { |
| 33 | var AuthVector vec; |
Vadim Yanitskiy | 6b29571 | 2020-11-04 11:15:55 +0700 | [diff] [blame] | 34 | vec.rand := f_rnd_octstring(16); |
| 35 | vec.sres := f_rnd_octstring(4); |
| 36 | vec.kc := f_rnd_octstring(8); |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 37 | return vec; |
| 38 | } |
| 39 | |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 40 | function f_gen_auth_vec_3g() return AuthVector { |
| 41 | var AuthVector vec := f_gen_auth_vec_2g(); |
Vadim Yanitskiy | 6b29571 | 2020-11-04 11:15:55 +0700 | [diff] [blame] | 42 | vec.ik := f_rnd_octstring(16); |
| 43 | vec.ck := f_rnd_octstring(16); |
| 44 | vec.autn := f_rnd_octstring(16); |
| 45 | vec.res := f_rnd_octstring(8); |
| 46 | vec.auts := f_rnd_octstring(14); |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 47 | return vec; |
| 48 | } |
| 49 | |
Harald Welte | 14a0f94 | 2018-02-16 20:42:23 +0100 | [diff] [blame] | 50 | /* 3GPP TS 23.003 2.6 */ |
| 51 | type enumerated TlliType { |
| 52 | TLLI_LOCAL, |
| 53 | TLLI_FOREIGN, |
| 54 | TLLI_RANDOM, |
| 55 | TLLI_AUXILIARY, |
| 56 | TLLI_RESERVED, |
| 57 | TLLI_G_RNTI, |
| 58 | TLLI_RAND_G_RNTI |
| 59 | } |
| 60 | |
| 61 | /* 3GPP TS 23.003 2.6 */ |
| 62 | function f_gprs_tlli_type(OCT4 tlli) return TlliType { |
| 63 | var bitstring tllib := oct2bit(tlli); |
| 64 | if (substr(tllib, 0, 2) == '11'B) { |
| 65 | return TLLI_LOCAL; |
| 66 | } else if (substr(tllib, 0, 2) == '10'B) { |
| 67 | return TLLI_FOREIGN; |
| 68 | } else if (substr(tllib, 0, 5) == '01111'B) { |
| 69 | return TLLI_RANDOM; |
| 70 | } else if (substr(tllib, 0, 4) == '0110'B) { |
| 71 | return TLLI_RESERVED; |
| 72 | } else if (substr(tllib, 0, 3) == '010'B) { |
| 73 | return TLLI_RESERVED; |
| 74 | } else if (substr(tllib, 0, 4) == '0000'B) { |
| 75 | return TLLI_G_RNTI; |
| 76 | } else if (substr(tllib, 0, 4) == '0001'B) { |
| 77 | return TLLI_RAND_G_RNTI; |
| 78 | } else { |
| 79 | setverdict(fail, "Unknonw TLLI Type ", tllib); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 80 | mtc.stop; |
Harald Welte | 14a0f94 | 2018-02-16 20:42:23 +0100 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
| 84 | function f_gprs_tlli_random() return OCT4 { |
| 85 | var OCT4 tlli := f_rnd_octstring(4); |
| 86 | return tlli or4b 'c0000000'O; |
| 87 | } |
| 88 | |
Harald Welte | 5a4fa04 | 2018-02-16 20:59:21 +0100 | [diff] [blame] | 89 | function f_RAI(HEX0_3n mcc, HEX0_3n mnc, OCT2 lac, OCT1 rac) return RoutingAreaIdentificationV { |
| 90 | if (lengthof(mnc) == 2) { |
| 91 | mnc := mnc & 'F'H; |
| 92 | } |
| 93 | var RoutingAreaIdentificationV ret := { |
| 94 | mccDigit1 := mcc[0], |
| 95 | mccDigit2 := mcc[1], |
| 96 | mccDigit3 := mcc[2], |
| 97 | mncDigit3 := mnc[2], |
| 98 | mncDigit1 := mnc[0], |
| 99 | mncDigit2 := mnc[1], |
| 100 | lac := lac, |
| 101 | rac := rac |
| 102 | } |
| 103 | return ret; |
| 104 | } |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 105 | |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 106 | function f_RAI_to_plmn_hexstr(RoutingAreaIdentificationV rai) return hexstring { |
| 107 | var hexstring plmn := |
| 108 | rai.mccDigit1 |
| 109 | & rai.mccDigit2 |
| 110 | & rai.mccDigit3 |
Alexander Couzens | c7dddbd | 2019-04-11 19:18:35 +0200 | [diff] [blame] | 111 | & rai.mncDigit3 |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 112 | & rai.mncDigit1 |
Alexander Couzens | c7dddbd | 2019-04-11 19:18:35 +0200 | [diff] [blame] | 113 | & rai.mncDigit2; |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 114 | return plmn; |
| 115 | } |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 116 | |
| 117 | } |