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