blob: 4c51790cfd4c539fda677111db91e12afef850f5 [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 <getopt.h>
25#include <stdlib.h>
26
27#include <osmocom/core/logging.h>
28#include <osmocom/core/utils.h>
29#include <osmocom/core/msgb.h>
30#include <osmocom/core/application.h>
31#include <osmocom/gsm/protocol/gsm_04_11.h>
32#include <osmocom/gsm/gsup.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020033#include <osmocom/msc/gsup_client.h>
34#include <osmocom/msc/gsm_04_11.h>
35#include <osmocom/msc/debug.h>
Max43b01b02017-09-15 11:22:30 +020036#include <osmocom/msc/gsm_04_08.h>
Neels Hofmeyra99b4272017-11-21 17:13:23 +010037#include <osmocom/msc/transaction.h>
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020038
39#if BUILD_IU
Neels Hofmeyr90843962017-09-04 15:04:35 +020040#include <osmocom/msc/iucs_ranap.h>
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020041#include <osmocom/ranap/iu_client.h>
42#else
Neels Hofmeyr90843962017-09-04 15:04:35 +020043#include <osmocom/msc/iu_dummy.h>
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020044#endif
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010045
46#include "msc_vlr_tests.h"
47
48bool _log_lines = false;
49
50struct gsm_network *net = NULL;
51
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010052const char *gsup_tx_expected = NULL;
53bool gsup_tx_confirmed;
54
55struct msgb *dtap_tx_expected = NULL;
56bool dtap_tx_confirmed;
57
58enum result_sent lu_result_sent;
59enum result_sent cm_service_result_sent;
60bool auth_request_sent;
61const char *auth_request_expect_rand;
62const char *auth_request_expect_autn;
63bool cipher_mode_cmd_sent;
64bool cipher_mode_cmd_sent_with_imeisv;
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010065const char *cipher_mode_expect_kc;
66bool security_mode_ctrl_sent;
67const char *security_mode_expect_ck;
68const char *security_mode_expect_ik;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010069
Philipp Maierfbf66102017-04-09 12:32:51 +020070bool iu_release_expected = false;
71bool iu_release_sent = false;
72bool bssap_clear_expected = false;
73bool bssap_clear_sent = false;
74
Neels Hofmeyra99b4272017-11-21 17:13:23 +010075uint32_t cc_to_mncc_tx_expected_msg_type = 0;
76const char *cc_to_mncc_tx_expected_imsi = NULL;
77bool cc_to_mncc_tx_confirmed = false;
78uint32_t cc_to_mncc_tx_got_callref = 0;
79
Harald Weltec2007852018-02-03 21:08:26 +010080extern int gsm0407_pdisc_ctr_bin(uint8_t pdisc);
81
82/* static state variables for the L3 send sequence numbers */
83static uint8_t n_sd[4];
84
85/* patch a correct send sequence number into the given message */
86static void patch_l3_seq_nr(struct msgb *msg)
87{
88 struct gsm48_hdr *gh = msgb_l3(msg);
89 uint8_t pdisc = gsm48_hdr_pdisc(gh);
90 uint8_t *msg_type_oct = &msg->l3h[1];
91 int bin = gsm0407_pdisc_ctr_bin(pdisc);
92
93 if (bin >= 0 && bin < ARRAY_SIZE(n_sd)) {
94 /* patch in n_sd into the msg_type octet */
95 *msg_type_oct = (*msg_type_oct & 0x3f) | ((n_sd[bin] & 0x3) << 6);
96 //fprintf(stderr, "pdisc=0x%02x bin=%d, patched n_sd=%u\n\n", pdisc, bin, n_sd[bin] & 3);
97 /* increment N(SD) */
98 n_sd[bin] = (n_sd[bin] + 1) % 4;
99 } else {
100 //fprintf(stderr, "pdisc=0x%02x NO SEQ\n\n", pdisc);
101 }
102}
103
104/* reset L3 sequence numbers (e.g. new RR connection) */
105static void reset_l3_seq_nr()
106{
107 memset(n_sd, 0, sizeof(n_sd));
108}
109
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100110struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex)
111{
112 struct msgb *msg = msgb_alloc(size, label);
113 unsigned char *rc;
114 msg->l2h = msg->head;
115 rc = msgb_put(msg, osmo_hexparse(hex, msg->head, msgb_tailroom(msg)));
116 OSMO_ASSERT(rc == msg->l2h);
117 return msg;
118}
119
Maxd8d1a9e2018-02-06 15:50:20 +0100120static const char *gh_type_name(struct gsm48_hdr *gh)
Neels Hofmeyr78ada642017-03-10 02:15:20 +0100121{
122 return gsm48_pdisc_msgtype_name(gsm48_hdr_pdisc(gh),
123 gsm48_hdr_msg_type(gh));
124}
125
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100126void dtap_expect_tx(const char *hex)
127{
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200128 /* Has the previously expected dtap been received? */
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100129 OSMO_ASSERT(!dtap_tx_expected);
130 if (!hex)
131 return;
132 dtap_tx_expected = msgb_from_hex("dtap_tx_expected", 1024, hex);
Harald Weltec2007852018-02-03 21:08:26 +0100133 /* Mask the sequence number out */
134 if (msgb_length(dtap_tx_expected) >= 2)
135 dtap_tx_expected->data[1] &= 0x3f;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100136 dtap_tx_confirmed = false;
137}
138
139void dtap_expect_tx_ussd(char *ussd_text)
140{
141 uint8_t ussd_enc[128];
142 int len;
143 /* header */
144 char ussd_msg_hex[128] = "8b2a1c27a225020100302002013b301b04010f0416";
145
146 log("expecting USSD:\n %s", ussd_text);
147 /* append encoded USSD text */
148 gsm_7bit_encode_n_ussd(ussd_enc, sizeof(ussd_enc), ussd_text,
149 &len);
150 strncat(ussd_msg_hex, osmo_hexdump_nospc(ussd_enc, len),
151 sizeof(ussd_msg_hex) - strlen(ussd_msg_hex));
152 dtap_expect_tx(ussd_msg_hex);
153}
154
155int vlr_gsupc_read_cb(struct gsup_client *gsupc, struct msgb *msg);
156
157void gsup_rx(const char *rx_hex, const char *expect_tx_hex)
158{
159 int rc;
160 struct msgb *msg;
161 const char *label;
162
163 gsup_expect_tx(expect_tx_hex);
164
165 msg = msgb_from_hex("gsup", 1024, rx_hex);
166 label = osmo_gsup_message_type_name(msg->l2h[0]);
167 fprintf(stderr, "<-- GSUP rx %s: %s\n", label,
168 osmo_hexdump_nospc(msgb_l2(msg), msgb_l2len(msg)));
Neels Hofmeyr834f94a2017-09-28 03:07:16 +0200169 /* GSUP read cb takes ownership of msgb */
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100170 rc = vlr_gsupc_read_cb(net->vlr->gsup_client, msg);
171 fprintf(stderr, "<-- GSUP rx %s: vlr_gsupc_read_cb() returns %d\n",
172 label, rc);
173 if (expect_tx_hex)
174 OSMO_ASSERT(gsup_tx_confirmed);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100175}
176
177bool conn_exists(struct gsm_subscriber_connection *conn)
178{
179 struct gsm_subscriber_connection *c;
180 llist_for_each_entry(c, &net->subscr_conns, entry) {
181 if (c == conn)
182 return true;
183 }
184 return false;
185}
186
187enum ran_type rx_from_ran = RAN_GERAN_A;
188
189struct gsm_subscriber_connection *conn_new(void)
190{
191 struct gsm_subscriber_connection *conn;
192 conn = msc_subscr_con_allocate(net);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100193 conn->via_ran = rx_from_ran;
Neels Hofmeyr8a656eb2017-11-22 02:55:52 +0100194 conn->lac = 23;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200195 if (conn->via_ran == RAN_UTRAN_IU) {
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200196 struct ranap_ue_conn_ctx *ue_ctx = talloc_zero(conn, struct ranap_ue_conn_ctx);
197 *ue_ctx = (struct ranap_ue_conn_ctx){
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200198 .conn_id = 42,
199 };
200 conn->iu.ue_ctx = ue_ctx;
201 }
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100202 return conn;
203}
204
205struct gsm_subscriber_connection *g_conn = NULL;
206
207void rx_from_ms(struct msgb *msg)
208{
209 int rc;
210
211 struct gsm48_hdr *gh = msgb_l3(msg);
Neels Hofmeyr78ada642017-03-10 02:15:20 +0100212
213 log("MSC <--%s-- MS: %s",
214 ran_type_name(rx_from_ran),
215 gh_type_name(gh));
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100216
217 if (g_conn && !conn_exists(g_conn))
218 g_conn = NULL;
219
220 if (!g_conn) {
221 log("new conn");
222 g_conn = conn_new();
Harald Weltec2007852018-02-03 21:08:26 +0100223 reset_l3_seq_nr();
224 patch_l3_seq_nr(msg);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200225 rc = msc_compl_l3(g_conn, msg, 23);
Harald Welted5db1702018-02-13 23:59:59 +0100226 if (rc != MSC_CONN_ACCEPT) {
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100227 msc_subscr_con_free(g_conn);
228 g_conn = NULL;
229 }
230 } else {
Harald Weltec2007852018-02-03 21:08:26 +0100231 patch_l3_seq_nr(msg);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100232 if ((gsm48_hdr_pdisc(gh) == GSM48_PDISC_RR)
233 && (gsm48_hdr_msg_type(gh) == GSM48_MT_RR_CIPH_M_COMPL))
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200234 msc_cipher_mode_compl(g_conn, msg, 0);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100235 else
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200236 msc_dtap(g_conn, 23, msg);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100237 }
238
239 if (g_conn && !conn_exists(g_conn))
240 g_conn = NULL;
241}
242
243void ms_sends_msg(const char *hex)
244{
245 struct msgb *msg;
246
247 msg = msgb_from_hex("ms_sends_msg", 1024, hex);
248 msg->l1h = msg->l2h = msg->l3h = msg->data;
249 rx_from_ms(msg);
250 talloc_free(msg);
251}
252
Maxd8d1a9e2018-02-06 15:50:20 +0100253static int ms_sends_msg_fake(uint8_t pdisc, uint8_t msg_type)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100254{
255 int rc;
256 struct msgb *msg;
257 struct gsm48_hdr *gh;
258
259 msg = msgb_alloc(1024, "ms_sends_msg_fake");
260 msg->l1h = msg->l2h = msg->l3h = msg->data;
261
262 gh = (struct gsm48_hdr*)msgb_put(msg, sizeof(*gh));
263 gh->proto_discr = pdisc;
264 gh->msg_type = msg_type;
265 /* some amount of data, whatever */
266 msgb_put(msg, 123);
267
Harald Weltec2007852018-02-03 21:08:26 +0100268 patch_l3_seq_nr(msg);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100269 rc = gsm0408_dispatch(g_conn, msg);
270
271 talloc_free(msg);
272 return rc;
273}
274
Max68171902018-02-06 17:55:19 +0100275static inline void ms_msg_log_err(uint8_t val, uint8_t msgtype)
276{
277 int rc = ms_sends_msg_fake(val, msgtype);
278 if (rc != -EACCES)
279 log("Unexpected return value %u != %u for %s/%s",
280 -rc, -EACCES, gsm48_pdisc_name(val), gsm48_cc_msg_name(msgtype));
281}
282
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100283void thwart_rx_non_initial_requests()
284{
285 log("requests shall be thwarted");
Max68171902018-02-06 17:55:19 +0100286
287 ms_msg_log_err(GSM48_PDISC_CC, GSM48_MT_CC_SETUP);
288 ms_msg_log_err(GSM48_PDISC_MM, 0x33); /* nonexistent */
289 ms_msg_log_err(GSM48_PDISC_RR, GSM48_MT_RR_SYSINFO_1);
290 ms_msg_log_err(GSM48_PDISC_SMS, GSM411_MT_CP_DATA);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100291}
292
293void send_sms(struct vlr_subscr *receiver,
294 struct vlr_subscr *sender,
295 char *str)
296{
297 struct gsm_sms *sms = sms_from_text(receiver, sender, 0, str);
298 gsm411_send_sms_subscr(receiver, sms);
299}
300
301unsigned char next_rand_byte = 0;
Max753c15d2017-12-21 14:50:44 +0100302/* override, requires '-Wl,--wrap=osmo_get_rand_id' */
303int __real_osmo_get_rand_id(uint8_t *buf, size_t num);
304int __wrap_osmo_get_rand_id(uint8_t *buf, size_t num)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100305{
Max753c15d2017-12-21 14:50:44 +0100306 size_t i;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100307 for (i = 0; i < num; i++)
308 buf[i] = next_rand_byte++;
309 return 1;
310}
311
312/* override, requires '-Wl,--wrap=gsm340_gen_scts' */
313void __real_gsm340_gen_scts(uint8_t *scts, time_t time);
314void __wrap_gsm340_gen_scts(uint8_t *scts, time_t time)
315{
Neels Hofmeyr05230ea2017-08-22 18:06:42 +0200316 /* Write fixed time bytes for deterministic test results */
317 osmo_hexparse("07101000000000", scts, 7);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100318}
319
320const char *paging_expecting_imsi = NULL;
321uint32_t paging_expecting_tmsi;
322bool paging_sent;
323bool paging_stopped;
324
325void paging_expect_imsi(const char *imsi)
326{
327 paging_expecting_imsi = imsi;
328 paging_expecting_tmsi = GSM_RESERVED_TMSI;
329}
330
331void paging_expect_tmsi(uint32_t tmsi)
332{
333 paging_expecting_tmsi = tmsi;
334 paging_expecting_imsi = NULL;
335}
336
Maxd8d1a9e2018-02-06 15:50:20 +0100337static int _paging_sent(enum ran_type via_ran, const char *imsi, uint32_t tmsi, uint32_t lac)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100338{
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200339 log("%s sends out paging request to IMSI %s, TMSI 0x%08x, LAC %u",
340 ran_type_name(via_ran), imsi, tmsi, lac);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100341 OSMO_ASSERT(paging_expecting_imsi || (paging_expecting_tmsi != GSM_RESERVED_TMSI));
342 if (paging_expecting_imsi)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200343 VERBOSE_ASSERT(strcmp(paging_expecting_imsi, imsi), == 0, "%d");
344 if (paging_expecting_tmsi != GSM_RESERVED_TMSI) {
345 VERBOSE_ASSERT(paging_expecting_tmsi, == tmsi, "0x%08x");
346 }
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100347 paging_sent = true;
348 paging_stopped = false;
349 return 1;
350}
351
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200352/* override, requires '-Wl,--wrap=ranap_iu_page_cs' */
353int __real_ranap_iu_page_cs(const char *imsi, const uint32_t *tmsi, uint16_t lac);
354int __wrap_ranap_iu_page_cs(const char *imsi, const uint32_t *tmsi, uint16_t lac)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200355{
356 return _paging_sent(RAN_UTRAN_IU, imsi, tmsi ? *tmsi : GSM_RESERVED_TMSI, lac);
357}
358
Philipp Maierfbf66102017-04-09 12:32:51 +0200359/* override, requires '-Wl,--wrap=a_iface_tx_paging' */
360int __real_a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac);
361int __wrap_a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200362{
363 return _paging_sent(RAN_GERAN_A, imsi, tmsi, lac);
364}
365
366/* override, requires '-Wl,--wrap=msc_stop_paging' */
367void __real_msc_stop_paging(struct vlr_subscr *vsub);
368void __wrap_msc_stop_paging(struct vlr_subscr *vsub)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100369{
370 paging_stopped = true;
371}
372
373void clear_vlr()
374{
375 struct vlr_subscr *vsub, *n;
376 llist_for_each_entry_safe(vsub, n, &net->vlr->subscribers, list) {
377 vlr_subscr_free(vsub);
378 }
379
380 net->authentication_required = false;
Harald Welte7b222aa2017-12-23 19:30:32 +0100381 net->a5_encryption_mask = (1 << 0);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100382 net->vlr->cfg.check_imei_rqd = false;
383 net->vlr->cfg.assign_tmsi = false;
Neels Hofmeyr54a706c2017-07-18 15:39:27 +0200384 net->vlr->cfg.retrieve_imeisv_early = false;
385 net->vlr->cfg.retrieve_imeisv_ciphered = false;
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100386 net->vlr->cfg.auth_tuple_max_reuse_count = 0;
387 net->vlr->cfg.auth_reuse_old_sets_on_error = false;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100388
389 rx_from_ran = RAN_GERAN_A;
390 auth_request_sent = false;
391 auth_request_expect_rand = NULL;
392 auth_request_expect_autn = NULL;
393
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100394 cipher_mode_cmd_sent = false;
395 cipher_mode_cmd_sent_with_imeisv = false;
396 cipher_mode_expect_kc = NULL;
397
398 security_mode_ctrl_sent = false;
399 security_mode_expect_ck = NULL;
400 security_mode_expect_ik = NULL;
401
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100402 next_rand_byte = 0;
403
Philipp Maierfbf66102017-04-09 12:32:51 +0200404 iu_release_expected = false;
405 iu_release_sent = false;
406 bssap_clear_expected = false;
407 bssap_clear_sent = false;
408
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100409 osmo_gettimeofday_override = false;
410}
411
412static struct log_info_cat test_categories[] = {
413 [DMSC] = {
414 .name = "DMSC",
415 .description = "Mobile Switching Center",
416 .enabled = 1, .loglevel = LOGL_DEBUG,
417 },
418 [DRLL] = {
419 .name = "DRLL",
420 .description = "A-bis Radio Link Layer (RLL)",
421 .enabled = 1, .loglevel = LOGL_DEBUG,
422 },
423 [DMM] = {
424 .name = "DMM",
425 .description = "Layer3 Mobility Management (MM)",
426 .enabled = 1, .loglevel = LOGL_DEBUG,
427 },
428 [DRR] = {
429 .name = "DRR",
430 .description = "Layer3 Radio Resource (RR)",
431 .enabled = 1, .loglevel = LOGL_DEBUG,
432 },
433 [DCC] = {
434 .name = "DCC",
435 .description = "Layer3 Call Control (CC)",
Neels Hofmeyr12e17be2018-03-12 23:59:37 +0100436 .enabled = 1, .loglevel = LOGL_DEBUG,
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100437 },
438 [DMM] = {
439 .name = "DMM",
440 .description = "Layer3 Mobility Management (MM)",
441 .enabled = 1, .loglevel = LOGL_DEBUG,
442 },
443 [DVLR] = {
444 .name = "DVLR",
445 .description = "Visitor Location Register",
446 .enabled = 1, .loglevel = LOGL_DEBUG,
447 },
448 [DREF] = {
449 .name = "DREF",
450 .description = "Reference Counting",
451 .enabled = 1, .loglevel = LOGL_DEBUG,
452 },
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200453 [DPAG] = {
454 .name = "DPAG",
455 .description = "Paging Subsystem",
456 .enabled = 1, .loglevel = LOGL_DEBUG,
457 },
458 [DIUCS] = {
459 .name = "DIUCS",
460 .description = "Iu-CS Protocol",
461 .enabled = 1, .loglevel = LOGL_DEBUG,
462 },
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100463 [DMNCC] = {
464 .name = "DMNCC",
465 .description = "MNCC API for Call Control application",
466 .enabled = 1, .loglevel = LOGL_DEBUG,
467 },
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100468};
469
470static struct log_info info = {
471 .cat = test_categories,
472 .num_cat = ARRAY_SIZE(test_categories),
473};
474
475extern void *tall_bsc_ctx;
476
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100477int mncc_recv(struct gsm_network *net, struct msgb *msg)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100478{
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100479 struct gsm_mncc *mncc = (void*)msg->data;
480 log("MSC --> MNCC: callref 0x%x: %s", mncc->callref,
481 get_mncc_name(mncc->msg_type));
482
483 OSMO_ASSERT(cc_to_mncc_tx_expected_msg_type);
484 if (cc_to_mncc_tx_expected_msg_type != mncc->msg_type) {
485 log("Mismatch! Expected MNCC msg type: %s",
486 get_mncc_name(cc_to_mncc_tx_expected_msg_type));
487 abort();
488 }
489
490 if (strcmp(cc_to_mncc_tx_expected_imsi, mncc->imsi)) {
491 log("Mismatch! Expected MNCC msg IMSI: '%s', got '%s'",
492 cc_to_mncc_tx_expected_imsi,
493 mncc->imsi);
494 abort();
495 }
496
497 cc_to_mncc_tx_confirmed = true;
498 cc_to_mncc_tx_got_callref = mncc->callref;
499 cc_to_mncc_tx_expected_imsi = NULL;
500 cc_to_mncc_tx_expected_msg_type = 0;
501 talloc_free(msg);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100502 return 0;
503}
504
505/* override, requires '-Wl,--wrap=gsup_client_create' */
506struct gsup_client *
507__real_gsup_client_create(const char *ip_addr, unsigned int tcp_port,
508 gsup_client_read_cb_t read_cb,
509 struct oap_client_config *oap_config);
510struct gsup_client *
511__wrap_gsup_client_create(const char *ip_addr, unsigned int tcp_port,
512 gsup_client_read_cb_t read_cb,
513 struct oap_client_config *oap_config)
514{
515 struct gsup_client *gsupc;
516 gsupc = talloc_zero(tall_bsc_ctx, struct gsup_client);
517 OSMO_ASSERT(gsupc);
518 return gsupc;
519}
520
521/* override, requires '-Wl,--wrap=gsup_client_send' */
522int __real_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg);
523int __wrap_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
524{
525 const char *is = osmo_hexdump_nospc(msg->data, msg->len);
526 fprintf(stderr, "GSUP --> HLR: %s: %s\n",
527 osmo_gsup_message_type_name(msg->data[0]), is);
528
529 OSMO_ASSERT(gsup_tx_expected);
530 if (strcmp(gsup_tx_expected, is)) {
531 fprintf(stderr, "Mismatch! Expected:\n%s\n", gsup_tx_expected);
532 abort();
533 }
534
535 talloc_free(msg);
536 gsup_tx_confirmed = true;
537 gsup_tx_expected = NULL;
538 return 0;
539}
540
Maxd8d1a9e2018-02-06 15:50:20 +0100541static int _validate_dtap(struct msgb *msg, enum ran_type to_ran)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100542{
Neels Hofmeyr78ada642017-03-10 02:15:20 +0100543 btw("DTAP --%s--> MS: %s: %s",
Maxd8d1a9e2018-02-06 15:50:20 +0100544 ran_type_name(to_ran), gh_type_name((void*)msg->data),
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200545 osmo_hexdump_nospc(msg->data, msg->len));
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100546
547 OSMO_ASSERT(dtap_tx_expected);
Harald Weltec2007852018-02-03 21:08:26 +0100548
549 /* Mask the sequence number out before comparing */
550 msg->data[1] &= 0x3f;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100551 if (msg->len != dtap_tx_expected->len
552 || memcmp(msg->data, dtap_tx_expected->data, msg->len)) {
553 fprintf(stderr, "Mismatch! Expected:\n%s\n",
554 osmo_hexdump_nospc(dtap_tx_expected->data,
555 dtap_tx_expected->len));
556 abort();
557 }
558
559 btw("DTAP matches expected message");
560
561 talloc_free(msg);
562 dtap_tx_confirmed = true;
563 talloc_free(dtap_tx_expected);
564 dtap_tx_expected = NULL;
565 return 0;
566}
567
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200568/* override, requires '-Wl,--wrap=ranap_iu_tx' */
569int __real_ranap_iu_tx(struct msgb *msg, uint8_t sapi);
570int __wrap_ranap_iu_tx(struct msgb *msg, uint8_t sapi)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200571{
572 return _validate_dtap(msg, RAN_UTRAN_IU);
573}
574
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200575/* override, requires '-Wl,--wrap=ranap_iu_tx_release' */
576int __real_ranap_iu_tx_release(struct ranap_ue_conn_ctx *ctx, const struct RANAP_Cause *cause);
577int __wrap_ranap_iu_tx_release(struct ranap_ue_conn_ctx *ctx, const struct RANAP_Cause *cause)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200578{
579 btw("Iu Release --%s--> MS", ran_type_name(RAN_UTRAN_IU));
Philipp Maierfbf66102017-04-09 12:32:51 +0200580 OSMO_ASSERT(iu_release_expected);
581 iu_release_expected = false;
582 iu_release_sent = true;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200583 return 0;
584}
585
586/* override, requires '-Wl,--wrap=iu_tx_common_id' */
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200587int __real_ranap_iu_tx_common_id(struct ranap_ue_conn_ctx *ue_ctx, const char *imsi);
588int __wrap_ranap_iu_tx_common_id(struct ranap_ue_conn_ctx *ue_ctx, const char *imsi)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200589{
590 btw("Iu Common ID --%s--> MS (IMSI=%s)", ran_type_name(RAN_UTRAN_IU), imsi);
591 return 0;
592}
593
Philipp Maierfbf66102017-04-09 12:32:51 +0200594/* override, requires '-Wl,--wrap=a_iface_tx_dtap' */
595int __real_a_iface_tx_dtap(struct msgb *msg);
596int __wrap_a_iface_tx_dtap(struct msgb *msg)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200597{
598 return _validate_dtap(msg, RAN_GERAN_A);
599}
600
Philipp Maierfbf66102017-04-09 12:32:51 +0200601/* override, requires '-Wl,--wrap=a_iface_tx_clear_cmd' */
602int __real_a_iface_tx_clear_cmd(struct gsm_subscriber_connection *conn);
603int __wrap_a_iface_tx_clear_cmd(struct gsm_subscriber_connection *conn)
604{
605 btw("BSSAP Clear --%s--> MS", ran_type_name(RAN_GERAN_A));
606 OSMO_ASSERT(bssap_clear_expected);
607 bssap_clear_expected = false;
608 bssap_clear_sent = true;
609 return 0;
610}
611
Philipp Maier621ba032017-11-07 17:19:25 +0100612/* override, requires '-Wl,--wrap=msc_mgcp_call_assignment' */
613int __real_msc_mgcp_call_assignment(struct gsm_trans *trans);
614int __wrap_msc_mgcp_call_assignment(struct gsm_trans *trans)
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100615{
616 log("MS <--Call Assignment-- MSC: subscr=%s callref=0x%x",
617 vlr_subscr_name(trans->vsub), trans->callref);
618 return 0;
619}
620
Philipp Maier621ba032017-11-07 17:19:25 +0100621/* override, requires '-Wl,--wrap=msc_mgcp_call_release' */
622void __real_msc_mgcp_call_release(struct gsm_trans *trans);
623void __wrap_msc_mgcp_call_release(struct gsm_trans *trans)
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100624{
625 log("MS <--Call Release-- MSC: subscr=%s callref=0x%x",
626 vlr_subscr_name(trans->vsub), trans->callref);
627}
628
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100629static int fake_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi)
630{
631 struct gsm_subscriber_connection *conn = msc_conn_ref;
632 if (send_tmsi == GSM_RESERVED_TMSI)
633 btw("sending LU Accept for %s", vlr_subscr_name(conn->vsub));
634 else
635 btw("sending LU Accept for %s, with TMSI 0x%08x",
636 vlr_subscr_name(conn->vsub), send_tmsi);
637 lu_result_sent |= RES_ACCEPT;
638 return 0;
639}
640
641static int fake_vlr_tx_lu_rej(void *msc_conn_ref, uint8_t cause)
642{
643 struct gsm_subscriber_connection *conn = msc_conn_ref;
644 btw("sending LU Reject for %s, cause %u", vlr_subscr_name(conn->vsub), cause);
645 lu_result_sent |= RES_REJECT;
646 return 0;
647}
648
649static int fake_vlr_tx_cm_serv_acc(void *msc_conn_ref)
650{
651 struct gsm_subscriber_connection *conn = msc_conn_ref;
652 btw("sending CM Service Accept for %s", vlr_subscr_name(conn->vsub));
653 cm_service_result_sent |= RES_ACCEPT;
654 return 0;
655}
656
657static int fake_vlr_tx_cm_serv_rej(void *msc_conn_ref,
658 enum vlr_proc_arq_result result)
659{
660 struct gsm_subscriber_connection *conn = msc_conn_ref;
661 btw("sending CM Service Reject for %s, result %s",
662 vlr_subscr_name(conn->vsub),
663 vlr_proc_arq_result_name(result));
664 cm_service_result_sent |= RES_REJECT;
665 return 0;
666}
667
668static int fake_vlr_tx_auth_req(void *msc_conn_ref, struct gsm_auth_tuple *at,
669 bool send_autn)
670{
671 struct gsm_subscriber_connection *conn = msc_conn_ref;
672 char *hex;
673 bool ok = true;
674 btw("sending %s Auth Request for %s: tuple use_count=%d key_seq=%d auth_types=0x%x and...",
675 send_autn? "UMTS" : "GSM", vlr_subscr_name(conn->vsub),
676 at->use_count, at->key_seq, at->vec.auth_types);
677
678 hex = osmo_hexdump_nospc((void*)&at->vec.rand, sizeof(at->vec.rand));
679 btw("...rand=%s", hex);
680 if (!auth_request_expect_rand
681 || strcmp(hex, auth_request_expect_rand) != 0) {
682 ok = false;
683 log("FAILURE: expected rand=%s",
684 auth_request_expect_rand ? auth_request_expect_rand : "-");
685 }
686
687 if (send_autn) {
688 hex = osmo_hexdump_nospc((void*)&at->vec.autn, sizeof(at->vec.autn));
689 btw("...autn=%s", hex);
690 if (!auth_request_expect_autn
691 || strcmp(hex, auth_request_expect_autn) != 0) {
692 ok = false;
693 log("FAILURE: expected autn=%s",
694 auth_request_expect_autn ? auth_request_expect_autn : "-");
695 }
696 } else if (auth_request_expect_autn) {
697 ok = false;
698 log("FAILURE: no AUTN sent, expected AUTN = %s",
699 auth_request_expect_autn);
700 }
701
702 if (send_autn)
703 btw("...expecting res=%s",
704 osmo_hexdump_nospc((void*)&at->vec.res, at->vec.res_len));
705 else
706 btw("...expecting sres=%s",
707 osmo_hexdump_nospc((void*)&at->vec.sres, sizeof(at->vec.sres)));
708
709 auth_request_sent = ok;
710 return 0;
711}
712
713static int fake_vlr_tx_auth_rej(void *msc_conn_ref)
714{
715 struct gsm_subscriber_connection *conn = msc_conn_ref;
716 btw("sending Auth Reject for %s", vlr_subscr_name(conn->vsub));
717 return 0;
718}
719
Neels Hofmeyrda21a522018-03-02 01:50:09 +0100720/* override, requires '-Wl,--wrap=a_iface_tx_cipher_mode' */
721int __real_a_iface_tx_cipher_mode(const struct gsm_subscriber_connection *conn,
722 struct gsm0808_encrypt_info *ei, int include_imeisv);
723int __wrap_a_iface_tx_cipher_mode(const struct gsm_subscriber_connection *conn,
724 struct gsm0808_encrypt_info *ei, int include_imeisv)
725{
726 int i;
727 btw("sending Ciphering Mode Command for %s: include_imeisv=%d",
728 vlr_subscr_name(conn->vsub), include_imeisv);
729 for (i = 0; i < ei->perm_algo_len; i++)
730 btw("...perm algo: %u", ei->perm_algo[i]);
731 OSMO_ASSERT(ei->key_len <= sizeof(ei->key));
732 btw("...key: %s", osmo_hexdump_nospc(ei->key, ei->key_len));
733 cipher_mode_cmd_sent = true;
734 cipher_mode_cmd_sent_with_imeisv = include_imeisv;
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100735
736 if (!cipher_mode_expect_kc
737 || strcmp(cipher_mode_expect_kc, osmo_hexdump_nospc(ei->key, ei->key_len))) {
738 log("FAILURE: expected kc=%s", cipher_mode_expect_kc ? : "NULL");
739 OSMO_ASSERT(false);
740 }
Neels Hofmeyrda21a522018-03-02 01:50:09 +0100741 return 0;
742}
743
744/* override, requires '-Wl,--wrap=ranap_iu_tx_sec_mode_cmd' */
745int __real_ranap_iu_tx_sec_mode_cmd(struct ranap_ue_conn_ctx *uectx, struct osmo_auth_vector *vec,
746 int send_ck, int new_key);
747int __wrap_ranap_iu_tx_sec_mode_cmd(struct ranap_ue_conn_ctx *uectx, struct osmo_auth_vector *vec,
748 int send_ck, int new_key)
749{
750 btw("sending SecurityModeControl for UE ctx %u send_ck=%d new_key=%d",
751 uectx->conn_id, send_ck, new_key);
752 btw("...ik=%s", osmo_hexdump_nospc(vec->ik, sizeof(vec->ik)));
753 if (send_ck)
754 btw("...ck=%s", osmo_hexdump_nospc(vec->ck, sizeof(vec->ck)));
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100755 security_mode_ctrl_sent = true;
756 if (!security_mode_expect_ik
757 || strcmp(security_mode_expect_ik, osmo_hexdump_nospc(vec->ik, sizeof(vec->ik)))) {
758 log("FAILURE: expected ik=%s", security_mode_expect_ik ? : "NULL");
759 OSMO_ASSERT(false);
760 }
761 if (((!!send_ck) != (!!security_mode_expect_ck))
762 || (security_mode_expect_ck
763 && strcmp(security_mode_expect_ck, osmo_hexdump_nospc(vec->ck, sizeof(vec->ck))))) {
764 log("FAILURE: expected ck=%s", security_mode_expect_ck ? : "NULL");
765 OSMO_ASSERT(false);
766 }
Neels Hofmeyrda21a522018-03-02 01:50:09 +0100767 return 0;
768}
769
770extern int msc_vlr_set_ciph_mode(void *msc_conn_ref, bool umts_aka, bool retrieve_imeisv);
771
Harald Welte71c51df2017-12-23 18:51:48 +0100772static int fake_vlr_tx_ciph_mode_cmd(void *msc_conn_ref, bool umts_aka, bool retrieve_imeisv)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100773{
Neels Hofmeyrda21a522018-03-02 01:50:09 +0100774 int rc;
775#ifndef BUILD_IU
776 /* If we built without support for IU, fake the IU part here. The root cause is that we don't
777 * have differing sets of expected outputs for --enable-iu and --disable-iu. */
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100778 struct gsm_subscriber_connection *conn = msc_conn_ref;
Neels Hofmeyrda21a522018-03-02 01:50:09 +0100779 if (conn->via_ran == RAN_UTRAN_IU) {
780 DEBUGP(DMM, "-> SECURITY MODE CONTROL %s\n", vlr_subscr_name(conn->vsub));
781 rc = __wrap_ranap_iu_tx_sec_mode_cmd(conn->iu.ue_ctx, &conn->vsub->last_tuple->vec,
782 0, 1);
783 } else
784#endif
785 rc = msc_vlr_set_ciph_mode(msc_conn_ref, umts_aka, retrieve_imeisv);
786 if (rc)
787 btw("ERROR sending ciphering mode command: rc=%d", rc);
788 return rc;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100789}
790
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200791void ms_sends_security_mode_complete()
792{
793 OSMO_ASSERT(g_conn);
794 OSMO_ASSERT(g_conn->via_ran == RAN_UTRAN_IU);
795 OSMO_ASSERT(g_conn->iu.ue_ctx);
796 msc_rx_sec_mode_compl(g_conn);
797}
798
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100799const struct timeval fake_time_start_time = { 123, 456 };
800
801void fake_time_start()
802{
803 osmo_gettimeofday_override_time = fake_time_start_time;
804 osmo_gettimeofday_override = true;
805 fake_time_passes(0, 0);
806}
807
Maxd8d1a9e2018-02-06 15:50:20 +0100808static void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100809{
810 talloc_report_full(msgb_ctx, stderr);
Neels Hofmeyr2c46e042017-11-18 23:29:24 +0100811 /* Expecting these to stick around in tall_bsc_ctx:
812full talloc report on 'msgb' (total 0 bytes in 1 blocks)
Harald Welte23466192018-02-14 00:19:06 +0100813talloc_total_blocks(tall_bsc_ctx) == 7
Harald Weltea3ab1de2018-01-24 15:17:06 +0100814full talloc report on 'subscr_conn_test_ctx' (total 2642 bytes in 8 blocks)
Neels Hofmeyr2c46e042017-11-18 23:29:24 +0100815 struct gsup_client contains 248 bytes in 1 blocks (ref 0) 0x61300000dee0
Harald Welte23466192018-02-14 00:19:06 +0100816 struct gsm_network contains 2023 bytes in 6 blocks (ref 0) 0x61700000fce0
Neels Hofmeyr2c46e042017-11-18 23:29:24 +0100817 struct vlr_instance contains 160 bytes in 1 blocks (ref 0) 0x611000009a60
818 no_gsup_server contains 15 bytes in 1 blocks (ref 0) 0x60b00000ade0
819 ../../../src/libosmocore/src/rate_ctr.c:199 contains 1552 bytes in 1 blocks (ref 0) 0x61b00001eae0
Neels Hofmeyr2c46e042017-11-18 23:29:24 +0100820 msgb contains 0 bytes in 1 blocks (ref 0) 0x60800000bf80
821 */
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100822 fprintf(stderr, "talloc_total_blocks(tall_bsc_ctx) == %zu\n",
823 talloc_total_blocks(tall_bsc_ctx));
824 if (talloc_total_blocks(tall_bsc_ctx) != expected_blocks)
825 talloc_report_full(tall_bsc_ctx, stderr);
826 fprintf(stderr, "\n");
827}
828
829static struct {
830 bool verbose;
831 int run_test_nr;
832} cmdline_opts = {
833 .verbose = false,
834 .run_test_nr = -1,
835};
836
837static void print_help(const char *program)
838{
839 printf("Usage:\n"
840 " %s [-v] [N [N...]]\n"
841 "Options:\n"
842 " -h --help show this text.\n"
843 " -v --verbose print source file and line numbers\n"
844 " N run only the Nth test (first test is N=1)\n",
845 program
846 );
847}
848
849static void handle_options(int argc, char **argv)
850{
851 while (1) {
852 int option_index = 0, c;
853 static struct option long_options[] = {
854 {"help", 0, 0, 'h'},
855 {"verbose", 1, 0, 'v'},
856 {0, 0, 0, 0}
857 };
858
859 c = getopt_long(argc, argv, "hv",
860 long_options, &option_index);
861 if (c == -1)
862 break;
863
864 switch (c) {
865 case 'h':
866 print_help(argv[0]);
867 exit(0);
868 case 'v':
869 cmdline_opts.verbose = true;
870 break;
871 default:
872 /* catch unknown options *as well as* missing arguments. */
873 fprintf(stderr, "Error in command line options. Exiting.\n");
874 exit(-1);
875 break;
876 }
877 }
878}
879
880void *msgb_ctx = NULL;
881
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100882static void run_tests(int nr)
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100883{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100884 int test_nr;
Max5e2e9bd2018-02-06 19:31:08 +0100885 nr--; /* arg's first test is 1, in here it's 0 */
886 for (test_nr = 0; msc_vlr_tests[test_nr]; test_nr++) {
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100887 if (nr >= 0 && test_nr != nr)
888 continue;
889
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100890 if (cmdline_opts.verbose)
891 fprintf(stderr, "(test nr %d)\n", test_nr + 1);
892
893 msc_vlr_tests[test_nr]();
894
895 if (cmdline_opts.verbose)
896 fprintf(stderr, "(test nr %d)\n", test_nr + 1);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100897
Harald Welte23466192018-02-14 00:19:06 +0100898 check_talloc(msgb_ctx, tall_bsc_ctx, 7);
Max29ce08a2018-02-06 18:46:57 +0100899 }
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100900}
901
Max5e60de62018-02-07 12:56:09 +0100902struct gsm_network *test_net(void *ctx)
903{
Neels Hofmeyr7f484202018-02-27 12:59:45 +0100904 struct gsm_network *net = gsm_network_init(ctx, mncc_recv);
Max5e60de62018-02-07 12:56:09 +0100905
906 net->gsup_server_addr_str = talloc_strdup(net, "no_gsup_server");
907 net->gsup_server_port = 0;
908
909 OSMO_ASSERT(msc_vlr_alloc(net) == 0);
910 OSMO_ASSERT(msc_vlr_start(net) == 0);
911 OSMO_ASSERT(net->vlr);
912 OSMO_ASSERT(net->vlr->gsup_client);
913
914 net->vlr->ops.tx_lu_acc = fake_vlr_tx_lu_acc;
915 net->vlr->ops.tx_lu_rej = fake_vlr_tx_lu_rej;
916 net->vlr->ops.tx_cm_serv_acc = fake_vlr_tx_cm_serv_acc;
917 net->vlr->ops.tx_cm_serv_rej = fake_vlr_tx_cm_serv_rej;
918 net->vlr->ops.tx_auth_req = fake_vlr_tx_auth_req;
919 net->vlr->ops.tx_auth_rej = fake_vlr_tx_auth_rej;
920 net->vlr->ops.set_ciph_mode = fake_vlr_tx_ciph_mode_cmd;
921
922 return net;
923}
924
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100925int main(int argc, char **argv)
926{
927 handle_options(argc, argv);
928
929 tall_bsc_ctx = talloc_named_const(NULL, 0, "subscr_conn_test_ctx");
930 msgb_ctx = msgb_talloc_ctx_init(tall_bsc_ctx, 0);
931 osmo_init_logging(&info);
932
933 _log_lines = cmdline_opts.verbose;
934
935 OSMO_ASSERT(osmo_stderr_target);
936 log_set_use_color(osmo_stderr_target, 0);
937 log_set_print_timestamp(osmo_stderr_target, 0);
938 log_set_print_filename(osmo_stderr_target, _log_lines? 1 : 0);
939 log_set_print_category(osmo_stderr_target, 1);
940
Neels Hofmeyr3f5b7802017-12-15 03:49:55 +0100941 if (cmdline_opts.verbose)
942 log_set_category_filter(osmo_stderr_target, DLSMS, 1, LOGL_DEBUG);
943
Max5e60de62018-02-07 12:56:09 +0100944 net = test_net(tall_bsc_ctx);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100945
946 osmo_fsm_log_addr(false);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100947
Max5e60de62018-02-07 12:56:09 +0100948 msc_subscr_conn_init();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100949
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200950 clear_vlr();
951
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100952 if (optind >= argc)
953 run_tests(-1);
954 else {
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100955 int arg;
956 long int nr;
957 for (arg = optind; arg < argc; arg++) {
Neels Hofmeyr9c848b52017-11-22 01:59:36 +0100958 errno = 0;
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100959 nr = strtol(argv[arg], NULL, 10);
960 if (errno) {
961 fprintf(stderr, "Invalid argument: %s\n",
962 argv[arg]);
963 exit(1);
964 }
965
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100966 run_tests(nr);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100967 }
968 }
969
970 printf("Done\n");
971
Harald Welte23466192018-02-14 00:19:06 +0100972 check_talloc(msgb_ctx, tall_bsc_ctx, 7);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100973 return 0;
974}