Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 1 | module MSC_ConnectionHandler { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 5 | import from GSM_Types all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 6 | import from SCCPasp_Types all; |
| 7 | import from BSSAP_Types all; |
| 8 | import from BSSMAP_Emulation all; |
| 9 | import from BSSMAP_Templates all; |
| 10 | |
| 11 | import from MGCP_Types all; |
| 12 | import from MGCP_Templates all; |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 13 | import from MGCP_Emulation all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 14 | import from SDP_Types all; |
| 15 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 16 | import from RSL_Emulation all; |
| 17 | import from RSL_Types all; |
| 18 | |
| 19 | import from MobileL3_Types all; |
| 20 | import from MobileL3_CommonIE_Types all; |
| 21 | //import from MobileL3_RRM_Types all; |
| 22 | import from L3_Templates all; |
| 23 | |
| 24 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 25 | /* this component represents a single subscriber connection at the MSC. |
| 26 | * There is a 1:1 mapping between SCCP connections and BSSAP_ConnHdlr components. |
| 27 | * We inherit all component variables, ports, functions, ... from BSSAP_ConnHdlr */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 28 | type component MSC_ConnHdlr extends BSSAP_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 29 | /* SCCP Connecction Identifier for the underlying SCCP connection */ |
| 30 | var integer g_sccp_conn_id; |
| 31 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 32 | /* procedure port back to our parent (BSSMAP_Emulation_CT) for control */ |
| 33 | port BSSMAPEM_PROC_PT BSSMAPEM; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 34 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 35 | var MSC_State g_state := MSC_STATE_NONE; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 39 | * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */ |
| 40 | private function UnitdataCallback(PDU_BSSAP bssap) |
| 41 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 42 | var template PDU_BSSAP resp := omit; |
| 43 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 44 | /* answer all RESET with a RESET ACK */ |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 45 | if (match(bssap, tr_BSSMAP_Reset)) { |
| 46 | resp := ts_BSSMAP_ResetAck; |
| 47 | } |
| 48 | |
| 49 | return resp; |
| 50 | } |
| 51 | |
| 52 | const BssmapOps MSC_BssmapOps := { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 53 | create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback), |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 54 | unitdata_cb := refers(UnitdataCallback), |
| 55 | decode_dtap := false, |
| 56 | role_ms := false |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 59 | const MGCPOps MSC_MGCPOps := { |
| 60 | create_cb := refers(MGCP_Emulation.ExpectedCreateCallback) |
| 61 | } |
| 62 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 63 | type enumerated MSC_State { |
| 64 | MSC_STATE_NONE, |
| 65 | MSC_STATE_WAIT_ASS_COMPL, |
| 66 | MSC_STATE_WAIT_CRCX_ACK, |
| 67 | MSC_STATE_WAIT_MDCX_ACK, |
| 68 | MSC_STATE_WAIT_CLEAR_COMPL, |
| 69 | MSC_STATE_WAIT_DLCX_ACK |
| 70 | } |
| 71 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 72 | /* register an expect with the BSSMAP core */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 73 | private function f_create_bssmap_exp(octetstring l3_enc) runs on MSC_ConnHdlr { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 74 | BSSMAPEM.call(BSSMAPEM_register:{l3_enc, self}) { |
| 75 | [] BSSMAPEM.getreply(BSSMAPEM_register:{?, ?}) {}; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 79 | type record TestHdlrParams { |
| 80 | OCT1 ra, |
| 81 | GsmFrameNumber fn, |
| 82 | hexstring imsi, |
| 83 | RslLinkId link_id |
| 84 | }; |
| 85 | |
| 86 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
| 87 | ra := '23'O, |
| 88 | fn := 23, |
| 89 | imsi := '001019876543210'H, |
| 90 | link_id := valueof(ts_RslLinkID_DCCH(0)) |
| 91 | } |
| 92 | |
| 93 | function f_create_chan_and_exp(TestHdlrParams pars) runs on MSC_ConnHdlr { |
| 94 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(pars.imsi)); |
Harald Welte | 6ed6bf9 | 2018-01-24 21:09:15 +0100 | [diff] [blame] | 95 | var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi)); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 96 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info); |
| 97 | |
| 98 | /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */ |
| 99 | RSL_Emulation.f_chan_est(pars.ra, l3_enc, pars.link_id, pars.fn); |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 100 | f_create_bssmap_exp(l3_enc); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig) runs on MSC_ConnHdlr { |
| 104 | var RslChannelNr chan_nr := orig.ies[0].body.chan_nr; |
Harald Welte | 1a40de6 | 2017-12-23 02:28:34 +0100 | [diff] [blame] | 105 | var RslLinkId link_id; |
Harald Welte | 8d5eead | 2017-12-17 18:56:45 +0100 | [diff] [blame] | 106 | if (orig.msg_type == RSL_MT_ENCR_CMD) { |
| 107 | link_id := orig.ies[2].body.link_id; |
| 108 | } else { |
| 109 | link_id := orig.ies[1].body.link_id; |
| 110 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 111 | RSL.send(ts_RSL_DATA_IND(chan_nr, link_id, enc_PDU_ML3_MS_NW(valueof(l3)))); |
| 112 | } |
| 113 | |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 114 | function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit, boolean exp_fail := false) |
| 115 | runs on MSC_ConnHdlr { |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 116 | var PDU_BSSAP bssap; |
| 117 | var RSL_Message rsl; |
| 118 | |
| 119 | if (isvalue(kc128)) { |
| 120 | BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128))); |
| 121 | } else { |
| 122 | BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key)); |
| 123 | } |
| 124 | alt { |
| 125 | /* RSL/UE Side */ |
| 126 | [] RSL.receive(tr_RSL_ENCR_CMD(g_chan_nr, ?, alg, key)) -> value rsl { |
| 127 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload); |
| 128 | log("Rx L3 from net: ", l3); |
| 129 | if (ischosen(l3.msgs.rrm.cipheringModeCommand)) { |
| 130 | f_rsl_reply(ts_RRM_CiphModeCompl, rsl); |
| 131 | } |
| 132 | repeat; |
| 133 | } |
| 134 | [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap { |
| 135 | // bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 136 | if (exp_fail == true) { |
| 137 | setverdict(fail, "Unexpected Cipher Mode Complete"); |
| 138 | } else { |
| 139 | setverdict(pass); |
| 140 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 141 | } |
| 142 | [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap { |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 143 | if (exp_fail == false) { |
| 144 | setverdict(fail, "Ciphering Mode Reject"); |
| 145 | } else { |
| 146 | setverdict(pass); |
| 147 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 152 | /* establish a channel fully, expecting an assignment matching 'exp' */ |
| 153 | function f_establish_fully(TestHdlrParams pars, PDU_BSSAP ass_cmd, template PDU_BSSAP exp_ass_cpl) |
| 154 | runs on MSC_ConnHdlr return PDU_BSSAP { |
| 155 | var PDU_BSSAP bssap; |
| 156 | var RSL_Message rsl; |
| 157 | timer T := 10.0; |
| 158 | var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete); |
Harald Welte | 82d2b87 | 2017-12-16 23:36:23 +0100 | [diff] [blame] | 159 | var boolean crcx_seen := false; |
| 160 | var boolean rr_modify_seen := false; |
Daniel Willmann | 21ea239 | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 161 | var ExpectCriteria mgcpcrit := { |
| 162 | connid := omit, |
| 163 | endpoint := omit, |
| 164 | transid := omit |
| 165 | }; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 166 | |
| 167 | f_create_chan_and_exp(pars); |
| 168 | /* we should now have a COMPL_L3 at the MSC */ |
| 169 | |
| 170 | BSSAP.receive(tr_BSSMAP_ComplL3); |
Daniel Willmann | 21ea239 | 2018-01-17 15:22:32 +0100 | [diff] [blame^] | 171 | f_create_mgcp_expect(mgcpcrit); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 172 | BSSAP.send(ass_cmd); |
| 173 | alt { |
| 174 | /* if we receive exactly what we expected, always return + pass */ |
| 175 | [] BSSAP.receive(exp_ass_cpl) -> value bssap { |
| 176 | setverdict(pass); |
| 177 | return bssap; |
| 178 | } |
Harald Welte | 82d2b87 | 2017-12-16 23:36:23 +0100 | [diff] [blame] | 179 | [rr_modify_seen == false] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 180 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 181 | log("Rx L3 from net: ", l3); |
| 182 | if (ischosen(l3.msgs.rrm.channelModeModify)) { |
| 183 | f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription, |
| 184 | l3.msgs.rrm.channelModeModify.channelMode), rsl); |
Harald Welte | 82d2b87 | 2017-12-16 23:36:23 +0100 | [diff] [blame] | 185 | rr_modify_seen := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 186 | } |
| 187 | repeat; |
| 188 | } |
Harald Welte | 82d2b87 | 2017-12-16 23:36:23 +0100 | [diff] [blame] | 189 | [rr_modify_seen] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_MODE_MODIFY_REQ)) -> value rsl { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 190 | RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr)); |
| 191 | repeat; |
| 192 | } |
Harald Welte | 82d2b87 | 2017-12-16 23:36:23 +0100 | [diff] [blame] | 193 | [crcx_seen == false] RSL.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 194 | RSL.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, 1, 1, 1, 1)); |
Harald Welte | 82d2b87 | 2017-12-16 23:36:23 +0100 | [diff] [blame] | 195 | crcx_seen := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 196 | repeat; |
| 197 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 198 | /* mgw CRCX goes here */ |
| 199 | |
Harald Welte | 82d2b87 | 2017-12-16 23:36:23 +0100 | [diff] [blame] | 200 | [crcx_seen] RSL.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 201 | RSL.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, 1, 1, 1, 1)); |
| 202 | repeat; |
| 203 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 204 | /* mgw MGCX goes here */ |
| 205 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 206 | [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
| 207 | setverdict(fail, "Received non-matching ASSIGNMENT COMPLETE"); |
| 208 | } |
| 209 | [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 210 | setverdict(fail, "Received unexpected ASSIGNMENT FAIL"); |
| 211 | } |
| 212 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
| 213 | setverdict(fail, "Received unexpected ASSIGNMENT COMPLETE"); |
| 214 | } |
| 215 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 216 | setverdict(fail, "Received non-matching ASSIGNMENT FAIL"); |
| 217 | } |
| 218 | [] T.timeout { |
| 219 | setverdict(inconc, "Timeout waiting for ASSIGNMENT COMPLETE"); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | self.stop; |
| 224 | } |
| 225 | |
| 226 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 227 | } |