Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1 | module BSC_ConnectionHandler { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 5 | import from Native_Functions all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 6 | import from GSM_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 7 | import from IPL4asp_Types all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 8 | import from SCCPasp_Types all; |
| 9 | import from BSSAP_Types all; |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 10 | import from RAN_Emulation all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 11 | import from BSSMAP_Templates all; |
| 12 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 13 | import from RANAP_Constants all; |
| 14 | import from RANAP_IEs all; |
| 15 | import from RANAP_PDU_Contents all; |
| 16 | import from RANAP_PDU_Descriptions all; |
| 17 | import from RANAP_Templates all; |
| 18 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 19 | import from GSUP_Types all; |
| 20 | import from GSUP_Emulation all; |
| 21 | |
| 22 | import from MNCC_Types all; |
| 23 | import from MNCC_Emulation all; |
| 24 | |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 25 | import from MGCP_Types all; |
| 26 | import from MGCP_Emulation all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 27 | import from MGCP_Templates all; |
| 28 | import from SDP_Types all; |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 29 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 30 | import from MobileL3_Types all; |
| 31 | import from MobileL3_CommonIE_Types all; |
| 32 | import from MobileL3_MM_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 33 | import from MobileL3_CC_Types all; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 34 | import from MobileL3_SMS_Types all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 35 | import from L3_Templates all; |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 36 | import from L3_Common all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 37 | |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 38 | import from SMPP_Emulation all; |
| 39 | |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 40 | import from IPA_Emulation all; |
| 41 | import from Osmocom_CTRL_Functions all; |
| 42 | import from Osmocom_CTRL_Types all; |
| 43 | import from Osmocom_CTRL_Adapter all; |
| 44 | |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 45 | import from TELNETasp_PortType all; |
| 46 | import from Osmocom_VTY_Functions all; |
| 47 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 48 | import from SGsAP_Emulation all; |
| 49 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 50 | /* this component represents a single subscriber connection */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 51 | type component BSC_ConnHdlr extends RAN_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT, SGsAP_ConnHdlr { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 52 | var BSC_ConnHdlrPars g_pars; |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 53 | timer g_Tguard := 60.0; |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 54 | port TELNETasp_PT MSCVTY; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 57 | type record BSC_ConnHdlrNetworkPars { |
| 58 | OCT1 kc_support, |
| 59 | boolean expect_tmsi, |
| 60 | boolean expect_auth, |
| 61 | boolean expect_ciph |
| 62 | } |
| 63 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 64 | type record BSC_ConnHdlrPars { |
| 65 | SCCP_PAR_Address sccp_addr_own, |
| 66 | SCCP_PAR_Address sccp_addr_peer, |
| 67 | BSSMAP_IE_CellIdentifier cell_id, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 68 | hexstring imei, |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 69 | hexstring imsi, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 70 | hexstring msisdn, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 71 | OCT4 tmsi optional, |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 72 | MobileStationClassmark1_V cm1, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 73 | BSSMAP_IE_ClassmarkInformationType2 cm2, |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 74 | BSSMAP_IE_ClassmarkInformationType3 cm3 optional, |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 75 | AuthVector vec optional, |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 76 | BSC_ConnHdlrNetworkPars net, |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 77 | boolean send_early_cm, |
| 78 | charstring ipa_ctrl_ip, |
| 79 | integer ipa_ctrl_port, |
Philipp Maier | 9b690e4 | 2018-12-21 11:50:03 +0100 | [diff] [blame] | 80 | boolean ipa_ctrl_enable, |
Philipp Maier | 5786548 | 2019-01-07 18:33:13 +0100 | [diff] [blame] | 81 | boolean mm_info, |
Philipp Maier | c09a131 | 2019-04-09 16:05:26 +0200 | [diff] [blame] | 82 | boolean sgsap_enable, |
Harald Welte | f9abf8d | 2019-04-21 13:07:17 +0200 | [diff] [blame] | 83 | boolean gsup_enable, |
Harald Welte | c1f937a | 2019-04-21 21:19:23 +0200 | [diff] [blame] | 84 | integer ran_idx, |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 85 | boolean use_umts_aka, |
| 86 | boolean ran_is_geran |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 89 | /* get a one-octet bitmaks of supported algorithms based on Classmark information */ |
| 90 | function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2) return OCT1 { |
| 91 | var BIT8 res := '00000001'B; /* A5/0 always supported */ |
| 92 | |
| 93 | if (cm2.a5_1 == '0'B) { |
| 94 | res := res or4b '00000010'B; |
| 95 | } |
| 96 | if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) { |
| 97 | res := res or4b '00000100'B; |
| 98 | } |
| 99 | if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) { |
| 100 | res := res or4b '00001000'B; |
| 101 | } |
| 102 | /* TODO: CM3 for A5/4 and beyond */ |
| 103 | return bit2oct(res); |
| 104 | } |
| 105 | |
| 106 | /* determine the best algorithm available within the bit-mask */ |
| 107 | function f_best_alg_from_mask(OCT1 alg_in) return OCT1 { |
| 108 | var BIT8 alg := oct2bit(alg_in); |
| 109 | var BIT8 ordered_algs[8] := { |
| 110 | '10000000'B, '01000000'B, '00100000'B, '00010000'B, |
| 111 | '00001000'B, /* A5/3 */ |
| 112 | '00000010'B, /* A5/1 */ |
| 113 | '00000100'B, /* A5/2 */ |
| 114 | '00000001'B /* A5/0 */ } |
| 115 | for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) { |
| 116 | if (alg and4b ordered_algs[i] != '00000000'B) { |
| 117 | return bit2oct(ordered_algs[i]); |
| 118 | } |
| 119 | } |
| 120 | return '00'O; |
| 121 | } |
| 122 | |
| 123 | /* return an integer like '1' for A5/1 based on a mask (with only one bit set */ |
| 124 | function f_alg_from_mask(OCT1 mask_in) return integer { |
| 125 | var BIT8 mask := oct2bit(mask_in); |
| 126 | for (var integer i := 0; i < 8; i := i+1) { |
| 127 | if (mask and4b ('00000001'B << i) != '00000000'B) { |
| 128 | return i; |
| 129 | } |
| 130 | } |
| 131 | return -1; |
| 132 | } |
| 133 | |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 134 | /* altstep for the global guard timer */ |
| 135 | private altstep as_Tguard() runs on BSC_ConnHdlr { |
| 136 | [] g_Tguard.timeout { |
Daniel Willmann | 90829d6 | 2018-02-15 17:45:14 +0100 | [diff] [blame] | 137 | setverdict(fail, "Tguard timeout"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 138 | mtc.stop; |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | /* init function, called as first function in new BSC_ConnHdlr */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 143 | function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr { |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 144 | /* make parameters available via component variable */ |
| 145 | g_pars := pars; |
| 146 | /* Start guard timer and activate it as default */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 147 | g_Tguard.start(t_guard); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 148 | activate(as_Tguard()); |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 149 | /* Route all SMPP messages for our MSISDN to us */ |
| 150 | f_create_smpp_expect(hex2str(pars.msisdn)); |
Philipp Maier | 5786548 | 2019-01-07 18:33:13 +0100 | [diff] [blame] | 151 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 152 | /* Route all SGs message for our IMSI to us */ |
Philipp Maier | 5786548 | 2019-01-07 18:33:13 +0100 | [diff] [blame] | 153 | if (g_pars.sgsap_enable == true) { |
| 154 | f_create_sgsap_expect(pars.imsi); |
| 155 | } |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 156 | |
| 157 | if (g_pars.ipa_ctrl_enable == true) { |
| 158 | f_ipa_ctrl_start(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port); |
| 159 | } |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 160 | |
| 161 | map(self:MSCVTY, system:MSCVTY); |
| 162 | f_vty_set_prompts(MSCVTY); |
| 163 | f_vty_transceive(MSCVTY, "enable"); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 166 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 167 | /* Callback function from general RAN_Emulation whenever a connectionless |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 168 | * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */ |
| 169 | private function BscUnitdataCallback(PDU_BSSAP bssap) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 170 | runs on RAN_Emulation_CT return template PDU_BSSAP { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 171 | var template PDU_BSSAP resp := omit; |
| 172 | |
| 173 | log("BSSMAP_BscUnitdataCallback"); |
| 174 | /* answer all RESET with RESET ACK */ |
| 175 | if (match(bssap, tr_BSSMAP_Reset)){ |
| 176 | log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK"); |
| 177 | resp := ts_BSSMAP_ResetAck; |
| 178 | } |
| 179 | |
| 180 | /* FIXME: Handle paging, etc. */ |
| 181 | return resp; |
| 182 | } |
| 183 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 184 | private function RncUnitdataCallback(RANAP_PDU ranap) |
| 185 | runs on RAN_Emulation_CT return template RANAP_PDU { |
| 186 | var template RANAP_PDU resp := omit; |
| 187 | |
| 188 | log("RANAP_RncUnitdataCallback"); |
| 189 | /* answer all RESET with RESET ACK */ |
| 190 | if (match(ranap, tr_RANAP_Reset)) { |
| 191 | log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK"); |
| 192 | var CN_DomainIndicator dom; |
| 193 | dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator; |
| 194 | resp := ts_RANAP_ResetAck(dom); |
| 195 | } |
| 196 | |
| 197 | /* FIXME: Handle paging, etc. */ |
| 198 | return resp; |
| 199 | } |
| 200 | |
| 201 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 202 | const RanOps BSC_RanOps := { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 203 | /* Create call-back for inbound connections from MSC (hand-over) */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 204 | create_cb := refers(RAN_Emulation.ExpectedCreateCallback), |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 205 | unitdata_cb := refers(BscUnitdataCallback), |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 206 | ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback), |
| 207 | ranap_unitdata_cb := refers(RncUnitdataCallback), |
| 208 | ps_domain := false, |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 209 | decode_dtap := true, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 210 | role_ms := true, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 211 | protocol := RAN_PROTOCOL_BSSAP, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 212 | sccp_addr_local := omit, |
| 213 | sccp_addr_peer := omit |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | |
| 217 | private function MnccUnitdataCallback(MNCC_PDU mncc) |
| 218 | runs on MNCC_Emulation_CT return template MNCC_PDU { |
| 219 | log("Ignoring MNCC", mncc); |
| 220 | return omit; |
| 221 | } |
| 222 | |
| 223 | const MnccOps BCC_MnccOps := { |
| 224 | create_cb := refers(MNCC_Emulation.ExpectedCreateCallback), |
| 225 | unitdata_cb := refers(MnccUnitdataCallback) |
| 226 | } |
| 227 | |
| 228 | |
| 229 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 230 | /* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */ |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 231 | function f_bssap_compl_l3(PDU_ML3_MS_NW l3) |
| 232 | runs on BSC_ConnHdlr { |
| 233 | log("Sending COMPL L3: ", l3); |
| 234 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3); |
| 235 | BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, |
| 236 | valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc)))); |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 237 | alt { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 238 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {} |
| 239 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 240 | setverdict(fail, "DISC.ind from SCCP"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 241 | mtc.stop; |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 242 | } |
| 243 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 246 | /* generate Iu LAI from BSSAP CGI */ |
| 247 | private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI { |
| 248 | var LAI lai; |
| 249 | if (ischosen(ci.cellIdentification.cI_CGI)) { |
| 250 | lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc; |
| 251 | lai.lAC := ci.cellIdentification.cI_CGI.lac; |
| 252 | } else if (ischosen(ci.cellIdentification.cI_SAI)) { |
| 253 | lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc; |
| 254 | lai.lAC := ci.cellIdentification.cI_SAI.lac; |
| 255 | } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) { |
| 256 | lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc; |
| 257 | lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac; |
| 258 | } else { |
| 259 | mtc.stop; |
| 260 | } |
| 261 | lai.iE_Extensions := omit; |
| 262 | return lai; |
| 263 | } |
| 264 | |
| 265 | /* like f_bssap_compl_l3() but for 3G */ |
| 266 | function f_ranap_initial_ue(PDU_ML3_MS_NW l3) |
| 267 | runs on BSC_ConnHdlr { |
| 268 | log("Sending InitialUE: ", l3); |
| 269 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3); |
| 270 | var RANAP_PDU ranap; |
| 271 | var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id); |
| 272 | var SAI sai := { |
| 273 | pLMNidentity := lai.pLMNidentity, |
| 274 | lAC := lai.lAC, |
| 275 | sAC := '0000'O, /* FIXME */ |
| 276 | iE_Extensions := omit |
| 277 | }; |
| 278 | var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24); |
| 279 | var GlobalRNC_ID grnc_id := { |
| 280 | pLMNidentity := lai.pLMNidentity, |
| 281 | rNC_ID := 2342 /* FIXME */ |
| 282 | }; |
| 283 | |
| 284 | ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id)); |
| 285 | BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap)); |
| 286 | alt { |
| 287 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {} |
| 288 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 289 | setverdict(fail, "DISC.ind from SCCP"); |
| 290 | mtc.stop; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
Harald Welte | dceacc7 | 2019-04-21 20:58:35 +0200 | [diff] [blame] | 295 | /* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */ |
| 296 | function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3) |
| 297 | runs on BSC_ConnHdlr { |
| 298 | if (g_pars.ran_is_geran) { |
| 299 | f_bssap_compl_l3(l3); |
| 300 | } else { |
| 301 | f_ranap_initial_ue(l3); |
| 302 | } |
| 303 | } |
| 304 | |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 305 | type enumerated EstablishType { |
| 306 | EST_TYPE_MO_CALL, |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 307 | EST_TYPE_EMERG_CALL, |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 308 | EST_TYPE_PAG_RESP, |
Vadim Yanitskiy | 20ee5e4 | 2018-05-27 17:54:21 +0700 | [diff] [blame] | 309 | EST_TYPE_MO_SMS, |
| 310 | EST_TYPE_SS_ACT |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 311 | }; |
| 312 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 313 | /* helper function to fully establish a dedicated channel */ |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 314 | function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL) |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 315 | runs on BSC_ConnHdlr { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 316 | var PDU_ML3_MS_NW l3_info; |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 317 | var MobileIdentityLV mi; |
| 318 | |
| 319 | /* If we have a TMSI, use TMSI instead of IMSI */ |
| 320 | if (ispresent(g_pars.tmsi)) { |
| 321 | mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi)); |
| 322 | } else { |
| 323 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 324 | } |
| 325 | |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 326 | select (etype) { |
| 327 | case (EST_TYPE_MO_CALL) { |
| 328 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi)); |
| 329 | } |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 330 | case (EST_TYPE_EMERG_CALL) { |
| 331 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi)); |
| 332 | } |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 333 | case (EST_TYPE_PAG_RESP) { |
| 334 | l3_info := valueof(ts_PAG_RESP(mi)); |
| 335 | } |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 336 | case (EST_TYPE_MO_SMS) { |
| 337 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi)); |
| 338 | } |
Vadim Yanitskiy | 20ee5e4 | 2018-05-27 17:54:21 +0700 | [diff] [blame] | 339 | case (EST_TYPE_SS_ACT) { |
| 340 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi)); |
| 341 | } |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 342 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 343 | |
| 344 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
Harald Welte | dceacc7 | 2019-04-21 20:58:35 +0200 | [diff] [blame] | 345 | f_cl3_or_initial_ue(l3_info); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 346 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 347 | f_mm_common(); |
| 348 | if (g_pars.net.expect_ciph) { |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 349 | /* implicit CM SERVICE ACCEPT? */ |
| 350 | } else { |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 351 | if (etype != EST_TYPE_PAG_RESP) { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 352 | /* explicit CM SERVICE ACCEPT */ |
| 353 | BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC)); |
| 354 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 355 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /* build a PDU_ML3_MS_NW containing a Location Update by IMSI */ |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 359 | function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 360 | { |
| 361 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi)); |
| 362 | return f_build_lu(mi); |
| 363 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 364 | function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | ba7b6d9 | 2018-01-23 21:32:34 +0100 | [diff] [blame] | 365 | { |
| 366 | var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei)); |
| 367 | return f_build_lu(mi); |
| 368 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 369 | function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | ba7b6d9 | 2018-01-23 21:32:34 +0100 | [diff] [blame] | 370 | { |
| 371 | var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi)); |
| 372 | return f_build_lu(mi); |
| 373 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 374 | private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 375 | { |
| 376 | var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O }; |
| 377 | var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach), |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 378 | old_lai, mi, g_pars.cm1)); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 379 | return l3_info; |
| 380 | } |
| 381 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 382 | function f_mm_auth() runs on BSC_ConnHdlr |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 383 | { |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 384 | if (g_pars.net.expect_auth) { |
Harald Welte | c1f937a | 2019-04-21 21:19:23 +0200 | [diff] [blame] | 385 | var GSUP_IE auth_tuple; |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 386 | GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 387 | |
Harald Welte | c1f937a | 2019-04-21 21:19:23 +0200 | [diff] [blame] | 388 | if (g_pars.use_umts_aka) { |
| 389 | g_pars.vec := f_gen_auth_vec_3g(); |
| 390 | auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand, |
| 391 | g_pars.vec.sres, |
| 392 | g_pars.vec.kc, |
| 393 | g_pars.vec.ik, |
| 394 | g_pars.vec.ck, |
| 395 | g_pars.vec.autn, |
| 396 | g_pars.vec.res)); |
| 397 | GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple)); |
| 398 | |
| 399 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn))); |
| 400 | var OCT4 res := substr(g_pars.vec.res, 0, 4); |
| 401 | var OCT4 xres := substr(g_pars.vec.res, 4, 4); |
| 402 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres))); |
| 403 | } else { |
| 404 | g_pars.vec := f_gen_auth_vec_2g(); |
| 405 | auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand, |
| 406 | g_pars.vec.sres, |
| 407 | g_pars.vec.kc)); |
| 408 | GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple)); |
| 409 | |
| 410 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand))); |
| 411 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres))); |
| 412 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 413 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 414 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 415 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 416 | function f_mm_common() runs on BSC_ConnHdlr |
| 417 | { |
| 418 | f_mm_auth(); |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 419 | if (g_pars.ran_is_geran) { |
| 420 | if (g_pars.net.expect_ciph) { |
| 421 | var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2); |
| 422 | var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net; |
| 423 | alt { |
| 424 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) { |
| 425 | var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect); |
| 426 | var integer a5_nr := f_alg_from_mask(a5_chosen); |
| 427 | BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1))); |
| 428 | } |
| 429 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) { |
| 430 | setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd"); |
| 431 | mtc.stop; |
| 432 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 433 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 434 | /* FIXME: Send the best available algorithm */ |
| 435 | } |
| 436 | } else { /* UTRAN */ |
| 437 | alt { |
| 438 | [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?, |
| 439 | uia_key := oct2bit(g_pars.vec.ik), |
| 440 | key_sts := ?, |
| 441 | uea_algs := ?, |
| 442 | uea_key := oct2bit(g_pars.vec.ck))) { |
| 443 | var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/ |
| 444 | var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/ |
| 445 | BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen)); |
| 446 | BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi))); |
| 447 | } |
| 448 | [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) { |
| 449 | setverdict(fail, "Invalid SecurityModeCommand (ciphering case)"); |
| 450 | mtc.stop; |
| 451 | } |
| 452 | [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?, |
| 453 | uia_key := oct2bit(g_pars.vec.ik), |
| 454 | key_sts := ?)) { |
| 455 | var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/ |
| 456 | BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen)); |
| 457 | BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi))); |
| 458 | } |
| 459 | [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) { |
| 460 | setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 461 | mtc.stop; |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 462 | } |
| 463 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
Philipp Maier | 9b690e4 | 2018-12-21 11:50:03 +0100 | [diff] [blame] | 467 | function f_expect_mm_info() runs on BSC_ConnHdlr { |
| 468 | if (g_pars.mm_info == true) { |
| 469 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info)); |
| 470 | } |
| 471 | } |
| 472 | |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 473 | function f_perform_lu() |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 474 | runs on BSC_ConnHdlr { |
| 475 | var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi) |
| 476 | var PDU_DTAP_MT dtap_mt; |
| 477 | |
| 478 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 479 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
| 480 | |
| 481 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 482 | if (g_pars.ran_is_geran) { |
| 483 | f_bssap_compl_l3(l3_lu); |
| 484 | if (g_pars.send_early_cm) { |
| 485 | BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3)); |
| 486 | } |
| 487 | } else { |
| 488 | f_ranap_initial_ue(l3_lu); |
Harald Welte | 8a121b3 | 2018-01-22 03:00:41 +0100 | [diff] [blame] | 489 | } |
Harald Welte | 5c2622c | 2018-01-21 20:45:20 +0100 | [diff] [blame] | 490 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 491 | f_mm_common(); |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 492 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 493 | /* Expect MSC to perform LU with HLR */ |
| 494 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
| 495 | GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn)); |
| 496 | GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi)); |
| 497 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 498 | |
| 499 | alt { |
| 500 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt { |
| 501 | var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept; |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 502 | if (g_pars.net.expect_tmsi) { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 503 | if (not ispresent(lu_acc.mobileIdentityTLV) or |
| 504 | not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 505 | setverdict(fail, "Expected TMSI but no TMSI was allocated"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 506 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 507 | } else { |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 508 | g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 509 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl)); |
| 510 | } |
| 511 | } else { |
| 512 | if (ispresent(lu_acc.mobileIdentityTLV) and |
| 513 | ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 514 | setverdict(fail, "Expected no TMSI but TMSI was allocated"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 515 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | } |
| 519 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { |
| 520 | setverdict(fail, "Expected LU ACK, but received LU REJ"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 521 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 522 | } |
| 523 | } |
Philipp Maier | 9b690e4 | 2018-12-21 11:50:03 +0100 | [diff] [blame] | 524 | |
| 525 | /* Wait for MM-Information (if enabled) */ |
| 526 | f_expect_mm_info(); |
| 527 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 528 | /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */ |
Harald Welte | a89fecf | 2019-04-21 15:37:39 +0200 | [diff] [blame] | 529 | f_expect_clear(); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 530 | setverdict(pass); |
| 531 | } |
| 532 | |
| 533 | function f_foo() runs on BSC_ConnHdlr{ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 534 | /* SCCP CC handled by RAN_Emulation_CT.main() */ |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 535 | /* Expect auth, if enabled */ |
| 536 | |
| 537 | /* TODO: ISD */ |
| 538 | /* Expect encr, if enabled */ |
| 539 | /* Expect encr, if enabled */ |
| 540 | /* Expect ASS CMD, if chan_type != requested */ |
| 541 | /* Send ASS CMPL in successful case */ |
| 542 | |
| 543 | /* Expect AoIP port/ip information for RTP stream */ |
| 544 | /* Expect MSC-originated MGCP to our simulated MGW */ |
| 545 | /* Verify Counters via CTRL */ |
| 546 | /* re-configure MSC behaviour via VTY */ |
| 547 | } |
| 548 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 549 | /* parameters related to a (MO?) voice call */ |
| 550 | type record CallParameters { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 551 | /* CC related parameters */ |
| 552 | hexstring called_party, /* whom are we calling */ |
| 553 | integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */ |
| 554 | BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */ |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 555 | boolean emergency, /* is this an emergency call? */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 556 | |
| 557 | /* MNCC related parameters */ |
| 558 | uint32_t mncc_callref optional, /* call reference on the MNCC side */ |
| 559 | MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */ |
| 560 | |
| 561 | /* RTP related parameters */ |
| 562 | HostName bss_rtp_ip optional, /* BSS Side RTP IP */ |
| 563 | PortNumber bss_rtp_port optional, /* BSS Side RTP Port */ |
| 564 | HostName mss_rtp_ip optional, /* MSS Side RTP IP */ |
| 565 | PortNumber mss_rtp_port optional, /* MSS Side RTP Port */ |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 566 | HostName mgw_rtp_ip_bss, /* BSS-facing MGW RTP IP */ |
| 567 | PortNumber mgw_rtp_port_bss, /* BSS-facing MGW RTP Port */ |
| 568 | HostName mgw_rtp_ip_mss, /* MSS-facing MGW RTP IP */ |
| 569 | PortNumber mgw_rtp_port_mss, /* MSS-facing MGW RTP Port */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 570 | uint7_t rtp_payload_type, /* dynamic RTP payload type */ |
| 571 | charstring rtp_sdp_format, /* AMR/8000 or the like */ |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 572 | boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX |
| 573 | (f_mt_call and f_mt_call) */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 574 | |
Philipp Maier | cd66857 | 2018-03-19 16:11:52 +0100 | [diff] [blame] | 575 | MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 576 | MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */, |
| 577 | MgcpConnectionId mgcp_connection_id_bss, /* MGCP Connection ID BSS Side */ |
| 578 | MgcpConnectionId mgcp_connection_id_mss /* MGCP Connection ID MSS Side */ |
| 579 | } |
| 580 | |
| 581 | template (value) CallParameters t_CallParams(hexstring called, integer tid) := { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 582 | called_party := called, |
| 583 | transaction_id := tid, |
| 584 | bearer_cap := valueof(ts_Bcap_voice), |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 585 | emergency := false, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 586 | mncc_callref := omit, |
| 587 | mncc_bearer_cap := valueof(ts_MNCC_bcap_voice), |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 588 | bss_rtp_ip := "9.8.7.6", |
| 589 | bss_rtp_port := 9000, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 590 | mss_rtp_ip := omit, |
| 591 | mss_rtp_port := omit, |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 592 | mgw_rtp_ip_bss := "1.1.1.1", |
| 593 | mgw_rtp_port_bss := 10000, |
| 594 | mgw_rtp_ip_mss := "1.1.1.1", |
| 595 | mgw_rtp_port_mss := 11000, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 596 | rtp_payload_type := 98, |
| 597 | rtp_sdp_format := "AMR/8000", |
| 598 | mgcp_call_id := omit, |
| 599 | mgcp_ep := omit, |
| 600 | mgcp_connection_id_bss := '0'H,// |
| 601 | mgcp_connection_id_mss := '0'H // |
| 602 | }; |
| 603 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 604 | /* Allocate a call reference and send SETUP via MNCC to MSC */ |
| 605 | function f_mt_call_initate(inout CallParameters cpars) |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 606 | runs on BSC_ConnHdlr { |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 607 | cpars.mncc_callref := f_rnd_int(2147483648); |
| 608 | MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn), |
| 609 | hex2str(cpars.called_party), hex2str(g_pars.imsi))); |
| 610 | } |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 611 | |
Harald Welte | 408a7ef | 2019-04-21 17:08:40 +0200 | [diff] [blame] | 612 | private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) := |
| 613 | ts_SDP(cpars.mgw_rtp_ip_mss, cpars.mgw_rtp_ip_mss, |
| 614 | hex2str(cpars.mgcp_call_id), "42", |
| 615 | cpars.mgw_rtp_port_mss, |
| 616 | { int2str(cpars.rtp_payload_type) }, |
| 617 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 618 | cpars.rtp_sdp_format)), |
| 619 | valueof(ts_SDP_ptime(20)) }); |
| 620 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 621 | /* Complete call, begin with a paging response message via BSSAP */ |
| 622 | function f_mt_call_complete(inout CallParameters cpars) |
| 623 | runs on BSC_ConnHdlr { |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 624 | var MNCC_PDU mncc; |
| 625 | var MgcpCommand mgcp_cmd; |
| 626 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 627 | f_ran_register_imsi(g_pars.imsi, g_pars.tmsi); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 628 | |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 629 | f_establish_fully(EST_TYPE_PAG_RESP); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 630 | |
| 631 | /* MS <- MSC: Expect CC SETUP */ |
| 632 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party))); |
| 633 | |
| 634 | /* MS -> MSC: ALERTING */ |
| 635 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id))); |
| 636 | MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref)); |
| 637 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 638 | /* Create MGCP expect */ |
| 639 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 640 | /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */ |
| 641 | MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 642 | |
| 643 | /* First MGCP CRCX (for BSS/RAN side) */ |
| 644 | MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 645 | cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd); |
Philipp Maier | 4b2692d | 2018-03-14 16:37:48 +0100 | [diff] [blame] | 646 | |
| 647 | /* When the endpoint contains a wildcard we keep the endpoint |
| 648 | * identifier we have set up in cpars. Otherwise we use the |
| 649 | * endpoint name that the call agent has supplied */ |
| 650 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) { |
| 651 | cpars.mgcp_ep := mgcp_cmd.line.ep; |
| 652 | } |
| 653 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 654 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_bss, cpars.mgw_rtp_ip_bss, |
| 655 | hex2str(cpars.mgcp_call_id), "42", |
| 656 | cpars.mgw_rtp_port_bss, |
| 657 | { int2str(cpars.rtp_payload_type) }, |
| 658 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 659 | cpars.rtp_sdp_format)), |
| 660 | valueof(ts_SDP_ptime(20)) })); |
Philipp Maier | 4b2692d | 2018-03-14 16:37:48 +0100 | [diff] [blame] | 661 | var template MgcpResponse mgcp_resp; |
| 662 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_bss, sdp); |
| 663 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep)); |
| 664 | MGCP.send(mgcp_resp); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 665 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 666 | |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 667 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 668 | if (g_pars.ran_is_geran) { |
| 669 | var BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 670 | valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_rtp_ip_bss),cpars.mgw_rtp_port_bss)); |
| 671 | |
| 672 | interleave { |
| 673 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 674 | [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 675 | var SDP_Message sdp := valueof(ts_SDP_CRCX_CN(cpars)); |
| 676 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
| 677 | /* MSC acknowledges the MNCC_CREATE to the MNCC handler */ |
| 678 | MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 679 | } |
| 680 | /* expect the MSC to trigger a BSSMAP ASSIGNMENT */ |
| 681 | [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) { |
| 682 | var BSSMAP_IE_AoIP_TransportLayerAddress tla; |
| 683 | var BSSMAP_IE_SpeechCodec codec; |
| 684 | |
| 685 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 686 | codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR})); |
| 687 | |
| 688 | BSSAP.send(ts_BSSMAP_AssignmentComplete(omit, tla, codec)); |
| 689 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 690 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 691 | } else { |
| 692 | var template TransportLayerAddress rab_tla := ? /* FIXME: encode the mgw_rtp_ip_bss/mgw_rtp_port_bss */ |
| 693 | var template RAB_SetupOrModifyList rab_sml := tr_RAB_SML(rab_id := ?, tla := rab_tla, binding_id := ?); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 694 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 695 | interleave { |
| 696 | [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 697 | var SDP_Message sdp := valueof(ts_SDP_CRCX_CN(cpars)); |
| 698 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
| 699 | /* MSC acknowledges the MNCC_CREATE to the MNCC handler */ |
| 700 | MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 701 | } |
| 702 | [] BSSAP.receive(tr_RANAP_RabAssReq(rab_sml)) { |
| 703 | //BSSAP.send(ts_RANAP_RabAssResp(rab_sml)); FIXME |
| 704 | } |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 705 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 706 | } |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 707 | |
| 708 | /* MS -> MSC: ALERTING */ |
| 709 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id))); |
| 710 | MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)); |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Harald Welte | e035e3e | 2019-04-21 17:32:05 +0200 | [diff] [blame] | 713 | function f_expect_paging(boolean by_tmsi := true) |
| 714 | runs on BSC_ConnHdlr { |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 715 | if (g_pars.ran_is_geran) { |
| 716 | BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi)); |
| 717 | } else { |
| 718 | BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi), ?)); |
| 719 | } |
Harald Welte | e035e3e | 2019-04-21 17:32:05 +0200 | [diff] [blame] | 720 | } |
| 721 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 722 | function f_mt_call_establish(inout CallParameters cpars) |
| 723 | runs on BSC_ConnHdlr { |
| 724 | |
| 725 | /* Initiate the call via MNCC */ |
| 726 | f_mt_call_initate(cpars); |
| 727 | |
| 728 | /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 729 | f_ran_register_imsi(g_pars.imsi, g_pars.tmsi); |
Harald Welte | e035e3e | 2019-04-21 17:32:05 +0200 | [diff] [blame] | 730 | f_expect_paging() |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 731 | |
| 732 | /* Complete the call via BSSAP */ |
| 733 | f_mt_call_complete(cpars); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 734 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 735 | setverdict(pass); |
| 736 | } |
| 737 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 738 | function f_mo_call_establish(inout CallParameters cpars) |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 739 | runs on BSC_ConnHdlr { |
| 740 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 741 | var MNCC_PDU mncc; |
| 742 | var MgcpCommand mgcp_cmd; |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 743 | var boolean respond_to_dlcx; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 744 | |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 745 | if (cpars.emergency) { |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 746 | f_establish_fully(EST_TYPE_EMERG_CALL); |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 747 | } else { |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 748 | f_establish_fully(EST_TYPE_MO_CALL); |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 749 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 750 | |
| 751 | /* Create MNCC and MGCP expect */ |
| 752 | f_create_mncc_expect(hex2str(cpars.called_party)); |
| 753 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 754 | |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 755 | if (cpars.emergency) { |
| 756 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id))); |
| 757 | } else { |
| 758 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party))); |
| 759 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 760 | interleave { |
| 761 | [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc { |
| 762 | cpars.mncc_callref := mncc.u.signal.callref; |
| 763 | /* Call Proceeding */ |
| 764 | MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap)); |
| 765 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id))); |
| 766 | }; |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 767 | /* First MGCP CRCX (for BSS/RAN side) */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 768 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 769 | cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd); |
Philipp Maier | f1e02bb | 2018-03-15 16:30:00 +0100 | [diff] [blame] | 770 | |
| 771 | /* When the endpoint contains a wildcard we keep the endpoint |
| 772 | * identifier we have set up in cpars. Otherwise we use the |
| 773 | * endpoint name that the call agent has supplied */ |
| 774 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) { |
| 775 | cpars.mgcp_ep := mgcp_cmd.line.ep; |
| 776 | } |
| 777 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 778 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_bss, cpars.mgw_rtp_ip_bss, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 779 | hex2str(cpars.mgcp_call_id), "42", |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 780 | cpars.mgw_rtp_port_bss, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 781 | { int2str(cpars.rtp_payload_type) }, |
| 782 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 783 | cpars.rtp_sdp_format)), |
| 784 | valueof(ts_SDP_ptime(20)) })); |
Philipp Maier | f1e02bb | 2018-03-15 16:30:00 +0100 | [diff] [blame] | 785 | |
| 786 | var template MgcpResponse mgcp_resp; |
| 787 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_bss, sdp); |
| 788 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep)); |
| 789 | MGCP.send(mgcp_resp); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 790 | } |
| 791 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 792 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 793 | if (g_pars.ran_is_geran) { |
| 794 | var BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 795 | valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_rtp_ip_bss),cpars.mgw_rtp_port_bss)); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 796 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 797 | interleave { |
| 798 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 799 | [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 800 | var SDP_Message sdp := valueof(ts_SDP_CRCX_CN(cpars)); |
| 801 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 802 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 803 | /* Alerting */ |
| 804 | MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref)); |
| 805 | } |
| 806 | |
| 807 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) { |
| 808 | } |
| 809 | /* expect AoIP IP/Port to match what we returned in CRCX_ACK above */ |
| 810 | [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) { |
| 811 | var BSSMAP_IE_AoIP_TransportLayerAddress tla; |
| 812 | var BSSMAP_IE_SpeechCodec codec; |
| 813 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 814 | codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR})); |
| 815 | BSSAP.send(ts_BSSMAP_AssignmentComplete(omit, tla, codec)); |
| 816 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 817 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 818 | } else { |
| 819 | var template TransportLayerAddress rab_tla := ?; /* FIXME: encode the mgw_rtp_ip_bss/mgw_rtp_port_bss */ |
| 820 | var template RAB_SetupOrModifyList rab_sml := tr_RAB_SML(rab_id := ?, tla := rab_tla, binding_id := ?); |
| 821 | |
| 822 | interleave { |
| 823 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 824 | [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 825 | var SDP_Message sdp := valueof(ts_SDP_CRCX_CN(cpars)); |
| 826 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
| 827 | |
| 828 | /* Alerting */ |
| 829 | MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref)); |
| 830 | } |
| 831 | |
| 832 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) { |
| 833 | } |
| 834 | |
| 835 | [] BSSAP.receive(tr_RANAP_RabAssReq(rab_sml)) { |
| 836 | //BSSAP.send(ts_RANAP_RabAssResp(rab_sml)); FIXME |
| 837 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 841 | /* Answer. MNCC_SETUP_RSP -> CONNECT to MS; CONNECT_ACK from MS */ |
| 842 | MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref)); |
| 843 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))); |
| 844 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id))); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 845 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 846 | setverdict(pass); |
| 847 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 848 | |
Harald Welte | 4c422b7 | 2019-02-17 16:27:10 +0100 | [diff] [blame] | 849 | function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false) |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 850 | runs on BSC_ConnHdlr { |
| 851 | |
| 852 | var MobileIdentityLV mi; |
| 853 | var MNCC_PDU mncc; |
| 854 | var MgcpCommand mgcp_cmd; |
| 855 | var boolean respond_to_dlcx; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 856 | MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23)))); |
| 857 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id))); |
| 858 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 859 | if (release_by_ms) { |
| 860 | /* B-side (MS) Release of call */ |
| 861 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_RELEASE(cpars.transaction_id, '1'B, '0000000'B))); |
| 862 | MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref)); |
| 863 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id))); |
| 864 | } else { |
| 865 | /* A-side (PLMN) Release of call */ |
| 866 | MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42)))); |
| 867 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))); |
| 868 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id))); |
| 869 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 870 | |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 871 | respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx)); |
| 872 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 873 | /* clearing of radio channel */ |
| 874 | if (g_pars.ran_is_geran) { |
| 875 | var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand; |
| 876 | if (is_csfb) { |
| 877 | t_clear := tr_BSSMAP_ClearCommandCSFB; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 878 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 879 | |
| 880 | interleave { |
| 881 | [] BSSAP.receive(t_clear) { |
| 882 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 883 | BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 884 | } |
| 885 | [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd { |
| 886 | if (respond_to_dlcx) { |
| 887 | /* TODO: For one or all connections on EP? */ |
| 888 | MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id)); |
| 889 | f_create_mgcp_delete_ep(cpars.mgcp_ep); |
| 890 | } |
| 891 | } |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 892 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 893 | } else { |
| 894 | var template RANAP_PDU t_iurel := tr_RANAP_IuReleaseCommand(?); |
| 895 | if (is_csfb) { |
| 896 | /* FIXME! */ |
| 897 | } |
| 898 | interleave { |
| 899 | [] BSSAP.receive(t_iurel) { |
| 900 | BSSAP.send(ts_RANAP_IuReleaseComplete); |
| 901 | BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 902 | } |
| 903 | [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd { |
| 904 | if (respond_to_dlcx) { |
| 905 | /* TODO: For one or all connections on EP? */ |
| 906 | MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id)); |
| 907 | f_create_mgcp_delete_ep(cpars.mgcp_ep); |
| 908 | } |
| 909 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 910 | } |
| 911 | } |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 912 | |
| 913 | setverdict(pass); |
| 914 | } |
| 915 | |
| 916 | function f_mt_call(inout CallParameters cpars) |
| 917 | runs on BSC_ConnHdlr { |
| 918 | |
| 919 | f_mt_call_establish(cpars); |
| 920 | |
| 921 | /* Hold the call for some time */ |
| 922 | f_sleep(3.0); |
| 923 | |
| 924 | f_call_hangup(cpars, true); |
| 925 | |
| 926 | setverdict(pass); |
| 927 | } |
| 928 | |
| 929 | function f_mo_call(inout CallParameters cpars) |
| 930 | runs on BSC_ConnHdlr { |
| 931 | |
| 932 | f_mo_call_establish(cpars); |
| 933 | |
| 934 | /* Hold the call for some time */ |
| 935 | f_sleep(3.0); |
| 936 | |
| 937 | f_call_hangup(cpars, false); |
| 938 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 939 | setverdict(pass); |
| 940 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 941 | |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 942 | function f_mo_seq_dtmf_dup(inout CallParameters cpars) |
| 943 | runs on BSC_ConnHdlr { |
| 944 | |
| 945 | timer T := 1.0; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 946 | var MNCC_PDU mncc; |
| 947 | var MgcpCommand mgcp_cmd; |
| 948 | var template PDU_ML3_MS_NW dtmf_dtap; |
| 949 | |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 950 | f_establish_fully(); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 951 | |
| 952 | /* Create MNCC and MGCP expect */ |
| 953 | f_create_mncc_expect(hex2str(cpars.called_party)); |
| 954 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 955 | |
| 956 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party))); |
| 957 | MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc; |
| 958 | cpars.mncc_callref := mncc.u.signal.callref; |
| 959 | |
| 960 | /* Send DTMF */ |
| 961 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2"); |
| 962 | dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(2, 2); |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 963 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 964 | T.start; |
| 965 | alt { |
| 966 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {} |
| 967 | [] T.timeout { |
| 968 | setverdict(fail, "Timeout waiting for START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 969 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 973 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 974 | T.start; |
| 975 | alt { |
| 976 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) { |
| 977 | setverdict(fail, "Received duplicate START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 978 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 979 | } |
| 980 | [] T.timeout { } |
| 981 | } |
| 982 | |
| 983 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3"); |
| 984 | dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(3, 2); |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 985 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 986 | alt { |
| 987 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) { } |
| 988 | [] T.timeout { |
| 989 | setverdict(fail, "Received duplicate START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 990 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | |
| 994 | setverdict(pass); |
| 995 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 996 | |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 997 | /* expect a clear command */ |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 998 | altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr { |
Neels Hofmeyr | 6b468a4 | 2019-03-06 15:25:14 +0100 | [diff] [blame] | 999 | var PDU_BSSAP bssap; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1000 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) { |
| 1001 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 1002 | alt { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1003 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1004 | setverdict(pass); |
| 1005 | } |
| 1006 | [] BSSAP.receive { |
| 1007 | setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1008 | mtc.stop; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | } |
Neels Hofmeyr | 6b468a4 | 2019-03-06 15:25:14 +0100 | [diff] [blame] | 1012 | [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap { |
| 1013 | setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1014 | mtc.stop; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1018 | /* expect a IuReleaseCommand; Confirm that; expect SCCP-level N-DISCONNET.ind */ |
| 1019 | altstep as_iu_release_compl_disc(float t := 5.0) runs on BSC_ConnHdlr { |
| 1020 | var RANAP_PDU ranap; |
| 1021 | [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) { |
| 1022 | BSSAP.send(ts_RANAP_IuReleaseComplete); |
| 1023 | alt { |
| 1024 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 1025 | setverdict(pass); |
| 1026 | } |
| 1027 | [] BSSAP.receive { |
| 1028 | setverdict(fail, "Unexpected RANAP while waiting for SCCP Release "); |
| 1029 | mtc.stop; |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | [] BSSAP.receive(RANAP_PDU:?) -> value ranap{ |
| 1034 | setverdict(fail, "Unexpected RANAP while waiting for IuReleaseCommand", ranap); |
| 1035 | mtc.stop; |
| 1036 | } |
| 1037 | } |
| 1038 | |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 1039 | function f_expect_clear(float t := 5.0) runs on BSC_ConnHdlr { |
| 1040 | timer T := t; |
| 1041 | |
| 1042 | T.start; |
| 1043 | alt { |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1044 | [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { } |
| 1045 | [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { } |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 1046 | [] T.timeout { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1047 | setverdict(fail, "Timeout waiting for ClearCommand/Release"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1048 | mtc.stop; |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1053 | type record SmsParametersTp { |
| 1054 | OCT1 msg_ref, |
| 1055 | TP_DA da, |
| 1056 | OCT1 pid, |
| 1057 | OCT1 dcs, |
| 1058 | integer udl, |
| 1059 | octetstring ud |
| 1060 | } |
| 1061 | type record SmsParametersRp { |
| 1062 | OCT1 msg_ref, |
| 1063 | RP_NumberingPlan_and_NumberDigits orig optional, |
| 1064 | RP_NumberingPlan_and_NumberDigits dest optional |
| 1065 | } |
| 1066 | type record SmsParameters { |
| 1067 | SmsParametersTp tp, |
| 1068 | SmsParametersRp rp, |
| 1069 | uint3_t tid, |
| 1070 | OCT1 dlci, |
| 1071 | uint7_t exp_rp_err optional |
| 1072 | } |
| 1073 | |
| 1074 | template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := { |
| 1075 | tP_DA_NoPad := { |
| 1076 | tP_LengthIndicator := 0, /* overwritten */ |
| 1077 | tP_NumberingPlanID := npl, |
| 1078 | tP_TypeOfNumber := ton, |
| 1079 | tp_Spare := '0'B, |
| 1080 | tP_DAValue := addr |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := { |
| 1085 | tp := { |
| 1086 | msg_ref := '23'O, |
| 1087 | da := ts_TP_DA('0000'B, '000'B, tp_daddr), |
| 1088 | pid := '00'O, |
| 1089 | dcs := '00'O, |
| 1090 | udl := 0, |
| 1091 | ud := ''O |
| 1092 | }, |
| 1093 | rp := { |
| 1094 | msg_ref := '42'O, |
| 1095 | orig := omit, |
| 1096 | dest := { '0000'B, '000'B, '0'B, '98765'H } |
| 1097 | }, |
| 1098 | tid := 0, |
| 1099 | dlci := '03'O, |
| 1100 | exp_rp_err := omit |
| 1101 | } |
| 1102 | |
| 1103 | private altstep as_other_sms() runs on BSC_ConnHdlr { |
| 1104 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) { |
| 1105 | setverdict(fail, "Unexpected SMS related PDU from MSC"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1106 | mtc.stop; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Vadim Yanitskiy | 9cc019a | 2018-11-15 02:06:07 +0700 | [diff] [blame] | 1110 | /* Submit a MO RP-SMMA over an already existing DTAP connection */ |
| 1111 | function f_mo_smma(inout SmsParameters spars) |
| 1112 | runs on BSC_ConnHdlr { |
| 1113 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1114 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1115 | |
| 1116 | var default d := activate(as_other_sms()); |
| 1117 | |
| 1118 | /* just in case this is routed to SMPP.. */ |
| 1119 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 1120 | |
| 1121 | rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref); |
| 1122 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo)); |
| 1123 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1124 | /* receive CP-ACK for CP-DATA above */ |
| 1125 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci)); |
| 1126 | |
| 1127 | deactivate(d); |
| 1128 | setverdict(pass); |
| 1129 | } |
| 1130 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1131 | /* Submit a MO-SMS over an already existing DTAP connection */ |
| 1132 | function f_mo_sms_submit(inout SmsParameters spars) |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1133 | runs on BSC_ConnHdlr { |
| 1134 | var template (value) TPDU_RP_DATA_MS_SGSN tp_mo; |
| 1135 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1136 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1137 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1138 | var default d := activate(as_other_sms()); |
| 1139 | |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 1140 | /* just in case this is routed to SMPP.. */ |
| 1141 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 1142 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1143 | tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs, |
| 1144 | spars.tp.udl, spars.tp.ud); |
| 1145 | rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, spars.rp.orig, spars.rp.dest, tp_mo); |
| 1146 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo)); |
| 1147 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1148 | /* receive CP-ACK for CP-DATA above */ |
| 1149 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci)); |
| 1150 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1151 | deactivate(d); |
| 1152 | setverdict(pass); |
| 1153 | } |
| 1154 | |
| 1155 | /* Wait RP-ACK for MO-SMS on an already existing DTAP connection */ |
| 1156 | function f_mo_sms_wait_rp_ack(inout SmsParameters spars) |
| 1157 | runs on BSC_ConnHdlr { |
| 1158 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1159 | |
| 1160 | var template TPDU_RP_DATA_SGSN_MS tp_mt; |
| 1161 | var template RPDU_SGSN_MS rp_mt; |
| 1162 | var template PDU_ML3_NW_MS l3_mt; |
| 1163 | |
| 1164 | var default d := activate(as_other_sms()); |
| 1165 | |
| 1166 | /* just in case this is routed to SMPP.. */ |
| 1167 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 1168 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1169 | if (ispresent(spars.exp_rp_err)) { |
| 1170 | /* expect an RP-ERROR message from MSC with given cause */ |
| 1171 | rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err); |
| 1172 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt)); |
| 1173 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1174 | /* send CP-ACK for CP-DATA just received */ |
| 1175 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO); |
| 1176 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1177 | } else { |
| 1178 | /* expect RP-ACK for RP-DATA */ |
| 1179 | rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref); |
| 1180 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt)); |
| 1181 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1182 | /* send CP-ACO for CP-DATA just received */ |
| 1183 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO); |
| 1184 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1185 | } |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1186 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1187 | deactivate(d); |
| 1188 | setverdict(pass); |
| 1189 | } |
| 1190 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1191 | /* Submit a MO-SMS, and wait for RP-ACK on an existing |
| 1192 | * (and authenticated, ...) DTAP connection */ |
| 1193 | function f_mo_sms(inout SmsParameters spars) |
| 1194 | runs on BSC_ConnHdlr { |
| 1195 | f_mo_sms_submit(spars); |
| 1196 | f_mo_sms_wait_rp_ack(spars); |
| 1197 | } |
| 1198 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1199 | /* Wait for MT SMS on an already existing DTAP connection */ |
| 1200 | function f_mt_sms_expect(inout SmsParameters spars) |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1201 | runs on BSC_ConnHdlr { |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1202 | var template (value) PDU_ML3_MS_NW l3_mo; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1203 | var template TPDU_RP_DATA_SGSN_MS tp_mt; |
| 1204 | var template RPDU_SGSN_MS rp_mt; |
| 1205 | var template PDU_ML3_NW_MS l3_mt; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1206 | var PDU_DTAP_MT dtap_mt; |
| 1207 | |
| 1208 | var default d := activate(as_other_sms()); |
| 1209 | |
| 1210 | /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */ |
| 1211 | tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?); |
| 1212 | rp_mt := tr_RP_DATA_MT(?, ?, omit, tp_mt); |
| 1213 | l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt)); |
| 1214 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)) -> value dtap_mt; |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1215 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1216 | /* Extract relevant identifiers */ |
| 1217 | spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio); |
| 1218 | spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference; |
| 1219 | |
| 1220 | /* send CP-ACK for CP-DATA just received */ |
| 1221 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO); |
| 1222 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1223 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1224 | deactivate(d); |
| 1225 | setverdict(pass); |
| 1226 | } |
| 1227 | |
| 1228 | /* Send RP-ACK for MT-SMS over an already existing DTAP connection */ |
| 1229 | function f_mt_sms_send_rp_ack(inout SmsParameters spars) |
| 1230 | runs on BSC_ConnHdlr { |
| 1231 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1232 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1233 | var template PDU_ML3_NW_MS l3_mt; |
| 1234 | |
| 1235 | var default d := activate(as_other_sms()); |
| 1236 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1237 | /* send RP-ACK for RP-DATA */ |
| 1238 | rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref); |
| 1239 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo)); |
| 1240 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1241 | |
| 1242 | /* expect CP-ACK for CP-DATA(RP-ACK) just sent */ |
Harald Welte | e008eea | 2018-04-14 21:05:48 +0200 | [diff] [blame] | 1243 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT); |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1244 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1245 | |
| 1246 | deactivate(d); |
| 1247 | setverdict(pass); |
| 1248 | } |
| 1249 | |
Vadim Yanitskiy | 5631852 | 2018-11-24 03:40:47 +0700 | [diff] [blame] | 1250 | /* Send RP-ERROR for MT-SMS over an already existing DTAP connection */ |
| 1251 | function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause) |
| 1252 | runs on BSC_ConnHdlr { |
| 1253 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1254 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1255 | var template PDU_ML3_NW_MS l3_mt; |
| 1256 | |
| 1257 | var default d := activate(as_other_sms()); |
| 1258 | |
| 1259 | /* send RP-ACK for RP-DATA */ |
| 1260 | rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause); |
| 1261 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo)); |
| 1262 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1263 | |
| 1264 | /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */ |
| 1265 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT); |
| 1266 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1267 | |
| 1268 | deactivate(d); |
| 1269 | setverdict(pass); |
| 1270 | } |
| 1271 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1272 | /* Wait for a MT-SMS and send RP-ACK over an already existing |
| 1273 | * (and authenticated, ...) DTAP connection */ |
| 1274 | function f_mt_sms(inout SmsParameters spars) |
| 1275 | runs on BSC_ConnHdlr { |
| 1276 | f_mt_sms_expect(spars); |
| 1277 | f_mt_sms_send_rp_ack(spars); |
| 1278 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1279 | |
| 1280 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | |