blob: b4269818ccfc361811722d0bcdd32edb7010a2de [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_ciph()
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 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +010034 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010035
36 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
37 lu_result_sent = RES_NONE;
38 gsup_expect_tx("08010809710000004026f0");
39 ms_sends_msg("050802008168000130089910070000006402");
40 OSMO_ASSERT(gsup_tx_confirmed);
41 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
42
43 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
44 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
45 auth_request_sent = false;
46 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
47 auth_request_expect_autn = NULL;
48 gsup_rx("0a"
49 /* imsi */
50 "0108" "09710000004026f0"
51 /* 5 auth vectors... */
52 /* TL TL rand */
53 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
54 /* TL sres TL kc */
55 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
56 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
57 "2104" "20bde240" "2208" "07fa7502e07e1c00"
58 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
59 "2104" "a29514ae" "2208" "e2b234f807886400"
60 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
61 "2104" "5afc8d72" "2208" "2392f14f709ae000"
62 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
63 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
64 NULL);
65 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
66 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
67
68 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010069 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010070 ms_sends_msg("05542d8b2c3e");
71 OSMO_ASSERT(cipher_mode_cmd_sent);
72 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
73
74 btw("needs ciph, not yet accepted");
75 EXPECT_ACCEPTED(false);
76 thwart_rx_non_initial_requests();
77 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
78
79 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
80 gsup_expect_tx("04010809710000004026f0");
81 ms_sends_msg("0632");
82 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
83
84 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
85 gsup_rx("10010809710000004026f00804036470f1",
86 "12010809710000004026f0");
87 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 Hofmeyr6a29d322017-01-25 15:04:16 +010091 gsup_rx("06010809710000004026f0", 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 Hofmeyr4068ab22018-04-01 20:55:54 +020096 bss_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 cm_service_result_sent = RES_NONE;
101 auth_request_sent = false;
102 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
103 ms_sends_msg("05247803305886089910070000006402");
104 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200105 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100106 OSMO_ASSERT(g_conn->vsub);
107 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
108 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
109
110 btw("needs auth, not yet accepted");
111 EXPECT_ACCEPTED(false);
112 thwart_rx_non_initial_requests();
113
114 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100115 expect_cipher_mode_cmd("07fa7502e07e1c00");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100116 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
117 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
118 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
119
120 btw("needs ciph, not yet accepted");
121 EXPECT_ACCEPTED(false);
122 thwart_rx_non_initial_requests();
123
124 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
125 ms_sends_msg("0632");
126 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
127
128 btw("a USSD request is serviced");
129 dtap_expect_tx_ussd("Your extension is 46071\r");
Philipp Maierfbf66102017-04-09 12:32:51 +0200130 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100131 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
132 OSMO_ASSERT(dtap_tx_confirmed);
Philipp Maierfbf66102017-04-09 12:32:51 +0200133 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100134
135 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200136 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100137 EXPECT_CONN_COUNT(0);
138
139 BTW("an SMS is sent, MS is paged");
140 paging_expect_imsi(imsi);
141 paging_sent = false;
142 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
143 OSMO_ASSERT(vsub);
144 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
145
146 send_sms(vsub, vsub,
147 "Privacy in residential applications is a desirable"
148 " marketing option.");
149
150 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
151 vlr_subscr_put(vsub);
152 vsub = NULL;
153 VERBOSE_ASSERT(paging_sent, == true, "%d");
154 VERBOSE_ASSERT(paging_stopped, == false, "%d");
155
156 btw("the subscriber and its pending request should remain");
157 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
158 OSMO_ASSERT(vsub);
159 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
160 vlr_subscr_put(vsub);
161
162 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
163 auth_request_sent = false;
164 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
165 ms_sends_msg("06270703305882089910070000006402");
166 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
167
168 btw("needs auth, not yet accepted");
169 EXPECT_ACCEPTED(false);
170 thwart_rx_non_initial_requests();
171
172 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100173 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100174 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
175 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
176
177 btw("needs ciph, not yet accepted");
178 EXPECT_ACCEPTED(false);
179 thwart_rx_non_initial_requests();
180
181 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
182 dtap_expect_tx("09" /* SMS messages */
183 "01" /* CP-DATA */
184 "58" /* length */
185 "01" /* Network to MS */
186 "00" /* reference */
187 /* originator (gsm411_send_sms() hardcodes this weird nr) */
188 "0791" "447758100650" /* 447785016005 */
189 "00" /* dest */
190 /* SMS TPDU */
191 "4c" /* len */
192 "00" /* SMS deliver */
193 "05806470f1" /* originating address 46071 */
194 "00" /* TP-PID */
195 "00" /* GSM default alphabet */
196 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
197 "000000" /* H-M-S */
198 "00" /* GMT+0 */
199 "44" /* data length */
200 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
201 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
202 "0c7ac3e9e9b7db05");
203 ms_sends_msg("0632");
204 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
205 VERBOSE_ASSERT(paging_stopped, == true, "%d");
206
207 btw("SMS was delivered, no requests pending for subscr");
208 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
209 OSMO_ASSERT(vsub);
210 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
211 vlr_subscr_put(vsub);
212
213 btw("conn is still open to wait for SMS ack dance");
214 EXPECT_CONN_COUNT(1);
215
216 btw("MS replies with CP-ACK for received SMS");
217 ms_sends_msg("8904");
218 EXPECT_CONN_COUNT(1);
219
220 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
221 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200222 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100223 ms_sends_msg("890106020041020000");
224 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200225 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100226
227 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200228 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100229 EXPECT_CONN_COUNT(0);
230
231 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200232 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100233 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200234 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100235
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200236 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100237 EXPECT_CONN_COUNT(0);
238 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100239 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100240}
241
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100242static void test_ciph_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100243{
244 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100245 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100246
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100247 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100248
249 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100250 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100251 net->vlr->cfg.assign_tmsi = true;
252
253 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
254 lu_result_sent = RES_NONE;
255 gsup_expect_tx("08010809710000004026f0");
256 ms_sends_msg("050802008168000130089910070000006402");
257 OSMO_ASSERT(gsup_tx_confirmed);
258 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
259
260 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
261 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
262 auth_request_sent = false;
263 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
264 auth_request_expect_autn = NULL;
265 gsup_rx("0a"
266 /* imsi */
267 "0108" "09710000004026f0"
268 /* 5 auth vectors... */
269 /* TL TL rand */
270 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
271 /* TL sres TL kc */
272 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
273 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
274 "2104" "20bde240" "2208" "07fa7502e07e1c00"
275 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
276 "2104" "a29514ae" "2208" "e2b234f807886400"
277 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
278 "2104" "5afc8d72" "2208" "2392f14f709ae000"
279 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
280 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
281 NULL);
282 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
283 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
284
285 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100286 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100287 ms_sends_msg("05542d8b2c3e");
288 OSMO_ASSERT(cipher_mode_cmd_sent);
289 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
290 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
291
292 btw("needs ciph, not yet accepted");
293 EXPECT_ACCEPTED(false);
294 thwart_rx_non_initial_requests();
295 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
296
297 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
298 gsup_expect_tx("04010809710000004026f0");
299 ms_sends_msg("0632");
300 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
301
302 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
303 gsup_rx("10010809710000004026f00804036470f1",
304 "12010809710000004026f0");
305 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
306
307 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
308 gsup_rx("06010809710000004026f0", NULL);
309
310 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
311 EXPECT_CONN_COUNT(1);
312 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
313 EXPECT_ACCEPTED(false);
314 thwart_rx_non_initial_requests();
315
316 btw("even though the TMSI is not acked, we can already find the subscr with it");
317 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
318 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
319 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
320 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
321 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
322 vlr_subscr_put(vsub);
323
324 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200325 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100326 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200327 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100328
329 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200330 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100331 EXPECT_CONN_COUNT(0);
332
333 btw("Subscriber has the new TMSI");
334 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
335 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
336 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
337 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
338 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
339 vlr_subscr_put(vsub);
340
341 BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector");
342 cm_service_result_sent = RES_NONE;
343 auth_request_sent = false;
344 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
345 auth_request_expect_autn = NULL;
346 ms_sends_msg("05247803305886" "05f4" "03020100");
347 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200348 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100349 OSMO_ASSERT(g_conn->vsub);
350 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
351 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
352
353 btw("needs auth, not yet accepted");
354 EXPECT_ACCEPTED(false);
355 thwart_rx_non_initial_requests();
356
357 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100358 expect_cipher_mode_cmd("07fa7502e07e1c00");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100359 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
360 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
361 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
362
363 btw("needs ciph, not yet accepted");
364 EXPECT_ACCEPTED(false);
365 thwart_rx_non_initial_requests();
366
367 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
368 ms_sends_msg("0632");
369 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
370
371 btw("a USSD request is serviced");
372 dtap_expect_tx_ussd("Your extension is 46071\r");
Philipp Maierfbf66102017-04-09 12:32:51 +0200373 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100374 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
375 OSMO_ASSERT(dtap_tx_confirmed);
Philipp Maierfbf66102017-04-09 12:32:51 +0200376 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100377
378 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200379 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100380 EXPECT_CONN_COUNT(0);
381
382 BTW("an SMS is sent, MS is paged");
383 paging_expect_tmsi(0x03020100);
384 paging_sent = false;
385 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
386 OSMO_ASSERT(vsub);
387 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
388
389 send_sms(vsub, vsub,
390 "Privacy in residential applications is a desirable"
391 " marketing option.");
392
393 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
394 vlr_subscr_put(vsub);
395 vsub = NULL;
396 VERBOSE_ASSERT(paging_sent, == true, "%d");
397 VERBOSE_ASSERT(paging_stopped, == false, "%d");
398
399 btw("the subscriber and its pending request should remain");
400 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
401 OSMO_ASSERT(vsub);
402 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
403 vlr_subscr_put(vsub);
404
405 btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key");
406 auth_request_sent = false;
407 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
408 ms_sends_msg("06270703305882" "05f4" "03020100");
409 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
410
411 btw("needs auth, not yet accepted");
412 EXPECT_ACCEPTED(false);
413 thwart_rx_non_initial_requests();
414
415 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100416 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100417 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
418 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
419
420 btw("needs ciph, not yet accepted");
421 EXPECT_ACCEPTED(false);
422 thwart_rx_non_initial_requests();
423
424 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
425 dtap_expect_tx("09" /* SMS messages */
426 "01" /* CP-DATA */
427 "58" /* length */
428 "01" /* Network to MS */
429 "00" /* reference */
430 /* originator (gsm411_send_sms() hardcodes this weird nr) */
431 "0791" "447758100650" /* 447785016005 */
432 "00" /* dest */
433 /* SMS TPDU */
434 "4c" /* len */
435 "00" /* SMS deliver */
436 "05806470f1" /* originating address 46071 */
437 "00" /* TP-PID */
438 "00" /* GSM default alphabet */
439 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
440 "000000" /* H-M-S */
441 "00" /* GMT+0 */
442 "44" /* data length */
443 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
444 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
445 "0c7ac3e9e9b7db05");
446 ms_sends_msg("0632");
447 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
448 VERBOSE_ASSERT(paging_stopped, == true, "%d");
449
450 btw("SMS was delivered, no requests pending for subscr");
451 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
452 OSMO_ASSERT(vsub);
453 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
454 vlr_subscr_put(vsub);
455
456 btw("conn is still open to wait for SMS ack dance");
457 EXPECT_CONN_COUNT(1);
458
459 btw("MS replies with CP-ACK for received SMS");
460 ms_sends_msg("8904");
461 EXPECT_CONN_COUNT(1);
462
463 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
464 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200465 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100466 ms_sends_msg("890106020041020000");
467 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200468 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100469
470 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200471 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100472 EXPECT_CONN_COUNT(0);
473
474 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200475 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100476 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200477 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100478
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200479 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100480 EXPECT_CONN_COUNT(0);
481 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100482 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100483}
484
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100485static void test_ciph_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100486{
487 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100488 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100489
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100490 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100491
492 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100493 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100494 net->vlr->cfg.check_imei_rqd = true;
495
496 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
497 lu_result_sent = RES_NONE;
498 gsup_expect_tx("08010809710000004026f0");
499 ms_sends_msg("050802008168000130089910070000006402");
500 OSMO_ASSERT(gsup_tx_confirmed);
501 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
502
503 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
504 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
505 auth_request_sent = false;
506 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
507 auth_request_expect_autn = NULL;
508 gsup_rx("0a"
509 /* imsi */
510 "0108" "09710000004026f0"
511 /* 5 auth vectors... */
512 /* TL TL rand */
513 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
514 /* TL sres TL kc */
515 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
516 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
517 "2104" "20bde240" "2208" "07fa7502e07e1c00"
518 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
519 "2104" "a29514ae" "2208" "e2b234f807886400"
520 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
521 "2104" "5afc8d72" "2208" "2392f14f709ae000"
522 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
523 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
524 NULL);
525 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
526 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
527
528 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100529 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100530 ms_sends_msg("05542d8b2c3e");
531 OSMO_ASSERT(cipher_mode_cmd_sent);
532 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
533
534 btw("needs ciph, not yet accepted");
535 EXPECT_ACCEPTED(false);
536 thwart_rx_non_initial_requests();
537 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
538
539 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
540 gsup_expect_tx("04010809710000004026f0");
541 ms_sends_msg("0632");
542 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
543
544 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
545 gsup_rx("10010809710000004026f00804036470f1",
546 "12010809710000004026f0");
547 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
548
549 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
550 dtap_expect_tx("051802");
551 gsup_rx("06010809710000004026f0", NULL);
552
553 btw("We will only do business when the IMEI is known");
554 EXPECT_CONN_COUNT(1);
555 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
556 OSMO_ASSERT(vsub);
557 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
558 vlr_subscr_put(vsub);
559 EXPECT_ACCEPTED(false);
560 thwart_rx_non_initial_requests();
561
562 btw("MS replies with an Identity Response");
Philipp Maierfbf66102017-04-09 12:32:51 +0200563 expect_bssap_clear();
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200564 ms_sends_msg("0559084a32244332244302");
Philipp Maierfbf66102017-04-09 12:32:51 +0200565 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100566
567 btw("LU was successful, and the conn has already been closed");
568 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200569 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100570 EXPECT_CONN_COUNT(0);
571
572 btw("Subscriber has the IMEI");
573 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
574 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200575 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100576 vlr_subscr_put(vsub);
577
578 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200579 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100580 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200581 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100582
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200583 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100584 EXPECT_CONN_COUNT(0);
585 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100586 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100587}
588
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100589static void test_ciph_imeisv()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100590{
591 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100592 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100593
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100594 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100595
596 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100597 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr54a706c2017-07-18 15:39:27 +0200598 net->vlr->cfg.retrieve_imeisv_ciphered = true;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100599
600 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
601 lu_result_sent = RES_NONE;
602 gsup_expect_tx("08010809710000004026f0");
603 ms_sends_msg("050802008168000130089910070000006402");
604 OSMO_ASSERT(gsup_tx_confirmed);
605 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
606
607 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
608 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
609 auth_request_sent = false;
610 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
611 auth_request_expect_autn = NULL;
612 gsup_rx("0a"
613 /* imsi */
614 "0108" "09710000004026f0"
615 /* 5 auth vectors... */
616 /* TL TL rand */
617 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
618 /* TL sres TL kc */
619 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
620 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
621 "2104" "20bde240" "2208" "07fa7502e07e1c00"
622 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
623 "2104" "a29514ae" "2208" "e2b234f807886400"
624 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
625 "2104" "5afc8d72" "2208" "2392f14f709ae000"
626 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
627 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
628 NULL);
629 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
630 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
631
632 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100633 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100634 ms_sends_msg("05542d8b2c3e");
635 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
636 VERBOSE_ASSERT(cipher_mode_cmd_sent_with_imeisv, == true, "%d");
637 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
638
639 btw("needs ciph, not yet accepted");
640 EXPECT_ACCEPTED(false);
641 thwart_rx_non_initial_requests();
642 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
643
644 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
645 OSMO_ASSERT(vsub);
646 VERBOSE_ASSERT(vsub->imeisv[0], == 0, "%d");
647 vlr_subscr_put(vsub);
648
649 btw("MS sends Ciphering Mode Complete with IMEISV, VLR accepts and sends GSUP LU Req to HLR");
650 gsup_expect_tx("04010809710000004026f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200651 ms_sends_msg("063217094b32244332244372f5");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100652 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
653
654 btw("Subscriber has the IMEISV");
655 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
656 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200657 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100658 vlr_subscr_put(vsub);
659
660 EXPECT_ACCEPTED(false);
661 thwart_rx_non_initial_requests();
662
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100663 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
664 gsup_rx("10010809710000004026f00804036470f1",
665 "12010809710000004026f0");
666 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
667
668 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200669 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100670 gsup_rx("06010809710000004026f0", NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200671 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100672
673 btw("LU was successful, and the conn has already been closed");
674 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200675 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100676 EXPECT_CONN_COUNT(0);
677
678 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200679 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100680 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200681 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100682
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200683 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100684 EXPECT_CONN_COUNT(0);
685 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100686 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100687}
688
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100689static void test_ciph_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100690{
691 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100692 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100693
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100694 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100695
696 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100697 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100698 net->vlr->cfg.assign_tmsi = true;
699 net->vlr->cfg.check_imei_rqd = true;
700
701 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
702 lu_result_sent = RES_NONE;
703 gsup_expect_tx("08010809710000004026f0");
704 ms_sends_msg("050802008168000130089910070000006402");
705 OSMO_ASSERT(gsup_tx_confirmed);
706 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
707
708 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
709 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
710 auth_request_sent = false;
711 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
712 auth_request_expect_autn = NULL;
713 gsup_rx("0a"
714 /* imsi */
715 "0108" "09710000004026f0"
716 /* 5 auth vectors... */
717 /* TL TL rand */
718 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
719 /* TL sres TL kc */
720 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
721 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
722 "2104" "20bde240" "2208" "07fa7502e07e1c00"
723 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
724 "2104" "a29514ae" "2208" "e2b234f807886400"
725 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
726 "2104" "5afc8d72" "2208" "2392f14f709ae000"
727 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
728 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
729 NULL);
730 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
731 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
732
733 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100734 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100735 ms_sends_msg("05542d8b2c3e");
736 OSMO_ASSERT(cipher_mode_cmd_sent);
737 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
738
739 btw("needs ciph, not yet accepted");
740 EXPECT_ACCEPTED(false);
741 thwart_rx_non_initial_requests();
742 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
743
744 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
745 gsup_expect_tx("04010809710000004026f0");
746 ms_sends_msg("0632");
747 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
748
749 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
750 gsup_rx("10010809710000004026f00804036470f1",
751 "12010809710000004026f0");
752 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
753
754 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
755 dtap_expect_tx("051802");
756 gsup_rx("06010809710000004026f0", NULL);
757
758 btw("We will only do business when the IMEI is known");
759 EXPECT_CONN_COUNT(1);
760 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
761 OSMO_ASSERT(vsub);
762 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
763 vlr_subscr_put(vsub);
764 EXPECT_ACCEPTED(false);
765 thwart_rx_non_initial_requests();
766
767 btw("MS replies with an Identity Response");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200768 ms_sends_msg("0559084a32244332244302");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100769
770 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
771 EXPECT_CONN_COUNT(1);
772 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
773 EXPECT_ACCEPTED(false);
774 thwart_rx_non_initial_requests();
775
776 btw("even though the TMSI is not acked, we can already find the subscr with it");
777 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
778 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
779 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
780 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
781 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
782 vlr_subscr_put(vsub);
783
784 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200785 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100786 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200787 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100788
789 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200790 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100791 EXPECT_CONN_COUNT(0);
792
793 btw("Subscriber has the IMEI and TMSI");
794 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
795 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200796 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100797 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
798 vlr_subscr_put(vsub);
799
800 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200801 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100802 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200803 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100804
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200805 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100806 EXPECT_CONN_COUNT(0);
807 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100808 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100809}
810
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100811static void test_gsm_ciph_in_umts_env()
812{
813 struct vlr_subscr *vsub;
814 const char *imsi = "901700000010650";
815 const char *sms =
816 "09" /* SMS messages */
817 "01" /* CP-DATA */
818 "58" /* length */
819 "01" /* Network to MS */
820 "00" /* reference */
821 /* originator (gsm411_send_sms() hardcodes this weird nr) */
822 "0791" "447758100650" /* 447785016005 */
823 "00" /* dest */
824 /* SMS TPDU */
825 "4c" /* len */
826 "00" /* SMS deliver */
827 "05802443f2" /* originating address 42342 */
828 "00" /* TP-PID */
829 "00" /* GSM default alphabet */
830 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
831 "000000" /* H-M-S */
832 "00" /* GMT+0 */
833 "44" /* data length */
834 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
835 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
836 "0c7ac3e9e9b7db05";
837
838 comment_start();
839
840 /* implicit: net->authentication_required = true; */
841 net->a5_encryption_mask = (1 << 1);
842 rx_from_ran = RAN_GERAN_A;
843
844 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
845 lu_result_sent = RES_NONE;
846 gsup_expect_tx("080108" "09710000000156f0");
847 ms_sends_msg("0508" /* MM LU */
848 "7" /* ciph key seq: no key available */
849 "0" /* LU type: normal */
850 "ffffff" "0000" /* LAI, LAC */
851 "57" /* classmark 1: R99, early classmark, no power lvl */
852 "089910070000106005" /* IMSI */
853 "3303575886" /* classmark 2 */
854 );
855 OSMO_ASSERT(gsup_tx_confirmed);
856 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
857
858 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends *UMTS AKA* Auth Req to MS");
859 /* based on
860 * 2G auth: COMP128v1
861 * KI=7bcd108be4c3d551ee6c67faaf52bd68
862 * 3G auth: MILENAGE
863 * K=7bcd108be4c3d551ee6c67faaf52bd68
864 * OPC=6e23f641ce724679b73d933515a8589d
865 * IND-bitlen=5 last-SQN=641
866 * Note that the SRES will be calculated by COMP128v1, separately from 3G tokens;
867 * the resulting Kc to use for ciphering returned by the HLR is also calculated from COMP128v1.
868 */
869 auth_request_sent = false;
870 auth_request_expect_rand = "4ac8d1cd1a51937597ca1016fe69a0fa";
871 auth_request_expect_autn = "2d837d2b0d6f00004b282d5acf23428d";
872 gsup_rx("0a"
873 /* imsi */
874 "0108" "09710000000156f0"
875 /* 5 auth vectors... */
876 /* TL TL rand */
877 "0362" "2010" "4ac8d1cd1a51937597ca1016fe69a0fa"
878 /* TL sres TL kc */
879 "2104" "dacc4b26" "2208" "7a75f0ac9b844400"
880 /* TL 3G IK */
881 "2310" "3747da4e31545baa2db59e500bdae047"
882 /* TL 3G CK */
883 "2410" "8544d35b945ccba01a7f1293575291c3"
884 /* TL AUTN */
885 "2510" "2d837d2b0d6f00004b282d5acf23428d"
886 /* TL RES */
887 "2708" "37527064741f8ddb"
888 /* TL TL rand */
889 "0362" "2010" "b2661531b97b12c5a2edc21a0ed16fc5"
890 "2104" "2fb4cfad" "2208" "da149b11d473f400"
891 "2310" "3fe013b1a428ea737c37f8f0288c8edf"
892 "2410" "f275438c02b97e4d6f639dddda3d10b9"
893 "2510" "78cdd96c60840000322f421b3bb778b1"
894 "2708" "ed3ebf9cb6ea48ed"
895 "0362" "2010" "54d8f19778056666b41c8c25e52eb60c"
896 "2104" "0ff61e0f" "2208" "26ec67fad3073000"
897 "2310" "2868b0922c652616f1c975e3eaf7943a"
898 "2410" "6a84a20b1bc13ec9840466406d2dd91e"
899 "2510" "53f3e5632b3d00008865dd54d49663f2"
900 "2708" "86e848a9e7ad8cd5"
901 "0362" "2010" "1f05607ff9c8984f46ad97f8c9a94982"
902 "2104" "91a36e3d" "2208" "5d84421884fdcc00"
903 "2310" "2171fef54b81e30c83a598a5e44f634c"
904 "2410" "f02d088697509827565b46938fece211"
905 "2510" "1b43bbf9815e00001cb9b2a9f6b8a77c"
906 "2708" "373e67d62e719c51"
907 "0362" "2010" "80d89a58a2a41050918caf68a4e93c64"
908 "2104" "a319f5f1" "2208" "883df2b867293000"
909 "2310" "fa5d70f929ff298efb160413698dc107"
910 "2410" "ae9a3d8ce70ce13bac297bdb91cd6c68"
911 "2510" "5c0dc2eeaefa0000396882a1fe2cf80b"
912 "2708" "65ab1cad216bfe87",
913 NULL);
914 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
915 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
916
917 btw("MS sends *GSM AKA* Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100918 expect_cipher_mode_cmd("7a75f0ac9b844400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100919 ms_sends_msg("0554" "dacc4b26");
920 OSMO_ASSERT(cipher_mode_cmd_sent);
921 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
922
923 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
924 gsup_expect_tx("04010809710000000156f0");
925 ms_sends_msg("0632");
926 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
927
928 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
929 gsup_rx("10010809710000000156f00804032443f2",
930 "12010809710000000156f0");
931 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
932
933 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
934 expect_bssap_clear();
935 gsup_rx("06010809710000000156f0", NULL);
936 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
937
938 btw("LU was successful, and the conn has already been closed");
939 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200940 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100941 EXPECT_CONN_COUNT(0);
942
943 BTW("after a while, a new conn sends a CM Service Request. VLR responds with *UMTS AKA* Auth Req, 2nd auth vector");
944 auth_request_sent = false;
945 auth_request_expect_rand = "b2661531b97b12c5a2edc21a0ed16fc5";
946 auth_request_expect_autn = "78cdd96c60840000322f421b3bb778b1";
947 cm_service_result_sent = RES_NONE;
948 ms_sends_msg("052478"
949 "03575886" /* classmark 2 */
950 "089910070000106005" /* IMSI */);
951 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200952 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100953 OSMO_ASSERT(g_conn->vsub);
954 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
955 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
956
957 btw("needs auth, not yet accepted");
958 EXPECT_ACCEPTED(false);
959 thwart_rx_non_initial_requests();
960
961 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100962 expect_cipher_mode_cmd("da149b11d473f400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100963 ms_sends_msg("0554" "2fb4cfad");
964 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
965 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
966
967 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
968 ms_sends_msg("0632");
969 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
970
971 btw("a USSD request is serviced");
972 dtap_expect_tx_ussd("Your extension is 42342\r");
973 expect_bssap_clear();
974 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
975 OSMO_ASSERT(dtap_tx_confirmed);
976 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
977
978 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200979 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100980 EXPECT_CONN_COUNT(0);
981
982 BTW("an SMS is sent, MS is paged");
983 paging_expect_imsi(imsi);
984 paging_sent = false;
985 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
986 OSMO_ASSERT(vsub);
987 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
988
989 send_sms(vsub, vsub,
990 "Privacy in residential applications is a desirable"
991 " marketing option.");
992
993 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
994 vlr_subscr_put(vsub);
995 vsub = NULL;
996 VERBOSE_ASSERT(paging_sent, == true, "%d");
997 VERBOSE_ASSERT(paging_stopped, == false, "%d");
998
999 btw("the subscriber and its pending request should remain");
1000 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1001 OSMO_ASSERT(vsub);
1002 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
1003 vlr_subscr_put(vsub);
1004
1005 btw("MS replies with Paging Response, and VLR sends *UMTS AKA* Auth Request with third key");
1006 auth_request_sent = false;
1007 auth_request_expect_rand = "54d8f19778056666b41c8c25e52eb60c";
1008 auth_request_expect_autn = "53f3e5632b3d00008865dd54d49663f2";
1009 ms_sends_msg("062707"
1010 "03575886" /* classmark 2 */
1011 "089910070000106005" /* IMSI */);
1012 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1013
1014 btw("needs auth, not yet accepted");
1015 EXPECT_ACCEPTED(false);
1016 thwart_rx_non_initial_requests();
1017
1018 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001019 expect_cipher_mode_cmd("26ec67fad3073000");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001020 ms_sends_msg("0554" "0ff61e0f");
1021 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1022
1023 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1024 dtap_expect_tx(sms);
1025 ms_sends_msg("0632");
1026 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1027 VERBOSE_ASSERT(paging_stopped, == true, "%d");
1028
1029 btw("SMS was delivered, no requests pending for subscr");
1030 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1031 OSMO_ASSERT(vsub);
1032 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1033 vlr_subscr_put(vsub);
1034
1035 btw("conn is still open to wait for SMS ack dance");
1036 EXPECT_CONN_COUNT(1);
1037
1038 btw("MS replies with CP-ACK for received SMS");
1039 ms_sends_msg("8904");
1040 EXPECT_CONN_COUNT(1);
1041
1042 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1043 dtap_expect_tx("0904");
1044 expect_bssap_clear();
1045 ms_sends_msg("890106020041020000");
1046 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1047 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1048
1049 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +02001050 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001051 EXPECT_CONN_COUNT(0);
1052
1053 BTW("subscriber detaches");
1054 expect_bssap_clear();
1055 ms_sends_msg("050130"
1056 "089910070000106005" /* IMSI */);
1057 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1058
Neels Hofmeyr4068ab22018-04-01 20:55:54 +02001059 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001060 EXPECT_CONN_COUNT(0);
1061 clear_vlr();
1062 comment_end();
1063}
1064
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001065static void test_a5_3_not_supported()
1066{
1067 comment_start();
1068
1069 /* implicit: net->authentication_required = true; */
1070 net->a5_encryption_mask = (1 << 3); /* A5/3 */
1071
1072 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1073 lu_result_sent = RES_NONE;
1074 gsup_expect_tx("08010809710000004026f0");
1075 ms_sends_msg("050802008168000130089910070000006402");
1076 OSMO_ASSERT(gsup_tx_confirmed);
1077 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1078
1079 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1080 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1081 auth_request_sent = false;
1082 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1083 auth_request_expect_autn = NULL;
1084 gsup_rx("0a"
1085 /* imsi */
1086 "0108" "09710000004026f0"
1087 /* 5 auth vectors... */
1088 /* TL TL rand */
1089 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1090 /* TL sres TL kc */
1091 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1092 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1093 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1094 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1095 "2104" "a29514ae" "2208" "e2b234f807886400"
1096 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1097 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1098 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
1099 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
1100 NULL);
1101 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1102 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1103
1104 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
1105 " -- alas, no matching cipher can be found, abort and release");
1106 cipher_mode_cmd_sent = false;
1107 expect_bssap_clear();
1108 ms_sends_msg("05542d8b2c3e");
1109 OSMO_ASSERT(!cipher_mode_cmd_sent);
1110 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
1111
Neels Hofmeyr4068ab22018-04-01 20:55:54 +02001112 bss_sends_clear_complete();
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001113 EXPECT_CONN_COUNT(0);
1114 clear_vlr();
1115 comment_end();
1116}
1117
1118
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001119msc_vlr_test_func_t msc_vlr_tests[] = {
1120 test_ciph,
1121 test_ciph_tmsi,
1122 test_ciph_imei,
1123 test_ciph_imeisv,
1124 test_ciph_tmsi_imei,
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001125 test_gsm_ciph_in_umts_env,
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001126 test_a5_3_not_supported,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001127 NULL
1128};