Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +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 | |
Max | 093300d | 2018-02-07 12:06:03 +0100 | [diff] [blame] | 26 | void test_ciph(const char *imsi) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 27 | { |
| 28 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 29 | |
| 30 | comment_start(); |
| 31 | |
| 32 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 33 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 34 | |
| 35 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 36 | lu_result_sent = RES_NONE; |
| 37 | gsup_expect_tx("08010809710000004026f0"); |
| 38 | ms_sends_msg("050802008168000130089910070000006402"); |
| 39 | OSMO_ASSERT(gsup_tx_confirmed); |
| 40 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 41 | |
| 42 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 43 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 44 | auth_request_sent = false; |
| 45 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 46 | auth_request_expect_autn = NULL; |
| 47 | gsup_rx("0a" |
| 48 | /* imsi */ |
| 49 | "0108" "09710000004026f0" |
| 50 | /* 5 auth vectors... */ |
| 51 | /* TL TL rand */ |
| 52 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 53 | /* TL sres TL kc */ |
| 54 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 55 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 56 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 57 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 58 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 59 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 60 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 61 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 62 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 63 | NULL); |
| 64 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 65 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 66 | |
| 67 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
| 68 | cipher_mode_cmd_sent = false; |
| 69 | ms_sends_msg("05542d8b2c3e"); |
| 70 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 71 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 72 | |
| 73 | btw("needs ciph, not yet accepted"); |
| 74 | EXPECT_ACCEPTED(false); |
| 75 | thwart_rx_non_initial_requests(); |
| 76 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 77 | |
| 78 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
| 79 | gsup_expect_tx("04010809710000004026f0"); |
| 80 | ms_sends_msg("0632"); |
| 81 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 82 | |
| 83 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 84 | gsup_rx("10010809710000004026f00804036470f1", |
| 85 | "12010809710000004026f0"); |
| 86 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 87 | |
| 88 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 89 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 90 | gsup_rx("06010809710000004026f0", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 91 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 92 | |
| 93 | btw("LU was successful, and the conn has already been closed"); |
| 94 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 95 | EXPECT_CONN_COUNT(0); |
| 96 | |
| 97 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 98 | cm_service_result_sent = RES_NONE; |
| 99 | auth_request_sent = false; |
| 100 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 101 | ms_sends_msg("05247803305886089910070000006402"); |
| 102 | OSMO_ASSERT(g_conn); |
| 103 | OSMO_ASSERT(g_conn->conn_fsm); |
| 104 | OSMO_ASSERT(g_conn->vsub); |
| 105 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 106 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 107 | |
| 108 | btw("needs auth, not yet accepted"); |
| 109 | EXPECT_ACCEPTED(false); |
| 110 | thwart_rx_non_initial_requests(); |
| 111 | |
| 112 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
| 113 | cipher_mode_cmd_sent = false; |
| 114 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 115 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 116 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 117 | |
| 118 | btw("needs ciph, not yet accepted"); |
| 119 | EXPECT_ACCEPTED(false); |
| 120 | thwart_rx_non_initial_requests(); |
| 121 | |
| 122 | btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 123 | ms_sends_msg("0632"); |
| 124 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 125 | |
| 126 | btw("a USSD request is serviced"); |
| 127 | dtap_expect_tx_ussd("Your extension is 46071\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 128 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 129 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
| 130 | OSMO_ASSERT(dtap_tx_confirmed); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 131 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 132 | |
| 133 | btw("all requests serviced, conn has been released"); |
| 134 | EXPECT_CONN_COUNT(0); |
| 135 | |
| 136 | BTW("an SMS is sent, MS is paged"); |
| 137 | paging_expect_imsi(imsi); |
| 138 | paging_sent = false; |
| 139 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 140 | OSMO_ASSERT(vsub); |
| 141 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 142 | |
| 143 | send_sms(vsub, vsub, |
| 144 | "Privacy in residential applications is a desirable" |
| 145 | " marketing option."); |
| 146 | |
| 147 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 148 | vlr_subscr_put(vsub); |
| 149 | vsub = NULL; |
| 150 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 151 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 152 | |
| 153 | btw("the subscriber and its pending request should remain"); |
| 154 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 155 | OSMO_ASSERT(vsub); |
| 156 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 157 | vlr_subscr_put(vsub); |
| 158 | |
| 159 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 160 | auth_request_sent = false; |
| 161 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 162 | ms_sends_msg("06270703305882089910070000006402"); |
| 163 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 164 | |
| 165 | btw("needs auth, not yet accepted"); |
| 166 | EXPECT_ACCEPTED(false); |
| 167 | thwart_rx_non_initial_requests(); |
| 168 | |
| 169 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
| 170 | cipher_mode_cmd_sent = false; |
| 171 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 172 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 173 | |
| 174 | btw("needs ciph, not yet accepted"); |
| 175 | EXPECT_ACCEPTED(false); |
| 176 | thwart_rx_non_initial_requests(); |
| 177 | |
| 178 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS"); |
| 179 | dtap_expect_tx("09" /* SMS messages */ |
| 180 | "01" /* CP-DATA */ |
| 181 | "58" /* length */ |
| 182 | "01" /* Network to MS */ |
| 183 | "00" /* reference */ |
| 184 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 185 | "0791" "447758100650" /* 447785016005 */ |
| 186 | "00" /* dest */ |
| 187 | /* SMS TPDU */ |
| 188 | "4c" /* len */ |
| 189 | "00" /* SMS deliver */ |
| 190 | "05806470f1" /* originating address 46071 */ |
| 191 | "00" /* TP-PID */ |
| 192 | "00" /* GSM default alphabet */ |
| 193 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 194 | "000000" /* H-M-S */ |
| 195 | "00" /* GMT+0 */ |
| 196 | "44" /* data length */ |
| 197 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 198 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 199 | "0c7ac3e9e9b7db05"); |
| 200 | ms_sends_msg("0632"); |
| 201 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 202 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 203 | |
| 204 | btw("SMS was delivered, no requests pending for subscr"); |
| 205 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 206 | OSMO_ASSERT(vsub); |
| 207 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 208 | vlr_subscr_put(vsub); |
| 209 | |
| 210 | btw("conn is still open to wait for SMS ack dance"); |
| 211 | EXPECT_CONN_COUNT(1); |
| 212 | |
| 213 | btw("MS replies with CP-ACK for received SMS"); |
| 214 | ms_sends_msg("8904"); |
| 215 | EXPECT_CONN_COUNT(1); |
| 216 | |
| 217 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 218 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 219 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 220 | ms_sends_msg("890106020041020000"); |
| 221 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 222 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 223 | |
| 224 | btw("SMS is done, conn is gone"); |
| 225 | EXPECT_CONN_COUNT(0); |
| 226 | |
| 227 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 228 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 229 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 230 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 231 | |
| 232 | EXPECT_CONN_COUNT(0); |
| 233 | clear_vlr(); |
| 234 | comment_end(); |
| 235 | } |
| 236 | |
Max | 093300d | 2018-02-07 12:06:03 +0100 | [diff] [blame] | 237 | void test_ciph_tmsi(const char *imsi) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 238 | { |
| 239 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 240 | |
| 241 | comment_start(); |
| 242 | |
| 243 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 244 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 245 | net->vlr->cfg.assign_tmsi = true; |
| 246 | |
| 247 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 248 | lu_result_sent = RES_NONE; |
| 249 | gsup_expect_tx("08010809710000004026f0"); |
| 250 | ms_sends_msg("050802008168000130089910070000006402"); |
| 251 | OSMO_ASSERT(gsup_tx_confirmed); |
| 252 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 253 | |
| 254 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 255 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 256 | auth_request_sent = false; |
| 257 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 258 | auth_request_expect_autn = NULL; |
| 259 | gsup_rx("0a" |
| 260 | /* imsi */ |
| 261 | "0108" "09710000004026f0" |
| 262 | /* 5 auth vectors... */ |
| 263 | /* TL TL rand */ |
| 264 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 265 | /* TL sres TL kc */ |
| 266 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 267 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 268 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 269 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 270 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 271 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 272 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 273 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 274 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 275 | NULL); |
| 276 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 277 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 278 | |
| 279 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
| 280 | cipher_mode_cmd_sent = false; |
| 281 | ms_sends_msg("05542d8b2c3e"); |
| 282 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 283 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 284 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 285 | |
| 286 | btw("needs ciph, not yet accepted"); |
| 287 | EXPECT_ACCEPTED(false); |
| 288 | thwart_rx_non_initial_requests(); |
| 289 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 290 | |
| 291 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
| 292 | gsup_expect_tx("04010809710000004026f0"); |
| 293 | ms_sends_msg("0632"); |
| 294 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 295 | |
| 296 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 297 | gsup_rx("10010809710000004026f00804036470f1", |
| 298 | "12010809710000004026f0"); |
| 299 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 300 | |
| 301 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 302 | gsup_rx("06010809710000004026f0", NULL); |
| 303 | |
| 304 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 305 | EXPECT_CONN_COUNT(1); |
| 306 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 307 | EXPECT_ACCEPTED(false); |
| 308 | thwart_rx_non_initial_requests(); |
| 309 | |
| 310 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 311 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 312 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 313 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 314 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 315 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 316 | vlr_subscr_put(vsub); |
| 317 | |
| 318 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 319 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 320 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 321 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 322 | |
| 323 | btw("LU was successful, and the conn has already been closed"); |
| 324 | EXPECT_CONN_COUNT(0); |
| 325 | |
| 326 | btw("Subscriber has the new TMSI"); |
| 327 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 328 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 329 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 330 | VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x"); |
| 331 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 332 | vlr_subscr_put(vsub); |
| 333 | |
| 334 | BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector"); |
| 335 | cm_service_result_sent = RES_NONE; |
| 336 | auth_request_sent = false; |
| 337 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 338 | auth_request_expect_autn = NULL; |
| 339 | ms_sends_msg("05247803305886" "05f4" "03020100"); |
| 340 | OSMO_ASSERT(g_conn); |
| 341 | OSMO_ASSERT(g_conn->conn_fsm); |
| 342 | OSMO_ASSERT(g_conn->vsub); |
| 343 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 344 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 345 | |
| 346 | btw("needs auth, not yet accepted"); |
| 347 | EXPECT_ACCEPTED(false); |
| 348 | thwart_rx_non_initial_requests(); |
| 349 | |
| 350 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
| 351 | cipher_mode_cmd_sent = false; |
| 352 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 353 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 354 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 355 | |
| 356 | btw("needs ciph, not yet accepted"); |
| 357 | EXPECT_ACCEPTED(false); |
| 358 | thwart_rx_non_initial_requests(); |
| 359 | |
| 360 | btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 361 | ms_sends_msg("0632"); |
| 362 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 363 | |
| 364 | btw("a USSD request is serviced"); |
| 365 | dtap_expect_tx_ussd("Your extension is 46071\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 366 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 367 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
| 368 | OSMO_ASSERT(dtap_tx_confirmed); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 369 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 370 | |
| 371 | btw("all requests serviced, conn has been released"); |
| 372 | EXPECT_CONN_COUNT(0); |
| 373 | |
| 374 | BTW("an SMS is sent, MS is paged"); |
| 375 | paging_expect_tmsi(0x03020100); |
| 376 | paging_sent = false; |
| 377 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 378 | OSMO_ASSERT(vsub); |
| 379 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 380 | |
| 381 | send_sms(vsub, vsub, |
| 382 | "Privacy in residential applications is a desirable" |
| 383 | " marketing option."); |
| 384 | |
| 385 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 386 | vlr_subscr_put(vsub); |
| 387 | vsub = NULL; |
| 388 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 389 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 390 | |
| 391 | btw("the subscriber and its pending request should remain"); |
| 392 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 393 | OSMO_ASSERT(vsub); |
| 394 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 395 | vlr_subscr_put(vsub); |
| 396 | |
| 397 | btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key"); |
| 398 | auth_request_sent = false; |
| 399 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 400 | ms_sends_msg("06270703305882" "05f4" "03020100"); |
| 401 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 402 | |
| 403 | btw("needs auth, not yet accepted"); |
| 404 | EXPECT_ACCEPTED(false); |
| 405 | thwart_rx_non_initial_requests(); |
| 406 | |
| 407 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
| 408 | cipher_mode_cmd_sent = false; |
| 409 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 410 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 411 | |
| 412 | btw("needs ciph, not yet accepted"); |
| 413 | EXPECT_ACCEPTED(false); |
| 414 | thwart_rx_non_initial_requests(); |
| 415 | |
| 416 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS"); |
| 417 | dtap_expect_tx("09" /* SMS messages */ |
| 418 | "01" /* CP-DATA */ |
| 419 | "58" /* length */ |
| 420 | "01" /* Network to MS */ |
| 421 | "00" /* reference */ |
| 422 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 423 | "0791" "447758100650" /* 447785016005 */ |
| 424 | "00" /* dest */ |
| 425 | /* SMS TPDU */ |
| 426 | "4c" /* len */ |
| 427 | "00" /* SMS deliver */ |
| 428 | "05806470f1" /* originating address 46071 */ |
| 429 | "00" /* TP-PID */ |
| 430 | "00" /* GSM default alphabet */ |
| 431 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 432 | "000000" /* H-M-S */ |
| 433 | "00" /* GMT+0 */ |
| 434 | "44" /* data length */ |
| 435 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 436 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 437 | "0c7ac3e9e9b7db05"); |
| 438 | ms_sends_msg("0632"); |
| 439 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 440 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 441 | |
| 442 | btw("SMS was delivered, no requests pending for subscr"); |
| 443 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 444 | OSMO_ASSERT(vsub); |
| 445 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 446 | vlr_subscr_put(vsub); |
| 447 | |
| 448 | btw("conn is still open to wait for SMS ack dance"); |
| 449 | EXPECT_CONN_COUNT(1); |
| 450 | |
| 451 | btw("MS replies with CP-ACK for received SMS"); |
| 452 | ms_sends_msg("8904"); |
| 453 | EXPECT_CONN_COUNT(1); |
| 454 | |
| 455 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 456 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 457 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 458 | ms_sends_msg("890106020041020000"); |
| 459 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 460 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 461 | |
| 462 | btw("SMS is done, conn is gone"); |
| 463 | EXPECT_CONN_COUNT(0); |
| 464 | |
| 465 | BTW("subscriber detaches, using TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 466 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 467 | ms_sends_msg("050130" "05f4" "03020100"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 468 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 469 | |
| 470 | EXPECT_CONN_COUNT(0); |
| 471 | clear_vlr(); |
| 472 | comment_end(); |
| 473 | } |
| 474 | |
Max | 093300d | 2018-02-07 12:06:03 +0100 | [diff] [blame] | 475 | void test_ciph_imei(const char *imsi) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 476 | { |
| 477 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 478 | |
| 479 | comment_start(); |
| 480 | |
| 481 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 482 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 483 | net->vlr->cfg.check_imei_rqd = true; |
| 484 | |
| 485 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 486 | lu_result_sent = RES_NONE; |
| 487 | gsup_expect_tx("08010809710000004026f0"); |
| 488 | ms_sends_msg("050802008168000130089910070000006402"); |
| 489 | OSMO_ASSERT(gsup_tx_confirmed); |
| 490 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 491 | |
| 492 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 493 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 494 | auth_request_sent = false; |
| 495 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 496 | auth_request_expect_autn = NULL; |
| 497 | gsup_rx("0a" |
| 498 | /* imsi */ |
| 499 | "0108" "09710000004026f0" |
| 500 | /* 5 auth vectors... */ |
| 501 | /* TL TL rand */ |
| 502 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 503 | /* TL sres TL kc */ |
| 504 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 505 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 506 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 507 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 508 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 509 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 510 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 511 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 512 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 513 | NULL); |
| 514 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 515 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 516 | |
| 517 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
| 518 | cipher_mode_cmd_sent = false; |
| 519 | ms_sends_msg("05542d8b2c3e"); |
| 520 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 521 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 522 | |
| 523 | btw("needs ciph, not yet accepted"); |
| 524 | EXPECT_ACCEPTED(false); |
| 525 | thwart_rx_non_initial_requests(); |
| 526 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 527 | |
| 528 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
| 529 | gsup_expect_tx("04010809710000004026f0"); |
| 530 | ms_sends_msg("0632"); |
| 531 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 532 | |
| 533 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 534 | gsup_rx("10010809710000004026f00804036470f1", |
| 535 | "12010809710000004026f0"); |
| 536 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 537 | |
| 538 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 539 | dtap_expect_tx("051802"); |
| 540 | gsup_rx("06010809710000004026f0", NULL); |
| 541 | |
| 542 | btw("We will only do business when the IMEI is known"); |
| 543 | EXPECT_CONN_COUNT(1); |
| 544 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 545 | OSMO_ASSERT(vsub); |
| 546 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 547 | vlr_subscr_put(vsub); |
| 548 | EXPECT_ACCEPTED(false); |
| 549 | thwart_rx_non_initial_requests(); |
| 550 | |
| 551 | btw("MS replies with an Identity Response"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 552 | expect_bssap_clear(); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 553 | ms_sends_msg("0559084a32244332244302"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 554 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 555 | |
| 556 | btw("LU was successful, and the conn has already been closed"); |
| 557 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 558 | EXPECT_CONN_COUNT(0); |
| 559 | |
| 560 | btw("Subscriber has the IMEI"); |
| 561 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 562 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 563 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 564 | vlr_subscr_put(vsub); |
| 565 | |
| 566 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 567 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 568 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 569 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 570 | |
| 571 | EXPECT_CONN_COUNT(0); |
| 572 | clear_vlr(); |
| 573 | comment_end(); |
| 574 | } |
| 575 | |
Max | 093300d | 2018-02-07 12:06:03 +0100 | [diff] [blame] | 576 | void test_ciph_imeisv(const char *imsi) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 577 | { |
| 578 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 579 | |
| 580 | comment_start(); |
| 581 | |
| 582 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 583 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 54a706c | 2017-07-18 15:39:27 +0200 | [diff] [blame] | 584 | net->vlr->cfg.retrieve_imeisv_ciphered = true; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 585 | |
| 586 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 587 | lu_result_sent = RES_NONE; |
| 588 | gsup_expect_tx("08010809710000004026f0"); |
| 589 | ms_sends_msg("050802008168000130089910070000006402"); |
| 590 | OSMO_ASSERT(gsup_tx_confirmed); |
| 591 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 592 | |
| 593 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 594 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 595 | auth_request_sent = false; |
| 596 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 597 | auth_request_expect_autn = NULL; |
| 598 | gsup_rx("0a" |
| 599 | /* imsi */ |
| 600 | "0108" "09710000004026f0" |
| 601 | /* 5 auth vectors... */ |
| 602 | /* TL TL rand */ |
| 603 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 604 | /* TL sres TL kc */ |
| 605 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 606 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 607 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 608 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 609 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 610 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 611 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 612 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 613 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 614 | NULL); |
| 615 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 616 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 617 | |
| 618 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
| 619 | cipher_mode_cmd_sent = false; |
| 620 | ms_sends_msg("05542d8b2c3e"); |
| 621 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 622 | VERBOSE_ASSERT(cipher_mode_cmd_sent_with_imeisv, == true, "%d"); |
| 623 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 624 | |
| 625 | btw("needs ciph, not yet accepted"); |
| 626 | EXPECT_ACCEPTED(false); |
| 627 | thwart_rx_non_initial_requests(); |
| 628 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 629 | |
| 630 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 631 | OSMO_ASSERT(vsub); |
| 632 | VERBOSE_ASSERT(vsub->imeisv[0], == 0, "%d"); |
| 633 | vlr_subscr_put(vsub); |
| 634 | |
| 635 | btw("MS sends Ciphering Mode Complete with IMEISV, VLR accepts and sends GSUP LU Req to HLR"); |
| 636 | gsup_expect_tx("04010809710000004026f0"); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 637 | ms_sends_msg("063217094b32244332244372f5"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 638 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 639 | |
| 640 | btw("Subscriber has the IMEISV"); |
| 641 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 642 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 643 | VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 644 | vlr_subscr_put(vsub); |
| 645 | |
| 646 | EXPECT_ACCEPTED(false); |
| 647 | thwart_rx_non_initial_requests(); |
| 648 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 649 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 650 | gsup_rx("10010809710000004026f00804036470f1", |
| 651 | "12010809710000004026f0"); |
| 652 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 653 | |
| 654 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 655 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 656 | gsup_rx("06010809710000004026f0", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 657 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 658 | |
| 659 | btw("LU was successful, and the conn has already been closed"); |
| 660 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 661 | EXPECT_CONN_COUNT(0); |
| 662 | |
| 663 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 664 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 665 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 666 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 667 | |
| 668 | EXPECT_CONN_COUNT(0); |
| 669 | clear_vlr(); |
| 670 | comment_end(); |
| 671 | } |
| 672 | |
Max | 093300d | 2018-02-07 12:06:03 +0100 | [diff] [blame] | 673 | void test_ciph_tmsi_imei(const char *imsi) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 674 | { |
| 675 | struct vlr_subscr *vsub; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 676 | |
| 677 | comment_start(); |
| 678 | |
| 679 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 680 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 681 | net->vlr->cfg.assign_tmsi = true; |
| 682 | net->vlr->cfg.check_imei_rqd = true; |
| 683 | |
| 684 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 685 | lu_result_sent = RES_NONE; |
| 686 | gsup_expect_tx("08010809710000004026f0"); |
| 687 | ms_sends_msg("050802008168000130089910070000006402"); |
| 688 | OSMO_ASSERT(gsup_tx_confirmed); |
| 689 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 690 | |
| 691 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 692 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 693 | auth_request_sent = false; |
| 694 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 695 | auth_request_expect_autn = NULL; |
| 696 | gsup_rx("0a" |
| 697 | /* imsi */ |
| 698 | "0108" "09710000004026f0" |
| 699 | /* 5 auth vectors... */ |
| 700 | /* TL TL rand */ |
| 701 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 702 | /* TL sres TL kc */ |
| 703 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 704 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 705 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 706 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 707 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 708 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 709 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 710 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 711 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 712 | NULL); |
| 713 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 714 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 715 | |
| 716 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
| 717 | cipher_mode_cmd_sent = false; |
| 718 | ms_sends_msg("05542d8b2c3e"); |
| 719 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 720 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 721 | |
| 722 | btw("needs ciph, not yet accepted"); |
| 723 | EXPECT_ACCEPTED(false); |
| 724 | thwart_rx_non_initial_requests(); |
| 725 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 726 | |
| 727 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
| 728 | gsup_expect_tx("04010809710000004026f0"); |
| 729 | ms_sends_msg("0632"); |
| 730 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 731 | |
| 732 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 733 | gsup_rx("10010809710000004026f00804036470f1", |
| 734 | "12010809710000004026f0"); |
| 735 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 736 | |
| 737 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 738 | dtap_expect_tx("051802"); |
| 739 | gsup_rx("06010809710000004026f0", NULL); |
| 740 | |
| 741 | btw("We will only do business when the IMEI is known"); |
| 742 | EXPECT_CONN_COUNT(1); |
| 743 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 744 | OSMO_ASSERT(vsub); |
| 745 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 746 | vlr_subscr_put(vsub); |
| 747 | EXPECT_ACCEPTED(false); |
| 748 | thwart_rx_non_initial_requests(); |
| 749 | |
| 750 | btw("MS replies with an Identity Response"); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 751 | ms_sends_msg("0559084a32244332244302"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 752 | |
| 753 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 754 | EXPECT_CONN_COUNT(1); |
| 755 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 756 | EXPECT_ACCEPTED(false); |
| 757 | thwart_rx_non_initial_requests(); |
| 758 | |
| 759 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 760 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 761 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 762 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 763 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 764 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 765 | vlr_subscr_put(vsub); |
| 766 | |
| 767 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 768 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 769 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 770 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 771 | |
| 772 | btw("LU was successful, and the conn has already been closed"); |
| 773 | EXPECT_CONN_COUNT(0); |
| 774 | |
| 775 | btw("Subscriber has the IMEI and TMSI"); |
| 776 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 777 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 778 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 779 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 780 | vlr_subscr_put(vsub); |
| 781 | |
| 782 | BTW("subscriber detaches, using TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 783 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 784 | ms_sends_msg("050130" "05f4" "03020100"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 785 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 786 | |
| 787 | EXPECT_CONN_COUNT(0); |
| 788 | clear_vlr(); |
| 789 | comment_end(); |
| 790 | } |
| 791 | |
| 792 | void test_lu_unknown_tmsi() |
| 793 | { |
| 794 | comment_start(); |
| 795 | |
| 796 | btw("Location Update request with unknown TMSI sends ID Request for IMSI"); |
| 797 | lu_result_sent = RES_NONE; |
| 798 | dtap_expect_tx("051801"); |
| 799 | ms_sends_msg("050802008168000130" "05f4" "23422342"); |
| 800 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 801 | |
| 802 | EXPECT_ACCEPTED(false); |
| 803 | thwart_rx_non_initial_requests(); |
| 804 | |
| 805 | btw("MS tells us the IMSI, causes a GSUP LU request to HLR"); |
| 806 | gsup_expect_tx("04010809710000004026f0"); |
| 807 | ms_sends_msg("0559089910070000006402"); |
| 808 | OSMO_ASSERT(gsup_tx_confirmed); |
| 809 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 810 | |
| 811 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 812 | gsup_rx("10010809710000004026f00804036470f1", |
| 813 | "12010809710000004026f0"); |
| 814 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 815 | |
| 816 | btw("having received subscriber data does not mean acceptance"); |
| 817 | EXPECT_ACCEPTED(false); |
| 818 | thwart_rx_non_initial_requests(); |
| 819 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 820 | |
| 821 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 822 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 823 | gsup_rx("06010809710000004026f0", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 824 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 825 | |
| 826 | btw("LU was successful, and the conn has already been closed"); |
| 827 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 828 | EXPECT_CONN_COUNT(0); |
| 829 | clear_vlr(); |
| 830 | comment_end(); |
| 831 | } |
| 832 | |
| 833 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 834 | test_ciph, |
| 835 | test_ciph_tmsi, |
| 836 | test_ciph_imei, |
| 837 | test_ciph_imeisv, |
| 838 | test_ciph_tmsi_imei, |
| 839 | NULL |
| 840 | }; |