blob: c81f5b5eaad1904f23dc56cf2327ce69458283f6 [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);
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
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010083 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010084}
85
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010086static void test_ms_timeout_cm_auth_resp()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010087{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010088 comment_start();
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();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100182 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100183}
184
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100185static void test_ms_timeout_paging()
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100186{
187 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100188 const char *imsi = "901700000004620";
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100189
190 rx_from_ran = RAN_GERAN_A;
191
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100192 comment_start();
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100193
194 fake_time_start();
195
196 btw("Location Update request causes a GSUP LU request to HLR");
197 lu_result_sent = RES_NONE;
198 gsup_expect_tx("04010809710000004026f0");
199 ms_sends_msg("050802008168000130089910070000006402");
200 OSMO_ASSERT(gsup_tx_confirmed);
201 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
202
203 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
204 gsup_rx("10010809710000004026f00804036470f1",
205 "12010809710000004026f0");
206 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
207
208 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
209 expect_bssap_clear();
210 gsup_rx("06010809710000004026f0", NULL);
211
212 btw("LU was successful, and the conn has already been closed");
213 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
214 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
215 EXPECT_CONN_COUNT(0);
216
217 BTW("an SMS is sent, MS is paged");
218 paging_expect_imsi(imsi);
219 paging_sent = false;
220 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
221 OSMO_ASSERT(vsub);
222 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
223
224 send_sms(vsub, vsub,
225 "Privacy in residential applications is a desirable"
226 " marketing option.");
227
228 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
229 vlr_subscr_put(vsub);
230 vsub = NULL;
231 VERBOSE_ASSERT(paging_sent, == true, "%d");
232 VERBOSE_ASSERT(paging_stopped, == false, "%d");
233
234 btw("time passes and no paging result is received");
235
236 fake_time_passes(MSC_PAGING_RESPONSE_TIMER_DEFAULT - 1, 0);
237
238 btw("the paging timeout has not yet expired");
239 VERBOSE_ASSERT(paging_stopped, == false, "%d");
240 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
241 OSMO_ASSERT(vsub);
242 VERBOSE_ASSERT(vsub->cs.is_paging, == true, "%d");
243 btw("another request is added to the list but does not cause another paging");
244 paging_sent = false;
245 paging_expect_imsi(NULL);
246 send_sms(vsub, vsub,
247 "One paging ought to be enough for anyone.");
248 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 2, "%d");
249 vlr_subscr_put(vsub);
250 vsub = NULL;
251 VERBOSE_ASSERT(paging_sent, == false, "%d");
252
253 btw("the paging timeout expires, the paging as well as the requests are canceled");
254 fake_time_passes(2, 0);
255 VERBOSE_ASSERT(paging_stopped, == true, "%d");
256
257 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
258 OSMO_ASSERT(vsub);
259 VERBOSE_ASSERT(vsub->cs.is_paging, == false, "%d");
260 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100261
262 BTW("Now that the timeout has expired, another Paging is sent on request");
263 paging_expect_imsi(imsi);
264 paging_sent = false;
265
266 send_sms(vsub, vsub,
267 "Privacy in residential applications is a desirable"
268 " marketing option.");
269
270 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100271 vlr_subscr_put(vsub);
272 vsub = NULL;
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100273 VERBOSE_ASSERT(paging_sent, == true, "%d");
274 VERBOSE_ASSERT(paging_stopped, == false, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100275
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100276 BTW("subscriber detaches, pagings are canceled");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100277 expect_bssap_clear();
278 ms_sends_msg("050130089910070000006402");
279 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrfacd57a2017-12-15 03:48:48 +0100280 VERBOSE_ASSERT(paging_stopped, == true, "%d");
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100281
282 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
283 OSMO_ASSERT(!vsub);
284
285 EXPECT_CONN_COUNT(0);
286 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100287 comment_end();
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100288}
289
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100290msc_vlr_test_func_t msc_vlr_tests[] = {
291 test_ms_timeout_lu_auth_resp,
292 test_ms_timeout_cm_auth_resp,
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100293 test_ms_timeout_paging,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100294 NULL
295};