blob: 392d38df6fae5b71f3bdb830613010bda05595aa [file] [log] [blame]
Neels Hofmeyra99b4272017-11-21 17:13:23 +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
26#include <osmocom/msc/gsm_04_08.h>
27
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010028static void mncc_sends_to_cc(uint32_t msg_type, struct gsm_mncc *mncc)
Neels Hofmeyra99b4272017-11-21 17:13:23 +010029{
30 mncc->msg_type = msg_type;
Neels Hofmeyr52558742019-05-09 01:23:09 +020031 mncc_tx_to_cc(net, mncc);
Neels Hofmeyra99b4272017-11-21 17:13:23 +010032}
33
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010034/*
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +010035static void on_call_release_mncc_sends_to_cc(uint32_t msg_type, struct gsm_mncc *mncc)
36{
37 mncc->msg_type = msg_type;
38 on_call_release_mncc_sends_to_cc_data = mncc;
39}
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010040*/
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +010041
Neels Hofmeyra99b4272017-11-21 17:13:23 +010042#define IMSI "901700000010650"
43
44static void standard_lu()
45{
46 struct vlr_subscr *vsub;
47
48 net->authentication_required = true;
49 net->vlr->cfg.assign_tmsi = true;
Neels Hofmeyr7814a832018-12-26 00:40:18 +010050 rx_from_ran = OSMO_RAT_UTRAN_IU;
Neels Hofmeyra99b4272017-11-21 17:13:23 +010051
52 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
53 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010054 gsup_expect_tx("080108" "09710000000156f0" VLR_TO_HLR);
Neels Hofmeyra99b4272017-11-21 17:13:23 +010055 ms_sends_msg("0508" /* MM LU */
56 "7" /* ciph key seq: no key available */
57 "0" /* LU type: normal */
58 "09f107" "0017" /* LAI, LAC */
59 "57" /* classmark 1: R99, early classmark, no power lvl */
60 "089910070000106005" /* IMSI */
61 "3303575886" /* classmark 2 */
62 );
63 OSMO_ASSERT(gsup_tx_confirmed);
64 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
65
66 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
67 /* based on auc_3g:
68 * K = 'EB215756028D60E3275E613320AEC880',
69 * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308'
70 * SQN = 0
71 */
72 auth_request_sent = false;
73 auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d";
74 auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919";
75 gsup_rx("0a"
76 /* imsi */
77 "0108" "09710000000156f0"
78 /* 5 auth vectors... */
79 /* TL TL rand */
80 "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d"
81 /* TL sres TL kc */
82 "2104" "9b36efdf" "2208" "059a4f668f6fbe39"
83 /* TL 3G IK */
84 "2310" "27497388b6cb044648f396aa155b95ef"
85 /* TL 3G CK */
86 "2410" "f64735036e5871319c679f4742a75ea1"
87 /* TL AUTN */
88 "2510" "8704f5ba55f30000d2ee44b22c8ea919"
89 /* TL RES */
90 "2708" "e229c19e791f2e41"
91 /* TL TL rand */
92 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
93 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
94 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
95 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
96 "2510" "1843a645b98d00005b2d666af46c45d9"
97 "2708" "7db47cf7f81e4dc7"
98 "0362" "2010" "efa9c29a9742148d5c9070348716e1bb"
99 "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d"
100 "2310" "eb50e770ddcc3060101d2f43b6c2b884"
101 "2410" "76542abce5ff9345b0e8947f4c6e019c"
102 "2510" "f9375e6d41e1000096e7fe4ff1c27e39"
103 "2708" "706f996719ba609c"
104 "0362" "2010" "f023d5a3b24726e0631b64b3840f8253"
105 "2104" "d570c03f" "2208" "ec011be8919883d6"
106 "2310" "c4e58af4ba43f3bcd904e16984f086d7"
107 "2410" "0593f65e752e5cb7f473862bda05aa0a"
108 "2510" "541ff1f077270000c5ea00d658bc7e9a"
109 "2708" "3fd26072eaa2a04d"
110 "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e"
111 "2104" "b072446f220823f39f9f425ad6e6"
112 "2310" "65af0527fda95b0dc5ae4aa515cdf32f"
113 "2410" "537c3b35a3b13b08d08eeb28098f45cc"
114 "2510" "4bf4e564f75300009bc796706bc65744"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100115 "2708" "0edb0eadbea94ac2"
116 HLR_TO_VLR,
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100117 NULL);
118 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
119 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
120
121 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100122 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100123 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100124 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100125 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
126
127 btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100128 gsup_expect_tx("04010809710000000156f0280102" VLR_TO_HLR);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100129 ms_sends_security_mode_complete();
130 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
131 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
132
133 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100134 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
135 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100136 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
137
138 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100139 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100140
141 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
142
143 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
144 EXPECT_CONN_COUNT(1);
145 EXPECT_ACCEPTED(false);
146
147 btw("MS sends TMSI Realloc Complete");
148 iu_release_expected = true;
149 iu_release_sent = false;
150 ms_sends_msg("055b");
151 VERBOSE_ASSERT(iu_release_sent, == true, "%d"); \
152
153 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100154 ran_sends_clear_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100155 EXPECT_CONN_COUNT(0);
156
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100157 vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI, __func__);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100158 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
159 VERBOSE_ASSERT(strcmp(vsub->imsi, IMSI), == 0, "%d");
Max7d41d872018-12-19 11:48:33 +0100160 VAL_ASSERT("LAC", vsub->cgi.lai.lac, == 23, "%u");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100161 vlr_subscr_put(vsub, __func__);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100162}
163
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100164static void test_call_mo()
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100165{
166 struct gsm_mncc mncc = {
167 .imsi = IMSI,
168 };
169
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100170 comment_start();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100171
172 fake_time_start();
173
174 standard_lu();
175
176 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
177 auth_request_sent = false;
178 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
179 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
180 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100181 ms_sends_msg("052471"
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100182 "03575886" /* classmark 2 */
183 "089910070000106005" /* IMSI */);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100184 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
185 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
186
187 btw("needs auth, not yet accepted");
188 EXPECT_ACCEPTED(false);
189
190 /* On UTRAN */
191 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100192 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100193 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100194 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100195 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
196
197 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
198 ms_sends_security_mode_complete();
199 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
200
201 BTW("a call is initiated");
202
203 btw("SETUP gets forwarded to MNCC");
204 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND);
205 ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */
206 "0406600402000581" /* Bearer Capability */
207 "5e038121f3" /* Called Number BCD */
208 "15020100" /* CC Capabilities */
209 "4008" /* Supported Codec List */
210 "04026000" /* UMTS: AMR 2 | AMR */
211 "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */
212 );
213 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
214 mncc.callref = cc_to_mncc_tx_got_callref;
215
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200216 btw("MNCC replies with MNCC_RTP_CREATE, causing MGW endpoint CRCX to RAN");
217 expect_crcx(RTP_TO_RAN);
218 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
219 OSMO_ASSERT(got_crcx);
220
221 btw("MGW acknowledges the CRCX, triggering Assignment");
222 expect_iu_rab_assignment();
223 crcx_ok(RTP_TO_RAN);
224 OSMO_ASSERT(iu_rab_assignment_sent);
225
226 btw("Assignment succeeds, triggering CRCX to CN");
227 expect_crcx(RTP_TO_CN);
228 ms_sends_assignment_complete(CODEC_AMR_8000_1);
229 OSMO_ASSERT(got_crcx);
230
231 btw("CN RTP address is available, trigger MNCC_RTP_CREATE");
232 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
233 crcx_ok(RTP_TO_CN);
234
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100235 btw("MNCC says that's fine");
236 dtap_expect_tx("8302" /* CC: Call Proceeding */);
237 mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc);
238 OSMO_ASSERT(dtap_tx_confirmed);
239
240 fake_time_passes(1, 23);
241
242 btw("The other call leg got established (not shown here), MNCC tells us so");
243 dtap_expect_tx("8301" /* CC: Call Alerting */);
244 mncc_sends_to_cc(MNCC_ALERT_REQ, &mncc);
245 OSMO_ASSERT(dtap_tx_confirmed);
246
247 dtap_expect_tx("8307" /* CC: Connect */);
248 mncc_sends_to_cc(MNCC_SETUP_RSP, &mncc);
249 OSMO_ASSERT(dtap_tx_confirmed);
250
251 fake_time_passes(1, 23);
252
253 cc_to_mncc_expect_tx("", MNCC_SETUP_COMPL_IND);
254 ms_sends_msg("03cf" /* CC: Connect Acknowledge */);
255 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
256
257 BTW("RTP stream goes ahead, not shown here.");
258 fake_time_passes(123, 45);
259
260 BTW("Call ends");
261 cc_to_mncc_expect_tx("", MNCC_DISC_IND);
262 ms_sends_msg("032502e090" /* CC: Disconnect, cause: Normal Call Clearing */);
263 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
264
265 dtap_expect_tx("832d" /* CC: Release */);
266 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
267 OSMO_ASSERT(dtap_tx_confirmed);
268
269 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
270 expect_iu_release();
271 ms_sends_msg("036a" /* CC: Release Complete */);
272 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
273 OSMO_ASSERT(iu_release_sent);
274
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100275 ran_sends_clear_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100276 EXPECT_CONN_COUNT(0);
277 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100278 comment_end();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100279}
280
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100281static void test_call_mt()
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100282{
283 struct gsm_mncc mncc = {
284 .imsi = IMSI,
285 .callref = 0x423,
286 };
287
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100288 comment_start();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100289
290 fake_time_start();
291
292 standard_lu();
293
294 BTW("after a while, MNCC asks us to setup a call, causing Paging");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100295
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100296 paging_expect_imsi(IMSI);
297 paging_sent = false;
298 mncc_sends_to_cc(MNCC_SETUP_REQ, &mncc);
299
300 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100301
302 btw("MS replies with Paging Response, and VLR sends Auth Request");
303 auth_request_sent = false;
304 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
305 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
306 ms_sends_msg("062707"
307 "03575886" /* classmark 2 */
308 "089910070000106005" /* IMSI */);
309 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
310
311 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100312 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100313 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100314 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100315
316 btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup");
317 dtap_expect_tx("0305" /* CC: Setup */);
318 ms_sends_security_mode_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100319
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200320 btw("MS confirms call, we create a RAN-side RTP and forward MNCC_CALL_CONF_IND");
321 expect_crcx(RTP_TO_RAN);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100322 cc_to_mncc_expect_tx(IMSI, MNCC_CALL_CONF_IND);
323 ms_sends_msg("8348" /* CC: Call Confirmed */
324 "0406600402000581" /* Bearer Capability */
325 "15020100" /* Call Control Capabilities */
326 "40080402600400021f00" /* Supported Codec List */);
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200327 OSMO_ASSERT(got_crcx);
328 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
329
330 btw("MNCC sends MNCC_RTP_CREATE");
331 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
332
333 btw("MGW acknowledges the CRCX to RAN, triggering Assignment");
334 expect_iu_rab_assignment();
335 crcx_ok(RTP_TO_RAN);
336 OSMO_ASSERT(iu_rab_assignment_sent);
337
338 btw("Assignment completes, triggering CRCX to CN");
339 expect_crcx(RTP_TO_CN);
340 ms_sends_assignment_complete(CODEC_AMR_8000_1);
341 OSMO_ASSERT(got_crcx);
342
343 btw("When the CN side RTP address is known, send MNCC_RTP_CREATE");
344 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
345 crcx_ok(RTP_TO_CN);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100346
347 fake_time_passes(1, 23);
348
349 cc_to_mncc_expect_tx("", MNCC_ALERT_IND);
350 ms_sends_msg("8381" /* CC: Alerting */);
351
352 fake_time_passes(1, 23);
353
354 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_CNF);
355 ms_sends_msg("83c7" /* CC: Connect */);
356
357 dtap_expect_tx("030f" /* CC: Connect Acknowledge */);
358 mncc_sends_to_cc(MNCC_SETUP_COMPL_REQ, &mncc);
359
360 BTW("RTP stream goes ahead, not shown here.");
361 fake_time_passes(123, 45);
362
363 BTW("Call ends");
364 cc_to_mncc_expect_tx("", MNCC_DISC_IND);
365 ms_sends_msg("832502e090" /* CC: Disconnect, cause: Normal Call Clearing */);
366 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
367
368 dtap_expect_tx("032d" /* CC: Release */);
369 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
370 OSMO_ASSERT(dtap_tx_confirmed);
371
372 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
373 expect_iu_release();
374 ms_sends_msg("836a" /* CC: Release Complete */);
375 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
376 OSMO_ASSERT(iu_release_sent);
377
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100378 ran_sends_clear_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100379 EXPECT_CONN_COUNT(0);
380 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100381 comment_end();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100382}
383
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100384static void test_call_mt2()
385{
386 struct gsm_mncc mncc = {
387 .imsi = IMSI,
388 .callref = 0x423,
389 };
390
391 comment_start();
392
393 fake_time_start();
394
395 standard_lu();
396
397 BTW("after a while, MNCC asks us to setup a call, causing Paging");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100398
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100399 paging_expect_imsi(IMSI);
400 paging_sent = false;
401 mncc_sends_to_cc(MNCC_SETUP_REQ, &mncc);
402
403 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100404
405 btw("MS replies with Paging Response, and VLR sends Auth Request");
406 auth_request_sent = false;
407 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
408 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
409 ms_sends_msg("062707"
410 "03575886" /* classmark 2 */
411 "089910070000106005" /* IMSI */);
412 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
413
414 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
415 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
416 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
417 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
418
419 btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup");
420 dtap_expect_tx("0305" /* CC: Setup */);
421 ms_sends_security_mode_complete();
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100422
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200423 btw("MS confirms call, we create a RAN-side RTP and forward MNCC_CALL_CONF_IND");
424 expect_crcx(RTP_TO_RAN);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100425 cc_to_mncc_expect_tx(IMSI, MNCC_CALL_CONF_IND);
426 ms_sends_msg("8348" /* CC: Call Confirmed */
427 "0406600402000581" /* Bearer Capability */
428 "15020100" /* Call Control Capabilities */
429 "40080402600400021f00" /* Supported Codec List */);
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200430 OSMO_ASSERT(got_crcx);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100431 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
432
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200433 btw("MNCC sends MNCC_RTP_CREATE");
434 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
435
436 btw("MGW acknowledges the CRCX to RAN, triggering Assignment");
437 expect_iu_rab_assignment();
438 crcx_ok(RTP_TO_RAN);
439 OSMO_ASSERT(iu_rab_assignment_sent);
440
441 btw("Assignment completes, triggering CRCX to CN");
442 expect_crcx(RTP_TO_CN);
443 ms_sends_assignment_complete(CODEC_AMR_8000_1);
444 OSMO_ASSERT(got_crcx);
445
446 btw("When the CN side RTP address is known, send MNCC_RTP_CREATE");
447 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
448 crcx_ok(RTP_TO_CN);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100449 fake_time_passes(1, 23);
450
451 cc_to_mncc_expect_tx("", MNCC_ALERT_IND);
452 ms_sends_msg("8381" /* CC: Alerting */);
453 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
454
455 fake_time_passes(15, 23);
456
457 btw("The call failed, the BSC sends a BSSMAP Clear Request");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100458 /* FIXME: in this scenario, we send an MNCC_REL_CNF even though MNCC never asked us to MNCC_REL_REQ. Legacy
459 * behavior did get to both MNCC_REL_IND, then an MNCC_REL_REQ from MNCC as well as a final MNCC_REL_CNF, but
460 * this only worked synchronously, i.e. only with internal MNCC. Instead of mimicking that, we need a proper
461 * async solution that also works with a PBX. */
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100462 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
Keith Whyteff17f8f2019-08-01 12:20:25 +0200463 dtap_expect_tx("032d0802e1af"); /* CC: Release */
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100464 expect_iu_release();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100465 msc_a_release_cn(msub_msc_a(g_msub));
466 OSMO_ASSERT(dtap_tx_confirmed);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100467 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
468 OSMO_ASSERT(iu_release_sent);
469
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100470 ran_sends_clear_complete();
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100471 EXPECT_CONN_COUNT(0);
472
473 /* Make sure a pending release timer doesn't fire later to access freed data */
474 fake_time_passes(15, 23);
475
476 clear_vlr();
477 comment_end();
478}
479
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100480static void test_call_mo_to_unknown()
481{
482 struct gsm_mncc mncc = {
483 .imsi = IMSI,
484 };
485
486 comment_start();
487
488 fake_time_start();
489
490 standard_lu();
491
492 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
493 auth_request_sent = false;
494 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
495 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
496 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100497 ms_sends_msg("052471"
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100498 "03575886" /* classmark 2 */
499 "089910070000106005" /* IMSI */);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100500 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
501 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
502
503 btw("needs auth, not yet accepted");
504 EXPECT_ACCEPTED(false);
505
506 /* On UTRAN */
507 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
508 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
509 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
510 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
511 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
512
513 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
514 ms_sends_security_mode_complete();
515 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
516
517 BTW("a call is initiated");
518
519 btw("SETUP gets forwarded to MNCC");
520 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND);
521 ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */
522 "0406600402000581" /* Bearer Capability */
523 "5e038121f3" /* Called Number BCD */
524 "15020100" /* CC Capabilities */
525 "4008" /* Supported Codec List */
526 "04026000" /* UMTS: AMR 2 | AMR */
527 "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */
528 );
529 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
530 mncc.callref = cc_to_mncc_tx_got_callref;
531
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200532 btw("MNCC replies with MNCC_RTP_CREATE, causing MGW endpoint CRCX to RAN");
533 expect_crcx(RTP_TO_RAN);
534 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
535 OSMO_ASSERT(got_crcx);
536
537 btw("MGW acknowledges the CRCX, triggering Assignment");
538 expect_iu_rab_assignment();
539 crcx_ok(RTP_TO_RAN);
540 OSMO_ASSERT(iu_rab_assignment_sent);
541
542 btw("Assignment succeeds, triggering CRCX to CN");
543 expect_crcx(RTP_TO_CN);
544 ms_sends_assignment_complete(CODEC_AMR_8000_1);
545 OSMO_ASSERT(got_crcx);
546
547 btw("CN RTP address is available, trigger MNCC_RTP_CREATE");
548 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
549 crcx_ok(RTP_TO_CN);
550
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100551 btw("MNCC says that's fine");
552 dtap_expect_tx("8302" /* CC: Call Proceeding */);
553 mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc);
554 OSMO_ASSERT(dtap_tx_confirmed);
555
556 btw("But the other side's MSISDN could not be resolved, MNCC tells us to cancel");
557 dtap_expect_tx("832d" /* CC: Release Request */);
558 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
559
560 dtap_expect_tx("832d" /* CC: Release Request */);
561 fake_time_passes(10, 23);
562
563 expect_iu_release();
564 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
565 ms_sends_msg("036a" /* CC: Release Complete */);
566 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
567 OSMO_ASSERT(iu_release_sent);
568 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
569
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100570 ran_sends_clear_complete();
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100571 EXPECT_CONN_COUNT(0);
572 clear_vlr();
573 comment_end();
574}
575
576static void test_call_mo_to_unknown_timeout()
577{
578 struct gsm_mncc mncc = {
579 .imsi = IMSI,
580 };
581
582 comment_start();
583
584 fake_time_start();
585
586 standard_lu();
587
588 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
589 auth_request_sent = false;
590 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
591 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
592 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100593 ms_sends_msg("052471"
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100594 "03575886" /* classmark 2 */
595 "089910070000106005" /* IMSI */);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100596 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
597 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
598
599 btw("needs auth, not yet accepted");
600 EXPECT_ACCEPTED(false);
601
602 /* On UTRAN */
603 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
604 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
605 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
606 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
607 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
608
609 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
610 ms_sends_security_mode_complete();
611 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
612
613 BTW("a call is initiated");
614
615 btw("SETUP gets forwarded to MNCC");
616 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND);
617 ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */
618 "0406600402000581" /* Bearer Capability */
619 "5e038121f3" /* Called Number BCD */
620 "15020100" /* CC Capabilities */
621 "4008" /* Supported Codec List */
622 "04026000" /* UMTS: AMR 2 | AMR */
623 "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */
624 );
625 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
626 mncc.callref = cc_to_mncc_tx_got_callref;
627
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200628 btw("MNCC replies with MNCC_RTP_CREATE, causing MGW endpoint CRCX to RAN");
629 expect_crcx(RTP_TO_RAN);
630 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
631 OSMO_ASSERT(got_crcx);
632
633 btw("MGW acknowledges the CRCX, triggering Assignment");
634 expect_iu_rab_assignment();
635 crcx_ok(RTP_TO_RAN);
636 OSMO_ASSERT(iu_rab_assignment_sent);
637
638 btw("Assignment succeeds, triggering CRCX to CN");
639 expect_crcx(RTP_TO_CN);
640 ms_sends_assignment_complete(CODEC_AMR_8000_1);
641 OSMO_ASSERT(got_crcx);
642
643 btw("CN RTP address is available, trigger MNCC_RTP_CREATE");
644 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
645 crcx_ok(RTP_TO_CN);
646
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100647 btw("MNCC says that's fine");
648 dtap_expect_tx("8302" /* CC: Call Proceeding */);
649 mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc);
650 OSMO_ASSERT(dtap_tx_confirmed);
651
652 btw("But the other side's MSISDN could not be resolved, MNCC tells us to cancel");
653 dtap_expect_tx("832d" /* CC: Release Request */);
654 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
655
656 btw("Despite our repeated CC Release Requests, the MS does not respond anymore");
657 dtap_expect_tx("832d" /* CC: Release Request */);
658 fake_time_passes(10, 23);
659
660 btw("The CC Release times out and we still properly clear the conn");
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100661 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
Neels Hofmeyrd6a769b2018-03-12 23:59:07 +0100662 expect_iu_release();
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100663 fake_time_passes(10, 23);
664 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100665 OSMO_ASSERT(iu_release_sent);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100666
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100667 ran_sends_clear_complete();
Neels Hofmeyrd6a769b2018-03-12 23:59:07 +0100668 EXPECT_CONN_COUNT(0);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100669 clear_vlr();
670 comment_end();
671}
672
673
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100674msc_vlr_test_func_t msc_vlr_tests[] = {
675 test_call_mo,
676 test_call_mt,
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100677 test_call_mt2,
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100678 test_call_mo_to_unknown,
679 test_call_mo_to_unknown_timeout,
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100680 NULL
681};