blob: b4e20be3880429173770d52b2eeba39c29990eda [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 Hofmeyr07351d82019-10-21 05:53:58 +020028#define mncc_sends_to_cc(MSG_TYPE, MNCC) do { \
29 (MNCC)->msg_type = MSG_TYPE; \
30 log("MSC <-- MNCC: callref 0x%x: %s\n%s", (MNCC)->callref, \
31 get_mncc_name((MNCC)->msg_type), \
32 (MNCC)->sdp); \
33 mncc_tx_to_cc(net, MNCC); \
34 } while(0)
Neels Hofmeyra99b4272017-11-21 17:13:23 +010035
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010036/*
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +010037static void on_call_release_mncc_sends_to_cc(uint32_t msg_type, struct gsm_mncc *mncc)
38{
39 mncc->msg_type = msg_type;
40 on_call_release_mncc_sends_to_cc_data = mncc;
41}
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010042*/
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +010043
Neels Hofmeyra99b4272017-11-21 17:13:23 +010044#define IMSI "901700000010650"
45
Neels Hofmeyr11bf0bc2019-10-21 05:55:49 +020046static void lu_utran_tmsi()
Neels Hofmeyra99b4272017-11-21 17:13:23 +010047{
48 struct vlr_subscr *vsub;
49
50 net->authentication_required = true;
51 net->vlr->cfg.assign_tmsi = true;
Neels Hofmeyr7814a832018-12-26 00:40:18 +010052 rx_from_ran = OSMO_RAT_UTRAN_IU;
Neels Hofmeyra99b4272017-11-21 17:13:23 +010053
54 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
55 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +010056 gsup_expect_tx("080108" "09710000000156f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyra99b4272017-11-21 17:13:23 +010057 ms_sends_msg("0508" /* MM LU */
58 "7" /* ciph key seq: no key available */
59 "0" /* LU type: normal */
60 "09f107" "0017" /* LAI, LAC */
61 "57" /* classmark 1: R99, early classmark, no power lvl */
62 "089910070000106005" /* IMSI */
63 "3303575886" /* classmark 2 */
64 );
65 OSMO_ASSERT(gsup_tx_confirmed);
66 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
67
68 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
69 /* based on auc_3g:
70 * K = 'EB215756028D60E3275E613320AEC880',
71 * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308'
72 * SQN = 0
73 */
74 auth_request_sent = false;
75 auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d";
76 auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919";
77 gsup_rx("0a"
78 /* imsi */
79 "0108" "09710000000156f0"
80 /* 5 auth vectors... */
81 /* TL TL rand */
82 "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d"
83 /* TL sres TL kc */
84 "2104" "9b36efdf" "2208" "059a4f668f6fbe39"
85 /* TL 3G IK */
86 "2310" "27497388b6cb044648f396aa155b95ef"
87 /* TL 3G CK */
88 "2410" "f64735036e5871319c679f4742a75ea1"
89 /* TL AUTN */
90 "2510" "8704f5ba55f30000d2ee44b22c8ea919"
91 /* TL RES */
92 "2708" "e229c19e791f2e41"
93 /* TL TL rand */
94 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
95 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
96 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
97 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
98 "2510" "1843a645b98d00005b2d666af46c45d9"
99 "2708" "7db47cf7f81e4dc7"
100 "0362" "2010" "efa9c29a9742148d5c9070348716e1bb"
101 "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d"
102 "2310" "eb50e770ddcc3060101d2f43b6c2b884"
103 "2410" "76542abce5ff9345b0e8947f4c6e019c"
104 "2510" "f9375e6d41e1000096e7fe4ff1c27e39"
105 "2708" "706f996719ba609c"
106 "0362" "2010" "f023d5a3b24726e0631b64b3840f8253"
107 "2104" "d570c03f" "2208" "ec011be8919883d6"
108 "2310" "c4e58af4ba43f3bcd904e16984f086d7"
109 "2410" "0593f65e752e5cb7f473862bda05aa0a"
110 "2510" "541ff1f077270000c5ea00d658bc7e9a"
111 "2708" "3fd26072eaa2a04d"
112 "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e"
113 "2104" "b072446f220823f39f9f425ad6e6"
114 "2310" "65af0527fda95b0dc5ae4aa515cdf32f"
115 "2410" "537c3b35a3b13b08d08eeb28098f45cc"
116 "2510" "4bf4e564f75300009bc796706bc65744"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100117 "2708" "0edb0eadbea94ac2"
118 HLR_TO_VLR,
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100119 NULL);
120 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
121 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
122
123 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100124 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100125 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100126 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100127 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
128
129 btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100130 gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100131 ms_sends_security_mode_complete();
132 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
133 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
134
135 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100136 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
137 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100138 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
139
140 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100141 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100142
143 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
144
145 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
146 EXPECT_CONN_COUNT(1);
147 EXPECT_ACCEPTED(false);
148
149 btw("MS sends TMSI Realloc Complete");
150 iu_release_expected = true;
151 iu_release_sent = false;
152 ms_sends_msg("055b");
153 VERBOSE_ASSERT(iu_release_sent, == true, "%d"); \
154
155 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100156 ran_sends_clear_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100157 EXPECT_CONN_COUNT(0);
158
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100159 vsub = vlr_subscr_find_by_imsi(net->vlr, IMSI, __func__);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100160 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
161 VERBOSE_ASSERT(strcmp(vsub->imsi, IMSI), == 0, "%d");
Max7d41d872018-12-19 11:48:33 +0100162 VAL_ASSERT("LAC", vsub->cgi.lai.lac, == 23, "%u");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100163 vlr_subscr_put(vsub, __func__);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100164}
165
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100166static void test_call_mo()
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100167{
168 struct gsm_mncc mncc = {
169 .imsi = IMSI,
170 };
171
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100172 comment_start();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100173
174 fake_time_start();
175
Neels Hofmeyr11bf0bc2019-10-21 05:55:49 +0200176 lu_utran_tmsi();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100177
178 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
179 auth_request_sent = false;
180 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
181 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
182 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100183 ms_sends_msg("052471"
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100184 "03575886" /* classmark 2 */
185 "089910070000106005" /* IMSI */);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100186 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
187 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
188
189 btw("needs auth, not yet accepted");
190 EXPECT_ACCEPTED(false);
191
192 /* On UTRAN */
193 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100194 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100195 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100196 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100197 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
198
199 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
200 ms_sends_security_mode_complete();
201 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
202
203 BTW("a call is initiated");
204
205 btw("SETUP gets forwarded to MNCC");
206 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND);
207 ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */
208 "0406600402000581" /* Bearer Capability */
209 "5e038121f3" /* Called Number BCD */
210 "15020100" /* CC Capabilities */
211 "4008" /* Supported Codec List */
212 "04026000" /* UMTS: AMR 2 | AMR */
213 "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */
214 );
215 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
216 mncc.callref = cc_to_mncc_tx_got_callref;
217
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200218 btw("MNCC replies with MNCC_RTP_CREATE, causing MGW endpoint CRCX to RAN");
219 expect_crcx(RTP_TO_RAN);
220 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
221 OSMO_ASSERT(got_crcx);
222
223 btw("MGW acknowledges the CRCX, triggering Assignment");
224 expect_iu_rab_assignment();
225 crcx_ok(RTP_TO_RAN);
226 OSMO_ASSERT(iu_rab_assignment_sent);
227
228 btw("Assignment succeeds, triggering CRCX to CN");
229 expect_crcx(RTP_TO_CN);
230 ms_sends_assignment_complete(CODEC_AMR_8000_1);
231 OSMO_ASSERT(got_crcx);
232
233 btw("CN RTP address is available, trigger MNCC_RTP_CREATE");
234 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
235 crcx_ok(RTP_TO_CN);
236
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100237 btw("MNCC says that's fine");
238 dtap_expect_tx("8302" /* CC: Call Proceeding */);
239 mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc);
240 OSMO_ASSERT(dtap_tx_confirmed);
241
242 fake_time_passes(1, 23);
243
244 btw("The other call leg got established (not shown here), MNCC tells us so");
245 dtap_expect_tx("8301" /* CC: Call Alerting */);
246 mncc_sends_to_cc(MNCC_ALERT_REQ, &mncc);
247 OSMO_ASSERT(dtap_tx_confirmed);
248
249 dtap_expect_tx("8307" /* CC: Connect */);
250 mncc_sends_to_cc(MNCC_SETUP_RSP, &mncc);
251 OSMO_ASSERT(dtap_tx_confirmed);
252
253 fake_time_passes(1, 23);
254
255 cc_to_mncc_expect_tx("", MNCC_SETUP_COMPL_IND);
256 ms_sends_msg("03cf" /* CC: Connect Acknowledge */);
257 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
258
259 BTW("RTP stream goes ahead, not shown here.");
260 fake_time_passes(123, 45);
261
262 BTW("Call ends");
263 cc_to_mncc_expect_tx("", MNCC_DISC_IND);
264 ms_sends_msg("032502e090" /* CC: Disconnect, cause: Normal Call Clearing */);
265 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
266
267 dtap_expect_tx("832d" /* CC: Release */);
268 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
269 OSMO_ASSERT(dtap_tx_confirmed);
270
271 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
272 expect_iu_release();
273 ms_sends_msg("036a" /* CC: Release Complete */);
274 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
275 OSMO_ASSERT(iu_release_sent);
276
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100277 ran_sends_clear_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100278 EXPECT_CONN_COUNT(0);
279 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100280 comment_end();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100281}
282
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100283static void test_call_mt()
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100284{
285 struct gsm_mncc mncc = {
286 .imsi = IMSI,
287 .callref = 0x423,
288 };
289
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100290 comment_start();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100291
292 fake_time_start();
293
Neels Hofmeyr11bf0bc2019-10-21 05:55:49 +0200294 lu_utran_tmsi();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100295
296 BTW("after a while, MNCC asks us to setup a call, causing Paging");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100297
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100298 paging_expect_imsi(IMSI);
299 paging_sent = false;
300 mncc_sends_to_cc(MNCC_SETUP_REQ, &mncc);
301
302 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100303
304 btw("MS replies with Paging Response, and VLR sends Auth Request");
305 auth_request_sent = false;
306 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
307 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
308 ms_sends_msg("062707"
309 "03575886" /* classmark 2 */
310 "089910070000106005" /* IMSI */);
311 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
312
313 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100314 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100315 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100316 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100317
318 btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup");
319 dtap_expect_tx("0305" /* CC: Setup */);
320 ms_sends_security_mode_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100321
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200322 btw("MS confirms call, we create a RAN-side RTP and forward MNCC_CALL_CONF_IND");
323 expect_crcx(RTP_TO_RAN);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100324 cc_to_mncc_expect_tx(IMSI, MNCC_CALL_CONF_IND);
325 ms_sends_msg("8348" /* CC: Call Confirmed */
326 "0406600402000581" /* Bearer Capability */
327 "15020100" /* Call Control Capabilities */
328 "40080402600400021f00" /* Supported Codec List */);
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200329 OSMO_ASSERT(got_crcx);
330 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
331
332 btw("MNCC sends MNCC_RTP_CREATE");
333 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
334
335 btw("MGW acknowledges the CRCX to RAN, triggering Assignment");
336 expect_iu_rab_assignment();
337 crcx_ok(RTP_TO_RAN);
338 OSMO_ASSERT(iu_rab_assignment_sent);
339
340 btw("Assignment completes, triggering CRCX to CN");
341 expect_crcx(RTP_TO_CN);
342 ms_sends_assignment_complete(CODEC_AMR_8000_1);
343 OSMO_ASSERT(got_crcx);
344
345 btw("When the CN side RTP address is known, send MNCC_RTP_CREATE");
346 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
347 crcx_ok(RTP_TO_CN);
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100348
349 fake_time_passes(1, 23);
350
351 cc_to_mncc_expect_tx("", MNCC_ALERT_IND);
352 ms_sends_msg("8381" /* CC: Alerting */);
353
354 fake_time_passes(1, 23);
355
356 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_CNF);
357 ms_sends_msg("83c7" /* CC: Connect */);
358
359 dtap_expect_tx("030f" /* CC: Connect Acknowledge */);
360 mncc_sends_to_cc(MNCC_SETUP_COMPL_REQ, &mncc);
361
362 BTW("RTP stream goes ahead, not shown here.");
363 fake_time_passes(123, 45);
364
365 BTW("Call ends");
366 cc_to_mncc_expect_tx("", MNCC_DISC_IND);
367 ms_sends_msg("832502e090" /* CC: Disconnect, cause: Normal Call Clearing */);
368 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
369
370 dtap_expect_tx("032d" /* CC: Release */);
371 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
372 OSMO_ASSERT(dtap_tx_confirmed);
373
374 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
375 expect_iu_release();
376 ms_sends_msg("836a" /* CC: Release Complete */);
377 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
378 OSMO_ASSERT(iu_release_sent);
379
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100380 ran_sends_clear_complete();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100381 EXPECT_CONN_COUNT(0);
382 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100383 comment_end();
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100384}
385
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100386static void test_call_mt2()
387{
388 struct gsm_mncc mncc = {
389 .imsi = IMSI,
390 .callref = 0x423,
391 };
392
393 comment_start();
394
395 fake_time_start();
396
Neels Hofmeyr11bf0bc2019-10-21 05:55:49 +0200397 lu_utran_tmsi();
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100398
399 BTW("after a while, MNCC asks us to setup a call, causing Paging");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100400
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100401 paging_expect_imsi(IMSI);
402 paging_sent = false;
403 mncc_sends_to_cc(MNCC_SETUP_REQ, &mncc);
404
405 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100406
407 btw("MS replies with Paging Response, and VLR sends Auth Request");
408 auth_request_sent = false;
409 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
410 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
411 ms_sends_msg("062707"
412 "03575886" /* classmark 2 */
413 "089910070000106005" /* IMSI */);
414 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
415
416 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
417 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
418 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
419 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
420
421 btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup");
422 dtap_expect_tx("0305" /* CC: Setup */);
423 ms_sends_security_mode_complete();
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100424
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200425 btw("MS confirms call, we create a RAN-side RTP and forward MNCC_CALL_CONF_IND");
426 expect_crcx(RTP_TO_RAN);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100427 cc_to_mncc_expect_tx(IMSI, MNCC_CALL_CONF_IND);
428 ms_sends_msg("8348" /* CC: Call Confirmed */
429 "0406600402000581" /* Bearer Capability */
430 "15020100" /* Call Control Capabilities */
431 "40080402600400021f00" /* Supported Codec List */);
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200432 OSMO_ASSERT(got_crcx);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100433 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
434
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200435 btw("MNCC sends MNCC_RTP_CREATE");
436 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
437
438 btw("MGW acknowledges the CRCX to RAN, triggering Assignment");
439 expect_iu_rab_assignment();
440 crcx_ok(RTP_TO_RAN);
441 OSMO_ASSERT(iu_rab_assignment_sent);
442
443 btw("Assignment completes, triggering CRCX to CN");
444 expect_crcx(RTP_TO_CN);
445 ms_sends_assignment_complete(CODEC_AMR_8000_1);
446 OSMO_ASSERT(got_crcx);
447
448 btw("When the CN side RTP address is known, send MNCC_RTP_CREATE");
449 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
450 crcx_ok(RTP_TO_CN);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100451 fake_time_passes(1, 23);
452
453 cc_to_mncc_expect_tx("", MNCC_ALERT_IND);
454 ms_sends_msg("8381" /* CC: Alerting */);
455 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
456
457 fake_time_passes(15, 23);
458
459 btw("The call failed, the BSC sends a BSSMAP Clear Request");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100460 /* FIXME: in this scenario, we send an MNCC_REL_CNF even though MNCC never asked us to MNCC_REL_REQ. Legacy
461 * behavior did get to both MNCC_REL_IND, then an MNCC_REL_REQ from MNCC as well as a final MNCC_REL_CNF, but
462 * this only worked synchronously, i.e. only with internal MNCC. Instead of mimicking that, we need a proper
463 * async solution that also works with a PBX. */
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100464 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
Keith Whyteff17f8f2019-08-01 12:20:25 +0200465 dtap_expect_tx("032d0802e1af"); /* CC: Release */
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100466 expect_iu_release();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100467 msc_a_release_cn(msub_msc_a(g_msub));
468 OSMO_ASSERT(dtap_tx_confirmed);
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100469 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
470 OSMO_ASSERT(iu_release_sent);
471
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100472 ran_sends_clear_complete();
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100473 EXPECT_CONN_COUNT(0);
474
475 /* Make sure a pending release timer doesn't fire later to access freed data */
476 fake_time_passes(15, 23);
477
478 clear_vlr();
479 comment_end();
480}
481
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100482static void test_call_mo_to_unknown()
483{
484 struct gsm_mncc mncc = {
485 .imsi = IMSI,
486 };
487
488 comment_start();
489
490 fake_time_start();
491
Neels Hofmeyr11bf0bc2019-10-21 05:55:49 +0200492 lu_utran_tmsi();
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100493
494 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
495 auth_request_sent = false;
496 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
497 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
498 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100499 ms_sends_msg("052471"
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100500 "03575886" /* classmark 2 */
501 "089910070000106005" /* IMSI */);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100502 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
503 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
504
505 btw("needs auth, not yet accepted");
506 EXPECT_ACCEPTED(false);
507
508 /* On UTRAN */
509 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
510 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
511 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
512 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
513 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
514
515 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
516 ms_sends_security_mode_complete();
517 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
518
519 BTW("a call is initiated");
520
521 btw("SETUP gets forwarded to MNCC");
522 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND);
523 ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */
524 "0406600402000581" /* Bearer Capability */
525 "5e038121f3" /* Called Number BCD */
526 "15020100" /* CC Capabilities */
527 "4008" /* Supported Codec List */
528 "04026000" /* UMTS: AMR 2 | AMR */
529 "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */
530 );
531 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
532 mncc.callref = cc_to_mncc_tx_got_callref;
533
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200534 btw("MNCC replies with MNCC_RTP_CREATE, causing MGW endpoint CRCX to RAN");
535 expect_crcx(RTP_TO_RAN);
536 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
537 OSMO_ASSERT(got_crcx);
538
539 btw("MGW acknowledges the CRCX, triggering Assignment");
540 expect_iu_rab_assignment();
541 crcx_ok(RTP_TO_RAN);
542 OSMO_ASSERT(iu_rab_assignment_sent);
543
544 btw("Assignment succeeds, triggering CRCX to CN");
545 expect_crcx(RTP_TO_CN);
546 ms_sends_assignment_complete(CODEC_AMR_8000_1);
547 OSMO_ASSERT(got_crcx);
548
549 btw("CN RTP address is available, trigger MNCC_RTP_CREATE");
550 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
551 crcx_ok(RTP_TO_CN);
552
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100553 btw("MNCC says that's fine");
554 dtap_expect_tx("8302" /* CC: Call Proceeding */);
555 mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc);
556 OSMO_ASSERT(dtap_tx_confirmed);
557
558 btw("But the other side's MSISDN could not be resolved, MNCC tells us to cancel");
559 dtap_expect_tx("832d" /* CC: Release Request */);
560 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
561
562 dtap_expect_tx("832d" /* CC: Release Request */);
563 fake_time_passes(10, 23);
564
565 expect_iu_release();
566 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
567 ms_sends_msg("036a" /* CC: Release Complete */);
568 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
569 OSMO_ASSERT(iu_release_sent);
570 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
571
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100572 ran_sends_clear_complete();
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100573 EXPECT_CONN_COUNT(0);
574 clear_vlr();
575 comment_end();
576}
577
578static void test_call_mo_to_unknown_timeout()
579{
580 struct gsm_mncc mncc = {
581 .imsi = IMSI,
582 };
583
584 comment_start();
585
586 fake_time_start();
587
Neels Hofmeyr11bf0bc2019-10-21 05:55:49 +0200588 lu_utran_tmsi();
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100589
590 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
591 auth_request_sent = false;
592 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
593 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
594 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100595 ms_sends_msg("052471"
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100596 "03575886" /* classmark 2 */
597 "089910070000106005" /* IMSI */);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100598 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
599 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
600
601 btw("needs auth, not yet accepted");
602 EXPECT_ACCEPTED(false);
603
604 /* On UTRAN */
605 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
606 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
607 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
608 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
609 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
610
611 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
612 ms_sends_security_mode_complete();
613 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
614
615 BTW("a call is initiated");
616
617 btw("SETUP gets forwarded to MNCC");
618 cc_to_mncc_expect_tx(IMSI, MNCC_SETUP_IND);
619 ms_sends_msg("0385" /* CC, seq = 2 -> 0x80 | CC Setup = 0x5 */
620 "0406600402000581" /* Bearer Capability */
621 "5e038121f3" /* Called Number BCD */
622 "15020100" /* CC Capabilities */
623 "4008" /* Supported Codec List */
624 "04026000" /* UMTS: AMR 2 | AMR */
625 "00021f00" /* GSM: HR AMR | FR AMR | GSM EFR | GSM HR | GSM FR */
626 );
627 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
628 mncc.callref = cc_to_mncc_tx_got_callref;
629
Neels Hofmeyr3f391dd2019-08-29 03:53:11 +0200630 btw("MNCC replies with MNCC_RTP_CREATE, causing MGW endpoint CRCX to RAN");
631 expect_crcx(RTP_TO_RAN);
632 mncc_sends_to_cc(MNCC_RTP_CREATE, &mncc);
633 OSMO_ASSERT(got_crcx);
634
635 btw("MGW acknowledges the CRCX, triggering Assignment");
636 expect_iu_rab_assignment();
637 crcx_ok(RTP_TO_RAN);
638 OSMO_ASSERT(iu_rab_assignment_sent);
639
640 btw("Assignment succeeds, triggering CRCX to CN");
641 expect_crcx(RTP_TO_CN);
642 ms_sends_assignment_complete(CODEC_AMR_8000_1);
643 OSMO_ASSERT(got_crcx);
644
645 btw("CN RTP address is available, trigger MNCC_RTP_CREATE");
646 cc_to_mncc_expect_tx("", MNCC_RTP_CREATE);
647 crcx_ok(RTP_TO_CN);
648
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100649 btw("MNCC says that's fine");
650 dtap_expect_tx("8302" /* CC: Call Proceeding */);
651 mncc_sends_to_cc(MNCC_CALL_PROC_REQ, &mncc);
652 OSMO_ASSERT(dtap_tx_confirmed);
653
654 btw("But the other side's MSISDN could not be resolved, MNCC tells us to cancel");
655 dtap_expect_tx("832d" /* CC: Release Request */);
656 mncc_sends_to_cc(MNCC_REL_REQ, &mncc);
657
658 btw("Despite our repeated CC Release Requests, the MS does not respond anymore");
659 dtap_expect_tx("832d" /* CC: Release Request */);
660 fake_time_passes(10, 23);
661
662 btw("The CC Release times out and we still properly clear the conn");
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100663 cc_to_mncc_expect_tx("", MNCC_REL_CNF);
Neels Hofmeyrd6a769b2018-03-12 23:59:07 +0100664 expect_iu_release();
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100665 fake_time_passes(10, 23);
666 OSMO_ASSERT(cc_to_mncc_tx_confirmed);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100667 OSMO_ASSERT(iu_release_sent);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100668
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100669 ran_sends_clear_complete();
Neels Hofmeyrd6a769b2018-03-12 23:59:07 +0100670 EXPECT_CONN_COUNT(0);
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100671 clear_vlr();
672 comment_end();
673}
674
675
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100676msc_vlr_test_func_t msc_vlr_tests[] = {
677 test_call_mo,
678 test_call_mt,
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100679 test_call_mt2,
Neels Hofmeyreb1cfdb2018-03-15 13:42:10 +0100680 test_call_mo_to_unknown,
681 test_call_mo_to_unknown_timeout,
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100682 NULL
683};