blob: df23011d61b2af64e8332964d2a4e6f7cf829e74 [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"
Harald Welte0df904d2018-12-03 11:00:04 +010025#include "stubs.h"
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010026
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010027static void test_no_authen()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010028{
29 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010030 const char *imsi = "901700000004620";
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020031
32 /* No auth only works on GERAN */
Neels Hofmeyr7814a832018-12-26 00:40:18 +010033 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010034
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010035 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010036
37 btw("Location Update request causes a GSUP LU request to HLR");
38 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +020039 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010040 ms_sends_msg("050802008168000130089910070000006402");
41 OSMO_ASSERT(gsup_tx_confirmed);
42 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
43
44 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
45 gsup_rx("10010809710000004026f00804036470f1",
46 "12010809710000004026f0");
47 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
48
49 btw("having received subscriber data does not mean acceptance");
50 EXPECT_ACCEPTED(false);
51
52 thwart_rx_non_initial_requests();
53
54 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
55
56 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +020057 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010058 gsup_rx("06010809710000004026f0", NULL);
59
60 btw("LU was successful, and the conn has already been closed");
61 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +020062 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +020063
64 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010065 EXPECT_CONN_COUNT(0);
66
67 BTW("after a while, a new conn sends a CM Service Request");
68 cm_service_result_sent = RES_NONE;
69 ms_sends_msg("05247803305886089910070000006402");
70 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +020071 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010072 OSMO_ASSERT(g_conn->vsub);
73 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
74 EXPECT_ACCEPTED(true);
75
Vadim Yanitskiy27605852018-06-15 23:57:30 +070076 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +010077 expect_bssap_clear(OSMO_RAT_GERAN_A);
78 conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010079
80 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +020081 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010082 EXPECT_CONN_COUNT(0);
83
84 BTW("an SMS is sent, MS is paged");
85 paging_expect_imsi(imsi);
86 paging_sent = false;
87 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
88 OSMO_ASSERT(vsub);
89 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
90
91 send_sms(vsub, vsub,
92 "Privacy in residential applications is a desirable"
93 " marketing option.");
94
95 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
96 vlr_subscr_put(vsub);
97 vsub = NULL;
98 VERBOSE_ASSERT(paging_sent, == true, "%d");
99 VERBOSE_ASSERT(paging_stopped, == false, "%d");
100
101 btw("the subscriber and its pending request should remain");
102 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
103 OSMO_ASSERT(vsub);
104 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
105 vlr_subscr_put(vsub);
106
107 btw("MS replies with Paging Response, we deliver the SMS");
108 dtap_expect_tx("09" /* SMS messages */
109 "01" /* CP-DATA */
110 "58" /* length */
111 "01" /* Network to MS */
112 "00" /* reference */
113 /* originator (gsm411_send_sms() hardcodes this weird nr) */
114 "0791" "447758100650" /* 447785016005 */
115 "00" /* dest */
116 /* SMS TPDU */
117 "4c" /* len */
118 "00" /* SMS deliver */
119 "05806470f1" /* originating address 46071 */
120 "00" /* TP-PID */
121 "00" /* GSM default alphabet */
122 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
123 "000000" /* H-M-S */
124 "00" /* GMT+0 */
125 "44" /* data length */
126 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
127 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
128 "0c7ac3e9e9b7db05");
129 ms_sends_msg("06270703305882089910070000006402");
130 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
131 VERBOSE_ASSERT(paging_stopped, == true, "%d");
132
133 btw("SMS was delivered, no requests pending for subscr");
134 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
135 OSMO_ASSERT(vsub);
136 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
137 vlr_subscr_put(vsub);
138
139 btw("conn is still open to wait for SMS ack dance");
140 EXPECT_CONN_COUNT(1);
141
142 btw("MS replies with CP-ACK for received SMS");
143 ms_sends_msg("8904");
144 EXPECT_CONN_COUNT(1);
145
146 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
147 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200148 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100149 ms_sends_msg("890106020041020000");
150 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200151 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100152
153 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200154 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100155 EXPECT_CONN_COUNT(0);
156
157 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200158 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100159 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200160 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100161
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200162 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100163 EXPECT_CONN_COUNT(0);
164 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100165 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100166}
167
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100168static void test_no_authen_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100169{
170 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100171 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100172
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100173 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200174
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100175 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100176
177 net->vlr->cfg.assign_tmsi = true;
178
179 btw("Location Update request causes a GSUP LU request to HLR");
180 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200181 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100182 ms_sends_msg("050802008168000130089910070000006402");
183 OSMO_ASSERT(gsup_tx_confirmed);
184 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
185
186 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
187 gsup_rx("10010809710000004026f00804036470f1",
188 "12010809710000004026f0");
189 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
190
191 btw("having received subscriber data does not mean acceptance");
192 EXPECT_ACCEPTED(false);
193 thwart_rx_non_initial_requests();
194 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
195
196 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
197 gsup_rx("06010809710000004026f0", NULL);
198
199 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
200 EXPECT_CONN_COUNT(1);
201 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
202 EXPECT_ACCEPTED(false);
203 thwart_rx_non_initial_requests();
204
205 btw("even though the TMSI is not acked, we can already find the subscr with it");
206 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
207 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
208 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
209 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
210 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
211 vlr_subscr_put(vsub);
212
213 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200214 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100215 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200216 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100217
218 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200219 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100220 EXPECT_CONN_COUNT(0);
221
222 btw("Subscriber has the new TMSI");
223 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
224 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
225 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
226 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
227 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
228 vlr_subscr_put(vsub);
229
230 BTW("after a while, a new conn sends a CM Service Request using above TMSI");
231 cm_service_result_sent = RES_NONE;
232 ms_sends_msg("05247803305886" "05f4" "03020100");
233 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200234 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100235 OSMO_ASSERT(g_conn->vsub);
236 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
237 EXPECT_ACCEPTED(true);
238
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700239 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100240 expect_bssap_clear(OSMO_RAT_GERAN_A);
241 conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100242
243 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200244 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100245 EXPECT_CONN_COUNT(0);
246
247 BTW("an SMS is sent, MS is paged using above TMSI");
248 paging_expect_tmsi(0x03020100);
249 paging_sent = false;
250 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
251 OSMO_ASSERT(vsub);
252 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
253
254 send_sms(vsub, vsub,
255 "Privacy in residential applications is a desirable"
256 " marketing option.");
257
258 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
259 vlr_subscr_put(vsub);
260 vsub = NULL;
261 VERBOSE_ASSERT(paging_sent, == true, "%d");
262 VERBOSE_ASSERT(paging_stopped, == false, "%d");
263
264 btw("the subscriber and its pending request should remain");
265 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
266 OSMO_ASSERT(vsub);
267 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
268 vlr_subscr_put(vsub);
269
270 btw("MS replies with Paging Response using TMSI, we deliver the SMS");
271 dtap_expect_tx("09" /* SMS messages */
272 "01" /* CP-DATA */
273 "58" /* length */
274 "01" /* Network to MS */
275 "00" /* reference */
276 /* originator (gsm411_send_sms() hardcodes this weird nr) */
277 "0791" "447758100650" /* 447785016005 */
278 "00" /* dest */
279 /* SMS TPDU */
280 "4c" /* len */
281 "00" /* SMS deliver */
282 "05806470f1" /* originating address 46071 */
283 "00" /* TP-PID */
284 "00" /* GSM default alphabet */
285 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
286 "000000" /* H-M-S */
287 "00" /* GMT+0 */
288 "44" /* data length */
289 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
290 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
291 "0c7ac3e9e9b7db05");
292 ms_sends_msg("06270703305882" "05f4" "03020100");
293 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
294 VERBOSE_ASSERT(paging_stopped, == true, "%d");
295
296 btw("SMS was delivered, no requests pending for subscr");
297 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
298 OSMO_ASSERT(vsub);
299 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
300 vlr_subscr_put(vsub);
301
302 btw("conn is still open to wait for SMS ack dance");
303 EXPECT_CONN_COUNT(1);
304
305 btw("MS replies with CP-ACK for received SMS");
306 ms_sends_msg("8904");
307 EXPECT_CONN_COUNT(1);
308
309 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
310 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200311 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100312 ms_sends_msg("890106020041020000");
313 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200314 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100315
316 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200317 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100318 EXPECT_CONN_COUNT(0);
319
320 /* TODO: when the subscriber detaches, the vlr_subscr gets
321 * deallocated and we no longer know the TMSI. This case is covered by
322 * test_lu_unknown_tmsi(), so here I'd like to still have the TMSI.
323 BTW("subscriber detaches, using TMSI");
324 ms_sends_msg("050130" "05f4" "03020100");
325 EXPECT_CONN_COUNT(0);
326 */
327
328 BTW("subscriber sends LU Request, this time with the TMSI");
329 btw("Location Update request causes a GSUP LU request to HLR");
330 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200331 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100332 ms_sends_msg("050802008168000130" "05f4" "03020100");
333 OSMO_ASSERT(gsup_tx_confirmed);
334 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
335
336 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
337 gsup_rx("10010809710000004026f00804036470f1",
338 "12010809710000004026f0");
339 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
340
341 btw("having received subscriber data does not mean acceptance");
342 EXPECT_ACCEPTED(false);
343 thwart_rx_non_initial_requests();
344 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
345
346 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
347 gsup_rx("06010809710000004026f0", NULL);
348
349 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
350 EXPECT_CONN_COUNT(1);
351 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
352 EXPECT_ACCEPTED(false);
353 thwart_rx_non_initial_requests();
354
355 btw("even though the TMSI is not acked, we can already find the subscr with it");
356 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
357 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
358 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
359 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
360 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
361 vlr_subscr_put(vsub);
362
363 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200364 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100365 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200366 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100367
368 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200369 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100370 EXPECT_CONN_COUNT(0);
371
372 btw("subscriber has the new TMSI");
373 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
374 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
375 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
376 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
377 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
378 vlr_subscr_put(vsub);
379
380 BTW("subscriber detaches, using new TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200381 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100382 ms_sends_msg("050130" "05f4" "07060504");
Philipp Maierfbf66102017-04-09 12:32:51 +0200383 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100384
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200385 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100386 EXPECT_CONN_COUNT(0);
387 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100388 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100389}
390
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100391static void test_no_authen_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100392{
393 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100394 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100395
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100396 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200397
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100398 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100399
400 net->vlr->cfg.check_imei_rqd = true;
401
402 btw("Location Update request causes a GSUP LU request to HLR");
403 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200404 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100405 ms_sends_msg("050802008168000130089910070000006402");
406 OSMO_ASSERT(gsup_tx_confirmed);
407 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
408
409 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
410 gsup_rx("10010809710000004026f00804036470f1",
411 "12010809710000004026f0");
412 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
413
414 btw("having received subscriber data does not mean acceptance");
415 EXPECT_ACCEPTED(false);
416 thwart_rx_non_initial_requests();
417 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
418
419 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
420 dtap_expect_tx("051802");
421 gsup_rx("06010809710000004026f0", NULL);
422
423 btw("We will only do business when the IMEI is known");
424 EXPECT_CONN_COUNT(1);
425 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
426 OSMO_ASSERT(vsub);
427 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
428 vlr_subscr_put(vsub);
429 EXPECT_ACCEPTED(false);
430 thwart_rx_non_initial_requests();
431
Oliver Smith7d053092018-12-14 17:37:38 +0100432 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
433 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200434 /* 3GPP TS 23.003: 6.2.1 Composition of IMEI: the IMEI ends with a
435 * spare digit that shall be sent as zero by the MS. */
436 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100437
438 btw("HLR accepts the IMEI");
439 expect_bssap_clear();
440 gsup_rx("32010809710000004026f0510100", NULL);
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 Hofmeyr7814a832018-12-26 00:40:18 +0100470 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200471
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;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200479 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100480 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
Oliver Smith7d053092018-12-14 17:37:38 +0100507 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
508 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200509 ms_sends_msg("0559084a32244332244302");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100510
Oliver Smith7d053092018-12-14 17:37:38 +0100511 btw("HLR accepts the IMEI");
512 gsup_rx("32010809710000004026f0510100", NULL);
513
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100514 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
515 EXPECT_CONN_COUNT(1);
516 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
517 EXPECT_ACCEPTED(false);
518 thwart_rx_non_initial_requests();
519
520 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200521 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100522 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200523 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100524
525 btw("LU was successful, and the conn has already been closed");
526 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200527 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100528 EXPECT_CONN_COUNT(0);
529
530 btw("Subscriber has the IMEI and TMSI");
531 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
532 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200533 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100534 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
535 vlr_subscr_put(vsub);
536
537 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200538 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100539 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200540 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100541
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200542 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100543 EXPECT_CONN_COUNT(0);
544 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100545 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100546}
547
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100548static void test_no_authen_imeisv()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200549{
550 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100551 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200552
553 /* No auth only works on GERAN */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100554 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200555
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100556 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200557
558 net->vlr->cfg.retrieve_imeisv_early = true;
559
560 btw("Location Update request causes an IMEISV ID request back to the MS");
561 lu_result_sent = RES_NONE;
562 dtap_expect_tx("051803");
563 ms_sends_msg("050802008168000130089910070000006402");
564 OSMO_ASSERT(dtap_tx_confirmed);
565
566 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 +0200567 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200568 ms_sends_msg("0559094332244332244372f5");
569 OSMO_ASSERT(gsup_tx_confirmed);
570 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
571
572 btw("Subscriber has the IMEISV from the ID Response");
573 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
574 OSMO_ASSERT(vsub);
575 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
576 vlr_subscr_put(vsub);
577
578 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
579 gsup_rx("10010809710000004026f00804036470f1",
580 "12010809710000004026f0");
581 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
582
583 btw("having received subscriber data does not mean acceptance");
584 EXPECT_ACCEPTED(false);
585
586 thwart_rx_non_initial_requests();
587
588 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
589
590 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
591 expect_bssap_clear();
592 gsup_rx("06010809710000004026f0", NULL);
593
594 btw("LU was successful, and the conn has already been closed");
595 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
596 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200597 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200598 EXPECT_CONN_COUNT(0);
599
600 BTW("subscriber detaches");
601 expect_bssap_clear();
602 ms_sends_msg("050130089910070000006402");
603 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
604
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200605 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200606 EXPECT_CONN_COUNT(0);
607 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100608 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200609}
610
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100611static void test_no_authen_imeisv_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200612{
613 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100614 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200615
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100616 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200617
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100618 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200619
620 net->vlr->cfg.retrieve_imeisv_early = true;
621 net->vlr->cfg.check_imei_rqd = true;
622
623 btw("Location Update request causes an IMEISV ID request back to the MS");
624 lu_result_sent = RES_NONE;
625 dtap_expect_tx("051803");
626 ms_sends_msg("050802008168000130089910070000006402");
627 OSMO_ASSERT(dtap_tx_confirmed);
628
629 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 +0200630 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200631 ms_sends_msg("0559094332244332244372f5");
632 OSMO_ASSERT(gsup_tx_confirmed);
633 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
634
635 btw("Subscriber has the IMEISV from the ID Response");
636 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
637 OSMO_ASSERT(vsub);
638 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
639 vlr_subscr_put(vsub);
640
641 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
642 gsup_rx("10010809710000004026f00804036470f1",
643 "12010809710000004026f0");
644 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
645
646 btw("having received subscriber data does not mean acceptance");
647 EXPECT_ACCEPTED(false);
648 thwart_rx_non_initial_requests();
649 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
650
651 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
652 dtap_expect_tx("051802");
653 gsup_rx("06010809710000004026f0", NULL);
654
655 btw("We will only do business when the IMEI is known");
656 EXPECT_CONN_COUNT(1);
657 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
658 OSMO_ASSERT(vsub);
659 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
660 vlr_subscr_put(vsub);
661 EXPECT_ACCEPTED(false);
662 thwart_rx_non_initial_requests();
663
Oliver Smith7d053092018-12-14 17:37:38 +0100664 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
665 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200666 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100667
668 btw("HLR accepts the IMEI");
669 expect_bssap_clear();
670 gsup_rx("32010809710000004026f0510100", NULL);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200671 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
672
673 btw("LU was successful, and the conn has already been closed");
674 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200675 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200676 EXPECT_CONN_COUNT(0);
677
678 btw("Subscriber has the IMEI");
679 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
680 OSMO_ASSERT(vsub);
681 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
682 vlr_subscr_put(vsub);
683
684 BTW("subscriber detaches");
685 expect_bssap_clear();
686 ms_sends_msg("050130089910070000006402");
687 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
688
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200689 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200690 EXPECT_CONN_COUNT(0);
691 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100692 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200693}
694
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100695static void test_no_authen_imeisv_tmsi()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200696{
697 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100698 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200699
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100700 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200701
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100702 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200703
704 net->vlr->cfg.retrieve_imeisv_early = true;
705 net->vlr->cfg.assign_tmsi = true;
706
707 btw("Location Update request causes an IMEISV ID request back to the MS");
708 lu_result_sent = RES_NONE;
709 dtap_expect_tx("051803");
710 ms_sends_msg("050802008168000130089910070000006402");
711 OSMO_ASSERT(dtap_tx_confirmed);
712
713 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 +0200714 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200715 ms_sends_msg("0559094332244332244372f5");
716 OSMO_ASSERT(gsup_tx_confirmed);
717 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
718
719 btw("Subscriber has the IMEISV from the ID Response");
720 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
721 OSMO_ASSERT(vsub);
722 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
723 vlr_subscr_put(vsub);
724
725 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
726 gsup_rx("10010809710000004026f00804036470f1",
727 "12010809710000004026f0");
728 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
729
730 btw("having received subscriber data does not mean acceptance");
731 EXPECT_ACCEPTED(false);
732 thwart_rx_non_initial_requests();
733 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
734
735 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
736 gsup_rx("06010809710000004026f0", NULL);
737
738 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
739 EXPECT_CONN_COUNT(1);
740 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
741 EXPECT_ACCEPTED(false);
742 thwart_rx_non_initial_requests();
743
744 btw("even though the TMSI is not acked, we can already find the subscr with it");
745 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
746 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
747 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
748 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
749 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
750 vlr_subscr_put(vsub);
751
752 btw("MS sends TMSI Realloc Complete");
753 expect_bssap_clear();
754 ms_sends_msg("055b");
755 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
756
757 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200758 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200759 EXPECT_CONN_COUNT(0);
760
761
762 BTW("subscriber sends LU Request, this time with the TMSI");
763 btw("Location Update request causes an IMEISV ID request back to the MS");
764 lu_result_sent = RES_NONE;
765 dtap_expect_tx("051803");
766 ms_sends_msg("050802008168000130089910070000006402");
767 OSMO_ASSERT(dtap_tx_confirmed);
768
769 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 +0200770 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200771 ms_sends_msg("0559095332244332244372f6");
772 OSMO_ASSERT(gsup_tx_confirmed);
773 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
774
775 btw("Subscriber has the IMEISV from the ID Response");
776 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
777 OSMO_ASSERT(vsub);
778 VERBOSE_ASSERT(strcmp(vsub->imeisv, "5234234234234276"), == 0, "%d");
779 vlr_subscr_put(vsub);
780
781 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
782 gsup_rx("10010809710000004026f00804036470f1",
783 "12010809710000004026f0");
784 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
785
786 btw("having received subscriber data does not mean acceptance");
787 EXPECT_ACCEPTED(false);
788 thwart_rx_non_initial_requests();
789 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
790
791 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
792 gsup_rx("06010809710000004026f0", NULL);
793
794 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
795 EXPECT_CONN_COUNT(1);
796 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
797 EXPECT_ACCEPTED(false);
798 thwart_rx_non_initial_requests();
799
800 btw("even though the TMSI is not acked, we can already find the subscr with it");
801 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
802 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
803 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
804 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
805 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
806 vlr_subscr_put(vsub);
807
808 btw("MS sends TMSI Realloc Complete");
809 expect_bssap_clear();
810 ms_sends_msg("055b");
811 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
812
813 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200814 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200815 EXPECT_CONN_COUNT(0);
816
817 btw("subscriber has the new TMSI");
818 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504);
819 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
820 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
821 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
822 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
823 vlr_subscr_put(vsub);
824
825 BTW("subscriber detaches, using new TMSI");
826 expect_bssap_clear();
827 ms_sends_msg("050130" "05f4" "07060504");
828 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
829
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200830 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200831 EXPECT_CONN_COUNT(0);
832 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100833 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200834}
835
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100836static void test_no_authen_imeisv_tmsi_imei()
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200837{
838 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100839 const char *imsi = "901700000004620";
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200840
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100841 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200842
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100843 comment_start();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200844
845 net->vlr->cfg.retrieve_imeisv_early = true;
846 net->vlr->cfg.assign_tmsi = true;
847 net->vlr->cfg.check_imei_rqd = true;
848
849 btw("Location Update request causes an IMEISV ID request back to the MS");
850 lu_result_sent = RES_NONE;
851 dtap_expect_tx("051803");
852 ms_sends_msg("050802008168000130089910070000006402");
853 OSMO_ASSERT(dtap_tx_confirmed);
854
855 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 +0200856 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200857 ms_sends_msg("0559094332244332244372f5");
858 OSMO_ASSERT(gsup_tx_confirmed);
859 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
860
861 btw("Subscriber has the IMEISV from the ID Response");
862 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
863 OSMO_ASSERT(vsub);
864 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
865 vlr_subscr_put(vsub);
866
867 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
868 gsup_rx("10010809710000004026f00804036470f1",
869 "12010809710000004026f0");
870 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
871
872 btw("having received subscriber data does not mean acceptance");
873 EXPECT_ACCEPTED(false);
874 thwart_rx_non_initial_requests();
875 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
876
877 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
878 dtap_expect_tx("051802");
879 gsup_rx("06010809710000004026f0", NULL);
880
881 btw("We will only do business when the IMEI is known");
882 EXPECT_CONN_COUNT(1);
883 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
884 OSMO_ASSERT(vsub);
885 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
886 vlr_subscr_put(vsub);
887 EXPECT_ACCEPTED(false);
888 thwart_rx_non_initial_requests();
889
Oliver Smith7d053092018-12-14 17:37:38 +0100890 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
891 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200892 ms_sends_msg("0559084a32244332244302");
893
Oliver Smith7d053092018-12-14 17:37:38 +0100894 btw("HLR accepts the IMEI");
895 gsup_rx("32010809710000004026f0510100", NULL);
896
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200897 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
898 EXPECT_CONN_COUNT(1);
899 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
900 EXPECT_ACCEPTED(false);
901 thwart_rx_non_initial_requests();
902
903 btw("MS sends TMSI Realloc Complete");
904 expect_bssap_clear();
905 ms_sends_msg("055b");
906 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
907
908 btw("LU was successful, and the conn has already been closed");
909 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200910 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200911 EXPECT_CONN_COUNT(0);
912
913 btw("Subscriber has the IMEISV, IMEI and TMSI");
914 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
915 OSMO_ASSERT(vsub);
916 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
917 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
918 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
919 vlr_subscr_put(vsub);
920
921 BTW("subscriber detaches");
922 expect_bssap_clear();
923 ms_sends_msg("050130089910070000006402");
924 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
925
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200926 bss_sends_clear_complete();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200927 EXPECT_CONN_COUNT(0);
928 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100929 comment_end();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200930}
931
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200932static void test_no_authen_subscr_expire()
933{
934 struct vlr_subscr *vsub;
935 const char *imsi = "901700000004620";
936
937 /* No auth only works on GERAN */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100938 rx_from_ran = OSMO_RAT_GERAN_A;
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200939
940 comment_start();
941
942 fake_time_start();
943
944 /* The test framework has already started the VLR before fake time was active.
945 * Manually schedule this timeout in fake time. */
946 osmo_timer_del(&net->vlr->lu_expire_timer);
947 osmo_timer_schedule(&net->vlr->lu_expire_timer, VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL, 0);
948
949 /* Let the LU expiration timer tick once */
950 fake_time_passes(VLR_SUBSCRIBER_LU_EXPIRATION_INTERVAL + 1, 0);
951
952 btw("Location Update request causes a GSUP LU request to HLR");
953 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200954 gsup_expect_tx("04010809710000004026f0280102");
Stefan Sperlingdefc3c82018-05-15 14:48:04 +0200955 ms_sends_msg("050802008168000130089910070000006402");
956 OSMO_ASSERT(gsup_tx_confirmed);
957 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
958
959 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
960 gsup_rx("10010809710000004026f00804036470f1",
961 "12010809710000004026f0");
962 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
963
964 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
965 expect_bssap_clear();
966 gsup_rx("06010809710000004026f0", NULL);
967
968 btw("LU was successful, and the conn has already been closed");
969 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
970 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
971
972 bss_sends_clear_complete();
973 EXPECT_CONN_COUNT(0);
974
975 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
976 OSMO_ASSERT(vsub);
977 vlr_subscr_put(vsub);
978
979 /* Let T3212 (periodic Location update timer) expire */
980 fake_time_passes((net->t3212 * 60 * 6 * 2) + 60*4, 0);
981
982 /* The subscriber should now be gone. */
983 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
984 OSMO_ASSERT(vsub == NULL);
985
986 EXPECT_CONN_COUNT(0);
987 clear_vlr();
988 comment_end();
989}
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200990
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100991msc_vlr_test_func_t msc_vlr_tests[] = {
992 test_no_authen,
993 test_no_authen_tmsi,
994 test_no_authen_imei,
995 test_no_authen_tmsi_imei,
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200996 test_no_authen_imeisv,
997 test_no_authen_imeisv_imei,
998 test_no_authen_imeisv_tmsi,
999 test_no_authen_imeisv_tmsi_imei,
Stefan Sperlingdefc3c82018-05-15 14:48:04 +02001000 test_no_authen_subscr_expire,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001001 NULL
1002};