blob: b34ddd7d9255548982e078938b344297ec66fbc2 [file] [log] [blame]
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001/* 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
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010026static void test_no_authen()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
28 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010029 const char *imsi = "901700000004620";
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020030
31 /* No auth only works on GERAN */
32 rx_from_ran = RAN_GERAN_A;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010033
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010034 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010035
36 btw("Location Update request causes a GSUP LU request to HLR");
37 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +020038 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010039 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 Maierfbf66102017-04-09 12:32:51 +020056 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010057 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 Maierfbf66102017-04-09 12:32:51 +020061 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +020062
63 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010064 EXPECT_CONN_COUNT(0);
65
66 BTW("after a while, a new conn sends a CM Service Request");
67 cm_service_result_sent = RES_NONE;
68 ms_sends_msg("05247803305886089910070000006402");
69 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +020070 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010071 OSMO_ASSERT(g_conn->vsub);
72 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
73 EXPECT_ACCEPTED(true);
74
Vadim Yanitskiy27605852018-06-15 23:57:30 +070075 /* Release connection */
76 expect_bssap_clear(RAN_GERAN_A);
77 conn_conclude_cm_service_req(g_conn, RAN_GERAN_A);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010078
79 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +020080 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010081 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 Maierfbf66102017-04-09 12:32:51 +0200147 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100148 ms_sends_msg("890106020041020000");
149 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200150 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100151
152 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200153 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100154 EXPECT_CONN_COUNT(0);
155
156 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200157 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100158 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200159 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100160
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200161 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100162 EXPECT_CONN_COUNT(0);
163 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100164 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100165}
166
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100167static void test_no_authen_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100168{
169 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100170 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100171
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200172 rx_from_ran = RAN_GERAN_A;
173
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100174 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100175
176 net->vlr->cfg.assign_tmsi = true;
177
178 btw("Location Update request causes a GSUP LU request to HLR");
179 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200180 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100181 ms_sends_msg("050802008168000130089910070000006402");
182 OSMO_ASSERT(gsup_tx_confirmed);
183 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
184
185 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
186 gsup_rx("10010809710000004026f00804036470f1",
187 "12010809710000004026f0");
188 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
189
190 btw("having received subscriber data does not mean acceptance");
191 EXPECT_ACCEPTED(false);
192 thwart_rx_non_initial_requests();
193 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
194
195 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
196 gsup_rx("06010809710000004026f0", NULL);
197
198 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
199 EXPECT_CONN_COUNT(1);
200 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
201 EXPECT_ACCEPTED(false);
202 thwart_rx_non_initial_requests();
203
204 btw("even though the TMSI is not acked, we can already find the subscr with it");
205 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
206 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
207 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
208 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
209 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
210 vlr_subscr_put(vsub);
211
212 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200213 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100214 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200215 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100216
217 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200218 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100219 EXPECT_CONN_COUNT(0);
220
221 btw("Subscriber has the new TMSI");
222 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
223 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
224 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
225 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
226 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
227 vlr_subscr_put(vsub);
228
229 BTW("after a while, a new conn sends a CM Service Request using above TMSI");
230 cm_service_result_sent = RES_NONE;
231 ms_sends_msg("05247803305886" "05f4" "03020100");
232 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200233 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100234 OSMO_ASSERT(g_conn->vsub);
235 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
236 EXPECT_ACCEPTED(true);
237
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700238 /* Release connection */
239 expect_bssap_clear(RAN_GERAN_A);
240 conn_conclude_cm_service_req(g_conn, RAN_GERAN_A);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100241
242 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200243 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100244 EXPECT_CONN_COUNT(0);
245
246 BTW("an SMS is sent, MS is paged using above TMSI");
247 paging_expect_tmsi(0x03020100);
248 paging_sent = false;
249 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
250 OSMO_ASSERT(vsub);
251 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
252
253 send_sms(vsub, vsub,
254 "Privacy in residential applications is a desirable"
255 " marketing option.");
256
257 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
258 vlr_subscr_put(vsub);
259 vsub = NULL;
260 VERBOSE_ASSERT(paging_sent, == true, "%d");
261 VERBOSE_ASSERT(paging_stopped, == false, "%d");
262
263 btw("the subscriber and its pending request should remain");
264 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
265 OSMO_ASSERT(vsub);
266 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
267 vlr_subscr_put(vsub);
268
269 btw("MS replies with Paging Response using TMSI, we deliver the SMS");
270 dtap_expect_tx("09" /* SMS messages */
271 "01" /* CP-DATA */
272 "58" /* length */
273 "01" /* Network to MS */
274 "00" /* reference */
275 /* originator (gsm411_send_sms() hardcodes this weird nr) */
276 "0791" "447758100650" /* 447785016005 */
277 "00" /* dest */
278 /* SMS TPDU */
279 "4c" /* len */
280 "00" /* SMS deliver */
281 "05806470f1" /* originating address 46071 */
282 "00" /* TP-PID */
283 "00" /* GSM default alphabet */
284 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
285 "000000" /* H-M-S */
286 "00" /* GMT+0 */
287 "44" /* data length */
288 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
289 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
290 "0c7ac3e9e9b7db05");
291 ms_sends_msg("06270703305882" "05f4" "03020100");
292 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
293 VERBOSE_ASSERT(paging_stopped, == true, "%d");
294
295 btw("SMS was delivered, no requests pending for subscr");
296 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
297 OSMO_ASSERT(vsub);
298 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
299 vlr_subscr_put(vsub);
300
301 btw("conn is still open to wait for SMS ack dance");
302 EXPECT_CONN_COUNT(1);
303
304 btw("MS replies with CP-ACK for received SMS");
305 ms_sends_msg("8904");
306 EXPECT_CONN_COUNT(1);
307
308 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
309 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200310 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100311 ms_sends_msg("890106020041020000");
312 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200313 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100314
315 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200316 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100317 EXPECT_CONN_COUNT(0);
318
319 /* TODO: when the subscriber detaches, the vlr_subscr gets
320 * deallocated and we no longer know the TMSI. This case is covered by
321 * test_lu_unknown_tmsi(), so here I'd like to still have the TMSI.
322 BTW("subscriber detaches, using TMSI");
323 ms_sends_msg("050130" "05f4" "03020100");
324 EXPECT_CONN_COUNT(0);
325 */
326
327 BTW("subscriber sends LU Request, this time with the TMSI");
328 btw("Location Update request causes a GSUP LU request to HLR");
329 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200330 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100331 ms_sends_msg("050802008168000130" "05f4" "03020100");
332 OSMO_ASSERT(gsup_tx_confirmed);
333 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
334
335 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
336 gsup_rx("10010809710000004026f00804036470f1",
337 "12010809710000004026f0");
338 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
339
340 btw("having received subscriber data does not mean acceptance");
341 EXPECT_ACCEPTED(false);
342 thwart_rx_non_initial_requests();
343 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
344
345 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
346 gsup_rx("06010809710000004026f0", NULL);
347
348 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
349 EXPECT_CONN_COUNT(1);
350 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
351 EXPECT_ACCEPTED(false);
352 thwart_rx_non_initial_requests();
353
354 btw("even though the TMSI is not acked, we can already find the subscr with it");
355 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
356 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
357 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
358 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
359 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
360 vlr_subscr_put(vsub);
361
362 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200363 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100364 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200365 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100366
367 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200368 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100369 EXPECT_CONN_COUNT(0);
370
371 btw("subscriber has the new TMSI");
372 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
373 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
374 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
375 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
376 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
377 vlr_subscr_put(vsub);
378
379 BTW("subscriber detaches, using new TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200380 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100381 ms_sends_msg("050130" "05f4" "07060504");
Philipp Maierfbf66102017-04-09 12:32:51 +0200382 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100383
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200384 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100385 EXPECT_CONN_COUNT(0);
386 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100387 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100388}
389
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100390static void test_no_authen_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100391{
392 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100393 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100394
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200395 rx_from_ran = RAN_GERAN_A;
396
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100397 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100398
399 net->vlr->cfg.check_imei_rqd = true;
400
401 btw("Location Update request causes a GSUP LU request to HLR");
402 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200403 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100404 ms_sends_msg("050802008168000130089910070000006402");
405 OSMO_ASSERT(gsup_tx_confirmed);
406 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
407
408 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
409 gsup_rx("10010809710000004026f00804036470f1",
410 "12010809710000004026f0");
411 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
412
413 btw("having received subscriber data does not mean acceptance");
414 EXPECT_ACCEPTED(false);
415 thwart_rx_non_initial_requests();
416 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
417
418 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
419 dtap_expect_tx("051802");
420 gsup_rx("06010809710000004026f0", NULL);
421
422 btw("We will only do business when the IMEI is known");
423 EXPECT_CONN_COUNT(1);
424 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
425 OSMO_ASSERT(vsub);
426 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
427 vlr_subscr_put(vsub);
428 EXPECT_ACCEPTED(false);
429 thwart_rx_non_initial_requests();
430
431 btw("MS replies with an Identity Response");
Philipp Maierfbf66102017-04-09 12:32:51 +0200432 expect_bssap_clear();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200433 /* 3GPP TS 23.003: 6.2.1 Composition of IMEI: the IMEI ends with a
434 * spare digit that shall be sent as zero by the MS. */
435 ms_sends_msg("0559084a32244332244302");
Philipp Maierfbf66102017-04-09 12:32:51 +0200436 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100437
438 btw("LU was successful, and the conn has already been closed");
439 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200440 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100441 EXPECT_CONN_COUNT(0);
442
443 btw("Subscriber has the IMEI");
444 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
445 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200446 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100447 vlr_subscr_put(vsub);
448
449 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200450 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100451 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200452 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100453
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200454 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100455 EXPECT_CONN_COUNT(0);
456 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100457 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100458}
459
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100460static void test_no_authen_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100461{
462 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100463 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100464
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200465 rx_from_ran = RAN_GERAN_A;
466
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100467 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100468
469 net->vlr->cfg.assign_tmsi = true;
470 net->vlr->cfg.check_imei_rqd = true;
471
472 btw("Location Update request causes a GSUP LU request to HLR");
473 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200474 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100475 ms_sends_msg("050802008168000130089910070000006402");
476 OSMO_ASSERT(gsup_tx_confirmed);
477 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
478
479 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
480 gsup_rx("10010809710000004026f00804036470f1",
481 "12010809710000004026f0");
482 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
483
484 btw("having received subscriber data does not mean acceptance");
485 EXPECT_ACCEPTED(false);
486 thwart_rx_non_initial_requests();
487 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
488
489 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
490 dtap_expect_tx("051802");
491 gsup_rx("06010809710000004026f0", NULL);
492
493 btw("We will only do business when the IMEI is known");
494 EXPECT_CONN_COUNT(1);
495 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
496 OSMO_ASSERT(vsub);
497 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
498 vlr_subscr_put(vsub);
499 EXPECT_ACCEPTED(false);
500 thwart_rx_non_initial_requests();
501
502 btw("MS replies with an Identity Response");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200503 ms_sends_msg("0559084a32244332244302");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100504
505 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
506 EXPECT_CONN_COUNT(1);
507 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
508 EXPECT_ACCEPTED(false);
509 thwart_rx_non_initial_requests();
510
511 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200512 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100513 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200514 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100515
516 btw("LU was successful, and the conn has already been closed");
517 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200518 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100519 EXPECT_CONN_COUNT(0);
520
521 btw("Subscriber has the IMEI and TMSI");
522 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
523 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200524 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100525 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
526 vlr_subscr_put(vsub);
527
528 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200529 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100530 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200531 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100532
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200533 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100534 EXPECT_CONN_COUNT(0);
535 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100536 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100537}
538
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100539static void test_no_authen_imeisv()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200540{
541 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100542 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200543
544 /* No auth only works on GERAN */
545 rx_from_ran = RAN_GERAN_A;
546
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100547 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200548
549 net->vlr->cfg.retrieve_imeisv_early = true;
550
551 btw("Location Update request causes an IMEISV ID request back to the MS");
552 lu_result_sent = RES_NONE;
553 dtap_expect_tx("051803");
554 ms_sends_msg("050802008168000130089910070000006402");
555 OSMO_ASSERT(dtap_tx_confirmed);
556
557 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200558 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200559 ms_sends_msg("0559094332244332244372f5");
560 OSMO_ASSERT(gsup_tx_confirmed);
561 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
562
563 btw("Subscriber has the IMEISV from the ID Response");
564 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
565 OSMO_ASSERT(vsub);
566 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
567 vlr_subscr_put(vsub);
568
569 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
570 gsup_rx("10010809710000004026f00804036470f1",
571 "12010809710000004026f0");
572 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
573
574 btw("having received subscriber data does not mean acceptance");
575 EXPECT_ACCEPTED(false);
576
577 thwart_rx_non_initial_requests();
578
579 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
580
581 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
582 expect_bssap_clear();
583 gsup_rx("06010809710000004026f0", NULL);
584
585 btw("LU was successful, and the conn has already been closed");
586 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
587 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200588 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200589 EXPECT_CONN_COUNT(0);
590
591 BTW("subscriber detaches");
592 expect_bssap_clear();
593 ms_sends_msg("050130089910070000006402");
594 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
595
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200596 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200597 EXPECT_CONN_COUNT(0);
598 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100599 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200600}
601
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100602static void test_no_authen_imeisv_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200603{
604 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100605 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200606
607 rx_from_ran = RAN_GERAN_A;
608
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100609 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200610
611 net->vlr->cfg.retrieve_imeisv_early = true;
612 net->vlr->cfg.check_imei_rqd = true;
613
614 btw("Location Update request causes an IMEISV ID request back to the MS");
615 lu_result_sent = RES_NONE;
616 dtap_expect_tx("051803");
617 ms_sends_msg("050802008168000130089910070000006402");
618 OSMO_ASSERT(dtap_tx_confirmed);
619
620 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200621 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200622 ms_sends_msg("0559094332244332244372f5");
623 OSMO_ASSERT(gsup_tx_confirmed);
624 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
625
626 btw("Subscriber has the IMEISV from the ID Response");
627 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
628 OSMO_ASSERT(vsub);
629 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
630 vlr_subscr_put(vsub);
631
632 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
633 gsup_rx("10010809710000004026f00804036470f1",
634 "12010809710000004026f0");
635 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
636
637 btw("having received subscriber data does not mean acceptance");
638 EXPECT_ACCEPTED(false);
639 thwart_rx_non_initial_requests();
640 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
641
642 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
643 dtap_expect_tx("051802");
644 gsup_rx("06010809710000004026f0", NULL);
645
646 btw("We will only do business when the IMEI is known");
647 EXPECT_CONN_COUNT(1);
648 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
649 OSMO_ASSERT(vsub);
650 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
651 vlr_subscr_put(vsub);
652 EXPECT_ACCEPTED(false);
653 thwart_rx_non_initial_requests();
654
655 btw("MS replies with an Identity Response");
656 expect_bssap_clear();
657 ms_sends_msg("0559084a32244332244302");
658 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
659
660 btw("LU was successful, and the conn has already been closed");
661 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200662 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200663 EXPECT_CONN_COUNT(0);
664
665 btw("Subscriber has the IMEI");
666 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
667 OSMO_ASSERT(vsub);
668 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
669 vlr_subscr_put(vsub);
670
671 BTW("subscriber detaches");
672 expect_bssap_clear();
673 ms_sends_msg("050130089910070000006402");
674 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
675
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200676 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200677 EXPECT_CONN_COUNT(0);
678 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100679 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200680}
681
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100682static void test_no_authen_imeisv_tmsi()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200683{
684 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100685 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200686
687 rx_from_ran = RAN_GERAN_A;
688
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100689 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200690
691 net->vlr->cfg.retrieve_imeisv_early = true;
692 net->vlr->cfg.assign_tmsi = true;
693
694 btw("Location Update request causes an IMEISV ID request back to the MS");
695 lu_result_sent = RES_NONE;
696 dtap_expect_tx("051803");
697 ms_sends_msg("050802008168000130089910070000006402");
698 OSMO_ASSERT(dtap_tx_confirmed);
699
700 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200701 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200702 ms_sends_msg("0559094332244332244372f5");
703 OSMO_ASSERT(gsup_tx_confirmed);
704 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
705
706 btw("Subscriber has the IMEISV from the ID Response");
707 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
708 OSMO_ASSERT(vsub);
709 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
710 vlr_subscr_put(vsub);
711
712 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
713 gsup_rx("10010809710000004026f00804036470f1",
714 "12010809710000004026f0");
715 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
716
717 btw("having received subscriber data does not mean acceptance");
718 EXPECT_ACCEPTED(false);
719 thwart_rx_non_initial_requests();
720 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
721
722 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
723 gsup_rx("06010809710000004026f0", NULL);
724
725 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
726 EXPECT_CONN_COUNT(1);
727 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
728 EXPECT_ACCEPTED(false);
729 thwart_rx_non_initial_requests();
730
731 btw("even though the TMSI is not acked, we can already find the subscr with it");
732 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
733 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
734 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
735 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
736 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
737 vlr_subscr_put(vsub);
738
739 btw("MS sends TMSI Realloc Complete");
740 expect_bssap_clear();
741 ms_sends_msg("055b");
742 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
743
744 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200745 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200746 EXPECT_CONN_COUNT(0);
747
748
749 BTW("subscriber sends LU Request, this time with the TMSI");
750 btw("Location Update request causes an IMEISV ID request back to the MS");
751 lu_result_sent = RES_NONE;
752 dtap_expect_tx("051803");
753 ms_sends_msg("050802008168000130089910070000006402");
754 OSMO_ASSERT(dtap_tx_confirmed);
755
756 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200757 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200758 ms_sends_msg("0559095332244332244372f6");
759 OSMO_ASSERT(gsup_tx_confirmed);
760 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
761
762 btw("Subscriber has the IMEISV from the ID Response");
763 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
764 OSMO_ASSERT(vsub);
765 VERBOSE_ASSERT(strcmp(vsub->imeisv, "5234234234234276"), == 0, "%d");
766 vlr_subscr_put(vsub);
767
768 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
769 gsup_rx("10010809710000004026f00804036470f1",
770 "12010809710000004026f0");
771 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
772
773 btw("having received subscriber data does not mean acceptance");
774 EXPECT_ACCEPTED(false);
775 thwart_rx_non_initial_requests();
776 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
777
778 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
779 gsup_rx("06010809710000004026f0", NULL);
780
781 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
782 EXPECT_CONN_COUNT(1);
783 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
784 EXPECT_ACCEPTED(false);
785 thwart_rx_non_initial_requests();
786
787 btw("even though the TMSI is not acked, we can already find the subscr with it");
788 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
789 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
790 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
791 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
792 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
793 vlr_subscr_put(vsub);
794
795 btw("MS sends TMSI Realloc Complete");
796 expect_bssap_clear();
797 ms_sends_msg("055b");
798 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
799
800 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200801 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200802 EXPECT_CONN_COUNT(0);
803
804 btw("subscriber has the new TMSI");
805 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
806 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
807 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
808 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
809 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
810 vlr_subscr_put(vsub);
811
812 BTW("subscriber detaches, using new TMSI");
813 expect_bssap_clear();
814 ms_sends_msg("050130" "05f4" "07060504");
815 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
816
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200817 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200818 EXPECT_CONN_COUNT(0);
819 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100820 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200821}
822
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100823static void test_no_authen_imeisv_tmsi_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200824{
825 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100826 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200827
828 rx_from_ran = RAN_GERAN_A;
829
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100830 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200831
832 net->vlr->cfg.retrieve_imeisv_early = true;
833 net->vlr->cfg.assign_tmsi = true;
834 net->vlr->cfg.check_imei_rqd = true;
835
836 btw("Location Update request causes an IMEISV ID request back to the MS");
837 lu_result_sent = RES_NONE;
838 dtap_expect_tx("051803");
839 ms_sends_msg("050802008168000130089910070000006402");
840 OSMO_ASSERT(dtap_tx_confirmed);
841
842 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200843 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200844 ms_sends_msg("0559094332244332244372f5");
845 OSMO_ASSERT(gsup_tx_confirmed);
846 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
847
848 btw("Subscriber has the IMEISV from the ID Response");
849 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
850 OSMO_ASSERT(vsub);
851 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
852 vlr_subscr_put(vsub);
853
854 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
855 gsup_rx("10010809710000004026f00804036470f1",
856 "12010809710000004026f0");
857 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
858
859 btw("having received subscriber data does not mean acceptance");
860 EXPECT_ACCEPTED(false);
861 thwart_rx_non_initial_requests();
862 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
863
864 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
865 dtap_expect_tx("051802");
866 gsup_rx("06010809710000004026f0", NULL);
867
868 btw("We will only do business when the IMEI is known");
869 EXPECT_CONN_COUNT(1);
870 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
871 OSMO_ASSERT(vsub);
872 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
873 vlr_subscr_put(vsub);
874 EXPECT_ACCEPTED(false);
875 thwart_rx_non_initial_requests();
876
877 btw("MS replies with an Identity Response");
878 ms_sends_msg("0559084a32244332244302");
879
880 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
881 EXPECT_CONN_COUNT(1);
882 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
883 EXPECT_ACCEPTED(false);
884 thwart_rx_non_initial_requests();
885
886 btw("MS sends TMSI Realloc Complete");
887 expect_bssap_clear();
888 ms_sends_msg("055b");
889 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
890
891 btw("LU was successful, and the conn has already been closed");
892 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200893 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200894 EXPECT_CONN_COUNT(0);
895
896 btw("Subscriber has the IMEISV, IMEI and TMSI");
897 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
898 OSMO_ASSERT(vsub);
899 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
900 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
901 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
902 vlr_subscr_put(vsub);
903
904 BTW("subscriber detaches");
905 expect_bssap_clear();
906 ms_sends_msg("050130089910070000006402");
907 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
908
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200909 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200910 EXPECT_CONN_COUNT(0);
911 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100912 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200913}
914
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200915static void test_no_authen_subscr_expire()
916{
917 struct vlr_subscr *vsub;
918 const char *imsi = "901700000004620";
919
920 /* No auth only works on GERAN */
921 rx_from_ran = RAN_GERAN_A;
922
923 comment_start();
924
925 fake_time_start();
926
927 /* The test framework has already started the VLR before fake time was active.
928 * Manually schedule this timeout in fake time. */
929 osmo_timer_del(&net->vlr->lu_expire_timer);
930 osmo_timer_schedule(&net->vlr->lu_expire_timer, VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL, 0);
931
932 /* Let the LU expiration timer tick once */
933 fake_time_passes(VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL + 1, 0);
934
935 btw("Location Update request causes a GSUP LU request to HLR");
936 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200937 gsup_expect_tx("04010809710000004026f0280102");
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200938 ms_sends_msg("050802008168000130089910070000006402");
939 OSMO_ASSERT(gsup_tx_confirmed);
940 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
941
942 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
943 gsup_rx("10010809710000004026f00804036470f1",
944 "12010809710000004026f0");
945 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
946
947 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
948 expect_bssap_clear();
949 gsup_rx("06010809710000004026f0", NULL);
950
951 btw("LU was successful, and the conn has already been closed");
952 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
953 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
954
955 bss_sends_clear_complete();
956 EXPECT_CONN_COUNT(0);
957
958 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
959 OSMO_ASSERT(vsub);
960 vlr_subscr_put(vsub);
961
962 /* Let T3212 (periodic Location update timer) expire */
963 fake_time_passes((net->t3212 * 60 * 6 * 2) + 60*4, 0);
964
965 /* The subscriber should now be gone. */
966 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
967 OSMO_ASSERT(vsub == NULL);
968
969 EXPECT_CONN_COUNT(0);
970 clear_vlr();
971 comment_end();
972}
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200973
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100974msc_vlr_test_func_t msc_vlr_tests[] = {
975 test_no_authen,
976 test_no_authen_tmsi,
977 test_no_authen_imei,
978 test_no_authen_tmsi_imei,
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200979 test_no_authen_imeisv,
980 test_no_authen_imeisv_imei,
981 test_no_authen_imeisv_tmsi,
982 test_no_authen_imeisv_tmsi_imei,
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200983 test_no_authen_subscr_expire,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100984 NULL
985};