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