blob: 32e0b40e2ca86c0f0ced1a7cc1c35b80b77077c4 [file] [log] [blame]
Neels Hofmeyr3dc2c642017-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 Hofmeyrd489ea32016-05-20 21:59:55 +020030
31 /* No auth only works on GERAN */
32 rx_from_ran = RAN_GERAN_A;
Neels Hofmeyr3dc2c642017-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");
Philipp Maier68760a82017-04-09 12:32:51 +020056 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-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 Maier68760a82017-04-09 12:32:51 +020061 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +010062 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 Maier68760a82017-04-09 12:32:51 +020075 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +010076 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
Neels Hofmeyrd489ea32016-05-20 21:59:55 +020077 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maier68760a82017-04-09 12:32:51 +020078 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +010079
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 Maier68760a82017-04-09 12:32:51 +0200147 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100148 ms_sends_msg("890106020041020000");
149 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maier68760a82017-04-09 12:32:51 +0200150 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100151
152 btw("SMS is done, conn is gone");
153 EXPECT_CONN_COUNT(0);
154
155 BTW("subscriber detaches");
Philipp Maier68760a82017-04-09 12:32:51 +0200156 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100157 ms_sends_msg("050130089910070000006402");
Philipp Maier68760a82017-04-09 12:32:51 +0200158 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100159
160 EXPECT_CONN_COUNT(0);
161 clear_vlr();
162 comment_end();
163}
164
165void test_no_authen_tmsi()
166{
167 struct vlr_subscr *vsub;
168 const char *imsi = "901700000004620";
169
Neels Hofmeyrd489ea32016-05-20 21:59:55 +0200170 rx_from_ran = RAN_GERAN_A;
171
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100172 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 Maier68760a82017-04-09 12:32:51 +0200211 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100212 ms_sends_msg("055b");
Philipp Maier68760a82017-04-09 12:32:51 +0200213 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100214
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 Maier68760a82017-04-09 12:32:51 +0200237 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100238 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
Philipp Maier68760a82017-04-09 12:32:51 +0200239 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100240
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 Maier68760a82017-04-09 12:32:51 +0200308 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100309 ms_sends_msg("890106020041020000");
310 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maier68760a82017-04-09 12:32:51 +0200311 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100312
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 Maier68760a82017-04-09 12:32:51 +0200360 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100361 ms_sends_msg("055b");
Philipp Maier68760a82017-04-09 12:32:51 +0200362 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100363
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 Maier68760a82017-04-09 12:32:51 +0200376 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100377 ms_sends_msg("050130" "05f4" "07060504");
Philipp Maier68760a82017-04-09 12:32:51 +0200378 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100379
380 EXPECT_CONN_COUNT(0);
381 clear_vlr();
382 comment_end();
383}
384
385void test_no_authen_imei()
386{
387 struct vlr_subscr *vsub;
388 const char *imsi = "901700000004620";
389
Neels Hofmeyrd489ea32016-05-20 21:59:55 +0200390 rx_from_ran = RAN_GERAN_A;
391
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100392 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 Maier68760a82017-04-09 12:32:51 +0200427 expect_bssap_clear();
Neels Hofmeyr5ae96122017-07-20 02:56:21 +0200428 /* 3GPP TS 23.003: 6.2.1 Composition of IMEI: the IMEI ends with a
429 * spare digit that shall be sent as zero by the MS. */
430 ms_sends_msg("0559084a32244332244302");
Philipp Maier68760a82017-04-09 12:32:51 +0200431 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100432
433 btw("LU was successful, and the conn has already been closed");
434 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
435 EXPECT_CONN_COUNT(0);
436
437 btw("Subscriber has the IMEI");
438 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
439 OSMO_ASSERT(vsub);
Neels Hofmeyr5ae96122017-07-20 02:56:21 +0200440 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100441 vlr_subscr_put(vsub);
442
443 BTW("subscriber detaches");
Philipp Maier68760a82017-04-09 12:32:51 +0200444 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100445 ms_sends_msg("050130089910070000006402");
Philipp Maier68760a82017-04-09 12:32:51 +0200446 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100447
448 EXPECT_CONN_COUNT(0);
449 clear_vlr();
450 comment_end();
451}
452
453void test_no_authen_tmsi_imei()
454{
455 struct vlr_subscr *vsub;
456 const char *imsi = "901700000004620";
457
Neels Hofmeyrd489ea32016-05-20 21:59:55 +0200458 rx_from_ran = RAN_GERAN_A;
459
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100460 comment_start();
461
462 net->vlr->cfg.assign_tmsi = true;
463 net->vlr->cfg.check_imei_rqd = true;
464
465 btw("Location Update request causes a GSUP LU request to HLR");
466 lu_result_sent = RES_NONE;
467 gsup_expect_tx("04010809710000004026f0");
468 ms_sends_msg("050802008168000130089910070000006402");
469 OSMO_ASSERT(gsup_tx_confirmed);
470 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
471
472 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
473 gsup_rx("10010809710000004026f00804036470f1",
474 "12010809710000004026f0");
475 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
476
477 btw("having received subscriber data does not mean acceptance");
478 EXPECT_ACCEPTED(false);
479 thwart_rx_non_initial_requests();
480 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
481
482 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
483 dtap_expect_tx("051802");
484 gsup_rx("06010809710000004026f0", NULL);
485
486 btw("We will only do business when the IMEI is known");
487 EXPECT_CONN_COUNT(1);
488 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
489 OSMO_ASSERT(vsub);
490 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
491 vlr_subscr_put(vsub);
492 EXPECT_ACCEPTED(false);
493 thwart_rx_non_initial_requests();
494
495 btw("MS replies with an Identity Response");
Neels Hofmeyr5ae96122017-07-20 02:56:21 +0200496 ms_sends_msg("0559084a32244332244302");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100497
498 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
499 EXPECT_CONN_COUNT(1);
500 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
501 EXPECT_ACCEPTED(false);
502 thwart_rx_non_initial_requests();
503
504 btw("MS sends TMSI Realloc Complete");
Philipp Maier68760a82017-04-09 12:32:51 +0200505 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100506 ms_sends_msg("055b");
Philipp Maier68760a82017-04-09 12:32:51 +0200507 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100508
509 btw("LU was successful, and the conn has already been closed");
510 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
511 EXPECT_CONN_COUNT(0);
512
513 btw("Subscriber has the IMEI and TMSI");
514 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
515 OSMO_ASSERT(vsub);
Neels Hofmeyr5ae96122017-07-20 02:56:21 +0200516 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100517 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
518 vlr_subscr_put(vsub);
519
520 BTW("subscriber detaches");
Philipp Maier68760a82017-04-09 12:32:51 +0200521 expect_bssap_clear();
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100522 ms_sends_msg("050130089910070000006402");
Philipp Maier68760a82017-04-09 12:32:51 +0200523 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100524
525 EXPECT_CONN_COUNT(0);
526 clear_vlr();
527 comment_end();
528}
529
Neels Hofmeyr5ae96122017-07-20 02:56:21 +0200530void test_no_authen_imeisv()
531{
532 struct vlr_subscr *vsub;
533 const char *imsi = "901700000004620";
534
535 /* No auth only works on GERAN */
536 rx_from_ran = RAN_GERAN_A;
537
538 comment_start();
539
540 net->vlr->cfg.retrieve_imeisv_early = true;
541
542 btw("Location Update request causes an IMEISV ID request back to the MS");
543 lu_result_sent = RES_NONE;
544 dtap_expect_tx("051803");
545 ms_sends_msg("050802008168000130089910070000006402");
546 OSMO_ASSERT(dtap_tx_confirmed);
547
548 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
549 gsup_expect_tx("04010809710000004026f0");
550 ms_sends_msg("0559094332244332244372f5");
551 OSMO_ASSERT(gsup_tx_confirmed);
552 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
553
554 btw("Subscriber has the IMEISV from the ID Response");
555 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
556 OSMO_ASSERT(vsub);
557 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
558 vlr_subscr_put(vsub);
559
560 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
561 gsup_rx("10010809710000004026f00804036470f1",
562 "12010809710000004026f0");
563 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
564
565 btw("having received subscriber data does not mean acceptance");
566 EXPECT_ACCEPTED(false);
567
568 thwart_rx_non_initial_requests();
569
570 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
571
572 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
573 expect_bssap_clear();
574 gsup_rx("06010809710000004026f0", NULL);
575
576 btw("LU was successful, and the conn has already been closed");
577 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
578 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
579 EXPECT_CONN_COUNT(0);
580
581 BTW("subscriber detaches");
582 expect_bssap_clear();
583 ms_sends_msg("050130089910070000006402");
584 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
585
586 EXPECT_CONN_COUNT(0);
587 clear_vlr();
588 comment_end();
589}
590
591void test_no_authen_imeisv_imei()
592{
593 struct vlr_subscr *vsub;
594 const char *imsi = "901700000004620";
595
596 rx_from_ran = RAN_GERAN_A;
597
598 comment_start();
599
600 net->vlr->cfg.retrieve_imeisv_early = true;
601 net->vlr->cfg.check_imei_rqd = true;
602
603 btw("Location Update request causes an IMEISV ID request back to the MS");
604 lu_result_sent = RES_NONE;
605 dtap_expect_tx("051803");
606 ms_sends_msg("050802008168000130089910070000006402");
607 OSMO_ASSERT(dtap_tx_confirmed);
608
609 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
610 gsup_expect_tx("04010809710000004026f0");
611 ms_sends_msg("0559094332244332244372f5");
612 OSMO_ASSERT(gsup_tx_confirmed);
613 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
614
615 btw("Subscriber has the IMEISV from the ID Response");
616 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
617 OSMO_ASSERT(vsub);
618 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
619 vlr_subscr_put(vsub);
620
621 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
622 gsup_rx("10010809710000004026f00804036470f1",
623 "12010809710000004026f0");
624 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
625
626 btw("having received subscriber data does not mean acceptance");
627 EXPECT_ACCEPTED(false);
628 thwart_rx_non_initial_requests();
629 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
630
631 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
632 dtap_expect_tx("051802");
633 gsup_rx("06010809710000004026f0", NULL);
634
635 btw("We will only do business when the IMEI is known");
636 EXPECT_CONN_COUNT(1);
637 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
638 OSMO_ASSERT(vsub);
639 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
640 vlr_subscr_put(vsub);
641 EXPECT_ACCEPTED(false);
642 thwart_rx_non_initial_requests();
643
644 btw("MS replies with an Identity Response");
645 expect_bssap_clear();
646 ms_sends_msg("0559084a32244332244302");
647 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
648
649 btw("LU was successful, and the conn has already been closed");
650 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
651 EXPECT_CONN_COUNT(0);
652
653 btw("Subscriber has the IMEI");
654 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
655 OSMO_ASSERT(vsub);
656 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
657 vlr_subscr_put(vsub);
658
659 BTW("subscriber detaches");
660 expect_bssap_clear();
661 ms_sends_msg("050130089910070000006402");
662 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
663
664 EXPECT_CONN_COUNT(0);
665 clear_vlr();
666 comment_end();
667}
668
669void test_no_authen_imeisv_tmsi()
670{
671 struct vlr_subscr *vsub;
672 const char *imsi = "901700000004620";
673
674 rx_from_ran = RAN_GERAN_A;
675
676 comment_start();
677
678 net->vlr->cfg.retrieve_imeisv_early = true;
679 net->vlr->cfg.assign_tmsi = true;
680
681 btw("Location Update request causes an IMEISV ID request back to the MS");
682 lu_result_sent = RES_NONE;
683 dtap_expect_tx("051803");
684 ms_sends_msg("050802008168000130089910070000006402");
685 OSMO_ASSERT(dtap_tx_confirmed);
686
687 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
688 gsup_expect_tx("04010809710000004026f0");
689 ms_sends_msg("0559094332244332244372f5");
690 OSMO_ASSERT(gsup_tx_confirmed);
691 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
692
693 btw("Subscriber has the IMEISV from the ID Response");
694 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
695 OSMO_ASSERT(vsub);
696 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
697 vlr_subscr_put(vsub);
698
699 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
700 gsup_rx("10010809710000004026f00804036470f1",
701 "12010809710000004026f0");
702 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
703
704 btw("having received subscriber data does not mean acceptance");
705 EXPECT_ACCEPTED(false);
706 thwart_rx_non_initial_requests();
707 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
708
709 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
710 gsup_rx("06010809710000004026f0", NULL);
711
712 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
713 EXPECT_CONN_COUNT(1);
714 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
715 EXPECT_ACCEPTED(false);
716 thwart_rx_non_initial_requests();
717
718 btw("even though the TMSI is not acked, we can already find the subscr with it");
719 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
720 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
721 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
722 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
723 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
724 vlr_subscr_put(vsub);
725
726 btw("MS sends TMSI Realloc Complete");
727 expect_bssap_clear();
728 ms_sends_msg("055b");
729 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
730
731 btw("LU was successful, and the conn has already been closed");
732 EXPECT_CONN_COUNT(0);
733
734
735 BTW("subscriber sends LU Request, this time with the TMSI");
736 btw("Location Update request causes an IMEISV ID request back to the MS");
737 lu_result_sent = RES_NONE;
738 dtap_expect_tx("051803");
739 ms_sends_msg("050802008168000130089910070000006402");
740 OSMO_ASSERT(dtap_tx_confirmed);
741
742 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
743 gsup_expect_tx("04010809710000004026f0");
744 ms_sends_msg("0559095332244332244372f6");
745 OSMO_ASSERT(gsup_tx_confirmed);
746 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
747
748 btw("Subscriber has the IMEISV from the ID Response");
749 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
750 OSMO_ASSERT(vsub);
751 VERBOSE_ASSERT(strcmp(vsub->imeisv, "5234234234234276"), == 0, "%d");
752 vlr_subscr_put(vsub);
753
754 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
755 gsup_rx("10010809710000004026f00804036470f1",
756 "12010809710000004026f0");
757 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
758
759 btw("having received subscriber data does not mean acceptance");
760 EXPECT_ACCEPTED(false);
761 thwart_rx_non_initial_requests();
762 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
763
764 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
765 gsup_rx("06010809710000004026f0", NULL);
766
767 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
768 EXPECT_CONN_COUNT(1);
769 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
770 EXPECT_ACCEPTED(false);
771 thwart_rx_non_initial_requests();
772
773 btw("even though the TMSI is not acked, we can already find the subscr with it");
774 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
775 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
776 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
777 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
778 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
779 vlr_subscr_put(vsub);
780
781 btw("MS sends TMSI Realloc Complete");
782 expect_bssap_clear();
783 ms_sends_msg("055b");
784 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
785
786 btw("LU was successful, and the conn has already been closed");
787 EXPECT_CONN_COUNT(0);
788
789 btw("subscriber has the new TMSI");
790 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
791 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
792 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
793 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
794 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
795 vlr_subscr_put(vsub);
796
797 BTW("subscriber detaches, using new TMSI");
798 expect_bssap_clear();
799 ms_sends_msg("050130" "05f4" "07060504");
800 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
801
802 EXPECT_CONN_COUNT(0);
803 clear_vlr();
804 comment_end();
805}
806
807void test_no_authen_imeisv_tmsi_imei()
808{
809 struct vlr_subscr *vsub;
810 const char *imsi = "901700000004620";
811
812 rx_from_ran = RAN_GERAN_A;
813
814 comment_start();
815
816 net->vlr->cfg.retrieve_imeisv_early = true;
817 net->vlr->cfg.assign_tmsi = true;
818 net->vlr->cfg.check_imei_rqd = true;
819
820 btw("Location Update request causes an IMEISV ID request back to the MS");
821 lu_result_sent = RES_NONE;
822 dtap_expect_tx("051803");
823 ms_sends_msg("050802008168000130089910070000006402");
824 OSMO_ASSERT(dtap_tx_confirmed);
825
826 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
827 gsup_expect_tx("04010809710000004026f0");
828 ms_sends_msg("0559094332244332244372f5");
829 OSMO_ASSERT(gsup_tx_confirmed);
830 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
831
832 btw("Subscriber has the IMEISV from the ID Response");
833 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
834 OSMO_ASSERT(vsub);
835 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
836 vlr_subscr_put(vsub);
837
838 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
839 gsup_rx("10010809710000004026f00804036470f1",
840 "12010809710000004026f0");
841 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
842
843 btw("having received subscriber data does not mean acceptance");
844 EXPECT_ACCEPTED(false);
845 thwart_rx_non_initial_requests();
846 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
847
848 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
849 dtap_expect_tx("051802");
850 gsup_rx("06010809710000004026f0", NULL);
851
852 btw("We will only do business when the IMEI is known");
853 EXPECT_CONN_COUNT(1);
854 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
855 OSMO_ASSERT(vsub);
856 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
857 vlr_subscr_put(vsub);
858 EXPECT_ACCEPTED(false);
859 thwart_rx_non_initial_requests();
860
861 btw("MS replies with an Identity Response");
862 ms_sends_msg("0559084a32244332244302");
863
864 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
865 EXPECT_CONN_COUNT(1);
866 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
867 EXPECT_ACCEPTED(false);
868 thwart_rx_non_initial_requests();
869
870 btw("MS sends TMSI Realloc Complete");
871 expect_bssap_clear();
872 ms_sends_msg("055b");
873 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
874
875 btw("LU was successful, and the conn has already been closed");
876 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
877 EXPECT_CONN_COUNT(0);
878
879 btw("Subscriber has the IMEISV, IMEI and TMSI");
880 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
881 OSMO_ASSERT(vsub);
882 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
883 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
884 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
885 vlr_subscr_put(vsub);
886
887 BTW("subscriber detaches");
888 expect_bssap_clear();
889 ms_sends_msg("050130089910070000006402");
890 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
891
892 EXPECT_CONN_COUNT(0);
893 clear_vlr();
894 comment_end();
895}
896
897
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100898msc_vlr_test_func_t msc_vlr_tests[] = {
899 test_no_authen,
900 test_no_authen_tmsi,
901 test_no_authen_imei,
902 test_no_authen_tmsi_imei,
Neels Hofmeyr5ae96122017-07-20 02:56:21 +0200903 test_no_authen_imeisv,
904 test_no_authen_imeisv_imei,
905 test_no_authen_imeisv_tmsi,
906 test_no_authen_imeisv_tmsi_imei,
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100907 NULL
908};