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; |
| 10 | import from BSSMAP_Emulation all; |
| 11 | import from BSSMAP_Templates all; |
| 12 | |
| 13 | import from GSUP_Types all; |
| 14 | import from GSUP_Emulation all; |
| 15 | |
| 16 | import from MNCC_Types all; |
| 17 | import from MNCC_Emulation all; |
| 18 | |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 19 | import from MGCP_Types all; |
| 20 | import from MGCP_Emulation all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 21 | import from MGCP_Templates all; |
| 22 | import from SDP_Types all; |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 23 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 24 | import from MobileL3_Types all; |
| 25 | import from MobileL3_CommonIE_Types all; |
| 26 | import from MobileL3_MM_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 27 | import from MobileL3_CC_Types all; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 28 | import from MobileL3_SMS_Types all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 29 | import from L3_Templates all; |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 30 | import from L3_Common all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 31 | |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 32 | import from SMPP_Emulation all; |
| 33 | |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 34 | import from IPA_Emulation all; |
| 35 | import from Osmocom_CTRL_Functions all; |
| 36 | import from Osmocom_CTRL_Types all; |
| 37 | import from Osmocom_CTRL_Adapter all; |
| 38 | |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 39 | import from TELNETasp_PortType all; |
| 40 | import from Osmocom_VTY_Functions all; |
| 41 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 42 | /* this component represents a single subscriber connection */ |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 43 | type component BSC_ConnHdlr extends BSSAP_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 44 | var BSC_ConnHdlrPars g_pars; |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 45 | timer g_Tguard := 60.0; |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 46 | port TELNETasp_PT MSCVTY; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 49 | type record BSC_ConnHdlrNetworkPars { |
| 50 | OCT1 kc_support, |
| 51 | boolean expect_tmsi, |
| 52 | boolean expect_auth, |
| 53 | boolean expect_ciph |
| 54 | } |
| 55 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 56 | type record BSC_ConnHdlrPars { |
| 57 | SCCP_PAR_Address sccp_addr_own, |
| 58 | SCCP_PAR_Address sccp_addr_peer, |
| 59 | BSSMAP_IE_CellIdentifier cell_id, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 60 | hexstring imei, |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 61 | hexstring imsi, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 62 | hexstring msisdn, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 63 | OCT4 tmsi optional, |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 64 | MobileStationClassmark1_V cm1, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 65 | BSSMAP_IE_ClassmarkInformationType2 cm2, |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 66 | BSSMAP_IE_ClassmarkInformationType3 cm3 optional, |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 67 | AuthVector vec optional, |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 68 | BSC_ConnHdlrNetworkPars net, |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 69 | boolean send_early_cm, |
| 70 | charstring ipa_ctrl_ip, |
| 71 | integer ipa_ctrl_port, |
| 72 | boolean ipa_ctrl_enable |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 75 | /* get a one-octet bitmaks of supported algorithms based on Classmark information */ |
| 76 | function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2) return OCT1 { |
| 77 | var BIT8 res := '00000001'B; /* A5/0 always supported */ |
| 78 | |
| 79 | if (cm2.a5_1 == '0'B) { |
| 80 | res := res or4b '00000010'B; |
| 81 | } |
| 82 | if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) { |
| 83 | res := res or4b '00000100'B; |
| 84 | } |
| 85 | if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) { |
| 86 | res := res or4b '00001000'B; |
| 87 | } |
| 88 | /* TODO: CM3 for A5/4 and beyond */ |
| 89 | return bit2oct(res); |
| 90 | } |
| 91 | |
| 92 | /* determine the best algorithm available within the bit-mask */ |
| 93 | function f_best_alg_from_mask(OCT1 alg_in) return OCT1 { |
| 94 | var BIT8 alg := oct2bit(alg_in); |
| 95 | var BIT8 ordered_algs[8] := { |
| 96 | '10000000'B, '01000000'B, '00100000'B, '00010000'B, |
| 97 | '00001000'B, /* A5/3 */ |
| 98 | '00000010'B, /* A5/1 */ |
| 99 | '00000100'B, /* A5/2 */ |
| 100 | '00000001'B /* A5/0 */ } |
| 101 | for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) { |
| 102 | if (alg and4b ordered_algs[i] != '00000000'B) { |
| 103 | return bit2oct(ordered_algs[i]); |
| 104 | } |
| 105 | } |
| 106 | return '00'O; |
| 107 | } |
| 108 | |
| 109 | /* return an integer like '1' for A5/1 based on a mask (with only one bit set */ |
| 110 | function f_alg_from_mask(OCT1 mask_in) return integer { |
| 111 | var BIT8 mask := oct2bit(mask_in); |
| 112 | for (var integer i := 0; i < 8; i := i+1) { |
| 113 | if (mask and4b ('00000001'B << i) != '00000000'B) { |
| 114 | return i; |
| 115 | } |
| 116 | } |
| 117 | return -1; |
| 118 | } |
| 119 | |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 120 | /* altstep for the global guard timer */ |
| 121 | private altstep as_Tguard() runs on BSC_ConnHdlr { |
| 122 | [] g_Tguard.timeout { |
Daniel Willmann | 90829d6 | 2018-02-15 17:45:14 +0100 | [diff] [blame] | 123 | setverdict(fail, "Tguard timeout"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 124 | mtc.stop; |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | /* init function, called as first function in new BSC_ConnHdlr */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 129 | 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] | 130 | /* make parameters available via component variable */ |
| 131 | g_pars := pars; |
| 132 | /* Start guard timer and activate it as default */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 133 | g_Tguard.start(t_guard); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 134 | activate(as_Tguard()); |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 135 | /* Route all SMPP messages for our MSISDN to us */ |
| 136 | f_create_smpp_expect(hex2str(pars.msisdn)); |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 137 | |
| 138 | if (g_pars.ipa_ctrl_enable == true) { |
| 139 | f_ipa_ctrl_start(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port); |
| 140 | } |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 141 | |
| 142 | map(self:MSCVTY, system:MSCVTY); |
| 143 | f_vty_set_prompts(MSCVTY); |
| 144 | f_vty_transceive(MSCVTY, "enable"); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 147 | |
| 148 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 149 | * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */ |
| 150 | private function BscUnitdataCallback(PDU_BSSAP bssap) |
| 151 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 152 | var template PDU_BSSAP resp := omit; |
| 153 | |
| 154 | log("BSSMAP_BscUnitdataCallback"); |
| 155 | /* answer all RESET with RESET ACK */ |
| 156 | if (match(bssap, tr_BSSMAP_Reset)){ |
| 157 | log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK"); |
| 158 | resp := ts_BSSMAP_ResetAck; |
| 159 | } |
| 160 | |
| 161 | /* FIXME: Handle paging, etc. */ |
| 162 | return resp; |
| 163 | } |
| 164 | |
| 165 | const BssmapOps BSC_BssmapOps := { |
| 166 | /* Create call-back for inbound connections from MSC (hand-over) */ |
| 167 | create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback), |
| 168 | unitdata_cb := refers(BscUnitdataCallback), |
| 169 | decode_dtap := true, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 170 | role_ms := true, |
| 171 | sccp_addr_local := omit, |
| 172 | sccp_addr_peer := omit |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
| 176 | private function MnccUnitdataCallback(MNCC_PDU mncc) |
| 177 | runs on MNCC_Emulation_CT return template MNCC_PDU { |
| 178 | log("Ignoring MNCC", mncc); |
| 179 | return omit; |
| 180 | } |
| 181 | |
| 182 | const MnccOps BCC_MnccOps := { |
| 183 | create_cb := refers(MNCC_Emulation.ExpectedCreateCallback), |
| 184 | unitdata_cb := refers(MnccUnitdataCallback) |
| 185 | } |
| 186 | |
| 187 | |
| 188 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 189 | /* Encode 'l3' and ask BSSMAP_Emulation to create new connection with COMPL L3 INFO */ |
| 190 | function f_bssap_compl_l3(PDU_ML3_MS_NW l3) |
| 191 | runs on BSC_ConnHdlr { |
| 192 | log("Sending COMPL L3: ", l3); |
| 193 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3); |
| 194 | BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, |
| 195 | valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc)))); |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 196 | alt { |
| 197 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {} |
| 198 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 199 | setverdict(fail, "DISC.ind from SCCP"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 200 | mtc.stop; |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 201 | } |
| 202 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 205 | type enumerated EstablishType { |
| 206 | EST_TYPE_MO_CALL, |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 207 | EST_TYPE_EMERG_CALL, |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 208 | EST_TYPE_PAG_RESP, |
Vadim Yanitskiy | 20ee5e4 | 2018-05-27 17:54:21 +0700 | [diff] [blame] | 209 | EST_TYPE_MO_SMS, |
| 210 | EST_TYPE_SS_ACT |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 211 | }; |
| 212 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 213 | /* helper function to fully establish a dedicated channel */ |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 214 | function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL) |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 215 | runs on BSC_ConnHdlr { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 216 | var PDU_ML3_MS_NW l3_info; |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 217 | var MobileIdentityLV mi; |
| 218 | |
| 219 | /* If we have a TMSI, use TMSI instead of IMSI */ |
| 220 | if (ispresent(g_pars.tmsi)) { |
| 221 | mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi)); |
| 222 | } else { |
| 223 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 224 | } |
| 225 | |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 226 | select (etype) { |
| 227 | case (EST_TYPE_MO_CALL) { |
| 228 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi)); |
| 229 | } |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 230 | case (EST_TYPE_EMERG_CALL) { |
| 231 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi)); |
| 232 | } |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 233 | case (EST_TYPE_PAG_RESP) { |
| 234 | l3_info := valueof(ts_PAG_RESP(mi)); |
| 235 | } |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 236 | case (EST_TYPE_MO_SMS) { |
| 237 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi)); |
| 238 | } |
Vadim Yanitskiy | 20ee5e4 | 2018-05-27 17:54:21 +0700 | [diff] [blame] | 239 | case (EST_TYPE_SS_ACT) { |
| 240 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi)); |
| 241 | } |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 242 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 243 | |
| 244 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
| 245 | f_bssap_compl_l3(l3_info); |
| 246 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 247 | f_mm_common(); |
| 248 | if (g_pars.net.expect_ciph) { |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 249 | /* implicit CM SERVICE ACCEPT? */ |
| 250 | } else { |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 251 | if (etype != EST_TYPE_PAG_RESP) { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 252 | /* explicit CM SERVICE ACCEPT */ |
| 253 | BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC)); |
| 254 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 255 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /* build a PDU_ML3_MS_NW containing a Location Update by IMSI */ |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 259 | 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] | 260 | { |
| 261 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi)); |
| 262 | return f_build_lu(mi); |
| 263 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 264 | 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] | 265 | { |
| 266 | var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei)); |
| 267 | return f_build_lu(mi); |
| 268 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 269 | 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] | 270 | { |
| 271 | var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi)); |
| 272 | return f_build_lu(mi); |
| 273 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 274 | 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] | 275 | { |
| 276 | var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O }; |
| 277 | 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] | 278 | old_lai, mi, g_pars.cm1)); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 279 | return l3_info; |
| 280 | } |
| 281 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 282 | function f_mm_auth() runs on BSC_ConnHdlr |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 283 | { |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 284 | if (g_pars.net.expect_auth) { |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 285 | g_pars.vec := f_gen_auth_vec_2g(); |
| 286 | var GSUP_IE auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand, |
| 287 | g_pars.vec.sres, |
| 288 | g_pars.vec.kc)); |
| 289 | GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); |
| 290 | GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple)); |
| 291 | |
| 292 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand))); |
| 293 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres))); |
| 294 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 295 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 296 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 297 | function f_mm_common() runs on BSC_ConnHdlr |
| 298 | { |
| 299 | f_mm_auth(); |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 300 | if (g_pars.net.expect_ciph) { |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 301 | var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2); |
| 302 | var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net; |
| 303 | alt { |
| 304 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) { |
| 305 | var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect); |
| 306 | var integer a5_nr := f_alg_from_mask(a5_chosen); |
| 307 | BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1))); |
| 308 | } |
| 309 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) { |
| 310 | setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 311 | mtc.stop; |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | /* FIXME: Send the best available algorithm */ |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 318 | function f_perform_lu() |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 319 | runs on BSC_ConnHdlr { |
| 320 | var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi) |
| 321 | var PDU_DTAP_MT dtap_mt; |
| 322 | |
| 323 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 324 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
| 325 | |
| 326 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
| 327 | f_bssap_compl_l3(l3_lu); |
| 328 | |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 329 | if (g_pars.send_early_cm) { |
Harald Welte | 8a121b3 | 2018-01-22 03:00:41 +0100 | [diff] [blame] | 330 | BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3)); |
| 331 | } |
Harald Welte | 5c2622c | 2018-01-21 20:45:20 +0100 | [diff] [blame] | 332 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 333 | f_mm_common(); |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 334 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 335 | /* Expect MSC to perform LU with HLR */ |
| 336 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
| 337 | GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn)); |
| 338 | GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi)); |
| 339 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 340 | |
| 341 | alt { |
| 342 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt { |
| 343 | var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept; |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 344 | if (g_pars.net.expect_tmsi) { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 345 | if (not ispresent(lu_acc.mobileIdentityTLV) or |
| 346 | not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 347 | setverdict(fail, "Expected TMSI but no TMSI was allocated"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 348 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 349 | } else { |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 350 | 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] | 351 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl)); |
| 352 | } |
| 353 | } else { |
| 354 | if (ispresent(lu_acc.mobileIdentityTLV) and |
| 355 | ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 356 | setverdict(fail, "Expected no TMSI but TMSI was allocated"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 357 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | } |
| 361 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { |
| 362 | setverdict(fail, "Expected LU ACK, but received LU REJ"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 363 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */ |
| 367 | BSSAP.receive(tr_BSSMAP_ClearCommand); |
| 368 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 369 | BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 370 | setverdict(pass); |
| 371 | } |
| 372 | |
| 373 | function f_foo() runs on BSC_ConnHdlr{ |
| 374 | /* SCCP CC handled by BSSMAP_Emulation_CT.main() */ |
| 375 | /* Expect auth, if enabled */ |
| 376 | |
| 377 | /* TODO: ISD */ |
| 378 | /* Expect encr, if enabled */ |
| 379 | /* Expect encr, if enabled */ |
| 380 | /* Expect ASS CMD, if chan_type != requested */ |
| 381 | /* Send ASS CMPL in successful case */ |
| 382 | |
| 383 | /* Expect AoIP port/ip information for RTP stream */ |
| 384 | /* Expect MSC-originated MGCP to our simulated MGW */ |
| 385 | /* Verify Counters via CTRL */ |
| 386 | /* re-configure MSC behaviour via VTY */ |
| 387 | } |
| 388 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 389 | /* parameters related to a (MO?) voice call */ |
| 390 | type record CallParameters { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 391 | /* CC related parameters */ |
| 392 | hexstring called_party, /* whom are we calling */ |
| 393 | integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */ |
| 394 | BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */ |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 395 | boolean emergency, /* is this an emergency call? */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 396 | |
| 397 | /* MNCC related parameters */ |
| 398 | uint32_t mncc_callref optional, /* call reference on the MNCC side */ |
| 399 | MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */ |
| 400 | |
| 401 | /* RTP related parameters */ |
| 402 | HostName bss_rtp_ip optional, /* BSS Side RTP IP */ |
| 403 | PortNumber bss_rtp_port optional, /* BSS Side RTP Port */ |
| 404 | HostName mss_rtp_ip optional, /* MSS Side RTP IP */ |
| 405 | PortNumber mss_rtp_port optional, /* MSS Side RTP Port */ |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 406 | HostName mgw_rtp_ip_bss, /* BSS-facing MGW RTP IP */ |
| 407 | PortNumber mgw_rtp_port_bss, /* BSS-facing MGW RTP Port */ |
| 408 | HostName mgw_rtp_ip_mss, /* MSS-facing MGW RTP IP */ |
| 409 | PortNumber mgw_rtp_port_mss, /* MSS-facing MGW RTP Port */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 410 | uint7_t rtp_payload_type, /* dynamic RTP payload type */ |
| 411 | charstring rtp_sdp_format, /* AMR/8000 or the like */ |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 412 | boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX |
| 413 | (f_mt_call and f_mt_call) */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 414 | |
Philipp Maier | cd66857 | 2018-03-19 16:11:52 +0100 | [diff] [blame] | 415 | MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 416 | MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */, |
| 417 | MgcpConnectionId mgcp_connection_id_bss, /* MGCP Connection ID BSS Side */ |
| 418 | MgcpConnectionId mgcp_connection_id_mss /* MGCP Connection ID MSS Side */ |
| 419 | } |
| 420 | |
| 421 | template (value) CallParameters t_CallParams(hexstring called, integer tid) := { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 422 | called_party := called, |
| 423 | transaction_id := tid, |
| 424 | bearer_cap := valueof(ts_Bcap_voice), |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 425 | emergency := false, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 426 | mncc_callref := omit, |
| 427 | mncc_bearer_cap := valueof(ts_MNCC_bcap_voice), |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 428 | bss_rtp_ip := "9.8.7.6", |
| 429 | bss_rtp_port := 9000, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 430 | mss_rtp_ip := omit, |
| 431 | mss_rtp_port := omit, |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 432 | mgw_rtp_ip_bss := "1.1.1.1", |
| 433 | mgw_rtp_port_bss := 10000, |
| 434 | mgw_rtp_ip_mss := "1.1.1.1", |
| 435 | mgw_rtp_port_mss := 11000, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 436 | rtp_payload_type := 98, |
| 437 | rtp_sdp_format := "AMR/8000", |
| 438 | mgcp_call_id := omit, |
| 439 | mgcp_ep := omit, |
| 440 | mgcp_connection_id_bss := '0'H,// |
| 441 | mgcp_connection_id_mss := '0'H // |
| 442 | }; |
| 443 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 444 | function f_mt_call_establish(inout CallParameters cpars) |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 445 | runs on BSC_ConnHdlr { |
| 446 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 447 | var MNCC_PDU mncc; |
| 448 | var MgcpCommand mgcp_cmd; |
| 449 | |
| 450 | f_bssmap_register_imsi(g_pars.imsi, g_pars.tmsi); |
| 451 | |
| 452 | /* Allocate a call reference and send SETUP via MNCC to MSC */ |
| 453 | cpars.mncc_callref := f_rnd_int(2147483648); |
| 454 | MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn), |
| 455 | hex2str(cpars.called_party), hex2str(g_pars.imsi))); |
| 456 | /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */ |
| 457 | BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi)); |
| 458 | |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 459 | f_establish_fully(EST_TYPE_PAG_RESP); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 460 | |
| 461 | /* MS <- MSC: Expect CC SETUP */ |
| 462 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party))); |
| 463 | |
| 464 | /* MS -> MSC: ALERTING */ |
| 465 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id))); |
| 466 | MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref)); |
| 467 | |
| 468 | |
| 469 | /* Create MGCP expect */ |
| 470 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 471 | /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */ |
| 472 | MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 473 | |
| 474 | /* First MGCP CRCX (for BSS/RAN side) */ |
| 475 | MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 476 | cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd); |
Philipp Maier | 4b2692d | 2018-03-14 16:37:48 +0100 | [diff] [blame] | 477 | |
| 478 | /* When the endpoint contains a wildcard we keep the endpoint |
| 479 | * identifier we have set up in cpars. Otherwise we use the |
| 480 | * endpoint name that the call agent has supplied */ |
| 481 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) { |
| 482 | cpars.mgcp_ep := mgcp_cmd.line.ep; |
| 483 | } |
| 484 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 485 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_bss, cpars.mgw_rtp_ip_bss, |
| 486 | hex2str(cpars.mgcp_call_id), "42", |
| 487 | cpars.mgw_rtp_port_bss, |
| 488 | { int2str(cpars.rtp_payload_type) }, |
| 489 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 490 | cpars.rtp_sdp_format)), |
| 491 | valueof(ts_SDP_ptime(20)) })); |
Philipp Maier | 4b2692d | 2018-03-14 16:37:48 +0100 | [diff] [blame] | 492 | var template MgcpResponse mgcp_resp; |
| 493 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_bss, sdp); |
| 494 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep)); |
| 495 | MGCP.send(mgcp_resp); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 496 | } |
| 497 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 498 | MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 499 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_mss, cpars.mgw_rtp_ip_mss, |
| 500 | hex2str(cpars.mgcp_call_id), "42", |
| 501 | cpars.mgw_rtp_port_mss, |
| 502 | { int2str(cpars.rtp_payload_type) }, |
| 503 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 504 | cpars.rtp_sdp_format)), |
| 505 | valueof(ts_SDP_ptime(20)) })); |
| 506 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
| 507 | /* MSC acknowledges the MNCC_CREATE to the MNCC handler */ |
| 508 | MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 509 | } |
| 510 | |
| 511 | /* expect the MSC to trigger a BSSMAP ASSIGNMENT */ |
| 512 | var BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 513 | valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_rtp_ip_bss),cpars.mgw_rtp_port_bss)); |
| 514 | BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) { |
| 515 | var BSSMAP_IE_AoIP_TransportLayerAddress tla; |
| 516 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 517 | BSSAP.send(ts_BSSMAP_AssignmentComplete(omit, tla)); |
| 518 | } |
| 519 | |
| 520 | /* MS -> MSC: ALERTING */ |
| 521 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id))); |
| 522 | MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)); |
| 523 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 524 | setverdict(pass); |
| 525 | } |
| 526 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 527 | function f_mo_call_establish(inout CallParameters cpars) |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 528 | runs on BSC_ConnHdlr { |
| 529 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 530 | var MNCC_PDU mncc; |
| 531 | var MgcpCommand mgcp_cmd; |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 532 | var boolean respond_to_dlcx; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 533 | |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 534 | if (cpars.emergency) { |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 535 | f_establish_fully(EST_TYPE_EMERG_CALL); |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 536 | } else { |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 537 | f_establish_fully(EST_TYPE_MO_CALL); |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 538 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 539 | |
| 540 | /* Create MNCC and MGCP expect */ |
| 541 | f_create_mncc_expect(hex2str(cpars.called_party)); |
| 542 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 543 | |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 544 | if (cpars.emergency) { |
| 545 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id))); |
| 546 | } else { |
| 547 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party))); |
| 548 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 549 | interleave { |
| 550 | [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc { |
| 551 | cpars.mncc_callref := mncc.u.signal.callref; |
| 552 | /* Call Proceeding */ |
| 553 | MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap)); |
| 554 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id))); |
| 555 | }; |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 556 | /* First MGCP CRCX (for BSS/RAN side) */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 557 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 558 | cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd); |
Philipp Maier | f1e02bb | 2018-03-15 16:30:00 +0100 | [diff] [blame] | 559 | |
| 560 | /* When the endpoint contains a wildcard we keep the endpoint |
| 561 | * identifier we have set up in cpars. Otherwise we use the |
| 562 | * endpoint name that the call agent has supplied */ |
| 563 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) { |
| 564 | cpars.mgcp_ep := mgcp_cmd.line.ep; |
| 565 | } |
| 566 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 567 | 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] | 568 | hex2str(cpars.mgcp_call_id), "42", |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 569 | cpars.mgw_rtp_port_bss, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 570 | { int2str(cpars.rtp_payload_type) }, |
| 571 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 572 | cpars.rtp_sdp_format)), |
| 573 | valueof(ts_SDP_ptime(20)) })); |
Philipp Maier | f1e02bb | 2018-03-15 16:30:00 +0100 | [diff] [blame] | 574 | |
| 575 | var template MgcpResponse mgcp_resp; |
| 576 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_bss, sdp); |
| 577 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep)); |
| 578 | MGCP.send(mgcp_resp); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 579 | } |
| 580 | } |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 581 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 582 | MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 583 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_mss, cpars.mgw_rtp_ip_mss, |
| 584 | hex2str(cpars.mgcp_call_id), "42", |
| 585 | cpars.mgw_rtp_port_mss, |
| 586 | { int2str(cpars.rtp_payload_type) }, |
| 587 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 588 | cpars.rtp_sdp_format)), |
| 589 | valueof(ts_SDP_ptime(20)) })); |
| 590 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
| 591 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 592 | |
| 593 | /* Alerting */ |
| 594 | MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref)); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 595 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 596 | var BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 597 | valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_rtp_ip_bss),cpars.mgw_rtp_port_bss)); |
| 598 | interleave { |
| 599 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {} |
| 600 | /* expect AoIP IP/Port to match what we returned in CRCX_ACK above */ |
| 601 | [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 602 | var BSSMAP_IE_AoIP_TransportLayerAddress tla; |
| 603 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 604 | BSSAP.send(ts_BSSMAP_AssignmentComplete(omit, tla)); |
| 605 | } |
| 606 | } |
| 607 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 608 | /* Answer. MNCC_SETUP_RSP -> CONNECT to MS; CONNECT_ACK from MS */ |
| 609 | MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref)); |
| 610 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))); |
| 611 | 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] | 612 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 613 | setverdict(pass); |
| 614 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 615 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 616 | function f_call_hangup(inout CallParameters cpars, boolean release_by_ms) |
| 617 | runs on BSC_ConnHdlr { |
| 618 | |
| 619 | var MobileIdentityLV mi; |
| 620 | var MNCC_PDU mncc; |
| 621 | var MgcpCommand mgcp_cmd; |
| 622 | var boolean respond_to_dlcx; |
| 623 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 624 | MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23)))); |
| 625 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id))); |
| 626 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 627 | if (release_by_ms) { |
| 628 | /* B-side (MS) Release of call */ |
| 629 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_RELEASE(cpars.transaction_id, '1'B, '0000000'B))); |
| 630 | MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref)); |
| 631 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id))); |
| 632 | } else { |
| 633 | /* A-side (PLMN) Release of call */ |
| 634 | MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42)))); |
| 635 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))); |
| 636 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id))); |
| 637 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 638 | |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 639 | respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx)); |
| 640 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 641 | /* clearing of radio channel */ |
| 642 | interleave { |
| 643 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) { |
| 644 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 645 | BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 646 | } |
| 647 | [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd { |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 648 | if (respond_to_dlcx) { |
| 649 | /* TODO: For one or all connections on EP? */ |
| 650 | MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id)); |
| 651 | f_create_mgcp_delete_ep(cpars.mgcp_ep); |
| 652 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 653 | } |
| 654 | } |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 655 | |
| 656 | setverdict(pass); |
| 657 | } |
| 658 | |
| 659 | function f_mt_call(inout CallParameters cpars) |
| 660 | runs on BSC_ConnHdlr { |
| 661 | |
| 662 | f_mt_call_establish(cpars); |
| 663 | |
| 664 | /* Hold the call for some time */ |
| 665 | f_sleep(3.0); |
| 666 | |
| 667 | f_call_hangup(cpars, true); |
| 668 | |
| 669 | setverdict(pass); |
| 670 | } |
| 671 | |
| 672 | function f_mo_call(inout CallParameters cpars) |
| 673 | runs on BSC_ConnHdlr { |
| 674 | |
| 675 | f_mo_call_establish(cpars); |
| 676 | |
| 677 | /* Hold the call for some time */ |
| 678 | f_sleep(3.0); |
| 679 | |
| 680 | f_call_hangup(cpars, false); |
| 681 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 682 | setverdict(pass); |
| 683 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 684 | |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 685 | function f_mo_seq_dtmf_dup(inout CallParameters cpars) |
| 686 | runs on BSC_ConnHdlr { |
| 687 | |
| 688 | timer T := 1.0; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 689 | var MNCC_PDU mncc; |
| 690 | var MgcpCommand mgcp_cmd; |
| 691 | var template PDU_ML3_MS_NW dtmf_dtap; |
| 692 | |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 693 | f_establish_fully(); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 694 | |
| 695 | /* Create MNCC and MGCP expect */ |
| 696 | f_create_mncc_expect(hex2str(cpars.called_party)); |
| 697 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 698 | |
| 699 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party))); |
| 700 | MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc; |
| 701 | cpars.mncc_callref := mncc.u.signal.callref; |
| 702 | |
| 703 | /* Send DTMF */ |
| 704 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2"); |
| 705 | dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(2, 2); |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 706 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 707 | T.start; |
| 708 | alt { |
| 709 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {} |
| 710 | [] T.timeout { |
| 711 | setverdict(fail, "Timeout waiting for START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 712 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 716 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 717 | T.start; |
| 718 | alt { |
| 719 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) { |
| 720 | setverdict(fail, "Received duplicate START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 721 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 722 | } |
| 723 | [] T.timeout { } |
| 724 | } |
| 725 | |
| 726 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3"); |
| 727 | dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(3, 2); |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 728 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 729 | alt { |
| 730 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) { } |
| 731 | [] T.timeout { |
| 732 | setverdict(fail, "Received duplicate START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 733 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
| 737 | setverdict(pass); |
| 738 | } |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 739 | /* expect a clear command */ |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 740 | altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr { |
| 741 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) { |
| 742 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 743 | alt { |
| 744 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 745 | setverdict(pass); |
| 746 | } |
| 747 | [] BSSAP.receive { |
| 748 | setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 749 | mtc.stop; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
| 753 | [] BSSAP.receive { |
| 754 | setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 755 | mtc.stop; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 759 | function f_expect_clear(float t := 5.0) runs on BSC_ConnHdlr { |
| 760 | timer T := t; |
| 761 | |
| 762 | T.start; |
| 763 | alt { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 764 | [] as_clear_cmd_compl_disc(t) { } |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 765 | [] T.timeout { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 766 | setverdict(fail, "Timeout waiting for ClearCommand/Release"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 767 | mtc.stop; |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 772 | type record SmsParametersTp { |
| 773 | OCT1 msg_ref, |
| 774 | TP_DA da, |
| 775 | OCT1 pid, |
| 776 | OCT1 dcs, |
| 777 | integer udl, |
| 778 | octetstring ud |
| 779 | } |
| 780 | type record SmsParametersRp { |
| 781 | OCT1 msg_ref, |
| 782 | RP_NumberingPlan_and_NumberDigits orig optional, |
| 783 | RP_NumberingPlan_and_NumberDigits dest optional |
| 784 | } |
| 785 | type record SmsParameters { |
| 786 | SmsParametersTp tp, |
| 787 | SmsParametersRp rp, |
| 788 | uint3_t tid, |
| 789 | OCT1 dlci, |
| 790 | uint7_t exp_rp_err optional |
| 791 | } |
| 792 | |
| 793 | template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := { |
| 794 | tP_DA_NoPad := { |
| 795 | tP_LengthIndicator := 0, /* overwritten */ |
| 796 | tP_NumberingPlanID := npl, |
| 797 | tP_TypeOfNumber := ton, |
| 798 | tp_Spare := '0'B, |
| 799 | tP_DAValue := addr |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := { |
| 804 | tp := { |
| 805 | msg_ref := '23'O, |
| 806 | da := ts_TP_DA('0000'B, '000'B, tp_daddr), |
| 807 | pid := '00'O, |
| 808 | dcs := '00'O, |
| 809 | udl := 0, |
| 810 | ud := ''O |
| 811 | }, |
| 812 | rp := { |
| 813 | msg_ref := '42'O, |
| 814 | orig := omit, |
| 815 | dest := { '0000'B, '000'B, '0'B, '98765'H } |
| 816 | }, |
| 817 | tid := 0, |
| 818 | dlci := '03'O, |
| 819 | exp_rp_err := omit |
| 820 | } |
| 821 | |
| 822 | private altstep as_other_sms() runs on BSC_ConnHdlr { |
| 823 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) { |
| 824 | setverdict(fail, "Unexpected SMS related PDU from MSC"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 825 | mtc.stop; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 829 | /* Submit a MO-SMS over an already existing DTAP connection */ |
| 830 | function f_mo_sms_submit(inout SmsParameters spars) |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 831 | runs on BSC_ConnHdlr { |
| 832 | var template (value) TPDU_RP_DATA_MS_SGSN tp_mo; |
| 833 | var template (value) RPDU_MS_SGSN rp_mo; |
| 834 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 835 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 836 | var default d := activate(as_other_sms()); |
| 837 | |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 838 | /* just in case this is routed to SMPP.. */ |
| 839 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 840 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 841 | tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs, |
| 842 | spars.tp.udl, spars.tp.ud); |
| 843 | rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, spars.rp.orig, spars.rp.dest, tp_mo); |
| 844 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo)); |
| 845 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 846 | /* receive CP-ACK for CP-DATA above */ |
| 847 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci)); |
| 848 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 849 | deactivate(d); |
| 850 | setverdict(pass); |
| 851 | } |
| 852 | |
| 853 | /* Wait RP-ACK for MO-SMS on an already existing DTAP connection */ |
| 854 | function f_mo_sms_wait_rp_ack(inout SmsParameters spars) |
| 855 | runs on BSC_ConnHdlr { |
| 856 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 857 | |
| 858 | var template TPDU_RP_DATA_SGSN_MS tp_mt; |
| 859 | var template RPDU_SGSN_MS rp_mt; |
| 860 | var template PDU_ML3_NW_MS l3_mt; |
| 861 | |
| 862 | var default d := activate(as_other_sms()); |
| 863 | |
| 864 | /* just in case this is routed to SMPP.. */ |
| 865 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 866 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 867 | if (ispresent(spars.exp_rp_err)) { |
| 868 | /* expect an RP-ERROR message from MSC with given cause */ |
| 869 | rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err); |
| 870 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt)); |
| 871 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 872 | /* send CP-ACK for CP-DATA just received */ |
| 873 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO); |
| 874 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 875 | } else { |
| 876 | /* expect RP-ACK for RP-DATA */ |
| 877 | rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref); |
| 878 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt)); |
| 879 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 880 | /* send CP-ACO for CP-DATA just received */ |
| 881 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO); |
| 882 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 883 | } |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 884 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 885 | deactivate(d); |
| 886 | setverdict(pass); |
| 887 | } |
| 888 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 889 | /* Submit a MO-SMS, and wait for RP-ACK on an existing |
| 890 | * (and authenticated, ...) DTAP connection */ |
| 891 | function f_mo_sms(inout SmsParameters spars) |
| 892 | runs on BSC_ConnHdlr { |
| 893 | f_mo_sms_submit(spars); |
| 894 | f_mo_sms_wait_rp_ack(spars); |
| 895 | } |
| 896 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 897 | /* Wait for MT SMS on an already existing DTAP connection */ |
| 898 | function f_mt_sms_expect(inout SmsParameters spars) |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 899 | runs on BSC_ConnHdlr { |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 900 | var template (value) PDU_ML3_MS_NW l3_mo; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 901 | var template TPDU_RP_DATA_SGSN_MS tp_mt; |
| 902 | var template RPDU_SGSN_MS rp_mt; |
| 903 | var template PDU_ML3_NW_MS l3_mt; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 904 | var PDU_DTAP_MT dtap_mt; |
| 905 | |
| 906 | var default d := activate(as_other_sms()); |
| 907 | |
| 908 | /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */ |
| 909 | tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?); |
| 910 | rp_mt := tr_RP_DATA_MT(?, ?, omit, tp_mt); |
| 911 | l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt)); |
| 912 | 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] | 913 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 914 | /* Extract relevant identifiers */ |
| 915 | spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio); |
| 916 | spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference; |
| 917 | |
| 918 | /* send CP-ACK for CP-DATA just received */ |
| 919 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO); |
| 920 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 921 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 922 | deactivate(d); |
| 923 | setverdict(pass); |
| 924 | } |
| 925 | |
| 926 | /* Send RP-ACK for MT-SMS over an already existing DTAP connection */ |
| 927 | function f_mt_sms_send_rp_ack(inout SmsParameters spars) |
| 928 | runs on BSC_ConnHdlr { |
| 929 | var template (value) RPDU_MS_SGSN rp_mo; |
| 930 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 931 | var template PDU_ML3_NW_MS l3_mt; |
| 932 | |
| 933 | var default d := activate(as_other_sms()); |
| 934 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 935 | /* send RP-ACK for RP-DATA */ |
| 936 | rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref); |
| 937 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo)); |
| 938 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 939 | |
| 940 | /* expect CP-ACK for CP-DATA(RP-ACK) just sent */ |
Harald Welte | e008eea | 2018-04-14 21:05:48 +0200 | [diff] [blame] | 941 | 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] | 942 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 943 | |
| 944 | deactivate(d); |
| 945 | setverdict(pass); |
| 946 | } |
| 947 | |
Vadim Yanitskiy | 5631852 | 2018-11-24 03:40:47 +0700 | [diff] [blame] | 948 | /* Send RP-ERROR for MT-SMS over an already existing DTAP connection */ |
| 949 | function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause) |
| 950 | runs on BSC_ConnHdlr { |
| 951 | var template (value) RPDU_MS_SGSN rp_mo; |
| 952 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 953 | var template PDU_ML3_NW_MS l3_mt; |
| 954 | |
| 955 | var default d := activate(as_other_sms()); |
| 956 | |
| 957 | /* send RP-ACK for RP-DATA */ |
| 958 | rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause); |
| 959 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo)); |
| 960 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 961 | |
| 962 | /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */ |
| 963 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT); |
| 964 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 965 | |
| 966 | deactivate(d); |
| 967 | setverdict(pass); |
| 968 | } |
| 969 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 970 | /* Wait for a MT-SMS and send RP-ACK over an already existing |
| 971 | * (and authenticated, ...) DTAP connection */ |
| 972 | function f_mt_sms(inout SmsParameters spars) |
| 973 | runs on BSC_ConnHdlr { |
| 974 | f_mt_sms_expect(spars); |
| 975 | f_mt_sms_send_rp_ack(spars); |
| 976 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 977 | |
| 978 | |
| 979 | |
| 980 | } |
| 981 | |
| 982 | |