blob: 2377c19b3af3a5051498df984389f121107bc6fb [file] [log] [blame]
Neels Hofmeyrf8178142017-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
26void test_reject_2nd_conn()
27{
28 struct gsm_subscriber_connection *conn1;
29 comment_start();
30
31 btw("Location Update Request on one connection");
32 lu_result_sent = RES_NONE;
33 gsup_expect_tx("04010809710000004026f0");
34 ms_sends_msg("050802008168000130089910070000006402");
35 OSMO_ASSERT(gsup_tx_confirmed);
36 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
37 EXPECT_CONN_COUNT(1);
38
39 btw("Another Location Update Request from the same subscriber on another connection is rejected");
40 conn1 = g_conn;
41 g_conn = NULL;
Philipp Maier4b60d072017-04-09 12:32:51 +020042 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +010043 ms_sends_msg("050802008168000130089910070000006402");
Philipp Maier4b60d072017-04-09 12:32:51 +020044 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +010045 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
46 EXPECT_CONN_COUNT(1);
47
48
49 BTW("The first connection can still complete its LU");
50 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
51 g_conn = conn1;
52 lu_result_sent = RES_NONE;
53 gsup_rx("10010809710000004026f00804036470f1",
54 "12010809710000004026f0");
55 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
56
57 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maier4b60d072017-04-09 12:32:51 +020058 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +010059 gsup_rx("06010809710000004026f0", NULL);
Philipp Maier4b60d072017-04-09 12:32:51 +020060 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +010061
62 btw("LU was successful, and the conn has already been closed");
63 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
64 EXPECT_CONN_COUNT(0);
65
66 clear_vlr();
67 comment_end();
68}
69
70void _normal_lu_part1()
71{
72 btw("Location Update Request");
73 lu_result_sent = RES_NONE;
74 gsup_expect_tx("04010809710000004026f0");
75 ms_sends_msg("050802008168000130089910070000006402");
76 OSMO_ASSERT(gsup_tx_confirmed);
77 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
78 EXPECT_CONN_COUNT(1);
79}
80
81void _normal_lu_part2()
82{
83 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
84 lu_result_sent = RES_NONE;
85 gsup_rx("10010809710000004026f00804036470f1",
86 "12010809710000004026f0");
87 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
88
89 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maier4b60d072017-04-09 12:32:51 +020090 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +010091 gsup_rx("06010809710000004026f0", NULL);
Philipp Maier4b60d072017-04-09 12:32:51 +020092 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +010093
94 btw("LU was successful, and the conn has already been closed");
95 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
96 EXPECT_CONN_COUNT(0);
97}
98
99void _normal_lu()
100{
101 BTW("Subscriber does a normal LU");
102 _normal_lu_part1();
103 _normal_lu_part2();
104}
105
106void _normal_cm_service_req()
107{
108 BTW("Subscriber does a normal CM Service Request");
109 cm_service_result_sent = RES_NONE;
110 ms_sends_msg("05247803305886089910070000006402");
111 OSMO_ASSERT(g_conn);
112 OSMO_ASSERT(g_conn->conn_fsm);
113 OSMO_ASSERT(g_conn->vsub);
114 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
115 EXPECT_ACCEPTED(true);
116}
117
118void _page()
119{
120 const char *imsi = "901700000004620";
121 struct vlr_subscr *vsub;
122
123 BTW("an SMS is sent, MS is paged");
124 paging_expect_imsi(imsi);
125 paging_sent = false;
126 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
127 OSMO_ASSERT(vsub);
128 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
129
130 send_sms(vsub, vsub,
131 "Privacy in residential applications is a desirable"
132 " marketing option.");
133
134 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
135 vlr_subscr_put(vsub);
136 vsub = NULL;
137 VERBOSE_ASSERT(paging_sent, == true, "%d");
138 VERBOSE_ASSERT(paging_stopped, == false, "%d");
139}
140
141void _paging_resp_part1()
142{
143 btw("MS replies with Paging Response, we deliver the SMS");
144 dtap_expect_tx("09" /* SMS messages */
145 "01" /* CP-DATA */
146 "58" /* length */
147 "01" /* Network to MS */
148 "00" /* reference */
149 /* originator (gsm411_send_sms() hardcodes this weird nr) */
150 "0791" "447758100650" /* 447785016005 */
151 "00" /* dest */
152 /* SMS TPDU */
153 "4c" /* len */
154 "00" /* SMS deliver */
155 "05806470f1" /* originating address 46071 */
156 "00" /* TP-PID */
157 "00" /* GSM default alphabet */
158 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
159 "000000" /* H-M-S */
160 "00" /* GMT+0 */
161 "44" /* data length */
162 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
163 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
164 "0c7ac3e9e9b7db05");
165 ms_sends_msg("06270703305882089910070000006402");
166 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
167 VERBOSE_ASSERT(paging_stopped, == true, "%d");
168
169 btw("conn is still open to wait for SMS ack dance");
170 EXPECT_CONN_COUNT(1);
171}
172
Philipp Maier4b60d072017-04-09 12:32:51 +0200173void _paging_resp_part2(int expect_conn_count, bool expect_clear)
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100174{
175 btw("MS replies with CP-ACK for received SMS");
176 ms_sends_msg("8904");
177 EXPECT_CONN_COUNT(1);
178
179 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
180 dtap_expect_tx("0904");
Philipp Maier4b60d072017-04-09 12:32:51 +0200181 if (expect_clear)
182 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100183 ms_sends_msg("890106020041020000");
184 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maier4b60d072017-04-09 12:32:51 +0200185 if (expect_clear)
186 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100187
188 btw("SMS is done");
189 EXPECT_CONN_COUNT(expect_conn_count);
190}
191
192void test_reject_lu_during_lu()
193{
194 comment_start();
195
196 _normal_lu_part1();
197
198 BTW("Another Location Update Request from the same subscriber on the same conn is dropped silently");
199 ms_sends_msg("050802008168000130089910070000006402");
200 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
201 EXPECT_CONN_COUNT(1);
202
203 BTW("The first LU can still complete");
204 _normal_lu_part2();
205
206 clear_vlr();
207 comment_end();
208}
209
210void test_reject_cm_during_lu()
211{
212 comment_start();
213
214 _normal_lu_part1();
215
216 BTW("A CM Service Request in the middle of a LU is rejected");
217 cm_service_result_sent = RES_NONE;
218 dtap_expect_tx("052211");
219 ms_sends_msg("05247803305886089910070000006402");
220 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
221 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
222 EXPECT_CONN_COUNT(1);
223
224 BTW("The first LU can still complete");
225 _normal_lu_part2();
226
227 clear_vlr();
228 comment_end();
229}
230
231void test_reject_paging_resp_during_lu()
232{
233 comment_start();
234
235 _normal_lu_part1();
236
237 BTW("An erratic Paging Response is dropped silently");
238 ms_sends_msg("06270703305882089910070000006402");
239 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
240 EXPECT_CONN_COUNT(1);
241
242 BTW("The first LU can still complete");
243 _normal_lu_part2();
244
245 clear_vlr();
246 comment_end();
247}
248
249void test_reject_lu_during_cm()
250{
251 comment_start();
252
253 _normal_lu();
254 _normal_cm_service_req();
255
256 btw("A LU request on an open conn is dropped silently");
257 /* TODO: accept periodic LU on an already open conn? */
258 lu_result_sent = RES_NONE;
259 ms_sends_msg("050802008168000130089910070000006402");
260 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
261 EXPECT_CONN_COUNT(1);
262
263 BTW("subscriber detaches");
Philipp Maier4b60d072017-04-09 12:32:51 +0200264 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100265 ms_sends_msg("050130089910070000006402");
Philipp Maier4b60d072017-04-09 12:32:51 +0200266 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100267 EXPECT_CONN_COUNT(0);
268
269 clear_vlr();
270 comment_end();
271}
272
273void test_reject_cm_during_cm()
274{
275 comment_start();
276
277 _normal_lu();
278 _normal_cm_service_req();
279
280 btw("A second CM Service Request on the same conn is accepted without another auth dance");
281 cm_service_result_sent = RES_NONE;
282 ms_sends_msg("05247803305886089910070000006402");
283 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
284 EXPECT_CONN_COUNT(1);
285
286 BTW("subscriber detaches");
Philipp Maier4b60d072017-04-09 12:32:51 +0200287 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100288 ms_sends_msg("050130089910070000006402");
Philipp Maier4b60d072017-04-09 12:32:51 +0200289 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100290 EXPECT_CONN_COUNT(0);
291
292 clear_vlr();
293 comment_end();
294}
295
296void test_reject_paging_resp_during_cm()
297{
298 comment_start();
299
300 _normal_lu();
301 _normal_cm_service_req();
302
303 BTW("An erratic Paging Response on the same conn is dropped silently");
304 ms_sends_msg("06270703305882089910070000006402");
305 EXPECT_CONN_COUNT(1);
306
307 BTW("The original CM Service Request can conclude");
308 btw("a USSD request is serviced");
309 dtap_expect_tx_ussd("Your extension is 46071\r");
Philipp Maier4b60d072017-04-09 12:32:51 +0200310 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100311 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
Philipp Maier4b60d072017-04-09 12:32:51 +0200312 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100313
314 btw("all requests serviced, conn has been released");
315 EXPECT_CONN_COUNT(0);
316
317 clear_vlr();
318 comment_end();
319}
320
321void test_reject_paging_resp_during_paging_resp()
322{
323 comment_start();
324
325 _normal_lu();
326 _page();
327 _paging_resp_part1();
328
329 BTW("MS sends another erratic Paging Response which is dropped silently");
330 ms_sends_msg("06270703305882089910070000006402");
331
Philipp Maier4b60d072017-04-09 12:32:51 +0200332 _paging_resp_part2(0, true);
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100333
334 clear_vlr();
335 comment_end();
336}
337
338void test_reject_lu_during_paging_resp()
339{
340 comment_start();
341
342 _normal_lu();
343 _page();
344 _paging_resp_part1();
345
346 BTW("MS sends erratic LU Request, which is dropped silently");
347 lu_result_sent = RES_NONE;
348 ms_sends_msg("050802008168000130089910070000006402");
349 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
350 EXPECT_CONN_COUNT(1);
351
Philipp Maier4b60d072017-04-09 12:32:51 +0200352 _paging_resp_part2(0, true);
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100353
354 clear_vlr();
355 comment_end();
356}
357
Philipp Maier4b60d072017-04-09 12:32:51 +0200358void test_accept_cm_during_paging_resp()
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100359{
360 comment_start();
361
362 _normal_lu();
363 _page();
364 _paging_resp_part1();
365
366 BTW("CM Service Request during open connection is accepted");
367 cm_service_result_sent = RES_NONE;
368 ms_sends_msg("05247803305886089910070000006402");
369 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
370 EXPECT_CONN_COUNT(1);
371 VERBOSE_ASSERT(g_conn->received_cm_service_request, == true, "%d");
372
Philipp Maier4b60d072017-04-09 12:32:51 +0200373 _paging_resp_part2(1, false);
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100374
375 BTW("subscriber detaches");
Philipp Maier4b60d072017-04-09 12:32:51 +0200376 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100377 ms_sends_msg("050130089910070000006402");
Philipp Maier4b60d072017-04-09 12:32:51 +0200378 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100379 EXPECT_CONN_COUNT(0);
380
381 clear_vlr();
382 comment_end();
383}
384
385msc_vlr_test_func_t msc_vlr_tests[] = {
386 test_reject_2nd_conn,
387 test_reject_lu_during_lu,
388 test_reject_cm_during_lu,
389 test_reject_paging_resp_during_lu,
390 test_reject_lu_during_cm,
391 test_reject_cm_during_cm,
392 test_reject_paging_resp_during_cm,
393 test_reject_lu_during_paging_resp,
Philipp Maier4b60d072017-04-09 12:32:51 +0200394 test_accept_cm_during_paging_resp,
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100395 test_reject_paging_resp_during_paging_resp,
396 NULL
397};