Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 1 | /* MME (Mobility Management Engine) test suite in TTCN-3 |
| 2 | * (C) 2019 Harald Welte <laforge@gnumonks.org> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Released under the terms of GNU General Public License, Version 2 or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | module MME_Tests { |
| 12 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 13 | import from General_Types all; |
| 14 | |
| 15 | import from S1AP_Types all; |
| 16 | import from S1AP_Templates all; |
| 17 | import from S1AP_Emulation all; |
| 18 | import from S1AP_PDU_Descriptions all; |
| 19 | import from S1AP_IEs all; |
| 20 | |
| 21 | import from NAS_EPS_Types all; |
| 22 | import from NAS_Templates all; |
| 23 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 24 | import from DIAMETER_Types all; |
| 25 | import from DIAMETER_Templates all; |
| 26 | import from DIAMETER_Emulation all; |
| 27 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 28 | import from SGsAP_Types all; |
| 29 | import from SGsAP_Templates all; |
| 30 | import from SGsAP_Emulation all; |
| 31 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 32 | import from LTE_CryptoFunctions all; |
| 33 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 34 | import from L3_Templates all; |
| 35 | import from DNS_Helpers all; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 36 | import from Osmocom_Types all; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 37 | |
| 38 | friend module MME_Tests_SGsAP; |
| 39 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 40 | /* (maximum) number of emulated eNBs */ |
| 41 | const integer NUM_ENB := 3; |
| 42 | |
| 43 | /* (maximum) number of emulated UEs */ |
| 44 | const integer NUM_UE := 3; |
| 45 | |
| 46 | /* parameters of emulated ENB */ |
| 47 | type record EnbParams { |
| 48 | Global_ENB_ID global_enb_id, |
| 49 | integer cell_identity, |
| 50 | SupportedTAs supported_tas |
| 51 | } |
| 52 | |
| 53 | /* parameters of emulated UE */ |
| 54 | type record UeParams { |
| 55 | hexstring imsi |
| 56 | } |
| 57 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 58 | type component MTC_CT { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 59 | /* S1 intreface of emulated ENBs */ |
| 60 | var EnbParams g_enb_pars[NUM_ENB]; |
| 61 | var S1AP_Emulation_CT vc_S1AP[NUM_ENB]; |
| 62 | port S1AP_PT S1AP_UNIT[NUM_ENB]; |
| 63 | port S1APEM_PROC_PT S1AP_PROC[NUM_ENB]; |
| 64 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 65 | /* S6a/S6d interface of emulated HSS */ |
| 66 | var DIAMETER_Emulation_CT vc_DIAMETER; |
| 67 | port DIAMETER_PT DIAMETER_UNIT; |
| 68 | port DIAMETEREM_PROC_PT DIAMETER_PROC; |
| 69 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 70 | /* SGs interface of emulated MSC/VLR */ |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 71 | var SGsAP_Emulation_CT vc_SGsAP; |
| 72 | port SGsAP_PT SGsAP_UNIT; |
| 73 | port SGsAPEM_PROC_PT SGsAP_PROC; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 74 | |
| 75 | var UeParams g_ue_pars[NUM_UE]; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 78 | type component ConnHdlr extends S1AP_ConnHdlr, SGsAP_ConnHdlr, DIAMETER_ConnHdlr { |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 79 | var ConnHdlrPars g_pars; |
| 80 | timer g_Tguard := 30.0; |
| 81 | } |
| 82 | |
| 83 | type record ConnHdlrPars { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 84 | /* copied over from MTC_CT on start of component */ |
| 85 | EnbParams enb_pars[NUM_ENB], |
| 86 | /* copied over from MTC_CT on start of component */ |
| 87 | UeParams ue_pars, |
| 88 | /* currently used MME (index into enb_pars, S1AP, ...) */ |
| 89 | integer mme_idx |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | modulepar { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 93 | /* S1 interface */ |
| 94 | charstring mp_mme_ip := "127.0.0.1"; |
| 95 | integer mp_mme_s1ap_port := 36412; |
| 96 | charstring mp_s1_local_ip := "127.0.0.1"; |
| 97 | integer mp_s1_local_port := 50000; |
| 98 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 99 | /* S6 interface */ |
| 100 | charstring mp_s6_local_ip := "127.0.0.4"; |
| 101 | integer mp_s6_local_port := 3868; |
| 102 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 103 | /* SGs interface */ |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 104 | charstring mp_sgs_local_ip := "127.0.0.1"; |
| 105 | integer mp_sgs_local_port := 29118; |
| 106 | charstring mp_vlr_name := "vlr.example.net"; |
| 107 | charstring mp_mme_name := "mmec01.mmegi0001.mme.epc.mnc070.mcc901.3gppnetwork.org"; |
| 108 | } |
| 109 | |
| 110 | /* send incoming unit data messages (like reset) to global SGsAP_UNIT port */ |
| 111 | friend function ForwardUnitdataCallback(PDU_SGsAP msg) |
| 112 | runs on SGsAP_Emulation_CT return template PDU_SGsAP { |
| 113 | SGsAP_UNIT.send(msg); |
| 114 | return omit; |
| 115 | } |
| 116 | |
| 117 | friend function f_init_sgsap(charstring id) runs on MTC_CT { |
| 118 | id := id & "-SGsAP"; |
| 119 | var SGsAPOps ops := { |
| 120 | create_cb := refers(SGsAP_Emulation.ExpectedCreateCallback), |
| 121 | unitdata_cb := refers(ForwardUnitdataCallback) |
| 122 | } |
| 123 | var SGsAP_conn_parameters pars := { |
| 124 | remote_ip := "", |
| 125 | remote_sctp_port := -1, |
| 126 | local_ip := mp_sgs_local_ip, |
| 127 | local_sctp_port := mp_sgs_local_port |
| 128 | } |
| 129 | |
| 130 | vc_SGsAP := SGsAP_Emulation_CT.create(id); |
| 131 | map(vc_SGsAP:SGsAP, system:SGsAP_CODEC_PT); |
| 132 | connect(vc_SGsAP:SGsAP_PROC, self:SGsAP_PROC); |
| 133 | connect(vc_SGsAP:SGsAP_UNIT, self:SGsAP_UNIT); |
| 134 | vc_SGsAP.start(SGsAP_Emulation.main(ops, pars, id)); |
| 135 | } |
| 136 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 137 | /* send incoming unit data messages (like reset) to global S1AP_UNIT port */ |
| 138 | friend function S1apForwardUnitdataCallback(S1AP_PDU msg) |
| 139 | runs on S1AP_Emulation_CT return template S1AP_PDU { |
| 140 | S1AP_UNIT.send(msg); |
| 141 | return omit; |
| 142 | } |
| 143 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 144 | friend function f_init_one_enb(charstring id, integer num := 0) runs on MTC_CT { |
| 145 | id := id & "-S1AP" & int2str(num); |
| 146 | var S1APOps ops := { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 147 | create_cb := refers(S1AP_Emulation.ExpectedCreateCallback), |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 148 | unitdata_cb := refers(S1apForwardUnitdataCallback) |
| 149 | } |
| 150 | var S1AP_conn_parameters pars := { |
| 151 | remote_ip := mp_mme_ip, |
| 152 | remote_sctp_port := mp_mme_s1ap_port, |
| 153 | local_ip := mp_s1_local_ip, |
| 154 | local_sctp_port := mp_s1_local_port + num, |
| 155 | role := NAS_ROLE_UE |
| 156 | } |
| 157 | var PLMNidentity plmn_id := '00f110'O; |
| 158 | var EnbParams enb_pars := { |
| 159 | global_enb_id := { |
| 160 | pLMNidentity := plmn_id, |
| 161 | eNB_ID := { |
| 162 | macroENB_ID := int2bit(num, 20) |
| 163 | }, |
| 164 | iE_Extensions := omit |
| 165 | }, |
| 166 | cell_identity := num, |
| 167 | supported_tas := { |
| 168 | { |
| 169 | tAC := int2oct(12345, 2), |
| 170 | broadcastPLMNs := { plmn_id }, |
| 171 | iE_Extensions := omit |
| 172 | } |
| 173 | } |
| 174 | }; |
| 175 | |
| 176 | g_enb_pars[num] := enb_pars; |
| 177 | vc_S1AP[num] := S1AP_Emulation_CT.create(id); |
| 178 | map(vc_S1AP[num]:S1AP, system:S1AP_CODEC_PT); |
| 179 | connect(vc_S1AP[num]:S1AP_PROC, self:S1AP_PROC[num]); |
| 180 | connect(vc_S1AP[num]:S1AP_UNIT, self:S1AP_UNIT[num]); |
| 181 | vc_S1AP[num].start(S1AP_Emulation.main(ops, pars, id)); |
| 182 | S1AP_UNIT[num].receive(S1APEM_Event:{up_down:=S1APEM_EVENT_UP}); |
| 183 | } |
| 184 | friend function f_init_one_ue(inout UeParams uep, integer imsi_suffix) { |
| 185 | uep := { |
| 186 | imsi := f_gen_imsi(imsi_suffix) |
| 187 | } |
| 188 | } |
| 189 | friend function f_init_s1ap(charstring id, integer imsi_suffix) runs on MTC_CT { |
| 190 | var integer i; |
| 191 | for (i := 0; i < NUM_ENB; i := i+1) { |
| 192 | f_init_one_enb(id, i); |
| 193 | } |
| 194 | for (i := 0; i < NUM_UE; i := i+1) { |
| 195 | f_init_one_ue(g_ue_pars[i], i*1000 + imsi_suffix); |
| 196 | } |
| 197 | } |
| 198 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 199 | friend function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 200 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 201 | DIAMETER_UNIT.send(msg); |
| 202 | return omit; |
| 203 | } |
| 204 | |
| 205 | friend function f_init_diameter(charstring id) runs on MTC_CT { |
| 206 | var DIAMETEROps ops := { |
| 207 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
Vadim Yanitskiy | b46f01e | 2021-12-06 03:23:13 +0300 | [diff] [blame] | 208 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 209 | raw := false /* handler mode (IMSI based routing) */ |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 210 | }; |
| 211 | var DIAMETER_conn_parameters pars := { |
| 212 | remote_ip := mp_mme_ip, |
| 213 | remote_sctp_port := -1, |
| 214 | local_ip := mp_s6_local_ip, |
Harald Welte | 61f73d5 | 2020-04-26 21:41:12 +0200 | [diff] [blame] | 215 | local_sctp_port := mp_s6_local_port, |
| 216 | origin_host := "hss.localdomain", |
| 217 | origin_realm := "localdomain", |
Pau Espin Pedrol | 33b4749 | 2022-03-08 17:43:01 +0100 | [diff] [blame] | 218 | auth_app_id := omit, |
Harald Welte | 61f73d5 | 2020-04-26 21:41:12 +0200 | [diff] [blame] | 219 | vendor_app_id := c_DIAMETER_3GPP_S6_AID |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 220 | }; |
| 221 | vc_DIAMETER := DIAMETER_Emulation_CT.create(id); |
| 222 | map(vc_DIAMETER:DIAMETER, system:DIAMETER_CODEC_PT); |
| 223 | connect(vc_DIAMETER:DIAMETER_UNIT, self:DIAMETER_UNIT); |
| 224 | connect(vc_DIAMETER:DIAMETER_PROC, self:DIAMETER_PROC); |
| 225 | vc_DIAMETER.start(DIAMETER_Emulation.main(ops, pars, id)); |
Harald Welte | d01b5d0 | 2020-04-26 22:05:53 +0200 | [diff] [blame] | 226 | |
| 227 | f_diameter_wait_capability(DIAMETER_UNIT); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 230 | friend template (value) TAI ts_enb_S1AP_TAI(EnbParams enb) := { |
| 231 | pLMNidentity := enb.global_enb_id.pLMNidentity, |
| 232 | tAC := enb.supported_tas[0].tAC, |
| 233 | iE_Extensions := omit |
| 234 | } |
| 235 | |
| 236 | friend template (value) EUTRAN_CGI ts_enb_S1AP_CGI(EnbParams enb) := { |
| 237 | pLMNidentity := enb.global_enb_id.pLMNidentity, |
| 238 | cell_ID := int2bit(enb.cell_identity, 28), |
| 239 | iE_Extensions := omit |
| 240 | } |
| 241 | |
| 242 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 243 | /* generate parameters for a connection handler */ |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 244 | friend function f_init_pars(integer ue_idx := 0) |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 245 | runs on MTC_CT return ConnHdlrPars { |
| 246 | var ConnHdlrPars pars := { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 247 | enb_pars := g_enb_pars, |
| 248 | ue_pars := g_ue_pars[ue_idx], |
| 249 | mme_idx := 0 |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 250 | }; |
| 251 | return pars; |
| 252 | } |
| 253 | |
| 254 | type function void_fn(ConnHdlrPars pars) runs on ConnHdlr; |
| 255 | |
| 256 | /* start a connection handler with given parameters */ |
| 257 | friend function f_start_handler_with_pars(void_fn fn, ConnHdlrPars pars, integer s1ap_idx := 0) |
| 258 | runs on MTC_CT return ConnHdlr { |
| 259 | var ConnHdlr vc_conn; |
| 260 | var charstring id := testcasename() & int2str(s1ap_idx); |
| 261 | |
| 262 | vc_conn := ConnHdlr.create(id); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 263 | /* S1AP part */ |
| 264 | connect(vc_conn:S1AP, vc_S1AP[s1ap_idx]:S1AP_CLIENT); |
| 265 | connect(vc_conn:S1AP_PROC, vc_S1AP[s1ap_idx]:S1AP_PROC); |
| 266 | if (isbound(vc_SGsAP)) { |
| 267 | /* SGsAP part */ |
| 268 | connect(vc_conn:SGsAP, vc_SGsAP:SGsAP_CLIENT); |
| 269 | connect(vc_conn:SGsAP_PROC, vc_SGsAP:SGsAP_PROC); |
| 270 | } |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 271 | if (isbound(vc_DIAMETER)) { |
| 272 | connect(vc_conn:DIAMETER, vc_DIAMETER:DIAMETER_CLIENT); |
| 273 | connect(vc_conn:DIAMETER_PROC, vc_DIAMETER:DIAMETER_PROC); |
| 274 | } |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 275 | |
| 276 | /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have |
| 277 | * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */ |
| 278 | vc_conn.start(derefers(fn)(pars)); |
| 279 | return vc_conn; |
| 280 | } |
| 281 | |
| 282 | /* altstep for the global guard timer */ |
| 283 | private altstep as_Tguard()runs on ConnHdlr { |
| 284 | [] g_Tguard.timeout { |
| 285 | setverdict(fail, "Tguard timeout"); |
| 286 | mtc.stop; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | friend function f_init_handler(ConnHdlrPars pars, float t_guard := 30.0) runs on ConnHdlr { |
| 291 | /* make parameters available via component variable */ |
| 292 | g_pars := pars; |
| 293 | /* start guard timre and activate it as default */ |
| 294 | g_Tguard.start(t_guard); |
| 295 | activate(as_Tguard()); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 296 | if (DIAMETER_PROC.checkstate("Connected")) { |
| 297 | f_diameter_expect(g_pars.ue_pars.imsi); |
| 298 | } |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 299 | if (SGsAP_PROC.checkstate("Connected")) { |
| 300 | /* Route all SGsAP mesages for our IMSIto us */ |
| 301 | f_create_sgsap_expect(pars.ue_pars.imsi); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | |
| 306 | |
| 307 | friend function f_s1ap_setup(integer idx := 0, template Cause cause := omit) runs on MTC_CT { |
| 308 | var template (present) Cause exp_cause; |
| 309 | var boolean exp_fail := false; |
| 310 | timer T := 5.0; |
| 311 | if (not istemplatekind(cause, "omit")) { |
| 312 | exp_fail := true; |
| 313 | exp_cause := cause; |
| 314 | } |
| 315 | |
| 316 | S1AP_UNIT[idx].send(ts_S1AP_SetupReq(g_enb_pars[idx].global_enb_id, |
| 317 | g_enb_pars[idx].supported_tas, v32)); |
| 318 | T.start; |
| 319 | alt { |
| 320 | [exp_fail] S1AP_UNIT[idx].receive(tr_S1AP_SetupFail(exp_cause)) { |
| 321 | setverdict(pass); |
| 322 | } |
| 323 | [not exp_fail] S1AP_UNIT[idx].receive(tr_S1AP_SetupResp) { |
| 324 | setverdict(pass); |
| 325 | } |
| 326 | [] S1AP_UNIT[idx].receive { |
| 327 | setverdict(fail, "Received unexpected S1AP"); |
| 328 | } |
| 329 | [] T.timeout { |
| 330 | setverdict(fail, "Timeout waiting for S1AP Setup result"); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /* Unsuccessful S1 Setup procedure to MME (wrong PLMN) */ |
| 336 | testcase TC_s1ap_setup_wrong_plmn() runs on MTC_CT { |
| 337 | var charstring id := testcasename(); |
| 338 | f_init_s1ap(id, 1); |
| 339 | g_enb_pars[0].global_enb_id.pLMNidentity := '62F224'O; |
| 340 | f_s1ap_setup(0, {misc:=unknown_PLMN}); |
| 341 | } |
| 342 | |
| 343 | /* Unsuccessful S1 Setup procedure to MME (wrong PLMN) */ |
| 344 | testcase TC_s1ap_setup_wrong_tac() runs on MTC_CT { |
| 345 | var charstring id := testcasename(); |
| 346 | f_init_s1ap(id, 2); |
| 347 | g_enb_pars[0].supported_tas[0].broadcastPLMNs[0] := '62F224'O; |
| 348 | f_s1ap_setup(0, {misc:=unknown_PLMN}); |
| 349 | } |
| 350 | |
| 351 | /* Successful S1 Setup procedure to MME */ |
| 352 | testcase TC_s1ap_setup() runs on MTC_CT { |
| 353 | var charstring id := testcasename(); |
| 354 | f_init_s1ap(id, 3); |
| 355 | f_s1ap_setup(0); |
| 356 | } |
| 357 | |
| 358 | private const EPS_QualityOfServiceV c_NAS_defaultQoS := { |
| 359 | qCI := '00'O, |
| 360 | maxBitRateUplink := omit, |
| 361 | maxBitRateDownlink := omit, |
| 362 | guaranteedBitRateUplink := omit, |
| 363 | guaranteedBitRateDownlink := omit, |
| 364 | maxBitRateUplinkExt := omit, |
| 365 | maxBitRateDownlinkExt := omit, |
| 366 | guaranteedBitRateUplinkExt := omit, |
| 367 | guaranteedBitRateDownlinkExt := omit, |
| 368 | maxBitRateUplinkExt2 := omit, |
| 369 | maxBitRateDownlinkExt2 := omit, |
| 370 | guaranteedBitRateUplinkExt2 := omit, |
| 371 | guaranteedBitRateDownlinkExt2 := omit |
| 372 | }; |
| 373 | |
| 374 | private const UENetworkCapabilityV c_NAS_defaultUeNetCap := { |
| 375 | eEA := '10000000'B, |
| 376 | eIA := '11000000'B, |
| 377 | uEA := omit, |
| 378 | uIA := omit, |
| 379 | uCS2 := omit, |
| 380 | nF := omit, |
| 381 | vCC := omit, |
| 382 | lCS := omit, |
| 383 | lPP := omit, |
| 384 | aCC_CSFB := omit, |
| 385 | h245_ASH := omit, |
| 386 | proSe := omit, |
| 387 | proSe_dd := omit, |
| 388 | proSe_dc := omit, |
| 389 | proSe_relay := omit, |
| 390 | cP_CIoT := omit, |
| 391 | uP_CIoT := omit, |
| 392 | s1_Udata := omit, |
| 393 | eRwoPDN := omit, |
| 394 | hC_CP_CIoT := omit, |
| 395 | ePCO := omit, |
| 396 | multipleDRB := omit, |
| 397 | v2XPC5 := omit, |
| 398 | restrictEC := omit, |
| 399 | cPbackoff := omit, |
| 400 | dCNR := omit, |
| 401 | n1Mode := omit, |
| 402 | sGC := omit, |
| 403 | spare1 := omit, |
| 404 | spare := omit |
| 405 | }; |
| 406 | |
| 407 | private const octetstring c_NAS_defaultAPN := '00'O; |
| 408 | |
| 409 | private altstep as_s1ap_handle_auth() runs on ConnHdlr { |
| 410 | var PDU_NAS_EPS rx_nas; |
| 411 | [] S1AP.receive(tr_NAS_AuthReq) -> value rx_nas { |
| 412 | /* static XRES result as we fixed the HSS RAND value and always have the following |
| 413 | RAND: 20080c3818183b522614162c07601d0d |
| 414 | AUTN: f11b89a2a8be00001f9c526f3d75d44c |
| 415 | IK: 11329aae8e8d2941bb226b2061137c58 |
| 416 | CK: 740d62df9803eebde5120acf358433d0 |
| 417 | RES: 6a91970e838fd079 |
| 418 | SRES: e91e4777 |
| 419 | Kc: 3b0f999e42198874 |
| 420 | SQN: 32 |
| 421 | IND: 0 |
| 422 | */ |
| 423 | /* KASME: 95AFAD9A0D29AFAA079A9451DF7161D7EE4CBF2AF9387F766D058BB6B44B905D */ |
| 424 | const OCT16 ck := '740d62df9803eebde5120acf358433d0'O; |
| 425 | const OCT16 ik := '11329aae8e8d2941bb226b2061137c58'O; |
| 426 | const OCT16 autn := 'f11b89a2a8be00001f9c526f3d75d44c'O; |
| 427 | const OCT8 res := '6a91970e838fd079'O; |
| 428 | const OCT3 plmn_id := '00F110'O; |
| 429 | const OCT6 sqn := '000000000020'O; |
| 430 | const OCT6 ak := substr(autn, 0, 6) xor4b sqn; |
| 431 | var octetstring kasme := f_kdf_kasme(ck, ik, plmn_id, sqn, ak); |
| 432 | var S1APEM_Config cfg := { |
| 433 | set_nas_keys := { |
| 434 | k_nas_int := f_kdf_nas_int(1, kasme), |
| 435 | k_nas_enc := f_kdf_nas_enc(1, kasme) |
| 436 | } |
| 437 | }; |
| 438 | S1AP.send(cfg); |
| 439 | S1AP.send(ts_NAS_AuthResp(res)); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | private altstep as_s1ap_handle_sec_mode() runs on ConnHdlr { |
| 444 | var PDU_NAS_EPS rx_nas; |
| 445 | var NAS_SecurityAlgorithmsV alg := { |
| 446 | typeOfIntegrityProtection := '001'B, |
| 447 | spare1 := '0'B, |
| 448 | typeOfCiphering := '000'B, |
| 449 | spare2 := '0'B |
| 450 | }; |
| 451 | var NAS_KeySetIdentifierV kset_id := { |
| 452 | identifier := '000'B, |
| 453 | tSC := '0'B |
| 454 | }; |
| 455 | [] S1AP.receive(tr_NAS_SecModeCmd(alg, kset_id, ?)) { |
| 456 | S1AP.send(ts_NAS_SecModeCmpl); |
| 457 | } |
| 458 | } |
| 459 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 460 | /* Exepect AuthInfoReq (AIR) from HSS; respond with AuthInforAnswer (AIA) */ |
| 461 | private altstep as_DIA_AuthInfo() runs on ConnHdlr { |
| 462 | var PDU_DIAMETER rx_dia; |
| 463 | [] DIAMETER.receive(tr_DIA_AIR(g_pars.ue_pars.imsi)) -> value rx_dia { |
| 464 | var template (omit) AVP avp; |
| 465 | var octetstring sess_id; |
| 466 | var octetstring vplmn_id; |
| 467 | var hexstring imsi; |
| 468 | var template (value) AVP_list auth_info_content; |
| 469 | |
| 470 | /* retrieve input data */ |
| 471 | imsi := valueof(f_DIAMETER_get_imsi(rx_dia)); |
| 472 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 473 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 474 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_AAA_3GPP_Visited_PLMN_Id); |
| 475 | vplmn_id := valueof(avp.avp_data.avp_AAA_3GPP_Visited_PLMN_Id); |
| 476 | |
| 477 | /* compute tuple */ |
| 478 | auth_info_content := { ts_AVP_EutranVec(1, '20080c3818183b522614162c07601d0d'O, '6a91970e838fd079'O, 'f11b89a2a8be00001f9c526f3d75d44c'O, '95AFAD9A0D29AFAA079A9451DF7161D7EE4CBF2AF9387F766D058BB6B44B905D'O) }; |
| 479 | |
Vadim Yanitskiy | 2dba494 | 2021-12-11 15:46:30 +0300 | [diff] [blame] | 480 | DIAMETER.send(ts_DIA_AIA(auth_info_content, sess_id, |
| 481 | hbh_id := rx_dia.hop_by_hop_id, |
| 482 | ete_id := rx_dia.end_to_end_id)); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | /* Expect UpdateLocationReq (ULR); respond with UpdateLocationAnswer (ULA) */ |
| 487 | private altstep as_DIA_UpdLoc() runs on ConnHdlr { |
| 488 | var PDU_DIAMETER rx_dia; |
| 489 | [] DIAMETER.receive(tr_DIA_ULR(g_pars.ue_pars.imsi)) -> value rx_dia { |
| 490 | var template (omit) AVP avp; |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 491 | var hexstring imsi; |
| 492 | var template (value) AVP_list sub_data; |
| 493 | |
| 494 | /* retrieve input data */ |
| 495 | imsi := valueof(f_DIAMETER_get_imsi(rx_dia)); |
| 496 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 497 | |
| 498 | sub_data := { |
| 499 | ts_AVP_3GPP_SubscriberStatus(SERVICE_GRANTED), |
| 500 | ts_AVP_3GPP_SubscrRauTauTmr(30), |
| 501 | ts_AVP_3GPP_AMBR(1000, 2000), |
| 502 | ts_AVP_3GPP_ApnConfigProfile({ |
| 503 | ts_AVP_3GPP_ContextId(1), |
| 504 | ts_AVP_3GPP_AllApnConfigsIncl, |
| 505 | ts_AVP_3GPP_ApnConfig(1, IPv4, "*") |
| 506 | }) |
| 507 | }; |
| 508 | |
Vadim Yanitskiy | 0e8f516 | 2021-12-15 05:00:32 +0300 | [diff] [blame] | 509 | DIAMETER.send(ts_DIA_ULA(sub_data, avp.avp_data.avp_BASE_NONE_Session_Id, |
| 510 | hbh_id := rx_dia.hop_by_hop_id, |
| 511 | ete_id := rx_dia.end_to_end_id)); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 515 | private function f_TC_attach(ConnHdlrPars pars) runs on ConnHdlr { |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 516 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 517 | f_init_handler(pars); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 518 | var template (value) EPS_MobileIdentityV mi := ts_NAS_MobileId_IMSI(pars.ue_pars.imsi); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 519 | var template (value) PDU_NAS_EPS nas_esm, nas_emm; |
| 520 | /* |
| 521 | nas_esm := ts_NAS_ActDefEpsBearCtxReq(bearer_id := '0000'B, proc_tid := int2bit(1,8), |
| 522 | qos := c_NAS_defaultQoS, apn := c_NAS_defaultAPN, |
| 523 | addr_type := '000'B, addr_info := ''O); |
| 524 | */ |
| 525 | nas_esm := ts_NAS_PdnConnReq(bearer_id := '0000'B, proc_tid := int2bit(1,8), |
| 526 | pdn_type := NAS_PDN_T_IPv4, req_type := '001'B); |
| 527 | nas_emm := ts_NAS_AttachRequest(att_type := '000'B, kset_id := '000'B, mobile_id := mi, |
| 528 | ue_net_cap := c_NAS_defaultUeNetCap, |
| 529 | esm_enc := enc_PDU_NAS_EPS(valueof(nas_esm))); |
| 530 | var template (value) S1AP_PDU tx; |
| 531 | tx := ts_S1AP_InitialUE(p_eNB_value := 0, p_nasPdu := enc_PDU_NAS_EPS(valueof(nas_emm)), |
| 532 | p_tAI := ts_enb_S1AP_TAI(g_pars.enb_pars[g_pars.mme_idx]), |
| 533 | p_eUTRAN_CGI := ts_enb_S1AP_CGI(g_pars.enb_pars[g_pars.mme_idx]), |
| 534 | p_rrcCause := mo_Signalling); |
| 535 | S1AP.send(tx); |
| 536 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 537 | as_DIA_AuthInfo(); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 538 | as_s1ap_handle_auth(); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 539 | alt { |
| 540 | [] as_DIA_UpdLoc() { |
| 541 | as_s1ap_handle_sec_mode(); |
| 542 | } |
| 543 | [] as_s1ap_handle_sec_mode() { |
| 544 | as_DIA_UpdLoc(); |
| 545 | } |
| 546 | } |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 547 | |
| 548 | f_sleep(10.0); |
| 549 | } |
| 550 | testcase TC_s1ap_attach() runs on MTC_CT { |
| 551 | var charstring id := testcasename(); |
| 552 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 553 | f_init_diameter(id); |
| 554 | f_sleep(10.0); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 555 | f_init_s1ap(id, 4); |
| 556 | f_s1ap_setup(0); |
| 557 | |
| 558 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 559 | var ConnHdlr vc_conn; |
| 560 | vc_conn := f_start_handler_with_pars(refers(f_TC_attach), pars); |
| 561 | vc_conn.done; |
| 562 | } |
| 563 | |
| 564 | control { |
| 565 | execute( TC_s1ap_setup_wrong_plmn() ); |
| 566 | execute( TC_s1ap_setup_wrong_tac() ); |
| 567 | execute( TC_s1ap_setup() ); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 568 | execute( TC_s1ap_attach() ); |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | |
| 572 | } |