blob: 15988584a0fb3276412a845ccfe58c6355ca7fc3 [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
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;
42 ms_sends_msg("050802008168000130089910070000006402");
43 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
44 EXPECT_CONN_COUNT(1);
45
46
47 BTW("The first connection can still complete its LU");
48 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
49 g_conn = conn1;
50 lu_result_sent = RES_NONE;
51 gsup_rx("10010809710000004026f00804036470f1",
52 "12010809710000004026f0");
53 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
54
55 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
56 gsup_rx("06010809710000004026f0", NULL);
57
58 btw("LU was successful, and the conn has already been closed");
59 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
60 EXPECT_CONN_COUNT(0);
61
62 clear_vlr();
63 comment_end();
64}
65
66void _normal_lu_part1()
67{
68 btw("Location Update Request");
69 lu_result_sent = RES_NONE;
70 gsup_expect_tx("04010809710000004026f0");
71 ms_sends_msg("050802008168000130089910070000006402");
72 OSMO_ASSERT(gsup_tx_confirmed);
73 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
74 EXPECT_CONN_COUNT(1);
75}
76
77void _normal_lu_part2()
78{
79 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
80 lu_result_sent = RES_NONE;
81 gsup_rx("10010809710000004026f00804036470f1",
82 "12010809710000004026f0");
83 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
84
85 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
86 gsup_rx("06010809710000004026f0", NULL);
87
88 btw("LU was successful, and the conn has already been closed");
89 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
90 EXPECT_CONN_COUNT(0);
91}
92
93void _normal_lu()
94{
95 BTW("Subscriber does a normal LU");
96 _normal_lu_part1();
97 _normal_lu_part2();
98}
99
100void _normal_cm_service_req()
101{
102 BTW("Subscriber does a normal CM Service Request");
103 cm_service_result_sent = RES_NONE;
104 ms_sends_msg("05247803305886089910070000006402");
105 OSMO_ASSERT(g_conn);
106 OSMO_ASSERT(g_conn->conn_fsm);
107 OSMO_ASSERT(g_conn->vsub);
108 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
109 EXPECT_ACCEPTED(true);
110}
111
112void _page()
113{
114 const char *imsi = "901700000004620";
115 struct vlr_subscr *vsub;
116
117 BTW("an SMS is sent, MS is paged");
118 paging_expect_imsi(imsi);
119 paging_sent = false;
120 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
121 OSMO_ASSERT(vsub);
122 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
123
124 send_sms(vsub, vsub,
125 "Privacy in residential applications is a desirable"
126 " marketing option.");
127
128 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
129 vlr_subscr_put(vsub);
130 vsub = NULL;
131 VERBOSE_ASSERT(paging_sent, == true, "%d");
132 VERBOSE_ASSERT(paging_stopped, == false, "%d");
133}
134
135void _paging_resp_part1()
136{
137 btw("MS replies with Paging Response, we deliver the SMS");
138 dtap_expect_tx("09" /* SMS messages */
139 "01" /* CP-DATA */
140 "58" /* length */
141 "01" /* Network to MS */
142 "00" /* reference */
143 /* originator (gsm411_send_sms() hardcodes this weird nr) */
144 "0791" "447758100650" /* 447785016005 */
145 "00" /* dest */
146 /* SMS TPDU */
147 "4c" /* len */
148 "00" /* SMS deliver */
149 "05806470f1" /* originating address 46071 */
150 "00" /* TP-PID */
151 "00" /* GSM default alphabet */
152 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
153 "000000" /* H-M-S */
154 "00" /* GMT+0 */
155 "44" /* data length */
156 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
157 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
158 "0c7ac3e9e9b7db05");
159 ms_sends_msg("06270703305882089910070000006402");
160 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
161 VERBOSE_ASSERT(paging_stopped, == true, "%d");
162
163 btw("conn is still open to wait for SMS ack dance");
164 EXPECT_CONN_COUNT(1);
165}
166
167void _paging_resp_part2(int expect_conn_count)
168{
169 btw("MS replies with CP-ACK for received SMS");
170 ms_sends_msg("8904");
171 EXPECT_CONN_COUNT(1);
172
173 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
174 dtap_expect_tx("0904");
175 ms_sends_msg("890106020041020000");
176 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
177
178 btw("SMS is done");
179 EXPECT_CONN_COUNT(expect_conn_count);
180}
181
182void test_reject_lu_during_lu()
183{
184 comment_start();
185
186 _normal_lu_part1();
187
188 BTW("Another Location Update Request from the same subscriber on the same conn is dropped silently");
189 ms_sends_msg("050802008168000130089910070000006402");
190 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
191 EXPECT_CONN_COUNT(1);
192
193 BTW("The first LU can still complete");
194 _normal_lu_part2();
195
196 clear_vlr();
197 comment_end();
198}
199
200void test_reject_cm_during_lu()
201{
202 comment_start();
203
204 _normal_lu_part1();
205
206 BTW("A CM Service Request in the middle of a LU is rejected");
207 cm_service_result_sent = RES_NONE;
208 dtap_expect_tx("052211");
209 ms_sends_msg("05247803305886089910070000006402");
210 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
211 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
212 EXPECT_CONN_COUNT(1);
213
214 BTW("The first LU can still complete");
215 _normal_lu_part2();
216
217 clear_vlr();
218 comment_end();
219}
220
221void test_reject_paging_resp_during_lu()
222{
223 comment_start();
224
225 _normal_lu_part1();
226
227 BTW("An erratic Paging Response is dropped silently");
228 ms_sends_msg("06270703305882089910070000006402");
229 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
230 EXPECT_CONN_COUNT(1);
231
232 BTW("The first LU can still complete");
233 _normal_lu_part2();
234
235 clear_vlr();
236 comment_end();
237}
238
239void test_reject_lu_during_cm()
240{
241 comment_start();
242
243 _normal_lu();
244 _normal_cm_service_req();
245
246 btw("A LU request on an open conn is dropped silently");
247 /* TODO: accept periodic LU on an already open conn? */
248 lu_result_sent = RES_NONE;
249 ms_sends_msg("050802008168000130089910070000006402");
250 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
251 EXPECT_CONN_COUNT(1);
252
253 BTW("subscriber detaches");
254 ms_sends_msg("050130089910070000006402");
255 EXPECT_CONN_COUNT(0);
256
257 clear_vlr();
258 comment_end();
259}
260
261void test_reject_cm_during_cm()
262{
263 comment_start();
264
265 _normal_lu();
266 _normal_cm_service_req();
267
268 btw("A second CM Service Request on the same conn is accepted without another auth dance");
269 cm_service_result_sent = RES_NONE;
270 ms_sends_msg("05247803305886089910070000006402");
271 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
272 EXPECT_CONN_COUNT(1);
273
274 BTW("subscriber detaches");
275 ms_sends_msg("050130089910070000006402");
276 EXPECT_CONN_COUNT(0);
277
278 clear_vlr();
279 comment_end();
280}
281
282void test_reject_paging_resp_during_cm()
283{
284 comment_start();
285
286 _normal_lu();
287 _normal_cm_service_req();
288
289 BTW("An erratic Paging Response on the same conn is dropped silently");
290 ms_sends_msg("06270703305882089910070000006402");
291 EXPECT_CONN_COUNT(1);
292
293 BTW("The original CM Service Request can conclude");
294 btw("a USSD request is serviced");
295 dtap_expect_tx_ussd("Your extension is 46071\r");
296 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
297
298 btw("all requests serviced, conn has been released");
299 EXPECT_CONN_COUNT(0);
300
301 clear_vlr();
302 comment_end();
303}
304
305void test_reject_paging_resp_during_paging_resp()
306{
307 comment_start();
308
309 _normal_lu();
310 _page();
311 _paging_resp_part1();
312
313 BTW("MS sends another erratic Paging Response which is dropped silently");
314 ms_sends_msg("06270703305882089910070000006402");
315
316 _paging_resp_part2(0);
317
318 clear_vlr();
319 comment_end();
320}
321
322void test_reject_lu_during_paging_resp()
323{
324 comment_start();
325
326 _normal_lu();
327 _page();
328 _paging_resp_part1();
329
330 BTW("MS sends erratic LU Request, which is dropped silently");
331 lu_result_sent = RES_NONE;
332 ms_sends_msg("050802008168000130089910070000006402");
333 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
334 EXPECT_CONN_COUNT(1);
335
336 _paging_resp_part2(0);
337
338 clear_vlr();
339 comment_end();
340}
341
342void test_reject_cm_during_paging_resp()
343{
344 comment_start();
345
346 _normal_lu();
347 _page();
348 _paging_resp_part1();
349
350 BTW("CM Service Request during open connection is accepted");
351 cm_service_result_sent = RES_NONE;
352 ms_sends_msg("05247803305886089910070000006402");
353 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
354 EXPECT_CONN_COUNT(1);
355 VERBOSE_ASSERT(g_conn->received_cm_service_request, == true, "%d");
356
357 _paging_resp_part2(1);
358
359 BTW("subscriber detaches");
360 ms_sends_msg("050130089910070000006402");
361 EXPECT_CONN_COUNT(0);
362
363 clear_vlr();
364 comment_end();
365}
366
367msc_vlr_test_func_t msc_vlr_tests[] = {
368 test_reject_2nd_conn,
369 test_reject_lu_during_lu,
370 test_reject_cm_during_lu,
371 test_reject_paging_resp_during_lu,
372 test_reject_lu_during_cm,
373 test_reject_cm_during_cm,
374 test_reject_paging_resp_during_cm,
375 test_reject_lu_during_paging_resp,
376 test_reject_cm_during_paging_resp,
377 test_reject_paging_resp_during_paging_resp,
378 NULL
379};