blob: c7af200edfca21aba15b526b68ee8fee13ebb5ad [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_reject_2nd_conn(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
28 struct gsm_subscriber_connection *conn1;
Maxb0a43142018-02-06 19:19:52 +010029 comment_start(nr, imsi);
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();
Maxb0a43142018-02-06 19:19:52 +010067 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010068}
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 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
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
Max093300d2018-02-07 12:06:03 +0100118void _page(const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100119{
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100120 struct vlr_subscr *vsub;
121
122 BTW("an SMS is sent, MS is paged");
123 paging_expect_imsi(imsi);
124 paging_sent = false;
125 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
126 OSMO_ASSERT(vsub);
127 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
128
129 send_sms(vsub, vsub,
130 "Privacy in residential applications is a desirable"
131 " marketing option.");
132
133 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
134 vlr_subscr_put(vsub);
135 vsub = NULL;
136 VERBOSE_ASSERT(paging_sent, == true, "%d");
137 VERBOSE_ASSERT(paging_stopped, == false, "%d");
138}
139
140void _paging_resp_part1()
141{
142 btw("MS replies with Paging Response, we deliver the SMS");
143 dtap_expect_tx("09" /* SMS messages */
144 "01" /* CP-DATA */
145 "58" /* length */
146 "01" /* Network to MS */
147 "00" /* reference */
148 /* originator (gsm411_send_sms() hardcodes this weird nr) */
149 "0791" "447758100650" /* 447785016005 */
150 "00" /* dest */
151 /* SMS TPDU */
152 "4c" /* len */
153 "00" /* SMS deliver */
154 "05806470f1" /* originating address 46071 */
155 "00" /* TP-PID */
156 "00" /* GSM default alphabet */
157 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
158 "000000" /* H-M-S */
159 "00" /* GMT+0 */
160 "44" /* data length */
161 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
162 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
163 "0c7ac3e9e9b7db05");
164 ms_sends_msg("06270703305882089910070000006402");
165 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
166 VERBOSE_ASSERT(paging_stopped, == true, "%d");
167
168 btw("conn is still open to wait for SMS ack dance");
169 EXPECT_CONN_COUNT(1);
170}
171
Philipp Maierfbf66102017-04-09 12:32:51 +0200172void _paging_resp_part2(int expect_conn_count, bool expect_clear)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100173{
174 btw("MS replies with CP-ACK for received SMS");
175 ms_sends_msg("8904");
176 EXPECT_CONN_COUNT(1);
177
178 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
179 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200180 if (expect_clear)
181 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100182 ms_sends_msg("890106020041020000");
183 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200184 if (expect_clear)
185 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100186
187 btw("SMS is done");
188 EXPECT_CONN_COUNT(expect_conn_count);
189}
190
Maxb0a43142018-02-06 19:19:52 +0100191void test_reject_lu_during_lu(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100192{
Maxb0a43142018-02-06 19:19:52 +0100193 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100194
195 _normal_lu_part1();
196
197 BTW("Another Location Update Request from the same subscriber on the same conn is dropped silently");
198 ms_sends_msg("050802008168000130089910070000006402");
199 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
200 EXPECT_CONN_COUNT(1);
201
202 BTW("The first LU can still complete");
203 _normal_lu_part2();
204
205 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100206 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100207}
208
Maxb0a43142018-02-06 19:19:52 +0100209void test_reject_cm_during_lu(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100210{
Maxb0a43142018-02-06 19:19:52 +0100211 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100212
213 _normal_lu_part1();
214
215 BTW("A CM Service Request in the middle of a LU is rejected");
216 cm_service_result_sent = RES_NONE;
217 dtap_expect_tx("052211");
218 ms_sends_msg("05247803305886089910070000006402");
219 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
220 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
221 EXPECT_CONN_COUNT(1);
222
223 BTW("The first LU can still complete");
224 _normal_lu_part2();
225
226 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100227 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100228}
229
Maxb0a43142018-02-06 19:19:52 +0100230void test_reject_paging_resp_during_lu(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100231{
Maxb0a43142018-02-06 19:19:52 +0100232 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100233
234 _normal_lu_part1();
235
236 BTW("An erratic Paging Response is dropped silently");
237 ms_sends_msg("06270703305882089910070000006402");
238 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
239 EXPECT_CONN_COUNT(1);
240
241 BTW("The first LU can still complete");
242 _normal_lu_part2();
243
244 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100245 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100246}
247
Maxb0a43142018-02-06 19:19:52 +0100248void test_reject_lu_during_cm(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100249{
Maxb0a43142018-02-06 19:19:52 +0100250 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100251
252 _normal_lu();
253 _normal_cm_service_req();
254
255 btw("A LU request on an open conn is dropped silently");
256 /* TODO: accept periodic LU on an already open conn? */
257 lu_result_sent = RES_NONE;
258 ms_sends_msg("050802008168000130089910070000006402");
259 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
260 EXPECT_CONN_COUNT(1);
261
262 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200263 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100264 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200265 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100266 EXPECT_CONN_COUNT(0);
267
268 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100269 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100270}
271
Maxb0a43142018-02-06 19:19:52 +0100272void test_reject_cm_during_cm(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100273{
Maxb0a43142018-02-06 19:19:52 +0100274 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100275
276 _normal_lu();
277 _normal_cm_service_req();
278
279 btw("A second CM Service Request on the same conn is accepted without another auth dance");
280 cm_service_result_sent = RES_NONE;
281 ms_sends_msg("05247803305886089910070000006402");
282 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
283 EXPECT_CONN_COUNT(1);
284
285 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200286 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100287 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200288 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100289 EXPECT_CONN_COUNT(0);
290
291 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100292 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100293}
294
Maxb0a43142018-02-06 19:19:52 +0100295void test_reject_paging_resp_during_cm(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100296{
Maxb0a43142018-02-06 19:19:52 +0100297 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100298
299 _normal_lu();
300 _normal_cm_service_req();
301
302 BTW("An erratic Paging Response on the same conn is dropped silently");
303 ms_sends_msg("06270703305882089910070000006402");
304 EXPECT_CONN_COUNT(1);
305
306 BTW("The original CM Service Request can conclude");
307 btw("a USSD request is serviced");
308 dtap_expect_tx_ussd("Your extension is 46071\r");
Philipp Maierfbf66102017-04-09 12:32:51 +0200309 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100310 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200311 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100312
313 btw("all requests serviced, conn has been released");
314 EXPECT_CONN_COUNT(0);
315
316 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100317 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100318}
319
Maxb0a43142018-02-06 19:19:52 +0100320void test_reject_paging_resp_during_paging_resp(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100321{
Maxb0a43142018-02-06 19:19:52 +0100322 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100323
324 _normal_lu();
Max093300d2018-02-07 12:06:03 +0100325 _page(imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100326 _paging_resp_part1();
327
328 BTW("MS sends another erratic Paging Response which is dropped silently");
329 ms_sends_msg("06270703305882089910070000006402");
330
Philipp Maierfbf66102017-04-09 12:32:51 +0200331 _paging_resp_part2(0, true);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100332
333 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100334 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100335}
336
Maxb0a43142018-02-06 19:19:52 +0100337void test_reject_lu_during_paging_resp(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100338{
Maxb0a43142018-02-06 19:19:52 +0100339 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100340
341 _normal_lu();
Max093300d2018-02-07 12:06:03 +0100342 _page(imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100343 _paging_resp_part1();
344
345 BTW("MS sends erratic LU Request, which is dropped silently");
346 lu_result_sent = RES_NONE;
347 ms_sends_msg("050802008168000130089910070000006402");
348 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
349 EXPECT_CONN_COUNT(1);
350
Philipp Maierfbf66102017-04-09 12:32:51 +0200351 _paging_resp_part2(0, true);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100352
353 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100354 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100355}
356
Maxb0a43142018-02-06 19:19:52 +0100357void test_accept_cm_during_paging_resp(uint8_t nr, const char *imsi)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100358{
Maxb0a43142018-02-06 19:19:52 +0100359 comment_start(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100360
361 _normal_lu();
Max093300d2018-02-07 12:06:03 +0100362 _page(imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100363 _paging_resp_part1();
364
365 BTW("CM Service Request during open connection is accepted");
366 cm_service_result_sent = RES_NONE;
367 ms_sends_msg("05247803305886089910070000006402");
368 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
369 EXPECT_CONN_COUNT(1);
370 VERBOSE_ASSERT(g_conn->received_cm_service_request, == true, "%d");
371
Philipp Maierfbf66102017-04-09 12:32:51 +0200372 _paging_resp_part2(1, false);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100373
374 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200375 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100376 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200377 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100378 EXPECT_CONN_COUNT(0);
379
380 clear_vlr();
Maxb0a43142018-02-06 19:19:52 +0100381 comment_end(nr, imsi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100382}
383
384msc_vlr_test_func_t msc_vlr_tests[] = {
385 test_reject_2nd_conn,
386 test_reject_lu_during_lu,
387 test_reject_cm_during_lu,
388 test_reject_paging_resp_during_lu,
389 test_reject_lu_during_cm,
390 test_reject_cm_during_cm,
391 test_reject_paging_resp_during_cm,
392 test_reject_lu_during_paging_resp,
Philipp Maierfbf66102017-04-09 12:32:51 +0200393 test_accept_cm_during_paging_resp,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100394 test_reject_paging_resp_during_paging_resp,
395 NULL
396};