Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 1 | module S1AP_Emulation { |
| 2 | |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 3 | /* S1AP Emulation, runs on top of S1AP_CodecPort. It multiplexes/demultiplexes |
| 4 | * the individual subscribers by their UE association (MME_UE_S1AP_ID/ |
| 5 | * ENB_UE_S1AP_ID identifiers), so there can be separate TTCN-3 components |
| 6 | * handling each of them. |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 7 | * |
| 8 | * The S1AP_Emulation.main() function processes S1AP primitives from the S1AP |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 9 | * socket via the S1AP_CodecPort, and dispatches them to the per-subscriber |
| 10 | * components. |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 11 | * |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 12 | * For each new subscruber, the S1apOps.create_cb() is called. It can create |
| 13 | * or resolve a TTCN-3 component, and returns a component reference to which |
| 14 | * that subscriber traffic is routed/dispatched. |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 15 | * |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 16 | * If a pre-existing component wants to register to handle a future inbound UE |
| 17 | * association, it can do so by registering an "expect" with the expected |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 18 | * MME_UE_S1AP_ID/ENB_UE_S1AP_ID identifiers. It is also possible to register |
| 19 | * an expect for a specific procedureCode, in case the expected message is non |
| 20 | * UE related (unit-data). |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 21 | * |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 22 | * Inbound non-UE related S1AP messages (such as RESET, SETUP, OVERLOAD) are |
| 23 | * dispatched to the S1apOps.unitdata_cb() callback, which is registered with |
| 24 | * an argument to the main() function below. |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 25 | * |
| 26 | * (C) 2019 by Harald Welte <laforge@gnumonks.org> |
| 27 | * All rights reserved. |
| 28 | * |
| 29 | * Released under the terms of GNU General Public License, Version 2 or |
| 30 | * (at your option) any later version. |
| 31 | * |
| 32 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 33 | */ |
| 34 | |
| 35 | import from S1AP_CodecPort all; |
| 36 | import from S1AP_CodecPort_CtrlFunct all; |
| 37 | import from S1AP_Types all; |
| 38 | import from S1AP_Constants all; |
| 39 | import from S1AP_PDU_Contents all; |
| 40 | import from S1AP_PDU_Descriptions all; |
| 41 | import from S1AP_IEs all; |
| 42 | import from S1AP_Templates all; |
| 43 | |
| 44 | import from NAS_EPS_Types all; |
| 45 | import from NAS_Templates all; |
| 46 | |
| 47 | import from LTE_CryptoFunctions all; |
| 48 | |
| 49 | import from General_Types all; |
| 50 | import from Osmocom_Types all; |
| 51 | import from IPL4asp_Types all; |
| 52 | import from DNS_Helpers all; |
| 53 | |
| 54 | |
| 55 | type component S1AP_ConnHdlr { |
| 56 | port S1AP_Conn_PT S1AP; |
| 57 | /* procedure based port to register for incoming connections */ |
| 58 | port S1APEM_PROC_PT S1AP_PROC; |
| 59 | } |
| 60 | |
| 61 | /* port between individual per-connection components and this dispatcher */ |
| 62 | type port S1AP_Conn_PT message { |
| 63 | inout S1AP_PDU, PDU_NAS_EPS, S1APEM_Config; |
| 64 | } with { extension "internal" }; |
| 65 | |
| 66 | type record NAS_Keys { |
| 67 | octetstring k_nas_int, |
| 68 | octetstring k_nas_enc |
| 69 | }; |
| 70 | type union S1APEM_Config { |
| 71 | NAS_Keys set_nas_keys |
| 72 | }; |
| 73 | |
| 74 | type enumerated S1APEM_EventUpDown { |
| 75 | S1APEM_EVENT_DOWN, |
| 76 | S1APEM_EVENT_UP |
| 77 | } |
| 78 | |
| 79 | /* an event indicating us whether or not a connection is physically up or down, |
| 80 | * and whether we have received an ID_ACK */ |
| 81 | type union S1APEM_Event { |
| 82 | S1APEM_EventUpDown up_down |
| 83 | } |
| 84 | |
| 85 | /* global test port e.g. for non-imsi/conn specific messages */ |
| 86 | type port S1AP_PT message { |
| 87 | inout S1AP_PDU, S1APEM_Event; |
| 88 | } with { extension "internal" }; |
| 89 | |
| 90 | |
| 91 | /* represents a single S1AP Association */ |
| 92 | type record AssociationData { |
| 93 | S1AP_ConnHdlr comp_ref, /* component handling this UE connection */ |
| 94 | uint24_t enb_ue_s1ap_id optional, /* eNB side S1AP ID */ |
| 95 | uint32_t mme_ue_s1ap_id optional, /* MME side S1AP ID */ |
| 96 | EUTRAN_CGI cgi optional, |
| 97 | TAI tai optional, |
| 98 | NAS_UE_State nus |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | type component S1AP_Emulation_CT { |
| 102 | /* Port facing to the UDP SUT */ |
| 103 | port S1AP_CODEC_PT S1AP; |
| 104 | /* All S1AP_ConnHdlr S1AP ports connect here |
| 105 | * S1AP_Emulation_CT.main needs to figure out what messages |
| 106 | * to send where with CLIENT.send() to vc_conn */ |
| 107 | port S1AP_Conn_PT S1AP_CLIENT; |
| 108 | /* currently tracked connections */ |
| 109 | var AssociationData S1apAssociationTable[16]; |
Philipp Maier | f935f0c | 2023-07-24 17:58:24 +0200 | [diff] [blame] | 110 | /* pending expected S1AP Association (UE oriented) */ |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 111 | var ExpectData S1apExpectTable[8]; |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 112 | /* pending expected S1AP PDU */ |
| 113 | var ExpectDataProc S1apExpectTableProc[8]; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 114 | /* procedure based port to register for incoming connections */ |
| 115 | port S1APEM_PROC_PT S1AP_PROC; |
| 116 | /* test port for unit data messages */ |
| 117 | port S1AP_PT S1AP_UNIT; |
| 118 | |
| 119 | var S1AP_conn_parameters g_pars; |
| 120 | var charstring g_s1ap_id; |
| 121 | var integer g_s1ap_conn_id := -1; |
| 122 | } |
| 123 | |
| 124 | type function S1APCreateCallback(S1AP_PDU msg, template (omit) MME_UE_S1AP_ID mme_id, |
| 125 | template (omit) ENB_UE_S1AP_ID enb_id, charstring id) |
| 126 | runs on S1AP_Emulation_CT return S1AP_ConnHdlr; |
| 127 | |
| 128 | type function S1APUnitdataCallback(S1AP_PDU msg) |
| 129 | runs on S1AP_Emulation_CT return template S1AP_PDU; |
| 130 | |
| 131 | type record S1APOps { |
| 132 | S1APCreateCallback create_cb, |
| 133 | S1APUnitdataCallback unitdata_cb |
| 134 | } |
| 135 | |
| 136 | type record S1AP_conn_parameters { |
| 137 | HostName remote_ip, |
| 138 | PortNumber remote_sctp_port, |
| 139 | HostName local_ip, |
| 140 | PortNumber local_sctp_port, |
| 141 | NAS_Role role |
| 142 | } |
| 143 | |
| 144 | function tr_S1AP_RecvFrom_R(template S1AP_PDU msg) |
| 145 | runs on S1AP_Emulation_CT return template S1AP_RecvFrom { |
| 146 | var template S1AP_RecvFrom mrf := { |
| 147 | connId := g_s1ap_conn_id, |
| 148 | remName := ?, |
| 149 | remPort := ?, |
| 150 | locName := ?, |
| 151 | locPort := ?, |
| 152 | msg := msg |
| 153 | } |
| 154 | return mrf; |
| 155 | } |
| 156 | |
| 157 | private function f_s1ap_ids_known(template (omit) MME_UE_S1AP_ID mme_id, |
| 158 | template (omit) ENB_UE_S1AP_ID enb_id) |
| 159 | runs on S1AP_Emulation_CT return boolean { |
| 160 | var integer i; |
| 161 | log("f_s1ap_ids_known(",mme_id,", ",enb_id,")"); |
| 162 | for (i := 0; i < sizeof(S1apAssociationTable); i := i+1) { |
| 163 | log("tbl[",i,"]: mme=", S1apAssociationTable[i].mme_ue_s1ap_id, |
| 164 | ", enb=", S1apAssociationTable[i].enb_ue_s1ap_id); |
| 165 | /* skip empty records */ |
| 166 | if (S1apAssociationTable[i].mme_ue_s1ap_id == omit and |
| 167 | S1apAssociationTable[i].enb_ue_s1ap_id == omit) { |
| 168 | log("skipping empty ", i); |
| 169 | continue; |
| 170 | } |
| 171 | if (S1apAssociationTable[i].mme_ue_s1ap_id == omit) { |
| 172 | log("entry ", i, " has no MME ID yet (enb=", S1apAssociationTable[i].enb_ue_s1ap_id); |
| 173 | /* Table doesn't yet know the MME side ID, let's look-up only |
| 174 | * based on the eNB side ID */ |
| 175 | if (match(S1apAssociationTable[i].enb_ue_s1ap_id, enb_id)) { |
| 176 | /* update table with MME side ID */ |
| 177 | S1apAssociationTable[i].mme_ue_s1ap_id := valueof(mme_id); |
| 178 | return true; |
| 179 | } |
| 180 | } else if (match(S1apAssociationTable[i].enb_ue_s1ap_id, enb_id) and |
| 181 | match(S1apAssociationTable[i].mme_ue_s1ap_id, mme_id)) { |
| 182 | return true; |
| 183 | } |
| 184 | } |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | private function f_comp_known(S1AP_ConnHdlr client) |
| 189 | runs on S1AP_Emulation_CT return boolean { |
| 190 | var integer i; |
| 191 | for (i := 0; i < sizeof(S1apAssociationTable); i := i+1) { |
| 192 | if (S1apAssociationTable[i].comp_ref == client) { |
| 193 | return true; |
| 194 | } |
| 195 | } |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | private function f_assoc_id_by_s1ap_ids(template (omit) MME_UE_S1AP_ID mme_id, |
| 200 | template (omit) ENB_UE_S1AP_ID enb_id) |
| 201 | runs on S1AP_Emulation_CT return integer { |
| 202 | var integer i; |
| 203 | for (i := 0; i < sizeof(S1apAssociationTable); i := i+1) { |
| 204 | if (match(S1apAssociationTable[i].enb_ue_s1ap_id, enb_id)) { |
| 205 | if (istemplatekind(mme_id, "omit")) { |
| 206 | return i; |
| 207 | } else { |
| 208 | if (match(S1apAssociationTable[i].mme_ue_s1ap_id, mme_id)) { |
| 209 | return i; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | setverdict(fail, "S1AP Association Table not found by ENB-ID=", enb_id, " MME-ID=", mme_id); |
| 215 | mtc.stop; |
| 216 | } |
| 217 | |
| 218 | private function f_assoc_id_by_comp(S1AP_ConnHdlr client) |
| 219 | runs on S1AP_Emulation_CT return integer { |
| 220 | var integer i; |
| 221 | for (i := 0; i < sizeof(S1apAssociationTable); i := i+1) { |
| 222 | if (S1apAssociationTable[i].comp_ref == client) { |
| 223 | return i; |
| 224 | } |
| 225 | } |
| 226 | setverdict(fail, "S1AP Association Table not found by component ", client); |
| 227 | mtc.stop; |
| 228 | } |
| 229 | |
| 230 | private function f_assoc_by_comp(S1AP_ConnHdlr client) |
| 231 | runs on S1AP_Emulation_CT return AssociationData { |
| 232 | var integer i := f_assoc_id_by_comp(client); |
| 233 | return S1apAssociationTable[i]; |
| 234 | } |
| 235 | |
| 236 | private function f_s1ap_id_table_add(S1AP_ConnHdlr comp_ref, |
| 237 | template (omit) MME_UE_S1AP_ID mme_id, ENB_UE_S1AP_ID enb_id) |
| 238 | runs on S1AP_Emulation_CT return integer { |
| 239 | var integer i; |
| 240 | for (i := 0; i < sizeof(S1apAssociationTable); i := i+1) { |
| 241 | if (not isvalue(S1apAssociationTable[i].enb_ue_s1ap_id)) { |
| 242 | S1apAssociationTable[i].enb_ue_s1ap_id := enb_id; |
| 243 | if (istemplatekind(mme_id, "omit")) { |
| 244 | S1apAssociationTable[i].mme_ue_s1ap_id := omit; |
| 245 | } else { |
| 246 | S1apAssociationTable[i].mme_ue_s1ap_id := valueof(mme_id); |
| 247 | } |
| 248 | S1apAssociationTable[i].comp_ref := comp_ref; |
| 249 | return i; |
| 250 | } |
| 251 | } |
| 252 | testcase.stop("S1AP Association Table full!"); |
| 253 | return -1; |
| 254 | } |
| 255 | |
| 256 | private function f_s1ap_id_table_del(S1AP_ConnHdlr comp_ref, ENB_UE_S1AP_ID enb_id) |
| 257 | runs on S1AP_Emulation_CT { |
| 258 | var integer i; |
| 259 | for (i := 0; i < sizeof(S1apAssociationTable); i := i+1) { |
| 260 | if (S1apAssociationTable[i].comp_ref == comp_ref and |
Philipp Maier | 0ce67ab | 2023-07-07 13:02:11 +0200 | [diff] [blame] | 261 | S1apAssociationTable[i].enb_ue_s1ap_id == enb_id) { |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 262 | S1apAssociationTable[i].enb_ue_s1ap_id := omit; |
| 263 | S1apAssociationTable[i].mme_ue_s1ap_id := omit; |
| 264 | S1apAssociationTable[i].comp_ref := null; |
| 265 | return; |
| 266 | } |
| 267 | } |
| 268 | setverdict(fail, "S1AP Association Table: Couldn't find to-be-deleted entry!"); |
| 269 | mtc.stop; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | private function f_s1ap_id_table_init() |
| 274 | runs on S1AP_Emulation_CT { |
| 275 | for (var integer i := 0; i < sizeof(S1apAssociationTable); i := i+1) { |
| 276 | S1apAssociationTable[i].mme_ue_s1ap_id := omit; |
| 277 | S1apAssociationTable[i].enb_ue_s1ap_id := omit; |
| 278 | S1apAssociationTable[i].cgi := omit; |
| 279 | S1apAssociationTable[i].tai := omit; |
| 280 | S1apAssociationTable[i].nus := valueof(t_NAS_UE_State(g_pars.role)); |
Philipp Maier | eb930fd | 2023-07-24 17:59:40 +0200 | [diff] [blame] | 281 | S1apAssociationTable[i].comp_ref := null; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | private template (value) SctpTuple ts_SCTP(template (omit) integer ppid := 18) := { |
| 286 | sinfo_stream := omit, |
| 287 | sinfo_ppid := ppid, |
| 288 | remSocks := omit, |
| 289 | assocId := omit |
| 290 | }; |
| 291 | |
| 292 | private template PortEvent tr_SctpAssocChange := { |
| 293 | sctpEvent := { |
| 294 | sctpAssocChange := ? |
| 295 | } |
| 296 | } |
| 297 | private template PortEvent tr_SctpPeerAddrChange := { |
| 298 | sctpEvent := { |
| 299 | sctpPeerAddrChange := ? |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | private function f_s1ap_xceive(template (value) S1AP_PDU tx, |
| 304 | template S1AP_PDU rx_t := ?) |
| 305 | runs on S1AP_Emulation_CT return S1AP_PDU { |
| 306 | timer T := 10.0; |
| 307 | var S1AP_RecvFrom mrf; |
| 308 | |
| 309 | S1AP.send(t_S1AP_Send(g_s1ap_conn_id, tx)); |
| 310 | alt { |
| 311 | [] S1AP.receive(tr_S1AP_RecvFrom_R(rx_t)) -> value mrf { } |
| 312 | [] S1AP.receive(tr_SctpAssocChange) { repeat; } |
| 313 | [] S1AP.receive(tr_SctpPeerAddrChange) { repeat; } |
| 314 | [] T.timeout { |
| 315 | setverdict(fail, "Timeout waiting for ", rx_t); |
| 316 | mtc.stop; |
| 317 | } |
| 318 | } |
| 319 | return mrf.msg; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | private function f_nas_try_decaps(PDU_NAS_EPS nas) return PDU_NAS_EPS |
| 324 | { |
| 325 | var PDU_NAS_EPS_SecurityProtectedNASMessage secp_nas; |
| 326 | if (not match(nas, tr_NAS_EMM_SecurityProtected)) { |
| 327 | return nas; |
| 328 | } |
| 329 | secp_nas := nas.ePS_messages.ePS_MobilityManagement.pDU_NAS_EPS_SecurityProtectedNASMessage; |
| 330 | select (secp_nas.securityHeaderType) { |
| 331 | case ('0011'B) { |
| 332 | var octetstring knas_int := '530ce32318f26264eab26bc116870b86'O; |
| 333 | var octetstring data_with_seq := int2oct(secp_nas.sequenceNumber, 1) & secp_nas.nAS_Message; |
| 334 | var OCT4 exp_mac := f_snow_3g_f9(knas_int, secp_nas.sequenceNumber, 0, |
| 335 | is_downlink:=true, data:=data_with_seq); |
| 336 | if (exp_mac != secp_nas.messageAuthenticationCode) { |
| 337 | setverdict(fail, "Received NAS MAC ", secp_nas.messageAuthenticationCode, |
| 338 | " doesn't match expected MAC ", exp_mac, ": ", nas); |
| 339 | mtc.stop; |
| 340 | } |
| 341 | return dec_PDU_NAS_EPS(secp_nas.nAS_Message); |
| 342 | } |
| 343 | case else { |
| 344 | setverdict(fail, "Implement SecHdrType for ", secp_nas); |
| 345 | mtc.stop; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | */ |
| 350 | |
Philipp Maier | bb8f05d | 2023-07-07 14:16:08 +0200 | [diff] [blame] | 351 | function handle_S1AP_UeContextReleaseCmd(template (present) S1AP_PDU rel_cmd) runs on S1AP_Emulation_CT { |
| 352 | if (ispresent(rel_cmd.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair)) { |
| 353 | var template MME_UE_S1AP_ID mme_ue_id; |
| 354 | var template ENB_UE_S1AP_ID enb_ue_id; |
| 355 | var integer assoc_id; |
| 356 | var S1AP_ConnHdlr vc_conn |
| 357 | |
| 358 | mme_ue_id := rel_cmd.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.mME_UE_S1AP_ID; |
| 359 | enb_ue_id := rel_cmd.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.eNB_UE_S1AP_ID; |
| 360 | |
| 361 | assoc_id := f_assoc_id_by_s1ap_ids(mme_ue_id, enb_ue_id); |
| 362 | vc_conn := S1apAssociationTable[assoc_id].comp_ref; |
| 363 | |
| 364 | f_s1ap_id_table_del(vc_conn, valueof(enb_ue_id)); |
| 365 | } else { |
| 366 | /* TODO: The UE CONTEXT RELEASE COMMAND (see also: 3GPP TS 36.413, section 9.1.4.6), may identify the |
| 367 | * context by either an uE_S1AP_ID_pair (MME_UE_S1AP_ID and ENB_UE_S1AP_ID) or an MME_UE_S1AP_ID alone. |
| 368 | * The latter case is not implemented here yet. */ |
| 369 | setverdict(fail, "complete implementation of UeContextReleaseCmd handling"); |
| 370 | mtc.stop; |
| 371 | } |
| 372 | } |
| 373 | |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 374 | private function SendToS1apExpectTableProc(S1AP_PDU msg) runs on S1AP_Emulation_CT { |
| 375 | var integer procedureCode; |
| 376 | var S1AP_ConnHdlr vc_conn; |
| 377 | |
| 378 | if (ispresent(msg.initiatingMessage.procedureCode)) { |
| 379 | procedureCode := msg.initiatingMessage.procedureCode; |
| 380 | } else if (ispresent(msg.unsuccessfulOutcome.procedureCode)) { |
| 381 | procedureCode := msg.unsuccessfulOutcome.procedureCode; |
| 382 | } else if (ispresent(msg.successfulOutcome.procedureCode)) { |
| 383 | procedureCode := msg.successfulOutcome.procedureCode; |
| 384 | } else { |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | for (var integer i := 0; i < sizeof(S1apExpectTableProc); i := i+1) { |
| 389 | if (S1apExpectTableProc[i].procedureCode == procedureCode) { |
| 390 | vc_conn := S1apExpectTableProc[i].vc_conn; |
| 391 | if (vc_conn != null) { |
| 392 | S1AP_CLIENT.send(msg) to vc_conn; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return; |
| 398 | } |
| 399 | |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 400 | function main(S1APOps ops, S1AP_conn_parameters p, charstring id) runs on S1AP_Emulation_CT { |
| 401 | var Result res; |
| 402 | g_pars := p; |
| 403 | g_s1ap_id := id; |
| 404 | f_s1ap_id_table_init(); |
| 405 | f_expect_table_init(); |
| 406 | |
| 407 | map(self:S1AP, system:S1AP_CODEC_PT); |
| 408 | if (p.remote_sctp_port == -1) { |
| 409 | res := S1AP_CodecPort_CtrlFunct.f_IPL4_listen(S1AP, p.local_ip, p.local_sctp_port, { sctp := valueof(ts_SCTP) }); |
| 410 | } else { |
| 411 | res := S1AP_CodecPort_CtrlFunct.f_IPL4_connect(S1AP, p.remote_ip, p.remote_sctp_port, |
| 412 | p.local_ip, p.local_sctp_port, -1, { sctp := valueof(ts_SCTP) }); |
| 413 | } |
| 414 | if (not ispresent(res.connId)) { |
| 415 | setverdict(fail, "Could not connect S1AP socket, check your configuration"); |
| 416 | mtc.stop; |
| 417 | } |
| 418 | g_s1ap_conn_id := res.connId; |
| 419 | |
| 420 | /* notify user about SCTP establishment */ |
| 421 | if (p.remote_sctp_port != -1) { |
| 422 | S1AP_UNIT.send(S1APEM_Event:{up_down:=S1APEM_EVENT_UP}) |
| 423 | } |
| 424 | |
| 425 | while (true) { |
| 426 | var S1AP_ConnHdlr vc_conn; |
| 427 | var PDU_NAS_EPS nas; |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 428 | var MME_UE_S1AP_ID mme_id; |
| 429 | var ENB_UE_S1AP_ID enb_id; |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 430 | var integer procedureCode; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 431 | var S1AP_RecvFrom mrf; |
| 432 | var S1AP_PDU msg; |
| 433 | var S1APEM_Config s1cfg; |
| 434 | var charstring vlr_name, mme_name; |
| 435 | var integer ai; |
| 436 | |
| 437 | alt { |
| 438 | /* Configuration primitive from client */ |
| 439 | [] S1AP_CLIENT.receive(S1APEM_Config:{set_nas_keys:=?}) -> value s1cfg sender vc_conn { |
| 440 | var integer assoc_id := f_assoc_id_by_comp(vc_conn); |
| 441 | S1apAssociationTable[assoc_id].nus.k_nas_int := s1cfg.set_nas_keys.k_nas_int; |
| 442 | S1apAssociationTable[assoc_id].nus.k_nas_enc := s1cfg.set_nas_keys.k_nas_enc; |
| 443 | } |
| 444 | /* S1AP from client: InitialUE */ |
| 445 | [] S1AP_CLIENT.receive(tr_S1AP_InitialUE) -> value msg sender vc_conn { |
| 446 | /* create a table entry about this connection */ |
| 447 | ai := f_s1ap_id_table_add(vc_conn, omit, valueof(f_S1AP_get_ENB_UE_S1AP_ID(msg))); |
| 448 | /* Store CGI + TAI so we can use it for generating UlNasTransport from NAS */ |
| 449 | S1apAssociationTable[ai].tai := msg.initiatingMessage.value_.InitialUEMessage.protocolIEs[2].value_.TAI; |
| 450 | S1apAssociationTable[ai].cgi := msg.initiatingMessage.value_.InitialUEMessage.protocolIEs[3].value_.EUTRAN_CGI; |
| 451 | /* Pass message through */ |
| 452 | S1AP.send(t_S1AP_Send(g_s1ap_conn_id, msg)); |
| 453 | } |
| 454 | /* NAS from client: Wrap in S1AP Uplink NAS Transport */ |
| 455 | [] S1AP_CLIENT.receive(PDU_NAS_EPS:?) -> value nas sender vc_conn { |
| 456 | var integer assoc_id := f_assoc_id_by_comp(vc_conn); |
| 457 | var AssociationData ad := S1apAssociationTable[assoc_id]; |
| 458 | nas := f_nas_encaps(S1apAssociationTable[assoc_id].nus, nas, new_ctx := false); |
| 459 | var octetstring nas_enc := enc_PDU_NAS_EPS(nas); |
| 460 | S1AP.send(t_S1AP_Send(g_s1ap_conn_id, |
| 461 | ts_S1AP_UlNasTransport(ad.mme_ue_s1ap_id, |
| 462 | ad.enb_ue_s1ap_id, |
| 463 | nas_enc, ad.cgi, ad.tai))); |
| 464 | } |
| 465 | /* S1AP from client: pass on transparently */ |
| 466 | [] S1AP_CLIENT.receive(S1AP_PDU:?) -> value msg sender vc_conn { |
| 467 | /* Pass message through */ |
| 468 | /* FIXME: validate S1AP_IDs ? */ |
| 469 | S1AP.send(t_S1AP_Send(g_s1ap_conn_id, msg)); |
| 470 | } |
| 471 | |
| 472 | /* non-UE related S1AP: pass through unmodified/unverified */ |
| 473 | [] S1AP_UNIT.receive(S1AP_PDU:?) -> value msg sender vc_conn { |
| 474 | /* Pass message through */ |
| 475 | S1AP.send(t_S1AP_Send(g_s1ap_conn_id, msg)); |
| 476 | } |
| 477 | |
| 478 | /* S1AP received from peer (MME) */ |
| 479 | [] S1AP.receive(tr_S1AP_RecvFrom_R(?)) -> value mrf { |
| 480 | if (match(mrf.msg, tr_S1AP_nonUErelated)) { |
| 481 | /* non-UE-related S1AP message */ |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 482 | SendToS1apExpectTableProc(mrf.msg); |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 483 | var template S1AP_PDU resp := ops.unitdata_cb.apply(mrf.msg); |
| 484 | if (isvalue(resp)) { |
| 485 | S1AP.send(t_S1AP_Send(g_s1ap_conn_id, valueof(resp))); |
| 486 | } |
| 487 | } else if (match(mrf.msg, tr_S1AP_UeContextReleaseCmd)) { |
Philipp Maier | bb8f05d | 2023-07-07 14:16:08 +0200 | [diff] [blame] | 488 | handle_S1AP_UeContextReleaseCmd(mrf.msg); |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 489 | } else { |
| 490 | /* Ue-related S1AP message */ |
| 491 | /* obtain MME + ENB UE S1AP ID */ |
| 492 | var template (omit) MME_UE_S1AP_ID mme_ue_id := f_S1AP_get_MME_UE_S1AP_ID(mrf.msg); |
| 493 | var template (omit) ENB_UE_S1AP_ID enb_ue_id := f_S1AP_get_ENB_UE_S1AP_ID(mrf.msg); |
| 494 | /* check if those IDs are known in our table */ |
| 495 | if (f_s1ap_ids_known(mme_ue_id, enb_ue_id)) { |
| 496 | /* if yes, dispatch to the ConnHdlr for this Ue-Connection */ |
| 497 | var template (omit) octetstring nas_enc; |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 498 | var integer assoc_id := f_assoc_id_by_s1ap_ids(mme_ue_id, enb_ue_id); |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 499 | vc_conn := S1apAssociationTable[assoc_id].comp_ref; |
| 500 | nas_enc := f_S1AP_get_NAS_PDU(mrf.msg); |
| 501 | if (isvalue(nas_enc)) { |
| 502 | nas := dec_PDU_NAS_EPS(valueof(nas_enc)); |
| 503 | if (match(nas, tr_NAS_EMM_SecurityProtected)) { |
| 504 | nas := f_nas_try_decaps(S1apAssociationTable[assoc_id].nus, nas); |
| 505 | } |
Pau Espin Pedrol | 2edec46 | 2023-12-15 19:16:02 +0100 | [diff] [blame] | 506 | /* DL/UlNasTransport are not interesting, don't send them */ |
| 507 | if (not match(mrf.msg, (tr_S1AP_DlNasTransport, tr_S1AP_UlNasTransport))) { |
| 508 | /* send raw S1AP */ |
| 509 | S1AP_CLIENT.send(mrf.msg) to vc_conn; |
| 510 | } |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 511 | /* send decoded NAS */ |
| 512 | S1AP_CLIENT.send(nas) to vc_conn; |
| 513 | } else { |
| 514 | /* send raw S1AP */ |
| 515 | S1AP_CLIENT.send(mrf.msg) to vc_conn; |
| 516 | } |
| 517 | } else { |
| 518 | /* if not, call create_cb so it can create new ConnHdlr */ |
| 519 | vc_conn := ops.create_cb.apply(mrf.msg, mme_ue_id, enb_ue_id, id); |
| 520 | f_s1ap_id_table_add(vc_conn, mme_ue_id, valueof(enb_ue_id)); |
| 521 | S1AP_CLIENT.send(mrf.msg) to vc_conn; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | [] S1AP.receive(tr_SctpAssocChange) { } |
| 526 | [] S1AP.receive(tr_SctpPeerAddrChange) { } |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 527 | [] S1AP_PROC.getcall(S1APEM_register:{?,?,?}) -> param(mme_id, enb_id, vc_conn) { |
| 528 | f_create_expect(mme_id, enb_id, vc_conn); |
| 529 | S1AP_PROC.reply(S1APEM_register:{mme_id, enb_id, vc_conn}) to vc_conn; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 530 | } |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 531 | [] S1AP_PROC.getcall(S1APEM_register_proc:{?,?}) -> param(procedureCode, vc_conn) { |
| 532 | f_create_expect_proc(procedureCode, vc_conn); |
| 533 | S1AP_PROC.reply(S1APEM_register_proc:{procedureCode, vc_conn}) to vc_conn; |
| 534 | } |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /* "Expect" Handling */ |
| 541 | |
| 542 | type record ExpectData { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 543 | MME_UE_S1AP_ID mme_id optional, |
| 544 | ENB_UE_S1AP_ID enb_id optional, |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 545 | S1AP_ConnHdlr vc_conn |
| 546 | } |
| 547 | |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 548 | /* represents a single S1AP PDU that we expect. When a matching PDU is seen, it is forwarded to the registered |
| 549 | * component */ |
| 550 | type record ExpectDataProc { |
| 551 | integer procedureCode optional, |
| 552 | S1AP_ConnHdlr vc_conn /* component handling this UE connection */ |
| 553 | }; |
| 554 | |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 555 | signature S1APEM_register(in MME_UE_S1AP_ID mme_id, in ENB_UE_S1AP_ID enb_id, in S1AP_ConnHdlr hdlr); |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 556 | signature S1APEM_register_proc(in integer procedureCode, in S1AP_ConnHdlr hdlr); |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 557 | |
| 558 | type port S1APEM_PROC_PT procedure { |
| 559 | inout S1APEM_register; |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 560 | inout S1APEM_register_proc; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 561 | } with { extension "internal" }; |
| 562 | |
Oliver Smith | 23e192e | 2023-02-13 15:00:46 +0100 | [diff] [blame] | 563 | /* Function that can be used as create_cb and will use the expect table */ |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 564 | function ExpectedCreateCallback(S1AP_PDU msg, |
| 565 | template (omit) MME_UE_S1AP_ID mme_id, |
| 566 | template (omit) ENB_UE_S1AP_ID enb_id, charstring id) |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 567 | runs on S1AP_Emulation_CT return S1AP_ConnHdlr { |
| 568 | var S1AP_ConnHdlr ret := null; |
| 569 | var integer i; |
| 570 | |
| 571 | for (i := 0; i < sizeof(S1apExpectTable); i := i+1) { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 572 | if (not ispresent(S1apExpectTable[i].mme_id) and not ispresent(S1apExpectTable[i].enb_id)) { |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 573 | continue; |
| 574 | } |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 575 | |
| 576 | if (valueof(mme_id) == S1apExpectTable[i].mme_id and valueof(enb_id) == S1apExpectTable[i].enb_id) { |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 577 | ret := S1apExpectTable[i].vc_conn; |
| 578 | /* Release this entry */ |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 579 | S1apExpectTable[i].mme_id := omit; |
| 580 | S1apExpectTable[i].enb_id := omit; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 581 | S1apExpectTable[i].vc_conn := null; |
| 582 | log("Found Expect[", i, "] for ", msg, " handled at ", ret); |
| 583 | return ret; |
| 584 | } |
| 585 | } |
| 586 | setverdict(fail, "Couldn't find Expect for ", msg); |
| 587 | mtc.stop; |
| 588 | } |
| 589 | |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 590 | private function f_create_expect(template (omit) MME_UE_S1AP_ID mme_id, |
| 591 | template (omit) ENB_UE_S1AP_ID enb_id, |
| 592 | S1AP_ConnHdlr hdlr) |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 593 | runs on S1AP_Emulation_CT { |
| 594 | var integer i; |
| 595 | |
| 596 | /* Check an entry like this is not already presnt */ |
| 597 | for (i := 0; i < sizeof(S1apExpectTable); i := i+1) { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 598 | if (not ispresent(S1apExpectTable[i].mme_id) and not ispresent(S1apExpectTable[i].enb_id)) { |
| 599 | continue; |
| 600 | } |
| 601 | if (valueof(mme_id) == S1apExpectTable[i].mme_id and valueof(enb_id) == S1apExpectTable[i].enb_id) { |
| 602 | setverdict(fail, "UE MME id / UE ENB id pair already present", mme_id, enb_id); |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 603 | mtc.stop; |
| 604 | } |
| 605 | } |
| 606 | for (i := 0; i < sizeof(S1apExpectTable); i := i+1) { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 607 | if (not ispresent(S1apExpectTable[i].mme_id) and not ispresent(S1apExpectTable[i].enb_id)) { |
| 608 | S1apExpectTable[i].mme_id := valueof(mme_id); |
| 609 | S1apExpectTable[i].enb_id := valueof(enb_id); |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 610 | S1apExpectTable[i].vc_conn := hdlr; |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 611 | log("Created Expect[", i, "] for UE MME id:", mme_id, ", UE ENB id:", enb_id, " to be handled at ", hdlr); |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 612 | return; |
| 613 | } |
| 614 | } |
| 615 | testcase.stop("No space left in S1apExpectTable") |
| 616 | } |
| 617 | |
| 618 | /* client/conn_hdlr side function to use procedure port to create expect in emulation */ |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 619 | function f_create_s1ap_expect(template (omit) MME_UE_S1AP_ID mme_id, |
| 620 | template (omit) ENB_UE_S1AP_ID enb_id) runs on S1AP_ConnHdlr { |
| 621 | S1AP_PROC.call(S1APEM_register:{mme_id, enb_id, self}) { |
| 622 | [] S1AP_PROC.getreply(S1APEM_register:{?,?,?}) {}; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 626 | private function f_create_expect_proc(integer procedureCode, S1AP_ConnHdlr hdlr) runs on S1AP_Emulation_CT { |
| 627 | var integer i; |
| 628 | |
| 629 | /* Check an entry like this is not already presnt */ |
| 630 | for (i := 0; i < sizeof(S1apExpectTableProc); i := i+1) { |
| 631 | if (S1apExpectTableProc[i].vc_conn == null) { |
| 632 | continue; |
| 633 | } |
| 634 | if (S1apExpectTableProc[i].procedureCode == procedureCode) { |
| 635 | setverdict(fail, "procedureCode ", procedureCode, " already present"); |
| 636 | mtc.stop; |
| 637 | } |
| 638 | } |
| 639 | for (i := 0; i < sizeof(S1apExpectTableProc); i := i+1) { |
| 640 | if (S1apExpectTableProc[i].vc_conn == null) { |
| 641 | S1apExpectTableProc[i].procedureCode := procedureCode; |
| 642 | S1apExpectTableProc[i].vc_conn := hdlr; |
| 643 | log("Created Expect[", i, "] for PDU:", procedureCode, " to be handled at ", hdlr); |
| 644 | return; |
| 645 | } |
| 646 | } |
| 647 | testcase.stop("No space left in S1apExpectTableProc") |
| 648 | } |
| 649 | |
| 650 | /* client/conn_hdlr side function to use procedure port to create expect (PDU) in emulation */ |
| 651 | function f_create_s1ap_expect_proc(integer procedureCode, S1AP_ConnHdlr hdlr) runs on S1AP_ConnHdlr |
| 652 | { |
| 653 | S1AP_PROC.call(S1APEM_register_proc:{procedureCode, self}) { |
| 654 | [] S1AP_PROC.getreply(S1APEM_register_proc:{?,?}) {}; |
| 655 | } |
| 656 | |
| 657 | log(procedureCode); |
| 658 | } |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 659 | |
| 660 | private function f_expect_table_init() |
| 661 | runs on S1AP_Emulation_CT { |
| 662 | var integer i; |
| 663 | for (i := 0; i < sizeof(S1apExpectTable); i := i + 1) { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 664 | S1apExpectTable[i].mme_id := omit; |
| 665 | S1apExpectTable[i].enb_id := omit; |
| 666 | S1apExpectTable[i].vc_conn := null; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 667 | } |
Philipp Maier | fc7ada2 | 2023-07-24 11:32:12 +0200 | [diff] [blame] | 668 | |
| 669 | for (i := 0; i < sizeof(S1apExpectTableProc); i := i + 1) { |
| 670 | S1apExpectTableProc[i].procedureCode := omit; |
| 671 | S1apExpectTableProc[i].vc_conn := null; |
| 672 | } |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | function DummyUnitdataCallback(S1AP_PDU msg) |
| 676 | runs on S1AP_Emulation_CT return template S1AP_PDU { |
| 677 | log("Ignoring S1AP ", msg); |
| 678 | return omit; |
| 679 | } |
| 680 | |
| 681 | |
| 682 | function f_S1AP_get_ENB_UE_S1AP_ID(S1AP_PDU s1ap) return template (omit) ENB_UE_S1AP_ID |
| 683 | { |
| 684 | if (ischosen(s1ap.initiatingMessage)) { |
| 685 | var InitiatingMessage im := s1ap.initiatingMessage; |
| 686 | select (s1ap) { |
| 687 | case (tr_S1AP_InitialUE) { |
| 688 | return im.value_.InitialUEMessage.protocolIEs[0].value_.ENB_UE_S1AP_ID; |
| 689 | } |
| 690 | case (tr_S1AP_DlNasTransport) { |
| 691 | return im.value_.DownlinkNASTransport.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 692 | } |
| 693 | case (tr_S1AP_UlNasTransport) { |
| 694 | return im.value_.UplinkNASTransport.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 695 | } |
| 696 | case (tr_S1AP_IntialCtxSetupReq) { |
| 697 | return im.value_.initialContextSetupRequest.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 698 | } |
| 699 | case (tr_S1AP_UeContextReleaseReq) { |
| 700 | return im.value_.UEContextReleaseRequest.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 701 | } |
Pau Espin Pedrol | a5bb807 | 2023-12-21 19:15:31 +0100 | [diff] [blame^] | 702 | case (tr_S1AP_UeContextReleaseCmd) { |
| 703 | if (ispresent(im.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair)) { |
| 704 | return im.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.eNB_UE_S1AP_ID; |
| 705 | } else { |
| 706 | return omit; |
| 707 | } |
| 708 | } |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 709 | case (tr_S1AP_ConnEstInd) { |
| 710 | return im.value_.ConnectionEstablishmentIndication.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 711 | } |
| 712 | /* TODO */ |
| 713 | } |
| 714 | } else if (ischosen(s1ap.successfulOutcome)) { |
| 715 | var SuccessfulOutcome so := s1ap.successfulOutcome; |
| 716 | select (s1ap) { |
| 717 | case (tr_S1AP_InitialCtxSetupResp) { |
| 718 | return so.value_.initialContextSetupResponse.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 719 | } |
| 720 | case (tr_S1AP_UeContextReleaseCompl) { |
| 721 | return so.value_.UEContextReleaseComplete.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 722 | } |
| 723 | /* TODO */ |
| 724 | } |
| 725 | } else if (ischosen(s1ap.unsuccessfulOutcome)) { |
| 726 | var UnsuccessfulOutcome uo := s1ap.unsuccessfulOutcome; |
| 727 | select (s1ap) { |
| 728 | case (tr_S1AP_InitialCtxSetupFail) { |
| 729 | return uo.value_.initialContextSetupFailure.protocolIEs[1].value_.ENB_UE_S1AP_ID; |
| 730 | } |
| 731 | /* TODO */ |
| 732 | } |
| 733 | } |
| 734 | return omit; |
| 735 | } |
| 736 | |
| 737 | function f_S1AP_get_MME_UE_S1AP_ID(S1AP_PDU s1ap) return template (omit) MME_UE_S1AP_ID |
| 738 | { |
| 739 | if (ischosen(s1ap.initiatingMessage)) { |
| 740 | var InitiatingMessage im := s1ap.initiatingMessage; |
| 741 | select (s1ap) { |
| 742 | case (tr_S1AP_DlNasTransport) { |
| 743 | return im.value_.DownlinkNASTransport.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 744 | } |
| 745 | case (tr_S1AP_UlNasTransport) { |
| 746 | return im.value_.UplinkNASTransport.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 747 | } |
| 748 | case (tr_S1AP_IntialCtxSetupReq) { |
| 749 | return im.value_.initialContextSetupRequest.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 750 | } |
| 751 | case (tr_S1AP_UeContextReleaseReq) { |
| 752 | return im.value_.UEContextReleaseRequest.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 753 | } |
Pau Espin Pedrol | a5bb807 | 2023-12-21 19:15:31 +0100 | [diff] [blame^] | 754 | case (tr_S1AP_UeContextReleaseCmd) { |
| 755 | if (ispresent(im.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair)) { |
| 756 | return im.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.mME_UE_S1AP_ID; |
| 757 | } else { |
| 758 | return im.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.mME_UE_S1AP_ID; |
| 759 | } |
| 760 | } |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 761 | case (tr_S1AP_ConnEstInd) { |
| 762 | return im.value_.ConnectionEstablishmentIndication.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 763 | } |
| 764 | /* TODO */ |
| 765 | } |
| 766 | } else if (ischosen(s1ap.successfulOutcome)) { |
| 767 | var SuccessfulOutcome so := s1ap.successfulOutcome; |
| 768 | select (s1ap) { |
| 769 | case (tr_S1AP_InitialCtxSetupResp) { |
| 770 | return so.value_.initialContextSetupResponse.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 771 | } |
| 772 | case (tr_S1AP_UeContextReleaseCompl) { |
| 773 | return so.value_.UEContextReleaseComplete.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 774 | } |
| 775 | /* TODO */ |
| 776 | } |
| 777 | } else if (ischosen(s1ap.unsuccessfulOutcome)) { |
| 778 | var UnsuccessfulOutcome uo := s1ap.unsuccessfulOutcome; |
| 779 | select (s1ap) { |
| 780 | case (tr_S1AP_InitialCtxSetupFail) { |
| 781 | return uo.value_.initialContextSetupFailure.protocolIEs[0].value_.MME_UE_S1AP_ID; |
| 782 | } |
| 783 | /* TODO */ |
| 784 | } |
| 785 | } |
| 786 | return omit; |
| 787 | } |
| 788 | |
| 789 | function f_S1AP_get_NAS_PDU(S1AP_PDU s1ap) return template (omit) NAS_PDU |
| 790 | { |
Pau Espin Pedrol | 2edec46 | 2023-12-15 19:16:02 +0100 | [diff] [blame] | 791 | var integer i, j; |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 792 | |
| 793 | if (ischosen(s1ap.initiatingMessage)) { |
| 794 | var InitiatingMessage im := s1ap.initiatingMessage; |
| 795 | select (s1ap) { |
| 796 | case (tr_S1AP_DlNasTransport) { |
| 797 | var DownlinkNASTransport msg := im.value_.DownlinkNASTransport; |
| 798 | for (i := 0; i < lengthof(msg.protocolIEs); i := i+1) { |
| 799 | if (msg.protocolIEs[i].id == id_NAS_PDU) { |
| 800 | return msg.protocolIEs[i].value_.NAS_PDU; |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | case (tr_S1AP_UlNasTransport) { |
| 805 | var UplinkNASTransport msg := im.value_.UplinkNASTransport; |
| 806 | for (i := 0; i < lengthof(msg.protocolIEs); i := i+1) { |
| 807 | if (msg.protocolIEs[i].id == id_NAS_PDU) { |
| 808 | return msg.protocolIEs[i].value_.NAS_PDU; |
| 809 | } |
| 810 | } |
| 811 | } |
Pau Espin Pedrol | 2edec46 | 2023-12-15 19:16:02 +0100 | [diff] [blame] | 812 | case (tr_S1AP_IntialCtxSetupReq) { |
| 813 | var InitialContextSetupRequest msg := im.value_.initialContextSetupRequest; |
| 814 | for (i := 0; i < lengthof(msg.protocolIEs); i := i+1) { |
| 815 | if (msg.protocolIEs[i].id == id_E_RABToBeSetupListCtxtSUReq) { |
| 816 | var E_RABToBeSetupListCtxtSUReq rab_req := msg.protocolIEs[i].value_.E_RABToBeSetupListCtxtSUReq; |
| 817 | for (j := 0; j < lengthof(rab_req); j := j+1) { |
| 818 | var E_RABToBeSetupItemCtxtSUReq it := rab_req[j].value_.E_RABToBeSetupItemCtxtSUReq; |
| 819 | return it.nAS_PDU; |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | return omit; |
| 824 | } |
Harald Welte | 3549811 | 2019-07-02 14:26:39 +0800 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | return omit; |
| 828 | } |
| 829 | |
| 830 | |
| 831 | |
| 832 | } |