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