blob: 45aaa8ca5348e536f67632b47e0363ebbb90f4b4 [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_hlr_rej_auth_info_unknown_imsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010028 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010029
30 net->authentication_required = true;
31
32 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
33 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010034 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010035 ms_sends_msg("050802008168000130089910070000006402");
36 OSMO_ASSERT(gsup_tx_confirmed);
37 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
38
39 btw("HLR sends _SEND_AUTH_INFO_ERROR = unknown IMSI");
40 auth_request_sent = false;
Philipp Maierfbf66102017-04-09 12:32:51 +020041 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010042 gsup_rx("09" "010809710000004026f0" "020102" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010043 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
44 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +020045 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010046
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010047 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010048 EXPECT_CONN_COUNT(0);
49 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010050 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010051}
52
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010053static void test_hlr_rej_auth_info_net_fail()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010054{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010055 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010056
57 net->authentication_required = true;
58
59 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
60 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010061 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010062 ms_sends_msg("050802008168000130089910070000006402");
63 OSMO_ASSERT(gsup_tx_confirmed);
64 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
65
66 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
67 auth_request_sent = false;
Philipp Maierfbf66102017-04-09 12:32:51 +020068 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010069 gsup_rx("09" "010809710000004026f0" "020111" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010070 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
71 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +020072 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010073
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010074 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010075 EXPECT_CONN_COUNT(0);
76 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010077 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010078}
79
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010080static void test_hlr_rej_auth_info_net_fail_no_reuse_tuples()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010081{
82 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010083 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010084
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010085 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010086
87 net->authentication_required = true;
88 net->vlr->cfg.auth_reuse_old_sets_on_error = false;
Neels Hofmeyr33f53412017-10-29 02:11:18 +010089 net->vlr->cfg.auth_tuple_max_reuse_count = 0;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010090
91 BTW("Submit a used auth tuple in the VLR");
92 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
93 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010094 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010095 ms_sends_msg("050802008168000130089910070000006402");
96 OSMO_ASSERT(gsup_tx_confirmed);
97 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
98
99 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
100 auth_request_sent = false;
101 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
102 auth_request_expect_autn = NULL;
103 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
104 gsup_rx("0a"
105 /* imsi */
106 "0108" "09710000004026f0"
107 /* auth vectors... */
108 /* TL TL rand */
109 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
110 /* TL sres TL kc */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100111 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" HLR_TO_VLR,
112 NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100113 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
114 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
115
116 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100117 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100118 ms_sends_msg("05542d8b2c3e");
119 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
120
121 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100122 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
123 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100124 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
125
126 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200127 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100128 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200129 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100130
131 btw("LU was successful, and the conn has already been closed");
132 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100133 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100134 EXPECT_CONN_COUNT(0);
135
136
137 BTW("Now one auth tuple is available, but used.");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100138 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100139 OSMO_ASSERT(vsub);
140 OSMO_ASSERT(vsub->last_tuple);
141 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
142 /* no need to look at all auth tuples, the ongoing test would take an
143 * unexpected course if there were more. */
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100144 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100145
146 BTW("Another LU wants to get new tuples; HLR sends Network Failure, we reject.");
147
148 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
149 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100150 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100151 ms_sends_msg("050802008168000130089910070000006402");
152 OSMO_ASSERT(gsup_tx_confirmed);
153 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
154
155 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
156 auth_request_sent = false;
Philipp Maierfbf66102017-04-09 12:32:51 +0200157 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100158 gsup_rx("09" "010809710000004026f0" "020111" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100159 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
160 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200161 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100162
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100163 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100164 EXPECT_CONN_COUNT(0);
165 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100166 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100167}
168
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100169static void test_hlr_rej_auth_info_unkown_imsi_no_reuse_tuples()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100170{
171 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100172 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100173
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100174 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100175
176 net->authentication_required = true;
177 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
Neels Hofmeyr33f53412017-10-29 02:11:18 +0100178 net->vlr->cfg.auth_tuple_max_reuse_count = 0;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100179
180 BTW("Submit a used auth tuple in the VLR");
181 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
182 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100183 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100184 ms_sends_msg("050802008168000130089910070000006402");
185 OSMO_ASSERT(gsup_tx_confirmed);
186 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
187
188 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
189 auth_request_sent = false;
190 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
191 auth_request_expect_autn = NULL;
192 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
193 gsup_rx("0a"
194 /* imsi */
195 "0108" "09710000004026f0"
196 /* auth vectors... */
197 /* TL TL rand */
198 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
199 /* TL sres TL kc */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100200 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" HLR_TO_VLR,
201 NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100202 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
203 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
204
205 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100206 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100207 ms_sends_msg("05542d8b2c3e");
208 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
209
210 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100211 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
212 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100213 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
214
215 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200216 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100217 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200218 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100219
220 btw("LU was successful, and the conn has already been closed");
221 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100222 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100223 EXPECT_CONN_COUNT(0);
224
225
226 BTW("Now one auth tuple is available, but used.");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100227 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100228 OSMO_ASSERT(vsub);
229 OSMO_ASSERT(vsub->last_tuple);
230 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
231 /* no need to look at all auth tuples, the ongoing test would take an
232 * unexpected course if there were more. */
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100233 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100234
235 BTW("Another LU wants to get new tuples; HLR sends IMSI Unknown. Even though we would re-use an old tuple, reject the unknown IMSI.");
236 VERBOSE_ASSERT(net->vlr->cfg.auth_reuse_old_sets_on_error, == true, "%d");
237
238 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
239 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100240 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100241 ms_sends_msg("050802008168000130089910070000006402");
242 OSMO_ASSERT(gsup_tx_confirmed);
243 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
244
245 btw("HLR sends _SEND_AUTH_INFO_ERROR = unknown IMSI");
246 auth_request_sent = false;
Philipp Maierfbf66102017-04-09 12:32:51 +0200247 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100248 gsup_rx("09" "010809710000004026f0" "020102" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100249 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
250 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200251 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100252
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100253 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100254 EXPECT_CONN_COUNT(0);
255 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100256 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100257}
258
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100259static void test_hlr_acc_but_no_auth_tuples()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100260{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100261 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100262
263 net->authentication_required = true;
264 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
Neels Hofmeyr33f53412017-10-29 02:11:18 +0100265 net->vlr->cfg.auth_tuple_max_reuse_count = 0;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100266
267 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
268 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100269 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100270 ms_sends_msg("050802008168000130089910070000006402");
271 OSMO_ASSERT(gsup_tx_confirmed);
272 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
273
274 btw("from HLR, rx _SEND_AUTH_INFO_RESULT but it lacks auth tuples");
275 auth_request_sent = false;
Philipp Maierfbf66102017-04-09 12:32:51 +0200276 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100277 gsup_rx("0a"
278 /* imsi */
279 "0108" "09710000004026f0"
280 /* NO auth vectors */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100281 HLR_TO_VLR,
282 NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100283 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
284 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200285 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100286
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100287 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100288 EXPECT_CONN_COUNT(0);
289 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100290 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100291}
292
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100293static void test_hlr_rej_auth_info_net_fail_reuse_tuples()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100294{
295 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100296 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100297
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100298 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100299
300 net->authentication_required = true;
301 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
Neels Hofmeyr33f53412017-10-29 02:11:18 +0100302 net->vlr->cfg.auth_tuple_max_reuse_count = 0;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100303
304 BTW("Submit a used auth tuple in the VLR");
305 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
306 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100307 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100308 ms_sends_msg("050802008168000130089910070000006402");
309 OSMO_ASSERT(gsup_tx_confirmed);
310 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
311
312 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
313 auth_request_sent = false;
314 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
315 auth_request_expect_autn = NULL;
316 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
317 gsup_rx("0a"
318 /* imsi */
319 "0108" "09710000004026f0"
320 /* auth vectors... */
321 /* TL TL rand */
322 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
323 /* TL sres TL kc */
324 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100325 HLR_TO_VLR,
326 NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100327 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
328 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
329
330 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100331 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100332 ms_sends_msg("05542d8b2c3e");
333 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
334
335 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100336 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
337 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100338 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
339
340 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200341 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100342 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200343 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100344
345 btw("LU was successful, and the conn has already been closed");
346 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100347 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100348 EXPECT_CONN_COUNT(0);
349
350
351 BTW("Now one auth tuple is available, but used.");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100352 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100353 OSMO_ASSERT(vsub);
354 OSMO_ASSERT(vsub->last_tuple);
355 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
356 /* no need to look at all auth tuples, the ongoing test would take an
357 * unexpected course if there were more. */
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100358 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100359
360 BTW("Another LU wants to get new tuples; even though HLR sends Network Failure, we are reusing the old tuples.");
361
362 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
363 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100364 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100365 ms_sends_msg("050802008168000130089910070000006402");
366 OSMO_ASSERT(gsup_tx_confirmed);
367 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
368
369 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
370 auth_request_sent = false;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100371 gsup_rx("09" "010809710000004026f0" "020111" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100372 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
373 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
374
375 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100376 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100377 ms_sends_msg("05542d8b2c3e");
378 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
379
380 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100381 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
382 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100383 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
384
385 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200386 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100387 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200388 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100389
390 btw("LU was successful, and the conn has already been closed");
391 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100392 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100393 EXPECT_CONN_COUNT(0);
394
395 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100396 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100397}
398
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100399static void test_hlr_rej_lu()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100400{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100401 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100402
403 btw("Location Update request causes a GSUP LU request to HLR");
404 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100405 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100406 ms_sends_msg("050802008168000130089910070000006402");
407 OSMO_ASSERT(gsup_tx_confirmed);
408 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
409
410 btw("HLR sends UPDATE_LOCATION_ERROR");
Philipp Maierfbf66102017-04-09 12:32:51 +0200411 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100412 gsup_rx("05" "010809710000004026f0" "020102" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100413 NULL);
414 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200415 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100416 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100417 EXPECT_CONN_COUNT(0);
418
419 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100420 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100421}
422
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100423static void test_hlr_no_insert_data()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100424{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100425 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100426
427 btw("Location Update request causes a GSUP LU request to HLR");
428 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100429 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100430 ms_sends_msg("050802008168000130089910070000006402");
431 OSMO_ASSERT(gsup_tx_confirmed);
432 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
433
434 btw("HLR sends only _UPDATE_LOCATION_RESULT, no INSERT DATA");
Philipp Maierfbf66102017-04-09 12:32:51 +0200435 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100436 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200437 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100438
439 /* TODO should we wait for OSMO_GSUP_MSGT_INSERT_DATA_REQUEST? */
440
441 btw("LU was successful, and the conn has already been closed");
442 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
443
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100444 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100445 EXPECT_CONN_COUNT(0);
446 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100447 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100448}
449
450msc_vlr_test_func_t msc_vlr_tests[] = {
451 test_hlr_rej_auth_info_unknown_imsi,
452 test_hlr_rej_auth_info_net_fail,
453 test_hlr_rej_auth_info_net_fail_reuse_tuples,
454 test_hlr_rej_auth_info_net_fail_no_reuse_tuples,
455 test_hlr_rej_auth_info_unkown_imsi_no_reuse_tuples,
456 test_hlr_acc_but_no_auth_tuples,
457 test_hlr_rej_lu,
458 test_hlr_no_insert_data,
459 NULL
460};