blob: 85c01d9d22d6f37103a95044083ce6064412f82a [file] [log] [blame]
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001/* Osmocom MSC+VLR end-to-end tests */
2
3/* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 *
5 * All Rights Reserved
6 *
7 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#include "msc_vlr_tests.h"
25
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010026static void test_no_authen()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
28 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010029 const char *imsi = "901700000004620";
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020030
31 /* No auth only works on GERAN */
32 rx_from_ran = RAN_GERAN_A;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010033
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010034 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010035
36 btw("Location Update request causes a GSUP LU request to HLR");
37 lu_result_sent = RES_NONE;
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 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
75 btw("a USSD request is serviced");
76 dtap_expect_tx_ussd("Your extension is 46071\r");
Philipp Maierfbf66102017-04-09 12:32:51 +020077 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010078 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020079 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +020080 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010081
82 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +020083 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010084 EXPECT_CONN_COUNT(0);
85
86 BTW("an SMS is sent, MS is paged");
87 paging_expect_imsi(imsi);
88 paging_sent = false;
89 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
90 OSMO_ASSERT(vsub);
91 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
92
93 send_sms(vsub, vsub,
94 "Privacy in residential applications is a desirable"
95 " marketing option.");
96
97 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
98 vlr_subscr_put(vsub);
99 vsub = NULL;
100 VERBOSE_ASSERT(paging_sent, == true, "%d");
101 VERBOSE_ASSERT(paging_stopped, == false, "%d");
102
103 btw("the subscriber and its pending request should remain");
104 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
105 OSMO_ASSERT(vsub);
106 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
107 vlr_subscr_put(vsub);
108
109 btw("MS replies with Paging Response, we deliver the SMS");
110 dtap_expect_tx("09" /* SMS messages */
111 "01" /* CP-DATA */
112 "58" /* length */
113 "01" /* Network to MS */
114 "00" /* reference */
115 /* originator (gsm411_send_sms() hardcodes this weird nr) */
116 "0791" "447758100650" /* 447785016005 */
117 "00" /* dest */
118 /* SMS TPDU */
119 "4c" /* len */
120 "00" /* SMS deliver */
121 "05806470f1" /* originating address 46071 */
122 "00" /* TP-PID */
123 "00" /* GSM default alphabet */
124 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
125 "000000" /* H-M-S */
126 "00" /* GMT+0 */
127 "44" /* data length */
128 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
129 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
130 "0c7ac3e9e9b7db05");
131 ms_sends_msg("06270703305882089910070000006402");
132 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
133 VERBOSE_ASSERT(paging_stopped, == true, "%d");
134
135 btw("SMS was delivered, no requests pending for subscr");
136 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
137 OSMO_ASSERT(vsub);
138 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
139 vlr_subscr_put(vsub);
140
141 btw("conn is still open to wait for SMS ack dance");
142 EXPECT_CONN_COUNT(1);
143
144 btw("MS replies with CP-ACK for received SMS");
145 ms_sends_msg("8904");
146 EXPECT_CONN_COUNT(1);
147
148 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
149 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200150 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100151 ms_sends_msg("890106020041020000");
152 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200153 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100154
155 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200156 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100157 EXPECT_CONN_COUNT(0);
158
159 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200160 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100161 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200162 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100163
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200164 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100165 EXPECT_CONN_COUNT(0);
166 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100167 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100168}
169
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100170static void test_no_authen_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100171{
172 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100173 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100174
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200175 rx_from_ran = RAN_GERAN_A;
176
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100177 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100178
179 net->vlr->cfg.assign_tmsi = true;
180
181 btw("Location Update request causes a GSUP LU request to HLR");
182 lu_result_sent = RES_NONE;
183 gsup_expect_tx("04010809710000004026f0");
184 ms_sends_msg("050802008168000130089910070000006402");
185 OSMO_ASSERT(gsup_tx_confirmed);
186 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
187
188 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
189 gsup_rx("10010809710000004026f00804036470f1",
190 "12010809710000004026f0");
191 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
192
193 btw("having received subscriber data does not mean acceptance");
194 EXPECT_ACCEPTED(false);
195 thwart_rx_non_initial_requests();
196 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
197
198 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
199 gsup_rx("06010809710000004026f0", NULL);
200
201 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
202 EXPECT_CONN_COUNT(1);
203 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
204 EXPECT_ACCEPTED(false);
205 thwart_rx_non_initial_requests();
206
207 btw("even though the TMSI is not acked, we can already find the subscr with it");
208 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
209 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
210 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
211 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
212 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
213 vlr_subscr_put(vsub);
214
215 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200216 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100217 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200218 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100219
220 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200221 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100222 EXPECT_CONN_COUNT(0);
223
224 btw("Subscriber has the new TMSI");
225 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
226 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
227 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
228 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
229 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
230 vlr_subscr_put(vsub);
231
232 BTW("after a while, a new conn sends a CM Service Request using above TMSI");
233 cm_service_result_sent = RES_NONE;
234 ms_sends_msg("05247803305886" "05f4" "03020100");
235 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200236 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100237 OSMO_ASSERT(g_conn->vsub);
238 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
239 EXPECT_ACCEPTED(true);
240
241 btw("a USSD request is serviced");
242 dtap_expect_tx_ussd("Your extension is 46071\r");
Philipp Maierfbf66102017-04-09 12:32:51 +0200243 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100244 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200245 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100246
247 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200248 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100249 EXPECT_CONN_COUNT(0);
250
251 BTW("an SMS is sent, MS is paged using above TMSI");
252 paging_expect_tmsi(0x03020100);
253 paging_sent = false;
254 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
255 OSMO_ASSERT(vsub);
256 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
257
258 send_sms(vsub, vsub,
259 "Privacy in residential applications is a desirable"
260 " marketing option.");
261
262 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
263 vlr_subscr_put(vsub);
264 vsub = NULL;
265 VERBOSE_ASSERT(paging_sent, == true, "%d");
266 VERBOSE_ASSERT(paging_stopped, == false, "%d");
267
268 btw("the subscriber and its pending request should remain");
269 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
270 OSMO_ASSERT(vsub);
271 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
272 vlr_subscr_put(vsub);
273
274 btw("MS replies with Paging Response using TMSI, we deliver the SMS");
275 dtap_expect_tx("09" /* SMS messages */
276 "01" /* CP-DATA */
277 "58" /* length */
278 "01" /* Network to MS */
279 "00" /* reference */
280 /* originator (gsm411_send_sms() hardcodes this weird nr) */
281 "0791" "447758100650" /* 447785016005 */
282 "00" /* dest */
283 /* SMS TPDU */
284 "4c" /* len */
285 "00" /* SMS deliver */
286 "05806470f1" /* originating address 46071 */
287 "00" /* TP-PID */
288 "00" /* GSM default alphabet */
289 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
290 "000000" /* H-M-S */
291 "00" /* GMT+0 */
292 "44" /* data length */
293 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
294 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
295 "0c7ac3e9e9b7db05");
296 ms_sends_msg("06270703305882" "05f4" "03020100");
297 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
298 VERBOSE_ASSERT(paging_stopped, == true, "%d");
299
300 btw("SMS was delivered, no requests pending for subscr");
301 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
302 OSMO_ASSERT(vsub);
303 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
304 vlr_subscr_put(vsub);
305
306 btw("conn is still open to wait for SMS ack dance");
307 EXPECT_CONN_COUNT(1);
308
309 btw("MS replies with CP-ACK for received SMS");
310 ms_sends_msg("8904");
311 EXPECT_CONN_COUNT(1);
312
313 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
314 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200315 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100316 ms_sends_msg("890106020041020000");
317 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200318 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100319
320 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200321 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100322 EXPECT_CONN_COUNT(0);
323
324 /* TODO: when the subscriber detaches, the vlr_subscr gets
325 * deallocated and we no longer know the TMSI. This case is covered by
326 * test_lu_unknown_tmsi(), so here I'd like to still have the TMSI.
327 BTW("subscriber detaches, using TMSI");
328 ms_sends_msg("050130" "05f4" "03020100");
329 EXPECT_CONN_COUNT(0);
330 */
331
332 BTW("subscriber sends LU Request, this time with the TMSI");
333 btw("Location Update request causes a GSUP LU request to HLR");
334 lu_result_sent = RES_NONE;
335 gsup_expect_tx("04010809710000004026f0");
336 ms_sends_msg("050802008168000130" "05f4" "03020100");
337 OSMO_ASSERT(gsup_tx_confirmed);
338 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
339
340 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
341 gsup_rx("10010809710000004026f00804036470f1",
342 "12010809710000004026f0");
343 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
344
345 btw("having received subscriber data does not mean acceptance");
346 EXPECT_ACCEPTED(false);
347 thwart_rx_non_initial_requests();
348 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
349
350 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
351 gsup_rx("06010809710000004026f0", NULL);
352
353 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
354 EXPECT_CONN_COUNT(1);
355 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
356 EXPECT_ACCEPTED(false);
357 thwart_rx_non_initial_requests();
358
359 btw("even though the TMSI is not acked, we can already find the subscr with it");
360 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
361 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
362 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
363 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
364 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
365 vlr_subscr_put(vsub);
366
367 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200368 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100369 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200370 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100371
372 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200373 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100374 EXPECT_CONN_COUNT(0);
375
376 btw("subscriber has the new TMSI");
377 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
378 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
379 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
380 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
381 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
382 vlr_subscr_put(vsub);
383
384 BTW("subscriber detaches, using new TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200385 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100386 ms_sends_msg("050130" "05f4" "07060504");
Philipp Maierfbf66102017-04-09 12:32:51 +0200387 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100388
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200389 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100390 EXPECT_CONN_COUNT(0);
391 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100392 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100393}
394
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100395static void test_no_authen_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100396{
397 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100398 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100399
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200400 rx_from_ran = RAN_GERAN_A;
401
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100402 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100403
404 net->vlr->cfg.check_imei_rqd = true;
405
406 btw("Location Update request causes a GSUP LU request to HLR");
407 lu_result_sent = RES_NONE;
408 gsup_expect_tx("04010809710000004026f0");
409 ms_sends_msg("050802008168000130089910070000006402");
410 OSMO_ASSERT(gsup_tx_confirmed);
411 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
412
413 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
414 gsup_rx("10010809710000004026f00804036470f1",
415 "12010809710000004026f0");
416 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
417
418 btw("having received subscriber data does not mean acceptance");
419 EXPECT_ACCEPTED(false);
420 thwart_rx_non_initial_requests();
421 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
422
423 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
424 dtap_expect_tx("051802");
425 gsup_rx("06010809710000004026f0", NULL);
426
427 btw("We will only do business when the IMEI is known");
428 EXPECT_CONN_COUNT(1);
429 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
430 OSMO_ASSERT(vsub);
431 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
432 vlr_subscr_put(vsub);
433 EXPECT_ACCEPTED(false);
434 thwart_rx_non_initial_requests();
435
436 btw("MS replies with an Identity Response");
Philipp Maierfbf66102017-04-09 12:32:51 +0200437 expect_bssap_clear();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200438 /* 3GPP TS 23.003: 6.2.1 Composition of IMEI: the IMEI ends with a
439 * spare digit that shall be sent as zero by the MS. */
440 ms_sends_msg("0559084a32244332244302");
Philipp Maierfbf66102017-04-09 12:32:51 +0200441 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100442
443 btw("LU was successful, and the conn has already been closed");
444 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200445 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100446 EXPECT_CONN_COUNT(0);
447
448 btw("Subscriber has the IMEI");
449 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
450 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200451 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100452 vlr_subscr_put(vsub);
453
454 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200455 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100456 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200457 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100458
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200459 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100460 EXPECT_CONN_COUNT(0);
461 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100462 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100463}
464
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100465static void test_no_authen_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100466{
467 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100468 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100469
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200470 rx_from_ran = RAN_GERAN_A;
471
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100472 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100473
474 net->vlr->cfg.assign_tmsi = true;
475 net->vlr->cfg.check_imei_rqd = true;
476
477 btw("Location Update request causes a GSUP LU request to HLR");
478 lu_result_sent = RES_NONE;
479 gsup_expect_tx("04010809710000004026f0");
480 ms_sends_msg("050802008168000130089910070000006402");
481 OSMO_ASSERT(gsup_tx_confirmed);
482 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
483
484 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
485 gsup_rx("10010809710000004026f00804036470f1",
486 "12010809710000004026f0");
487 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
488
489 btw("having received subscriber data does not mean acceptance");
490 EXPECT_ACCEPTED(false);
491 thwart_rx_non_initial_requests();
492 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
493
494 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
495 dtap_expect_tx("051802");
496 gsup_rx("06010809710000004026f0", NULL);
497
498 btw("We will only do business when the IMEI is known");
499 EXPECT_CONN_COUNT(1);
500 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
501 OSMO_ASSERT(vsub);
502 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
503 vlr_subscr_put(vsub);
504 EXPECT_ACCEPTED(false);
505 thwart_rx_non_initial_requests();
506
507 btw("MS replies with an Identity Response");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200508 ms_sends_msg("0559084a32244332244302");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100509
510 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
511 EXPECT_CONN_COUNT(1);
512 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
513 EXPECT_ACCEPTED(false);
514 thwart_rx_non_initial_requests();
515
516 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200517 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100518 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200519 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100520
521 btw("LU was successful, and the conn has already been closed");
522 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200523 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100524 EXPECT_CONN_COUNT(0);
525
526 btw("Subscriber has the IMEI and TMSI");
527 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
528 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200529 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100530 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
531 vlr_subscr_put(vsub);
532
533 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200534 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100535 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200536 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100537
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200538 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100539 EXPECT_CONN_COUNT(0);
540 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100541 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100542}
543
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100544static void test_no_authen_imeisv()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200545{
546 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100547 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200548
549 /* No auth only works on GERAN */
550 rx_from_ran = RAN_GERAN_A;
551
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100552 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200553
554 net->vlr->cfg.retrieve_imeisv_early = true;
555
556 btw("Location Update request causes an IMEISV ID request back to the MS");
557 lu_result_sent = RES_NONE;
558 dtap_expect_tx("051803");
559 ms_sends_msg("050802008168000130089910070000006402");
560 OSMO_ASSERT(dtap_tx_confirmed);
561
562 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
563 gsup_expect_tx("04010809710000004026f0");
564 ms_sends_msg("0559094332244332244372f5");
565 OSMO_ASSERT(gsup_tx_confirmed);
566 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
567
568 btw("Subscriber has the IMEISV from the ID Response");
569 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
570 OSMO_ASSERT(vsub);
571 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
572 vlr_subscr_put(vsub);
573
574 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
575 gsup_rx("10010809710000004026f00804036470f1",
576 "12010809710000004026f0");
577 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
578
579 btw("having received subscriber data does not mean acceptance");
580 EXPECT_ACCEPTED(false);
581
582 thwart_rx_non_initial_requests();
583
584 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
585
586 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
587 expect_bssap_clear();
588 gsup_rx("06010809710000004026f0", NULL);
589
590 btw("LU was successful, and the conn has already been closed");
591 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
592 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200593 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200594 EXPECT_CONN_COUNT(0);
595
596 BTW("subscriber detaches");
597 expect_bssap_clear();
598 ms_sends_msg("050130089910070000006402");
599 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
600
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200601 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200602 EXPECT_CONN_COUNT(0);
603 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100604 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200605}
606
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100607static void test_no_authen_imeisv_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200608{
609 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100610 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200611
612 rx_from_ran = RAN_GERAN_A;
613
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100614 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200615
616 net->vlr->cfg.retrieve_imeisv_early = true;
617 net->vlr->cfg.check_imei_rqd = true;
618
619 btw("Location Update request causes an IMEISV ID request back to the MS");
620 lu_result_sent = RES_NONE;
621 dtap_expect_tx("051803");
622 ms_sends_msg("050802008168000130089910070000006402");
623 OSMO_ASSERT(dtap_tx_confirmed);
624
625 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
626 gsup_expect_tx("04010809710000004026f0");
627 ms_sends_msg("0559094332244332244372f5");
628 OSMO_ASSERT(gsup_tx_confirmed);
629 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
630
631 btw("Subscriber has the IMEISV from the ID Response");
632 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
633 OSMO_ASSERT(vsub);
634 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
635 vlr_subscr_put(vsub);
636
637 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
638 gsup_rx("10010809710000004026f00804036470f1",
639 "12010809710000004026f0");
640 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
641
642 btw("having received subscriber data does not mean acceptance");
643 EXPECT_ACCEPTED(false);
644 thwart_rx_non_initial_requests();
645 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
646
647 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
648 dtap_expect_tx("051802");
649 gsup_rx("06010809710000004026f0", NULL);
650
651 btw("We will only do business when the IMEI is known");
652 EXPECT_CONN_COUNT(1);
653 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
654 OSMO_ASSERT(vsub);
655 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
656 vlr_subscr_put(vsub);
657 EXPECT_ACCEPTED(false);
658 thwart_rx_non_initial_requests();
659
660 btw("MS replies with an Identity Response");
661 expect_bssap_clear();
662 ms_sends_msg("0559084a32244332244302");
663 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
664
665 btw("LU was successful, and the conn has already been closed");
666 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200667 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200668 EXPECT_CONN_COUNT(0);
669
670 btw("Subscriber has the IMEI");
671 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
672 OSMO_ASSERT(vsub);
673 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
674 vlr_subscr_put(vsub);
675
676 BTW("subscriber detaches");
677 expect_bssap_clear();
678 ms_sends_msg("050130089910070000006402");
679 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
680
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200681 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200682 EXPECT_CONN_COUNT(0);
683 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100684 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200685}
686
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100687static void test_no_authen_imeisv_tmsi()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200688{
689 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100690 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200691
692 rx_from_ran = RAN_GERAN_A;
693
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100694 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200695
696 net->vlr->cfg.retrieve_imeisv_early = true;
697 net->vlr->cfg.assign_tmsi = true;
698
699 btw("Location Update request causes an IMEISV ID request back to the MS");
700 lu_result_sent = RES_NONE;
701 dtap_expect_tx("051803");
702 ms_sends_msg("050802008168000130089910070000006402");
703 OSMO_ASSERT(dtap_tx_confirmed);
704
705 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
706 gsup_expect_tx("04010809710000004026f0");
707 ms_sends_msg("0559094332244332244372f5");
708 OSMO_ASSERT(gsup_tx_confirmed);
709 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
710
711 btw("Subscriber has the IMEISV from the ID Response");
712 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
713 OSMO_ASSERT(vsub);
714 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
715 vlr_subscr_put(vsub);
716
717 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
718 gsup_rx("10010809710000004026f00804036470f1",
719 "12010809710000004026f0");
720 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
721
722 btw("having received subscriber data does not mean acceptance");
723 EXPECT_ACCEPTED(false);
724 thwart_rx_non_initial_requests();
725 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
726
727 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
728 gsup_rx("06010809710000004026f0", NULL);
729
730 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
731 EXPECT_CONN_COUNT(1);
732 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
733 EXPECT_ACCEPTED(false);
734 thwart_rx_non_initial_requests();
735
736 btw("even though the TMSI is not acked, we can already find the subscr with it");
737 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
738 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
739 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
740 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
741 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
742 vlr_subscr_put(vsub);
743
744 btw("MS sends TMSI Realloc Complete");
745 expect_bssap_clear();
746 ms_sends_msg("055b");
747 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
748
749 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200750 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200751 EXPECT_CONN_COUNT(0);
752
753
754 BTW("subscriber sends LU Request, this time with the TMSI");
755 btw("Location Update request causes an IMEISV ID request back to the MS");
756 lu_result_sent = RES_NONE;
757 dtap_expect_tx("051803");
758 ms_sends_msg("050802008168000130089910070000006402");
759 OSMO_ASSERT(dtap_tx_confirmed);
760
761 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
762 gsup_expect_tx("04010809710000004026f0");
763 ms_sends_msg("0559095332244332244372f6");
764 OSMO_ASSERT(gsup_tx_confirmed);
765 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
766
767 btw("Subscriber has the IMEISV from the ID Response");
768 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
769 OSMO_ASSERT(vsub);
770 VERBOSE_ASSERT(strcmp(vsub->imeisv, "5234234234234276"), == 0, "%d");
771 vlr_subscr_put(vsub);
772
773 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
774 gsup_rx("10010809710000004026f00804036470f1",
775 "12010809710000004026f0");
776 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
777
778 btw("having received subscriber data does not mean acceptance");
779 EXPECT_ACCEPTED(false);
780 thwart_rx_non_initial_requests();
781 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
782
783 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
784 gsup_rx("06010809710000004026f0", NULL);
785
786 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
787 EXPECT_CONN_COUNT(1);
788 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
789 EXPECT_ACCEPTED(false);
790 thwart_rx_non_initial_requests();
791
792 btw("even though the TMSI is not acked, we can already find the subscr with it");
793 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
794 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
795 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
796 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
797 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
798 vlr_subscr_put(vsub);
799
800 btw("MS sends TMSI Realloc Complete");
801 expect_bssap_clear();
802 ms_sends_msg("055b");
803 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
804
805 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200806 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200807 EXPECT_CONN_COUNT(0);
808
809 btw("subscriber has the new TMSI");
810 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
811 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
812 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
813 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
814 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
815 vlr_subscr_put(vsub);
816
817 BTW("subscriber detaches, using new TMSI");
818 expect_bssap_clear();
819 ms_sends_msg("050130" "05f4" "07060504");
820 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
821
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200822 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200823 EXPECT_CONN_COUNT(0);
824 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100825 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200826}
827
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100828static void test_no_authen_imeisv_tmsi_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200829{
830 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100831 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200832
833 rx_from_ran = RAN_GERAN_A;
834
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100835 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200836
837 net->vlr->cfg.retrieve_imeisv_early = true;
838 net->vlr->cfg.assign_tmsi = true;
839 net->vlr->cfg.check_imei_rqd = true;
840
841 btw("Location Update request causes an IMEISV ID request back to the MS");
842 lu_result_sent = RES_NONE;
843 dtap_expect_tx("051803");
844 ms_sends_msg("050802008168000130089910070000006402");
845 OSMO_ASSERT(dtap_tx_confirmed);
846
847 btw("MS replies with an Identity Response, causes LU to commence with a GSUP LU request to HLR");
848 gsup_expect_tx("04010809710000004026f0");
849 ms_sends_msg("0559094332244332244372f5");
850 OSMO_ASSERT(gsup_tx_confirmed);
851 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
852
853 btw("Subscriber has the IMEISV from the ID Response");
854 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
855 OSMO_ASSERT(vsub);
856 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
857 vlr_subscr_put(vsub);
858
859 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
860 gsup_rx("10010809710000004026f00804036470f1",
861 "12010809710000004026f0");
862 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
863
864 btw("having received subscriber data does not mean acceptance");
865 EXPECT_ACCEPTED(false);
866 thwart_rx_non_initial_requests();
867 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
868
869 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
870 dtap_expect_tx("051802");
871 gsup_rx("06010809710000004026f0", NULL);
872
873 btw("We will only do business when the IMEI is known");
874 EXPECT_CONN_COUNT(1);
875 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
876 OSMO_ASSERT(vsub);
877 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
878 vlr_subscr_put(vsub);
879 EXPECT_ACCEPTED(false);
880 thwart_rx_non_initial_requests();
881
882 btw("MS replies with an Identity Response");
883 ms_sends_msg("0559084a32244332244302");
884
885 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
886 EXPECT_CONN_COUNT(1);
887 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
888 EXPECT_ACCEPTED(false);
889 thwart_rx_non_initial_requests();
890
891 btw("MS sends TMSI Realloc Complete");
892 expect_bssap_clear();
893 ms_sends_msg("055b");
894 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
895
896 btw("LU was successful, and the conn has already been closed");
897 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200898 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200899 EXPECT_CONN_COUNT(0);
900
901 btw("Subscriber has the IMEISV, IMEI and TMSI");
902 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
903 OSMO_ASSERT(vsub);
904 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
905 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
906 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
907 vlr_subscr_put(vsub);
908
909 BTW("subscriber detaches");
910 expect_bssap_clear();
911 ms_sends_msg("050130089910070000006402");
912 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
913
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200914 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200915 EXPECT_CONN_COUNT(0);
916 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100917 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200918}
919
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200920static void test_no_authen_subscr_expire()
921{
922 struct vlr_subscr *vsub;
923 const char *imsi = "901700000004620";
924
925 /* No auth only works on GERAN */
926 rx_from_ran = RAN_GERAN_A;
927
928 comment_start();
929
930 fake_time_start();
931
932 /* The test framework has already started the VLR before fake time was active.
933 * Manually schedule this timeout in fake time. */
934 osmo_timer_del(&net->vlr->lu_expire_timer);
935 osmo_timer_schedule(&net->vlr->lu_expire_timer, VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL, 0);
936
937 /* Let the LU expiration timer tick once */
938 fake_time_passes(VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL + 1, 0);
939
940 btw("Location Update request causes a GSUP LU request to HLR");
941 lu_result_sent = RES_NONE;
942 gsup_expect_tx("04010809710000004026f0");
943 ms_sends_msg("050802008168000130089910070000006402");
944 OSMO_ASSERT(gsup_tx_confirmed);
945 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
946
947 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
948 gsup_rx("10010809710000004026f00804036470f1",
949 "12010809710000004026f0");
950 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
951
952 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
953 expect_bssap_clear();
954 gsup_rx("06010809710000004026f0", NULL);
955
956 btw("LU was successful, and the conn has already been closed");
957 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
958 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
959
960 bss_sends_clear_complete();
961 EXPECT_CONN_COUNT(0);
962
963 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
964 OSMO_ASSERT(vsub);
965 vlr_subscr_put(vsub);
966
967 /* Let T3212 (periodic Location update timer) expire */
968 fake_time_passes((net->t3212 * 60 * 6 * 2) + 60*4, 0);
969
970 /* The subscriber should now be gone. */
971 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
972 OSMO_ASSERT(vsub == NULL);
973
974 EXPECT_CONN_COUNT(0);
975 clear_vlr();
976 comment_end();
977}
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200978
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100979msc_vlr_test_func_t msc_vlr_tests[] = {
980 test_no_authen,
981 test_no_authen_tmsi,
982 test_no_authen_imei,
983 test_no_authen_tmsi_imei,
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200984 test_no_authen_imeisv,
985 test_no_authen_imeisv_imei,
986 test_no_authen_imeisv_tmsi,
987 test_no_authen_imeisv_tmsi_imei,
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200988 test_no_authen_subscr_expire,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100989 NULL
990};