blob: 953b4c90921d1db69cde50705ccc94db60c2c878 [file] [log] [blame]
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001/* Osmocom MSC+VLR end-to-end tests */
2
3/* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
4 *
5 * All Rights Reserved
6 *
7 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24#include "msc_vlr_tests.h"
Harald Welte0df904d2018-12-03 11:00:04 +010025#include "stubs.h"
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010026
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010027static const struct osmo_gsm48_classmark classmark = {
28 // TODO
29 //bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100");
30};
31
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010032static void test_ciph()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010033{
34 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010035 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010036
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010037 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010038
39 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +010040 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010041
42 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
43 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010044 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010045 ms_sends_msg("050802008168000130089910070000006402");
46 OSMO_ASSERT(gsup_tx_confirmed);
47 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
48
49 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
50 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
51 auth_request_sent = false;
52 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
53 auth_request_expect_autn = NULL;
54 gsup_rx("0a"
55 /* imsi */
56 "0108" "09710000004026f0"
57 /* 5 auth vectors... */
58 /* TL TL rand */
59 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
60 /* TL sres TL kc */
61 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
62 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
63 "2104" "20bde240" "2208" "07fa7502e07e1c00"
64 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
65 "2104" "a29514ae" "2208" "e2b234f807886400"
66 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
67 "2104" "5afc8d72" "2208" "2392f14f709ae000"
68 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010069 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010070 NULL);
71 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
72 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
73
74 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010075 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010076 ms_sends_msg("05542d8b2c3e");
77 OSMO_ASSERT(cipher_mode_cmd_sent);
78 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
79
80 btw("needs ciph, not yet accepted");
81 EXPECT_ACCEPTED(false);
82 thwart_rx_non_initial_requests();
83 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
84
85 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010086 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
87 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010088 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
89
90 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010091 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
92 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010093 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
94
95 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +020096 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010097 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +020098 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010099
100 btw("LU was successful, and the conn has already been closed");
101 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100102 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100103 EXPECT_CONN_COUNT(0);
104
105 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
106 cm_service_result_sent = RES_NONE;
107 auth_request_sent = false;
108 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100109 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100110 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
111 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
112
113 btw("needs auth, not yet accepted");
114 EXPECT_ACCEPTED(false);
115 thwart_rx_non_initial_requests();
116
117 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100118 expect_cipher_mode_cmd("07fa7502e07e1c00");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100119 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
120 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
121 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
122
123 btw("needs ciph, not yet accepted");
124 EXPECT_ACCEPTED(false);
125 thwart_rx_non_initial_requests();
126
127 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100128 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100129 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
130
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700131 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100132 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100133 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100134
135 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100136 ran_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;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100142 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100143 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");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100151 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100152 vsub = NULL;
153 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100154
155 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100156 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100157 OSMO_ASSERT(vsub);
158 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100159 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100160
161 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
162 auth_request_sent = false;
163 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
164 ms_sends_msg("06270703305882089910070000006402");
165 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
166
167 btw("needs auth, not yet accepted");
168 EXPECT_ACCEPTED(false);
169 thwart_rx_non_initial_requests();
170
171 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100172 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100173 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
174 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
175
176 btw("needs ciph, not yet accepted");
177 EXPECT_ACCEPTED(false);
178 thwart_rx_non_initial_requests();
179
180 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
181 dtap_expect_tx("09" /* SMS messages */
182 "01" /* CP-DATA */
183 "58" /* length */
184 "01" /* Network to MS */
185 "00" /* reference */
186 /* originator (gsm411_send_sms() hardcodes this weird nr) */
187 "0791" "447758100650" /* 447785016005 */
188 "00" /* dest */
189 /* SMS TPDU */
190 "4c" /* len */
191 "00" /* SMS deliver */
192 "05806470f1" /* originating address 46071 */
193 "00" /* TP-PID */
194 "00" /* GSM default alphabet */
195 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
196 "000000" /* H-M-S */
197 "00" /* GMT+0 */
198 "44" /* data length */
199 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
200 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
201 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100202 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100203 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100204
205 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100206 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100207 OSMO_ASSERT(vsub);
208 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100209 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100210
211 btw("conn is still open to wait for SMS ack dance");
212 EXPECT_CONN_COUNT(1);
213
214 btw("MS replies with CP-ACK for received SMS");
215 ms_sends_msg("8904");
216 EXPECT_CONN_COUNT(1);
217
218 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
219 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200220 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100221 ms_sends_msg("890106020041020000");
222 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200223 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100224
225 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100226 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100227 EXPECT_CONN_COUNT(0);
228
229 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200230 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100231 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200232 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100233
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100234 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100235 EXPECT_CONN_COUNT(0);
236 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100237 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100238}
239
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100240static void test_ciph_tmsi()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100241{
242 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100243 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100244
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100245 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100246
247 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100248 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100249 net->vlr->cfg.assign_tmsi = true;
250
251 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
252 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100253 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100254 ms_sends_msg("050802008168000130089910070000006402");
255 OSMO_ASSERT(gsup_tx_confirmed);
256 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
257
258 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
259 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
260 auth_request_sent = false;
261 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
262 auth_request_expect_autn = NULL;
263 gsup_rx("0a"
264 /* imsi */
265 "0108" "09710000004026f0"
266 /* 5 auth vectors... */
267 /* TL TL rand */
268 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
269 /* TL sres TL kc */
270 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
271 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
272 "2104" "20bde240" "2208" "07fa7502e07e1c00"
273 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
274 "2104" "a29514ae" "2208" "e2b234f807886400"
275 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
276 "2104" "5afc8d72" "2208" "2392f14f709ae000"
277 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100278 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100279 NULL);
280 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
281 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
282
283 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100284 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100285 ms_sends_msg("05542d8b2c3e");
286 OSMO_ASSERT(cipher_mode_cmd_sent);
287 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
288 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
289
290 btw("needs ciph, not yet accepted");
291 EXPECT_ACCEPTED(false);
292 thwart_rx_non_initial_requests();
293 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
294
295 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100296 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
297 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100298 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
299
300 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100301 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
302 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100303 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
304
305 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100306 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100307
308 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
309 EXPECT_CONN_COUNT(1);
310 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
311 EXPECT_ACCEPTED(false);
312 thwart_rx_non_initial_requests();
313
314 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100315 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100316 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
317 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
318 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
319 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100320 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100321
322 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200323 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100324 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200325 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100326
327 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100328 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100329 EXPECT_CONN_COUNT(0);
330
331 btw("Subscriber has the new TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100332 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100333 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
334 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
335 VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x");
336 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100337 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100338
339 BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector");
340 cm_service_result_sent = RES_NONE;
341 auth_request_sent = false;
342 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
343 auth_request_expect_autn = NULL;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100344 ms_sends_msg("05247403305886" "05f4" "03020100");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100345 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
346 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
347
348 btw("needs auth, not yet accepted");
349 EXPECT_ACCEPTED(false);
350 thwart_rx_non_initial_requests();
351
352 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100353 expect_cipher_mode_cmd("07fa7502e07e1c00");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100354 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
355 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
356 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
357
358 btw("needs ciph, not yet accepted");
359 EXPECT_ACCEPTED(false);
360 thwart_rx_non_initial_requests();
361
362 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100363 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100364 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
365
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700366 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100367 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100368 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100369
370 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100371 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100372 EXPECT_CONN_COUNT(0);
373
374 BTW("an SMS is sent, MS is paged");
375 paging_expect_tmsi(0x03020100);
376 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100377 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100378 OSMO_ASSERT(vsub);
379 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
380
381 send_sms(vsub, vsub,
382 "Privacy in residential applications is a desirable"
383 " marketing option.");
384
385 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100386 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100387 vsub = NULL;
388 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100389
390 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100391 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100392 OSMO_ASSERT(vsub);
393 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100394 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100395
396 btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key");
397 auth_request_sent = false;
398 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
399 ms_sends_msg("06270703305882" "05f4" "03020100");
400 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
401
402 btw("needs auth, not yet accepted");
403 EXPECT_ACCEPTED(false);
404 thwart_rx_non_initial_requests();
405
406 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100407 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100408 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
409 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
410
411 btw("needs ciph, not yet accepted");
412 EXPECT_ACCEPTED(false);
413 thwart_rx_non_initial_requests();
414
415 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
416 dtap_expect_tx("09" /* SMS messages */
417 "01" /* CP-DATA */
418 "58" /* length */
419 "01" /* Network to MS */
420 "00" /* reference */
421 /* originator (gsm411_send_sms() hardcodes this weird nr) */
422 "0791" "447758100650" /* 447785016005 */
423 "00" /* dest */
424 /* SMS TPDU */
425 "4c" /* len */
426 "00" /* SMS deliver */
427 "05806470f1" /* originating address 46071 */
428 "00" /* TP-PID */
429 "00" /* GSM default alphabet */
430 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
431 "000000" /* H-M-S */
432 "00" /* GMT+0 */
433 "44" /* data length */
434 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
435 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
436 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100437 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100438 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100439
440 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100441 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100442 OSMO_ASSERT(vsub);
443 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100444 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100445
446 btw("conn is still open to wait for SMS ack dance");
447 EXPECT_CONN_COUNT(1);
448
449 btw("MS replies with CP-ACK for received SMS");
450 ms_sends_msg("8904");
451 EXPECT_CONN_COUNT(1);
452
453 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
454 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200455 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100456 ms_sends_msg("890106020041020000");
457 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200458 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100459
460 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100461 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100462 EXPECT_CONN_COUNT(0);
463
464 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200465 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100466 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200467 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100468
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100469 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100470 EXPECT_CONN_COUNT(0);
471 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100472 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100473}
474
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100475static void test_ciph_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100476{
477 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100478 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100479
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100480 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100481
482 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100483 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100484 net->vlr->cfg.check_imei_rqd = true;
485
486 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
487 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100488 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100489 ms_sends_msg("050802008168000130089910070000006402");
490 OSMO_ASSERT(gsup_tx_confirmed);
491 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
492
493 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
494 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
495 auth_request_sent = false;
496 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
497 auth_request_expect_autn = NULL;
498 gsup_rx("0a"
499 /* imsi */
500 "0108" "09710000004026f0"
501 /* 5 auth vectors... */
502 /* TL TL rand */
503 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
504 /* TL sres TL kc */
505 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
506 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
507 "2104" "20bde240" "2208" "07fa7502e07e1c00"
508 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
509 "2104" "a29514ae" "2208" "e2b234f807886400"
510 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
511 "2104" "5afc8d72" "2208" "2392f14f709ae000"
512 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100513 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100514 NULL);
515 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
516 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
517
518 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100519 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100520 ms_sends_msg("05542d8b2c3e");
521 OSMO_ASSERT(cipher_mode_cmd_sent);
522 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
523
524 btw("needs ciph, not yet accepted");
525 EXPECT_ACCEPTED(false);
526 thwart_rx_non_initial_requests();
527 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
528
529 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100530 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
531 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100532 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
533
534 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100535 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
536 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100537 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
538
539 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
540 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100541 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100542
543 btw("We will only do business when the IMEI is known");
544 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100545 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100546 OSMO_ASSERT(vsub);
547 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100548 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100549 EXPECT_ACCEPTED(false);
550 thwart_rx_non_initial_requests();
551
Oliver Smith7d053092018-12-14 17:37:38 +0100552 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100553 gsup_expect_tx("30010809710000004026f050090824433224433224f0" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200554 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100555 EXPECT_ACCEPTED(false);
556 thwart_rx_non_initial_requests();
557
558 btw("HLR accepts the IMEI");
559 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100560 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200561 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100562
563 btw("LU was successful, and the conn has already been closed");
564 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100565 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100566 EXPECT_CONN_COUNT(0);
567
568 btw("Subscriber has the IMEI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100569 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100570 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200571 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100572 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100573
574 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200575 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100576 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200577 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100578
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100579 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100580 EXPECT_CONN_COUNT(0);
581 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100582 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100583}
584
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100585static void test_ciph_imeisv()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100586{
587 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100588 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100589
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100590 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100591
592 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100593 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr54a706c2017-07-18 15:39:27 +0200594 net->vlr->cfg.retrieve_imeisv_ciphered = true;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100595
596 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
597 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100598 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100599 ms_sends_msg("050802008168000130089910070000006402");
600 OSMO_ASSERT(gsup_tx_confirmed);
601 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
602
603 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
604 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
605 auth_request_sent = false;
606 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
607 auth_request_expect_autn = NULL;
608 gsup_rx("0a"
609 /* imsi */
610 "0108" "09710000004026f0"
611 /* 5 auth vectors... */
612 /* TL TL rand */
613 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
614 /* TL sres TL kc */
615 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
616 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
617 "2104" "20bde240" "2208" "07fa7502e07e1c00"
618 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
619 "2104" "a29514ae" "2208" "e2b234f807886400"
620 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
621 "2104" "5afc8d72" "2208" "2392f14f709ae000"
622 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100623 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100624 NULL);
625 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
626 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
627
628 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100629 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100630 ms_sends_msg("05542d8b2c3e");
631 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
632 VERBOSE_ASSERT(cipher_mode_cmd_sent_with_imeisv, == true, "%d");
633 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
634
635 btw("needs ciph, not yet accepted");
636 EXPECT_ACCEPTED(false);
637 thwart_rx_non_initial_requests();
638 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
639
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100640 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100641 OSMO_ASSERT(vsub);
642 VERBOSE_ASSERT(vsub->imeisv[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100643 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100644
645 btw("MS sends Ciphering Mode Complete with IMEISV, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100646 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
647 ms_sends_ciphering_mode_complete("063217094b32244332244372f5");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100648 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
649
650 btw("Subscriber has the IMEISV");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100651 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100652 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200653 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100654 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100655
656 EXPECT_ACCEPTED(false);
657 thwart_rx_non_initial_requests();
658
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100659 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100660 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
661 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100662 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
663
664 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200665 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100666 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200667 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100668
669 btw("LU was successful, and the conn has already been closed");
670 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100671 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100672 EXPECT_CONN_COUNT(0);
673
674 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200675 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100676 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200677 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100678
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100679 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100680 EXPECT_CONN_COUNT(0);
681 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100682 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100683}
684
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100685static void test_ciph_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100686{
687 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100688 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100689
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100690 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100691
692 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100693 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100694 net->vlr->cfg.assign_tmsi = true;
695 net->vlr->cfg.check_imei_rqd = true;
696
697 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
698 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100699 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100700 ms_sends_msg("050802008168000130089910070000006402");
701 OSMO_ASSERT(gsup_tx_confirmed);
702 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
703
704 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
705 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
706 auth_request_sent = false;
707 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
708 auth_request_expect_autn = NULL;
709 gsup_rx("0a"
710 /* imsi */
711 "0108" "09710000004026f0"
712 /* 5 auth vectors... */
713 /* TL TL rand */
714 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
715 /* TL sres TL kc */
716 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
717 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
718 "2104" "20bde240" "2208" "07fa7502e07e1c00"
719 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
720 "2104" "a29514ae" "2208" "e2b234f807886400"
721 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
722 "2104" "5afc8d72" "2208" "2392f14f709ae000"
723 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100724 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100725 NULL);
726 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
727 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
728
729 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100730 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100731 ms_sends_msg("05542d8b2c3e");
732 OSMO_ASSERT(cipher_mode_cmd_sent);
733 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
734
735 btw("needs ciph, not yet accepted");
736 EXPECT_ACCEPTED(false);
737 thwart_rx_non_initial_requests();
738 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
739
740 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100741 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
742 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100743 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
744
745 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100746 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
747 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100748 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
749
750 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
751 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100752 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100753
754 btw("We will only do business when the IMEI is known");
755 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100756 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100757 OSMO_ASSERT(vsub);
758 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100759 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100760 EXPECT_ACCEPTED(false);
761 thwart_rx_non_initial_requests();
762
Oliver Smith7d053092018-12-14 17:37:38 +0100763 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100764 gsup_expect_tx("30010809710000004026f050090824433224433224f0" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200765 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100766 EXPECT_ACCEPTED(false);
767 thwart_rx_non_initial_requests();
768
769 btw("HLR accepts the IMEI");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100770 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100771
772 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
773 EXPECT_CONN_COUNT(1);
774 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
775 EXPECT_ACCEPTED(false);
776 thwart_rx_non_initial_requests();
777
778 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100779 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100780 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
781 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
782 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
783 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100784 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100785
786 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200787 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100788 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200789 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100790
791 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100792 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100793 EXPECT_CONN_COUNT(0);
794
795 btw("Subscriber has the IMEI and TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100796 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100797 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200798 VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100799 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100800 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100801
802 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200803 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100804 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200805 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100806
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100807 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100808 EXPECT_CONN_COUNT(0);
809 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100810 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100811}
812
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100813static void test_gsm_ciph_in_umts_env()
814{
815 struct vlr_subscr *vsub;
816 const char *imsi = "901700000010650";
817 const char *sms =
818 "09" /* SMS messages */
819 "01" /* CP-DATA */
820 "58" /* length */
821 "01" /* Network to MS */
822 "00" /* reference */
823 /* originator (gsm411_send_sms() hardcodes this weird nr) */
824 "0791" "447758100650" /* 447785016005 */
825 "00" /* dest */
826 /* SMS TPDU */
827 "4c" /* len */
828 "00" /* SMS deliver */
829 "05802443f2" /* originating address 42342 */
830 "00" /* TP-PID */
831 "00" /* GSM default alphabet */
832 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
833 "000000" /* H-M-S */
834 "00" /* GMT+0 */
835 "44" /* data length */
836 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
837 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
838 "0c7ac3e9e9b7db05";
839
840 comment_start();
841
842 /* implicit: net->authentication_required = true; */
843 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100844 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100845
846 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
847 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100848 gsup_expect_tx("080108" "09710000000156f0" VLR_TO_HLR);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100849 ms_sends_msg("0508" /* MM LU */
850 "7" /* ciph key seq: no key available */
851 "0" /* LU type: normal */
852 "ffffff" "0000" /* LAI, LAC */
853 "57" /* classmark 1: R99, early classmark, no power lvl */
854 "089910070000106005" /* IMSI */
855 "3303575886" /* classmark 2 */
856 );
857 OSMO_ASSERT(gsup_tx_confirmed);
858 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
859
860 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends *UMTS AKA* Auth Req to MS");
861 /* based on
862 * 2G auth: COMP128v1
863 * KI=7bcd108be4c3d551ee6c67faaf52bd68
864 * 3G auth: MILENAGE
865 * K=7bcd108be4c3d551ee6c67faaf52bd68
866 * OPC=6e23f641ce724679b73d933515a8589d
867 * IND-bitlen=5 last-SQN=641
868 * Note that the SRES will be calculated by COMP128v1, separately from 3G tokens;
869 * the resulting Kc to use for ciphering returned by the HLR is also calculated from COMP128v1.
870 */
871 auth_request_sent = false;
872 auth_request_expect_rand = "4ac8d1cd1a51937597ca1016fe69a0fa";
873 auth_request_expect_autn = "2d837d2b0d6f00004b282d5acf23428d";
874 gsup_rx("0a"
875 /* imsi */
876 "0108" "09710000000156f0"
877 /* 5 auth vectors... */
878 /* TL TL rand */
879 "0362" "2010" "4ac8d1cd1a51937597ca1016fe69a0fa"
880 /* TL sres TL kc */
881 "2104" "dacc4b26" "2208" "7a75f0ac9b844400"
882 /* TL 3G IK */
883 "2310" "3747da4e31545baa2db59e500bdae047"
884 /* TL 3G CK */
885 "2410" "8544d35b945ccba01a7f1293575291c3"
886 /* TL AUTN */
887 "2510" "2d837d2b0d6f00004b282d5acf23428d"
888 /* TL RES */
889 "2708" "37527064741f8ddb"
890 /* TL TL rand */
891 "0362" "2010" "b2661531b97b12c5a2edc21a0ed16fc5"
892 "2104" "2fb4cfad" "2208" "da149b11d473f400"
893 "2310" "3fe013b1a428ea737c37f8f0288c8edf"
894 "2410" "f275438c02b97e4d6f639dddda3d10b9"
895 "2510" "78cdd96c60840000322f421b3bb778b1"
896 "2708" "ed3ebf9cb6ea48ed"
897 "0362" "2010" "54d8f19778056666b41c8c25e52eb60c"
898 "2104" "0ff61e0f" "2208" "26ec67fad3073000"
899 "2310" "2868b0922c652616f1c975e3eaf7943a"
900 "2410" "6a84a20b1bc13ec9840466406d2dd91e"
901 "2510" "53f3e5632b3d00008865dd54d49663f2"
902 "2708" "86e848a9e7ad8cd5"
903 "0362" "2010" "1f05607ff9c8984f46ad97f8c9a94982"
904 "2104" "91a36e3d" "2208" "5d84421884fdcc00"
905 "2310" "2171fef54b81e30c83a598a5e44f634c"
906 "2410" "f02d088697509827565b46938fece211"
907 "2510" "1b43bbf9815e00001cb9b2a9f6b8a77c"
908 "2708" "373e67d62e719c51"
909 "0362" "2010" "80d89a58a2a41050918caf68a4e93c64"
910 "2104" "a319f5f1" "2208" "883df2b867293000"
911 "2310" "fa5d70f929ff298efb160413698dc107"
912 "2410" "ae9a3d8ce70ce13bac297bdb91cd6c68"
913 "2510" "5c0dc2eeaefa0000396882a1fe2cf80b"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100914 "2708" "65ab1cad216bfe87" HLR_TO_VLR,
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100915 NULL);
916 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
917 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
918
919 btw("MS sends *GSM AKA* Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100920 expect_cipher_mode_cmd("7a75f0ac9b844400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100921 ms_sends_msg("0554" "dacc4b26");
922 OSMO_ASSERT(cipher_mode_cmd_sent);
923 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
924
925 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100926 gsup_expect_tx("04010809710000000156f0280102" VLR_TO_HLR);
927 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100928 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
929
930 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100931 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
932 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100933 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
934
935 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
936 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100937 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100938 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
939
940 btw("LU was successful, and the conn has already been closed");
941 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100942 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100943 EXPECT_CONN_COUNT(0);
944
945 BTW("after a while, a new conn sends a CM Service Request. VLR responds with *UMTS AKA* Auth Req, 2nd auth vector");
946 auth_request_sent = false;
947 auth_request_expect_rand = "b2661531b97b12c5a2edc21a0ed16fc5";
948 auth_request_expect_autn = "78cdd96c60840000322f421b3bb778b1";
949 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100950 ms_sends_msg("052474"
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100951 "03575886" /* classmark 2 */
952 "089910070000106005" /* IMSI */);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100953 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
954 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
955
956 btw("needs auth, not yet accepted");
957 EXPECT_ACCEPTED(false);
958 thwart_rx_non_initial_requests();
959
960 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100961 expect_cipher_mode_cmd("da149b11d473f400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100962 ms_sends_msg("0554" "2fb4cfad");
963 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
964 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
965
966 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100967 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100968 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
969
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700970 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100971 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100972 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100973
974 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100975 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100976 EXPECT_CONN_COUNT(0);
977
978 BTW("an SMS is sent, MS is paged");
979 paging_expect_imsi(imsi);
980 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100981 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100982 OSMO_ASSERT(vsub);
983 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
984
985 send_sms(vsub, vsub,
986 "Privacy in residential applications is a desirable"
987 " marketing option.");
988
989 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100990 vlr_subscr_put(vsub, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100991 vsub = NULL;
992 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100993
994 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100995 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100996 OSMO_ASSERT(vsub);
997 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100998 vlr_subscr_put(vsub, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100999
1000 btw("MS replies with Paging Response, and VLR sends *UMTS AKA* Auth Request with third key");
1001 auth_request_sent = false;
1002 auth_request_expect_rand = "54d8f19778056666b41c8c25e52eb60c";
1003 auth_request_expect_autn = "53f3e5632b3d00008865dd54d49663f2";
1004 ms_sends_msg("062707"
1005 "03575886" /* classmark 2 */
1006 "089910070000106005" /* IMSI */);
1007 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1008
1009 btw("needs auth, not yet accepted");
1010 EXPECT_ACCEPTED(false);
1011 thwart_rx_non_initial_requests();
1012
1013 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001014 expect_cipher_mode_cmd("26ec67fad3073000");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001015 ms_sends_msg("0554" "0ff61e0f");
1016 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1017
1018 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1019 dtap_expect_tx(sms);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001020 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001021 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001022
1023 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001024 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001025 OSMO_ASSERT(vsub);
1026 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001027 vlr_subscr_put(vsub, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001028
1029 btw("conn is still open to wait for SMS ack dance");
1030 EXPECT_CONN_COUNT(1);
1031
1032 btw("MS replies with CP-ACK for received SMS");
1033 ms_sends_msg("8904");
1034 EXPECT_CONN_COUNT(1);
1035
1036 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1037 dtap_expect_tx("0904");
1038 expect_bssap_clear();
1039 ms_sends_msg("890106020041020000");
1040 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1041 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1042
1043 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001044 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001045 EXPECT_CONN_COUNT(0);
1046
1047 BTW("subscriber detaches");
1048 expect_bssap_clear();
1049 ms_sends_msg("050130"
1050 "089910070000106005" /* IMSI */);
1051 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1052
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001053 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001054 EXPECT_CONN_COUNT(0);
1055 clear_vlr();
1056 comment_end();
1057}
1058
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001059static void test_a5_3_supported()
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001060{
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001061 struct vlr_subscr *vsub;
1062 const char *imsi = "901700000004620";
1063
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001064 comment_start();
1065
1066 /* implicit: net->authentication_required = true; */
1067 net->a5_encryption_mask = (1 << 3); /* A5/3 */
1068
1069 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1070 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001071 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001072 ms_sends_msg("050802008168000130089910070000006402");
1073 OSMO_ASSERT(gsup_tx_confirmed);
1074 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1075
1076 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1077 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1078 auth_request_sent = false;
1079 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1080 auth_request_expect_autn = NULL;
1081 gsup_rx("0a"
1082 /* imsi */
1083 "0108" "09710000004026f0"
1084 /* 5 auth vectors... */
1085 /* TL TL rand */
1086 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1087 /* TL sres TL kc */
1088 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1089 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1090 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1091 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1092 "2104" "a29514ae" "2208" "e2b234f807886400"
1093 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1094 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1095 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001096 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001097 NULL);
1098 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1099 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1100
1101 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001102 " -- but needs Classmark 2 to determine whether A5/3 is supported");
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001103 cipher_mode_cmd_sent = false;
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001104 ms_sends_msg("05542d8b2c3e");
1105 OSMO_ASSERT(!cipher_mode_cmd_sent);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001106 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1107
1108 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1109 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001110 ms_sends_classmark_update(&classmark);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001111 OSMO_ASSERT(cipher_mode_cmd_sent);
1112 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1113
1114 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001115 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
1116 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001117 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1118
1119 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001120 gsup_rx("10010809710000004026f00804032443f2" HLR_TO_VLR,
1121 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001122 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1123
1124 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
1125 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001126 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001127 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1128
1129 btw("LU was successful, and the conn has already been closed");
1130 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001131 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001132 EXPECT_CONN_COUNT(0);
1133
1134 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1135 cm_service_result_sent = RES_NONE;
1136 auth_request_sent = false;
1137 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001138 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001139 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1140 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1141
1142 btw("needs auth, not yet accepted");
1143 EXPECT_ACCEPTED(false);
1144 thwart_rx_non_initial_requests();
1145
1146 btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3,"
1147 " so no need to request Classmark Update.");
1148 expect_cipher_mode_cmd("07fa7502e07e1c00");
1149 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
1150 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1151 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1152
1153 btw("needs ciph, not yet accepted");
1154 EXPECT_ACCEPTED(false);
1155 thwart_rx_non_initial_requests();
1156
1157 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001158 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001159 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1160
1161 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +01001162 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001163 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001164
1165 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001166 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001167 EXPECT_CONN_COUNT(0);
1168
1169 BTW("an SMS is sent, MS is paged");
1170 paging_expect_imsi(imsi);
1171 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001172 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001173 OSMO_ASSERT(vsub);
1174 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1175
1176 send_sms(vsub, vsub,
1177 "Privacy in residential applications is a desirable"
1178 " marketing option.");
1179
1180 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001181 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001182 vsub = NULL;
1183 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001184
1185 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001186 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001187 OSMO_ASSERT(vsub);
1188 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001189 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001190
1191 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1192 auth_request_sent = false;
1193 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
1194 ms_sends_msg("06270703305882089910070000006402");
1195 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1196
1197 btw("needs auth, not yet accepted");
1198 EXPECT_ACCEPTED(false);
1199 thwart_rx_non_initial_requests();
1200
1201 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
1202 expect_cipher_mode_cmd("e2b234f807886400");
1203 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
1204 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1205
1206 btw("needs ciph, not yet accepted");
1207 EXPECT_ACCEPTED(false);
1208 thwart_rx_non_initial_requests();
1209
1210 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1211 dtap_expect_tx("09" /* SMS messages */
1212 "01" /* CP-DATA */
1213 "58" /* length */
1214 "01" /* Network to MS */
1215 "00" /* reference */
1216 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1217 "0791" "447758100650" /* 447785016005 */
1218 "00" /* dest */
1219 /* SMS TPDU */
1220 "4c" /* len */
1221 "00" /* SMS deliver */
1222 "05802443f2" /* originating address 42342 */
1223 "00" /* TP-PID */
1224 "00" /* GSM default alphabet */
1225 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1226 "000000" /* H-M-S */
1227 "00" /* GMT+0 */
1228 "44" /* data length */
1229 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1230 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1231 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001232 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001233 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001234
1235 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001236 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001237 OSMO_ASSERT(vsub);
1238 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001239 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001240
1241 btw("conn is still open to wait for SMS ack dance");
1242 EXPECT_CONN_COUNT(1);
1243
1244 btw("MS replies with CP-ACK for received SMS");
1245 ms_sends_msg("8904");
1246 EXPECT_CONN_COUNT(1);
1247
1248 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1249 dtap_expect_tx("0904");
1250 expect_bssap_clear();
1251 ms_sends_msg("890106020041020000");
1252 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1253 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1254
1255 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001256 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001257 EXPECT_CONN_COUNT(0);
1258
1259 BTW("subscriber detaches");
1260 expect_bssap_clear();
1261 ms_sends_msg("050130089910070000006402");
1262 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1263
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001264 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001265 EXPECT_CONN_COUNT(0);
1266 clear_vlr();
1267 comment_end();
1268}
1269
1270/* During CM Service Request or Paging Response we already have Classmark 2 that indicates A5/3
1271 * availablity. Here, in a hacky way remove the knowledge of Classmark 2 to tickle a code path where
1272 * proc_arq_fsm needs a Classmark Update during Ciphering. Shouldn't happen in reality though. */
1273static void test_cm_service_needs_classmark_update()
1274{
1275 struct vlr_subscr *vsub;
1276 const char *imsi = "901700000004620";
1277
1278 comment_start();
1279
1280 /* A5/3 support is indicated in Classmark 3. By configuring A5/3, trigger the code paths that
1281 * send a Classmark Request. */
1282 net->a5_encryption_mask = (1 << 3); /* A5/3 */
1283 /* implicit: net->authentication_required = true; */
1284
1285 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1286 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001287 gsup_expect_tx("08010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001288 ms_sends_msg("050802008168000130089910070000006402");
1289 OSMO_ASSERT(gsup_tx_confirmed);
1290 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1291
1292 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1293 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1294 auth_request_sent = false;
1295 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1296 auth_request_expect_autn = NULL;
1297 gsup_rx("0a"
1298 /* imsi */
1299 "0108" "09710000004026f0"
1300 /* 5 auth vectors... */
1301 /* TL TL rand */
1302 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1303 /* TL sres TL kc */
1304 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1305 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1306 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1307 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1308 "2104" "a29514ae" "2208" "e2b234f807886400"
1309 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1310 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1311 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001312 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001313 NULL);
1314 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1315 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1316
1317 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
1318 " -- but needs Classmark 2 to determine whether A5/3 is supported");
1319 cipher_mode_cmd_sent = false;
1320 ms_sends_msg("05542d8b2c3e");
1321 OSMO_ASSERT(!cipher_mode_cmd_sent);
1322 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1323
1324 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1325 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001326 ms_sends_classmark_update(&classmark);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001327 OSMO_ASSERT(cipher_mode_cmd_sent);
1328 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1329
1330 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001331 gsup_expect_tx("04010809710000004026f0280102" VLR_TO_HLR);
1332 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001333 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1334
1335 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001336 gsup_rx("10010809710000004026f00804032443f2" HLR_TO_VLR,
1337 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001338 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1339
1340 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
1341 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001342 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001343 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1344
1345 btw("LU was successful, and the conn has already been closed");
1346 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001347 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001348 EXPECT_CONN_COUNT(0);
1349
1350
1351 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1352 cm_service_result_sent = RES_NONE;
1353 auth_request_sent = false;
1354 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001355 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001356 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1357 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1358
1359 btw("needs auth, not yet accepted");
1360 EXPECT_ACCEPTED(false);
1361 thwart_rx_non_initial_requests();
1362
1363 btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3,"
1364 " so no need to request Classmark Update.");
1365 expect_cipher_mode_cmd("07fa7502e07e1c00");
1366 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
1367 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1368 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1369
1370 btw("needs ciph, not yet accepted");
1371 EXPECT_ACCEPTED(false);
1372 thwart_rx_non_initial_requests();
1373
1374 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001375 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001376 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1377
1378 /* Release connection */
Neels Hofmeyr7814a832018-12-26 00:40:18 +01001379 expect_bssap_clear(OSMO_RAT_GERAN_A);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001380 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001381
1382 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001383 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001384 EXPECT_CONN_COUNT(0);
1385
1386 BTW("an SMS is sent, MS is paged");
1387 paging_expect_imsi(imsi);
1388 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001389 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001390 OSMO_ASSERT(vsub);
1391 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1392
1393 send_sms(vsub, vsub, "Privacy in residential applications is a desirable marketing option.");
1394
1395 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001396 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001397 vsub = NULL;
1398 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001399
1400 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001401 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001402 OSMO_ASSERT(vsub);
1403 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001404 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001405
1406 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1407 auth_request_sent = false;
1408 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
1409 ms_sends_msg("06270703305882089910070000006402");
1410 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1411
1412 BTW("Fake a situation where Classmark 2 is unknown during proc_arq_fsm");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001413 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001414 OSMO_ASSERT(vsub);
1415 vsub->classmark.classmark2_len = 0;
1416 vsub->classmark.classmark3_len = 0;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001417 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001418
1419 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
1420 btw("MS sends Authen Response, VLR accepts and requests Ciphering."
1421 " Normally, we'd know Classmark 3, but this test removed it."
1422 " Hence a Classmark Request is generated.");
1423 cipher_mode_cmd_sent = false;
1424 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
1425 OSMO_ASSERT(!cipher_mode_cmd_sent);
1426
1427 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1428 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001429 ms_sends_classmark_update(&classmark);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001430 OSMO_ASSERT(cipher_mode_cmd_sent);
1431
1432 btw("needs ciph, not yet accepted");
1433 EXPECT_ACCEPTED(false);
1434
1435 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1436 dtap_expect_tx("09" /* SMS messages */
1437 "01" /* CP-DATA */
1438 "58" /* length */
1439 "01" /* Network to MS */
1440 "00" /* reference */
1441 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1442 "0791" "447758100650" /* 447785016005 */
1443 "00" /* dest */
1444 /* SMS TPDU */
1445 "4c" /* len */
1446 "00" /* SMS deliver */
1447 "05802443f2" /* originating address 42342 */
1448 "00" /* TP-PID */
1449 "00" /* GSM default alphabet */
1450 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1451 "000000" /* H-M-S */
1452 "00" /* GMT+0 */
1453 "44" /* data length */
1454 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1455 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1456 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001457 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001458 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001459
1460 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001461 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001462 OSMO_ASSERT(vsub);
1463 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001464 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001465
1466 btw("conn is still open to wait for SMS ack dance");
1467 EXPECT_CONN_COUNT(1);
1468
1469 btw("MS replies with CP-ACK for received SMS");
1470 ms_sends_msg("8904");
1471 EXPECT_CONN_COUNT(1);
1472
1473 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1474 dtap_expect_tx("0904");
1475 expect_bssap_clear();
1476 ms_sends_msg("890106020041020000");
1477 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1478 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1479
1480 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001481 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001482 EXPECT_CONN_COUNT(0);
1483
1484 BTW("subscriber detaches");
1485 expect_bssap_clear();
1486 ms_sends_msg("050130089910070000006402");
1487 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001488
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001489 ran_sends_clear_complete();
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001490 EXPECT_CONN_COUNT(0);
1491 clear_vlr();
1492 comment_end();
1493}
1494
1495
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001496msc_vlr_test_func_t msc_vlr_tests[] = {
1497 test_ciph,
1498 test_ciph_tmsi,
1499 test_ciph_imei,
1500 test_ciph_imeisv,
1501 test_ciph_tmsi_imei,
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001502 test_gsm_ciph_in_umts_env,
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001503 test_a5_3_supported,
1504 test_cm_service_needs_classmark_update,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001505 NULL
1506};