Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 1 | module SGSN_Tests { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 5 | import from Native_Functions all; |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 6 | import from NS_Types all; |
| 7 | import from NS_Emulation all; |
| 8 | import from BSSGP_Types all; |
| 9 | import from BSSGP_Emulation all; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 10 | import from Osmocom_Gb_Types all; |
| 11 | |
| 12 | import from MobileL3_CommonIE_Types all; |
| 13 | import from MobileL3_GMM_SM_Types all; |
| 14 | import from MobileL3_Types all; |
| 15 | import from L3_Templates all; |
| 16 | import from L3_Common all; |
| 17 | |
| 18 | import from GSUP_Emulation all; |
| 19 | import from GSUP_Types all; |
| 20 | import from IPA_Emulation all; |
| 21 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 22 | import from GTP_Emulation all; |
| 23 | import from GTP_Templates all; |
| 24 | import from GTP_CodecPort all; |
| 25 | import from GTPC_Types all; |
| 26 | import from GTPU_Types all; |
| 27 | |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 28 | import from LLC_Types all; |
| 29 | import from LLC_Templates all; |
| 30 | |
| 31 | import from SNDCP_Types all; |
| 32 | |
Harald Welte | bd19472 | 2018-02-16 22:11:08 +0100 | [diff] [blame] | 33 | import from TELNETasp_PortType all; |
| 34 | import from Osmocom_VTY_Functions all; |
| 35 | |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 36 | import from GSM_RR_Types all; |
| 37 | |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 38 | import from MobileL3_MM_Types all; |
| 39 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 40 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 41 | modulepar { |
| 42 | /* IP/port on which we run our internal GSUP/HLR emulation */ |
| 43 | charstring mp_hlr_ip := "127.0.0.1"; |
| 44 | integer mp_hlr_port := 4222; |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 45 | charstring mp_ggsn_ip := "127.0.0.2"; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | type record GbInstance { |
| 49 | NS_CT vc_NS, |
| 50 | BSSGP_CT vc_BSSGP, |
| 51 | BssgpConfig cfg |
| 52 | }; |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 53 | |
| 54 | type component test_CT { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 55 | var GbInstance g_gb[3]; |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 56 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 57 | var GSUP_Emulation_CT vc_GSUP; |
| 58 | var IPA_Emulation_CT vc_GSUP_IPA; |
| 59 | /* only to get events from IPA underneath GSUP */ |
| 60 | port IPA_CTRL_PT GSUP_IPA_EVENT; |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 61 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 62 | var GTP_Emulation_CT vc_GTP; |
| 63 | |
Harald Welte | bd19472 | 2018-02-16 22:11:08 +0100 | [diff] [blame] | 64 | port TELNETasp_PT SGSNVTY; |
| 65 | |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 66 | var boolean g_initialized := false; |
| 67 | }; |
| 68 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 69 | type component BSSGP_ConnHdlr extends BSSGP_Client_CT, GSUP_ConnHdlr, GTP_ConnHdlr { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 70 | var BSSGP_ConnHdlrPars g_pars; |
Harald Welte | 62e2958 | 2018-02-16 21:17:11 +0100 | [diff] [blame] | 71 | timer g_Tguard; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | type record SGSN_ConnHdlrNetworkPars { |
| 75 | boolean expect_ptmsi, |
| 76 | boolean expect_auth, |
| 77 | boolean expect_ciph |
| 78 | }; |
| 79 | |
| 80 | type record BSSGP_ConnHdlrPars { |
| 81 | /* IMEI of the simulated ME */ |
| 82 | hexstring imei, |
Alexander Couzens | 8f0fb00 | 2018-05-02 19:30:55 +0200 | [diff] [blame] | 83 | /* IMSI of the simulated MS */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 84 | hexstring imsi, |
| 85 | /* MSISDN of the simulated MS (probably unused) */ |
| 86 | hexstring msisdn, |
| 87 | /* P-TMSI allocated to the simulated MS */ |
| 88 | OCT4 p_tmsi optional, |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 89 | OCT3 p_tmsi_sig optional, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 90 | /* TLLI of the simulated MS */ |
| 91 | OCT4 tlli, |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 92 | OCT4 tlli_old optional, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 93 | RoutingAreaIdentificationV ra optional, |
| 94 | BssgpCellId bssgp_cell_id, |
| 95 | AuthVector vec optional, |
Harald Welte | 62e2958 | 2018-02-16 21:17:11 +0100 | [diff] [blame] | 96 | SGSN_ConnHdlrNetworkPars net, |
| 97 | float t_guard |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Harald Welte | 3fdbe82 | 2018-02-18 19:10:18 +0100 | [diff] [blame] | 100 | private function f_init_gb(inout GbInstance gb, charstring id) runs on test_CT { |
| 101 | gb.vc_NS := NS_CT.create(id & "-NS"); |
| 102 | gb.vc_BSSGP := BSSGP_CT.create(id & "-BSSGP"); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 103 | /* connect lower end of BSSGP emulation with NS upper port */ |
| 104 | connect(gb.vc_BSSGP:BSCP, gb.vc_NS:NS_SP); |
| 105 | /* connect lower end of NS emulation to NS codec port (on top of IPL4) */ |
| 106 | map(gb.vc_NS:NSCP, system:NS_CODEC_PORT); |
| 107 | |
| 108 | gb.vc_NS.start(NSStart()); |
| 109 | gb.vc_BSSGP.start(BssgpStart(gb.cfg)); |
| 110 | } |
| 111 | |
| 112 | private function f_init_gsup(charstring id) runs on test_CT { |
| 113 | id := id & "-GSUP"; |
| 114 | var GsupOps ops := { |
| 115 | create_cb := refers(GSUP_Emulation.ExpectedCreateCallback) |
| 116 | }; |
| 117 | |
| 118 | vc_GSUP_IPA := IPA_Emulation_CT.create(id & "-IPA"); |
| 119 | vc_GSUP := GSUP_Emulation_CT.create(id); |
| 120 | |
| 121 | map(vc_GSUP_IPA:IPA_PORT, system:IPA_CODEC_PT); |
| 122 | connect(vc_GSUP:GSUP, vc_GSUP_IPA:IPA_GSUP_PORT); |
| 123 | /* we use this hack to get events like ASP_IPA_EVENT_UP */ |
| 124 | connect(vc_GSUP_IPA:IPA_CTRL_PORT, self:GSUP_IPA_EVENT); |
| 125 | |
| 126 | vc_GSUP.start(GSUP_Emulation.main(ops, id)); |
| 127 | vc_GSUP_IPA.start(IPA_Emulation.main_server(mp_hlr_ip, mp_hlr_port)); |
| 128 | |
| 129 | /* wait for incoming connection to GSUP port before proceeding */ |
| 130 | timer T := 10.0; |
| 131 | T.start; |
| 132 | alt { |
| 133 | [] GSUP_IPA_EVENT.receive(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_UP)) { } |
| 134 | [] T.timeout { |
| 135 | setverdict(fail, "No connection to GSUP Port"); |
| 136 | self.stop; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 141 | private function f_init_gtp(charstring id) runs on test_CT { |
| 142 | id := id & "-GTP"; |
| 143 | |
| 144 | var GtpEmulationCfg gtp_cfg := { |
| 145 | gtpc_bind_ip := mp_ggsn_ip, |
| 146 | gtpc_bind_port := GTP1C_PORT, |
| 147 | gtpu_bind_ip := mp_ggsn_ip, |
| 148 | gtpu_bind_port := GTP1U_PORT, |
| 149 | sgsn_role := false |
| 150 | }; |
| 151 | |
| 152 | vc_GTP := GTP_Emulation_CT.create(id); |
| 153 | vc_GTP.start(GTP_Emulation.main(gtp_cfg)); |
| 154 | } |
| 155 | |
Harald Welte | bd19472 | 2018-02-16 22:11:08 +0100 | [diff] [blame] | 156 | private function f_init_vty() runs on test_CT { |
| 157 | map(self:SGSNVTY, system:SGSNVTY); |
| 158 | f_vty_set_prompts(SGSNVTY); |
| 159 | f_vty_transceive(SGSNVTY, "enable"); |
| 160 | f_vty_config(SGSNVTY, "sgsn", "auth-policy remote"); |
| 161 | } |
| 162 | |
| 163 | |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 164 | function f_init(BcdMccMnc mcc_mnc := '26242F'H) runs on test_CT { |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 165 | if (g_initialized == true) { |
| 166 | return; |
| 167 | } |
| 168 | g_initialized := true; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 169 | g_gb[0].cfg := { |
| 170 | nsei := 96, |
| 171 | bvci := 196, |
| 172 | cell_id := { |
| 173 | ra_id := { |
| 174 | lai := { |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 175 | mcc_mnc := mcc_mnc, lac := 13135}, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 176 | rac := 0 |
| 177 | }, |
| 178 | cell_id := 20960 |
| 179 | }, |
| 180 | sgsn_role := false |
| 181 | }; |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 182 | |
Harald Welte | 3fdbe82 | 2018-02-18 19:10:18 +0100 | [diff] [blame] | 183 | f_init_gb(g_gb[0], "SGSN_Test-Gb0"); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 184 | f_init_gsup("SGSN_Test"); |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 185 | f_init_gtp("SGSN_Test"); |
Harald Welte | bd19472 | 2018-02-16 22:11:08 +0100 | [diff] [blame] | 186 | f_init_vty(); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 187 | } |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 188 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 189 | type function void_fn(charstring id) runs on BSSGP_ConnHdlr; |
| 190 | |
| 191 | /* helper function to create, connect and start a BSSGP_ConnHdlr component */ |
Harald Welte | 62e2958 | 2018-02-16 21:17:11 +0100 | [diff] [blame] | 192 | function f_start_handler(void_fn fn, charstring id, GbInstance gb, integer imsi_suffix, |
| 193 | float t_guard := 30.0) |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 194 | runs on test_CT return BSSGP_ConnHdlr { |
| 195 | var BSSGP_ConnHdlr vc_conn; |
| 196 | var SGSN_ConnHdlrNetworkPars net_pars := { |
| 197 | expect_ptmsi := true, |
| 198 | expect_auth := true, |
| 199 | expect_ciph := false |
| 200 | }; |
| 201 | var BSSGP_ConnHdlrPars pars := { |
| 202 | imei := f_gen_imei(imsi_suffix), |
| 203 | imsi := f_gen_imsi(imsi_suffix), |
| 204 | msisdn := f_gen_msisdn(imsi_suffix), |
| 205 | p_tmsi := omit, |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 206 | p_tmsi_sig := omit, |
Harald Welte | 14a0f94 | 2018-02-16 20:42:23 +0100 | [diff] [blame] | 207 | tlli := f_gprs_tlli_random(), |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 208 | tlli_old := omit, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 209 | ra := omit, |
| 210 | bssgp_cell_id := gb.cfg.cell_id, |
| 211 | vec := omit, |
Harald Welte | 62e2958 | 2018-02-16 21:17:11 +0100 | [diff] [blame] | 212 | net := net_pars, |
| 213 | t_guard := t_guard |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | vc_conn := BSSGP_ConnHdlr.create(id); |
| 217 | connect(vc_conn:BSSGP, gb.vc_BSSGP:BSSGP_SP); |
| 218 | connect(vc_conn:BSSGP_PROC, gb.vc_BSSGP:BSSGP_PROC); |
| 219 | |
| 220 | connect(vc_conn:GSUP, vc_GSUP:GSUP_CLIENT); |
| 221 | connect(vc_conn:GSUP_PROC, vc_GSUP:GSUP_PROC); |
| 222 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 223 | connect(vc_conn:GTP, vc_GTP:CLIENT); |
| 224 | connect(vc_conn:GTP_PROC, vc_GTP:CLIENT_PROC); |
| 225 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 226 | vc_conn.start(f_handler_init(fn, id, pars)); |
| 227 | return vc_conn; |
| 228 | } |
| 229 | |
Harald Welte | 62e2958 | 2018-02-16 21:17:11 +0100 | [diff] [blame] | 230 | private altstep as_Tguard() runs on BSSGP_ConnHdlr { |
| 231 | [] g_Tguard.timeout { |
| 232 | setverdict(fail, "Tguard timeout"); |
| 233 | self.stop; |
| 234 | } |
| 235 | } |
| 236 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 237 | /* first function called in every ConnHdlr */ |
| 238 | private function f_handler_init(void_fn fn, charstring id, BSSGP_ConnHdlrPars pars) |
| 239 | runs on BSSGP_ConnHdlr { |
| 240 | /* do some common stuff like setting up g_pars */ |
| 241 | g_pars := pars; |
| 242 | |
| 243 | /* register with BSSGP core */ |
| 244 | f_bssgp_client_register(g_pars.imsi, g_pars.tlli, g_pars.bssgp_cell_id); |
| 245 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 246 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 247 | /* tell GTP dispatcher to send this IMSI to us */ |
| 248 | f_gtp_register_imsi(g_pars.imsi); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 249 | |
Harald Welte | 62e2958 | 2018-02-16 21:17:11 +0100 | [diff] [blame] | 250 | g_Tguard.start(pars.t_guard); |
| 251 | activate(as_Tguard()); |
| 252 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 253 | /* call the user-supplied test case function */ |
| 254 | fn.apply(id); |
| 255 | f_bssgp_client_unregister(g_pars.imsi); |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /* TODO: |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 259 | * Detach without Attach |
| 260 | * SM procedures without attach / RAU |
| 261 | * ATTACH / RAU |
| 262 | ** with / without authentication |
| 263 | ** with / without P-TMSI allocation |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 264 | * re-transmissions of LLC frames |
| 265 | * PDP Context activation |
| 266 | ** with different GGSN config in SGSN VTY |
| 267 | ** with different PDP context type (v4/v6/v46) |
| 268 | ** timeout from GGSN |
Harald Welte | 6f20316 | 2018-02-18 22:04:55 +0100 | [diff] [blame] | 269 | ** multiple / secondary PDP context |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 270 | */ |
| 271 | |
| 272 | testcase TC_wait_ns_up() runs on test_CT { |
| 273 | f_init(); |
| 274 | f_sleep(20.0); |
| 275 | } |
| 276 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 277 | altstep as_mm_identity() runs on BSSGP_ConnHdlr { |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 278 | var MobileL3_CommonIE_Types.MobileIdentityLV mi; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 279 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ID_REQ('001'B))) { |
| 280 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 281 | BSSGP.send(ts_GMM_ID_RESP(mi)); |
| 282 | repeat; |
| 283 | } |
| 284 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ID_REQ('010'B))) { |
| 285 | mi := valueof(ts_MI_IMEI_LV(g_pars.imei)); |
| 286 | BSSGP.send(ts_GMM_ID_RESP(mi)); |
| 287 | repeat; |
| 288 | } |
| 289 | } |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 290 | |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 291 | /* perform GMM authentication (if expected). |
| 292 | * Note, for umts_aka_challenge to work, the revisionLevelIndicatior needs to |
| 293 | * be 1 to mark R99 capability, in the GMM Attach Request, see f_gmm_attach(). */ |
| 294 | function f_gmm_auth (boolean umts_aka_challenge := false, boolean force_gsm_sres := false) runs on BSSGP_ConnHdlr { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 295 | var BssgpDecoded bd; |
| 296 | var PDU_L3_MS_SGSN l3_mo; |
| 297 | var PDU_L3_SGSN_MS l3_mt; |
| 298 | var default di := activate(as_mm_identity()); |
| 299 | if (g_pars.net.expect_auth) { |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 300 | var GSUP_IE auth_tuple; |
| 301 | var template AuthenticationParameterAUTNTLV autn; |
| 302 | |
| 303 | if (umts_aka_challenge) { |
| 304 | g_pars.vec := f_gen_auth_vec_3g(); |
| 305 | autn := { |
| 306 | elementIdentifier := '28'O, |
| 307 | lengthIndicator := lengthof(g_pars.vec.autn), |
| 308 | autnValue := g_pars.vec.autn |
| 309 | }; |
| 310 | |
| 311 | auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand, |
| 312 | g_pars.vec.sres, |
| 313 | g_pars.vec.kc, |
| 314 | g_pars.vec.ik, |
| 315 | g_pars.vec.ck, |
| 316 | g_pars.vec.autn, |
| 317 | g_pars.vec.res)); |
| 318 | log("GSUP sends 2G and 3G auth tuples", auth_tuple); |
| 319 | } else { |
| 320 | g_pars.vec := f_gen_auth_vec_2g(); |
| 321 | autn := omit; |
| 322 | auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand, |
| 323 | g_pars.vec.sres, |
| 324 | g_pars.vec.kc)); |
| 325 | log("GSUP sends only 2G auth tuple", auth_tuple); |
| 326 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 327 | GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); |
| 328 | GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple)); |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 329 | |
| 330 | var template PDU_L3_SGSN_MS auth_ciph_req := tr_GMM_AUTH_REQ(g_pars.vec.rand); |
| 331 | auth_ciph_req.msgs.gprs_mm.authenticationAndCipheringRequest.authenticationParameterAUTN := autn; |
| 332 | BSSGP.receive(tr_BD_L3_MT(auth_ciph_req)) -> value bd; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 333 | l3_mt := bd.l3_mt; |
| 334 | var BIT4 ac_ref := l3_mt.msgs.gprs_mm.authenticationAndCipheringRequest.acReferenceNumber.valueField; |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 335 | var template PDU_L3_MS_SGSN auth_ciph_resp := ts_GMM_AUTH_RESP_2G(ac_ref, g_pars.vec.sres); |
| 336 | |
| 337 | if (umts_aka_challenge and not force_gsm_sres) { |
| 338 | /* set UMTS response instead */ |
| 339 | auth_ciph_resp.msgs.gprs_mm.authenticationAndCipheringResponse.authenticationParResp := { |
| 340 | valueField := substr(g_pars.vec.res, 0, 4) |
| 341 | }; |
| 342 | auth_ciph_resp.msgs.gprs_mm.authenticationAndCipheringResponse.authenticationRespParExt := { |
| 343 | elementIdentifier := '21'O, |
| 344 | lengthIndicator := lengthof(g_pars.vec.res) - 4, |
| 345 | valueField := substr(g_pars.vec.res, 4, lengthof(g_pars.vec.res) - 4) |
| 346 | }; |
| 347 | } |
| 348 | |
| 349 | l3_mo := valueof(auth_ciph_resp); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 350 | if (ispresent(l3_mt.msgs.gprs_mm.authenticationAndCipheringRequest.imeisvRequest) and |
| 351 | l3_mt.msgs.gprs_mm.authenticationAndCipheringRequest.imeisvRequest.valueField == '001'B) { |
| 352 | l3_mo.msgs.gprs_mm.authenticationAndCipheringResponse.imeisv := |
| 353 | valueof(ts_MI_IMEISV_TLV(g_pars.imei & '0'H)); |
| 354 | } |
| 355 | BSSGP.send(l3_mo); |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 356 | } else { |
| 357 | /* wait for identity procedure */ |
| 358 | f_sleep(1.0); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 359 | } |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 360 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 361 | deactivate(di); |
| 362 | } |
| 363 | |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 364 | function f_upd_ptmsi_and_tlli(OCT4 p_tmsi) runs on BSSGP_ConnHdlr { |
| 365 | g_pars.p_tmsi := p_tmsi; |
| 366 | /* update TLLI */ |
| 367 | g_pars.tlli_old := g_pars.tlli; |
| 368 | g_pars.tlli := g_pars.p_tmsi or4b 'c0000000'O; |
| 369 | f_bssgp_client_llgmm_assign(g_pars.tlli_old, g_pars.tlli); |
| 370 | } |
| 371 | |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 372 | function f_process_attach_accept(PDU_GMM_AttachAccept aa) runs on BSSGP_ConnHdlr { |
| 373 | /* mandatory IE */ |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 374 | var hexstring aa_plmn := f_RAI_to_plmn_hexstr(aa.routingAreaIdentification); |
| 375 | if (not (g_pars.bssgp_cell_id.ra_id.lai.mcc_mnc == aa_plmn)) { |
| 376 | setverdict(fail, "mismatching PLMN in Attach Accept: " & hex2str(aa_plmn) |
| 377 | & "; expected " & hex2str(g_pars.bssgp_cell_id.ra_id.lai.mcc_mnc)); |
| 378 | self.stop; |
| 379 | } |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 380 | g_pars.ra := aa.routingAreaIdentification; |
| 381 | if (ispresent(aa.allocatedPTMSI)) { |
| 382 | if (not g_pars.net.expect_ptmsi) { |
| 383 | setverdict(fail, "unexpected P-TMSI allocation"); |
| 384 | self.stop; |
| 385 | } |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 386 | f_upd_ptmsi_and_tlli(aa.allocatedPTMSI.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets); |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 387 | } |
| 388 | if (ispresent(aa.msIdentity)) { |
| 389 | setverdict(fail, "unexpected TMSI allocation in non-combined attach"); |
| 390 | self.stop; |
| 391 | } |
| 392 | /* P-TMSI.sig */ |
| 393 | if (ispresent(aa.ptmsiSignature)) { |
| 394 | g_pars.p_tmsi_sig := aa.ptmsiSignature.valueField; |
| 395 | } |
| 396 | /* updateTimer */ |
| 397 | // aa.readyTimer |
| 398 | /* T3302, T3319, T3323, T3312_ext, T3324 */ |
| 399 | } |
| 400 | |
Harald Welte | 91636de | 2018-02-17 10:16:14 +0100 | [diff] [blame] | 401 | function f_process_rau_accept(PDU_GMM_RoutingAreaUpdateAccept ra) runs on BSSGP_ConnHdlr { |
| 402 | /* mandatory IE */ |
| 403 | g_pars.ra := ra.routingAreaId; |
| 404 | if (ispresent(ra.allocatedPTMSI)) { |
| 405 | if (not g_pars.net.expect_ptmsi) { |
| 406 | setverdict(fail, "unexpected P-TMSI allocation"); |
| 407 | self.stop; |
| 408 | } |
| 409 | f_upd_ptmsi_and_tlli(ra.allocatedPTMSI.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets); |
| 410 | } |
| 411 | if (ispresent(ra.msIdentity)) { |
| 412 | setverdict(fail, "unexpected TMSI allocation in non-combined attach"); |
| 413 | self.stop; |
| 414 | } |
| 415 | /* P-TMSI.sig */ |
| 416 | if (ispresent(ra.ptmsiSignature)) { |
| 417 | g_pars.p_tmsi_sig := ra.ptmsiSignature.valueField; |
| 418 | } |
| 419 | /* updateTimer */ |
| 420 | // aa.readyTimer |
| 421 | /* T3302, T3319, T3323, T3312_ext, T3324 */ |
| 422 | } |
| 423 | |
| 424 | |
Harald Welte | 5a4fa04 | 2018-02-16 20:59:21 +0100 | [diff] [blame] | 425 | function f_random_RAI(HEX0_3n mcc := '262'H, HEX0_3n mnc := '42'H) return RoutingAreaIdentificationV { |
| 426 | return f_RAI(mcc, mnc, f_rnd_octstring(2), f_rnd_octstring(1)); |
| 427 | } |
| 428 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 429 | /* return a MobileIdentityLV: P-TMSI if we have one, IMSI otherwise */ |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 430 | private function f_mi_get_lv() runs on BSSGP_ConnHdlr return MobileL3_CommonIE_Types.MobileIdentityLV { |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 431 | if (ispresent(g_pars.p_tmsi)) { |
| 432 | return valueof(ts_MI_TMSI_LV(g_pars.p_tmsi)); |
| 433 | } else { |
| 434 | return valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 435 | } |
| 436 | } |
| 437 | |
Harald Welte | 311ec27 | 2018-02-17 09:40:03 +0100 | [diff] [blame] | 438 | private function f_gmm_gsup_lu_isd() runs on BSSGP_ConnHdlr { |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 439 | var GSUP_PDU gsup; |
Harald Welte | 311ec27 | 2018-02-17 09:40:03 +0100 | [diff] [blame] | 440 | /* Expect MSC to perform LU with HLR */ |
| 441 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 442 | gsup := valueof(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn)); |
| 443 | gsup.ies := gsup.ies & { valueof(ts_GSUP_IE_PdpInfo(char2oct("*"), '0121'O, ''O)) }; |
| 444 | GSUP.send(gsup); |
Harald Welte | 311ec27 | 2018-02-17 09:40:03 +0100 | [diff] [blame] | 445 | GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi)); |
| 446 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 447 | } |
| 448 | |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 449 | private function f_gmm_attach(boolean umts_aka_challenge, boolean force_gsm_sres) runs on BSSGP_ConnHdlr { |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 450 | var BssgpDecoded bd; |
Harald Welte | 5a4fa04 | 2018-02-16 20:59:21 +0100 | [diff] [blame] | 451 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 452 | var template PDU_L3_MS_SGSN attach_req := ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 453 | |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 454 | /* indicate R99 capability of the MS to enable UMTS AKA in presence of |
| 455 | * 3G auth vectors */ |
| 456 | attach_req.msgs.gprs_mm.attachRequest.msNetworkCapability.msNetworkCapabilityV.revisionLevelIndicatior := '1'B; |
| 457 | /* The thing is, if the solSACapability is 'omit', then the |
| 458 | * revisionLevelIndicatior is at the wrong place! */ |
| 459 | attach_req.msgs.gprs_mm.attachRequest.msNetworkCapability.msNetworkCapabilityV.solSACapability := '0'B; |
| 460 | |
| 461 | BSSGP.send(attach_req); |
| 462 | f_gmm_auth(umts_aka_challenge, force_gsm_sres); |
Alexander Couzens | 5844d5b | 2018-05-14 06:30:56 +0200 | [diff] [blame] | 463 | /* Expect SGSN to perform LU with HLR */ |
Harald Welte | 311ec27 | 2018-02-17 09:40:03 +0100 | [diff] [blame] | 464 | f_gmm_gsup_lu_isd(); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 465 | |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 466 | BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_ACCEPT('001'B, ?, ?))) -> value bd { |
| 467 | f_process_attach_accept(bd.l3_mt.msgs.gprs_mm.attachAccept); |
| 468 | } |
| 469 | /* FIXME: Extract P-TMSI, if any. Only send Complete if necessary */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 470 | BSSGP.send(ts_GMM_ATTACH_COMPL); |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | private function f_TC_attach(charstring id) runs on BSSGP_ConnHdlr { |
| 474 | f_gmm_attach(false, false); |
Harald Welte | 5a4fa04 | 2018-02-16 20:59:21 +0100 | [diff] [blame] | 475 | setverdict(pass); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | testcase TC_attach() runs on test_CT { |
| 479 | var BSSGP_ConnHdlr vc_conn; |
| 480 | f_init(); |
| 481 | f_sleep(1.0); |
| 482 | vc_conn := f_start_handler(refers(f_TC_attach), testcasename(), g_gb[0], 1); |
| 483 | vc_conn.done; |
| 484 | } |
| 485 | |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 486 | testcase TC_attach_mnc3() runs on test_CT { |
| 487 | var BSSGP_ConnHdlr vc_conn; |
| 488 | f_init('023042'H); |
| 489 | f_sleep(1.0); |
| 490 | vc_conn := f_start_handler(refers(f_TC_attach), testcasename(), g_gb[0], 1001); |
| 491 | vc_conn.done; |
| 492 | } |
| 493 | |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 494 | private function f_TC_attach_umts_aka_umts_res(charstring id) runs on BSSGP_ConnHdlr { |
| 495 | f_gmm_attach(true, false); |
| 496 | setverdict(pass); |
| 497 | } |
| 498 | testcase TC_attach_umts_aka_umts_res() runs on test_CT { |
| 499 | var BSSGP_ConnHdlr vc_conn; |
| 500 | f_init(); |
| 501 | f_sleep(1.0); |
| 502 | vc_conn := f_start_handler(refers(f_TC_attach_umts_aka_umts_res), testcasename(), g_gb[0], 1002); |
| 503 | vc_conn.done; |
| 504 | } |
| 505 | |
| 506 | private function f_TC_attach_umts_aka_gsm_sres(charstring id) runs on BSSGP_ConnHdlr { |
| 507 | f_gmm_attach(true, true); |
| 508 | setverdict(pass); |
| 509 | } |
| 510 | testcase TC_attach_umts_aka_gsm_sres() runs on test_CT { |
| 511 | var BSSGP_ConnHdlr vc_conn; |
| 512 | f_init(); |
| 513 | f_sleep(1.0); |
| 514 | vc_conn := f_start_handler(refers(f_TC_attach_umts_aka_gsm_sres), testcasename(), g_gb[0], 1003); |
| 515 | vc_conn.done; |
| 516 | } |
| 517 | |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 518 | /* MS never responds to ID REQ, expect ATTACH REJECT */ |
| 519 | private function f_TC_attach_auth_id_timeout(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 520 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 521 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 522 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit)); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 523 | alt { |
Harald Welte | 1967d47 | 2018-02-16 21:54:21 +0100 | [diff] [blame] | 524 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ID_REQ(?))) { |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 525 | /* don't send ID Response */ |
| 526 | repeat; |
| 527 | } |
Harald Welte | 1967d47 | 2018-02-16 21:54:21 +0100 | [diff] [blame] | 528 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT('09'O))) { |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 529 | setverdict(pass); |
| 530 | } |
Harald Welte | 1967d47 | 2018-02-16 21:54:21 +0100 | [diff] [blame] | 531 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))) { |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 532 | setverdict(fail, "Wrong Attach Reject Cause"); |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | testcase TC_attach_auth_id_timeout() runs on test_CT { |
| 537 | var BSSGP_ConnHdlr vc_conn; |
| 538 | f_init(); |
| 539 | vc_conn := f_start_handler(refers(f_TC_attach_auth_id_timeout), testcasename(), g_gb[0], 2, 40.0); |
| 540 | vc_conn.done; |
| 541 | } |
| 542 | |
| 543 | /* HLR never responds to SAI REQ, expect ATTACH REJECT */ |
| 544 | private function f_TC_attach_auth_sai_timeout(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 545 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 546 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 547 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit)); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 548 | alt { |
| 549 | [] as_mm_identity(); |
| 550 | [] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); { } |
| 551 | } |
| 552 | /* don't send SAI-response from HLR */ |
Harald Welte | 1967d47 | 2018-02-16 21:54:21 +0100 | [diff] [blame] | 553 | BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 554 | setverdict(pass); |
| 555 | } |
| 556 | testcase TC_attach_auth_sai_timeout() runs on test_CT { |
| 557 | var BSSGP_ConnHdlr vc_conn; |
| 558 | f_init(); |
| 559 | vc_conn := f_start_handler(refers(f_TC_attach_auth_sai_timeout), testcasename(), g_gb[0], 3); |
| 560 | vc_conn.done; |
| 561 | } |
| 562 | |
Harald Welte | fe25388 | 2018-02-17 09:25:00 +0100 | [diff] [blame] | 563 | /* HLR rejects SAI, expect ATTACH REJECT */ |
| 564 | private function f_TC_attach_auth_sai_reject(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | fe25388 | 2018-02-17 09:25:00 +0100 | [diff] [blame] | 565 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 566 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 567 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit)); |
Harald Welte | fe25388 | 2018-02-17 09:25:00 +0100 | [diff] [blame] | 568 | alt { |
| 569 | [] as_mm_identity(); |
| 570 | [] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); { |
| 571 | GSUP.send(ts_GSUP_SAI_ERR(g_pars.imsi, 23)); |
| 572 | } |
| 573 | } |
| 574 | BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))); |
| 575 | setverdict(pass); |
| 576 | } |
| 577 | testcase TC_attach_auth_sai_reject() runs on test_CT { |
| 578 | var BSSGP_ConnHdlr vc_conn; |
| 579 | f_init(); |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 580 | vc_conn := f_start_handler(refers(f_TC_attach_auth_sai_reject), testcasename(), g_gb[0], 4); |
Harald Welte | fe25388 | 2018-02-17 09:25:00 +0100 | [diff] [blame] | 581 | vc_conn.done; |
| 582 | } |
| 583 | |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 584 | /* HLR never responds to UL REQ, expect ATTACH REJECT */ |
| 585 | private function f_TC_attach_gsup_lu_timeout(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 586 | var BssgpDecoded bd; |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 587 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 588 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 589 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit)); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 590 | f_gmm_auth(); |
| 591 | /* Expect MSC to perform LU with HLR */ |
| 592 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
| 593 | /* Never follow-up with ISD_REQ or UL_RES */ |
| 594 | alt { |
Harald Welte | 1967d47 | 2018-02-16 21:54:21 +0100 | [diff] [blame] | 595 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))) { |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 596 | setverdict(pass); |
| 597 | } |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 598 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_ACCEPT('001'B, ?, ?))) -> value bd { |
| 599 | f_process_attach_accept(bd.l3_mt.msgs.gprs_mm.attachAccept); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 600 | setverdict(fail); |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | testcase TC_attach_gsup_lu_timeout() runs on test_CT { |
| 605 | var BSSGP_ConnHdlr vc_conn; |
| 606 | f_init(); |
| 607 | f_sleep(1.0); |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 608 | vc_conn := f_start_handler(refers(f_TC_attach_gsup_lu_timeout), testcasename(), g_gb[0], 5); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 609 | vc_conn.done; |
| 610 | } |
| 611 | |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 612 | /* HLR rejects UL REQ, expect ATTACH REJECT */ |
| 613 | private function f_TC_attach_gsup_lu_reject(charstring id) runs on BSSGP_ConnHdlr { |
| 614 | var BssgpDecoded bd; |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 615 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 616 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 617 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit)); |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 618 | f_gmm_auth(); |
| 619 | /* Expect MSC to perform LU with HLR */ |
| 620 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)) { |
| 621 | GSUP.send(ts_GSUP_UL_ERR(g_pars.imsi, 0)); |
| 622 | } |
| 623 | alt { |
| 624 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))) { |
| 625 | setverdict(pass); |
| 626 | } |
| 627 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_ACCEPT('001'B, ?, ?))) -> value bd { |
| 628 | f_process_attach_accept(bd.l3_mt.msgs.gprs_mm.attachAccept); |
| 629 | setverdict(fail); |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | testcase TC_attach_gsup_lu_reject() runs on test_CT { |
| 634 | var BSSGP_ConnHdlr vc_conn; |
| 635 | f_init(); |
| 636 | f_sleep(1.0); |
| 637 | vc_conn := f_start_handler(refers(f_TC_attach_gsup_lu_reject), testcasename(), g_gb[0], 6); |
| 638 | vc_conn.done; |
| 639 | } |
| 640 | |
| 641 | |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 642 | /* Attempt of combined GPRS + IMSI attach: network should ACK only GPRS attach */ |
| 643 | private function f_TC_attach_combined(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 644 | var BssgpDecoded bd; |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 645 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 646 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 647 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, true, false, omit, omit)); |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 648 | f_gmm_auth(); |
| 649 | /* Expect MSC to perform LU with HLR */ |
Harald Welte | 311ec27 | 2018-02-17 09:40:03 +0100 | [diff] [blame] | 650 | f_gmm_gsup_lu_isd(); |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 651 | |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 652 | BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_ACCEPT('001'B, ?, ?))) -> value bd { |
| 653 | f_process_attach_accept(bd.l3_mt.msgs.gprs_mm.attachAccept); |
| 654 | } |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 655 | BSSGP.send(ts_GMM_ATTACH_COMPL); |
| 656 | setverdict(pass); |
| 657 | } |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 658 | testcase TC_attach_combined() runs on test_CT { |
| 659 | var BSSGP_ConnHdlr vc_conn; |
| 660 | f_init(); |
| 661 | f_sleep(1.0); |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 662 | vc_conn := f_start_handler(refers(f_TC_attach_combined), testcasename(), g_gb[0], 7); |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 663 | vc_conn.done; |
| 664 | } |
| 665 | |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 666 | /* Attempt of GPRS ATTACH in 'accept all' mode */ |
| 667 | private function f_TC_attach_accept_all(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 668 | var BssgpDecoded bd; |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 669 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 670 | |
| 671 | g_pars.net.expect_auth := false; |
| 672 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 673 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit)); |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 674 | f_gmm_auth(); |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 675 | BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_ACCEPT('001'B, ?, ?))) -> value bd { |
| 676 | f_process_attach_accept(bd.l3_mt.msgs.gprs_mm.attachAccept); |
| 677 | } |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 678 | BSSGP.send(ts_GMM_ATTACH_COMPL); |
| 679 | setverdict(pass); |
| 680 | } |
| 681 | testcase TC_attach_accept_all() runs on test_CT { |
| 682 | var BSSGP_ConnHdlr vc_conn; |
| 683 | f_init(); |
| 684 | f_sleep(1.0); |
| 685 | f_vty_config(SGSNVTY, "sgsn", "auth-policy accept-all"); |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 686 | vc_conn := f_start_handler(refers(f_TC_attach_accept_all), testcasename(), g_gb[0], 8); |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 687 | vc_conn.done; |
| 688 | } |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 689 | |
Harald Welte | b2124b2 | 2018-02-16 22:26:56 +0100 | [diff] [blame] | 690 | /* Attempt of GPRS ATTACH in 'accept all' mode */ |
| 691 | private function f_TC_attach_closed_foreign(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | b2124b2 | 2018-02-16 22:26:56 +0100 | [diff] [blame] | 692 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 693 | |
| 694 | /* Simulate a foreign IMSI */ |
| 695 | g_pars.imsi := '001010123456789'H; |
| 696 | f_bssgp_client_register(g_pars.imsi, g_pars.tlli, g_pars.bssgp_cell_id); |
| 697 | |
| 698 | g_pars.net.expect_auth := false; |
| 699 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 700 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), old_ra, false, false, omit, omit)); |
Harald Welte | b2124b2 | 2018-02-16 22:26:56 +0100 | [diff] [blame] | 701 | alt { |
| 702 | [] as_mm_identity(); |
| 703 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT('07'O))) { |
| 704 | setverdict(pass); |
| 705 | } |
| 706 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))) { |
| 707 | setverdict(pass); |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | testcase TC_attach_closed() runs on test_CT { |
| 712 | var BSSGP_ConnHdlr vc_conn; |
| 713 | f_init(); |
| 714 | f_sleep(1.0); |
| 715 | f_vty_config(SGSNVTY, "sgsn", "auth-policy closed"); |
| 716 | /* test with foreign IMSI: Must Reject */ |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 717 | vc_conn := f_start_handler(refers(f_TC_attach_closed_foreign), testcasename(), g_gb[0], 9); |
Harald Welte | b2124b2 | 2018-02-16 22:26:56 +0100 | [diff] [blame] | 718 | vc_conn.done; |
| 719 | /* test with home IMSI: Must Accept */ |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 720 | vc_conn := f_start_handler(refers(f_TC_attach_accept_all), testcasename(), g_gb[0], 10); |
Harald Welte | b2124b2 | 2018-02-16 22:26:56 +0100 | [diff] [blame] | 721 | vc_conn.done; |
| 722 | } |
| 723 | |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 724 | /* Routing Area Update from Unknown TLLI -> REJECT */ |
| 725 | private function f_TC_rau_unknown(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 726 | var RoutingAreaIdentificationV old_ra := f_random_RAI(); |
| 727 | |
Harald Welte | 23178c5 | 2018-02-17 09:36:33 +0100 | [diff] [blame] | 728 | BSSGP.send(ts_GMM_RAU_REQ(f_mi_get_lv(), GPRS_UPD_T_RA, old_ra, false, omit, omit)); |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 729 | alt { |
| 730 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_RAU_REJECT('0a'O))) { |
| 731 | setverdict(pass); |
| 732 | } |
| 733 | /* FIXME: Expect XID RESET? */ |
| 734 | [] BSSGP.receive { repeat; } |
| 735 | } |
| 736 | } |
| 737 | testcase TC_rau_unknown() runs on test_CT { |
| 738 | var BSSGP_ConnHdlr vc_conn; |
| 739 | f_init(); |
| 740 | f_sleep(1.0); |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 741 | vc_conn := f_start_handler(refers(f_TC_rau_unknown), testcasename(), g_gb[0], 11); |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 742 | vc_conn.done; |
| 743 | } |
| 744 | |
Harald Welte | 91636de | 2018-02-17 10:16:14 +0100 | [diff] [blame] | 745 | private function f_TC_attach_rau(charstring id) runs on BSSGP_ConnHdlr { |
| 746 | var BssgpDecoded bd; |
| 747 | |
| 748 | /* first perform regular attach */ |
| 749 | f_TC_attach(id); |
| 750 | |
| 751 | /* then send RAU */ |
| 752 | BSSGP.send(ts_GMM_RAU_REQ(f_mi_get_lv(), GPRS_UPD_T_RA, g_pars.ra, false, omit, omit)); |
| 753 | alt { |
| 754 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_RAU_ACCEPT)) -> value bd { |
| 755 | f_process_rau_accept(bd.l3_mt.msgs.gprs_mm.routingAreaUpdateAccept); |
Alexander Couzens | 80ec1ea | 2018-05-12 16:44:36 +0200 | [diff] [blame] | 756 | BSSGP.send(ts_GMM_RAU_COMPL); |
Harald Welte | 91636de | 2018-02-17 10:16:14 +0100 | [diff] [blame] | 757 | setverdict(pass); |
| 758 | } |
| 759 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_RAU_REJECT)) { |
| 760 | setverdict(fail, "Unexpected RAU Reject"); |
| 761 | } |
| 762 | [] BSSGP.receive { repeat; } |
| 763 | } |
| 764 | } |
| 765 | testcase TC_attach_rau() runs on test_CT { |
| 766 | var BSSGP_ConnHdlr vc_conn; |
| 767 | f_init(); |
| 768 | f_sleep(1.0); |
| 769 | vc_conn := f_start_handler(refers(f_TC_attach_rau), testcasename(), g_gb[0], 12); |
| 770 | vc_conn.done; |
| 771 | } |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 772 | |
Harald Welte | 6abb9fe | 2018-02-17 15:24:48 +0100 | [diff] [blame] | 773 | /* general GPRS DETACH helper */ |
| 774 | function f_detach_mo(BIT3 detach_type, boolean power_off, boolean expect_purge) runs on BSSGP_ConnHdlr { |
| 775 | var BssgpDecoded bd; |
| 776 | timer T := 5.0; |
| 777 | BSSGP.send(ts_GMM_DET_REQ_MO(detach_type, power_off)); |
| 778 | if (expect_purge) { |
| 779 | GSUP.receive(tr_GSUP_PURGE_MS_REQ(g_pars.imsi, OSMO_GSUP_CN_DOMAIN_PS)); |
| 780 | GSUP.send(ts_GSUP_PURGE_MS_RES(g_pars.imsi)); |
| 781 | } |
| 782 | T.start; |
| 783 | alt { |
| 784 | [not expect_purge] GSUP.receive(tr_GSUP_PURGE_MS_REQ(?)) { |
| 785 | setverdict(fail, "Unexpected GSUP PURGE MS for unregistered TLLI"); |
| 786 | } |
| 787 | [power_off] BSSGP.receive(tr_BD_L3_MT(tr_GMM_DET_ACCEPT_MT)) -> value bd { |
| 788 | g_pars.ra := omit; |
| 789 | setverdict(fail, "Unexpected ATTACH ACCEPT in no-power-off DETACH"); |
| 790 | /* TODO: check if any PDP contexts are deactivated on network side? */ |
| 791 | } |
| 792 | [power_off] T.timeout { |
| 793 | setverdict(pass); |
| 794 | } |
| 795 | [not power_off] BSSGP.receive(tr_BD_L3_MT(tr_GMM_DET_ACCEPT_MT)) -> value bd { |
| 796 | g_pars.ra := omit; |
| 797 | setverdict(pass); |
| 798 | /* TODO: check if any PDP contexts are deactivated on network side? */ |
| 799 | } |
| 800 | [] BSSGP.receive { repeat; } |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | /* IMSI DETACH (non-power-off) for unknown TLLI */ |
| 805 | private function f_TC_detach_unknown_nopoweroff(charstring id) runs on BSSGP_ConnHdlr { |
| 806 | f_detach_mo(c_GMM_DTT_MO_GPRS, false, false); |
| 807 | } |
| 808 | testcase TC_detach_unknown_nopoweroff() runs on test_CT { |
| 809 | var BSSGP_ConnHdlr vc_conn; |
| 810 | f_init(); |
| 811 | f_sleep(1.0); |
| 812 | vc_conn := f_start_handler(refers(f_TC_detach_unknown_nopoweroff), testcasename(), g_gb[0], 13); |
| 813 | vc_conn.done; |
| 814 | } |
| 815 | |
| 816 | /* IMSI DETACH (power-off) for unknown TLLI */ |
| 817 | private function f_TC_detach_unknown_poweroff(charstring id) runs on BSSGP_ConnHdlr { |
| 818 | f_detach_mo(c_GMM_DTT_MO_GPRS, true, false); |
| 819 | } |
| 820 | testcase TC_detach_unknown_poweroff() runs on test_CT { |
| 821 | var BSSGP_ConnHdlr vc_conn; |
| 822 | f_init(); |
| 823 | f_sleep(1.0); |
| 824 | vc_conn := f_start_handler(refers(f_TC_detach_unknown_poweroff), testcasename(), g_gb[0], 14); |
| 825 | vc_conn.done; |
| 826 | } |
| 827 | |
| 828 | /* IMSI DETACH (non-power-off) for known TLLI */ |
| 829 | private function f_TC_detach_nopoweroff(charstring id) runs on BSSGP_ConnHdlr { |
| 830 | /* first perform regular attach */ |
| 831 | f_TC_attach(id); |
| 832 | |
| 833 | f_detach_mo(c_GMM_DTT_MO_GPRS, false, true); |
| 834 | } |
| 835 | testcase TC_detach_nopoweroff() runs on test_CT { |
| 836 | var BSSGP_ConnHdlr vc_conn; |
| 837 | f_init(); |
| 838 | f_sleep(1.0); |
| 839 | vc_conn := f_start_handler(refers(f_TC_detach_nopoweroff), testcasename(), g_gb[0], 15); |
| 840 | vc_conn.done; |
| 841 | } |
| 842 | |
| 843 | /* IMSI DETACH (power-off) for known TLLI */ |
| 844 | private function f_TC_detach_poweroff(charstring id) runs on BSSGP_ConnHdlr { |
| 845 | /* first perform regular attach */ |
| 846 | f_TC_attach(id); |
| 847 | |
| 848 | f_detach_mo(c_GMM_DTT_MO_GPRS, true, true); |
| 849 | } |
| 850 | testcase TC_detach_poweroff() runs on test_CT { |
| 851 | var BSSGP_ConnHdlr vc_conn; |
| 852 | f_init(); |
| 853 | f_sleep(1.0); |
| 854 | vc_conn := f_start_handler(refers(f_TC_detach_poweroff), testcasename(), g_gb[0], 16); |
| 855 | vc_conn.done; |
| 856 | } |
| 857 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 858 | type record PdpActPars { |
Harald Welte | 822f910 | 2018-02-18 20:39:06 +0100 | [diff] [blame] | 859 | BIT3 tid, /* L3 Transaction ID */ |
| 860 | BIT4 nsapi, /* SNDCP NSAPI */ |
| 861 | BIT4 sapi, /* LLC SAPI */ |
| 862 | QoSV qos, /* QoS parameters */ |
| 863 | PDPAddressV addr, /* IP address */ |
| 864 | octetstring apn optional, /* APN name */ |
| 865 | ProtocolConfigOptionsV pco optional, /* protoco config opts */ |
| 866 | OCT1 exp_rej_cause optional, /* expected SM reject cause */ |
Harald Welte | 1d6ae93 | 2018-02-18 21:24:44 +0100 | [diff] [blame] | 867 | OCT1 gtp_resp_cause, /* GTP response cause */ |
Harald Welte | 822f910 | 2018-02-18 20:39:06 +0100 | [diff] [blame] | 868 | OCT4 chg_id, /* GTP Charging Identifier */ |
Harald Welte | 6abb9fe | 2018-02-17 15:24:48 +0100 | [diff] [blame] | 869 | |
Harald Welte | 822f910 | 2018-02-18 20:39:06 +0100 | [diff] [blame] | 870 | OCT4 ggsn_tei_c, /* GGSN TEI Control*/ |
| 871 | OCT4 ggsn_tei_u, /* GGSN TEI User */ |
| 872 | octetstring ggsn_ip_c, /* GGSN IP Control */ |
| 873 | octetstring ggsn_ip_u, /* GGSN IP User */ |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 874 | |
Harald Welte | 822f910 | 2018-02-18 20:39:06 +0100 | [diff] [blame] | 875 | OCT4 sgsn_tei_c optional, /* SGSN TEI Control */ |
| 876 | OCT4 sgsn_tei_u optional, /* SGSN TEI User */ |
| 877 | octetstring sgsn_ip_c optional, /* SGSN IP Control */ |
| 878 | octetstring sgsn_ip_u optional /* SGSN IP USer */ |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 879 | }; |
| 880 | |
Harald Welte | 5b5ca1b | 2018-02-18 21:25:03 +0100 | [diff] [blame] | 881 | |
| 882 | private function f_process_gtp_ctx_act_req(inout PdpActPars apars, PDU_GTPC gtpc) runs on BSSGP_ConnHdlr { |
| 883 | var GTPC_PDUs gtpc_rx := gtpc.gtpc_pdu; |
| 884 | apars.sgsn_tei_c := gtpc_rx.createPDPContextRequest.teidControlPlane.teidControlPlane; |
| 885 | apars.sgsn_tei_u := gtpc_rx.createPDPContextRequest.teidDataI.teidDataI; |
| 886 | apars.sgsn_ip_c := gtpc_rx.createPDPContextRequest.sgsn_addr_signalling.addressf; |
| 887 | apars.sgsn_ip_u := gtpc_rx.createPDPContextRequest.sgsn_addr_traffic.addressf; |
| 888 | f_gtp_register_teid(apars.ggsn_tei_c); |
| 889 | f_gtp_register_teid(apars.ggsn_tei_u); |
| 890 | } |
| 891 | |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 892 | function f_pdp_ctx_act(inout PdpActPars apars) runs on BSSGP_ConnHdlr { |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 893 | var boolean exp_rej := ispresent(apars.exp_rej_cause); |
| 894 | var Gtp1cUnitdata g_ud; |
| 895 | |
| 896 | BSSGP.send(ts_SM_ACT_PDP_REQ(apars.tid, apars.nsapi, apars.sapi, apars.qos, apars.addr, |
| 897 | apars.apn, apars.pco)); |
Harald Welte | 5b5ca1b | 2018-02-18 21:25:03 +0100 | [diff] [blame] | 898 | GTP.receive(tr_GTPC_MsgType(?, createPDPContextRequest, ?)) -> value g_ud { |
| 899 | f_process_gtp_ctx_act_req(apars, g_ud.gtpc); |
| 900 | var integer seq_nr := oct2int(g_ud.gtpc.opt_part.sequenceNumber); |
| 901 | GTP.send(ts_GTPC_CreatePdpResp(g_ud.peer, seq_nr, |
| 902 | apars.sgsn_tei_c, apars.gtp_resp_cause, |
| 903 | apars.ggsn_tei_c, apars.ggsn_tei_u, |
| 904 | apars.nsapi, |
| 905 | apars.ggsn_ip_c, apars.ggsn_ip_u, apars.chg_id)); |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 906 | } |
| 907 | alt { |
Harald Welte | 2830708 | 2018-02-18 12:14:18 +0100 | [diff] [blame] | 908 | [exp_rej] BSSGP.receive(tr_BD_L3_MT(tr_SM_ACT_PDP_REJ(apars.tid, apars.exp_rej_cause))) { |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 909 | setverdict(pass); |
| 910 | } |
Harald Welte | 2830708 | 2018-02-18 12:14:18 +0100 | [diff] [blame] | 911 | [exp_rej] BSSGP.receive(tr_BD_L3_MT(tr_SM_ACT_PDP_ACCEPT)) { |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 912 | setverdict(fail, "Unexpected PDP CTX ACT ACC"); |
| 913 | } |
Harald Welte | 2830708 | 2018-02-18 12:14:18 +0100 | [diff] [blame] | 914 | [not exp_rej] BSSGP.receive(tr_BD_L3_MT(tr_SM_ACT_PDP_REJ(apars.tid, ?))) { |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 915 | setverdict(fail, "Unexpected PDP CTX ACT FAIL"); |
| 916 | } |
Harald Welte | 2830708 | 2018-02-18 12:14:18 +0100 | [diff] [blame] | 917 | [not exp_rej] BSSGP.receive(tr_BD_L3_MT(tr_SM_ACT_PDP_ACCEPT(apars.tid, apars.sapi))) { |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 918 | setverdict(pass); |
| 919 | } |
Harald Welte | 5b5ca1b | 2018-02-18 21:25:03 +0100 | [diff] [blame] | 920 | [] as_xid(apars); |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
Harald Welte | 6f20316 | 2018-02-18 22:04:55 +0100 | [diff] [blame] | 924 | function f_pdp_ctx_deact_mo(inout PdpActPars apars, OCT1 cause) runs on BSSGP_ConnHdlr { |
| 925 | var boolean exp_rej := ispresent(apars.exp_rej_cause); |
| 926 | var Gtp1cUnitdata g_ud; |
| 927 | |
| 928 | BSSGP.send(ts_SM_DEACT_PDP_REQ_MO(apars.tid, cause, false, omit)); |
| 929 | GTP.receive(tr_GTPC_MsgType(?, deletePDPContextRequest, apars.ggsn_tei_c)) -> value g_ud { |
| 930 | var integer seq_nr := oct2int(g_ud.gtpc.opt_part.sequenceNumber); |
| 931 | BSSGP.clear; |
| 932 | GTP.send(ts_GTPC_DeletePdpResp(g_ud.peer, seq_nr, apars.sgsn_tei_c, '7F'O)); |
| 933 | } |
| 934 | alt { |
| 935 | [] BSSGP.receive(tr_BD_L3_MT(tr_SM_DEACT_PDP_ACCEPT_MT(apars.tid))) { |
| 936 | setverdict(pass); |
| 937 | } |
| 938 | [] as_xid(apars); |
| 939 | } |
| 940 | } |
| 941 | |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 942 | function f_pdp_ctx_deact_mt(inout PdpActPars apars, OCT1 cause) runs on BSSGP_ConnHdlr { |
| 943 | var Gtp1cUnitdata g_ud; |
| 944 | var integer seq_nr := 23; |
| 945 | var GtpPeer peer := valueof(ts_GtpPeerC(apars.sgsn_ip_c)); |
| 946 | |
| 947 | BSSGP.clear; |
| 948 | GTP.send(ts_GTPC_DeletePDP(peer, seq_nr, apars.sgsn_tei_c, apars.nsapi, omit)); |
| 949 | |
| 950 | interleave { |
| 951 | [] BSSGP.receive(tr_BD_L3_MT(tr_SM_DEACT_PDP_REQ_MT(apars.tid, ?))) { |
| 952 | BSSGP.send(ts_SM_DEACT_PDP_ACCEPT_MO(apars.tid)); |
| 953 | } |
| 954 | [] GTP.receive(tr_GTPC_MsgType(?, deletePDPContextResponse, apars.ggsn_tei_c)) { } |
| 955 | } |
| 956 | } |
| 957 | |
Harald Welte | 6f20316 | 2018-02-18 22:04:55 +0100 | [diff] [blame] | 958 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 959 | /* Table 10.5.156/3GPP TS 24.008 */ |
| 960 | template (value) QoSV t_QosDefault := { |
| 961 | reliabilityClass := '011'B, /* unacknowledged GTP+LLC, acknowledged RLC */ |
| 962 | delayClass := '100'B, /* best effort */ |
| 963 | spare1 := '00'B, |
| 964 | precedenceClass := '010'B, /* normal */ |
| 965 | spare2 := '0'B, |
| 966 | peakThroughput := '0000'B, /* subscribed */ |
| 967 | meanThroughput := '00000'B, /* subscribed */ |
| 968 | spare3 := '000'B, |
| 969 | deliverErroneusSDU := omit, |
| 970 | deliveryOrder := omit, |
| 971 | trafficClass := omit, |
| 972 | maxSDUSize := omit, |
| 973 | maxBitrateUplink := omit, |
| 974 | maxBitrateDownlink := omit, |
| 975 | sduErrorRatio := omit, |
| 976 | residualBER := omit, |
| 977 | trafficHandlingPriority := omit, |
| 978 | transferDelay := omit, |
| 979 | guaranteedBitRateUplink := omit, |
| 980 | guaranteedBitRateDownlink := omit, |
| 981 | sourceStatisticsDescriptor := omit, |
| 982 | signallingIndication := omit, |
| 983 | spare4 := omit, |
| 984 | maxBitrateDownlinkExt := omit, |
| 985 | guaranteedBitRateDownlinkExt := omit, |
| 986 | maxBitrateUplinkExt := omit, |
| 987 | guaranteedBitRateUplinkExt := omit, |
| 988 | maxBitrateDownlinkExt2 := omit, |
| 989 | guaranteedBitRateDownlinkExt2 := omit, |
| 990 | maxBitrateUplinkExt2 := omit, |
| 991 | guaranteedBitRateUplinkExt2 := omit |
| 992 | } |
| 993 | |
| 994 | /* 10.5.6.4 / 3GPP TS 24.008 */ |
| 995 | template (value) PDPAddressV t_AddrIPv4dyn := { |
| 996 | pdpTypeOrg := '0001'B, /* IETF */ |
| 997 | spare := '0000'B, |
| 998 | pdpTypeNum := '21'O, /* IPv4 */ |
| 999 | addressInfo := omit |
| 1000 | } |
| 1001 | template (value) PDPAddressV t_AddrIPv6dyn := { |
| 1002 | pdpTypeOrg := '0001'B, /* IETF */ |
| 1003 | spare := '0000'B, |
| 1004 | pdpTypeNum := '53'O, /* IPv6 */ |
| 1005 | addressInfo := omit |
| 1006 | } |
| 1007 | |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 1008 | template (value) PdpActPars t_PdpActPars(charstring ggsn_ip) := { |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1009 | tid := '000'B, |
| 1010 | nsapi := '0101'B, /* < 5 are reserved */ |
| 1011 | sapi := '0011'B, /* 3/5/9/11 */ |
| 1012 | qos := t_QosDefault, |
| 1013 | addr := t_AddrIPv4dyn, |
| 1014 | apn := omit, |
| 1015 | pco := omit, |
| 1016 | exp_rej_cause := omit, |
Harald Welte | 1d6ae93 | 2018-02-18 21:24:44 +0100 | [diff] [blame] | 1017 | gtp_resp_cause := int2oct(128, 1), |
| 1018 | chg_id := f_rnd_octstring(4), |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1019 | |
| 1020 | /* FIXME: make below dynamic !! */ |
Harald Welte | 1d6ae93 | 2018-02-18 21:24:44 +0100 | [diff] [blame] | 1021 | ggsn_tei_c := f_rnd_octstring(4), |
| 1022 | ggsn_tei_u := f_rnd_octstring(4), |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 1023 | ggsn_ip_c := f_inet_addr(ggsn_ip), |
| 1024 | ggsn_ip_u := f_inet_addr(ggsn_ip), |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1025 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1026 | sgsn_tei_c := omit, |
Harald Welte | f8af5d6 | 2018-02-18 15:06:42 +0100 | [diff] [blame] | 1027 | sgsn_tei_u := omit, |
| 1028 | sgsn_ip_c := omit, |
| 1029 | sgsn_ip_u := omit |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1030 | } |
| 1031 | |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 1032 | template (value) GtpPeer ts_GtpPeerU(octetstring ip) := { |
| 1033 | connId := 1, |
| 1034 | remName := f_inet_ntoa(ip), |
| 1035 | remPort := GTP1U_PORT |
| 1036 | } |
| 1037 | |
| 1038 | template (value) GtpPeer ts_GtpPeerC(octetstring ip) := { |
| 1039 | connId := 1, |
| 1040 | remName := f_inet_ntoa(ip), |
| 1041 | remPort := GTP1C_PORT |
| 1042 | } |
| 1043 | |
| 1044 | private function f_gtpu_send(inout PdpActPars apars, octetstring payload) runs on BSSGP_ConnHdlr { |
| 1045 | var GtpPeer peer := valueof(ts_GtpPeerU(apars.sgsn_ip_u)); |
| 1046 | GTP.send(ts_GTP1U_GPDU(peer, 0 /*seq*/, apars.sgsn_tei_u, payload)); |
| 1047 | } |
| 1048 | |
| 1049 | private altstep as_xid(PdpActPars apars) runs on BSSGP_ConnHdlr { |
| 1050 | [] BSSGP.receive(tr_BD_LLC(tr_LLC_XID(?, apars.sapi))) { |
| 1051 | repeat; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | template PDU_SN tr_SN_UD(template BIT4 nsapi, template octetstring payload) := { |
| 1056 | pDU_SN_UNITDATA := { |
| 1057 | nsapi := nsapi, |
| 1058 | moreBit := ?, |
| 1059 | snPduType := '1'B, |
| 1060 | firstSegmentIndicator := ?, |
| 1061 | spareBit := ?, |
| 1062 | pcomp := ?, |
| 1063 | dcomp := ?, |
| 1064 | npduNumber := ?, |
| 1065 | segmentNumber := ?, |
| 1066 | npduNumberContinued := ?, |
| 1067 | dataSegmentSnUnitdataPdu := payload |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | /* simple case: single segment, no compression */ |
| 1072 | template (value) PDU_SN ts_SN_UD(BIT4 nsapi, octetstring payload) := { |
| 1073 | pDU_SN_UNITDATA := { |
| 1074 | nsapi := nsapi, |
| 1075 | moreBit := '0'B, |
| 1076 | snPduType := '1'B, |
| 1077 | firstSegmentIndicator := '1'B, |
| 1078 | spareBit := '0'B, |
| 1079 | pcomp := '0000'B, |
| 1080 | dcomp := '0000'B, |
| 1081 | npduNumber := '0000'B, |
| 1082 | segmentNumber := '0000'B, |
| 1083 | npduNumberContinued := '00'O, |
| 1084 | dataSegmentSnUnitdataPdu := payload |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | /* Transceive given 'payload' as MT message from GTP -> OsmoSGSN -> Gb */ |
| 1089 | private function f_gtpu_xceive_mt(inout PdpActPars apars, octetstring payload) runs on BSSGP_ConnHdlr { |
| 1090 | /* Send PDU via GTP from our simulated GGSN to the SGSN */ |
| 1091 | f_gtpu_send(apars, payload); |
| 1092 | /* Expect PDU via BSSGP/LLC on simulated PCU from SGSN */ |
| 1093 | alt { |
| 1094 | [] as_xid(apars); |
| 1095 | [] BSSGP.receive(tr_BD_SNDCP(apars.sapi, tr_SN_UD(apars.nsapi, payload))); |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | private function f_gtpu_xceive_mo(inout PdpActPars apars, octetstring payload) runs on BSSGP_ConnHdlr { |
| 1100 | /* Send PDU via SNDCP/LLC/BSSGP/NS via simulated MS/PCU to the SGSN */ |
| 1101 | var GtpPeer peer := valueof(ts_GtpPeerU(apars.sgsn_ip_u)); |
| 1102 | var PDU_SN sndcp := valueof(ts_SN_UD(apars.nsapi, payload)); |
| 1103 | BSSGP.send(ts_LLC_UI(enc_PDU_SN(sndcp), apars.sapi, '0'B, 0)); |
| 1104 | f_gtpu_send(apars, payload); |
| 1105 | /* Expect PDU via GTP from SGSN on simulated GGSN */ |
| 1106 | alt { |
| 1107 | [] GTP.receive(tr_GTPU_GPDU(peer, apars.ggsn_tei_u, payload)); |
| 1108 | } |
| 1109 | } |
| 1110 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1111 | private function f_TC_attach_pdp_act(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 1112 | var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip)); |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1113 | |
| 1114 | /* first perform regular attach */ |
| 1115 | f_TC_attach(id); |
| 1116 | |
| 1117 | f_pdp_ctx_act(apars); |
| 1118 | } |
| 1119 | testcase TC_attach_pdp_act() runs on test_CT { |
| 1120 | var BSSGP_ConnHdlr vc_conn; |
| 1121 | f_init(); |
| 1122 | vc_conn := f_start_handler(refers(f_TC_attach_pdp_act), testcasename(), g_gb[0], 17); |
| 1123 | vc_conn.done; |
| 1124 | } |
Harald Welte | b2124b2 | 2018-02-16 22:26:56 +0100 | [diff] [blame] | 1125 | |
Harald Welte | 835b15f | 2018-02-18 14:39:11 +0100 | [diff] [blame] | 1126 | /* PDP Context activation for not-attached subscriber; expect fail */ |
| 1127 | private function f_TC_pdp_act_unattached(charstring id) runs on BSSGP_ConnHdlr { |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 1128 | var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip)); |
Harald Welte | 835b15f | 2018-02-18 14:39:11 +0100 | [diff] [blame] | 1129 | BSSGP.send(ts_SM_ACT_PDP_REQ(apars.tid, apars.nsapi, apars.sapi, apars.qos, apars.addr, |
| 1130 | apars.apn, apars.pco)); |
| 1131 | alt { |
| 1132 | /* We might want toalso actually expect a PDPC CTX ACT REJ? */ |
| 1133 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_DET_REQ_MT(?, ?))) { |
| 1134 | setverdict(pass); |
| 1135 | } |
| 1136 | [] GTP.receive(tr_GTPC_MsgType(?, createPDPContextRequest, ?)) { |
| 1137 | setverdict(fail, "Unexpected GTP PDP CTX ACT"); |
| 1138 | } |
| 1139 | [] BSSGP.receive(tr_BD_L3_MT(tr_SM_ACT_PDP_ACCEPT(?, ?))) { |
| 1140 | setverdict(fail, "Unexpected SM PDP CTX ACT ACK"); |
| 1141 | } |
| 1142 | [] BSSGP.receive { repeat; } |
| 1143 | } |
| 1144 | } |
| 1145 | testcase TC_pdp_act_unattached() runs on test_CT { |
| 1146 | var BSSGP_ConnHdlr vc_conn; |
| 1147 | f_init(); |
| 1148 | vc_conn := f_start_handler(refers(f_TC_pdp_act_unattached), testcasename(), g_gb[0], 18); |
| 1149 | vc_conn.done; |
| 1150 | } |
| 1151 | |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 1152 | /* ATTACH + PDP CTX ACT + user plane traffic */ |
| 1153 | private function f_TC_attach_pdp_act_user(charstring id) runs on BSSGP_ConnHdlr { |
| 1154 | var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip)); |
| 1155 | |
| 1156 | /* first perform regular attach */ |
| 1157 | f_TC_attach(id); |
| 1158 | /* then activate PDP context */ |
| 1159 | f_pdp_ctx_act(apars); |
| 1160 | /* then transceive a downlink PDU */ |
| 1161 | f_gtpu_xceive_mt(apars, f_rnd_octstring(100)); |
| 1162 | f_gtpu_xceive_mo(apars, f_rnd_octstring(200)); |
| 1163 | } |
| 1164 | testcase TC_attach_pdp_act_user() runs on test_CT { |
| 1165 | var BSSGP_ConnHdlr vc_conn; |
| 1166 | f_init(); |
| 1167 | vc_conn := f_start_handler(refers(f_TC_attach_pdp_act_user), testcasename(), g_gb[0], 19); |
| 1168 | vc_conn.done; |
| 1169 | } |
| 1170 | |
Harald Welte | 5b5ca1b | 2018-02-18 21:25:03 +0100 | [diff] [blame] | 1171 | /* ATTACH + PDP CTX ACT; reject from GGSN */ |
| 1172 | private function f_TC_attach_pdp_act_ggsn_reject(charstring id) runs on BSSGP_ConnHdlr { |
| 1173 | var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip)); |
| 1174 | |
| 1175 | apars.gtp_resp_cause := int2oct(199, 1); /* no resources available */ |
| 1176 | apars.exp_rej_cause := '1a'O; /* insufficient resources */ |
| 1177 | |
| 1178 | /* first perform regular attach */ |
| 1179 | f_TC_attach(id); |
| 1180 | /* then activate PDP context */ |
| 1181 | f_pdp_ctx_act(apars); |
| 1182 | } |
| 1183 | testcase TC_attach_pdp_act_ggsn_reject() runs on test_CT { |
| 1184 | var BSSGP_ConnHdlr vc_conn; |
| 1185 | f_init(); |
| 1186 | vc_conn := f_start_handler(refers(f_TC_attach_pdp_act_ggsn_reject), testcasename(), g_gb[0], 20); |
| 1187 | vc_conn.done; |
| 1188 | } |
Harald Welte | 835b15f | 2018-02-18 14:39:11 +0100 | [diff] [blame] | 1189 | |
Harald Welte | 6f20316 | 2018-02-18 22:04:55 +0100 | [diff] [blame] | 1190 | /* ATTACH + PDP CTX ACT + user plane traffic + PDP CTX DEACT in MO direction */ |
| 1191 | private function f_TC_attach_pdp_act_user_deact_mo(charstring id) runs on BSSGP_ConnHdlr { |
| 1192 | var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip)); |
| 1193 | |
| 1194 | /* first perform regular attach */ |
| 1195 | f_TC_attach(id); |
| 1196 | /* then activate PDP context */ |
| 1197 | f_pdp_ctx_act(apars); |
| 1198 | /* then transceive a downlink PDU */ |
| 1199 | f_gtpu_xceive_mt(apars, f_rnd_octstring(100)); |
| 1200 | f_gtpu_xceive_mo(apars, f_rnd_octstring(200)); |
| 1201 | |
| 1202 | f_pdp_ctx_deact_mo(apars, '00'O); |
| 1203 | } |
| 1204 | testcase TC_attach_pdp_act_user_deact_mo() runs on test_CT { |
| 1205 | var BSSGP_ConnHdlr vc_conn; |
| 1206 | f_init(); |
| 1207 | vc_conn := f_start_handler(refers(f_TC_attach_pdp_act_user_deact_mo), testcasename(), g_gb[0], 21); |
| 1208 | vc_conn.done; |
| 1209 | } |
| 1210 | |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 1211 | /* ATTACH + PDP CTX ACT + user plane traffic + PDP CTX DEACT in MT direction */ |
| 1212 | private function f_TC_attach_pdp_act_user_deact_mt(charstring id) runs on BSSGP_ConnHdlr { |
| 1213 | var PdpActPars apars := valueof(t_PdpActPars(mp_ggsn_ip)); |
| 1214 | |
| 1215 | /* first perform regular attach */ |
| 1216 | f_TC_attach(id); |
| 1217 | /* then activate PDP context */ |
| 1218 | f_pdp_ctx_act(apars); |
| 1219 | /* then transceive a downlink PDU */ |
| 1220 | f_gtpu_xceive_mt(apars, f_rnd_octstring(100)); |
| 1221 | f_gtpu_xceive_mo(apars, f_rnd_octstring(200)); |
| 1222 | |
| 1223 | f_pdp_ctx_deact_mt(apars, '00'O); |
| 1224 | } |
| 1225 | testcase TC_attach_pdp_act_user_deact_mt() runs on test_CT { |
| 1226 | var BSSGP_ConnHdlr vc_conn; |
| 1227 | f_init(); |
| 1228 | vc_conn := f_start_handler(refers(f_TC_attach_pdp_act_user_deact_mt), testcasename(), g_gb[0], 22); |
| 1229 | vc_conn.done; |
| 1230 | } |
| 1231 | |
Alexander Couzens | 187ad5d | 2018-05-02 19:31:10 +0200 | [diff] [blame] | 1232 | /* ATTACH + ATTACH (2nd) */ |
| 1233 | private function f_TC_attach_forget_tlli_attach(charstring id) runs on BSSGP_ConnHdlr { |
| 1234 | g_pars.t_guard := 5.0; |
| 1235 | |
| 1236 | /* first perform regular attach */ |
| 1237 | f_TC_attach(id); |
| 1238 | |
| 1239 | /* second to perform regular attach */ |
| 1240 | f_TC_attach(id); |
| 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | testcase TC_attach_second_attempt() runs on test_CT { |
| 1245 | var BSSGP_ConnHdlr vc_conn; |
| 1246 | f_init(); |
| 1247 | vc_conn := f_start_handler(refers(f_TC_attach_forget_tlli_attach), testcasename(), g_gb[0], 22); |
| 1248 | vc_conn.done; |
| 1249 | } |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 1250 | |
Alexander Couzens | 5e307b4 | 2018-05-22 18:12:20 +0200 | [diff] [blame] | 1251 | private function f_TC_hlr_location_cancel_request_update(charstring id) runs on BSSGP_ConnHdlr { |
| 1252 | /* MS: perform regular attach */ |
| 1253 | f_TC_attach(id); |
| 1254 | |
| 1255 | /* HLR: cancel the location request */ |
| 1256 | GSUP.send(ts_GSUP_CL_REQ(g_pars.imsi, OSMO_GSUP_CANCEL_TYPE_UPDATE)); |
| 1257 | GSUP.receive(tr_GSUP_CL_RES(g_pars.imsi)); |
| 1258 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 1259 | |
| 1260 | /* ensure no Detach Request got received */ |
| 1261 | timer T := 5.0; |
| 1262 | T.start; |
| 1263 | alt { |
| 1264 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_DET_REQ_MT(*, *, *))) { |
| 1265 | T.stop; |
| 1266 | setverdict(fail, "Unexpected GMM Detach Request"); |
| 1267 | } |
| 1268 | [] T.timeout { |
| 1269 | setverdict(pass); |
| 1270 | self.stop; |
| 1271 | } |
| 1272 | [] BSSGP.receive { |
| 1273 | repeat; |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | testcase TC_hlr_location_cancel_request_update() runs on test_CT { |
| 1279 | /* MS <-> SGSN: GMM Attach |
| 1280 | * HLR -> SGSN: Cancel Location Request |
| 1281 | * HLR <- SGSN: Cancel Location Ack |
| 1282 | */ |
| 1283 | var BSSGP_ConnHdlr vc_conn; |
| 1284 | f_init(); |
| 1285 | f_sleep(1.0); |
| 1286 | vc_conn := f_start_handler(refers(f_TC_hlr_location_cancel_request_update), testcasename(), g_gb[0], 31); |
| 1287 | vc_conn.done; |
| 1288 | } |
| 1289 | |
| 1290 | |
Alexander Couzens | c87967a | 2018-05-22 16:09:54 +0200 | [diff] [blame] | 1291 | private function f_TC_hlr_location_cancel_request_withdraw(charstring id) runs on BSSGP_ConnHdlr { |
| 1292 | /* MS: perform regular attach */ |
| 1293 | f_TC_attach(id); |
| 1294 | |
| 1295 | /* HLR: cancel the location request */ |
| 1296 | GSUP.send(ts_GSUP_CL_REQ(g_pars.imsi, OSMO_GSUP_CANCEL_TYPE_WITHDRAW)); |
| 1297 | GSUP.receive(tr_GSUP_CL_RES(g_pars.imsi)); |
| 1298 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 1299 | |
| 1300 | /* MS: receive a Detach Request */ |
| 1301 | BSSGP.receive(tr_BD_L3_MT(tr_GMM_DET_REQ_MT(c_GMM_DTT_MT_IMSI_DETACH, ?, ?))); |
| 1302 | BSSGP.send(ts_GMM_DET_ACCEPT_MO); |
| 1303 | |
| 1304 | setverdict(pass); |
| 1305 | } |
| 1306 | |
| 1307 | testcase TC_hlr_location_cancel_request_withdraw() runs on test_CT { |
| 1308 | /* MS <-> SGSN: GMM Attach |
| 1309 | * HLR -> SGSN: Cancel Location Request |
| 1310 | * HLR <- SGSN: Cancel Location Ack |
| 1311 | * MS <- SGSN: Detach Request |
| 1312 | * SGSN-> MS: Detach Complete |
| 1313 | */ |
| 1314 | var BSSGP_ConnHdlr vc_conn; |
| 1315 | f_init(); |
| 1316 | f_sleep(1.0); |
| 1317 | vc_conn := f_start_handler(refers(f_TC_hlr_location_cancel_request_withdraw), testcasename(), g_gb[0], 29); |
| 1318 | vc_conn.done; |
| 1319 | } |
| 1320 | |
| 1321 | |
Alexander Couzens | 6c47f29 | 2018-05-22 17:09:49 +0200 | [diff] [blame] | 1322 | private function f_hlr_location_cancel_request_unknown_subscriber( |
| 1323 | charstring id, |
| 1324 | GSUP_CancelType canceltype) runs on BSSGP_ConnHdlr { |
| 1325 | |
| 1326 | /* HLR: cancel the location request */ |
| 1327 | GSUP.send(ts_GSUP_CL_REQ(g_pars.imsi, canceltype)); |
| 1328 | |
| 1329 | /* cause 2 = IMSI_UNKNOWN */ |
| 1330 | GSUP.receive(tr_GSUP_CL_ERR(g_pars.imsi, 2)); |
| 1331 | |
| 1332 | setverdict(pass); |
| 1333 | } |
| 1334 | |
| 1335 | private function f_TC_hlr_location_cancel_request_unknown_subscriber_withdraw(charstring id) runs on BSSGP_ConnHdlr { |
Alexander Couzens | ace6fc6 | 2018-06-05 16:29:02 +0200 | [diff] [blame] | 1336 | f_hlr_location_cancel_request_unknown_subscriber(id, OSMO_GSUP_CANCEL_TYPE_WITHDRAW); |
Alexander Couzens | 6c47f29 | 2018-05-22 17:09:49 +0200 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | testcase TC_hlr_location_cancel_request_unknown_subscriber_withdraw() runs on test_CT { |
| 1340 | /* HLR -> SGSN: Cancel Location Request |
| 1341 | * HLR <- SGSN: Cancel Location Error |
| 1342 | */ |
| 1343 | |
| 1344 | var BSSGP_ConnHdlr vc_conn; |
| 1345 | f_init(); |
| 1346 | f_sleep(1.0); |
| 1347 | vc_conn := f_start_handler(refers(f_TC_hlr_location_cancel_request_unknown_subscriber_withdraw), testcasename(), g_gb[0], 30); |
| 1348 | vc_conn.done; |
| 1349 | } |
| 1350 | |
| 1351 | private function f_TC_hlr_location_cancel_request_unknown_subscriber_update(charstring id) runs on BSSGP_ConnHdlr { |
Alexander Couzens | ace6fc6 | 2018-06-05 16:29:02 +0200 | [diff] [blame] | 1352 | f_hlr_location_cancel_request_unknown_subscriber(id, OSMO_GSUP_CANCEL_TYPE_WITHDRAW); |
Alexander Couzens | 6c47f29 | 2018-05-22 17:09:49 +0200 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | testcase TC_hlr_location_cancel_request_unknown_subscriber_update() runs on test_CT { |
| 1356 | /* HLR -> SGSN: Cancel Location Request |
| 1357 | * HLR <- SGSN: Cancel Location Error |
| 1358 | */ |
| 1359 | |
| 1360 | var BSSGP_ConnHdlr vc_conn; |
| 1361 | f_init(); |
| 1362 | f_sleep(1.0); |
| 1363 | vc_conn := f_start_handler(refers(f_TC_hlr_location_cancel_request_unknown_subscriber_update), testcasename(), g_gb[0], 30); |
| 1364 | vc_conn.done; |
| 1365 | } |
| 1366 | |
Alexander Couzens | 49bb4b4 | 2018-06-05 16:28:36 +0200 | [diff] [blame^] | 1367 | private function f_TC_attach_detach_check_subscriber_list(charstring id) runs on BSSGP_ConnHdlr { |
| 1368 | f_TC_attach(id); |
| 1369 | f_detach_mo(c_GMM_DTT_MO_GPRS, true, true); |
| 1370 | } |
Alexander Couzens | 6c47f29 | 2018-05-22 17:09:49 +0200 | [diff] [blame] | 1371 | |
Alexander Couzens | 49bb4b4 | 2018-06-05 16:28:36 +0200 | [diff] [blame^] | 1372 | testcase TC_attach_detach_check_subscriber_list() runs on test_CT { |
| 1373 | /* MS <-> SGSN: Attach |
| 1374 | * MS -> SGSN: Detach Req (Power off) |
| 1375 | * VTY -> SGSN: Check if MS is NOT in subscriber cache |
| 1376 | */ |
| 1377 | var BSSGP_ConnHdlr vc_conn; |
| 1378 | var integer id := 33; |
| 1379 | var charstring imsi := hex2str(f_gen_imsi(id)); |
| 1380 | |
| 1381 | f_init(); |
| 1382 | vc_conn := f_start_handler(refers(f_TC_attach_detach_check_subscriber_list), testcasename(), g_gb[0], id); |
| 1383 | vc_conn.done; |
| 1384 | |
| 1385 | f_vty_transceive_not_match(SGSNVTY, "show subscriber cache", pattern "* IMSI: {imsi}*"); |
| 1386 | } |
Alexander Couzens | 6c47f29 | 2018-05-22 17:09:49 +0200 | [diff] [blame] | 1387 | |
Alexander Couzens | 667dd7f | 2018-06-12 16:24:01 +0200 | [diff] [blame] | 1388 | /* Attempt an attach, but loose the Identification Request (IMEI) */ |
| 1389 | private function f_TC_attach_no_imei_response(charstring id) runs on BSSGP_ConnHdlr { |
| 1390 | var integer count_req := 0; |
| 1391 | var MobileL3_CommonIE_Types.MobileIdentityLV mi; |
| 1392 | |
| 1393 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), f_random_RAI(), true, false, omit, omit)); |
| 1394 | |
| 1395 | alt { |
| 1396 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))) { |
| 1397 | /* break */ |
| 1398 | } |
| 1399 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ID_REQ('001'B))) { |
| 1400 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 1401 | BSSGP.send(ts_GMM_ID_RESP(mi)); |
| 1402 | repeat; |
| 1403 | } |
| 1404 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ID_REQ('010'B))) { |
| 1405 | /* ignore ID REQ IMEI */ |
| 1406 | count_req := count_req + 1; |
| 1407 | repeat; |
| 1408 | } |
| 1409 | } |
| 1410 | if (count_req != 5) { |
| 1411 | setverdict(fail, "Did not received GMM ID Request Type IMEI 5 times!"); |
| 1412 | } |
| 1413 | setverdict(pass); |
| 1414 | } |
| 1415 | |
| 1416 | testcase TC_attach_no_imei_response() runs on test_CT { |
| 1417 | /* MS -> SGSN: Attach Request IMSI |
| 1418 | * MS <- SGSN: Identity Request IMSI (optional) |
| 1419 | * MS -> SGSN: Identity Response IMSI (optional) |
| 1420 | * MS <- SGSN: Identity Request IMEI |
| 1421 | * MS -x SGSN: no response |
| 1422 | * MS <- SGSN: re-send: Identity Request IMEI 4x |
| 1423 | * MS <- SGSN: Attach Reject |
| 1424 | */ |
| 1425 | var BSSGP_ConnHdlr vc_conn; |
| 1426 | f_init(); |
| 1427 | f_sleep(1.0); |
| 1428 | vc_conn := f_start_handler(refers(f_TC_attach_no_imei_response), testcasename(), g_gb[0], 32, 60.0); |
| 1429 | vc_conn.done; |
| 1430 | } |
| 1431 | |
Alexander Couzens | 53f2056 | 2018-06-12 16:24:12 +0200 | [diff] [blame] | 1432 | /* Attempt an attach, but loose the Identification Request (IMSI) */ |
| 1433 | private function f_TC_attach_no_imsi_response(charstring id) runs on BSSGP_ConnHdlr { |
| 1434 | var integer count_req := 0; |
| 1435 | var MobileL3_CommonIE_Types.MobileIdentityLV mi; |
| 1436 | |
| 1437 | /* set p_tmsi to use it in Attach Req via f_mi_get_lv() */ |
| 1438 | g_pars.p_tmsi := 'c0000035'O; |
| 1439 | |
| 1440 | BSSGP.send(ts_GMM_ATTACH_REQ(f_mi_get_lv(), f_random_RAI(), true, false, omit, omit)); |
| 1441 | |
| 1442 | alt { |
| 1443 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ATTACH_REJECT(?))) { |
| 1444 | /* break */ |
| 1445 | } |
| 1446 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ID_REQ('001'B))) { |
| 1447 | /* ignore ID REQ IMSI */ |
| 1448 | count_req := count_req + 1; |
| 1449 | repeat; |
| 1450 | } |
| 1451 | [] BSSGP.receive(tr_BD_L3_MT(tr_GMM_ID_REQ('010'B))) { |
| 1452 | mi := valueof(ts_MI_IMEI_LV(g_pars.imei)); |
| 1453 | BSSGP.send(ts_GMM_ID_RESP(mi)); |
| 1454 | repeat; |
| 1455 | } |
| 1456 | } |
| 1457 | if (count_req != 5) { |
| 1458 | setverdict(fail, "Did not received GMM ID Request Type IMSI 5 times!"); |
| 1459 | } |
| 1460 | setverdict(pass); |
| 1461 | } |
| 1462 | |
| 1463 | testcase TC_attach_no_imsi_response() runs on test_CT { |
| 1464 | /* MS -> SGSN: Attach Request TMSI (unknown) |
| 1465 | * MS <- SGSN: Identity Request IMEI (optional) |
| 1466 | * MS -> SGSN: Identity Response IMEI (optional) |
| 1467 | * MS <- SGSN: Identity Request IMSI |
| 1468 | * MS -x SGSN: no response |
| 1469 | * MS <- SGSN: re-send: Identity Request IMSI 4x |
| 1470 | * MS <- SGSN: Attach Reject |
| 1471 | */ |
| 1472 | var BSSGP_ConnHdlr vc_conn; |
| 1473 | f_init(); |
| 1474 | f_sleep(1.0); |
| 1475 | vc_conn := f_start_handler(refers(f_TC_attach_no_imsi_response), testcasename(), g_gb[0], 35, 60.0); |
| 1476 | vc_conn.done; |
| 1477 | } |
| 1478 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1479 | control { |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 1480 | execute( TC_attach() ); |
Neels Hofmeyr | 8df7d15 | 2018-03-14 19:03:28 +0100 | [diff] [blame] | 1481 | execute( TC_attach_mnc3() ); |
Neels Hofmeyr | 0ecb2e3 | 2018-04-30 15:13:55 +0200 | [diff] [blame] | 1482 | execute( TC_attach_umts_aka_umts_res() ); |
| 1483 | execute( TC_attach_umts_aka_gsm_sres() ); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 1484 | execute( TC_attach_auth_id_timeout() ); |
| 1485 | execute( TC_attach_auth_sai_timeout() ); |
Harald Welte | fe25388 | 2018-02-17 09:25:00 +0100 | [diff] [blame] | 1486 | execute( TC_attach_auth_sai_reject() ); |
Harald Welte | 5b7c812 | 2018-02-16 21:48:17 +0100 | [diff] [blame] | 1487 | execute( TC_attach_gsup_lu_timeout() ); |
Harald Welte | b7c14e9 | 2018-02-17 09:29:16 +0100 | [diff] [blame] | 1488 | execute( TC_attach_gsup_lu_reject() ); |
Harald Welte | 3823e2e | 2018-02-16 21:53:48 +0100 | [diff] [blame] | 1489 | execute( TC_attach_combined() ); |
Harald Welte | 76dee09 | 2018-02-16 22:12:59 +0100 | [diff] [blame] | 1490 | execute( TC_attach_accept_all() ); |
Harald Welte | b2124b2 | 2018-02-16 22:26:56 +0100 | [diff] [blame] | 1491 | execute( TC_attach_closed() ); |
Alexander Couzens | 667dd7f | 2018-06-12 16:24:01 +0200 | [diff] [blame] | 1492 | execute( TC_attach_no_imei_response() ); |
Alexander Couzens | 53f2056 | 2018-06-12 16:24:12 +0200 | [diff] [blame] | 1493 | execute( TC_attach_no_imsi_response() ); |
Alexander Couzens | 49bb4b4 | 2018-06-05 16:28:36 +0200 | [diff] [blame^] | 1494 | execute( TC_attach_detach_check_subscriber_list(), 10.0 ); |
Alexander Couzens | 5e307b4 | 2018-05-22 18:12:20 +0200 | [diff] [blame] | 1495 | execute( TC_hlr_location_cancel_request_update(), 10.0 ); |
Alexander Couzens | 234c588 | 2018-05-29 15:48:44 +0200 | [diff] [blame] | 1496 | execute( TC_hlr_location_cancel_request_withdraw(), 10.0 ); |
| 1497 | execute( TC_hlr_location_cancel_request_unknown_subscriber_withdraw(), 10.0 ); |
| 1498 | execute( TC_hlr_location_cancel_request_unknown_subscriber_update(), 10.0 ); |
Harald Welte | 04683d0 | 2018-02-16 22:43:45 +0100 | [diff] [blame] | 1499 | execute( TC_rau_unknown() ); |
Harald Welte | 91636de | 2018-02-17 10:16:14 +0100 | [diff] [blame] | 1500 | execute( TC_attach_rau() ); |
Harald Welte | 6abb9fe | 2018-02-17 15:24:48 +0100 | [diff] [blame] | 1501 | execute( TC_detach_unknown_nopoweroff() ); |
| 1502 | execute( TC_detach_unknown_poweroff() ); |
| 1503 | execute( TC_detach_nopoweroff() ); |
| 1504 | execute( TC_detach_poweroff() ); |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 1505 | execute( TC_attach_pdp_act() ); |
Harald Welte | 835b15f | 2018-02-18 14:39:11 +0100 | [diff] [blame] | 1506 | execute( TC_pdp_act_unattached() ); |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 1507 | execute( TC_attach_pdp_act_user() ); |
Harald Welte | 5b5ca1b | 2018-02-18 21:25:03 +0100 | [diff] [blame] | 1508 | execute( TC_attach_pdp_act_ggsn_reject() ); |
Harald Welte | 6f20316 | 2018-02-18 22:04:55 +0100 | [diff] [blame] | 1509 | execute( TC_attach_pdp_act_user_deact_mo() ); |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 1510 | execute( TC_attach_pdp_act_user_deact_mt() ); |
Alexander Couzens | 187ad5d | 2018-05-02 19:31:10 +0200 | [diff] [blame] | 1511 | execute( TC_attach_second_attempt() ); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1512 | } |
Harald Welte | 96a33b0 | 2018-02-04 10:36:22 +0100 | [diff] [blame] | 1513 | |
| 1514 | |
| 1515 | |
| 1516 | } |