Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 1 | /* Osmocom MSC+VLR end-to-end tests */ |
| 2 | |
| 3 | /* (C) 2017 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "msc_vlr_tests.h" |
| 25 | |
| 26 | #include <osmocom/msc/gsm_04_08.h> |
| 27 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 28 | static void mncc_sends_to_cc(uint32_t msg_type, struct gsm_mncc *mncc) |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 29 | { |
| 30 | mncc->msg_type = msg_type; |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 31 | mncc_tx_to_cc(net, mncc); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 34 | /* |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 35 | static void on_call_release_mncc_sends_to_cc(uint32_t msg_type, struct gsm_mncc *mncc) |
| 36 | { |
| 37 | mncc->msg_type = msg_type; |
| 38 | on_call_release_mncc_sends_to_cc_data = mncc; |
| 39 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 40 | */ |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 41 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 42 | #define IMSI "901700000010650" |
| 43 | |
| 44 | static void standard_lu() |
| 45 | { |
| 46 | struct vlr_subscr *vsub; |
| 47 | |
| 48 | net->authentication_required = true; |
| 49 | net->vlr->cfg.assign_tmsi = true; |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 50 | rx_from_ran = OSMO_RAT_UTRAN_IU; |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 51 | |
| 52 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 53 | lu_result_sent = RES_NONE; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 54 | gsup_expect_tx("080108" "09710000000156f0" VLR_TO_HLR); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 55 | ms_sends_msg("0508" /* MM LU */ |
| 56 | "7" /* ciph key seq: no key available */ |
| 57 | "0" /* LU type: normal */ |
| 58 | "09f107" "0017" /* LAI, LAC */ |
| 59 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 60 | "089910070000106005" /* IMSI */ |
| 61 | "3303575886" /* classmark 2 */ |
| 62 | ); |
| 63 | OSMO_ASSERT(gsup_tx_confirmed); |
| 64 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 65 | |
| 66 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 67 | /* based on auc_3g: |
| 68 | * K = 'EB215756028D60E3275E613320AEC880', |
| 69 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 70 | * SQN = 0 |
| 71 | */ |
| 72 | auth_request_sent = false; |
| 73 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 74 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 75 | gsup_rx("0a" |
| 76 | /* imsi */ |
| 77 | "0108" "09710000000156f0" |
| 78 | /* 5 auth vectors... */ |
| 79 | /* TL TL rand */ |
| 80 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 81 | /* TL sres TL kc */ |
| 82 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 83 | /* TL 3G IK */ |
| 84 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 85 | /* TL 3G CK */ |
| 86 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 87 | /* TL AUTN */ |
| 88 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 89 | /* TL RES */ |
| 90 | "2708" "e229c19e791f2e41" |
| 91 | /* TL TL rand */ |
| 92 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 93 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 94 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 95 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 96 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 97 | "2708" "7db47cf7f81e4dc7" |
| 98 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 99 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 100 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 101 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 102 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 103 | "2708" "706f996719ba609c" |
| 104 | "0362" "2010" "f023d5a3b24726e0631b64b3840f8253" |
| 105 | "2104" "d570c03f" "2208" "ec011be8919883d6" |
| 106 | "2310" "c4e58af4ba43f3bcd904e16984f086d7" |
| 107 | "2410" "0593f65e752e5cb7f473862bda05aa0a" |
| 108 | "2510" "541ff1f077270000c5ea00d658bc7e9a" |
| 109 | "2708" "3fd26072eaa2a04d" |
| 110 | "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e" |
| 111 | "2104" "b072446f220823f39f9f425ad6e6" |
| 112 | "2310" "65af0527fda95b0dc5ae4aa515cdf32f" |
| 113 | "2410" "537c3b35a3b13b08d08eeb28098f45cc" |
| 114 | "2510" "4bf4e564f75300009bc796706bc65744" |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 115 | "2708" "0edb0eadbea94ac2" |
| 116 | HLR_TO_VLR, |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 117 | NULL); |
| 118 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 119 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 120 | |
| 121 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 122 | expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef"); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 123 | ms_sends_msg("0554" "e229c19e" "2104" "791f2e41"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 124 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 125 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 126 | |
| 127 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 128 | gsup_expect_tx("04010809710000000156f0280102" VLR_TO_HLR); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 129 | ms_sends_security_mode_complete(); |
| 130 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 131 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 132 | |
| 133 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 134 | gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR, |
| 135 | "12010809710000000156f0" VLR_TO_HLR); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 136 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 137 | |
| 138 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 139 | gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 140 | |
| 141 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 142 | |
| 143 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 144 | EXPECT_CONN_COUNT(1); |
| 145 | EXPECT_ACCEPTED(false); |
| 146 | |
| 147 | btw("MS sends TMSI Realloc Complete"); |
| 148 | iu_release_expected = true; |
| 149 | iu_release_sent = false; |
| 150 | ms_sends_msg("055b"); |
| 151 | VERBOSE_ASSERT(iu_release_sent, == true, "%d"); \ |
| 152 | |
| 153 | btw("LU was successful, and the conn has already been closed"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 154 | ran_sends_clear_complete(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 155 | EXPECT_CONN_COUNT(0); |
| 156 | |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 157 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI, __func__); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 158 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 159 | VERBOSE_ASSERT(strcmp(vsub->imsi, IMSI), == 0, "%d"); |
Max | 7d41d87 | 2018-12-19 11:48:33 +0100 | [diff] [blame] | 160 | VAL_ASSERT("LAC", vsub->cgi.lai.lac, == 23, "%u"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame] | 161 | vlr_subscr_put(vsub, __func__); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 164 | static void test_call_mo() |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 165 | { |
| 166 | struct gsm_mncc mncc = { |
| 167 | .imsi = IMSI, |
| 168 | }; |
| 169 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 170 | comment_start(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 171 | |
| 172 | fake_time_start(); |
| 173 | |
| 174 | standard_lu(); |
| 175 | |
| 176 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 177 | auth_request_sent = false; |
| 178 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 179 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 180 | cm_service_result_sent = RES_NONE; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 181 | ms_sends_msg("052471" |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 182 | "03575886" /* classmark 2 */ |
| 183 | "089910070000106005" /* IMSI */); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 184 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 185 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 186 | |
| 187 | btw("needs auth, not yet accepted"); |
| 188 | EXPECT_ACCEPTED(false); |
| 189 | |
| 190 | /* On UTRAN */ |
| 191 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 192 | expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d"); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 193 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 194 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 195 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 196 | |
| 197 | btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 198 | ms_sends_security_mode_complete(); |
| 199 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 200 | |
| 201 | BTW("a call is initiated"); |
| 202 | |
| 203 | btw("SETUP gets forwarded to MNCC"); |
| 204 | cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND); |
| 205 | ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */ |
| 206 | "0406600402000581" /* Bearer Capability */ |
| 207 | "5e038121f3" /* Called Number BCD */ |
| 208 | "15020100" /* CC Capabilities */ |
| 209 | "4008" /* Supported Codec List */ |
| 210 | "04026000" /* UMTS: AMR 2 | AMR */ |
| 211 | "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */ |
| 212 | ); |
| 213 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 214 | mncc.callref = cc_to_mncc_tx_got_callref; |
| 215 | |
| 216 | btw("MNCC says that's fine"); |
| 217 | dtap_expect_tx("8302" /* CC: Call Proceeding */); |
| 218 | mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc); |
| 219 | OSMO_ASSERT(dtap_tx_confirmed); |
| 220 | |
| 221 | fake_time_passes(1, 23); |
| 222 | |
| 223 | btw("The other call leg got established (not shown here), MNCC tells us so"); |
| 224 | dtap_expect_tx("8301" /* CC: Call Alerting */); |
| 225 | mncc_sends_to_cc(MNCC_ALERT_REQ, &mncc); |
| 226 | OSMO_ASSERT(dtap_tx_confirmed); |
| 227 | |
| 228 | dtap_expect_tx("8307" /* CC: Connect */); |
| 229 | mncc_sends_to_cc(MNCC_SETUP_RSP, &mncc); |
| 230 | OSMO_ASSERT(dtap_tx_confirmed); |
| 231 | |
| 232 | fake_time_passes(1, 23); |
| 233 | |
| 234 | cc_to_mncc_expect_tx("", MNCC_SETUP_COMPL_IND); |
| 235 | ms_sends_msg("03cf" /* CC: Connect Acknowledge */); |
| 236 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 237 | |
| 238 | BTW("RTP stream goes ahead, not shown here."); |
| 239 | fake_time_passes(123, 45); |
| 240 | |
| 241 | BTW("Call ends"); |
| 242 | cc_to_mncc_expect_tx("", MNCC_DISC_IND); |
| 243 | ms_sends_msg("032502e090" /* CC: Disconnect, cause: Normal Call Clearing */); |
| 244 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 245 | |
| 246 | dtap_expect_tx("832d" /* CC: Release */); |
| 247 | mncc_sends_to_cc(MNCC_REL_REQ, &mncc); |
| 248 | OSMO_ASSERT(dtap_tx_confirmed); |
| 249 | |
| 250 | cc_to_mncc_expect_tx("", MNCC_REL_CNF); |
| 251 | expect_iu_release(); |
| 252 | ms_sends_msg("036a" /* CC: Release Complete */); |
| 253 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 254 | OSMO_ASSERT(iu_release_sent); |
| 255 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 256 | ran_sends_clear_complete(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 257 | EXPECT_CONN_COUNT(0); |
| 258 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 259 | comment_end(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 260 | } |
| 261 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 262 | static void test_call_mt() |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 263 | { |
| 264 | struct gsm_mncc mncc = { |
| 265 | .imsi = IMSI, |
| 266 | .callref = 0x423, |
| 267 | }; |
| 268 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 269 | comment_start(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 270 | |
| 271 | fake_time_start(); |
| 272 | |
| 273 | standard_lu(); |
| 274 | |
| 275 | BTW("after a while, MNCC asks us to setup a call, causing Paging"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 276 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 277 | paging_expect_imsi(IMSI); |
| 278 | paging_sent = false; |
| 279 | mncc_sends_to_cc(MNCC_SETUP_REQ, &mncc); |
| 280 | |
| 281 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 282 | |
| 283 | btw("MS replies with Paging Response, and VLR sends Auth Request"); |
| 284 | auth_request_sent = false; |
| 285 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 286 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 287 | ms_sends_msg("062707" |
| 288 | "03575886" /* classmark 2 */ |
| 289 | "089910070000106005" /* IMSI */); |
| 290 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 291 | |
| 292 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 293 | expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d"); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 294 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 295 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 296 | |
| 297 | btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup"); |
| 298 | dtap_expect_tx("0305" /* CC: Setup */); |
| 299 | ms_sends_security_mode_complete(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 300 | |
| 301 | cc_to_mncc_expect_tx(IMSI, MNCC_CALL_CONF_IND); |
| 302 | ms_sends_msg("8348" /* CC: Call Confirmed */ |
| 303 | "0406600402000581" /* Bearer Capability */ |
| 304 | "15020100" /* Call Control Capabilities */ |
| 305 | "40080402600400021f00" /* Supported Codec List */); |
| 306 | |
| 307 | fake_time_passes(1, 23); |
| 308 | |
| 309 | cc_to_mncc_expect_tx("", MNCC_ALERT_IND); |
| 310 | ms_sends_msg("8381" /* CC: Alerting */); |
| 311 | |
| 312 | fake_time_passes(1, 23); |
| 313 | |
| 314 | cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_CNF); |
| 315 | ms_sends_msg("83c7" /* CC: Connect */); |
| 316 | |
| 317 | dtap_expect_tx("030f" /* CC: Connect Acknowledge */); |
| 318 | mncc_sends_to_cc(MNCC_SETUP_COMPL_REQ, &mncc); |
| 319 | |
| 320 | BTW("RTP stream goes ahead, not shown here."); |
| 321 | fake_time_passes(123, 45); |
| 322 | |
| 323 | BTW("Call ends"); |
| 324 | cc_to_mncc_expect_tx("", MNCC_DISC_IND); |
| 325 | ms_sends_msg("832502e090" /* CC: Disconnect, cause: Normal Call Clearing */); |
| 326 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 327 | |
| 328 | dtap_expect_tx("032d" /* CC: Release */); |
| 329 | mncc_sends_to_cc(MNCC_REL_REQ, &mncc); |
| 330 | OSMO_ASSERT(dtap_tx_confirmed); |
| 331 | |
| 332 | cc_to_mncc_expect_tx("", MNCC_REL_CNF); |
| 333 | expect_iu_release(); |
| 334 | ms_sends_msg("836a" /* CC: Release Complete */); |
| 335 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 336 | OSMO_ASSERT(iu_release_sent); |
| 337 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 338 | ran_sends_clear_complete(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 339 | EXPECT_CONN_COUNT(0); |
| 340 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 341 | comment_end(); |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 344 | static void test_call_mt2() |
| 345 | { |
| 346 | struct gsm_mncc mncc = { |
| 347 | .imsi = IMSI, |
| 348 | .callref = 0x423, |
| 349 | }; |
| 350 | |
| 351 | comment_start(); |
| 352 | |
| 353 | fake_time_start(); |
| 354 | |
| 355 | standard_lu(); |
| 356 | |
| 357 | BTW("after a while, MNCC asks us to setup a call, causing Paging"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 358 | |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 359 | paging_expect_imsi(IMSI); |
| 360 | paging_sent = false; |
| 361 | mncc_sends_to_cc(MNCC_SETUP_REQ, &mncc); |
| 362 | |
| 363 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 364 | |
| 365 | btw("MS replies with Paging Response, and VLR sends Auth Request"); |
| 366 | auth_request_sent = false; |
| 367 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 368 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 369 | ms_sends_msg("062707" |
| 370 | "03575886" /* classmark 2 */ |
| 371 | "089910070000106005" /* IMSI */); |
| 372 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 373 | |
| 374 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 375 | expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d"); |
| 376 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 377 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
| 378 | |
| 379 | btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup"); |
| 380 | dtap_expect_tx("0305" /* CC: Setup */); |
| 381 | ms_sends_security_mode_complete(); |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 382 | |
| 383 | cc_to_mncc_expect_tx(IMSI, MNCC_CALL_CONF_IND); |
| 384 | ms_sends_msg("8348" /* CC: Call Confirmed */ |
| 385 | "0406600402000581" /* Bearer Capability */ |
| 386 | "15020100" /* Call Control Capabilities */ |
| 387 | "40080402600400021f00" /* Supported Codec List */); |
| 388 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 389 | |
| 390 | fake_time_passes(1, 23); |
| 391 | |
| 392 | cc_to_mncc_expect_tx("", MNCC_ALERT_IND); |
| 393 | ms_sends_msg("8381" /* CC: Alerting */); |
| 394 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 395 | |
| 396 | fake_time_passes(15, 23); |
| 397 | |
| 398 | btw("The call failed, the BSC sends a BSSMAP Clear Request"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 399 | /* FIXME: in this scenario, we send an MNCC_REL_CNF even though MNCC never asked us to MNCC_REL_REQ. Legacy |
| 400 | * behavior did get to both MNCC_REL_IND, then an MNCC_REL_REQ from MNCC as well as a final MNCC_REL_CNF, but |
| 401 | * this only worked synchronously, i.e. only with internal MNCC. Instead of mimicking that, we need a proper |
| 402 | * async solution that also works with a PBX. */ |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 403 | cc_to_mncc_expect_tx("", MNCC_REL_CNF); |
Keith Whyte | ff17f8f | 2019-08-01 12:20:25 +0200 | [diff] [blame] | 404 | dtap_expect_tx("032d0802e1af"); /* CC: Release */ |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 405 | expect_iu_release(); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 406 | msc_a_release_cn(msub_msc_a(g_msub)); |
| 407 | OSMO_ASSERT(dtap_tx_confirmed); |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 408 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 409 | OSMO_ASSERT(iu_release_sent); |
| 410 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 411 | ran_sends_clear_complete(); |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 412 | EXPECT_CONN_COUNT(0); |
| 413 | |
| 414 | /* Make sure a pending release timer doesn't fire later to access freed data */ |
| 415 | fake_time_passes(15, 23); |
| 416 | |
| 417 | clear_vlr(); |
| 418 | comment_end(); |
| 419 | } |
| 420 | |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 421 | static void test_call_mo_to_unknown() |
| 422 | { |
| 423 | struct gsm_mncc mncc = { |
| 424 | .imsi = IMSI, |
| 425 | }; |
| 426 | |
| 427 | comment_start(); |
| 428 | |
| 429 | fake_time_start(); |
| 430 | |
| 431 | standard_lu(); |
| 432 | |
| 433 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 434 | auth_request_sent = false; |
| 435 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 436 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 437 | cm_service_result_sent = RES_NONE; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 438 | ms_sends_msg("052471" |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 439 | "03575886" /* classmark 2 */ |
| 440 | "089910070000106005" /* IMSI */); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 441 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 442 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 443 | |
| 444 | btw("needs auth, not yet accepted"); |
| 445 | EXPECT_ACCEPTED(false); |
| 446 | |
| 447 | /* On UTRAN */ |
| 448 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 449 | expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d"); |
| 450 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 451 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
| 452 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 453 | |
| 454 | btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 455 | ms_sends_security_mode_complete(); |
| 456 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 457 | |
| 458 | BTW("a call is initiated"); |
| 459 | |
| 460 | btw("SETUP gets forwarded to MNCC"); |
| 461 | cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND); |
| 462 | ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */ |
| 463 | "0406600402000581" /* Bearer Capability */ |
| 464 | "5e038121f3" /* Called Number BCD */ |
| 465 | "15020100" /* CC Capabilities */ |
| 466 | "4008" /* Supported Codec List */ |
| 467 | "04026000" /* UMTS: AMR 2 | AMR */ |
| 468 | "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */ |
| 469 | ); |
| 470 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 471 | mncc.callref = cc_to_mncc_tx_got_callref; |
| 472 | |
| 473 | btw("MNCC says that's fine"); |
| 474 | dtap_expect_tx("8302" /* CC: Call Proceeding */); |
| 475 | mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc); |
| 476 | OSMO_ASSERT(dtap_tx_confirmed); |
| 477 | |
| 478 | btw("But the other side's MSISDN could not be resolved, MNCC tells us to cancel"); |
| 479 | dtap_expect_tx("832d" /* CC: Release Request */); |
| 480 | mncc_sends_to_cc(MNCC_REL_REQ, &mncc); |
| 481 | |
| 482 | dtap_expect_tx("832d" /* CC: Release Request */); |
| 483 | fake_time_passes(10, 23); |
| 484 | |
| 485 | expect_iu_release(); |
| 486 | cc_to_mncc_expect_tx("", MNCC_REL_CNF); |
| 487 | ms_sends_msg("036a" /* CC: Release Complete */); |
| 488 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 489 | OSMO_ASSERT(iu_release_sent); |
| 490 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 491 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 492 | ran_sends_clear_complete(); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 493 | EXPECT_CONN_COUNT(0); |
| 494 | clear_vlr(); |
| 495 | comment_end(); |
| 496 | } |
| 497 | |
| 498 | static void test_call_mo_to_unknown_timeout() |
| 499 | { |
| 500 | struct gsm_mncc mncc = { |
| 501 | .imsi = IMSI, |
| 502 | }; |
| 503 | |
| 504 | comment_start(); |
| 505 | |
| 506 | fake_time_start(); |
| 507 | |
| 508 | standard_lu(); |
| 509 | |
| 510 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 511 | auth_request_sent = false; |
| 512 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 513 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 514 | cm_service_result_sent = RES_NONE; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 515 | ms_sends_msg("052471" |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 516 | "03575886" /* classmark 2 */ |
| 517 | "089910070000106005" /* IMSI */); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 518 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 519 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 520 | |
| 521 | btw("needs auth, not yet accepted"); |
| 522 | EXPECT_ACCEPTED(false); |
| 523 | |
| 524 | /* On UTRAN */ |
| 525 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 526 | expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d"); |
| 527 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 528 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
| 529 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 530 | |
| 531 | btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 532 | ms_sends_security_mode_complete(); |
| 533 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 534 | |
| 535 | BTW("a call is initiated"); |
| 536 | |
| 537 | btw("SETUP gets forwarded to MNCC"); |
| 538 | cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND); |
| 539 | ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */ |
| 540 | "0406600402000581" /* Bearer Capability */ |
| 541 | "5e038121f3" /* Called Number BCD */ |
| 542 | "15020100" /* CC Capabilities */ |
| 543 | "4008" /* Supported Codec List */ |
| 544 | "04026000" /* UMTS: AMR 2 | AMR */ |
| 545 | "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */ |
| 546 | ); |
| 547 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 548 | mncc.callref = cc_to_mncc_tx_got_callref; |
| 549 | |
| 550 | btw("MNCC says that's fine"); |
| 551 | dtap_expect_tx("8302" /* CC: Call Proceeding */); |
| 552 | mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc); |
| 553 | OSMO_ASSERT(dtap_tx_confirmed); |
| 554 | |
| 555 | btw("But the other side's MSISDN could not be resolved, MNCC tells us to cancel"); |
| 556 | dtap_expect_tx("832d" /* CC: Release Request */); |
| 557 | mncc_sends_to_cc(MNCC_REL_REQ, &mncc); |
| 558 | |
| 559 | btw("Despite our repeated CC Release Requests, the MS does not respond anymore"); |
| 560 | dtap_expect_tx("832d" /* CC: Release Request */); |
| 561 | fake_time_passes(10, 23); |
| 562 | |
| 563 | btw("The CC Release times out and we still properly clear the conn"); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 564 | cc_to_mncc_expect_tx("", MNCC_REL_CNF); |
Neels Hofmeyr | d6a769b | 2018-03-12 23:59:07 +0100 | [diff] [blame] | 565 | expect_iu_release(); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 566 | fake_time_passes(10, 23); |
| 567 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 568 | OSMO_ASSERT(iu_release_sent); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 569 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 570 | ran_sends_clear_complete(); |
Neels Hofmeyr | d6a769b | 2018-03-12 23:59:07 +0100 | [diff] [blame] | 571 | EXPECT_CONN_COUNT(0); |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 572 | clear_vlr(); |
| 573 | comment_end(); |
| 574 | } |
| 575 | |
| 576 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 577 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 578 | test_call_mo, |
| 579 | test_call_mt, |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 580 | test_call_mt2, |
Neels Hofmeyr | eb1cfdb | 2018-03-15 13:42:10 +0100 | [diff] [blame] | 581 | test_call_mo_to_unknown, |
| 582 | test_call_mo_to_unknown_timeout, |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 583 | NULL |
| 584 | }; |