blob: 08fc9e7a37fca1e7219f56c89eaf7dbb828a9ddb [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_reject_2nd_conn()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
28 struct gsm_subscriber_connection *conn1;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010029 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010030
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 Maierfbf66102017-04-09 12:32:51 +020042 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010043 ms_sends_msg("050802008168000130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +020044 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-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 Maierfbf66102017-04-09 12:32:51 +020058 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010059 gsup_rx("06010809710000004026f0", NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +020060 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-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();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010067 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010068}
69
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010070static void _normal_lu_part1()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010071{
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
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010081static void _normal_lu_part2()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010082{
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 Maierfbf66102017-04-09 12:32:51 +020090 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010091 gsup_rx("06010809710000004026f0", NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +020092 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-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
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010099static void _normal_lu()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100100{
101 BTW("Subscriber does a normal LU");
102 _normal_lu_part1();
103 _normal_lu_part2();
104}
105
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100106static void _normal_cm_service_req()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100107{
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
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100118static void _page()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100119{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100120 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100121 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
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100141static void _paging_resp_part1()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100142{
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
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100173static void _paging_resp_part2(int expect_conn_count, bool expect_clear)
Neels Hofmeyr6a29d322017-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 Maierfbf66102017-04-09 12:32:51 +0200181 if (expect_clear)
182 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100183 ms_sends_msg("890106020041020000");
184 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200185 if (expect_clear)
186 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100187
188 btw("SMS is done");
189 EXPECT_CONN_COUNT(expect_conn_count);
190}
191
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100192static void test_reject_lu_during_lu()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100193{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100194 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100195
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();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100207 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100208}
209
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100210static void test_reject_cm_during_lu()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100211{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100212 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100213
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");
Neels Hofmeyr9fe52e42018-04-02 22:46:55 +0200222 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100223 EXPECT_CONN_COUNT(1);
224
225 BTW("The first LU can still complete");
226 _normal_lu_part2();
227
228 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100229 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100230}
231
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100232static void test_reject_paging_resp_during_lu()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100233{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100234 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100235
236 _normal_lu_part1();
237
238 BTW("An erratic Paging Response is dropped silently");
239 ms_sends_msg("06270703305882089910070000006402");
240 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
241 EXPECT_CONN_COUNT(1);
242
243 BTW("The first LU can still complete");
244 _normal_lu_part2();
245
246 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100247 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100248}
249
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100250static void test_reject_lu_during_cm()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100251{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100252 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100253
254 _normal_lu();
255 _normal_cm_service_req();
256
257 btw("A LU request on an open conn is dropped silently");
258 /* TODO: accept periodic LU on an already open conn? */
259 lu_result_sent = RES_NONE;
260 ms_sends_msg("050802008168000130089910070000006402");
261 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
262 EXPECT_CONN_COUNT(1);
263
264 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200265 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100266 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200267 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100268 EXPECT_CONN_COUNT(0);
269
270 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100271 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100272}
273
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100274static void test_reject_cm_during_cm()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100275{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100276 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100277
278 _normal_lu();
279 _normal_cm_service_req();
280
281 btw("A second CM Service Request on the same conn is accepted without another auth dance");
282 cm_service_result_sent = RES_NONE;
283 ms_sends_msg("05247803305886089910070000006402");
284 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
285 EXPECT_CONN_COUNT(1);
286
287 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200288 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100289 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200290 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100291 EXPECT_CONN_COUNT(0);
292
293 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100294 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100295}
296
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100297static void test_reject_paging_resp_during_cm()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100298{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100299 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100300
301 _normal_lu();
302 _normal_cm_service_req();
303
304 BTW("An erratic Paging Response on the same conn is dropped silently");
305 ms_sends_msg("06270703305882089910070000006402");
306 EXPECT_CONN_COUNT(1);
307
308 BTW("The original CM Service Request can conclude");
309 btw("a USSD request is serviced");
310 dtap_expect_tx_ussd("Your extension is 46071\r");
Philipp Maierfbf66102017-04-09 12:32:51 +0200311 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100312 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200313 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100314
315 btw("all requests serviced, conn has been released");
316 EXPECT_CONN_COUNT(0);
317
318 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100319 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100320}
321
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100322static void test_reject_paging_resp_during_paging_resp()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100323{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100324 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100325
326 _normal_lu();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100327 _page();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100328 _paging_resp_part1();
329
330 BTW("MS sends another erratic Paging Response which is dropped silently");
331 ms_sends_msg("06270703305882089910070000006402");
332
Philipp Maierfbf66102017-04-09 12:32:51 +0200333 _paging_resp_part2(0, true);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100334
335 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100336 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100337}
338
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100339static void test_reject_lu_during_paging_resp()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100340{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100341 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100342
343 _normal_lu();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100344 _page();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100345 _paging_resp_part1();
346
347 BTW("MS sends erratic LU Request, which is dropped silently");
348 lu_result_sent = RES_NONE;
349 ms_sends_msg("050802008168000130089910070000006402");
350 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
351 EXPECT_CONN_COUNT(1);
352
Philipp Maierfbf66102017-04-09 12:32:51 +0200353 _paging_resp_part2(0, true);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100354
355 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100356 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100357}
358
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100359static void test_accept_cm_during_paging_resp()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100360{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100361 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100362
363 _normal_lu();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100364 _page();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100365 _paging_resp_part1();
366
367 BTW("CM Service Request during open connection is accepted");
368 cm_service_result_sent = RES_NONE;
369 ms_sends_msg("05247803305886089910070000006402");
370 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
371 EXPECT_CONN_COUNT(1);
372 VERBOSE_ASSERT(g_conn->received_cm_service_request, == true, "%d");
373
Philipp Maierfbf66102017-04-09 12:32:51 +0200374 _paging_resp_part2(1, false);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100375
376 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200377 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100378 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200379 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100380 EXPECT_CONN_COUNT(0);
381
382 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100383 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100384}
385
386msc_vlr_test_func_t msc_vlr_tests[] = {
387 test_reject_2nd_conn,
388 test_reject_lu_during_lu,
389 test_reject_cm_during_lu,
390 test_reject_paging_resp_during_lu,
391 test_reject_lu_during_cm,
392 test_reject_cm_during_cm,
393 test_reject_paging_resp_during_cm,
394 test_reject_lu_during_paging_resp,
Philipp Maierfbf66102017-04-09 12:32:51 +0200395 test_accept_cm_during_paging_resp,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100396 test_reject_paging_resp_during_paging_resp,
397 NULL
398};