blob: 31b5f5d323b6c8009d971406714a394b9e6335d6 [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");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +020080 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010081 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
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700128 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100129 expect_bssap_clear(OSMO_RAT_GERAN_A);
130 conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100131
132 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200133 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100134 EXPECT_CONN_COUNT(0);
135
136 BTW("an SMS is sent, MS is paged");
137 paging_expect_imsi(imsi);
138 paging_sent = false;
139 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
140 OSMO_ASSERT(vsub);
141 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
142
143 send_sms(vsub, vsub,
144 "Privacy in residential applications is a desirable"
145 " marketing option.");
146
147 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
148 vlr_subscr_put(vsub);
149 vsub = NULL;
150 VERBOSE_ASSERT(paging_sent, == true, "%d");
151 VERBOSE_ASSERT(paging_stopped, == false, "%d");
152
153 btw("the subscriber and its pending request should remain");
154 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
155 OSMO_ASSERT(vsub);
156 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
157 vlr_subscr_put(vsub);
158
159 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
160 auth_request_sent = false;
161 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
162 ms_sends_msg("06270703305882089910070000006402");
163 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
164
165 btw("needs auth, not yet accepted");
166 EXPECT_ACCEPTED(false);
167 thwart_rx_non_initial_requests();
168
169 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100170 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100171 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
172 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
173
174 btw("needs ciph, not yet accepted");
175 EXPECT_ACCEPTED(false);
176 thwart_rx_non_initial_requests();
177
178 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
179 dtap_expect_tx("09" /* SMS messages */
180 "01" /* CP-DATA */
181 "58" /* length */
182 "01" /* Network to MS */
183 "00" /* reference */
184 /* originator (gsm411_send_sms() hardcodes this weird nr) */
185 "0791" "447758100650" /* 447785016005 */
186 "00" /* dest */
187 /* SMS TPDU */
188 "4c" /* len */
189 "00" /* SMS deliver */
190 "05806470f1" /* originating address 46071 */
191 "00" /* TP-PID */
192 "00" /* GSM default alphabet */
193 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
194 "000000" /* H-M-S */
195 "00" /* GMT+0 */
196 "44" /* data length */
197 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
198 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
199 "0c7ac3e9e9b7db05");
200 ms_sends_msg("0632");
201 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
202 VERBOSE_ASSERT(paging_stopped, == true, "%d");
203
204 btw("SMS was delivered, no requests pending for subscr");
205 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
206 OSMO_ASSERT(vsub);
207 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
208 vlr_subscr_put(vsub);
209
210 btw("conn is still open to wait for SMS ack dance");
211 EXPECT_CONN_COUNT(1);
212
213 btw("MS replies with CP-ACK for received SMS");
214 ms_sends_msg("8904");
215 EXPECT_CONN_COUNT(1);
216
217 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
218 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200219 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100220 ms_sends_msg("890106020041020000");
221 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200222 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100223
224 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200225 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100226 EXPECT_CONN_COUNT(0);
227
228 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200229 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100230 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200231 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100232
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200233 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100234 EXPECT_CONN_COUNT(0);
235 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100236 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100237}
238
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100239static void test_ciph_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100240{
241 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100242 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100243
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100244 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100245
246 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100247 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100248 net->vlr->cfg.assign_tmsi = true;
249
250 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
251 lu_result_sent = RES_NONE;
252 gsup_expect_tx("08010809710000004026f0");
253 ms_sends_msg("050802008168000130089910070000006402");
254 OSMO_ASSERT(gsup_tx_confirmed);
255 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
256
257 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
258 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
259 auth_request_sent = false;
260 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
261 auth_request_expect_autn = NULL;
262 gsup_rx("0a"
263 /* imsi */
264 "0108" "09710000004026f0"
265 /* 5 auth vectors... */
266 /* TL TL rand */
267 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
268 /* TL sres TL kc */
269 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
270 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
271 "2104" "20bde240" "2208" "07fa7502e07e1c00"
272 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
273 "2104" "a29514ae" "2208" "e2b234f807886400"
274 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
275 "2104" "5afc8d72" "2208" "2392f14f709ae000"
276 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
277 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
278 NULL);
279 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
280 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
281
282 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100283 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100284 ms_sends_msg("05542d8b2c3e");
285 OSMO_ASSERT(cipher_mode_cmd_sent);
286 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
287 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
288
289 btw("needs ciph, not yet accepted");
290 EXPECT_ACCEPTED(false);
291 thwart_rx_non_initial_requests();
292 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
293
294 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200295 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100296 ms_sends_msg("0632");
297 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
298
299 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
300 gsup_rx("10010809710000004026f00804036470f1",
301 "12010809710000004026f0");
302 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
303
304 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
305 gsup_rx("06010809710000004026f0", NULL);
306
307 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
308 EXPECT_CONN_COUNT(1);
309 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
310 EXPECT_ACCEPTED(false);
311 thwart_rx_non_initial_requests();
312
313 btw("even though the TMSI is not acked, we can already find the subscr with it");
314 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
315 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
316 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
317 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
318 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
319 vlr_subscr_put(vsub);
320
321 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200322 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100323 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200324 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100325
326 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200327 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100328 EXPECT_CONN_COUNT(0);
329
330 btw("Subscriber has the new TMSI");
331 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
332 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
333 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
334 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
335 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
336 vlr_subscr_put(vsub);
337
338 BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector");
339 cm_service_result_sent = RES_NONE;
340 auth_request_sent = false;
341 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
342 auth_request_expect_autn = NULL;
343 ms_sends_msg("05247803305886" "05f4" "03020100");
344 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200345 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100346 OSMO_ASSERT(g_conn->vsub);
347 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
348 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
349
350 btw("needs auth, not yet accepted");
351 EXPECT_ACCEPTED(false);
352 thwart_rx_non_initial_requests();
353
354 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100355 expect_cipher_mode_cmd("07fa7502e07e1c00");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100356 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
357 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
358 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
359
360 btw("needs ciph, not yet accepted");
361 EXPECT_ACCEPTED(false);
362 thwart_rx_non_initial_requests();
363
364 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
365 ms_sends_msg("0632");
366 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
367
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700368 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100369 expect_bssap_clear(OSMO_RAT_GERAN_A);
370 conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100371
372 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200373 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100374 EXPECT_CONN_COUNT(0);
375
376 BTW("an SMS is sent, MS is paged");
377 paging_expect_tmsi(0x03020100);
378 paging_sent = false;
379 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
380 OSMO_ASSERT(vsub);
381 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
382
383 send_sms(vsub, vsub,
384 "Privacy in residential applications is a desirable"
385 " marketing option.");
386
387 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
388 vlr_subscr_put(vsub);
389 vsub = NULL;
390 VERBOSE_ASSERT(paging_sent, == true, "%d");
391 VERBOSE_ASSERT(paging_stopped, == false, "%d");
392
393 btw("the subscriber and its pending request should remain");
394 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
395 OSMO_ASSERT(vsub);
396 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
397 vlr_subscr_put(vsub);
398
399 btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key");
400 auth_request_sent = false;
401 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
402 ms_sends_msg("06270703305882" "05f4" "03020100");
403 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
404
405 btw("needs auth, not yet accepted");
406 EXPECT_ACCEPTED(false);
407 thwart_rx_non_initial_requests();
408
409 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100410 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100411 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
412 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
413
414 btw("needs ciph, not yet accepted");
415 EXPECT_ACCEPTED(false);
416 thwart_rx_non_initial_requests();
417
418 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
419 dtap_expect_tx("09" /* SMS messages */
420 "01" /* CP-DATA */
421 "58" /* length */
422 "01" /* Network to MS */
423 "00" /* reference */
424 /* originator (gsm411_send_sms() hardcodes this weird nr) */
425 "0791" "447758100650" /* 447785016005 */
426 "00" /* dest */
427 /* SMS TPDU */
428 "4c" /* len */
429 "00" /* SMS deliver */
430 "05806470f1" /* originating address 46071 */
431 "00" /* TP-PID */
432 "00" /* GSM default alphabet */
433 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
434 "000000" /* H-M-S */
435 "00" /* GMT+0 */
436 "44" /* data length */
437 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
438 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
439 "0c7ac3e9e9b7db05");
440 ms_sends_msg("0632");
441 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
442 VERBOSE_ASSERT(paging_stopped, == true, "%d");
443
444 btw("SMS was delivered, no requests pending for subscr");
445 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
446 OSMO_ASSERT(vsub);
447 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
448 vlr_subscr_put(vsub);
449
450 btw("conn is still open to wait for SMS ack dance");
451 EXPECT_CONN_COUNT(1);
452
453 btw("MS replies with CP-ACK for received SMS");
454 ms_sends_msg("8904");
455 EXPECT_CONN_COUNT(1);
456
457 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
458 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200459 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100460 ms_sends_msg("890106020041020000");
461 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200462 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100463
464 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200465 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100466 EXPECT_CONN_COUNT(0);
467
468 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200469 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100470 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200471 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100472
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200473 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100474 EXPECT_CONN_COUNT(0);
475 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100476 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100477}
478
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100479static void test_ciph_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100480{
481 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100482 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100483
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100484 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100485
486 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100487 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100488 net->vlr->cfg.check_imei_rqd = true;
489
490 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
491 lu_result_sent = RES_NONE;
492 gsup_expect_tx("08010809710000004026f0");
493 ms_sends_msg("050802008168000130089910070000006402");
494 OSMO_ASSERT(gsup_tx_confirmed);
495 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
496
497 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
498 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
499 auth_request_sent = false;
500 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
501 auth_request_expect_autn = NULL;
502 gsup_rx("0a"
503 /* imsi */
504 "0108" "09710000004026f0"
505 /* 5 auth vectors... */
506 /* TL TL rand */
507 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
508 /* TL sres TL kc */
509 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
510 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
511 "2104" "20bde240" "2208" "07fa7502e07e1c00"
512 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
513 "2104" "a29514ae" "2208" "e2b234f807886400"
514 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
515 "2104" "5afc8d72" "2208" "2392f14f709ae000"
516 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
517 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
518 NULL);
519 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
520 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
521
522 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100523 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100524 ms_sends_msg("05542d8b2c3e");
525 OSMO_ASSERT(cipher_mode_cmd_sent);
526 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
527
528 btw("needs ciph, not yet accepted");
529 EXPECT_ACCEPTED(false);
530 thwart_rx_non_initial_requests();
531 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
532
533 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200534 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100535 ms_sends_msg("0632");
536 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
537
538 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
539 gsup_rx("10010809710000004026f00804036470f1",
540 "12010809710000004026f0");
541 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
542
543 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
544 dtap_expect_tx("051802");
545 gsup_rx("06010809710000004026f0", NULL);
546
547 btw("We will only do business when the IMEI is known");
548 EXPECT_CONN_COUNT(1);
549 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
550 OSMO_ASSERT(vsub);
551 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
552 vlr_subscr_put(vsub);
553 EXPECT_ACCEPTED(false);
554 thwart_rx_non_initial_requests();
555
Oliver Smith7d053092018-12-14 17:37:38 +0100556 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
557 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200558 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100559 EXPECT_ACCEPTED(false);
560 thwart_rx_non_initial_requests();
561
562 btw("HLR accepts the IMEI");
563 expect_bssap_clear();
564 gsup_rx("32010809710000004026f0510100", NULL);
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");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200650 gsup_expect_tx("04010809710000004026f0280102");
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");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200745 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100746 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
Oliver Smith7d053092018-12-14 17:37:38 +0100767 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
768 gsup_expect_tx("30010809710000004026f050090824433224433224f0");
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200769 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100770 EXPECT_ACCEPTED(false);
771 thwart_rx_non_initial_requests();
772
773 btw("HLR accepts the IMEI");
774 gsup_rx("32010809710000004026f0510100", NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100775
776 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
777 EXPECT_CONN_COUNT(1);
778 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
779 EXPECT_ACCEPTED(false);
780 thwart_rx_non_initial_requests();
781
782 btw("even though the TMSI is not acked, we can already find the subscr with it");
783 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
784 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
785 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
786 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
787 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
788 vlr_subscr_put(vsub);
789
790 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200791 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100792 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200793 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100794
795 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200796 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100797 EXPECT_CONN_COUNT(0);
798
799 btw("Subscriber has the IMEI and TMSI");
800 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
801 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200802 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100803 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
804 vlr_subscr_put(vsub);
805
806 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200807 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100808 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200809 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100810
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200811 bss_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100812 EXPECT_CONN_COUNT(0);
813 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100814 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100815}
816
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100817static void test_gsm_ciph_in_umts_env()
818{
819 struct vlr_subscr *vsub;
820 const char *imsi = "901700000010650";
821 const char *sms =
822 "09" /* SMS messages */
823 "01" /* CP-DATA */
824 "58" /* length */
825 "01" /* Network to MS */
826 "00" /* reference */
827 /* originator (gsm411_send_sms() hardcodes this weird nr) */
828 "0791" "447758100650" /* 447785016005 */
829 "00" /* dest */
830 /* SMS TPDU */
831 "4c" /* len */
832 "00" /* SMS deliver */
833 "05802443f2" /* originating address 42342 */
834 "00" /* TP-PID */
835 "00" /* GSM default alphabet */
836 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
837 "000000" /* H-M-S */
838 "00" /* GMT+0 */
839 "44" /* data length */
840 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
841 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
842 "0c7ac3e9e9b7db05";
843
844 comment_start();
845
846 /* implicit: net->authentication_required = true; */
847 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100848 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100849
850 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
851 lu_result_sent = RES_NONE;
852 gsup_expect_tx("080108" "09710000000156f0");
853 ms_sends_msg("0508" /* MM LU */
854 "7" /* ciph key seq: no key available */
855 "0" /* LU type: normal */
856 "ffffff" "0000" /* LAI, LAC */
857 "57" /* classmark 1: R99, early classmark, no power lvl */
858 "089910070000106005" /* IMSI */
859 "3303575886" /* classmark 2 */
860 );
861 OSMO_ASSERT(gsup_tx_confirmed);
862 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
863
864 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends *UMTS AKA* Auth Req to MS");
865 /* based on
866 * 2G auth: COMP128v1
867 * KI=7bcd108be4c3d551ee6c67faaf52bd68
868 * 3G auth: MILENAGE
869 * K=7bcd108be4c3d551ee6c67faaf52bd68
870 * OPC=6e23f641ce724679b73d933515a8589d
871 * IND-bitlen=5 last-SQN=641
872 * Note that the SRES will be calculated by COMP128v1, separately from 3G tokens;
873 * the resulting Kc to use for ciphering returned by the HLR is also calculated from COMP128v1.
874 */
875 auth_request_sent = false;
876 auth_request_expect_rand = "4ac8d1cd1a51937597ca1016fe69a0fa";
877 auth_request_expect_autn = "2d837d2b0d6f00004b282d5acf23428d";
878 gsup_rx("0a"
879 /* imsi */
880 "0108" "09710000000156f0"
881 /* 5 auth vectors... */
882 /* TL TL rand */
883 "0362" "2010" "4ac8d1cd1a51937597ca1016fe69a0fa"
884 /* TL sres TL kc */
885 "2104" "dacc4b26" "2208" "7a75f0ac9b844400"
886 /* TL 3G IK */
887 "2310" "3747da4e31545baa2db59e500bdae047"
888 /* TL 3G CK */
889 "2410" "8544d35b945ccba01a7f1293575291c3"
890 /* TL AUTN */
891 "2510" "2d837d2b0d6f00004b282d5acf23428d"
892 /* TL RES */
893 "2708" "37527064741f8ddb"
894 /* TL TL rand */
895 "0362" "2010" "b2661531b97b12c5a2edc21a0ed16fc5"
896 "2104" "2fb4cfad" "2208" "da149b11d473f400"
897 "2310" "3fe013b1a428ea737c37f8f0288c8edf"
898 "2410" "f275438c02b97e4d6f639dddda3d10b9"
899 "2510" "78cdd96c60840000322f421b3bb778b1"
900 "2708" "ed3ebf9cb6ea48ed"
901 "0362" "2010" "54d8f19778056666b41c8c25e52eb60c"
902 "2104" "0ff61e0f" "2208" "26ec67fad3073000"
903 "2310" "2868b0922c652616f1c975e3eaf7943a"
904 "2410" "6a84a20b1bc13ec9840466406d2dd91e"
905 "2510" "53f3e5632b3d00008865dd54d49663f2"
906 "2708" "86e848a9e7ad8cd5"
907 "0362" "2010" "1f05607ff9c8984f46ad97f8c9a94982"
908 "2104" "91a36e3d" "2208" "5d84421884fdcc00"
909 "2310" "2171fef54b81e30c83a598a5e44f634c"
910 "2410" "f02d088697509827565b46938fece211"
911 "2510" "1b43bbf9815e00001cb9b2a9f6b8a77c"
912 "2708" "373e67d62e719c51"
913 "0362" "2010" "80d89a58a2a41050918caf68a4e93c64"
914 "2104" "a319f5f1" "2208" "883df2b867293000"
915 "2310" "fa5d70f929ff298efb160413698dc107"
916 "2410" "ae9a3d8ce70ce13bac297bdb91cd6c68"
917 "2510" "5c0dc2eeaefa0000396882a1fe2cf80b"
918 "2708" "65ab1cad216bfe87",
919 NULL);
920 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
921 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
922
923 btw("MS sends *GSM AKA* Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100924 expect_cipher_mode_cmd("7a75f0ac9b844400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100925 ms_sends_msg("0554" "dacc4b26");
926 OSMO_ASSERT(cipher_mode_cmd_sent);
927 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
928
929 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +0200930 gsup_expect_tx("04010809710000000156f0280102");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100931 ms_sends_msg("0632");
932 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
933
934 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
935 gsup_rx("10010809710000000156f00804032443f2",
936 "12010809710000000156f0");
937 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
938
939 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
940 expect_bssap_clear();
941 gsup_rx("06010809710000000156f0", NULL);
942 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
943
944 btw("LU was successful, and the conn has already been closed");
945 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200946 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100947 EXPECT_CONN_COUNT(0);
948
949 BTW("after a while, a new conn sends a CM Service Request. VLR responds with *UMTS AKA* Auth Req, 2nd auth vector");
950 auth_request_sent = false;
951 auth_request_expect_rand = "b2661531b97b12c5a2edc21a0ed16fc5";
952 auth_request_expect_autn = "78cdd96c60840000322f421b3bb778b1";
953 cm_service_result_sent = RES_NONE;
954 ms_sends_msg("052478"
955 "03575886" /* classmark 2 */
956 "089910070000106005" /* IMSI */);
957 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200958 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100959 OSMO_ASSERT(g_conn->vsub);
960 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
961 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
962
963 btw("needs auth, not yet accepted");
964 EXPECT_ACCEPTED(false);
965 thwart_rx_non_initial_requests();
966
967 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100968 expect_cipher_mode_cmd("da149b11d473f400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100969 ms_sends_msg("0554" "2fb4cfad");
970 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
971 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
972
973 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
974 ms_sends_msg("0632");
975 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
976
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700977 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100978 expect_bssap_clear(OSMO_RAT_GERAN_A);
979 conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100980
981 btw("all requests serviced, conn has been released");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200982 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100983 EXPECT_CONN_COUNT(0);
984
985 BTW("an SMS is sent, MS is paged");
986 paging_expect_imsi(imsi);
987 paging_sent = false;
988 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
989 OSMO_ASSERT(vsub);
990 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
991
992 send_sms(vsub, vsub,
993 "Privacy in residential applications is a desirable"
994 " marketing option.");
995
996 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
997 vlr_subscr_put(vsub);
998 vsub = NULL;
999 VERBOSE_ASSERT(paging_sent, == true, "%d");
1000 VERBOSE_ASSERT(paging_stopped, == false, "%d");
1001
1002 btw("the subscriber and its pending request should remain");
1003 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1004 OSMO_ASSERT(vsub);
1005 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
1006 vlr_subscr_put(vsub);
1007
1008 btw("MS replies with Paging Response, and VLR sends *UMTS AKA* Auth Request with third key");
1009 auth_request_sent = false;
1010 auth_request_expect_rand = "54d8f19778056666b41c8c25e52eb60c";
1011 auth_request_expect_autn = "53f3e5632b3d00008865dd54d49663f2";
1012 ms_sends_msg("062707"
1013 "03575886" /* classmark 2 */
1014 "089910070000106005" /* IMSI */);
1015 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1016
1017 btw("needs auth, not yet accepted");
1018 EXPECT_ACCEPTED(false);
1019 thwart_rx_non_initial_requests();
1020
1021 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001022 expect_cipher_mode_cmd("26ec67fad3073000");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001023 ms_sends_msg("0554" "0ff61e0f");
1024 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1025
1026 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1027 dtap_expect_tx(sms);
1028 ms_sends_msg("0632");
1029 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1030 VERBOSE_ASSERT(paging_stopped, == true, "%d");
1031
1032 btw("SMS was delivered, no requests pending for subscr");
1033 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1034 OSMO_ASSERT(vsub);
1035 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1036 vlr_subscr_put(vsub);
1037
1038 btw("conn is still open to wait for SMS ack dance");
1039 EXPECT_CONN_COUNT(1);
1040
1041 btw("MS replies with CP-ACK for received SMS");
1042 ms_sends_msg("8904");
1043 EXPECT_CONN_COUNT(1);
1044
1045 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1046 dtap_expect_tx("0904");
1047 expect_bssap_clear();
1048 ms_sends_msg("890106020041020000");
1049 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1050 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1051
1052 btw("SMS is done, conn is gone");
Neels Hofmeyr4068ab22018-04-01 20:55:54 +02001053 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001054 EXPECT_CONN_COUNT(0);
1055
1056 BTW("subscriber detaches");
1057 expect_bssap_clear();
1058 ms_sends_msg("050130"
1059 "089910070000106005" /* IMSI */);
1060 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1061
Neels Hofmeyr4068ab22018-04-01 20:55:54 +02001062 bss_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001063 EXPECT_CONN_COUNT(0);
1064 clear_vlr();
1065 comment_end();
1066}
1067
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001068static void test_a5_3_supported()
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001069{
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001070 struct vlr_subscr *vsub;
1071 const char *imsi = "901700000004620";
1072
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001073 comment_start();
1074
1075 /* implicit: net->authentication_required = true; */
1076 net->a5_encryption_mask = (1 << 3); /* A5/3 */
1077
1078 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1079 lu_result_sent = RES_NONE;
1080 gsup_expect_tx("08010809710000004026f0");
1081 ms_sends_msg("050802008168000130089910070000006402");
1082 OSMO_ASSERT(gsup_tx_confirmed);
1083 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1084
1085 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1086 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1087 auth_request_sent = false;
1088 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1089 auth_request_expect_autn = NULL;
1090 gsup_rx("0a"
1091 /* imsi */
1092 "0108" "09710000004026f0"
1093 /* 5 auth vectors... */
1094 /* TL TL rand */
1095 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1096 /* TL sres TL kc */
1097 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1098 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1099 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1100 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1101 "2104" "a29514ae" "2208" "e2b234f807886400"
1102 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1103 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1104 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
1105 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
1106 NULL);
1107 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1108 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1109
1110 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001111 " -- but needs Classmark 2 to determine whether A5/3 is supported");
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001112 cipher_mode_cmd_sent = false;
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001113 ms_sends_msg("05542d8b2c3e");
1114 OSMO_ASSERT(!cipher_mode_cmd_sent);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001115 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1116
1117 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1118 expect_cipher_mode_cmd("61855fb81fc2a800");
1119 bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100");
1120 OSMO_ASSERT(cipher_mode_cmd_sent);
1121 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1122
1123 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +02001124 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001125 ms_sends_msg("0632");
1126 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1127
1128 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
1129 gsup_rx("10010809710000004026f00804032443f2",
1130 "12010809710000004026f0");
1131 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1132
1133 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
1134 expect_bssap_clear();
1135 gsup_rx("06010809710000004026f0", NULL);
1136 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1137
1138 btw("LU was successful, and the conn has already been closed");
1139 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
1140 bss_sends_clear_complete();
1141 EXPECT_CONN_COUNT(0);
1142
1143 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1144 cm_service_result_sent = RES_NONE;
1145 auth_request_sent = false;
1146 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
1147 ms_sends_msg("05247803305886089910070000006402");
1148 OSMO_ASSERT(g_conn);
1149 OSMO_ASSERT(g_conn->fi);
1150 OSMO_ASSERT(g_conn->vsub);
1151 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1152 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1153
1154 btw("needs auth, not yet accepted");
1155 EXPECT_ACCEPTED(false);
1156 thwart_rx_non_initial_requests();
1157
1158 btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3,"
1159 " so no need to request Classmark Update.");
1160 expect_cipher_mode_cmd("07fa7502e07e1c00");
1161 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
1162 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1163 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1164
1165 btw("needs ciph, not yet accepted");
1166 EXPECT_ACCEPTED(false);
1167 thwart_rx_non_initial_requests();
1168
1169 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
1170 ms_sends_msg("0632");
1171 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1172
1173 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +01001174 expect_bssap_clear(OSMO_RAT_GERAN_A);
1175 conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001176
1177 btw("all requests serviced, conn has been released");
1178 bss_sends_clear_complete();
1179 EXPECT_CONN_COUNT(0);
1180
1181 BTW("an SMS is sent, MS is paged");
1182 paging_expect_imsi(imsi);
1183 paging_sent = false;
1184 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1185 OSMO_ASSERT(vsub);
1186 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1187
1188 send_sms(vsub, vsub,
1189 "Privacy in residential applications is a desirable"
1190 " marketing option.");
1191
1192 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
1193 vlr_subscr_put(vsub);
1194 vsub = NULL;
1195 VERBOSE_ASSERT(paging_sent, == true, "%d");
1196 VERBOSE_ASSERT(paging_stopped, == false, "%d");
1197
1198 btw("the subscriber and its pending request should remain");
1199 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1200 OSMO_ASSERT(vsub);
1201 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
1202 vlr_subscr_put(vsub);
1203
1204 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1205 auth_request_sent = false;
1206 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
1207 ms_sends_msg("06270703305882089910070000006402");
1208 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1209
1210 btw("needs auth, not yet accepted");
1211 EXPECT_ACCEPTED(false);
1212 thwart_rx_non_initial_requests();
1213
1214 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
1215 expect_cipher_mode_cmd("e2b234f807886400");
1216 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
1217 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1218
1219 btw("needs ciph, not yet accepted");
1220 EXPECT_ACCEPTED(false);
1221 thwart_rx_non_initial_requests();
1222
1223 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1224 dtap_expect_tx("09" /* SMS messages */
1225 "01" /* CP-DATA */
1226 "58" /* length */
1227 "01" /* Network to MS */
1228 "00" /* reference */
1229 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1230 "0791" "447758100650" /* 447785016005 */
1231 "00" /* dest */
1232 /* SMS TPDU */
1233 "4c" /* len */
1234 "00" /* SMS deliver */
1235 "05802443f2" /* originating address 42342 */
1236 "00" /* TP-PID */
1237 "00" /* GSM default alphabet */
1238 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1239 "000000" /* H-M-S */
1240 "00" /* GMT+0 */
1241 "44" /* data length */
1242 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1243 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1244 "0c7ac3e9e9b7db05");
1245 ms_sends_msg("0632");
1246 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1247 VERBOSE_ASSERT(paging_stopped, == true, "%d");
1248
1249 btw("SMS was delivered, no requests pending for subscr");
1250 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1251 OSMO_ASSERT(vsub);
1252 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1253 vlr_subscr_put(vsub);
1254
1255 btw("conn is still open to wait for SMS ack dance");
1256 EXPECT_CONN_COUNT(1);
1257
1258 btw("MS replies with CP-ACK for received SMS");
1259 ms_sends_msg("8904");
1260 EXPECT_CONN_COUNT(1);
1261
1262 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1263 dtap_expect_tx("0904");
1264 expect_bssap_clear();
1265 ms_sends_msg("890106020041020000");
1266 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1267 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1268
1269 btw("SMS is done, conn is gone");
1270 bss_sends_clear_complete();
1271 EXPECT_CONN_COUNT(0);
1272
1273 BTW("subscriber detaches");
1274 expect_bssap_clear();
1275 ms_sends_msg("050130089910070000006402");
1276 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1277
1278 bss_sends_clear_complete();
1279 EXPECT_CONN_COUNT(0);
1280 clear_vlr();
1281 comment_end();
1282}
1283
1284/* During CM Service Request or Paging Response we already have Classmark 2 that indicates A5/3
1285 * availablity. Here, in a hacky way remove the knowledge of Classmark 2 to tickle a code path where
1286 * proc_arq_fsm needs a Classmark Update during Ciphering. Shouldn't happen in reality though. */
1287static void test_cm_service_needs_classmark_update()
1288{
1289 struct vlr_subscr *vsub;
1290 const char *imsi = "901700000004620";
1291
1292 comment_start();
1293
1294 /* A5/3 support is indicated in Classmark 3. By configuring A5/3, trigger the code paths that
1295 * send a Classmark Request. */
1296 net->a5_encryption_mask = (1 << 3); /* A5/3 */
1297 /* implicit: net->authentication_required = true; */
1298
1299 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1300 lu_result_sent = RES_NONE;
1301 gsup_expect_tx("08010809710000004026f0");
1302 ms_sends_msg("050802008168000130089910070000006402");
1303 OSMO_ASSERT(gsup_tx_confirmed);
1304 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1305
1306 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1307 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1308 auth_request_sent = false;
1309 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1310 auth_request_expect_autn = NULL;
1311 gsup_rx("0a"
1312 /* imsi */
1313 "0108" "09710000004026f0"
1314 /* 5 auth vectors... */
1315 /* TL TL rand */
1316 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1317 /* TL sres TL kc */
1318 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1319 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1320 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1321 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1322 "2104" "a29514ae" "2208" "e2b234f807886400"
1323 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1324 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1325 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
1326 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000",
1327 NULL);
1328 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1329 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1330
1331 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
1332 " -- but needs Classmark 2 to determine whether A5/3 is supported");
1333 cipher_mode_cmd_sent = false;
1334 ms_sends_msg("05542d8b2c3e");
1335 OSMO_ASSERT(!cipher_mode_cmd_sent);
1336 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1337
1338 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1339 expect_cipher_mode_cmd("61855fb81fc2a800");
1340 bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100");
1341 OSMO_ASSERT(cipher_mode_cmd_sent);
1342 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1343
1344 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrd0756b12018-09-28 02:41:39 +02001345 gsup_expect_tx("04010809710000004026f0280102");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001346 ms_sends_msg("0632");
1347 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1348
1349 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
1350 gsup_rx("10010809710000004026f00804032443f2",
1351 "12010809710000004026f0");
1352 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1353
1354 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
1355 expect_bssap_clear();
1356 gsup_rx("06010809710000004026f0", NULL);
1357 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1358
1359 btw("LU was successful, and the conn has already been closed");
1360 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
1361 bss_sends_clear_complete();
1362 EXPECT_CONN_COUNT(0);
1363
1364
1365 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1366 cm_service_result_sent = RES_NONE;
1367 auth_request_sent = false;
1368 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
1369 ms_sends_msg("05247803305886089910070000006402");
1370 OSMO_ASSERT(g_conn);
1371 OSMO_ASSERT(g_conn->fi);
1372 OSMO_ASSERT(g_conn->vsub);
1373 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1374 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1375
1376 btw("needs auth, not yet accepted");
1377 EXPECT_ACCEPTED(false);
1378 thwart_rx_non_initial_requests();
1379
1380 btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3,"
1381 " so no need to request Classmark Update.");
1382 expect_cipher_mode_cmd("07fa7502e07e1c00");
1383 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
1384 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1385 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1386
1387 btw("needs ciph, not yet accepted");
1388 EXPECT_ACCEPTED(false);
1389 thwart_rx_non_initial_requests();
1390
1391 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
1392 ms_sends_msg("0632");
1393 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1394
1395 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +01001396 expect_bssap_clear(OSMO_RAT_GERAN_A);
1397 conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001398
1399 btw("all requests serviced, conn has been released");
1400 bss_sends_clear_complete();
1401 EXPECT_CONN_COUNT(0);
1402
1403 BTW("an SMS is sent, MS is paged");
1404 paging_expect_imsi(imsi);
1405 paging_sent = false;
1406 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1407 OSMO_ASSERT(vsub);
1408 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1409
1410 send_sms(vsub, vsub, "Privacy in residential applications is a desirable marketing option.");
1411
1412 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
1413 vlr_subscr_put(vsub);
1414 vsub = NULL;
1415 VERBOSE_ASSERT(paging_sent, == true, "%d");
1416 VERBOSE_ASSERT(paging_stopped, == false, "%d");
1417
1418 btw("the subscriber and its pending request should remain");
1419 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1420 OSMO_ASSERT(vsub);
1421 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
1422 vlr_subscr_put(vsub);
1423
1424 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1425 auth_request_sent = false;
1426 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
1427 ms_sends_msg("06270703305882089910070000006402");
1428 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1429
1430 BTW("Fake a situation where Classmark 2 is unknown during proc_arq_fsm");
1431 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1432 OSMO_ASSERT(vsub);
1433 vsub->classmark.classmark2_len = 0;
1434 vsub->classmark.classmark3_len = 0;
1435 vlr_subscr_put(vsub);
1436
1437
1438 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
1439 btw("MS sends Authen Response, VLR accepts and requests Ciphering."
1440 " Normally, we'd know Classmark 3, but this test removed it."
1441 " Hence a Classmark Request is generated.");
1442 cipher_mode_cmd_sent = false;
1443 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
1444 OSMO_ASSERT(!cipher_mode_cmd_sent);
1445
1446 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1447 expect_cipher_mode_cmd("e2b234f807886400");
1448 bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100");
1449 OSMO_ASSERT(cipher_mode_cmd_sent);
1450
1451 btw("needs ciph, not yet accepted");
1452 EXPECT_ACCEPTED(false);
1453
1454 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1455 dtap_expect_tx("09" /* SMS messages */
1456 "01" /* CP-DATA */
1457 "58" /* length */
1458 "01" /* Network to MS */
1459 "00" /* reference */
1460 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1461 "0791" "447758100650" /* 447785016005 */
1462 "00" /* dest */
1463 /* SMS TPDU */
1464 "4c" /* len */
1465 "00" /* SMS deliver */
1466 "05802443f2" /* originating address 42342 */
1467 "00" /* TP-PID */
1468 "00" /* GSM default alphabet */
1469 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1470 "000000" /* H-M-S */
1471 "00" /* GMT+0 */
1472 "44" /* data length */
1473 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1474 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1475 "0c7ac3e9e9b7db05");
1476 ms_sends_msg("0632");
1477 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1478 VERBOSE_ASSERT(paging_stopped, == true, "%d");
1479
1480 btw("SMS was delivered, no requests pending for subscr");
1481 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
1482 OSMO_ASSERT(vsub);
1483 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1484 vlr_subscr_put(vsub);
1485
1486 btw("conn is still open to wait for SMS ack dance");
1487 EXPECT_CONN_COUNT(1);
1488
1489 btw("MS replies with CP-ACK for received SMS");
1490 ms_sends_msg("8904");
1491 EXPECT_CONN_COUNT(1);
1492
1493 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1494 dtap_expect_tx("0904");
1495 expect_bssap_clear();
1496 ms_sends_msg("890106020041020000");
1497 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1498 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1499
1500 btw("SMS is done, conn is gone");
1501 bss_sends_clear_complete();
1502 EXPECT_CONN_COUNT(0);
1503
1504 BTW("subscriber detaches");
1505 expect_bssap_clear();
1506 ms_sends_msg("050130089910070000006402");
1507 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001508
Neels Hofmeyr4068ab22018-04-01 20:55:54 +02001509 bss_sends_clear_complete();
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001510 EXPECT_CONN_COUNT(0);
1511 clear_vlr();
1512 comment_end();
1513}
1514
1515
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001516msc_vlr_test_func_t msc_vlr_tests[] = {
1517 test_ciph,
1518 test_ciph_tmsi,
1519 test_ciph_imei,
1520 test_ciph_imeisv,
1521 test_ciph_tmsi_imei,
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001522 test_gsm_ciph_in_umts_env,
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001523 test_a5_3_supported,
1524 test_cm_service_needs_classmark_update,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001525 NULL
1526};