blob: d68ce056e4be70cc4291053d8c35e36eb03e6424 [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"
Harald Welte0df904d2018-12-03 11:00:04 +010025#include "stubs.h"
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010026
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010027static void test_gsm_authen()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010028{
29 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010030 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010031
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010032 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010033
34 net->authentication_required = true;
35
36 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
37 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010038 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +010039 ms_sends_msg("0508020081680001"
40 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
41 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010042 OSMO_ASSERT(gsup_tx_confirmed);
43 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
44
45 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
46 auth_request_sent = false;
47 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
48 auth_request_expect_autn = NULL;
49 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
50 gsup_rx("0a"
51 /* imsi */
52 "0108" "09710000004026f0"
53 /* 5 auth vectors... */
54 /* TL TL rand */
55 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
56 /* TL sres TL kc */
57 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
58 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
59 "2104" "20bde240" "2208" "07fa7502e07e1c00"
60 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
61 "2104" "a29514ae" "2208" "e2b234f807886400"
62 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
63 "2104" "5afc8d72" "2208" "2392f14f709ae000"
64 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010065 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
66 HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010067 NULL);
68 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
69 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
70
71 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010072 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010073 EXPECT_ACCEPTED(false);
74
75 thwart_rx_non_initial_requests();
76
77 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
78
79 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010080 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010081 ms_sends_msg("05542d8b2c3e");
82 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
83
84 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010085 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
86 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010087 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
88
89 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +020090 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010091 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +020092 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010093
94 btw("LU was successful, and the conn has already been closed");
95 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010096 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010097 EXPECT_CONN_COUNT(0);
98
99 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
100 auth_request_sent = false;
101 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
102 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100103 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100104 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
105 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
106
107 btw("needs auth, not yet accepted");
108 EXPECT_ACCEPTED(false);
109 thwart_rx_non_initial_requests();
110
111 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
112 gsup_expect_tx(NULL);
113 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
114 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
115
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700116 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100117 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100118 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100119
120 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100121 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100122 EXPECT_CONN_COUNT(0);
123
124 BTW("an SMS is sent, MS is paged");
125 paging_expect_imsi(imsi);
126 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100127 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100128 OSMO_ASSERT(vsub);
129 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
130
131 send_sms(vsub, vsub,
132 "Privacy in residential applications is a desirable"
133 " marketing option.");
134
135 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100136 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100137 vsub = NULL;
138 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100139
140 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100141 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100142 OSMO_ASSERT(vsub);
143 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100144 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100145
146 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
147 auth_request_sent = false;
148 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
149 ms_sends_msg("06270703305882089910070000006402");
150 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
151
152 btw("needs auth, not yet accepted");
153 EXPECT_ACCEPTED(false);
154 thwart_rx_non_initial_requests();
155
156 btw("MS sends Authen Response, VLR accepts and sends pending SMS");
157 dtap_expect_tx("09" /* SMS messages */
158 "01" /* CP-DATA */
159 "58" /* length */
160 "01" /* Network to MS */
161 "00" /* reference */
162 /* originator (gsm411_send_sms() hardcodes this weird nr) */
163 "0791" "447758100650" /* 447785016005 */
164 "00" /* dest */
165 /* SMS TPDU */
166 "4c" /* len */
167 "00" /* SMS deliver */
168 "05806470f1" /* originating address 46071 */
169 "00" /* TP-PID */
170 "00" /* GSM default alphabet */
171 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
172 "000000" /* H-M-S */
173 "00" /* GMT+0 */
174 "44" /* data length */
175 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
176 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
177 "0c7ac3e9e9b7db05");
178 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
179 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100180
181 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100182 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100183 OSMO_ASSERT(vsub);
184 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100185 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100186
187 btw("conn is still open to wait for SMS ack dance");
188 EXPECT_CONN_COUNT(1);
189
190 btw("MS replies with CP-ACK for received SMS");
191 ms_sends_msg("8904");
192 EXPECT_CONN_COUNT(1);
193
194 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
195 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200196 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100197 ms_sends_msg("890106020041020000");
198 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200199 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100200
201 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100202 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100203 EXPECT_CONN_COUNT(0);
204
205 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200206 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100207 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200208 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100209
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100210 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100211 EXPECT_CONN_COUNT(0);
212 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100213 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100214}
215
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100216static void test_gsm_authen_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100217{
218 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100219 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100220
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100221 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100222
223 net->authentication_required = true;
224 net->vlr->cfg.assign_tmsi = true;
225
226 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
227 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100228 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100229 ms_sends_msg("0508020081680001"
230 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
231 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100232 OSMO_ASSERT(gsup_tx_confirmed);
233 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
234
235 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
236 auth_request_sent = false;
237 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
238 auth_request_expect_autn = NULL;
239 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
240 gsup_rx("0a"
241 /* imsi */
242 "0108" "09710000004026f0"
243 /* 5 auth vectors... */
244 /* TL TL rand */
245 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
246 /* TL sres TL kc */
247 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
248 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
249 "2104" "20bde240" "2208" "07fa7502e07e1c00"
250 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
251 "2104" "a29514ae" "2208" "e2b234f807886400"
252 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
253 "2104" "5afc8d72" "2208" "2392f14f709ae000"
254 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100255 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
256 HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100257 NULL);
258 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
259 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
260
261 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100262 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100263 EXPECT_ACCEPTED(false);
264
265 thwart_rx_non_initial_requests();
266
267 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
268
269 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100270 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100271 ms_sends_msg("05542d8b2c3e");
272 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
273
274 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100275 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
276 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100277 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
278
279 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100280 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100281
282 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
283 EXPECT_CONN_COUNT(1);
284 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
285 EXPECT_ACCEPTED(false);
286 thwart_rx_non_initial_requests();
287
288 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100289 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100290 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
291 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
292 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
293 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100294 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100295
296 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200297 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100298 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200299 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100300
301 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100302 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100303 EXPECT_CONN_COUNT(0);
304
305 btw("Subscriber has the new TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100306 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100307 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
308 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
309 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
310 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100311 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100312
313 BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector");
314 auth_request_sent = false;
315 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
316 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100317 ms_sends_msg("05247403305886" "05f4" "03020100");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100318 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
319 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
320
321 btw("needs auth, not yet accepted");
322 EXPECT_ACCEPTED(false);
323 thwart_rx_non_initial_requests();
324
325 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
326 gsup_expect_tx(NULL);
327 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
328 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
329
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700330 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100331 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100332 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100333
334 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100335 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100336 EXPECT_CONN_COUNT(0);
337
338 BTW("an SMS is sent, MS is paged");
339 paging_expect_tmsi(0x03020100);
340 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100341 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100342 OSMO_ASSERT(vsub);
343 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
344
345 send_sms(vsub, vsub,
346 "Privacy in residential applications is a desirable"
347 " marketing option.");
348
349 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100350 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100351 vsub = NULL;
352 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100353
354 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100355 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100356 OSMO_ASSERT(vsub);
357 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100358 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100359
360 btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key");
361 auth_request_sent = false;
362 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
363 ms_sends_msg("06270703305882" "05f4" "03020100");
364 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
365
366 btw("needs auth, not yet accepted");
367 EXPECT_ACCEPTED(false);
368 thwart_rx_non_initial_requests();
369
370 btw("MS sends Authen Response, VLR accepts and sends pending SMS");
371 dtap_expect_tx("09" /* SMS messages */
372 "01" /* CP-DATA */
373 "58" /* length */
374 "01" /* Network to MS */
375 "00" /* reference */
376 /* originator (gsm411_send_sms() hardcodes this weird nr) */
377 "0791" "447758100650" /* 447785016005 */
378 "00" /* dest */
379 /* SMS TPDU */
380 "4c" /* len */
381 "00" /* SMS deliver */
382 "05806470f1" /* originating address 46071 */
383 "00" /* TP-PID */
384 "00" /* GSM default alphabet */
385 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
386 "000000" /* H-M-S */
387 "00" /* GMT+0 */
388 "44" /* data length */
389 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
390 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
391 "0c7ac3e9e9b7db05");
392 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
393 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100394
395 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100396 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100397 OSMO_ASSERT(vsub);
398 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100399 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100400
401 btw("conn is still open to wait for SMS ack dance");
402 EXPECT_CONN_COUNT(1);
403
404 btw("MS replies with CP-ACK for received SMS");
405 ms_sends_msg("8904");
406 EXPECT_CONN_COUNT(1);
407
408 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
409 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200410 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100411 ms_sends_msg("890106020041020000");
412 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200413 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100414
415 btw("SMS is done, conn is gone");
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 /* TODO: when the subscriber detaches, the vlr_subscr gets
420 * deallocated and we no longer know the TMSI. This case is covered by
421 * test_lu_unknown_tmsi(), so here I'd like to still have the TMSI.
422 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200423 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100424 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200425 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100426 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100427 EXPECT_CONN_COUNT(0);
428 */
429
430 BTW("subscriber sends LU Request, this time with the TMSI");
431 btw("Location Update request causes an Auth Req to MS");
432 lu_result_sent = RES_NONE;
433 auth_request_sent = false;
434 auth_request_expect_rand = "fa8f20b781b5881329d4fea26b1a3c51";
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100435 ms_sends_msg("0508020081680001"
436 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
437 "05f4" "03020100");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100438 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
439 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
440
441 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100442 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100443 ms_sends_msg("05545afc8d72");
444 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
445
446 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100447 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
448 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100449 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
450
451 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100452 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100453
454 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
455 EXPECT_CONN_COUNT(1);
456 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
457 EXPECT_ACCEPTED(false);
458 thwart_rx_non_initial_requests();
459
460 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100461 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100462 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
463 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
464 VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x");
465 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100466 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100467
468 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200469 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100470 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200471 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100472
473 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100474 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100475 EXPECT_CONN_COUNT(0);
476
477 btw("subscriber has the new TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100478 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100479 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
480 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
481 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
482 VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100483 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100484
485 BTW("subscriber detaches, using new TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200486 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100487 ms_sends_msg("050130" "05f4" "07060504");
Philipp Maierfbf66102017-04-09 12:32:51 +0200488 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100489
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100490 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100491 EXPECT_CONN_COUNT(0);
492 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100493 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100494}
495
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100496static void test_gsm_authen_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100497{
498 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100499 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100500
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100501 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100502
503 net->authentication_required = true;
504 net->vlr->cfg.check_imei_rqd = true;
505
506 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
507 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100508 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100509 ms_sends_msg("0508020081680001"
510 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
511 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100512 OSMO_ASSERT(gsup_tx_confirmed);
513 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
514
515 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
516 auth_request_sent = false;
517 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
518 auth_request_expect_autn = NULL;
519 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
520 gsup_rx("0a"
521 /* imsi */
522 "0108" "09710000004026f0"
523 /* 5 auth vectors... */
524 /* TL TL rand */
525 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
526 /* TL sres TL kc */
527 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
528 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
529 "2104" "20bde240" "2208" "07fa7502e07e1c00"
530 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
531 "2104" "a29514ae" "2208" "e2b234f807886400"
532 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
533 "2104" "5afc8d72" "2208" "2392f14f709ae000"
534 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100535 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
536 HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100537 NULL);
538 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
539 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
540
541 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100542 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100543 EXPECT_ACCEPTED(false);
544 thwart_rx_non_initial_requests();
545 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
546
547 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100548 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100549 ms_sends_msg("05542d8b2c3e");
550 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
551
552 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100553 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
554 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100555 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
556
557 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
558 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100559 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100560
561 btw("We will only do business when the IMEI is known");
562 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100563 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100564 OSMO_ASSERT(vsub);
565 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100566 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100567 EXPECT_ACCEPTED(false);
568 thwart_rx_non_initial_requests();
569
Oliver Smith7d053092018-12-14 17:37:38 +0100570 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100571 gsup_expect_tx("30010809710000004026f050090824433224433224f0" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200572 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100573 EXPECT_ACCEPTED(false);
574 thwart_rx_non_initial_requests();
575
576 btw("HLR accepts the IMEI");
577 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100578 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200579 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100580
581 btw("LU was successful, and the conn has already been closed");
582 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100583 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100584 EXPECT_CONN_COUNT(0);
585
586 btw("Subscriber has the IMEI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100587 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100588 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200589 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100590 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100591
592 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200593 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100594 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200595 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100596
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100597 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100598 EXPECT_CONN_COUNT(0);
599 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100600 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100601}
602
Oliver Smith7d053092018-12-14 17:37:38 +0100603static void test_gsm_authen_imei_nack()
604{
605 struct vlr_subscr *vsub;
606 const char *imsi = "901700000004620";
607
608 comment_start();
609
610 net->authentication_required = true;
611 net->vlr->cfg.check_imei_rqd = true;
612
613 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
614 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100615 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100616 ms_sends_msg("0508020081680001"
617 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
618 "089910070000006402");
619 OSMO_ASSERT(gsup_tx_confirmed);
620 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
621
622 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
623 auth_request_sent = false;
624 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
625 auth_request_expect_autn = NULL;
626 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
627 gsup_rx("0a"
628 /* imsi */
629 "0108" "09710000004026f0"
630 /* 5 auth vectors... */
631 /* TL TL rand */
632 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
633 /* TL sres TL kc */
634 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
635 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
636 "2104" "20bde240" "2208" "07fa7502e07e1c00"
637 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
638 "2104" "a29514ae" "2208" "e2b234f807886400"
639 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
640 "2104" "5afc8d72" "2208" "2392f14f709ae000"
641 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100642 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000"
643 HLR_TO_VLR,
Oliver Smith7d053092018-12-14 17:37:38 +0100644 NULL);
645 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
646 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
647
648 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100649 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100650 EXPECT_ACCEPTED(false);
651
652 thwart_rx_non_initial_requests();
653
654 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
655
656 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100657 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100658 ms_sends_msg("05542d8b2c3e");
659 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
660
661 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100662 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
663 "12010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100664 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
665
666 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
667 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100668 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100669
670 btw("We will only do business when the IMEI is known");
671 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100672 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100673 OSMO_ASSERT(vsub);
674 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100675 vlr_subscr_put(vsub, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100676 EXPECT_ACCEPTED(false);
677 thwart_rx_non_initial_requests();
678
679 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100680 gsup_expect_tx("30010809710000004026f050090824433224433224f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100681 ms_sends_msg("0559084a32244332244302");
682 EXPECT_ACCEPTED(false);
683 thwart_rx_non_initial_requests();
684
685 expect_bssap_clear();
686 btw("HLR does not like the IMEI and sends NACK");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100687 gsup_rx("32010809710000004026f0510101" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100688 EXPECT_ACCEPTED(false);
689 thwart_rx_non_initial_requests();
690
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100691 ran_sends_clear_complete();
Oliver Smith7d053092018-12-14 17:37:38 +0100692 EXPECT_CONN_COUNT(0);
693 clear_vlr();
694 comment_end();
695}
696
697static void test_gsm_authen_imei_err()
698{
699 struct vlr_subscr *vsub;
700 const char *imsi = "901700000004620";
701
702 comment_start();
703
704 net->authentication_required = true;
705 net->vlr->cfg.check_imei_rqd = true;
706
707 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
708 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100709 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100710 ms_sends_msg("0508020081680001"
711 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
712 "089910070000006402");
713 OSMO_ASSERT(gsup_tx_confirmed);
714 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
715
716 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
717 auth_request_sent = false;
718 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
719 auth_request_expect_autn = NULL;
720 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
721 gsup_rx("0a"
722 /* imsi */
723 "0108" "09710000004026f0"
724 /* 5 auth vectors... */
725 /* TL TL rand */
726 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
727 /* TL sres TL kc */
728 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
729 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
730 "2104" "20bde240" "2208" "07fa7502e07e1c00"
731 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
732 "2104" "a29514ae" "2208" "e2b234f807886400"
733 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
734 "2104" "5afc8d72" "2208" "2392f14f709ae000"
735 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100736 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Oliver Smith7d053092018-12-14 17:37:38 +0100737 NULL);
738 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
739 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
740
741 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100742 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100743 EXPECT_ACCEPTED(false);
744
745 thwart_rx_non_initial_requests();
746
747 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
748
749 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100750 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100751 ms_sends_msg("05542d8b2c3e");
752 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
753
754 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100755 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
756 "12010809710000004026f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100757 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
758
759 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
760 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100761 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100762
763 btw("We will only do business when the IMEI is known");
764 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100765 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100766 OSMO_ASSERT(vsub);
767 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100768 vlr_subscr_put(vsub, __func__);
Oliver Smith7d053092018-12-14 17:37:38 +0100769 EXPECT_ACCEPTED(false);
770 thwart_rx_non_initial_requests();
771
772 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100773 gsup_expect_tx("30010809710000004026f050090824433224433224f0" VLR_TO_HLR);
Oliver Smith7d053092018-12-14 17:37:38 +0100774 ms_sends_msg("0559084a32244332244302");
775 EXPECT_ACCEPTED(false);
776 thwart_rx_non_initial_requests();
777
778 expect_bssap_clear();
779 btw("HLR can't parse the message and returns ERR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100780 gsup_rx("31010809710000004026f0020160" HLR_TO_VLR, NULL);
Oliver Smith7d053092018-12-14 17:37:38 +0100781 EXPECT_ACCEPTED(false);
782 thwart_rx_non_initial_requests();
783
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100784 ran_sends_clear_complete();
Oliver Smith7d053092018-12-14 17:37:38 +0100785 EXPECT_CONN_COUNT(0);
786 clear_vlr();
787 comment_end();
788}
789
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100790static void test_gsm_authen_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100791{
792 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100793 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100794
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100795 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100796
797 net->authentication_required = true;
798 net->vlr->cfg.assign_tmsi = true;
799 net->vlr->cfg.check_imei_rqd = true;
800
801 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
802 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100803 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +0100804 ms_sends_msg("0508020081680001"
805 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
806 "089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100807 OSMO_ASSERT(gsup_tx_confirmed);
808 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
809
810 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
811 auth_request_sent = false;
812 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
813 auth_request_expect_autn = NULL;
814 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
815 gsup_rx("0a"
816 /* imsi */
817 "0108" "09710000004026f0"
818 /* 5 auth vectors... */
819 /* TL TL rand */
820 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
821 /* TL sres TL kc */
822 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
823 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
824 "2104" "20bde240" "2208" "07fa7502e07e1c00"
825 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
826 "2104" "a29514ae" "2208" "e2b234f807886400"
827 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
828 "2104" "5afc8d72" "2208" "2392f14f709ae000"
829 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100830 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100831 NULL);
832 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
833 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
834
835 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100836 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100837 EXPECT_ACCEPTED(false);
838
839 thwart_rx_non_initial_requests();
840
841 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
842
843 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100844 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100845 ms_sends_msg("05542d8b2c3e");
846 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
847
848 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100849 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
850 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100851 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
852
853 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
854 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100855 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100856
857 btw("We will only do business when the IMEI is known");
858 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100859 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100860 OSMO_ASSERT(vsub);
861 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100862 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100863 EXPECT_ACCEPTED(false);
864 thwart_rx_non_initial_requests();
865
Oliver Smith7d053092018-12-14 17:37:38 +0100866 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100867 gsup_expect_tx("30010809710000004026f050090824433224433224f0" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200868 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100869 EXPECT_ACCEPTED(false);
870 thwart_rx_non_initial_requests();
871
872 btw("HLR accepts the IMEI");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100873 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100874
875 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
876 EXPECT_CONN_COUNT(1);
877 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
878 EXPECT_ACCEPTED(false);
879 thwart_rx_non_initial_requests();
880
881 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100882 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100883 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
884 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
885 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
886 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100887 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100888
889 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200890 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100891 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200892 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100893
894 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100895 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100896 EXPECT_CONN_COUNT(0);
897
898 btw("Subscriber has the IMEI and TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100899 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100900 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200901 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100902 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100903 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100904
905 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200906 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100907 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200908 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100909
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100910 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100911 EXPECT_CONN_COUNT(0);
912 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100913 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100914}
915
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100916static void test_gsm_milenage_authen()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100917{
918 struct vlr_subscr *vsub;
919 const char *imsi = "901700000010650";
920
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100921 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100922
923 net->authentication_required = true;
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100924 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100925
926 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
927 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100928 gsup_expect_tx("080108" "09710000000156f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100929 ms_sends_msg("0508" /* MM LU */
930 "7" /* ciph key seq: no key available */
931 "0" /* LU type: normal */
932 "ffffff" "0000" /* LAI, LAC */
933 "30" /* classmark 1: GSM phase 2 */
934 "089910070000106005" /* IMSI */
935 );
936 OSMO_ASSERT(gsup_tx_confirmed);
937 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
938
939 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
940 /* based on auc_3g:
941 * K = 'EB215756028D60E3275E613320AEC880',
942 * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308'
943 * SQN = 0
944 */
945 auth_request_sent = false;
946 auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d";
947 auth_request_expect_autn = NULL;
948 gsup_rx("0a"
949 /* imsi */
950 "0108" "09710000000156f0"
951 /* 5 auth vectors... */
952 /* TL TL rand */
953 "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d"
954 /* TL sres TL kc */
955 "2104" "9b36efdf" "2208" "059a4f668f6fbe39"
956 /* TL 3G IK */
957 "2310" "27497388b6cb044648f396aa155b95ef"
958 /* TL 3G CK */
959 "2410" "f64735036e5871319c679f4742a75ea1"
960 /* TL AUTN */
961 "2510" "8704f5ba55f30000d2ee44b22c8ea919"
962 /* TL RES */
963 "2708" "e229c19e791f2e41"
964 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
965 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
966 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
967 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
968 "2510" "1843a645b98d00005b2d666af46c45d9"
969 "2708" "7db47cf7f81e4dc7"
970 "0362" "2010" "efa9c29a9742148d5c9070348716e1bb"
971 "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d"
972 "2310" "eb50e770ddcc3060101d2f43b6c2b884"
973 "2410" "76542abce5ff9345b0e8947f4c6e019c"
974 "2510" "f9375e6d41e1000096e7fe4ff1c27e39"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100975 "2708" "706f996719ba609c" HLR_TO_VLR,
976 NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100977 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
978 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
979
980 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100981 gsup_expect_tx("04010809710000000156f0280102" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100982 ms_sends_msg("0554" "9b36efdf");
983 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
984
985 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100986 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
987 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100988 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
989
990 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200991 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100992 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200993 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100994
995 btw("LU was successful, and the conn has already been closed");
996 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100997 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100998 EXPECT_CONN_COUNT(0);
999
1000 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1001 auth_request_sent = false;
1002 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
1003 auth_request_expect_autn = NULL;
1004 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001005 ms_sends_msg("052474"
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001006 "03305886" /* classmark 2: GSM phase 2 */
1007 "089910070000106005" /* IMSI */);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001008 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1009 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1010
1011 btw("needs auth, not yet accepted");
1012 EXPECT_ACCEPTED(false);
1013 thwart_rx_non_initial_requests();
1014
1015 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
1016 gsup_expect_tx(NULL);
1017 ms_sends_msg("0554" "85aa3130"); /* 2nd vector's sres, s.a. */
1018 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
1019
Vadim Yanitskiy27605852018-06-15 23:57:30 +07001020 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +01001021 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001022 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001023
1024 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001025 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001026 EXPECT_CONN_COUNT(0);
1027
1028 BTW("an SMS is sent, MS is paged");
1029 paging_expect_imsi(imsi);
1030 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001031 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001032 OSMO_ASSERT(vsub);
1033 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1034
1035 send_sms(vsub, vsub,
1036 "Privacy in residential applications is a desirable"
1037 " marketing option.");
1038
1039 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001040 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001041 vsub = NULL;
1042 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001043
1044 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001045 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001046 OSMO_ASSERT(vsub);
1047 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001048 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001049
1050 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1051 auth_request_sent = false;
1052 auth_request_expect_rand = "efa9c29a9742148d5c9070348716e1bb";
1053 auth_request_expect_autn = NULL;
1054 ms_sends_msg("062707"
1055 "03305886" /* classmark 2 */
1056 "089910070000106005" /* IMSI */);
1057 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1058
1059 btw("needs auth, not yet accepted");
1060 EXPECT_ACCEPTED(false);
1061 thwart_rx_non_initial_requests();
1062
1063 btw("MS sends Authen Response, VLR accepts and sends pending SMS");
1064 dtap_expect_tx("09" /* SMS messages */
1065 "01" /* CP-DATA */
1066 "58" /* length */
1067 "01" /* Network to MS */
1068 "00" /* reference */
1069 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1070 "0791" "447758100650" /* 447785016005 */
1071 "00" /* dest */
1072 /* SMS TPDU */
1073 "4c" /* len */
1074 "00" /* SMS deliver */
1075 "05802443f2" /* originating address 42342 */
1076 "00" /* TP-PID */
1077 "00" /* GSM default alphabet */
1078 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1079 "000000" /* H-M-S */
1080 "00" /* GMT+0 */
1081 "44" /* data length */
1082 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1083 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1084 "0c7ac3e9e9b7db05");
1085 ms_sends_msg("0554" "69d5f9fb"); /* 3nd vector's sres, s.a. */
1086 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001087
1088 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001089 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001090 OSMO_ASSERT(vsub);
1091 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001092 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001093
1094 btw("conn is still open to wait for SMS ack dance");
1095 EXPECT_CONN_COUNT(1);
1096
1097 btw("MS replies with CP-ACK for received SMS");
1098 ms_sends_msg("8904");
1099 EXPECT_CONN_COUNT(1);
1100
1101 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1102 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +02001103 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001104 ms_sends_msg("890106020041020000");
1105 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +02001106 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001107
1108 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001109 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001110 EXPECT_CONN_COUNT(0);
1111
1112 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +02001113 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001114 ms_sends_msg("050130"
1115 "089910070000106005" /* IMSI */);
Philipp Maierfbf66102017-04-09 12:32:51 +02001116 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001117
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001118 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001119 EXPECT_CONN_COUNT(0);
1120 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +01001121 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001122}
1123
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001124static void test_wrong_sres_length()
1125{
1126 comment_start();
1127 fake_time_start();
1128
1129 net->authentication_required = true;
1130
1131 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1132 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001133 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyrfe718bc2018-03-11 01:24:33 +01001134 ms_sends_msg("0508020081680001"
1135 "30" /* <-- Revision Level == 1, i.e. is_r99 == false */
1136 "089910070000006402");
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001137 OSMO_ASSERT(gsup_tx_confirmed);
1138 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1139
1140 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1141 auth_request_sent = false;
1142 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1143 auth_request_expect_autn = NULL;
1144 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1145 gsup_rx("0a"
1146 /* imsi */
1147 "0108" "09710000004026f0"
1148 /* 5 auth vectors... */
1149 /* TL TL rand */
1150 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1151 /* TL sres TL kc */
1152 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1153 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1154 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1155 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1156 "2104" "a29514ae" "2208" "e2b234f807886400"
1157 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1158 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1159 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001160 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001161 NULL);
1162 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1163 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1164
1165 btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001166 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001167 EXPECT_ACCEPTED(false);
1168
1169 thwart_rx_non_initial_requests();
1170
1171 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1172
1173 btw("MS sends Authen Response with too short SRES data, auth is thwarted.");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001174 gsup_expect_tx("0b010809710000004026f0" VLR_TO_HLR); /* OSMO_GSUP_MSGT_AUTH_FAIL_REPORT */
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001175 expect_bssap_clear();
1176 ms_sends_msg("05542d8b2c");
1177 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
1178
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001179 ran_sends_clear_complete();
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001180 EXPECT_CONN_COUNT(0);
1181 clear_vlr();
1182 comment_end();
1183}
1184
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001185msc_vlr_test_func_t msc_vlr_tests[] = {
1186 test_gsm_authen,
1187 test_gsm_authen_tmsi,
1188 test_gsm_authen_imei,
Oliver Smith7d053092018-12-14 17:37:38 +01001189 test_gsm_authen_imei_nack,
1190 test_gsm_authen_imei_err,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001191 test_gsm_authen_tmsi_imei,
1192 test_gsm_milenage_authen,
Neels Hofmeyr8e0af0b2018-03-10 03:32:18 +01001193 test_wrong_sres_length,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001194 NULL
1195};