blob: ee5af1ecbd8a06b75621a91f1e8d99d898d63814 [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_gsm_authen()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010027{
28 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010029 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010030
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010031 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010032
33 net->authentication_required = true;
34
35 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
36 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010037 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +010038 ms_sends_msg("0508020081680001"
39 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
40 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010041 OSMO_ASSERT(gsup_tx_confirmed);
42 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
43
44 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
45 auth_request_sent = false;
46 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
47 auth_request_expect_autn = NULL;
48 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
49 gsup_rx("0a"
50 /* imsi */
51 "0108" "09710000004026f0"
52 /* 5 auth vectors... */
53 /* TL TL rand */
54 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
55 /* TL sres TL kc */
56 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
57 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
58 "2104" "20bde240" "2208" "07fa7502e07e1c00"
59 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
60 "2104" "a29514ae" "2208" "e2b234f807886400"
61 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
62 "2104" "5afc8d72" "2208" "2392f14f709ae000"
63 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010064 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
65 HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010066 NULL);
67 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
68 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
69
70 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010071 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010072 EXPECT_ACCEPTED(false);
73
74 thwart_rx_non_initial_requests();
75
76 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
77
78 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010079 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010080 ms_sends_msg("05542d8b2c3e");
81 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
82
83 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010084 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
85 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010086 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
87
88 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +020089 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010090 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +020091 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010092
93 btw("LU was successful, and the conn has already been closed");
94 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010095 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010096 EXPECT_CONN_COUNT(0);
97
98 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
99 auth_request_sent = false;
100 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
101 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100102 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100103 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
104 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
105
106 btw("needs auth, not yet accepted");
107 EXPECT_ACCEPTED(false);
108 thwart_rx_non_initial_requests();
109
110 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
111 gsup_expect_tx(NULL);
112 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
113 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
114
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700115 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +0700116 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100117 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100118
119 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100120 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100121 EXPECT_CONN_COUNT(0);
122
123 BTW("an SMS is sent, MS is paged");
124 paging_expect_imsi(imsi);
125 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100126 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100127 OSMO_ASSERT(vsub);
128 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
129
130 send_sms(vsub, vsub,
131 "Privacy in residential applications is a desirable"
132 " marketing option.");
133
134 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100135 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100136 vsub = NULL;
137 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100138
139 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100140 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100141 OSMO_ASSERT(vsub);
142 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100143 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100144
145 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
146 auth_request_sent = false;
147 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
148 ms_sends_msg("06270703305882089910070000006402");
149 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
150
151 btw("needs auth, not yet accepted");
152 EXPECT_ACCEPTED(false);
153 thwart_rx_non_initial_requests();
154
155 btw("MS sends Authen Response, VLR accepts and sends pending SMS");
156 dtap_expect_tx("09" /* SMS messages */
157 "01" /* CP-DATA */
158 "58" /* length */
159 "01" /* Network to MS */
160 "00" /* reference */
161 /* originator (gsm411_send_sms() hardcodes this weird nr) */
162 "0791" "447758100650" /* 447785016005 */
163 "00" /* dest */
164 /* SMS TPDU */
165 "4c" /* len */
166 "00" /* SMS deliver */
167 "05806470f1" /* originating address 46071 */
168 "00" /* TP-PID */
169 "00" /* GSM default alphabet */
170 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
171 "000000" /* H-M-S */
172 "00" /* GMT+0 */
173 "44" /* data length */
174 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
175 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
176 "0c7ac3e9e9b7db05");
177 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
178 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100179
180 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100181 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100182 OSMO_ASSERT(vsub);
183 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100184 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100185
186 btw("conn is still open to wait for SMS ack dance");
187 EXPECT_CONN_COUNT(1);
188
189 btw("MS replies with CP-ACK for received SMS");
190 ms_sends_msg("8904");
191 EXPECT_CONN_COUNT(1);
192
193 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
194 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200195 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100196 ms_sends_msg("890106020041020000");
197 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200198 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100199
200 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100201 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100202 EXPECT_CONN_COUNT(0);
203
204 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200205 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100206 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200207 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100208
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100209 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100210 EXPECT_CONN_COUNT(0);
211 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100212 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100213}
214
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100215static void test_gsm_authen_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100216{
217 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100218 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100219
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100220 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100221
222 net->authentication_required = true;
223 net->vlr->cfg.assign_tmsi = true;
224
225 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
226 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100227 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100228 ms_sends_msg("0508020081680001"
229 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
230 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100231 OSMO_ASSERT(gsup_tx_confirmed);
232 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
233
234 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
235 auth_request_sent = false;
236 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
237 auth_request_expect_autn = NULL;
238 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
239 gsup_rx("0a"
240 /* imsi */
241 "0108" "09710000004026f0"
242 /* 5 auth vectors... */
243 /* TL TL rand */
244 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
245 /* TL sres TL kc */
246 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
247 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
248 "2104" "20bde240" "2208" "07fa7502e07e1c00"
249 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
250 "2104" "a29514ae" "2208" "e2b234f807886400"
251 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
252 "2104" "5afc8d72" "2208" "2392f14f709ae000"
253 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100254 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
255 HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100256 NULL);
257 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
258 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
259
260 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100261 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100262 EXPECT_ACCEPTED(false);
263
264 thwart_rx_non_initial_requests();
265
266 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
267
268 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100269 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100270 ms_sends_msg("05542d8b2c3e");
271 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
272
273 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100274 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
275 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100276 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
277
278 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100279 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100280
281 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
282 EXPECT_CONN_COUNT(1);
283 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
284 EXPECT_ACCEPTED(false);
285 thwart_rx_non_initial_requests();
286
287 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100288 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100289 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
290 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
291 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
292 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100293 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100294
295 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200296 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100297 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200298 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100299
300 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100301 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100302 EXPECT_CONN_COUNT(0);
303
304 btw("Subscriber has the new TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100305 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100306 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
307 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
308 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
309 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100310 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100311
312 BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector");
313 auth_request_sent = false;
314 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
315 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100316 ms_sends_msg("05247403305886" "05f4" "03020100");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100317 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
318 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
319
320 btw("needs auth, not yet accepted");
321 EXPECT_ACCEPTED(false);
322 thwart_rx_non_initial_requests();
323
324 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
325 gsup_expect_tx(NULL);
326 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
327 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
328
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700329 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +0700330 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100331 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100332
333 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100334 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100335 EXPECT_CONN_COUNT(0);
336
337 BTW("an SMS is sent, MS is paged");
338 paging_expect_tmsi(0x03020100);
339 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100340 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100341 OSMO_ASSERT(vsub);
342 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
343
344 send_sms(vsub, vsub,
345 "Privacy in residential applications is a desirable"
346 " marketing option.");
347
348 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100349 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100350 vsub = NULL;
351 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100352
353 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100354 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100355 OSMO_ASSERT(vsub);
356 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100357 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100358
359 btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key");
360 auth_request_sent = false;
361 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
362 ms_sends_msg("06270703305882" "05f4" "03020100");
363 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
364
365 btw("needs auth, not yet accepted");
366 EXPECT_ACCEPTED(false);
367 thwart_rx_non_initial_requests();
368
369 btw("MS sends Authen Response, VLR accepts and sends pending SMS");
370 dtap_expect_tx("09" /* SMS messages */
371 "01" /* CP-DATA */
372 "58" /* length */
373 "01" /* Network to MS */
374 "00" /* reference */
375 /* originator (gsm411_send_sms() hardcodes this weird nr) */
376 "0791" "447758100650" /* 447785016005 */
377 "00" /* dest */
378 /* SMS TPDU */
379 "4c" /* len */
380 "00" /* SMS deliver */
381 "05806470f1" /* originating address 46071 */
382 "00" /* TP-PID */
383 "00" /* GSM default alphabet */
384 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
385 "000000" /* H-M-S */
386 "00" /* GMT+0 */
387 "44" /* data length */
388 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
389 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
390 "0c7ac3e9e9b7db05");
391 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
392 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100393
394 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100395 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100396 OSMO_ASSERT(vsub);
397 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100398 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100399
400 btw("conn is still open to wait for SMS ack dance");
401 EXPECT_CONN_COUNT(1);
402
403 btw("MS replies with CP-ACK for received SMS");
404 ms_sends_msg("8904");
405 EXPECT_CONN_COUNT(1);
406
407 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
408 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200409 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100410 ms_sends_msg("890106020041020000");
411 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200412 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100413
414 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100415 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100416 EXPECT_CONN_COUNT(0);
417
418 /* TODO: when the subscriber detaches, the vlr_subscr gets
419 * deallocated and we no longer know the TMSI. This case is covered by
420 * test_lu_unknown_tmsi(), so here I'd like to still have the TMSI.
421 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200422 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100423 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200424 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100425 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100426 EXPECT_CONN_COUNT(0);
427 */
428
429 BTW("subscriber sends LU Request, this time with the TMSI");
430 btw("Location Update request causes an Auth Req to MS");
431 lu_result_sent = RES_NONE;
432 auth_request_sent = false;
433 auth_request_expect_rand = "fa8f20b781b5881329d4fea26b1a3c51";
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100434 ms_sends_msg("0508020081680001"
435 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
436 "05f4" "03020100");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100437 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
438 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
439
440 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100441 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100442 ms_sends_msg("05545afc8d72");
443 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
444
445 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100446 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
447 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100448 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
449
450 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100451 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100452
453 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
454 EXPECT_CONN_COUNT(1);
455 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
456 EXPECT_ACCEPTED(false);
457 thwart_rx_non_initial_requests();
458
459 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100460 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100461 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
462 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
463 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
464 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100465 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100466
467 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200468 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100469 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200470 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100471
472 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100473 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100474 EXPECT_CONN_COUNT(0);
475
476 btw("subscriber has the new TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100477 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100478 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
479 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
480 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
481 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100482 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100483
484 BTW("subscriber detaches, using new TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200485 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100486 ms_sends_msg("050130" "05f4" "07060504");
Philipp Maierfbf66102017-04-09 12:32:51 +0200487 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100488
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100489 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100490 EXPECT_CONN_COUNT(0);
491 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100492 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100493}
494
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100495static void test_gsm_authen_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100496{
497 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100498 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100499
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100500 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100501
502 net->authentication_required = true;
503 net->vlr->cfg.check_imei_rqd = true;
504
505 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
506 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100507 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100508 ms_sends_msg("0508020081680001"
509 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
510 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100511 OSMO_ASSERT(gsup_tx_confirmed);
512 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
513
514 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
515 auth_request_sent = false;
516 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
517 auth_request_expect_autn = NULL;
518 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
519 gsup_rx("0a"
520 /* imsi */
521 "0108" "09710000004026f0"
522 /* 5 auth vectors... */
523 /* TL TL rand */
524 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
525 /* TL sres TL kc */
526 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
527 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
528 "2104" "20bde240" "2208" "07fa7502e07e1c00"
529 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
530 "2104" "a29514ae" "2208" "e2b234f807886400"
531 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
532 "2104" "5afc8d72" "2208" "2392f14f709ae000"
533 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100534 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
535 HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100536 NULL);
537 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
538 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
539
540 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100541 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100542 EXPECT_ACCEPTED(false);
543 thwart_rx_non_initial_requests();
544 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
545
546 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100547 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100548 ms_sends_msg("05542d8b2c3e");
549 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
550
551 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100552 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
553 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100554 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
555
556 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
557 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100558 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100559
560 btw("We will only do business when the IMEI is known");
561 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100562 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100563 OSMO_ASSERT(vsub);
564 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100565 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100566 EXPECT_ACCEPTED(false);
567 thwart_rx_non_initial_requests();
568
Oliver Smith7d053092018-12-14 17:37:38 +0100569 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Oliver Smithd1037052019-05-02 13:39:26 +0200570 gsup_expect_tx("30010809710000004026f050080724433224433224" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200571 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100572 EXPECT_ACCEPTED(false);
573 thwart_rx_non_initial_requests();
574
575 btw("HLR accepts the IMEI");
576 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100577 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200578 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100579
580 btw("LU was successful, and the conn has already been closed");
581 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100582 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100583 EXPECT_CONN_COUNT(0);
584
585 btw("Subscriber has the IMEI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100586 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100587 OSMO_ASSERT(vsub);
Oliver Smithd1037052019-05-02 13:39:26 +0200588 VERBOSE_ASSERT(strcmp(vsub->imei, "42342342342342"), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100589 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100590
591 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200592 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100593 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200594 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100595
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100596 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100597 EXPECT_CONN_COUNT(0);
598 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100599 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100600}
601
Oliver Smith7d053092018-12-14 17:37:38 +0100602static void test_gsm_authen_imei_nack()
603{
604 struct vlr_subscr *vsub;
605 const char *imsi = "901700000004620";
606
607 comment_start();
608
609 net->authentication_required = true;
610 net->vlr->cfg.check_imei_rqd = true;
611
612 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
613 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100614 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100615 ms_sends_msg("0508020081680001"
616 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
617 "089910070000006402");
618 OSMO_ASSERT(gsup_tx_confirmed);
619 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
620
621 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
622 auth_request_sent = false;
623 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
624 auth_request_expect_autn = NULL;
625 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
626 gsup_rx("0a"
627 /* imsi */
628 "0108" "09710000004026f0"
629 /* 5 auth vectors... */
630 /* TL TL rand */
631 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
632 /* TL sres TL kc */
633 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
634 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
635 "2104" "20bde240" "2208" "07fa7502e07e1c00"
636 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
637 "2104" "a29514ae" "2208" "e2b234f807886400"
638 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
639 "2104" "5afc8d72" "2208" "2392f14f709ae000"
640 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100641 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
642 HLR_TO_VLR,
Oliver Smith7d053092018-12-14 17:37:38 +0100643 NULL);
644 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
645 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
646
647 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100648 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100649 EXPECT_ACCEPTED(false);
650
651 thwart_rx_non_initial_requests();
652
653 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
654
655 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100656 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100657 ms_sends_msg("05542d8b2c3e");
658 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
659
660 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100661 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
662 "12010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100663 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
664
665 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
666 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100667 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100668
669 btw("We will only do business when the IMEI is known");
670 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100671 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100672 OSMO_ASSERT(vsub);
673 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100674 vlr_subscr_put(vsub, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100675 EXPECT_ACCEPTED(false);
676 thwart_rx_non_initial_requests();
677
678 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Oliver Smithd1037052019-05-02 13:39:26 +0200679 gsup_expect_tx("30010809710000004026f050080724433224433224" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100680 ms_sends_msg("0559084a32244332244302");
681 EXPECT_ACCEPTED(false);
682 thwart_rx_non_initial_requests();
683
684 expect_bssap_clear();
685 btw("HLR does not like the IMEI and sends NACK");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100686 gsup_rx("32010809710000004026f0510101" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100687 EXPECT_ACCEPTED(false);
688 thwart_rx_non_initial_requests();
689
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100690 ran_sends_clear_complete();
Oliver Smith7d053092018-12-14 17:37:38 +0100691 EXPECT_CONN_COUNT(0);
692 clear_vlr();
693 comment_end();
694}
695
696static void test_gsm_authen_imei_err()
697{
698 struct vlr_subscr *vsub;
699 const char *imsi = "901700000004620";
700
701 comment_start();
702
703 net->authentication_required = true;
704 net->vlr->cfg.check_imei_rqd = true;
705
706 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
707 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100708 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100709 ms_sends_msg("0508020081680001"
710 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
711 "089910070000006402");
712 OSMO_ASSERT(gsup_tx_confirmed);
713 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
714
715 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
716 auth_request_sent = false;
717 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
718 auth_request_expect_autn = NULL;
719 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
720 gsup_rx("0a"
721 /* imsi */
722 "0108" "09710000004026f0"
723 /* 5 auth vectors... */
724 /* TL TL rand */
725 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
726 /* TL sres TL kc */
727 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
728 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
729 "2104" "20bde240" "2208" "07fa7502e07e1c00"
730 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
731 "2104" "a29514ae" "2208" "e2b234f807886400"
732 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
733 "2104" "5afc8d72" "2208" "2392f14f709ae000"
734 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100735 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Oliver Smith7d053092018-12-14 17:37:38 +0100736 NULL);
737 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
738 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
739
740 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100741 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100742 EXPECT_ACCEPTED(false);
743
744 thwart_rx_non_initial_requests();
745
746 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
747
748 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100749 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100750 ms_sends_msg("05542d8b2c3e");
751 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
752
753 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100754 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
755 "12010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100756 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
757
758 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
759 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100760 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100761
762 btw("We will only do business when the IMEI is known");
763 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100764 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100765 OSMO_ASSERT(vsub);
766 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100767 vlr_subscr_put(vsub, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100768 EXPECT_ACCEPTED(false);
769 thwart_rx_non_initial_requests();
770
771 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Oliver Smithd1037052019-05-02 13:39:26 +0200772 gsup_expect_tx("30010809710000004026f050080724433224433224" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100773 ms_sends_msg("0559084a32244332244302");
774 EXPECT_ACCEPTED(false);
775 thwart_rx_non_initial_requests();
776
777 expect_bssap_clear();
778 btw("HLR can't parse the message and returns ERR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100779 gsup_rx("31010809710000004026f0020160" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100780 EXPECT_ACCEPTED(false);
781 thwart_rx_non_initial_requests();
782
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100783 ran_sends_clear_complete();
Oliver Smith7d053092018-12-14 17:37:38 +0100784 EXPECT_CONN_COUNT(0);
785 clear_vlr();
786 comment_end();
787}
788
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100789static void test_gsm_authen_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100790{
791 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100792 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100793
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100794 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100795
796 net->authentication_required = true;
797 net->vlr->cfg.assign_tmsi = true;
798 net->vlr->cfg.check_imei_rqd = true;
799
800 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
801 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100802 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100803 ms_sends_msg("0508020081680001"
804 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
805 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100806 OSMO_ASSERT(gsup_tx_confirmed);
807 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
808
809 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
810 auth_request_sent = false;
811 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
812 auth_request_expect_autn = NULL;
813 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
814 gsup_rx("0a"
815 /* imsi */
816 "0108" "09710000004026f0"
817 /* 5 auth vectors... */
818 /* TL TL rand */
819 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
820 /* TL sres TL kc */
821 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
822 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
823 "2104" "20bde240" "2208" "07fa7502e07e1c00"
824 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
825 "2104" "a29514ae" "2208" "e2b234f807886400"
826 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
827 "2104" "5afc8d72" "2208" "2392f14f709ae000"
828 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100829 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100830 NULL);
831 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
832 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
833
834 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100835 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100836 EXPECT_ACCEPTED(false);
837
838 thwart_rx_non_initial_requests();
839
840 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
841
842 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100843 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100844 ms_sends_msg("05542d8b2c3e");
845 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
846
847 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100848 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
849 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100850 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
851
852 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
853 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100854 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100855
856 btw("We will only do business when the IMEI is known");
857 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100858 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100859 OSMO_ASSERT(vsub);
860 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100861 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100862 EXPECT_ACCEPTED(false);
863 thwart_rx_non_initial_requests();
864
Oliver Smith7d053092018-12-14 17:37:38 +0100865 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Oliver Smithd1037052019-05-02 13:39:26 +0200866 gsup_expect_tx("30010809710000004026f050080724433224433224" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200867 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100868 EXPECT_ACCEPTED(false);
869 thwart_rx_non_initial_requests();
870
871 btw("HLR accepts the IMEI");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100872 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100873
874 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
875 EXPECT_CONN_COUNT(1);
876 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
877 EXPECT_ACCEPTED(false);
878 thwart_rx_non_initial_requests();
879
880 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100881 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100882 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
883 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
884 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
885 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100886 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100887
888 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200889 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100890 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200891 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100892
893 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100894 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100895 EXPECT_CONN_COUNT(0);
896
897 btw("Subscriber has the IMEI and TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100898 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100899 OSMO_ASSERT(vsub);
Oliver Smithd1037052019-05-02 13:39:26 +0200900 VERBOSE_ASSERT(strcmp(vsub->imei, "42342342342342"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100901 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100902 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100903
904 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200905 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100906 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200907 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100908
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100909 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100910 EXPECT_CONN_COUNT(0);
911 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100912 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100913}
914
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100915static void test_gsm_milenage_authen()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100916{
917 struct vlr_subscr *vsub;
918 const char *imsi = "901700000010650";
919
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100920 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100921
922 net->authentication_required = true;
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100923 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100924
925 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
926 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100927 gsup_expect_tx("080108" "09710000000156f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100928 ms_sends_msg("0508" /* MM LU */
929 "7" /* ciph key seq: no key available */
930 "0" /* LU type: normal */
931 "ffffff" "0000" /* LAI, LAC */
932 "30" /* classmark 1: GSM phase 2 */
933 "089910070000106005" /* IMSI */
934 );
935 OSMO_ASSERT(gsup_tx_confirmed);
936 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
937
938 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
939 /* based on auc_3g:
940 * K = 'EB215756028D60E3275E613320AEC880',
941 * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308'
942 * SQN = 0
943 */
944 auth_request_sent = false;
945 auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d";
946 auth_request_expect_autn = NULL;
947 gsup_rx("0a"
948 /* imsi */
949 "0108" "09710000000156f0"
950 /* 5 auth vectors... */
951 /* TL TL rand */
952 "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d"
953 /* TL sres TL kc */
954 "2104" "9b36efdf" "2208" "059a4f668f6fbe39"
955 /* TL 3G IK */
956 "2310" "27497388b6cb044648f396aa155b95ef"
957 /* TL 3G CK */
958 "2410" "f64735036e5871319c679f4742a75ea1"
959 /* TL AUTN */
960 "2510" "8704f5ba55f30000d2ee44b22c8ea919"
961 /* TL RES */
962 "2708" "e229c19e791f2e41"
963 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
964 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
965 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
966 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
967 "2510" "1843a645b98d00005b2d666af46c45d9"
968 "2708" "7db47cf7f81e4dc7"
969 "0362" "2010" "efa9c29a9742148d5c9070348716e1bb"
970 "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d"
971 "2310" "eb50e770ddcc3060101d2f43b6c2b884"
972 "2410" "76542abce5ff9345b0e8947f4c6e019c"
973 "2510" "f9375e6d41e1000096e7fe4ff1c27e39"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100974 "2708" "706f996719ba609c" HLR_TO_VLR,
975 NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100976 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
977 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
978
979 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100980 gsup_expect_tx("04010809710000000156f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100981 ms_sends_msg("0554" "9b36efdf");
982 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
983
984 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100985 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
986 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100987 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
988
989 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200990 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100991 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200992 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100993
994 btw("LU was successful, and the conn has already been closed");
995 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100996 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100997 EXPECT_CONN_COUNT(0);
998
999 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1000 auth_request_sent = false;
1001 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
1002 auth_request_expect_autn = NULL;
1003 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001004 ms_sends_msg("052474"
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001005 "03305886" /* classmark 2: GSM phase 2 */
1006 "089910070000106005" /* IMSI */);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001007 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1008 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1009
1010 btw("needs auth, not yet accepted");
1011 EXPECT_ACCEPTED(false);
1012 thwart_rx_non_initial_requests();
1013
1014 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
1015 gsup_expect_tx(NULL);
1016 ms_sends_msg("0554" "85aa3130"); /* 2nd vector's sres, s.a. */
1017 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
1018
Vadim Yanitskiy27605852018-06-15 23:57:30 +07001019 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +07001020 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001021 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001022
1023 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001024 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001025 EXPECT_CONN_COUNT(0);
1026
1027 BTW("an SMS is sent, MS is paged");
1028 paging_expect_imsi(imsi);
1029 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001030 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001031 OSMO_ASSERT(vsub);
1032 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1033
1034 send_sms(vsub, vsub,
1035 "Privacy in residential applications is a desirable"
1036 " marketing option.");
1037
1038 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001039 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001040 vsub = NULL;
1041 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001042
1043 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001044 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001045 OSMO_ASSERT(vsub);
1046 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001047 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001048
1049 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1050 auth_request_sent = false;
1051 auth_request_expect_rand = "efa9c29a9742148d5c9070348716e1bb";
1052 auth_request_expect_autn = NULL;
1053 ms_sends_msg("062707"
1054 "03305886" /* classmark 2 */
1055 "089910070000106005" /* IMSI */);
1056 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1057
1058 btw("needs auth, not yet accepted");
1059 EXPECT_ACCEPTED(false);
1060 thwart_rx_non_initial_requests();
1061
1062 btw("MS sends Authen Response, VLR accepts and sends pending SMS");
1063 dtap_expect_tx("09" /* SMS messages */
1064 "01" /* CP-DATA */
1065 "58" /* length */
1066 "01" /* Network to MS */
1067 "00" /* reference */
1068 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1069 "0791" "447758100650" /* 447785016005 */
1070 "00" /* dest */
1071 /* SMS TPDU */
1072 "4c" /* len */
1073 "00" /* SMS deliver */
1074 "05802443f2" /* originating address 42342 */
1075 "00" /* TP-PID */
1076 "00" /* GSM default alphabet */
1077 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1078 "000000" /* H-M-S */
1079 "00" /* GMT+0 */
1080 "44" /* data length */
1081 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1082 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1083 "0c7ac3e9e9b7db05");
1084 ms_sends_msg("0554" "69d5f9fb"); /* 3nd vector's sres, s.a. */
1085 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001086
1087 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001088 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001089 OSMO_ASSERT(vsub);
1090 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001091 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001092
1093 btw("conn is still open to wait for SMS ack dance");
1094 EXPECT_CONN_COUNT(1);
1095
1096 btw("MS replies with CP-ACK for received SMS");
1097 ms_sends_msg("8904");
1098 EXPECT_CONN_COUNT(1);
1099
1100 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1101 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +02001102 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001103 ms_sends_msg("890106020041020000");
1104 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +02001105 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001106
1107 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001108 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001109 EXPECT_CONN_COUNT(0);
1110
1111 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +02001112 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001113 ms_sends_msg("050130"
1114 "089910070000106005" /* IMSI */);
Philipp Maierfbf66102017-04-09 12:32:51 +02001115 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001116
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001117 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001118 EXPECT_CONN_COUNT(0);
1119 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +01001120 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001121}
1122
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001123static void test_wrong_sres_length()
1124{
1125 comment_start();
1126 fake_time_start();
1127
1128 net->authentication_required = true;
1129
1130 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1131 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001132 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +01001133 ms_sends_msg("0508020081680001"
1134 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
1135 "089910070000006402");
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001136 OSMO_ASSERT(gsup_tx_confirmed);
1137 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1138
1139 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1140 auth_request_sent = false;
1141 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1142 auth_request_expect_autn = NULL;
1143 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1144 gsup_rx("0a"
1145 /* imsi */
1146 "0108" "09710000004026f0"
1147 /* 5 auth vectors... */
1148 /* TL TL rand */
1149 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1150 /* TL sres TL kc */
1151 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1152 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1153 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1154 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1155 "2104" "a29514ae" "2208" "e2b234f807886400"
1156 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1157 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1158 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001159 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001160 NULL);
1161 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1162 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1163
1164 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001165 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001166 EXPECT_ACCEPTED(false);
1167
1168 thwart_rx_non_initial_requests();
1169
1170 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1171
1172 btw("MS sends Authen Response with too short SRES data, auth is thwarted.");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001173 gsup_expect_tx("0b010809710000004026f0" VLR_TO_HLR); /* OSMO_GSUP_MSGT_AUTH_FAIL_REPORT */
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001174 expect_bssap_clear();
1175 ms_sends_msg("05542d8b2c");
1176 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
1177
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001178 ran_sends_clear_complete();
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001179 EXPECT_CONN_COUNT(0);
1180 clear_vlr();
1181 comment_end();
1182}
1183
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001184msc_vlr_test_func_t msc_vlr_tests[] = {
1185 test_gsm_authen,
1186 test_gsm_authen_tmsi,
1187 test_gsm_authen_imei,
Oliver Smith7d053092018-12-14 17:37:38 +01001188 test_gsm_authen_imei_nack,
1189 test_gsm_authen_imei_err,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001190 test_gsm_authen_tmsi_imei,
1191 test_gsm_milenage_authen,
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001192 test_wrong_sres_length,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001193 NULL
1194};