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 | |
| 28 | void mncc_sends_to_cc(uint32_t msg_type, struct gsm_mncc *mncc) |
| 29 | { |
| 30 | mncc->msg_type = msg_type; |
| 31 | mncc_tx_to_cc(net, msg_type, mncc); |
| 32 | } |
| 33 | |
| 34 | #define IMSI "901700000010650" |
| 35 | |
| 36 | static void standard_lu() |
| 37 | { |
| 38 | struct vlr_subscr *vsub; |
| 39 | |
| 40 | net->authentication_required = true; |
| 41 | net->vlr->cfg.assign_tmsi = true; |
| 42 | rx_from_ran = RAN_UTRAN_IU; |
| 43 | |
| 44 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 45 | lu_result_sent = RES_NONE; |
| 46 | gsup_expect_tx("080108" "09710000000156f0"); |
| 47 | ms_sends_msg("0508" /* MM LU */ |
| 48 | "7" /* ciph key seq: no key available */ |
| 49 | "0" /* LU type: normal */ |
| 50 | "09f107" "0017" /* LAI, LAC */ |
| 51 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 52 | "089910070000106005" /* IMSI */ |
| 53 | "3303575886" /* classmark 2 */ |
| 54 | ); |
| 55 | OSMO_ASSERT(gsup_tx_confirmed); |
| 56 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 57 | |
| 58 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 59 | /* based on auc_3g: |
| 60 | * K = 'EB215756028D60E3275E613320AEC880', |
| 61 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 62 | * SQN = 0 |
| 63 | */ |
| 64 | auth_request_sent = false; |
| 65 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 66 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 67 | gsup_rx("0a" |
| 68 | /* imsi */ |
| 69 | "0108" "09710000000156f0" |
| 70 | /* 5 auth vectors... */ |
| 71 | /* TL TL rand */ |
| 72 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 73 | /* TL sres TL kc */ |
| 74 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 75 | /* TL 3G IK */ |
| 76 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 77 | /* TL 3G CK */ |
| 78 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 79 | /* TL AUTN */ |
| 80 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 81 | /* TL RES */ |
| 82 | "2708" "e229c19e791f2e41" |
| 83 | /* TL TL rand */ |
| 84 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 85 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 86 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 87 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 88 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 89 | "2708" "7db47cf7f81e4dc7" |
| 90 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 91 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 92 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 93 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 94 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 95 | "2708" "706f996719ba609c" |
| 96 | "0362" "2010" "f023d5a3b24726e0631b64b3840f8253" |
| 97 | "2104" "d570c03f" "2208" "ec011be8919883d6" |
| 98 | "2310" "c4e58af4ba43f3bcd904e16984f086d7" |
| 99 | "2410" "0593f65e752e5cb7f473862bda05aa0a" |
| 100 | "2510" "541ff1f077270000c5ea00d658bc7e9a" |
| 101 | "2708" "3fd26072eaa2a04d" |
| 102 | "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e" |
| 103 | "2104" "b072446f220823f39f9f425ad6e6" |
| 104 | "2310" "65af0527fda95b0dc5ae4aa515cdf32f" |
| 105 | "2410" "537c3b35a3b13b08d08eeb28098f45cc" |
| 106 | "2510" "4bf4e564f75300009bc796706bc65744" |
| 107 | "2708" "0edb0eadbea94ac2", |
| 108 | NULL); |
| 109 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 110 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 111 | |
| 112 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 113 | cipher_mode_cmd_sent = false; |
| 114 | ms_sends_msg("0554" "e229c19e" "2104" "791f2e41"); |
| 115 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 116 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 117 | |
| 118 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR"); |
| 119 | gsup_expect_tx("04010809710000000156f0"); |
| 120 | ms_sends_security_mode_complete(); |
| 121 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 122 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 123 | |
| 124 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 125 | gsup_rx("10010809710000000156f00804032443f2", |
| 126 | "12010809710000000156f0"); |
| 127 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 128 | |
| 129 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 130 | gsup_rx("06010809710000000156f0", NULL); |
| 131 | |
| 132 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 133 | |
| 134 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 135 | EXPECT_CONN_COUNT(1); |
| 136 | EXPECT_ACCEPTED(false); |
| 137 | |
| 138 | btw("MS sends TMSI Realloc Complete"); |
| 139 | iu_release_expected = true; |
| 140 | iu_release_sent = false; |
| 141 | ms_sends_msg("055b"); |
| 142 | VERBOSE_ASSERT(iu_release_sent, == true, "%d"); \ |
| 143 | |
| 144 | btw("LU was successful, and the conn has already been closed"); |
| 145 | EXPECT_CONN_COUNT(0); |
| 146 | |
| 147 | vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI); |
| 148 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 149 | VERBOSE_ASSERT(strcmp(vsub->imsi, IMSI), == 0, "%d"); |
| 150 | VERBOSE_ASSERT(vsub->lac, == 23, "%u"); |
| 151 | vlr_subscr_put(vsub); |
| 152 | } |
| 153 | |
| 154 | void test_call_mo() |
| 155 | { |
| 156 | struct gsm_mncc mncc = { |
| 157 | .imsi = IMSI, |
| 158 | }; |
| 159 | |
| 160 | comment_start(); |
| 161 | |
| 162 | fake_time_start(); |
| 163 | |
| 164 | standard_lu(); |
| 165 | |
| 166 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 167 | auth_request_sent = false; |
| 168 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 169 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 170 | cm_service_result_sent = RES_NONE; |
| 171 | ms_sends_msg("052478" |
| 172 | "03575886" /* classmark 2 */ |
| 173 | "089910070000106005" /* IMSI */); |
| 174 | OSMO_ASSERT(g_conn); |
| 175 | OSMO_ASSERT(g_conn->conn_fsm); |
| 176 | OSMO_ASSERT(g_conn->vsub); |
| 177 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 178 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 179 | |
| 180 | btw("needs auth, not yet accepted"); |
| 181 | EXPECT_ACCEPTED(false); |
| 182 | |
| 183 | /* On UTRAN */ |
| 184 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 185 | cipher_mode_cmd_sent = false; |
| 186 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 187 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 188 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 189 | |
| 190 | btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 191 | ms_sends_security_mode_complete(); |
| 192 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 193 | |
| 194 | BTW("a call is initiated"); |
| 195 | |
| 196 | btw("SETUP gets forwarded to MNCC"); |
| 197 | cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND); |
| 198 | ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */ |
| 199 | "0406600402000581" /* Bearer Capability */ |
| 200 | "5e038121f3" /* Called Number BCD */ |
| 201 | "15020100" /* CC Capabilities */ |
| 202 | "4008" /* Supported Codec List */ |
| 203 | "04026000" /* UMTS: AMR 2 | AMR */ |
| 204 | "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */ |
| 205 | ); |
| 206 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 207 | mncc.callref = cc_to_mncc_tx_got_callref; |
| 208 | |
| 209 | btw("MNCC says that's fine"); |
| 210 | dtap_expect_tx("8302" /* CC: Call Proceeding */); |
| 211 | mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc); |
| 212 | OSMO_ASSERT(dtap_tx_confirmed); |
| 213 | |
| 214 | fake_time_passes(1, 23); |
| 215 | |
| 216 | btw("The other call leg got established (not shown here), MNCC tells us so"); |
| 217 | dtap_expect_tx("8301" /* CC: Call Alerting */); |
| 218 | mncc_sends_to_cc(MNCC_ALERT_REQ, &mncc); |
| 219 | OSMO_ASSERT(dtap_tx_confirmed); |
| 220 | |
| 221 | dtap_expect_tx("8307" /* CC: Connect */); |
| 222 | mncc_sends_to_cc(MNCC_SETUP_RSP, &mncc); |
| 223 | OSMO_ASSERT(dtap_tx_confirmed); |
| 224 | |
| 225 | fake_time_passes(1, 23); |
| 226 | |
| 227 | cc_to_mncc_expect_tx("", MNCC_SETUP_COMPL_IND); |
| 228 | ms_sends_msg("03cf" /* CC: Connect Acknowledge */); |
| 229 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 230 | |
| 231 | BTW("RTP stream goes ahead, not shown here."); |
| 232 | fake_time_passes(123, 45); |
| 233 | |
| 234 | BTW("Call ends"); |
| 235 | cc_to_mncc_expect_tx("", MNCC_DISC_IND); |
| 236 | ms_sends_msg("032502e090" /* CC: Disconnect, cause: Normal Call Clearing */); |
| 237 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 238 | |
| 239 | dtap_expect_tx("832d" /* CC: Release */); |
| 240 | mncc_sends_to_cc(MNCC_REL_REQ, &mncc); |
| 241 | OSMO_ASSERT(dtap_tx_confirmed); |
| 242 | |
| 243 | cc_to_mncc_expect_tx("", MNCC_REL_CNF); |
| 244 | expect_iu_release(); |
| 245 | ms_sends_msg("036a" /* CC: Release Complete */); |
| 246 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 247 | OSMO_ASSERT(iu_release_sent); |
| 248 | |
| 249 | EXPECT_CONN_COUNT(0); |
| 250 | clear_vlr(); |
| 251 | comment_end(); |
| 252 | } |
| 253 | |
| 254 | void test_call_mt() |
| 255 | { |
| 256 | struct gsm_mncc mncc = { |
| 257 | .imsi = IMSI, |
| 258 | .callref = 0x423, |
| 259 | }; |
| 260 | |
| 261 | comment_start(); |
| 262 | |
| 263 | fake_time_start(); |
| 264 | |
| 265 | standard_lu(); |
| 266 | |
| 267 | BTW("after a while, MNCC asks us to setup a call, causing Paging"); |
| 268 | |
| 269 | paging_expect_imsi(IMSI); |
| 270 | paging_sent = false; |
| 271 | mncc_sends_to_cc(MNCC_SETUP_REQ, &mncc); |
| 272 | |
| 273 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 274 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 275 | |
| 276 | btw("MS replies with Paging Response, and VLR sends Auth Request"); |
| 277 | auth_request_sent = false; |
| 278 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 279 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 280 | ms_sends_msg("062707" |
| 281 | "03575886" /* classmark 2 */ |
| 282 | "089910070000106005" /* IMSI */); |
| 283 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 284 | |
| 285 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 286 | cipher_mode_cmd_sent = false; |
| 287 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 288 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 289 | |
| 290 | btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup"); |
| 291 | dtap_expect_tx("0305" /* CC: Setup */); |
| 292 | ms_sends_security_mode_complete(); |
| 293 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 294 | |
| 295 | cc_to_mncc_expect_tx(IMSI, MNCC_CALL_CONF_IND); |
| 296 | ms_sends_msg("8348" /* CC: Call Confirmed */ |
| 297 | "0406600402000581" /* Bearer Capability */ |
| 298 | "15020100" /* Call Control Capabilities */ |
| 299 | "40080402600400021f00" /* Supported Codec List */); |
| 300 | |
| 301 | fake_time_passes(1, 23); |
| 302 | |
| 303 | cc_to_mncc_expect_tx("", MNCC_ALERT_IND); |
| 304 | ms_sends_msg("8381" /* CC: Alerting */); |
| 305 | |
| 306 | fake_time_passes(1, 23); |
| 307 | |
| 308 | cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_CNF); |
| 309 | ms_sends_msg("83c7" /* CC: Connect */); |
| 310 | |
| 311 | dtap_expect_tx("030f" /* CC: Connect Acknowledge */); |
| 312 | mncc_sends_to_cc(MNCC_SETUP_COMPL_REQ, &mncc); |
| 313 | |
| 314 | BTW("RTP stream goes ahead, not shown here."); |
| 315 | fake_time_passes(123, 45); |
| 316 | |
| 317 | BTW("Call ends"); |
| 318 | cc_to_mncc_expect_tx("", MNCC_DISC_IND); |
| 319 | ms_sends_msg("832502e090" /* CC: Disconnect, cause: Normal Call Clearing */); |
| 320 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 321 | |
| 322 | dtap_expect_tx("032d" /* CC: Release */); |
| 323 | mncc_sends_to_cc(MNCC_REL_REQ, &mncc); |
| 324 | OSMO_ASSERT(dtap_tx_confirmed); |
| 325 | |
| 326 | cc_to_mncc_expect_tx("", MNCC_REL_CNF); |
| 327 | expect_iu_release(); |
| 328 | ms_sends_msg("836a" /* CC: Release Complete */); |
| 329 | OSMO_ASSERT(cc_to_mncc_tx_confirmed); |
| 330 | OSMO_ASSERT(iu_release_sent); |
| 331 | |
| 332 | EXPECT_CONN_COUNT(0); |
| 333 | clear_vlr(); |
| 334 | comment_end(); |
| 335 | } |
| 336 | |
| 337 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 338 | test_call_mo, |
| 339 | test_call_mt, |
| 340 | NULL |
| 341 | }; |