blob: a878be7840ff59fdf7a1c90f49b1101ece0179b6 [file] [log] [blame]
Neels Hofmeyr3dc2c642017-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>
33#include <openbsc/gsup_client.h>
34#include <openbsc/gsm_04_11.h>
35#include <openbsc/bsc_subscriber.h>
36#include <openbsc/debug.h>
37
38#include "msc_vlr_tests.h"
39
40bool _log_lines = false;
41
42struct gsm_network *net = NULL;
43
44struct gsm_bts *the_bts;
45
46const char *gsup_tx_expected = NULL;
47bool gsup_tx_confirmed;
48
49struct msgb *dtap_tx_expected = NULL;
50bool dtap_tx_confirmed;
51
52enum result_sent lu_result_sent;
53enum result_sent cm_service_result_sent;
54bool auth_request_sent;
55const char *auth_request_expect_rand;
56const char *auth_request_expect_autn;
57bool cipher_mode_cmd_sent;
58bool cipher_mode_cmd_sent_with_imeisv;
59
60struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex)
61{
62 struct msgb *msg = msgb_alloc(size, label);
63 unsigned char *rc;
64 msg->l2h = msg->head;
65 rc = msgb_put(msg, osmo_hexparse(hex, msg->head, msgb_tailroom(msg)));
66 OSMO_ASSERT(rc == msg->l2h);
67 return msg;
68}
69
70void dtap_expect_tx(const char *hex)
71{
72 OSMO_ASSERT(!dtap_tx_expected);
73 if (!hex)
74 return;
75 dtap_tx_expected = msgb_from_hex("dtap_tx_expected", 1024, hex);
76 dtap_tx_confirmed = false;
77}
78
79void dtap_expect_tx_ussd(char *ussd_text)
80{
81 uint8_t ussd_enc[128];
82 int len;
83 /* header */
84 char ussd_msg_hex[128] = "8b2a1c27a225020100302002013b301b04010f0416";
85
86 log("expecting USSD:\n %s", ussd_text);
87 /* append encoded USSD text */
88 gsm_7bit_encode_n_ussd(ussd_enc, sizeof(ussd_enc), ussd_text,
89 &len);
90 strncat(ussd_msg_hex, osmo_hexdump_nospc(ussd_enc, len),
91 sizeof(ussd_msg_hex) - strlen(ussd_msg_hex));
92 dtap_expect_tx(ussd_msg_hex);
93}
94
95int vlr_gsupc_read_cb(struct gsup_client *gsupc, struct msgb *msg);
96
97void gsup_rx(const char *rx_hex, const char *expect_tx_hex)
98{
99 int rc;
100 struct msgb *msg;
101 const char *label;
102
103 gsup_expect_tx(expect_tx_hex);
104
105 msg = msgb_from_hex("gsup", 1024, rx_hex);
106 label = osmo_gsup_message_type_name(msg->l2h[0]);
107 fprintf(stderr, "<-- GSUP rx %s: %s\n", label,
108 osmo_hexdump_nospc(msgb_l2(msg), msgb_l2len(msg)));
109 rc = vlr_gsupc_read_cb(net->vlr->gsup_client, msg);
110 fprintf(stderr, "<-- GSUP rx %s: vlr_gsupc_read_cb() returns %d\n",
111 label, rc);
112 if (expect_tx_hex)
113 OSMO_ASSERT(gsup_tx_confirmed);
114 talloc_free(msg);
115}
116
117bool conn_exists(struct gsm_subscriber_connection *conn)
118{
119 struct gsm_subscriber_connection *c;
120 llist_for_each_entry(c, &net->subscr_conns, entry) {
121 if (c == conn)
122 return true;
123 }
124 return false;
125}
126
127enum ran_type rx_from_ran = RAN_GERAN_A;
128
129struct gsm_subscriber_connection *conn_new(void)
130{
131 struct gsm_subscriber_connection *conn;
132 conn = msc_subscr_con_allocate(net);
133 conn->bts = the_bts;
134 conn->via_ran = rx_from_ran;
135 return conn;
136}
137
138struct gsm_subscriber_connection *g_conn = NULL;
139
140void rx_from_ms(struct msgb *msg)
141{
142 int rc;
143
144 struct gsm48_hdr *gh = msgb_l3(msg);
145 log("rx from MS: pdisc=0x%02x msg_type=0x%02x",
146 gh->proto_discr, gh->msg_type);
147
148 if (g_conn && !conn_exists(g_conn))
149 g_conn = NULL;
150
151 if (!g_conn) {
152 log("new conn");
153 g_conn = conn_new();
154 rc = net->bsc_api->compl_l3(g_conn, msg, 23);
155 if (rc == BSC_API_CONN_POL_REJECT) {
156 msc_subscr_con_free(g_conn);
157 g_conn = NULL;
158 }
159 } else {
160 if ((gsm48_hdr_pdisc(gh) == GSM48_PDISC_RR)
161 && (gsm48_hdr_msg_type(gh) == GSM48_MT_RR_CIPH_M_COMPL))
162 net->bsc_api->cipher_mode_compl(g_conn, msg, 0);
163 else
164 net->bsc_api->dtap(g_conn, 23, msg);
165 }
166
167 if (g_conn && !conn_exists(g_conn))
168 g_conn = NULL;
169}
170
171void ms_sends_msg(const char *hex)
172{
173 struct msgb *msg;
174
175 msg = msgb_from_hex("ms_sends_msg", 1024, hex);
176 msg->l1h = msg->l2h = msg->l3h = msg->data;
177 rx_from_ms(msg);
178 talloc_free(msg);
179}
180
181int ms_sends_msg_fake(uint8_t pdisc, uint8_t msg_type)
182{
183 int rc;
184 struct msgb *msg;
185 struct gsm48_hdr *gh;
186
187 msg = msgb_alloc(1024, "ms_sends_msg_fake");
188 msg->l1h = msg->l2h = msg->l3h = msg->data;
189
190 gh = (struct gsm48_hdr*)msgb_put(msg, sizeof(*gh));
191 gh->proto_discr = pdisc;
192 gh->msg_type = msg_type;
193 /* some amount of data, whatever */
194 msgb_put(msg, 123);
195
196 rc = gsm0408_dispatch(g_conn, msg);
197
198 talloc_free(msg);
199 return rc;
200}
201
202void thwart_rx_non_initial_requests()
203{
204 log("requests shall be thwarted");
205 OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_CC, GSM48_MT_CC_SETUP) == -EACCES);
206 OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_MM, 0x33 /* nonexistent */) == -EACCES);
207 OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_RR, GSM48_MT_RR_SYSINFO_1) == -EACCES);
208 OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_SMS, GSM411_MT_CP_DATA) == -EACCES);
209}
210
211void send_sms(struct vlr_subscr *receiver,
212 struct vlr_subscr *sender,
213 char *str)
214{
215 struct gsm_sms *sms = sms_from_text(receiver, sender, 0, str);
216 gsm411_send_sms_subscr(receiver, sms);
217}
218
219unsigned char next_rand_byte = 0;
220/* override, requires '-Wl,--wrap=RAND_bytes' */
221int __real_RAND_bytes(unsigned char *buf, int num);
222int __wrap_RAND_bytes(unsigned char *buf, int num)
223{
224 int i;
225 for (i = 0; i < num; i++)
226 buf[i] = next_rand_byte++;
227 return 1;
228}
229
230/* override, requires '-Wl,--wrap=gsm340_gen_scts' */
231void __real_gsm340_gen_scts(uint8_t *scts, time_t time);
232void __wrap_gsm340_gen_scts(uint8_t *scts, time_t time)
233{
234 /* Remove the time to encode for deterministic test results */
235 __real_gsm340_gen_scts(scts, 0);
236}
237
238const char *paging_expecting_imsi = NULL;
239uint32_t paging_expecting_tmsi;
240bool paging_sent;
241bool paging_stopped;
242
243void paging_expect_imsi(const char *imsi)
244{
245 paging_expecting_imsi = imsi;
246 paging_expecting_tmsi = GSM_RESERVED_TMSI;
247}
248
249void paging_expect_tmsi(uint32_t tmsi)
250{
251 paging_expecting_tmsi = tmsi;
252 paging_expecting_imsi = NULL;
253}
254
255/* override, requires '-Wl,--wrap=paging_request' */
256int __real_paging_request(struct gsm_network *network, struct bsc_subscr *sub,
257 int type, gsm_cbfn *cbfn, void *data);
258int __wrap_paging_request(struct gsm_network *network, struct bsc_subscr *sub,
259 int type, gsm_cbfn *cbfn, void *data)
260{
261 log("BTS/BSC sends out paging request to %s for channel type %d",
262 bsc_subscr_name(sub), type);
263 OSMO_ASSERT(paging_expecting_imsi || (paging_expecting_tmsi != GSM_RESERVED_TMSI));
264 if (paging_expecting_imsi)
265 VERBOSE_ASSERT(strcmp(paging_expecting_imsi, sub->imsi), == 0, "%d");
266 if (paging_expecting_tmsi != GSM_RESERVED_TMSI)
267 VERBOSE_ASSERT(paging_expecting_tmsi, == sub->tmsi, "0x%08x");
268 paging_sent = true;
269 paging_stopped = false;
270 return 1;
271}
272
273/* override, requires '-Wl,--wrap=paging_request_stop' */
274void __real_paging_request_stop(struct gsm_bts *_bts,
275 struct vlr_subscr *vsub,
276 struct gsm_subscriber_connection *conn,
277 struct msgb *msg);
278void __wrap_paging_request_stop(struct gsm_bts *_bts,
279 struct vlr_subscr *vsub,
280 struct gsm_subscriber_connection *conn,
281 struct msgb *msg)
282{
283 paging_stopped = true;
284}
285
286void clear_vlr()
287{
288 struct vlr_subscr *vsub, *n;
289 llist_for_each_entry_safe(vsub, n, &net->vlr->subscribers, list) {
290 vlr_subscr_free(vsub);
291 }
292
293 net->authentication_required = false;
294 net->a5_encryption = VLR_CIPH_NONE;
295 net->vlr->cfg.check_imei_rqd = false;
296 net->vlr->cfg.assign_tmsi = false;
Neels Hofmeyr0e255582017-07-18 15:39:27 +0200297 net->vlr->cfg.retrieve_imeisv_early = false;
298 net->vlr->cfg.retrieve_imeisv_ciphered = false;
Neels Hofmeyr3dc2c642017-01-25 15:04:16 +0100299
300 rx_from_ran = RAN_GERAN_A;
301 auth_request_sent = false;
302 auth_request_expect_rand = NULL;
303 auth_request_expect_autn = NULL;
304
305 next_rand_byte = 0;
306
307 osmo_gettimeofday_override = false;
308}
309
310static struct log_info_cat test_categories[] = {
311 [DMSC] = {
312 .name = "DMSC",
313 .description = "Mobile Switching Center",
314 .enabled = 1, .loglevel = LOGL_DEBUG,
315 },
316 [DRLL] = {
317 .name = "DRLL",
318 .description = "A-bis Radio Link Layer (RLL)",
319 .enabled = 1, .loglevel = LOGL_DEBUG,
320 },
321 [DMM] = {
322 .name = "DMM",
323 .description = "Layer3 Mobility Management (MM)",
324 .enabled = 1, .loglevel = LOGL_DEBUG,
325 },
326 [DRR] = {
327 .name = "DRR",
328 .description = "Layer3 Radio Resource (RR)",
329 .enabled = 1, .loglevel = LOGL_DEBUG,
330 },
331 [DCC] = {
332 .name = "DCC",
333 .description = "Layer3 Call Control (CC)",
334 .enabled = 1, .loglevel = LOGL_NOTICE,
335 },
336 [DMM] = {
337 .name = "DMM",
338 .description = "Layer3 Mobility Management (MM)",
339 .enabled = 1, .loglevel = LOGL_DEBUG,
340 },
341 [DVLR] = {
342 .name = "DVLR",
343 .description = "Visitor Location Register",
344 .enabled = 1, .loglevel = LOGL_DEBUG,
345 },
346 [DREF] = {
347 .name = "DREF",
348 .description = "Reference Counting",
349 .enabled = 1, .loglevel = LOGL_DEBUG,
350 },
351};
352
353static struct log_info info = {
354 .cat = test_categories,
355 .num_cat = ARRAY_SIZE(test_categories),
356};
357
358extern void *tall_bsc_ctx;
359
360int fake_mncc_recv(struct gsm_network *net, struct msgb *msg)
361{
362 fprintf(stderr, "rx MNCC\n");
363 return 0;
364}
365
366/* override, requires '-Wl,--wrap=gsup_client_create' */
367struct gsup_client *
368__real_gsup_client_create(const char *ip_addr, unsigned int tcp_port,
369 gsup_client_read_cb_t read_cb,
370 struct oap_client_config *oap_config);
371struct gsup_client *
372__wrap_gsup_client_create(const char *ip_addr, unsigned int tcp_port,
373 gsup_client_read_cb_t read_cb,
374 struct oap_client_config *oap_config)
375{
376 struct gsup_client *gsupc;
377 gsupc = talloc_zero(tall_bsc_ctx, struct gsup_client);
378 OSMO_ASSERT(gsupc);
379 return gsupc;
380}
381
382/* override, requires '-Wl,--wrap=gsup_client_send' */
383int __real_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg);
384int __wrap_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
385{
386 const char *is = osmo_hexdump_nospc(msg->data, msg->len);
387 fprintf(stderr, "GSUP --> HLR: %s: %s\n",
388 osmo_gsup_message_type_name(msg->data[0]), is);
389
390 OSMO_ASSERT(gsup_tx_expected);
391 if (strcmp(gsup_tx_expected, is)) {
392 fprintf(stderr, "Mismatch! Expected:\n%s\n", gsup_tx_expected);
393 abort();
394 }
395
396 talloc_free(msg);
397 gsup_tx_confirmed = true;
398 gsup_tx_expected = NULL;
399 return 0;
400}
401
402/* override, requires '-Wl,--wrap=gsm0808_submit_dtap' */
403int __real_gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
404 struct msgb *msg, int link_id, int allow_sacch);
405int __wrap_gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
406 struct msgb *msg, int link_id, int allow_sacch)
407{
408 btw("DTAP --> MS: %s", osmo_hexdump_nospc(msg->data, msg->len));
409
410 OSMO_ASSERT(dtap_tx_expected);
411 if (msg->len != dtap_tx_expected->len
412 || memcmp(msg->data, dtap_tx_expected->data, msg->len)) {
413 fprintf(stderr, "Mismatch! Expected:\n%s\n",
414 osmo_hexdump_nospc(dtap_tx_expected->data,
415 dtap_tx_expected->len));
416 abort();
417 }
418
419 btw("DTAP matches expected message");
420
421 talloc_free(msg);
422 dtap_tx_confirmed = true;
423 talloc_free(dtap_tx_expected);
424 dtap_tx_expected = NULL;
425 return 0;
426}
427
428static int fake_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi)
429{
430 struct gsm_subscriber_connection *conn = msc_conn_ref;
431 if (send_tmsi == GSM_RESERVED_TMSI)
432 btw("sending LU Accept for %s", vlr_subscr_name(conn->vsub));
433 else
434 btw("sending LU Accept for %s, with TMSI 0x%08x",
435 vlr_subscr_name(conn->vsub), send_tmsi);
436 lu_result_sent |= RES_ACCEPT;
437 return 0;
438}
439
440static int fake_vlr_tx_lu_rej(void *msc_conn_ref, uint8_t cause)
441{
442 struct gsm_subscriber_connection *conn = msc_conn_ref;
443 btw("sending LU Reject for %s, cause %u", vlr_subscr_name(conn->vsub), cause);
444 lu_result_sent |= RES_REJECT;
445 return 0;
446}
447
448static int fake_vlr_tx_cm_serv_acc(void *msc_conn_ref)
449{
450 struct gsm_subscriber_connection *conn = msc_conn_ref;
451 btw("sending CM Service Accept for %s", vlr_subscr_name(conn->vsub));
452 cm_service_result_sent |= RES_ACCEPT;
453 return 0;
454}
455
456static int fake_vlr_tx_cm_serv_rej(void *msc_conn_ref,
457 enum vlr_proc_arq_result result)
458{
459 struct gsm_subscriber_connection *conn = msc_conn_ref;
460 btw("sending CM Service Reject for %s, result %s",
461 vlr_subscr_name(conn->vsub),
462 vlr_proc_arq_result_name(result));
463 cm_service_result_sent |= RES_REJECT;
464 return 0;
465}
466
467static int fake_vlr_tx_auth_req(void *msc_conn_ref, struct gsm_auth_tuple *at,
468 bool send_autn)
469{
470 struct gsm_subscriber_connection *conn = msc_conn_ref;
471 char *hex;
472 bool ok = true;
473 btw("sending %s Auth Request for %s: tuple use_count=%d key_seq=%d auth_types=0x%x and...",
474 send_autn? "UMTS" : "GSM", vlr_subscr_name(conn->vsub),
475 at->use_count, at->key_seq, at->vec.auth_types);
476
477 hex = osmo_hexdump_nospc((void*)&at->vec.rand, sizeof(at->vec.rand));
478 btw("...rand=%s", hex);
479 if (!auth_request_expect_rand
480 || strcmp(hex, auth_request_expect_rand) != 0) {
481 ok = false;
482 log("FAILURE: expected rand=%s",
483 auth_request_expect_rand ? auth_request_expect_rand : "-");
484 }
485
486 if (send_autn) {
487 hex = osmo_hexdump_nospc((void*)&at->vec.autn, sizeof(at->vec.autn));
488 btw("...autn=%s", hex);
489 if (!auth_request_expect_autn
490 || strcmp(hex, auth_request_expect_autn) != 0) {
491 ok = false;
492 log("FAILURE: expected autn=%s",
493 auth_request_expect_autn ? auth_request_expect_autn : "-");
494 }
495 } else if (auth_request_expect_autn) {
496 ok = false;
497 log("FAILURE: no AUTN sent, expected AUTN = %s",
498 auth_request_expect_autn);
499 }
500
501 if (send_autn)
502 btw("...expecting res=%s",
503 osmo_hexdump_nospc((void*)&at->vec.res, at->vec.res_len));
504 else
505 btw("...expecting sres=%s",
506 osmo_hexdump_nospc((void*)&at->vec.sres, sizeof(at->vec.sres)));
507
508 auth_request_sent = ok;
509 return 0;
510}
511
512static int fake_vlr_tx_auth_rej(void *msc_conn_ref)
513{
514 struct gsm_subscriber_connection *conn = msc_conn_ref;
515 btw("sending Auth Reject for %s", vlr_subscr_name(conn->vsub));
516 return 0;
517}
518
519static int fake_vlr_tx_ciph_mode_cmd(void *msc_conn_ref, enum vlr_ciph ciph,
520 bool retrieve_imeisv)
521{
522 /* FIXME: we actually would like to see the message bytes checked here,
523 * not possible while msc_vlr_set_ciph_mode() calls
524 * gsm0808_cipher_mode() directly. When the MSCSPLIT is ready, check
525 * the tx bytes in the sense of dtap_expect_tx() above. */
526 struct gsm_subscriber_connection *conn = msc_conn_ref;
527 btw("sending Ciphering Mode Command for %s: cipher=%s kc=%s"
528 " retrieve_imeisv=%d",
529 vlr_subscr_name(conn->vsub),
530 vlr_ciph_name(conn->network->a5_encryption),
531 osmo_hexdump_nospc(conn->vsub->last_tuple->vec.kc, 8),
532 retrieve_imeisv);
533 cipher_mode_cmd_sent = true;
534 cipher_mode_cmd_sent_with_imeisv = retrieve_imeisv;
535 return 0;
536}
537
538const struct timeval fake_time_start_time = { 123, 456 };
539
540void fake_time_start()
541{
542 osmo_gettimeofday_override_time = fake_time_start_time;
543 osmo_gettimeofday_override = true;
544 fake_time_passes(0, 0);
545}
546
547void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks)
548{
549 talloc_report_full(msgb_ctx, stderr);
550 fprintf(stderr, "talloc_total_blocks(tall_bsc_ctx) == %zu\n",
551 talloc_total_blocks(tall_bsc_ctx));
552 if (talloc_total_blocks(tall_bsc_ctx) != expected_blocks)
553 talloc_report_full(tall_bsc_ctx, stderr);
554 fprintf(stderr, "\n");
555}
556
557static struct {
558 bool verbose;
559 int run_test_nr;
560} cmdline_opts = {
561 .verbose = false,
562 .run_test_nr = -1,
563};
564
565static void print_help(const char *program)
566{
567 printf("Usage:\n"
568 " %s [-v] [N [N...]]\n"
569 "Options:\n"
570 " -h --help show this text.\n"
571 " -v --verbose print source file and line numbers\n"
572 " N run only the Nth test (first test is N=1)\n",
573 program
574 );
575}
576
577static void handle_options(int argc, char **argv)
578{
579 while (1) {
580 int option_index = 0, c;
581 static struct option long_options[] = {
582 {"help", 0, 0, 'h'},
583 {"verbose", 1, 0, 'v'},
584 {0, 0, 0, 0}
585 };
586
587 c = getopt_long(argc, argv, "hv",
588 long_options, &option_index);
589 if (c == -1)
590 break;
591
592 switch (c) {
593 case 'h':
594 print_help(argv[0]);
595 exit(0);
596 case 'v':
597 cmdline_opts.verbose = true;
598 break;
599 default:
600 /* catch unknown options *as well as* missing arguments. */
601 fprintf(stderr, "Error in command line options. Exiting.\n");
602 exit(-1);
603 break;
604 }
605 }
606}
607
608void *msgb_ctx = NULL;
609
610void run_tests(int nr)
611{
612 int test_nr;
613 nr --; /* arg's first test is 1, in here it's 0 */
614 for (test_nr = 0; msc_vlr_tests[test_nr]; test_nr ++) {
615 if (nr >= 0 && test_nr != nr)
616 continue;
617
618 if (cmdline_opts.verbose)
619 fprintf(stderr, "(test nr %d)\n", test_nr + 1);
620
621 msc_vlr_tests[test_nr]();
622
623 if (cmdline_opts.verbose)
624 fprintf(stderr, "(test nr %d)\n", test_nr + 1);
625
626 check_talloc(msgb_ctx, tall_bsc_ctx, 75);
627 } while(0);
628}
629
630int main(int argc, char **argv)
631{
632 handle_options(argc, argv);
633
634 tall_bsc_ctx = talloc_named_const(NULL, 0, "subscr_conn_test_ctx");
635 msgb_ctx = msgb_talloc_ctx_init(tall_bsc_ctx, 0);
636 osmo_init_logging(&info);
637
638 _log_lines = cmdline_opts.verbose;
639
640 OSMO_ASSERT(osmo_stderr_target);
641 log_set_use_color(osmo_stderr_target, 0);
642 log_set_print_timestamp(osmo_stderr_target, 0);
643 log_set_print_filename(osmo_stderr_target, _log_lines? 1 : 0);
644 log_set_print_category(osmo_stderr_target, 1);
645
646 net = gsm_network_init(tall_bsc_ctx, 1, 1, fake_mncc_recv);
647 bsc_api_init(net, msc_bsc_api());
648 the_bts = gsm_bts_alloc(net);
649 net->gsup_server_addr_str = talloc_strdup(net, "no_gsup_server");
650 net->gsup_server_port = 0;
651
652 osmo_fsm_log_addr(false);
653 OSMO_ASSERT(msc_vlr_alloc(net) == 0);
654 OSMO_ASSERT(msc_vlr_start(net) == 0);
655 OSMO_ASSERT(net->vlr);
656 OSMO_ASSERT(net->vlr->gsup_client);
657 msc_subscr_conn_init();
658
659 net->vlr->ops.tx_lu_acc = fake_vlr_tx_lu_acc;
660 net->vlr->ops.tx_lu_rej = fake_vlr_tx_lu_rej;
661 net->vlr->ops.tx_cm_serv_acc = fake_vlr_tx_cm_serv_acc;
662 net->vlr->ops.tx_cm_serv_rej = fake_vlr_tx_cm_serv_rej;
663 net->vlr->ops.tx_auth_req = fake_vlr_tx_auth_req;
664 net->vlr->ops.tx_auth_rej = fake_vlr_tx_auth_rej;
665 net->vlr->ops.set_ciph_mode = fake_vlr_tx_ciph_mode_cmd;
666
667 if (optind >= argc)
668 run_tests(-1);
669 else {
670 int arg;
671 long int nr;
672 for (arg = optind; arg < argc; arg++) {
673 nr = strtol(argv[arg], NULL, 10);
674 if (errno) {
675 fprintf(stderr, "Invalid argument: %s\n",
676 argv[arg]);
677 exit(1);
678 }
679
680 run_tests(nr);
681 }
682 }
683
684 printf("Done\n");
685
686 talloc_free(the_bts);
687
688 check_talloc(msgb_ctx, tall_bsc_ctx, 9);
689 return 0;
690}