blob: b09bcee2589e76ccf3a5e38167c4723dabca0f5b [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_ms_timeout_lu_auth_resp()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010028 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010029
30 net->authentication_required = true;
31
32 fake_time_start();
33
34 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
35 lu_result_sent = RES_NONE;
36 gsup_expect_tx("08010809710000004026f0");
37 ms_sends_msg("050802008168000130089910070000006402");
38 OSMO_ASSERT(gsup_tx_confirmed);
39 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
40
41 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
42 auth_request_sent = false;
43 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
44 auth_request_expect_autn = NULL;
45 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
46 gsup_rx("0a"
47 /* imsi */
48 "0108" "09710000004026f0"
49 /* auth vectors... */
50 /* TL TL rand */
51 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
52 /* TL sres TL kc */
53 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
54 ,NULL);
55 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
56 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
57
58 BTW("MS fails to send an Authentication Response");
59
60 btw("At first, we're still waiting");
61 fake_time_passes(0, 423);
62 EXPECT_CONN_COUNT(1);
63 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
64 fake_time_passes(1, 235);
65 EXPECT_CONN_COUNT(1);
66 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
67 fake_time_passes(1, 235);
68 EXPECT_CONN_COUNT(1);
69 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
70 fake_time_passes(1, 235);
71 EXPECT_CONN_COUNT(1);
72 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
73 fake_time_passes(1, 235);
74 EXPECT_CONN_COUNT(1);
75 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +020076 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010077 fake_time_passes(1, 235);
Neels Hofmeyrc036b792018-11-29 22:37:51 +010078 btw("RAN_CONN_TIMEOUT has passed, conn is gone.");
Philipp Maierfbf66102017-04-09 12:32:51 +020079 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
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 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
83
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010084 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010085}
86
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010087static void test_ms_timeout_cm_auth_resp()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010088{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010089 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010090
91 net->authentication_required = true;
92
93 fake_time_start();
94
95 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
96 lu_result_sent = RES_NONE;
97 gsup_expect_tx("08010809710000004026f0");
98 ms_sends_msg("050802008168000130089910070000006402");
99 OSMO_ASSERT(gsup_tx_confirmed);
100 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
101
102 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
103 auth_request_sent = false;
104 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
105 auth_request_expect_autn = NULL;
106 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
107 gsup_rx("0a"
108 /* imsi */
109 "0108" "09710000004026f0"
110 /* 5 auth vectors... */
111 /* TL TL rand */
112 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
113 /* TL sres TL kc */
114 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
115 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
116 "2104" "20bde240" "2208" "07fa7502e07e1c00"
117 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
118 "2104" "a29514ae" "2208" "e2b234f807886400"
119 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
120 "2104" "5afc8d72" "2208" "2392f14f709ae000"
121 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
122 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
123 NULL);
124 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
125 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
126
127 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200128 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100129 ms_sends_msg("05542d8b2c3e");
130 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
131
132 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
133 gsup_rx("10010809710000004026f00804036470f1",
134 "12010809710000004026f0");
135 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
136
137 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200138 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100139 gsup_rx("06010809710000004026f0", NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200140 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100141
142 btw("LU was successful, and the conn has already been closed");
143 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200144 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100145 EXPECT_CONN_COUNT(0);
146
147 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
148 auth_request_sent = false;
149 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
150 cm_service_result_sent = RES_NONE;
151 ms_sends_msg("05247803305886089910070000006402");
152 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200153 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100154 OSMO_ASSERT(g_conn->vsub);
155 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
156 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
157
158 BTW("MS fails to send an Authentication Response");
159
160 btw("At first, we're still waiting");
161 fake_time_passes(0, 423);
162 EXPECT_CONN_COUNT(1);
163 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
164 fake_time_passes(1, 235);
165 EXPECT_CONN_COUNT(1);
166 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
167 fake_time_passes(1, 235);
168 EXPECT_CONN_COUNT(1);
169 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
170 fake_time_passes(1, 235);
171 EXPECT_CONN_COUNT(1);
172 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
173 fake_time_passes(1, 235);
174 EXPECT_CONN_COUNT(1);
175 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200176 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100177 fake_time_passes(1, 235);
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100178 btw("RAN_CONN_TIMEOUT has passed, conn is gone.");
Philipp Maierfbf66102017-04-09 12:32:51 +0200179 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200180 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100181 EXPECT_CONN_COUNT(0);
182 VERBOSE_ASSERT(cm_service_result_sent, == RES_REJECT, "%d");
183
184 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100185 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100186}
187
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100188static void test_ms_timeout_paging()
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100189{
190 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100191 const char *imsi = "901700000004620";
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100192
193 rx_from_ran = RAN_GERAN_A;
194
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100195 comment_start();
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100196
197 fake_time_start();
198
199 btw("Location Update request causes a GSUP LU request to HLR");
200 lu_result_sent = RES_NONE;
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200201 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100202 ms_sends_msg("050802008168000130089910070000006402");
203 OSMO_ASSERT(gsup_tx_confirmed);
204 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
205
206 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
207 gsup_rx("10010809710000004026f00804036470f1",
208 "12010809710000004026f0");
209 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
210
211 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
212 expect_bssap_clear();
213 gsup_rx("06010809710000004026f0", NULL);
214
215 btw("LU was successful, and the conn has already been closed");
216 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
217 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200218 bss_sends_clear_complete();
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100219 EXPECT_CONN_COUNT(0);
220
221 BTW("an SMS is sent, MS is paged");
222 paging_expect_imsi(imsi);
223 paging_sent = false;
224 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
225 OSMO_ASSERT(vsub);
226 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
227
228 send_sms(vsub, vsub,
229 "Privacy in residential applications is a desirable"
230 " marketing option.");
231
232 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
233 vlr_subscr_put(vsub);
234 vsub = NULL;
235 VERBOSE_ASSERT(paging_sent, == true, "%d");
236 VERBOSE_ASSERT(paging_stopped, == false, "%d");
237
238 btw("time passes and no paging result is received");
239
240 fake_time_passes(MSC_PAGING_RESPONSE_TIMER_DEFAULT - 1, 0);
241
242 btw("the paging timeout has not yet expired");
243 VERBOSE_ASSERT(paging_stopped, == false, "%d");
244 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
245 OSMO_ASSERT(vsub);
246 VERBOSE_ASSERT(vsub->cs.is_paging, == true, "%d");
247 btw("another request is added to the list but does not cause another paging");
248 paging_sent = false;
249 paging_expect_imsi(NULL);
250 send_sms(vsub, vsub,
251 "One paging ought to be enough for anyone.");
252 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 2, "%d");
253 vlr_subscr_put(vsub);
254 vsub = NULL;
255 VERBOSE_ASSERT(paging_sent, == false, "%d");
256
257 btw("the paging timeout expires, the paging as well as the requests are canceled");
258 fake_time_passes(2, 0);
259 VERBOSE_ASSERT(paging_stopped, == true, "%d");
260
261 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
262 OSMO_ASSERT(vsub);
263 VERBOSE_ASSERT(vsub->cs.is_paging, == false, "%d");
264 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100265
266 BTW("Now that the timeout has expired, another Paging is sent on request");
267 paging_expect_imsi(imsi);
268 paging_sent = false;
269
270 send_sms(vsub, vsub,
271 "Privacy in residential applications is a desirable"
272 " marketing option.");
273
274 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100275 vlr_subscr_put(vsub);
276 vsub = NULL;
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100277 VERBOSE_ASSERT(paging_sent, == true, "%d");
278 VERBOSE_ASSERT(paging_stopped, == false, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100279
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100280 BTW("subscriber detaches, pagings are canceled");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100281 expect_bssap_clear();
282 ms_sends_msg("050130089910070000006402");
283 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100284 VERBOSE_ASSERT(paging_stopped, == true, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100285
286 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
287 OSMO_ASSERT(!vsub);
288
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200289 bss_sends_clear_complete();
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100290 EXPECT_CONN_COUNT(0);
291 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100292 comment_end();
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100293}
294
Neels Hofmeyr3117b702018-09-13 03:23:07 +0200295static void test_classmark_update_timeout()
296{
297 comment_start();
298
299 fake_time_start();
300
301 /* implicit: net->authentication_required = true; */
302 net->a5_encryption_mask = (1 << 3); /* A5/3 */
303
304 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
305 lu_result_sent = RES_NONE;
306 gsup_expect_tx("08010809710000004026f0");
307 ms_sends_msg("050802008168000130089910070000006402");
308 OSMO_ASSERT(gsup_tx_confirmed);
309 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
310
311 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
312 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
313 auth_request_sent = false;
314 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
315 auth_request_expect_autn = NULL;
316 gsup_rx("0a"
317 /* imsi */
318 "0108" "09710000004026f0"
319 /* TL TL rand */
320 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
321 /* TL sres TL kc */
322 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
323 ,
324 NULL);
325 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
326 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
327
328 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
329 " -- but needs Classmark 2 to determine whether A5/3 is supported");
330 cipher_mode_cmd_sent = false;
331 ms_sends_msg("05542d8b2c3e");
332 OSMO_ASSERT(!cipher_mode_cmd_sent);
333 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
334
335 BTW("But the BSSMAP Classmark Update never arrives");
336 btw("At first, we're still waiting");
337 fake_time_passes(0, 423);
338 EXPECT_CONN_COUNT(1);
339 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
340 fake_time_passes(1, 235);
341 EXPECT_CONN_COUNT(1);
342 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
343 fake_time_passes(1, 235);
344 EXPECT_CONN_COUNT(1);
345 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
346 fake_time_passes(1, 235);
347 EXPECT_CONN_COUNT(1);
348 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
349 fake_time_passes(1, 235);
350 EXPECT_CONN_COUNT(1);
351 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
352 expect_bssap_clear();
353 fake_time_passes(1, 235);
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100354 btw("RAN_CONN_TIMEOUT has passed, conn is gone.");
Neels Hofmeyr3117b702018-09-13 03:23:07 +0200355 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
356 bss_sends_clear_complete();
357 EXPECT_CONN_COUNT(0);
358 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
359
360 comment_end();
361}
362
363
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100364msc_vlr_test_func_t msc_vlr_tests[] = {
365 test_ms_timeout_lu_auth_resp,
366 test_ms_timeout_cm_auth_resp,
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100367 test_ms_timeout_paging,
Neels Hofmeyr3117b702018-09-13 03:23:07 +0200368 test_classmark_update_timeout,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100369 NULL
370};