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 | |
| 26 | void test_no_authen() |
| 27 | { |
| 28 | struct vlr_subscr *vsub; |
| 29 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 30 | |
| 31 | /* No auth only works on GERAN */ |
| 32 | rx_from_ran = RAN_GERAN_A; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 33 | |
| 34 | comment_start(); |
| 35 | |
| 36 | btw("Location Update request causes a GSUP LU request to HLR"); |
| 37 | lu_result_sent = RES_NONE; |
| 38 | gsup_expect_tx("04010809710000004026f0"); |
| 39 | ms_sends_msg("050802008168000130089910070000006402"); |
| 40 | OSMO_ASSERT(gsup_tx_confirmed); |
| 41 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 42 | |
| 43 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 44 | gsup_rx("10010809710000004026f00804036470f1", |
| 45 | "12010809710000004026f0"); |
| 46 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 47 | |
| 48 | btw("having received subscriber data does not mean acceptance"); |
| 49 | EXPECT_ACCEPTED(false); |
| 50 | |
| 51 | thwart_rx_non_initial_requests(); |
| 52 | |
| 53 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 54 | |
| 55 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 56 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 57 | gsup_rx("06010809710000004026f0", NULL); |
| 58 | |
| 59 | btw("LU was successful, and the conn has already been closed"); |
| 60 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 61 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 62 | EXPECT_CONN_COUNT(0); |
| 63 | |
| 64 | BTW("after a while, a new conn sends a CM Service Request"); |
| 65 | cm_service_result_sent = RES_NONE; |
| 66 | ms_sends_msg("05247803305886089910070000006402"); |
| 67 | OSMO_ASSERT(g_conn); |
| 68 | OSMO_ASSERT(g_conn->conn_fsm); |
| 69 | OSMO_ASSERT(g_conn->vsub); |
| 70 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 71 | EXPECT_ACCEPTED(true); |
| 72 | |
| 73 | btw("a USSD request is serviced"); |
| 74 | dtap_expect_tx_ussd("Your extension is 46071\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 75 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 76 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 77 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 78 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 79 | |
| 80 | btw("all requests serviced, conn has been released"); |
| 81 | EXPECT_CONN_COUNT(0); |
| 82 | |
| 83 | BTW("an SMS is sent, MS is paged"); |
| 84 | paging_expect_imsi(imsi); |
| 85 | paging_sent = false; |
| 86 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 87 | OSMO_ASSERT(vsub); |
| 88 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 89 | |
| 90 | send_sms(vsub, vsub, |
| 91 | "Privacy in residential applications is a desirable" |
| 92 | " marketing option."); |
| 93 | |
| 94 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 95 | vlr_subscr_put(vsub); |
| 96 | vsub = NULL; |
| 97 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 98 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 99 | |
| 100 | btw("the subscriber and its pending request should remain"); |
| 101 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 102 | OSMO_ASSERT(vsub); |
| 103 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 104 | vlr_subscr_put(vsub); |
| 105 | |
| 106 | btw("MS replies with Paging Response, we deliver the SMS"); |
| 107 | dtap_expect_tx("09" /* SMS messages */ |
| 108 | "01" /* CP-DATA */ |
| 109 | "58" /* length */ |
| 110 | "01" /* Network to MS */ |
| 111 | "00" /* reference */ |
| 112 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 113 | "0791" "447758100650" /* 447785016005 */ |
| 114 | "00" /* dest */ |
| 115 | /* SMS TPDU */ |
| 116 | "4c" /* len */ |
| 117 | "00" /* SMS deliver */ |
| 118 | "05806470f1" /* originating address 46071 */ |
| 119 | "00" /* TP-PID */ |
| 120 | "00" /* GSM default alphabet */ |
| 121 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 122 | "000000" /* H-M-S */ |
| 123 | "00" /* GMT+0 */ |
| 124 | "44" /* data length */ |
| 125 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 126 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 127 | "0c7ac3e9e9b7db05"); |
| 128 | ms_sends_msg("06270703305882089910070000006402"); |
| 129 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 130 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 131 | |
| 132 | btw("SMS was delivered, no requests pending for subscr"); |
| 133 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 134 | OSMO_ASSERT(vsub); |
| 135 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 136 | vlr_subscr_put(vsub); |
| 137 | |
| 138 | btw("conn is still open to wait for SMS ack dance"); |
| 139 | EXPECT_CONN_COUNT(1); |
| 140 | |
| 141 | btw("MS replies with CP-ACK for received SMS"); |
| 142 | ms_sends_msg("8904"); |
| 143 | EXPECT_CONN_COUNT(1); |
| 144 | |
| 145 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 146 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 147 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 148 | ms_sends_msg("890106020041020000"); |
| 149 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 150 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 151 | |
| 152 | btw("SMS is done, conn is gone"); |
| 153 | EXPECT_CONN_COUNT(0); |
| 154 | |
| 155 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 156 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 157 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 158 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 159 | |
| 160 | EXPECT_CONN_COUNT(0); |
| 161 | clear_vlr(); |
| 162 | comment_end(); |
| 163 | } |
| 164 | |
| 165 | void test_no_authen_tmsi() |
| 166 | { |
| 167 | struct vlr_subscr *vsub; |
| 168 | const char *imsi = "901700000004620"; |
| 169 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 170 | rx_from_ran = RAN_GERAN_A; |
| 171 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 172 | comment_start(); |
| 173 | |
| 174 | net->vlr->cfg.assign_tmsi = true; |
| 175 | |
| 176 | btw("Location Update request causes a GSUP LU request to HLR"); |
| 177 | lu_result_sent = RES_NONE; |
| 178 | gsup_expect_tx("04010809710000004026f0"); |
| 179 | ms_sends_msg("050802008168000130089910070000006402"); |
| 180 | OSMO_ASSERT(gsup_tx_confirmed); |
| 181 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 182 | |
| 183 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 184 | gsup_rx("10010809710000004026f00804036470f1", |
| 185 | "12010809710000004026f0"); |
| 186 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 187 | |
| 188 | btw("having received subscriber data does not mean acceptance"); |
| 189 | EXPECT_ACCEPTED(false); |
| 190 | thwart_rx_non_initial_requests(); |
| 191 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 192 | |
| 193 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 194 | gsup_rx("06010809710000004026f0", NULL); |
| 195 | |
| 196 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 197 | EXPECT_CONN_COUNT(1); |
| 198 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 199 | EXPECT_ACCEPTED(false); |
| 200 | thwart_rx_non_initial_requests(); |
| 201 | |
| 202 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 203 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 204 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 205 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 206 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 207 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 208 | vlr_subscr_put(vsub); |
| 209 | |
| 210 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 211 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 212 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 213 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 214 | |
| 215 | btw("LU was successful, and the conn has already been closed"); |
| 216 | EXPECT_CONN_COUNT(0); |
| 217 | |
| 218 | btw("Subscriber has the new TMSI"); |
| 219 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 220 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 221 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 222 | VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x"); |
| 223 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 224 | vlr_subscr_put(vsub); |
| 225 | |
| 226 | BTW("after a while, a new conn sends a CM Service Request using above TMSI"); |
| 227 | cm_service_result_sent = RES_NONE; |
| 228 | ms_sends_msg("05247803305886" "05f4" "03020100"); |
| 229 | OSMO_ASSERT(g_conn); |
| 230 | OSMO_ASSERT(g_conn->conn_fsm); |
| 231 | OSMO_ASSERT(g_conn->vsub); |
| 232 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 233 | EXPECT_ACCEPTED(true); |
| 234 | |
| 235 | btw("a USSD request is serviced"); |
| 236 | dtap_expect_tx_ussd("Your extension is 46071\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 237 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 238 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 239 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 240 | |
| 241 | btw("all requests serviced, conn has been released"); |
| 242 | EXPECT_CONN_COUNT(0); |
| 243 | |
| 244 | BTW("an SMS is sent, MS is paged using above TMSI"); |
| 245 | paging_expect_tmsi(0x03020100); |
| 246 | paging_sent = false; |
| 247 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 248 | OSMO_ASSERT(vsub); |
| 249 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 250 | |
| 251 | send_sms(vsub, vsub, |
| 252 | "Privacy in residential applications is a desirable" |
| 253 | " marketing option."); |
| 254 | |
| 255 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 256 | vlr_subscr_put(vsub); |
| 257 | vsub = NULL; |
| 258 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 259 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 260 | |
| 261 | btw("the subscriber and its pending request should remain"); |
| 262 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 263 | OSMO_ASSERT(vsub); |
| 264 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 265 | vlr_subscr_put(vsub); |
| 266 | |
| 267 | btw("MS replies with Paging Response using TMSI, we deliver the SMS"); |
| 268 | dtap_expect_tx("09" /* SMS messages */ |
| 269 | "01" /* CP-DATA */ |
| 270 | "58" /* length */ |
| 271 | "01" /* Network to MS */ |
| 272 | "00" /* reference */ |
| 273 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 274 | "0791" "447758100650" /* 447785016005 */ |
| 275 | "00" /* dest */ |
| 276 | /* SMS TPDU */ |
| 277 | "4c" /* len */ |
| 278 | "00" /* SMS deliver */ |
| 279 | "05806470f1" /* originating address 46071 */ |
| 280 | "00" /* TP-PID */ |
| 281 | "00" /* GSM default alphabet */ |
| 282 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 283 | "000000" /* H-M-S */ |
| 284 | "00" /* GMT+0 */ |
| 285 | "44" /* data length */ |
| 286 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 287 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 288 | "0c7ac3e9e9b7db05"); |
| 289 | ms_sends_msg("06270703305882" "05f4" "03020100"); |
| 290 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 291 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 292 | |
| 293 | btw("SMS was delivered, no requests pending for subscr"); |
| 294 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 295 | OSMO_ASSERT(vsub); |
| 296 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 297 | vlr_subscr_put(vsub); |
| 298 | |
| 299 | btw("conn is still open to wait for SMS ack dance"); |
| 300 | EXPECT_CONN_COUNT(1); |
| 301 | |
| 302 | btw("MS replies with CP-ACK for received SMS"); |
| 303 | ms_sends_msg("8904"); |
| 304 | EXPECT_CONN_COUNT(1); |
| 305 | |
| 306 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 307 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 308 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 309 | ms_sends_msg("890106020041020000"); |
| 310 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 311 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 312 | |
| 313 | btw("SMS is done, conn is gone"); |
| 314 | EXPECT_CONN_COUNT(0); |
| 315 | |
| 316 | /* TODO: when the subscriber detaches, the vlr_subscr gets |
| 317 | * deallocated and we no longer know the TMSI. This case is covered by |
| 318 | * test_lu_unknown_tmsi(), so here I'd like to still have the TMSI. |
| 319 | BTW("subscriber detaches, using TMSI"); |
| 320 | ms_sends_msg("050130" "05f4" "03020100"); |
| 321 | EXPECT_CONN_COUNT(0); |
| 322 | */ |
| 323 | |
| 324 | BTW("subscriber sends LU Request, this time with the TMSI"); |
| 325 | btw("Location Update request causes a GSUP LU request to HLR"); |
| 326 | lu_result_sent = RES_NONE; |
| 327 | gsup_expect_tx("04010809710000004026f0"); |
| 328 | ms_sends_msg("050802008168000130" "05f4" "03020100"); |
| 329 | OSMO_ASSERT(gsup_tx_confirmed); |
| 330 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 331 | |
| 332 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 333 | gsup_rx("10010809710000004026f00804036470f1", |
| 334 | "12010809710000004026f0"); |
| 335 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 336 | |
| 337 | btw("having received subscriber data does not mean acceptance"); |
| 338 | EXPECT_ACCEPTED(false); |
| 339 | thwart_rx_non_initial_requests(); |
| 340 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 341 | |
| 342 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 343 | gsup_rx("06010809710000004026f0", NULL); |
| 344 | |
| 345 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 346 | EXPECT_CONN_COUNT(1); |
| 347 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 348 | EXPECT_ACCEPTED(false); |
| 349 | thwart_rx_non_initial_requests(); |
| 350 | |
| 351 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 352 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504); |
| 353 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 354 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 355 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x"); |
| 356 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 357 | vlr_subscr_put(vsub); |
| 358 | |
| 359 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 360 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 361 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 362 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 363 | |
| 364 | btw("LU was successful, and the conn has already been closed"); |
| 365 | EXPECT_CONN_COUNT(0); |
| 366 | |
| 367 | btw("subscriber has the new TMSI"); |
| 368 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504); |
| 369 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 370 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 371 | VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x"); |
| 372 | VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x"); |
| 373 | vlr_subscr_put(vsub); |
| 374 | |
| 375 | BTW("subscriber detaches, using new TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 376 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 377 | ms_sends_msg("050130" "05f4" "07060504"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 378 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 379 | |
| 380 | EXPECT_CONN_COUNT(0); |
| 381 | clear_vlr(); |
| 382 | comment_end(); |
| 383 | } |
| 384 | |
| 385 | void test_no_authen_imei() |
| 386 | { |
| 387 | struct vlr_subscr *vsub; |
| 388 | const char *imsi = "901700000004620"; |
| 389 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 390 | rx_from_ran = RAN_GERAN_A; |
| 391 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 392 | comment_start(); |
| 393 | |
| 394 | net->vlr->cfg.check_imei_rqd = true; |
| 395 | |
| 396 | btw("Location Update request causes a GSUP LU request to HLR"); |
| 397 | lu_result_sent = RES_NONE; |
| 398 | gsup_expect_tx("04010809710000004026f0"); |
| 399 | ms_sends_msg("050802008168000130089910070000006402"); |
| 400 | OSMO_ASSERT(gsup_tx_confirmed); |
| 401 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 402 | |
| 403 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 404 | gsup_rx("10010809710000004026f00804036470f1", |
| 405 | "12010809710000004026f0"); |
| 406 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 407 | |
| 408 | btw("having received subscriber data does not mean acceptance"); |
| 409 | EXPECT_ACCEPTED(false); |
| 410 | thwart_rx_non_initial_requests(); |
| 411 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 412 | |
| 413 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 414 | dtap_expect_tx("051802"); |
| 415 | gsup_rx("06010809710000004026f0", NULL); |
| 416 | |
| 417 | btw("We will only do business when the IMEI is known"); |
| 418 | EXPECT_CONN_COUNT(1); |
| 419 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 420 | OSMO_ASSERT(vsub); |
| 421 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 422 | vlr_subscr_put(vsub); |
| 423 | EXPECT_ACCEPTED(false); |
| 424 | thwart_rx_non_initial_requests(); |
| 425 | |
| 426 | btw("MS replies with an Identity Response"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 427 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 428 | ms_sends_msg("0559084a32244332244332"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 429 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 430 | |
| 431 | btw("LU was successful, and the conn has already been closed"); |
| 432 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 433 | EXPECT_CONN_COUNT(0); |
| 434 | |
| 435 | btw("Subscriber has the IMEI"); |
| 436 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 437 | OSMO_ASSERT(vsub); |
| 438 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423423"), == 0, "%d"); |
| 439 | vlr_subscr_put(vsub); |
| 440 | |
| 441 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 442 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 443 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 444 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 445 | |
| 446 | EXPECT_CONN_COUNT(0); |
| 447 | clear_vlr(); |
| 448 | comment_end(); |
| 449 | } |
| 450 | |
| 451 | void test_no_authen_tmsi_imei() |
| 452 | { |
| 453 | struct vlr_subscr *vsub; |
| 454 | const char *imsi = "901700000004620"; |
| 455 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 456 | rx_from_ran = RAN_GERAN_A; |
| 457 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 458 | comment_start(); |
| 459 | |
| 460 | net->vlr->cfg.assign_tmsi = true; |
| 461 | net->vlr->cfg.check_imei_rqd = true; |
| 462 | |
| 463 | btw("Location Update request causes a GSUP LU request to HLR"); |
| 464 | lu_result_sent = RES_NONE; |
| 465 | gsup_expect_tx("04010809710000004026f0"); |
| 466 | ms_sends_msg("050802008168000130089910070000006402"); |
| 467 | OSMO_ASSERT(gsup_tx_confirmed); |
| 468 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 469 | |
| 470 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 471 | gsup_rx("10010809710000004026f00804036470f1", |
| 472 | "12010809710000004026f0"); |
| 473 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 474 | |
| 475 | btw("having received subscriber data does not mean acceptance"); |
| 476 | EXPECT_ACCEPTED(false); |
| 477 | thwart_rx_non_initial_requests(); |
| 478 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 479 | |
| 480 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 481 | dtap_expect_tx("051802"); |
| 482 | gsup_rx("06010809710000004026f0", NULL); |
| 483 | |
| 484 | btw("We will only do business when the IMEI is known"); |
| 485 | EXPECT_CONN_COUNT(1); |
| 486 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 487 | OSMO_ASSERT(vsub); |
| 488 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 489 | vlr_subscr_put(vsub); |
| 490 | EXPECT_ACCEPTED(false); |
| 491 | thwart_rx_non_initial_requests(); |
| 492 | |
| 493 | btw("MS replies with an Identity Response"); |
| 494 | ms_sends_msg("0559084a32244332244332"); |
| 495 | |
| 496 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 497 | EXPECT_CONN_COUNT(1); |
| 498 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 499 | EXPECT_ACCEPTED(false); |
| 500 | thwart_rx_non_initial_requests(); |
| 501 | |
| 502 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 503 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 504 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 505 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 506 | |
| 507 | btw("LU was successful, and the conn has already been closed"); |
| 508 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 509 | EXPECT_CONN_COUNT(0); |
| 510 | |
| 511 | btw("Subscriber has the IMEI and TMSI"); |
| 512 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 513 | OSMO_ASSERT(vsub); |
| 514 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423423"), == 0, "%d"); |
| 515 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 516 | vlr_subscr_put(vsub); |
| 517 | |
| 518 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 519 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 520 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 521 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 522 | |
| 523 | EXPECT_CONN_COUNT(0); |
| 524 | clear_vlr(); |
| 525 | comment_end(); |
| 526 | } |
| 527 | |
| 528 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 529 | test_no_authen, |
| 530 | test_no_authen_tmsi, |
| 531 | test_no_authen_imei, |
| 532 | test_no_authen_tmsi_imei, |
| 533 | NULL |
| 534 | }; |