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