blob: 38a5caff07551816f5e21f09a9d964866dad236f [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 Hofmeyrc4628a32018-12-07 14:47:34 +010026static const struct osmo_gsm48_classmark classmark = {
27 // TODO
28 //bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100");
29};
30
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010031static void test_ciph()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010032{
33 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010034 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010035
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010036 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010037
38 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +010039 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010040
41 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
42 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +010043 gsup_expect_tx("08010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010044 ms_sends_msg("050802008168000130089910070000006402");
45 OSMO_ASSERT(gsup_tx_confirmed);
46 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
47
48 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
49 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
50 auth_request_sent = false;
51 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
52 auth_request_expect_autn = NULL;
53 gsup_rx("0a"
54 /* imsi */
55 "0108" "09710000004026f0"
56 /* 5 auth vectors... */
57 /* TL TL rand */
58 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
59 /* TL sres TL kc */
60 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
61 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
62 "2104" "20bde240" "2208" "07fa7502e07e1c00"
63 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
64 "2104" "a29514ae" "2208" "e2b234f807886400"
65 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
66 "2104" "5afc8d72" "2208" "2392f14f709ae000"
67 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010068 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010069 NULL);
70 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
71 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
72
73 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010074 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010075 ms_sends_msg("05542d8b2c3e");
76 OSMO_ASSERT(cipher_mode_cmd_sent);
77 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
78
79 btw("needs ciph, not yet accepted");
80 EXPECT_ACCEPTED(false);
81 thwart_rx_non_initial_requests();
82 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
83
84 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +010085 gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010086 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010087 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
88
89 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010090 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
91 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010092 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
93
94 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +020095 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010096 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +020097 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010098
99 btw("LU was successful, and the conn has already been closed");
100 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100101 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100102 EXPECT_CONN_COUNT(0);
103
104 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
105 cm_service_result_sent = RES_NONE;
106 auth_request_sent = false;
107 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100108 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100109 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
110 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
111
112 btw("needs auth, not yet accepted");
113 EXPECT_ACCEPTED(false);
114 thwart_rx_non_initial_requests();
115
116 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100117 expect_cipher_mode_cmd("07fa7502e07e1c00");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100118 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
119 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
120 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
121
122 btw("needs ciph, not yet accepted");
123 EXPECT_ACCEPTED(false);
124 thwart_rx_non_initial_requests();
125
126 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100127 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100128 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
129
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700130 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +0700131 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100132 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100133
134 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100135 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100136 EXPECT_CONN_COUNT(0);
137
138 BTW("an SMS is sent, MS is paged");
139 paging_expect_imsi(imsi);
140 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100141 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100142 OSMO_ASSERT(vsub);
143 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
144
145 send_sms(vsub, vsub,
146 "Privacy in residential applications is a desirable"
147 " marketing option.");
148
149 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100150 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100151 vsub = NULL;
152 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100153
154 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100155 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100156 OSMO_ASSERT(vsub);
157 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100158 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100159
160 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
161 auth_request_sent = false;
162 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
163 ms_sends_msg("06270703305882089910070000006402");
164 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
165
166 btw("needs auth, not yet accepted");
167 EXPECT_ACCEPTED(false);
168 thwart_rx_non_initial_requests();
169
170 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100171 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100172 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
173 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
174
175 btw("needs ciph, not yet accepted");
176 EXPECT_ACCEPTED(false);
177 thwart_rx_non_initial_requests();
178
179 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
180 dtap_expect_tx("09" /* SMS messages */
181 "01" /* CP-DATA */
182 "58" /* length */
183 "01" /* Network to MS */
184 "00" /* reference */
185 /* originator (gsm411_send_sms() hardcodes this weird nr) */
186 "0791" "447758100650" /* 447785016005 */
187 "00" /* dest */
188 /* SMS TPDU */
189 "4c" /* len */
190 "00" /* SMS deliver */
191 "05806470f1" /* originating address 46071 */
192 "00" /* TP-PID */
193 "00" /* GSM default alphabet */
194 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
195 "000000" /* H-M-S */
196 "00" /* GMT+0 */
197 "44" /* data length */
198 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
199 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
200 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100201 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100202 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100203
204 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100205 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100206 OSMO_ASSERT(vsub);
207 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100208 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100209
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 Hofmeyrc4628a32018-12-07 14:47:34 +0100225 ran_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 Hofmeyrc4628a32018-12-07 14:47:34 +0100233 ran_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;
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100252 gsup_expect_tx("08010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100253 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"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100277 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100278 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 Hofmeyr63b24642019-12-12 01:31:04 +0100295 gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100296 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100297 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
298
299 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100300 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
301 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100302 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
303
304 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100305 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100306
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");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100314 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100315 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");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100319 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100320
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 Hofmeyrc4628a32018-12-07 14:47:34 +0100327 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100328 EXPECT_CONN_COUNT(0);
329
330 btw("Subscriber has the new TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100331 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100332 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");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100336 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100337
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;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100343 ms_sends_msg("05247403305886" "05f4" "03020100");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100344 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
345 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
346
347 btw("needs auth, not yet accepted");
348 EXPECT_ACCEPTED(false);
349 thwart_rx_non_initial_requests();
350
351 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100352 expect_cipher_mode_cmd("07fa7502e07e1c00");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100353 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
354 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
355 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
356
357 btw("needs ciph, not yet accepted");
358 EXPECT_ACCEPTED(false);
359 thwart_rx_non_initial_requests();
360
361 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100362 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100363 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
364
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700365 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +0700366 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100367 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100368
369 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100370 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100371 EXPECT_CONN_COUNT(0);
372
373 BTW("an SMS is sent, MS is paged");
374 paging_expect_tmsi(0x03020100);
375 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100376 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100377 OSMO_ASSERT(vsub);
378 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
379
380 send_sms(vsub, vsub,
381 "Privacy in residential applications is a desirable"
382 " marketing option.");
383
384 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100385 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100386 vsub = NULL;
387 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100388
389 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100390 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100391 OSMO_ASSERT(vsub);
392 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100393 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100394
395 btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key");
396 auth_request_sent = false;
397 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
398 ms_sends_msg("06270703305882" "05f4" "03020100");
399 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
400
401 btw("needs auth, not yet accepted");
402 EXPECT_ACCEPTED(false);
403 thwart_rx_non_initial_requests();
404
405 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100406 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100407 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
408 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
409
410 btw("needs ciph, not yet accepted");
411 EXPECT_ACCEPTED(false);
412 thwart_rx_non_initial_requests();
413
414 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
415 dtap_expect_tx("09" /* SMS messages */
416 "01" /* CP-DATA */
417 "58" /* length */
418 "01" /* Network to MS */
419 "00" /* reference */
420 /* originator (gsm411_send_sms() hardcodes this weird nr) */
421 "0791" "447758100650" /* 447785016005 */
422 "00" /* dest */
423 /* SMS TPDU */
424 "4c" /* len */
425 "00" /* SMS deliver */
426 "05806470f1" /* originating address 46071 */
427 "00" /* TP-PID */
428 "00" /* GSM default alphabet */
429 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
430 "000000" /* H-M-S */
431 "00" /* GMT+0 */
432 "44" /* data length */
433 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
434 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
435 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100436 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100437 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100438
439 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100440 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100441 OSMO_ASSERT(vsub);
442 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100443 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100444
445 btw("conn is still open to wait for SMS ack dance");
446 EXPECT_CONN_COUNT(1);
447
448 btw("MS replies with CP-ACK for received SMS");
449 ms_sends_msg("8904");
450 EXPECT_CONN_COUNT(1);
451
452 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
453 dtap_expect_tx("0904");
Philipp Maierfbf66102017-04-09 12:32:51 +0200454 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100455 ms_sends_msg("890106020041020000");
456 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Philipp Maierfbf66102017-04-09 12:32:51 +0200457 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100458
459 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100460 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100461 EXPECT_CONN_COUNT(0);
462
463 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200464 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100465 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200466 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100467
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100468 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100469 EXPECT_CONN_COUNT(0);
470 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100471 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100472}
473
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100474static void test_ciph_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100475{
476 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100477 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100478
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100479 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100480
481 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100482 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100483 net->vlr->cfg.check_imei_rqd = true;
484
485 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
486 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100487 gsup_expect_tx("08010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100488 ms_sends_msg("050802008168000130089910070000006402");
489 OSMO_ASSERT(gsup_tx_confirmed);
490 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
491
492 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
493 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
494 auth_request_sent = false;
495 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
496 auth_request_expect_autn = NULL;
497 gsup_rx("0a"
498 /* imsi */
499 "0108" "09710000004026f0"
500 /* 5 auth vectors... */
501 /* TL TL rand */
502 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
503 /* TL sres TL kc */
504 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
505 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
506 "2104" "20bde240" "2208" "07fa7502e07e1c00"
507 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
508 "2104" "a29514ae" "2208" "e2b234f807886400"
509 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
510 "2104" "5afc8d72" "2208" "2392f14f709ae000"
511 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100512 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100513 NULL);
514 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
515 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
516
517 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100518 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100519 ms_sends_msg("05542d8b2c3e");
520 OSMO_ASSERT(cipher_mode_cmd_sent);
521 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
522
523 btw("needs ciph, not yet accepted");
524 EXPECT_ACCEPTED(false);
525 thwart_rx_non_initial_requests();
526 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
527
528 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100529 gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100530 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100531 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
532
533 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100534 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
535 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100536 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
537
538 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
539 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100540 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100541
542 btw("We will only do business when the IMEI is known");
543 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100544 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100545 OSMO_ASSERT(vsub);
546 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100547 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100548 EXPECT_ACCEPTED(false);
549 thwart_rx_non_initial_requests();
550
Oliver Smith7d053092018-12-14 17:37:38 +0100551 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Oliver Smithd1037052019-05-02 13:39:26 +0200552 gsup_expect_tx("30010809710000004026f050080724433224433224" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200553 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100554 EXPECT_ACCEPTED(false);
555 thwart_rx_non_initial_requests();
556
557 btw("HLR accepts the IMEI");
558 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100559 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200560 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100561
562 btw("LU was successful, and the conn has already been closed");
563 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100564 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100565 EXPECT_CONN_COUNT(0);
566
567 btw("Subscriber has the IMEI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100568 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100569 OSMO_ASSERT(vsub);
Oliver Smithd1037052019-05-02 13:39:26 +0200570 VERBOSE_ASSERT(strcmp(vsub->imei, "42342342342342"), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100571 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100572
573 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200574 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100575 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200576 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100577
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100578 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100579 EXPECT_CONN_COUNT(0);
580 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100581 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100582}
583
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100584static void test_ciph_imeisv()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100585{
586 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100587 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100588
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100589 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100590
591 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100592 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr54a706c2017-07-18 15:39:27 +0200593 net->vlr->cfg.retrieve_imeisv_ciphered = true;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100594
595 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
596 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100597 gsup_expect_tx("08010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100598 ms_sends_msg("050802008168000130089910070000006402");
599 OSMO_ASSERT(gsup_tx_confirmed);
600 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
601
602 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
603 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
604 auth_request_sent = false;
605 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
606 auth_request_expect_autn = NULL;
607 gsup_rx("0a"
608 /* imsi */
609 "0108" "09710000004026f0"
610 /* 5 auth vectors... */
611 /* TL TL rand */
612 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
613 /* TL sres TL kc */
614 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
615 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
616 "2104" "20bde240" "2208" "07fa7502e07e1c00"
617 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
618 "2104" "a29514ae" "2208" "e2b234f807886400"
619 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
620 "2104" "5afc8d72" "2208" "2392f14f709ae000"
621 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100622 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100623 NULL);
624 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
625 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
626
627 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100628 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100629 ms_sends_msg("05542d8b2c3e");
630 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
631 VERBOSE_ASSERT(cipher_mode_cmd_sent_with_imeisv, == true, "%d");
632 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
633
634 btw("needs ciph, not yet accepted");
635 EXPECT_ACCEPTED(false);
636 thwart_rx_non_initial_requests();
637 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
638
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100639 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100640 OSMO_ASSERT(vsub);
641 VERBOSE_ASSERT(vsub->imeisv[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100642 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100643
644 btw("MS sends Ciphering Mode Complete with IMEISV, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100645 gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr0ec7b232020-05-29 03:28:32 +0200646 ms_sends_ciphering_mode_complete("063217094332244332244372f5");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100647 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
648
649 btw("Subscriber has the IMEISV");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100650 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100651 OSMO_ASSERT(vsub);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200652 VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100653 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100654
655 EXPECT_ACCEPTED(false);
656 thwart_rx_non_initial_requests();
657
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100658 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100659 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
660 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100661 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
662
663 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maierfbf66102017-04-09 12:32:51 +0200664 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100665 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Philipp Maierfbf66102017-04-09 12:32:51 +0200666 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100667
668 btw("LU was successful, and the conn has already been closed");
669 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100670 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100671 EXPECT_CONN_COUNT(0);
672
673 BTW("subscriber detaches");
Philipp Maierfbf66102017-04-09 12:32:51 +0200674 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100675 ms_sends_msg("050130089910070000006402");
Philipp Maierfbf66102017-04-09 12:32:51 +0200676 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100677
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100678 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100679 EXPECT_CONN_COUNT(0);
680 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100681 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100682}
683
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100684static void test_ciph_tmsi_imei()
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100685{
686 struct vlr_subscr *vsub;
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100687 const char *imsi = "901700000004620";
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100688
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100689 comment_start();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100690
691 /* implicit: net->authentication_required = true; */
Harald Welte7b222aa2017-12-23 19:30:32 +0100692 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100693 net->vlr->cfg.assign_tmsi = true;
694 net->vlr->cfg.check_imei_rqd = true;
695
696 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
697 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100698 gsup_expect_tx("08010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100699 ms_sends_msg("050802008168000130089910070000006402");
700 OSMO_ASSERT(gsup_tx_confirmed);
701 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
702
703 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
704 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
705 auth_request_sent = false;
706 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
707 auth_request_expect_autn = NULL;
708 gsup_rx("0a"
709 /* imsi */
710 "0108" "09710000004026f0"
711 /* 5 auth vectors... */
712 /* TL TL rand */
713 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
714 /* TL sres TL kc */
715 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
716 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
717 "2104" "20bde240" "2208" "07fa7502e07e1c00"
718 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
719 "2104" "a29514ae" "2208" "e2b234f807886400"
720 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
721 "2104" "5afc8d72" "2208" "2392f14f709ae000"
722 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100723 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100724 NULL);
725 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
726 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
727
728 btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100729 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100730 ms_sends_msg("05542d8b2c3e");
731 OSMO_ASSERT(cipher_mode_cmd_sent);
732 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
733
734 btw("needs ciph, not yet accepted");
735 EXPECT_ACCEPTED(false);
736 thwart_rx_non_initial_requests();
737 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
738
739 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100740 gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100741 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100742 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
743
744 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100745 gsup_rx("10010809710000004026f00804036470f1" HLR_TO_VLR,
746 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100747 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
748
749 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS");
750 dtap_expect_tx("051802");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100751 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100752
753 btw("We will only do business when the IMEI is known");
754 EXPECT_CONN_COUNT(1);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100755 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100756 OSMO_ASSERT(vsub);
757 VERBOSE_ASSERT(vsub->imei[0], == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100758 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100759 EXPECT_ACCEPTED(false);
760 thwart_rx_non_initial_requests();
761
Oliver Smith7d053092018-12-14 17:37:38 +0100762 btw("MS replies with an Identity Response, VLR sends the IMEI to HLR");
Oliver Smithd1037052019-05-02 13:39:26 +0200763 gsup_expect_tx("30010809710000004026f050080724433224433224" VLR_TO_HLR);
Neels Hofmeyr34d33bd2017-07-20 02:56:21 +0200764 ms_sends_msg("0559084a32244332244302");
Oliver Smith7d053092018-12-14 17:37:38 +0100765 EXPECT_ACCEPTED(false);
766 thwart_rx_non_initial_requests();
767
768 btw("HLR accepts the IMEI");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100769 gsup_rx("32010809710000004026f0510100" HLR_TO_VLR, NULL);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100770
771 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
772 EXPECT_CONN_COUNT(1);
773 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
774 EXPECT_ACCEPTED(false);
775 thwart_rx_non_initial_requests();
776
777 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100778 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100779 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
780 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
781 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
782 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100783 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100784
785 btw("MS sends TMSI Realloc Complete");
Philipp Maierfbf66102017-04-09 12:32:51 +0200786 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100787 ms_sends_msg("055b");
Philipp Maierfbf66102017-04-09 12:32:51 +0200788 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100789
790 btw("LU was successful, and the conn has already been closed");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100791 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100792 EXPECT_CONN_COUNT(0);
793
794 btw("Subscriber has the IMEI and TMSI");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100795 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100796 OSMO_ASSERT(vsub);
Oliver Smithd1037052019-05-02 13:39:26 +0200797 VERBOSE_ASSERT(strcmp(vsub->imei, "42342342342342"), == 0, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100798 VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100799 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100800
801 BTW("subscriber detaches, using TMSI");
Philipp Maierfbf66102017-04-09 12:32:51 +0200802 expect_bssap_clear();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100803 ms_sends_msg("050130" "05f4" "03020100");
Philipp Maierfbf66102017-04-09 12:32:51 +0200804 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100805
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100806 ran_sends_clear_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100807 EXPECT_CONN_COUNT(0);
808 clear_vlr();
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100809 comment_end();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100810}
811
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100812static void test_gsm_ciph_in_umts_env()
813{
814 struct vlr_subscr *vsub;
815 const char *imsi = "901700000010650";
816 const char *sms =
817 "09" /* SMS messages */
818 "01" /* CP-DATA */
819 "58" /* length */
820 "01" /* Network to MS */
821 "00" /* reference */
822 /* originator (gsm411_send_sms() hardcodes this weird nr) */
823 "0791" "447758100650" /* 447785016005 */
824 "00" /* dest */
825 /* SMS TPDU */
826 "4c" /* len */
827 "00" /* SMS deliver */
828 "05802443f2" /* originating address 42342 */
829 "00" /* TP-PID */
830 "00" /* GSM default alphabet */
831 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
832 "000000" /* H-M-S */
833 "00" /* GMT+0 */
834 "44" /* data length */
835 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
836 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
837 "0c7ac3e9e9b7db05";
838
839 comment_start();
840
841 /* implicit: net->authentication_required = true; */
842 net->a5_encryption_mask = (1 << 1);
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100843 rx_from_ran = OSMO_RAT_GERAN_A;
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100844
845 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
846 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100847 gsup_expect_tx("080108" "09710000000156f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100848 ms_sends_msg("0508" /* MM LU */
849 "7" /* ciph key seq: no key available */
850 "0" /* LU type: normal */
851 "ffffff" "0000" /* LAI, LAC */
852 "57" /* classmark 1: R99, early classmark, no power lvl */
853 "089910070000106005" /* IMSI */
854 "3303575886" /* classmark 2 */
855 );
856 OSMO_ASSERT(gsup_tx_confirmed);
857 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
858
859 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends *UMTS AKA* Auth Req to MS");
860 /* based on
861 * 2G auth: COMP128v1
862 * KI=7bcd108be4c3d551ee6c67faaf52bd68
863 * 3G auth: MILENAGE
864 * K=7bcd108be4c3d551ee6c67faaf52bd68
865 * OPC=6e23f641ce724679b73d933515a8589d
866 * IND-bitlen=5 last-SQN=641
867 * Note that the SRES will be calculated by COMP128v1, separately from 3G tokens;
868 * the resulting Kc to use for ciphering returned by the HLR is also calculated from COMP128v1.
869 */
870 auth_request_sent = false;
871 auth_request_expect_rand = "4ac8d1cd1a51937597ca1016fe69a0fa";
872 auth_request_expect_autn = "2d837d2b0d6f00004b282d5acf23428d";
873 gsup_rx("0a"
874 /* imsi */
875 "0108" "09710000000156f0"
876 /* 5 auth vectors... */
877 /* TL TL rand */
878 "0362" "2010" "4ac8d1cd1a51937597ca1016fe69a0fa"
879 /* TL sres TL kc */
880 "2104" "dacc4b26" "2208" "7a75f0ac9b844400"
881 /* TL 3G IK */
882 "2310" "3747da4e31545baa2db59e500bdae047"
883 /* TL 3G CK */
884 "2410" "8544d35b945ccba01a7f1293575291c3"
885 /* TL AUTN */
886 "2510" "2d837d2b0d6f00004b282d5acf23428d"
887 /* TL RES */
888 "2708" "37527064741f8ddb"
889 /* TL TL rand */
890 "0362" "2010" "b2661531b97b12c5a2edc21a0ed16fc5"
891 "2104" "2fb4cfad" "2208" "da149b11d473f400"
892 "2310" "3fe013b1a428ea737c37f8f0288c8edf"
893 "2410" "f275438c02b97e4d6f639dddda3d10b9"
894 "2510" "78cdd96c60840000322f421b3bb778b1"
895 "2708" "ed3ebf9cb6ea48ed"
896 "0362" "2010" "54d8f19778056666b41c8c25e52eb60c"
897 "2104" "0ff61e0f" "2208" "26ec67fad3073000"
898 "2310" "2868b0922c652616f1c975e3eaf7943a"
899 "2410" "6a84a20b1bc13ec9840466406d2dd91e"
900 "2510" "53f3e5632b3d00008865dd54d49663f2"
901 "2708" "86e848a9e7ad8cd5"
902 "0362" "2010" "1f05607ff9c8984f46ad97f8c9a94982"
903 "2104" "91a36e3d" "2208" "5d84421884fdcc00"
904 "2310" "2171fef54b81e30c83a598a5e44f634c"
905 "2410" "f02d088697509827565b46938fece211"
906 "2510" "1b43bbf9815e00001cb9b2a9f6b8a77c"
907 "2708" "373e67d62e719c51"
908 "0362" "2010" "80d89a58a2a41050918caf68a4e93c64"
909 "2104" "a319f5f1" "2208" "883df2b867293000"
910 "2310" "fa5d70f929ff298efb160413698dc107"
911 "2410" "ae9a3d8ce70ce13bac297bdb91cd6c68"
912 "2510" "5c0dc2eeaefa0000396882a1fe2cf80b"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100913 "2708" "65ab1cad216bfe87" HLR_TO_VLR,
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100914 NULL);
915 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
916 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
917
918 btw("MS sends *GSM AKA* Authen Response, VLR accepts and sends Ciphering Mode Command to MS");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100919 expect_cipher_mode_cmd("7a75f0ac9b844400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100920 ms_sends_msg("0554" "dacc4b26");
921 OSMO_ASSERT(cipher_mode_cmd_sent);
922 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
923
924 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100925 gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100926 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100927 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
928
929 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100930 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
931 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100932 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
933
934 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
935 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100936 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100937 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
938
939 btw("LU was successful, and the conn has already been closed");
940 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100941 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100942 EXPECT_CONN_COUNT(0);
943
944 BTW("after a while, a new conn sends a CM Service Request. VLR responds with *UMTS AKA* Auth Req, 2nd auth vector");
945 auth_request_sent = false;
946 auth_request_expect_rand = "b2661531b97b12c5a2edc21a0ed16fc5";
947 auth_request_expect_autn = "78cdd96c60840000322f421b3bb778b1";
948 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100949 ms_sends_msg("052474"
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100950 "03575886" /* classmark 2 */
951 "089910070000106005" /* IMSI */);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100952 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
953 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
954
955 btw("needs auth, not yet accepted");
956 EXPECT_ACCEPTED(false);
957 thwart_rx_non_initial_requests();
958
959 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100960 expect_cipher_mode_cmd("da149b11d473f400");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100961 ms_sends_msg("0554" "2fb4cfad");
962 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
963 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
964
965 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100966 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100967 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
968
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700969 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +0700970 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100971 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100972
973 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100974 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100975 EXPECT_CONN_COUNT(0);
976
977 BTW("an SMS is sent, MS is paged");
978 paging_expect_imsi(imsi);
979 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100980 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100981 OSMO_ASSERT(vsub);
982 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
983
984 send_sms(vsub, vsub,
985 "Privacy in residential applications is a desirable"
986 " marketing option.");
987
988 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100989 vlr_subscr_put(vsub, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100990 vsub = NULL;
991 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100992
993 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100994 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100995 OSMO_ASSERT(vsub);
996 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100997 vlr_subscr_put(vsub, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +0100998
999 btw("MS replies with Paging Response, and VLR sends *UMTS AKA* Auth Request with third key");
1000 auth_request_sent = false;
1001 auth_request_expect_rand = "54d8f19778056666b41c8c25e52eb60c";
1002 auth_request_expect_autn = "53f3e5632b3d00008865dd54d49663f2";
1003 ms_sends_msg("062707"
1004 "03575886" /* classmark 2 */
1005 "089910070000106005" /* IMSI */);
1006 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1007
1008 btw("needs auth, not yet accepted");
1009 EXPECT_ACCEPTED(false);
1010 thwart_rx_non_initial_requests();
1011
1012 btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001013 expect_cipher_mode_cmd("26ec67fad3073000");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001014 ms_sends_msg("0554" "0ff61e0f");
1015 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1016
1017 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1018 dtap_expect_tx(sms);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001019 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001020 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001021
1022 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001023 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001024 OSMO_ASSERT(vsub);
1025 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001026 vlr_subscr_put(vsub, __func__);
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001027
1028 btw("conn is still open to wait for SMS ack dance");
1029 EXPECT_CONN_COUNT(1);
1030
1031 btw("MS replies with CP-ACK for received SMS");
1032 ms_sends_msg("8904");
1033 EXPECT_CONN_COUNT(1);
1034
1035 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1036 dtap_expect_tx("0904");
1037 expect_bssap_clear();
1038 ms_sends_msg("890106020041020000");
1039 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1040 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1041
1042 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001043 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001044 EXPECT_CONN_COUNT(0);
1045
1046 BTW("subscriber detaches");
1047 expect_bssap_clear();
1048 ms_sends_msg("050130"
1049 "089910070000106005" /* IMSI */);
1050 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1051
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001052 ran_sends_clear_complete();
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001053 EXPECT_CONN_COUNT(0);
1054 clear_vlr();
1055 comment_end();
1056}
1057
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001058static void test_a5_3_supported()
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001059{
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001060 struct vlr_subscr *vsub;
1061 const char *imsi = "901700000004620";
1062
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001063 comment_start();
1064
1065 /* implicit: net->authentication_required = true; */
1066 net->a5_encryption_mask = (1 << 3); /* A5/3 */
1067
1068 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1069 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +01001070 gsup_expect_tx("08010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001071 ms_sends_msg("050802008168000130089910070000006402");
1072 OSMO_ASSERT(gsup_tx_confirmed);
1073 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1074
1075 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1076 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1077 auth_request_sent = false;
1078 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1079 auth_request_expect_autn = NULL;
1080 gsup_rx("0a"
1081 /* imsi */
1082 "0108" "09710000004026f0"
1083 /* 5 auth vectors... */
1084 /* TL TL rand */
1085 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1086 /* TL sres TL kc */
1087 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1088 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1089 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1090 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1091 "2104" "a29514ae" "2208" "e2b234f807886400"
1092 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1093 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1094 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001095 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001096 NULL);
1097 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1098 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1099
1100 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001101 " -- but needs Classmark 2 to determine whether A5/3 is supported");
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001102 cipher_mode_cmd_sent = false;
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001103 ms_sends_msg("05542d8b2c3e");
1104 OSMO_ASSERT(!cipher_mode_cmd_sent);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001105 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1106
1107 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1108 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001109 ms_sends_classmark_update(&classmark);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001110 OSMO_ASSERT(cipher_mode_cmd_sent);
1111 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1112
1113 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +01001114 gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001115 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001116 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1117
1118 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001119 gsup_rx("10010809710000004026f00804032443f2" HLR_TO_VLR,
1120 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001121 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1122
1123 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
1124 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001125 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001126 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1127
1128 btw("LU was successful, and the conn has already been closed");
1129 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001130 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001131 EXPECT_CONN_COUNT(0);
1132
1133 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1134 cm_service_result_sent = RES_NONE;
1135 auth_request_sent = false;
1136 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001137 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001138 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1139 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1140
1141 btw("needs auth, not yet accepted");
1142 EXPECT_ACCEPTED(false);
1143 thwart_rx_non_initial_requests();
1144
1145 btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3,"
1146 " so no need to request Classmark Update.");
1147 expect_cipher_mode_cmd("07fa7502e07e1c00");
1148 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
1149 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1150 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1151
1152 btw("needs ciph, not yet accepted");
1153 EXPECT_ACCEPTED(false);
1154 thwart_rx_non_initial_requests();
1155
1156 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001157 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001158 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1159
1160 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +07001161 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001162 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001163
1164 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001165 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001166 EXPECT_CONN_COUNT(0);
1167
1168 BTW("an SMS is sent, MS is paged");
1169 paging_expect_imsi(imsi);
1170 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001171 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001172 OSMO_ASSERT(vsub);
1173 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1174
1175 send_sms(vsub, vsub,
1176 "Privacy in residential applications is a desirable"
1177 " marketing option.");
1178
1179 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001180 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001181 vsub = NULL;
1182 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001183
1184 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001185 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001186 OSMO_ASSERT(vsub);
1187 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001188 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001189
1190 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1191 auth_request_sent = false;
1192 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
1193 ms_sends_msg("06270703305882089910070000006402");
1194 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1195
1196 btw("needs auth, not yet accepted");
1197 EXPECT_ACCEPTED(false);
1198 thwart_rx_non_initial_requests();
1199
1200 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
1201 expect_cipher_mode_cmd("e2b234f807886400");
1202 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
1203 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1204
1205 btw("needs ciph, not yet accepted");
1206 EXPECT_ACCEPTED(false);
1207 thwart_rx_non_initial_requests();
1208
1209 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1210 dtap_expect_tx("09" /* SMS messages */
1211 "01" /* CP-DATA */
1212 "58" /* length */
1213 "01" /* Network to MS */
1214 "00" /* reference */
1215 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1216 "0791" "447758100650" /* 447785016005 */
1217 "00" /* dest */
1218 /* SMS TPDU */
1219 "4c" /* len */
1220 "00" /* SMS deliver */
1221 "05802443f2" /* originating address 42342 */
1222 "00" /* TP-PID */
1223 "00" /* GSM default alphabet */
1224 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1225 "000000" /* H-M-S */
1226 "00" /* GMT+0 */
1227 "44" /* data length */
1228 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1229 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1230 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001231 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001232 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001233
1234 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001235 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001236 OSMO_ASSERT(vsub);
1237 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001238 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001239
1240 btw("conn is still open to wait for SMS ack dance");
1241 EXPECT_CONN_COUNT(1);
1242
1243 btw("MS replies with CP-ACK for received SMS");
1244 ms_sends_msg("8904");
1245 EXPECT_CONN_COUNT(1);
1246
1247 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1248 dtap_expect_tx("0904");
1249 expect_bssap_clear();
1250 ms_sends_msg("890106020041020000");
1251 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1252 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1253
1254 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001255 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001256 EXPECT_CONN_COUNT(0);
1257
1258 BTW("subscriber detaches");
1259 expect_bssap_clear();
1260 ms_sends_msg("050130089910070000006402");
1261 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1262
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001263 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001264 EXPECT_CONN_COUNT(0);
1265 clear_vlr();
1266 comment_end();
1267}
1268
1269/* During CM Service Request or Paging Response we already have Classmark 2 that indicates A5/3
Martin Hauke3f07dac2019-11-14 17:49:08 +01001270 * availability. Here, in a hacky way remove the knowledge of Classmark 2 to tickle a code path where
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001271 * proc_arq_fsm needs a Classmark Update during Ciphering. Shouldn't happen in reality though. */
1272static void test_cm_service_needs_classmark_update()
1273{
1274 struct vlr_subscr *vsub;
1275 const char *imsi = "901700000004620";
1276
1277 comment_start();
1278
1279 /* A5/3 support is indicated in Classmark 3. By configuring A5/3, trigger the code paths that
1280 * send a Classmark Request. */
1281 net->a5_encryption_mask = (1 << 3); /* A5/3 */
1282 /* implicit: net->authentication_required = true; */
1283
1284 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
1285 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +01001286 gsup_expect_tx("08010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001287 ms_sends_msg("050802008168000130089910070000006402");
1288 OSMO_ASSERT(gsup_tx_confirmed);
1289 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1290
1291 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
1292 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
1293 auth_request_sent = false;
1294 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
1295 auth_request_expect_autn = NULL;
1296 gsup_rx("0a"
1297 /* imsi */
1298 "0108" "09710000004026f0"
1299 /* 5 auth vectors... */
1300 /* TL TL rand */
1301 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
1302 /* TL sres TL kc */
1303 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
1304 "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b"
1305 "2104" "20bde240" "2208" "07fa7502e07e1c00"
1306 "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42"
1307 "2104" "a29514ae" "2208" "e2b234f807886400"
1308 "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51"
1309 "2104" "5afc8d72" "2208" "2392f14f709ae000"
1310 "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001311 "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000" HLR_TO_VLR,
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001312 NULL);
1313 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1314 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1315
1316 BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS"
1317 " -- but needs Classmark 2 to determine whether A5/3 is supported");
1318 cipher_mode_cmd_sent = false;
1319 ms_sends_msg("05542d8b2c3e");
1320 OSMO_ASSERT(!cipher_mode_cmd_sent);
1321 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1322
1323 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1324 expect_cipher_mode_cmd("61855fb81fc2a800");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001325 ms_sends_classmark_update(&classmark);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001326 OSMO_ASSERT(cipher_mode_cmd_sent);
1327 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1328
1329 btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +01001330 gsup_expect_tx("04010809710000004026f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001331 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001332 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1333
1334 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001335 gsup_rx("10010809710000004026f00804032443f2" HLR_TO_VLR,
1336 "12010809710000004026f0" VLR_TO_HLR);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001337 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
1338
1339 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
1340 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001341 gsup_rx("06010809710000004026f0" HLR_TO_VLR, NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001342 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1343
1344 btw("LU was successful, and the conn has already been closed");
1345 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001346 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001347 EXPECT_CONN_COUNT(0);
1348
1349
1350 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector");
1351 cm_service_result_sent = RES_NONE;
1352 auth_request_sent = false;
1353 auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b";
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001354 ms_sends_msg("05247403305886089910070000006402");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001355 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1356 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1357
1358 btw("needs auth, not yet accepted");
1359 EXPECT_ACCEPTED(false);
1360 thwart_rx_non_initial_requests();
1361
1362 btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3,"
1363 " so no need to request Classmark Update.");
1364 expect_cipher_mode_cmd("07fa7502e07e1c00");
1365 ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */);
1366 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1367 VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d");
1368
1369 btw("needs ciph, not yet accepted");
1370 EXPECT_ACCEPTED(false);
1371 thwart_rx_non_initial_requests();
1372
1373 btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001374 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001375 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
1376
1377 /* Release connection */
Vadim Yanitskiy188dd5f2019-06-19 02:05:08 +07001378 expect_bssap_clear();
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001379 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001380
1381 btw("all requests serviced, conn has been released");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001382 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001383 EXPECT_CONN_COUNT(0);
1384
1385 BTW("an SMS is sent, MS is paged");
1386 paging_expect_imsi(imsi);
1387 paging_sent = false;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001388 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001389 OSMO_ASSERT(vsub);
1390 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
1391
1392 send_sms(vsub, vsub, "Privacy in residential applications is a desirable marketing option.");
1393
1394 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001395 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001396 vsub = NULL;
1397 VERBOSE_ASSERT(paging_sent, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001398
1399 btw("the subscriber and its pending request should remain");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001400 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001401 OSMO_ASSERT(vsub);
1402 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001403 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001404
1405 btw("MS replies with Paging Response, and VLR sends Auth Request with third key");
1406 auth_request_sent = false;
1407 auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42";
1408 ms_sends_msg("06270703305882089910070000006402");
1409 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
1410
1411 BTW("Fake a situation where Classmark 2 is unknown during proc_arq_fsm");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001412 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001413 OSMO_ASSERT(vsub);
1414 vsub->classmark.classmark2_len = 0;
1415 vsub->classmark.classmark3_len = 0;
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001416 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001417
1418 btw("MS sends Authen Response, VLR accepts and requests Ciphering");
1419 btw("MS sends Authen Response, VLR accepts and requests Ciphering."
1420 " Normally, we'd know Classmark 3, but this test removed it."
1421 " Hence a Classmark Request is generated.");
1422 cipher_mode_cmd_sent = false;
1423 ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */);
1424 OSMO_ASSERT(!cipher_mode_cmd_sent);
1425
1426 btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3");
1427 expect_cipher_mode_cmd("e2b234f807886400");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001428 ms_sends_classmark_update(&classmark);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001429 OSMO_ASSERT(cipher_mode_cmd_sent);
1430
1431 btw("needs ciph, not yet accepted");
1432 EXPECT_ACCEPTED(false);
1433
1434 btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS");
1435 dtap_expect_tx("09" /* SMS messages */
1436 "01" /* CP-DATA */
1437 "58" /* length */
1438 "01" /* Network to MS */
1439 "00" /* reference */
1440 /* originator (gsm411_send_sms() hardcodes this weird nr) */
1441 "0791" "447758100650" /* 447785016005 */
1442 "00" /* dest */
1443 /* SMS TPDU */
1444 "4c" /* len */
1445 "00" /* SMS deliver */
1446 "05802443f2" /* originating address 42342 */
1447 "00" /* TP-PID */
1448 "00" /* GSM default alphabet */
1449 "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/
1450 "000000" /* H-M-S */
1451 "00" /* GMT+0 */
1452 "44" /* data length */
1453 "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e"
1454 "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb"
1455 "0c7ac3e9e9b7db05");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001456 ms_sends_ciphering_mode_complete(NULL);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001457 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001458
1459 btw("SMS was delivered, no requests pending for subscr");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001460 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001461 OSMO_ASSERT(vsub);
1462 VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +01001463 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001464
1465 btw("conn is still open to wait for SMS ack dance");
1466 EXPECT_CONN_COUNT(1);
1467
1468 btw("MS replies with CP-ACK for received SMS");
1469 ms_sends_msg("8904");
1470 EXPECT_CONN_COUNT(1);
1471
1472 btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that");
1473 dtap_expect_tx("0904");
1474 expect_bssap_clear();
1475 ms_sends_msg("890106020041020000");
1476 VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d");
1477 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
1478
1479 btw("SMS is done, conn is gone");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001480 ran_sends_clear_complete();
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001481 EXPECT_CONN_COUNT(0);
1482
1483 BTW("subscriber detaches");
1484 expect_bssap_clear();
1485 ms_sends_msg("050130089910070000006402");
1486 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001487
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001488 ran_sends_clear_complete();
Neels Hofmeyra7fd88c2018-03-02 01:50:42 +01001489 EXPECT_CONN_COUNT(0);
1490 clear_vlr();
1491 comment_end();
1492}
1493
1494
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001495msc_vlr_test_func_t msc_vlr_tests[] = {
1496 test_ciph,
1497 test_ciph_tmsi,
1498 test_ciph_imei,
1499 test_ciph_imeisv,
1500 test_ciph_tmsi_imei,
Neels Hofmeyrcac6e892018-03-10 02:05:44 +01001501 test_gsm_ciph_in_umts_env,
Neels Hofmeyr3117b702018-09-13 03:23:07 +02001502 test_a5_3_supported,
1503 test_cm_service_needs_classmark_update,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001504 NULL
1505};