blob: d52d3d6ff726925372ee2fe0669a78940794023e [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 */
Neels Hofmeyr7814a832018-12-26 00:40:18 +010032 rx_from_ran = OSMO_RAT_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 */
Neels Hofmeyr7814a832018-12-26 00:40:18 +010076 expect_bssap_clear(OSMO_RAT_GERAN_A);
77 conn_conclude_cm_service_req(g_conn, OSMO_RAT_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 Hofmeyr7814a832018-12-26 00:40:18 +0100172 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200173
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 */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100239 expect_bssap_clear(OSMO_RAT_GERAN_A);
240 conn_conclude_cm_service_req(g_conn, OSMO_RAT_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 Hofmeyr7814a832018-12-26 00:40:18 +0100395 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200396
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
Oliver Smith7d053092018-12-14 17:37:38 +0100431 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
432 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
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");
Oliver Smith7d053092018-12-14 17:37:38 +0100436
437 btw("HLR accepts the IMEI");
438 expect_bssap_clear();
439 gsup_rx("32010809710000004026f0510100", NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200440 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100441
442 btw("LU was successful, and the conn has already been closed");
443 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200444 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100445 EXPECT_CONN_COUNT(0);
446
447 btw("Subscriber has the IMEI");
448 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
449 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200450 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100451 vlr_subscr_put(vsub);
452
453 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200454 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100455 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200456 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100457
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200458 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100459 EXPECT_CONN_COUNT(0);
460 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100461 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100462}
463
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100464static void test_no_authen_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100465{
466 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100467 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100468
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100469 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200470
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100471 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100472
473 net->vlr->cfg.assign_tmsi = true;
474 net->vlr->cfg.check_imei_rqd = true;
475
476 btw("Location Update request causes a GSUP LU request to HLR");
477 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200478 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100479 ms_sends_msg("050802008168000130089910070000006402");
480 OSMO_ASSERT(gsup_tx_confirmed);
481 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
482
483 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
484 gsup_rx("10010809710000004026f00804036470f1",
485 "12010809710000004026f0");
486 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
487
488 btw("having received subscriber data does not mean acceptance");
489 EXPECT_ACCEPTED(false);
490 thwart_rx_non_initial_requests();
491 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
492
493 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
494 dtap_expect_tx("051802");
495 gsup_rx("06010809710000004026f0", NULL);
496
497 btw("We will only do business when the IMEI is known");
498 EXPECT_CONN_COUNT(1);
499 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
500 OSMO_ASSERT(vsub);
501 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
502 vlr_subscr_put(vsub);
503 EXPECT_ACCEPTED(false);
504 thwart_rx_non_initial_requests();
505
Oliver Smith7d053092018-12-14 17:37:38 +0100506 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
507 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200508 ms_sends_msg("0559084a32244332244302");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100509
Oliver Smith7d053092018-12-14 17:37:38 +0100510 btw("HLR accepts the IMEI");
511 gsup_rx("32010809710000004026f0510100", NULL);
512
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100513 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
514 EXPECT_CONN_COUNT(1);
515 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
516 EXPECT_ACCEPTED(false);
517 thwart_rx_non_initial_requests();
518
519 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200520 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100521 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200522 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100523
524 btw("LU was successful, and the conn has already been closed");
525 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200526 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100527 EXPECT_CONN_COUNT(0);
528
529 btw("Subscriber has the IMEI and TMSI");
530 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
531 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200532 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100533 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
534 vlr_subscr_put(vsub);
535
536 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200537 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100538 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200539 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100540
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200541 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100542 EXPECT_CONN_COUNT(0);
543 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100544 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100545}
546
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100547static void test_no_authen_imeisv()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200548{
549 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100550 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200551
552 /* No auth only works on GERAN */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100553 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200554
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100555 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200556
557 net->vlr->cfg.retrieve_imeisv_early = true;
558
559 btw("Location Update request causes an IMEISV ID request back to the MS");
560 lu_result_sent = RES_NONE;
561 dtap_expect_tx("051803");
562 ms_sends_msg("050802008168000130089910070000006402");
563 OSMO_ASSERT(dtap_tx_confirmed);
564
565 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 +0200566 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200567 ms_sends_msg("0559094332244332244372f5");
568 OSMO_ASSERT(gsup_tx_confirmed);
569 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
570
571 btw("Subscriber has the IMEISV from the ID Response");
572 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
573 OSMO_ASSERT(vsub);
574 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
575 vlr_subscr_put(vsub);
576
577 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
578 gsup_rx("10010809710000004026f00804036470f1",
579 "12010809710000004026f0");
580 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
581
582 btw("having received subscriber data does not mean acceptance");
583 EXPECT_ACCEPTED(false);
584
585 thwart_rx_non_initial_requests();
586
587 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
588
589 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
590 expect_bssap_clear();
591 gsup_rx("06010809710000004026f0", NULL);
592
593 btw("LU was successful, and the conn has already been closed");
594 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
595 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
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
599 BTW("subscriber detaches");
600 expect_bssap_clear();
601 ms_sends_msg("050130089910070000006402");
602 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
603
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200604 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200605 EXPECT_CONN_COUNT(0);
606 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100607 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200608}
609
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100610static void test_no_authen_imeisv_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200611{
612 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100613 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200614
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100615 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200616
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100617 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200618
619 net->vlr->cfg.retrieve_imeisv_early = true;
620 net->vlr->cfg.check_imei_rqd = true;
621
622 btw("Location Update request causes an IMEISV ID request back to the MS");
623 lu_result_sent = RES_NONE;
624 dtap_expect_tx("051803");
625 ms_sends_msg("050802008168000130089910070000006402");
626 OSMO_ASSERT(dtap_tx_confirmed);
627
628 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 +0200629 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200630 ms_sends_msg("0559094332244332244372f5");
631 OSMO_ASSERT(gsup_tx_confirmed);
632 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
633
634 btw("Subscriber has the IMEISV from the ID Response");
635 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
636 OSMO_ASSERT(vsub);
637 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
638 vlr_subscr_put(vsub);
639
640 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
641 gsup_rx("10010809710000004026f00804036470f1",
642 "12010809710000004026f0");
643 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
644
645 btw("having received subscriber data does not mean acceptance");
646 EXPECT_ACCEPTED(false);
647 thwart_rx_non_initial_requests();
648 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
649
650 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
651 dtap_expect_tx("051802");
652 gsup_rx("06010809710000004026f0", NULL);
653
654 btw("We will only do business when the IMEI is known");
655 EXPECT_CONN_COUNT(1);
656 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
657 OSMO_ASSERT(vsub);
658 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
659 vlr_subscr_put(vsub);
660 EXPECT_ACCEPTED(false);
661 thwart_rx_non_initial_requests();
662
Oliver Smith7d053092018-12-14 17:37:38 +0100663 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
664 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200665 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100666
667 btw("HLR accepts the IMEI");
668 expect_bssap_clear();
669 gsup_rx("32010809710000004026f0510100", NULL);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200670 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
671
672 btw("LU was successful, and the conn has already been closed");
673 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200674 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200675 EXPECT_CONN_COUNT(0);
676
677 btw("Subscriber has the IMEI");
678 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
679 OSMO_ASSERT(vsub);
680 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
681 vlr_subscr_put(vsub);
682
683 BTW("subscriber detaches");
684 expect_bssap_clear();
685 ms_sends_msg("050130089910070000006402");
686 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
687
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200688 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200689 EXPECT_CONN_COUNT(0);
690 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100691 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200692}
693
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100694static void test_no_authen_imeisv_tmsi()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200695{
696 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100697 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200698
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100699 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200700
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100701 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200702
703 net->vlr->cfg.retrieve_imeisv_early = true;
704 net->vlr->cfg.assign_tmsi = true;
705
706 btw("Location Update request causes an IMEISV ID request back to the MS");
707 lu_result_sent = RES_NONE;
708 dtap_expect_tx("051803");
709 ms_sends_msg("050802008168000130089910070000006402");
710 OSMO_ASSERT(dtap_tx_confirmed);
711
712 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 +0200713 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200714 ms_sends_msg("0559094332244332244372f5");
715 OSMO_ASSERT(gsup_tx_confirmed);
716 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
717
718 btw("Subscriber has the IMEISV from the ID Response");
719 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
720 OSMO_ASSERT(vsub);
721 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
722 vlr_subscr_put(vsub);
723
724 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
725 gsup_rx("10010809710000004026f00804036470f1",
726 "12010809710000004026f0");
727 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
728
729 btw("having received subscriber data does not mean acceptance");
730 EXPECT_ACCEPTED(false);
731 thwart_rx_non_initial_requests();
732 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
733
734 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
735 gsup_rx("06010809710000004026f0", NULL);
736
737 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
738 EXPECT_CONN_COUNT(1);
739 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
740 EXPECT_ACCEPTED(false);
741 thwart_rx_non_initial_requests();
742
743 btw("even though the TMSI is not acked, we can already find the subscr with it");
744 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
745 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
746 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
747 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
748 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
749 vlr_subscr_put(vsub);
750
751 btw("MS sends TMSI Realloc Complete");
752 expect_bssap_clear();
753 ms_sends_msg("055b");
754 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
755
756 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200757 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200758 EXPECT_CONN_COUNT(0);
759
760
761 BTW("subscriber sends LU Request, this time with the TMSI");
762 btw("Location Update request causes an IMEISV ID request back to the MS");
763 lu_result_sent = RES_NONE;
764 dtap_expect_tx("051803");
765 ms_sends_msg("050802008168000130089910070000006402");
766 OSMO_ASSERT(dtap_tx_confirmed);
767
768 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 +0200769 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200770 ms_sends_msg("0559095332244332244372f6");
771 OSMO_ASSERT(gsup_tx_confirmed);
772 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
773
774 btw("Subscriber has the IMEISV from the ID Response");
775 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
776 OSMO_ASSERT(vsub);
777 VERBOSE_ASSERT(strcmp(vsub->imeisv, "5234234234234276"), == 0, "%d");
778 vlr_subscr_put(vsub);
779
780 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
781 gsup_rx("10010809710000004026f00804036470f1",
782 "12010809710000004026f0");
783 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
784
785 btw("having received subscriber data does not mean acceptance");
786 EXPECT_ACCEPTED(false);
787 thwart_rx_non_initial_requests();
788 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
789
790 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
791 gsup_rx("06010809710000004026f0", NULL);
792
793 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
794 EXPECT_CONN_COUNT(1);
795 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
796 EXPECT_ACCEPTED(false);
797 thwart_rx_non_initial_requests();
798
799 btw("even though the TMSI is not acked, we can already find the subscr with it");
800 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
801 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
802 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
803 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
804 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
805 vlr_subscr_put(vsub);
806
807 btw("MS sends TMSI Realloc Complete");
808 expect_bssap_clear();
809 ms_sends_msg("055b");
810 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
811
812 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200813 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200814 EXPECT_CONN_COUNT(0);
815
816 btw("subscriber has the new TMSI");
817 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
818 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
819 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
820 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
821 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
822 vlr_subscr_put(vsub);
823
824 BTW("subscriber detaches, using new TMSI");
825 expect_bssap_clear();
826 ms_sends_msg("050130" "05f4" "07060504");
827 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
828
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200829 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200830 EXPECT_CONN_COUNT(0);
831 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100832 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200833}
834
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100835static void test_no_authen_imeisv_tmsi_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200836{
837 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100838 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200839
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100840 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200841
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100842 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200843
844 net->vlr->cfg.retrieve_imeisv_early = true;
845 net->vlr->cfg.assign_tmsi = true;
846 net->vlr->cfg.check_imei_rqd = true;
847
848 btw("Location Update request causes an IMEISV ID request back to the MS");
849 lu_result_sent = RES_NONE;
850 dtap_expect_tx("051803");
851 ms_sends_msg("050802008168000130089910070000006402");
852 OSMO_ASSERT(dtap_tx_confirmed);
853
854 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 +0200855 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200856 ms_sends_msg("0559094332244332244372f5");
857 OSMO_ASSERT(gsup_tx_confirmed);
858 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
859
860 btw("Subscriber has the IMEISV from the ID Response");
861 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
862 OSMO_ASSERT(vsub);
863 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
864 vlr_subscr_put(vsub);
865
866 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
867 gsup_rx("10010809710000004026f00804036470f1",
868 "12010809710000004026f0");
869 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
870
871 btw("having received subscriber data does not mean acceptance");
872 EXPECT_ACCEPTED(false);
873 thwart_rx_non_initial_requests();
874 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
875
876 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
877 dtap_expect_tx("051802");
878 gsup_rx("06010809710000004026f0", NULL);
879
880 btw("We will only do business when the IMEI is known");
881 EXPECT_CONN_COUNT(1);
882 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
883 OSMO_ASSERT(vsub);
884 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
885 vlr_subscr_put(vsub);
886 EXPECT_ACCEPTED(false);
887 thwart_rx_non_initial_requests();
888
Oliver Smith7d053092018-12-14 17:37:38 +0100889 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
890 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200891 ms_sends_msg("0559084a32244332244302");
892
Oliver Smith7d053092018-12-14 17:37:38 +0100893 btw("HLR accepts the IMEI");
894 gsup_rx("32010809710000004026f0510100", NULL);
895
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200896 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
897 EXPECT_CONN_COUNT(1);
898 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
899 EXPECT_ACCEPTED(false);
900 thwart_rx_non_initial_requests();
901
902 btw("MS sends TMSI Realloc Complete");
903 expect_bssap_clear();
904 ms_sends_msg("055b");
905 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
906
907 btw("LU was successful, and the conn has already been closed");
908 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
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
912 btw("Subscriber has the IMEISV, IMEI and TMSI");
913 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
914 OSMO_ASSERT(vsub);
915 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
916 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
917 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
918 vlr_subscr_put(vsub);
919
920 BTW("subscriber detaches");
921 expect_bssap_clear();
922 ms_sends_msg("050130089910070000006402");
923 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
924
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200925 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200926 EXPECT_CONN_COUNT(0);
927 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100928 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200929}
930
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200931static void test_no_authen_subscr_expire()
932{
933 struct vlr_subscr *vsub;
934 const char *imsi = "901700000004620";
935
936 /* No auth only works on GERAN */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100937 rx_from_ran = OSMO_RAT_GERAN_A;
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200938
939 comment_start();
940
941 fake_time_start();
942
943 /* The test framework has already started the VLR before fake time was active.
944 * Manually schedule this timeout in fake time. */
945 osmo_timer_del(&net->vlr->lu_expire_timer);
946 osmo_timer_schedule(&net->vlr->lu_expire_timer, VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL, 0);
947
948 /* Let the LU expiration timer tick once */
949 fake_time_passes(VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL + 1, 0);
950
951 btw("Location Update request causes a GSUP LU request to HLR");
952 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200953 gsup_expect_tx("04010809710000004026f0280102");
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200954 ms_sends_msg("050802008168000130089910070000006402");
955 OSMO_ASSERT(gsup_tx_confirmed);
956 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
957
958 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
959 gsup_rx("10010809710000004026f00804036470f1",
960 "12010809710000004026f0");
961 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
962
963 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
964 expect_bssap_clear();
965 gsup_rx("06010809710000004026f0", NULL);
966
967 btw("LU was successful, and the conn has already been closed");
968 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
969 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
970
971 bss_sends_clear_complete();
972 EXPECT_CONN_COUNT(0);
973
974 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
975 OSMO_ASSERT(vsub);
976 vlr_subscr_put(vsub);
977
978 /* Let T3212 (periodic Location update timer) expire */
979 fake_time_passes((net->t3212 * 60 * 6 * 2) + 60*4, 0);
980
981 /* The subscriber should now be gone. */
982 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
983 OSMO_ASSERT(vsub == NULL);
984
985 EXPECT_CONN_COUNT(0);
986 clear_vlr();
987 comment_end();
988}
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200989
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100990msc_vlr_test_func_t msc_vlr_tests[] = {
991 test_no_authen,
992 test_no_authen_tmsi,
993 test_no_authen_imei,
994 test_no_authen_tmsi_imei,
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200995 test_no_authen_imeisv,
996 test_no_authen_imeisv_imei,
997 test_no_authen_imeisv_tmsi,
998 test_no_authen_imeisv_tmsi_imei,
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200999 test_no_authen_subscr_expire,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001000 NULL
1001};