blob: 569bbf5473d4dd5af3d3ec1f91d0c4181b00b6c8 [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
Maxb0a43142018-02-06 19:19:52 +010026void test_ms_timeout_lu_auth_resp(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
Maxb0a43142018-02-06 19:19:52 +010028 comment_start(nr, imsi);
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);
78 btw("SUBSCR_CONN_TIMEOUT has passed, conn is gone.");
Philipp Maierfbf66102017-04-09 12:32:51 +020079 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010080 EXPECT_CONN_COUNT(0);
81 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
82
Maxb0a43142018-02-06 19:19:52 +010083 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010084}
85
Maxb0a43142018-02-06 19:19:52 +010086void test_ms_timeout_cm_auth_resp(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010087{
Maxb0a43142018-02-06 19:19:52 +010088 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010089
90 net->authentication_required = true;
91
92 fake_time_start();
93
94 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
95 lu_result_sent = RES_NONE;
96 gsup_expect_tx("08010809710000004026f0");
97 ms_sends_msg("050802008168000130089910070000006402");
98 OSMO_ASSERT(gsup_tx_confirmed);
99 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
100
101 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
102 auth_request_sent = false;
103 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
104 auth_request_expect_autn = NULL;
105 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
106 gsup_rx("0a"
107 /* imsi */
108 "0108" "09710000004026f0"
109 /* 5 auth vectors... */
110 /* TL TL rand */
111 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
112 /* TL sres TL kc */
113 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
114 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
115 "2104" "20bde240" "2208" "07fa7502e07e1c00"
116 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
117 "2104" "a29514ae" "2208" "e2b234f807886400"
118 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
119 "2104" "5afc8d72" "2208" "2392f14f709ae000"
120 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
121 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
122 NULL);
123 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
124 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
125
126 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
127 gsup_expect_tx("04010809710000004026f0");
128 ms_sends_msg("05542d8b2c3e");
129 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
130
131 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
132 gsup_rx("10010809710000004026f00804036470f1",
133 "12010809710000004026f0");
134 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
135
136 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200137 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100138 gsup_rx("06010809710000004026f0", NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200139 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100140
141 btw("LU was successful, and the conn has already been closed");
142 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
143 EXPECT_CONN_COUNT(0);
144
145 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
146 auth_request_sent = false;
147 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
148 cm_service_result_sent = RES_NONE;
149 ms_sends_msg("05247803305886089910070000006402");
150 OSMO_ASSERT(g_conn);
151 OSMO_ASSERT(g_conn->conn_fsm);
152 OSMO_ASSERT(g_conn->vsub);
153 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
154 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
155
156 BTW("MS fails to send an Authentication Response");
157
158 btw("At first, we're still waiting");
159 fake_time_passes(0, 423);
160 EXPECT_CONN_COUNT(1);
161 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
162 fake_time_passes(1, 235);
163 EXPECT_CONN_COUNT(1);
164 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
165 fake_time_passes(1, 235);
166 EXPECT_CONN_COUNT(1);
167 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
168 fake_time_passes(1, 235);
169 EXPECT_CONN_COUNT(1);
170 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
171 fake_time_passes(1, 235);
172 EXPECT_CONN_COUNT(1);
173 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200174 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100175 fake_time_passes(1, 235);
176 btw("SUBSCR_CONN_TIMEOUT has passed, conn is gone.");
Philipp Maierfbf66102017-04-09 12:32:51 +0200177 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100178 EXPECT_CONN_COUNT(0);
179 VERBOSE_ASSERT(cm_service_result_sent, == RES_REJECT, "%d");
180
181 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100182 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100183}
184
Maxb0a43142018-02-06 19:19:52 +0100185void test_ms_timeout_paging(uint8_t nr, const char *imsi)
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100186{
187 struct vlr_subscr *vsub;
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100188
189 rx_from_ran = RAN_GERAN_A;
190
Maxb0a43142018-02-06 19:19:52 +0100191 comment_start(nr, imsi);
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100192
193 fake_time_start();
194
195 btw("Location Update request causes a GSUP LU request to HLR");
196 lu_result_sent = RES_NONE;
197 gsup_expect_tx("04010809710000004026f0");
198 ms_sends_msg("050802008168000130089910070000006402");
199 OSMO_ASSERT(gsup_tx_confirmed);
200 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
201
202 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
203 gsup_rx("10010809710000004026f00804036470f1",
204 "12010809710000004026f0");
205 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
206
207 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
208 expect_bssap_clear();
209 gsup_rx("06010809710000004026f0", NULL);
210
211 btw("LU was successful, and the conn has already been closed");
212 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
213 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
214 EXPECT_CONN_COUNT(0);
215
216 BTW("an SMS is sent, MS is paged");
217 paging_expect_imsi(imsi);
218 paging_sent = false;
219 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
220 OSMO_ASSERT(vsub);
221 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
222
223 send_sms(vsub, vsub,
224 "Privacy in residential applications is a desirable"
225 " marketing option.");
226
227 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
228 vlr_subscr_put(vsub);
229 vsub = NULL;
230 VERBOSE_ASSERT(paging_sent, == true, "%d");
231 VERBOSE_ASSERT(paging_stopped, == false, "%d");
232
233 btw("time passes and no paging result is received");
234
235 fake_time_passes(MSC_PAGING_RESPONSE_TIMER_DEFAULT - 1, 0);
236
237 btw("the paging timeout has not yet expired");
238 VERBOSE_ASSERT(paging_stopped, == false, "%d");
239 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
240 OSMO_ASSERT(vsub);
241 VERBOSE_ASSERT(vsub->cs.is_paging, == true, "%d");
242 btw("another request is added to the list but does not cause another paging");
243 paging_sent = false;
244 paging_expect_imsi(NULL);
245 send_sms(vsub, vsub,
246 "One paging ought to be enough for anyone.");
247 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 2, "%d");
248 vlr_subscr_put(vsub);
249 vsub = NULL;
250 VERBOSE_ASSERT(paging_sent, == false, "%d");
251
252 btw("the paging timeout expires, the paging as well as the requests are canceled");
253 fake_time_passes(2, 0);
254 VERBOSE_ASSERT(paging_stopped, == true, "%d");
255
256 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
257 OSMO_ASSERT(vsub);
258 VERBOSE_ASSERT(vsub->cs.is_paging, == false, "%d");
259 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100260
261 BTW("Now that the timeout has expired, another Paging is sent on request");
262 paging_expect_imsi(imsi);
263 paging_sent = false;
264
265 send_sms(vsub, vsub,
266 "Privacy in residential applications is a desirable"
267 " marketing option.");
268
269 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100270 vlr_subscr_put(vsub);
271 vsub = NULL;
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100272 VERBOSE_ASSERT(paging_sent, == true, "%d");
273 VERBOSE_ASSERT(paging_stopped, == false, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100274
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100275 BTW("subscriber detaches, pagings are canceled");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100276 expect_bssap_clear();
277 ms_sends_msg("050130089910070000006402");
278 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100279 VERBOSE_ASSERT(paging_stopped, == true, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100280
281 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
282 OSMO_ASSERT(!vsub);
283
284 EXPECT_CONN_COUNT(0);
285 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100286 comment_end(nr, imsi);
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100287}
288
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100289msc_vlr_test_func_t msc_vlr_tests[] = {
290 test_ms_timeout_lu_auth_resp,
291 test_ms_timeout_cm_auth_resp,
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100292 test_ms_timeout_paging,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100293 NULL
294};