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