blob: a40f1e5c6e3371492bc494d982a713f018d21bb7 [file] [log] [blame]
Neels Hofmeyr6bd54472017-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
Neels Hofmeyrce67be12017-05-08 15:12:20 +0200255/* override, requires '-Wl,--wrap=msc_fake_paging_request' */
256int __real_msc_fake_paging_request(struct vlr_subscr *vsub);
257int __wrap_msc_fake_paging_request(struct vlr_subscr *vsub)
Neels Hofmeyr6bd54472017-01-25 15:04:16 +0100258{
Neels Hofmeyrce67be12017-05-08 15:12:20 +0200259 log("BTS/BSC sends out paging request to %s",
260 vlr_subscr_name(vsub));
Neels Hofmeyr6bd54472017-01-25 15:04:16 +0100261 OSMO_ASSERT(paging_expecting_imsi || (paging_expecting_tmsi != GSM_RESERVED_TMSI));
262 if (paging_expecting_imsi)
Neels Hofmeyrce67be12017-05-08 15:12:20 +0200263 VERBOSE_ASSERT(strcmp(paging_expecting_imsi, vsub->imsi), == 0, "%d");
Neels Hofmeyr6bd54472017-01-25 15:04:16 +0100264 if (paging_expecting_tmsi != GSM_RESERVED_TMSI)
Neels Hofmeyrce67be12017-05-08 15:12:20 +0200265 VERBOSE_ASSERT(paging_expecting_tmsi, == vsub->tmsi, "0x%08x");
Neels Hofmeyr6bd54472017-01-25 15:04:16 +0100266 paging_sent = true;
267 paging_stopped = false;
268 return 1;
269}
270
Neels Hofmeyrce67be12017-05-08 15:12:20 +0200271/* override, requires '-Wl,--wrap=msc_fake_paging_request_stop' */
272void __real_msc_fake_paging_request_stop(struct vlr_subscr *vsub);
273void __wrap_msc_fake_paging_request_stop(struct vlr_subscr *vsub)
Neels Hofmeyr6bd54472017-01-25 15:04:16 +0100274{
275 paging_stopped = true;
276}
277
278void clear_vlr()
279{
280 struct vlr_subscr *vsub, *n;
281 llist_for_each_entry_safe(vsub, n, &net->vlr->subscribers, list) {
282 vlr_subscr_free(vsub);
283 }
284
285 net->authentication_required = false;
286 net->a5_encryption = VLR_CIPH_NONE;
287 net->vlr->cfg.check_imei_rqd = false;
288 net->vlr->cfg.assign_tmsi = false;
Neels Hofmeyrfa68ccd2017-07-18 15:39:27 +0200289 net->vlr->cfg.retrieve_imeisv_early = false;
290 net->vlr->cfg.retrieve_imeisv_ciphered = false;
Neels Hofmeyr6bd54472017-01-25 15:04:16 +0100291
292 rx_from_ran = RAN_GERAN_A;
293 auth_request_sent = false;
294 auth_request_expect_rand = NULL;
295 auth_request_expect_autn = NULL;
296
297 next_rand_byte = 0;
298
299 osmo_gettimeofday_override = false;
300}
301
302static struct log_info_cat test_categories[] = {
303 [DMSC] = {
304 .name = "DMSC",
305 .description = "Mobile Switching Center",
306 .enabled = 1, .loglevel = LOGL_DEBUG,
307 },
308 [DRLL] = {
309 .name = "DRLL",
310 .description = "A-bis Radio Link Layer (RLL)",
311 .enabled = 1, .loglevel = LOGL_DEBUG,
312 },
313 [DMM] = {
314 .name = "DMM",
315 .description = "Layer3 Mobility Management (MM)",
316 .enabled = 1, .loglevel = LOGL_DEBUG,
317 },
318 [DRR] = {
319 .name = "DRR",
320 .description = "Layer3 Radio Resource (RR)",
321 .enabled = 1, .loglevel = LOGL_DEBUG,
322 },
323 [DCC] = {
324 .name = "DCC",
325 .description = "Layer3 Call Control (CC)",
326 .enabled = 1, .loglevel = LOGL_NOTICE,
327 },
328 [DMM] = {
329 .name = "DMM",
330 .description = "Layer3 Mobility Management (MM)",
331 .enabled = 1, .loglevel = LOGL_DEBUG,
332 },
333 [DVLR] = {
334 .name = "DVLR",
335 .description = "Visitor Location Register",
336 .enabled = 1, .loglevel = LOGL_DEBUG,
337 },
338 [DREF] = {
339 .name = "DREF",
340 .description = "Reference Counting",
341 .enabled = 1, .loglevel = LOGL_DEBUG,
342 },
343};
344
345static struct log_info info = {
346 .cat = test_categories,
347 .num_cat = ARRAY_SIZE(test_categories),
348};
349
350extern void *tall_bsc_ctx;
351
352int fake_mncc_recv(struct gsm_network *net, struct msgb *msg)
353{
354 fprintf(stderr, "rx MNCC\n");
355 return 0;
356}
357
358/* override, requires '-Wl,--wrap=gsup_client_create' */
359struct gsup_client *
360__real_gsup_client_create(const char *ip_addr, unsigned int tcp_port,
361 gsup_client_read_cb_t read_cb,
362 struct oap_client_config *oap_config);
363struct gsup_client *
364__wrap_gsup_client_create(const char *ip_addr, unsigned int tcp_port,
365 gsup_client_read_cb_t read_cb,
366 struct oap_client_config *oap_config)
367{
368 struct gsup_client *gsupc;
369 gsupc = talloc_zero(tall_bsc_ctx, struct gsup_client);
370 OSMO_ASSERT(gsupc);
371 return gsupc;
372}
373
374/* override, requires '-Wl,--wrap=gsup_client_send' */
375int __real_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg);
376int __wrap_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg)
377{
378 const char *is = osmo_hexdump_nospc(msg->data, msg->len);
379 fprintf(stderr, "GSUP --> HLR: %s: %s\n",
380 osmo_gsup_message_type_name(msg->data[0]), is);
381
382 OSMO_ASSERT(gsup_tx_expected);
383 if (strcmp(gsup_tx_expected, is)) {
384 fprintf(stderr, "Mismatch! Expected:\n%s\n", gsup_tx_expected);
385 abort();
386 }
387
388 talloc_free(msg);
389 gsup_tx_confirmed = true;
390 gsup_tx_expected = NULL;
391 return 0;
392}
393
394/* override, requires '-Wl,--wrap=gsm0808_submit_dtap' */
395int __real_gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
396 struct msgb *msg, int link_id, int allow_sacch);
397int __wrap_gsm0808_submit_dtap(struct gsm_subscriber_connection *conn,
398 struct msgb *msg, int link_id, int allow_sacch)
399{
400 btw("DTAP --> MS: %s", osmo_hexdump_nospc(msg->data, msg->len));
401
402 OSMO_ASSERT(dtap_tx_expected);
403 if (msg->len != dtap_tx_expected->len
404 || memcmp(msg->data, dtap_tx_expected->data, msg->len)) {
405 fprintf(stderr, "Mismatch! Expected:\n%s\n",
406 osmo_hexdump_nospc(dtap_tx_expected->data,
407 dtap_tx_expected->len));
408 abort();
409 }
410
411 btw("DTAP matches expected message");
412
413 talloc_free(msg);
414 dtap_tx_confirmed = true;
415 talloc_free(dtap_tx_expected);
416 dtap_tx_expected = NULL;
417 return 0;
418}
419
420static int fake_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi)
421{
422 struct gsm_subscriber_connection *conn = msc_conn_ref;
423 if (send_tmsi == GSM_RESERVED_TMSI)
424 btw("sending LU Accept for %s", vlr_subscr_name(conn->vsub));
425 else
426 btw("sending LU Accept for %s, with TMSI 0x%08x",
427 vlr_subscr_name(conn->vsub), send_tmsi);
428 lu_result_sent |= RES_ACCEPT;
429 return 0;
430}
431
432static int fake_vlr_tx_lu_rej(void *msc_conn_ref, uint8_t cause)
433{
434 struct gsm_subscriber_connection *conn = msc_conn_ref;
435 btw("sending LU Reject for %s, cause %u", vlr_subscr_name(conn->vsub), cause);
436 lu_result_sent |= RES_REJECT;
437 return 0;
438}
439
440static int fake_vlr_tx_cm_serv_acc(void *msc_conn_ref)
441{
442 struct gsm_subscriber_connection *conn = msc_conn_ref;
443 btw("sending CM Service Accept for %s", vlr_subscr_name(conn->vsub));
444 cm_service_result_sent |= RES_ACCEPT;
445 return 0;
446}
447
448static int fake_vlr_tx_cm_serv_rej(void *msc_conn_ref,
449 enum vlr_proc_arq_result result)
450{
451 struct gsm_subscriber_connection *conn = msc_conn_ref;
452 btw("sending CM Service Reject for %s, result %s",
453 vlr_subscr_name(conn->vsub),
454 vlr_proc_arq_result_name(result));
455 cm_service_result_sent |= RES_REJECT;
456 return 0;
457}
458
459static int fake_vlr_tx_auth_req(void *msc_conn_ref, struct gsm_auth_tuple *at,
460 bool send_autn)
461{
462 struct gsm_subscriber_connection *conn = msc_conn_ref;
463 char *hex;
464 bool ok = true;
465 btw("sending %s Auth Request for %s: tuple use_count=%d key_seq=%d auth_types=0x%x and...",
466 send_autn? "UMTS" : "GSM", vlr_subscr_name(conn->vsub),
467 at->use_count, at->key_seq, at->vec.auth_types);
468
469 hex = osmo_hexdump_nospc((void*)&at->vec.rand, sizeof(at->vec.rand));
470 btw("...rand=%s", hex);
471 if (!auth_request_expect_rand
472 || strcmp(hex, auth_request_expect_rand) != 0) {
473 ok = false;
474 log("FAILURE: expected rand=%s",
475 auth_request_expect_rand ? auth_request_expect_rand : "-");
476 }
477
478 if (send_autn) {
479 hex = osmo_hexdump_nospc((void*)&at->vec.autn, sizeof(at->vec.autn));
480 btw("...autn=%s", hex);
481 if (!auth_request_expect_autn
482 || strcmp(hex, auth_request_expect_autn) != 0) {
483 ok = false;
484 log("FAILURE: expected autn=%s",
485 auth_request_expect_autn ? auth_request_expect_autn : "-");
486 }
487 } else if (auth_request_expect_autn) {
488 ok = false;
489 log("FAILURE: no AUTN sent, expected AUTN = %s",
490 auth_request_expect_autn);
491 }
492
493 if (send_autn)
494 btw("...expecting res=%s",
495 osmo_hexdump_nospc((void*)&at->vec.res, at->vec.res_len));
496 else
497 btw("...expecting sres=%s",
498 osmo_hexdump_nospc((void*)&at->vec.sres, sizeof(at->vec.sres)));
499
500 auth_request_sent = ok;
501 return 0;
502}
503
504static int fake_vlr_tx_auth_rej(void *msc_conn_ref)
505{
506 struct gsm_subscriber_connection *conn = msc_conn_ref;
507 btw("sending Auth Reject for %s", vlr_subscr_name(conn->vsub));
508 return 0;
509}
510
511static int fake_vlr_tx_ciph_mode_cmd(void *msc_conn_ref, enum vlr_ciph ciph,
512 bool retrieve_imeisv)
513{
514 /* FIXME: we actually would like to see the message bytes checked here,
515 * not possible while msc_vlr_set_ciph_mode() calls
516 * gsm0808_cipher_mode() directly. When the MSCSPLIT is ready, check
517 * the tx bytes in the sense of dtap_expect_tx() above. */
518 struct gsm_subscriber_connection *conn = msc_conn_ref;
519 btw("sending Ciphering Mode Command for %s: cipher=%s kc=%s"
520 " retrieve_imeisv=%d",
521 vlr_subscr_name(conn->vsub),
522 vlr_ciph_name(conn->network->a5_encryption),
523 osmo_hexdump_nospc(conn->vsub->last_tuple->vec.kc, 8),
524 retrieve_imeisv);
525 cipher_mode_cmd_sent = true;
526 cipher_mode_cmd_sent_with_imeisv = retrieve_imeisv;
527 return 0;
528}
529
530const struct timeval fake_time_start_time = { 123, 456 };
531
532void fake_time_start()
533{
534 osmo_gettimeofday_override_time = fake_time_start_time;
535 osmo_gettimeofday_override = true;
536 fake_time_passes(0, 0);
537}
538
539void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks)
540{
541 talloc_report_full(msgb_ctx, stderr);
542 fprintf(stderr, "talloc_total_blocks(tall_bsc_ctx) == %zu\n",
543 talloc_total_blocks(tall_bsc_ctx));
544 if (talloc_total_blocks(tall_bsc_ctx) != expected_blocks)
545 talloc_report_full(tall_bsc_ctx, stderr);
546 fprintf(stderr, "\n");
547}
548
549static struct {
550 bool verbose;
551 int run_test_nr;
552} cmdline_opts = {
553 .verbose = false,
554 .run_test_nr = -1,
555};
556
557static void print_help(const char *program)
558{
559 printf("Usage:\n"
560 " %s [-v] [N [N...]]\n"
561 "Options:\n"
562 " -h --help show this text.\n"
563 " -v --verbose print source file and line numbers\n"
564 " N run only the Nth test (first test is N=1)\n",
565 program
566 );
567}
568
569static void handle_options(int argc, char **argv)
570{
571 while (1) {
572 int option_index = 0, c;
573 static struct option long_options[] = {
574 {"help", 0, 0, 'h'},
575 {"verbose", 1, 0, 'v'},
576 {0, 0, 0, 0}
577 };
578
579 c = getopt_long(argc, argv, "hv",
580 long_options, &option_index);
581 if (c == -1)
582 break;
583
584 switch (c) {
585 case 'h':
586 print_help(argv[0]);
587 exit(0);
588 case 'v':
589 cmdline_opts.verbose = true;
590 break;
591 default:
592 /* catch unknown options *as well as* missing arguments. */
593 fprintf(stderr, "Error in command line options. Exiting.\n");
594 exit(-1);
595 break;
596 }
597 }
598}
599
600void *msgb_ctx = NULL;
601
602void run_tests(int nr)
603{
604 int test_nr;
605 nr --; /* arg's first test is 1, in here it's 0 */
606 for (test_nr = 0; msc_vlr_tests[test_nr]; test_nr ++) {
607 if (nr >= 0 && test_nr != nr)
608 continue;
609
610 if (cmdline_opts.verbose)
611 fprintf(stderr, "(test nr %d)\n", test_nr + 1);
612
613 msc_vlr_tests[test_nr]();
614
615 if (cmdline_opts.verbose)
616 fprintf(stderr, "(test nr %d)\n", test_nr + 1);
617
618 check_talloc(msgb_ctx, tall_bsc_ctx, 75);
619 } while(0);
620}
621
622int main(int argc, char **argv)
623{
624 handle_options(argc, argv);
625
626 tall_bsc_ctx = talloc_named_const(NULL, 0, "subscr_conn_test_ctx");
627 msgb_ctx = msgb_talloc_ctx_init(tall_bsc_ctx, 0);
628 osmo_init_logging(&info);
629
630 _log_lines = cmdline_opts.verbose;
631
632 OSMO_ASSERT(osmo_stderr_target);
633 log_set_use_color(osmo_stderr_target, 0);
634 log_set_print_timestamp(osmo_stderr_target, 0);
635 log_set_print_filename(osmo_stderr_target, _log_lines? 1 : 0);
636 log_set_print_category(osmo_stderr_target, 1);
637
638 net = gsm_network_init(tall_bsc_ctx, 1, 1, fake_mncc_recv);
639 bsc_api_init(net, msc_bsc_api());
640 the_bts = gsm_bts_alloc(net);
641 net->gsup_server_addr_str = talloc_strdup(net, "no_gsup_server");
642 net->gsup_server_port = 0;
643
644 osmo_fsm_log_addr(false);
645 OSMO_ASSERT(msc_vlr_alloc(net) == 0);
646 OSMO_ASSERT(msc_vlr_start(net) == 0);
647 OSMO_ASSERT(net->vlr);
648 OSMO_ASSERT(net->vlr->gsup_client);
649 msc_subscr_conn_init();
650
651 net->vlr->ops.tx_lu_acc = fake_vlr_tx_lu_acc;
652 net->vlr->ops.tx_lu_rej = fake_vlr_tx_lu_rej;
653 net->vlr->ops.tx_cm_serv_acc = fake_vlr_tx_cm_serv_acc;
654 net->vlr->ops.tx_cm_serv_rej = fake_vlr_tx_cm_serv_rej;
655 net->vlr->ops.tx_auth_req = fake_vlr_tx_auth_req;
656 net->vlr->ops.tx_auth_rej = fake_vlr_tx_auth_rej;
657 net->vlr->ops.set_ciph_mode = fake_vlr_tx_ciph_mode_cmd;
658
659 if (optind >= argc)
660 run_tests(-1);
661 else {
662 int arg;
663 long int nr;
664 for (arg = optind; arg < argc; arg++) {
665 nr = strtol(argv[arg], NULL, 10);
666 if (errno) {
667 fprintf(stderr, "Invalid argument: %s\n",
668 argv[arg]);
669 exit(1);
670 }
671
672 run_tests(nr);
673 }
674 }
675
676 printf("Done\n");
677
678 talloc_free(the_bts);
679
680 check_talloc(msgb_ctx, tall_bsc_ctx, 9);
681 return 0;
682}