int main(int argc, char **argv) { int quit = 0; int rc; char const * home; size_t len; const char osmocomcfg[] = ".osmocom/bb/mobile.cfg"; char *config_file = NULL; printf("%s\n", openbsc_copyright); srand(time(NULL)); INIT_LLIST_HEAD(&ms_list); log_init(&log_info, NULL); stderr_target = log_target_create_stderr(); log_add_target(stderr_target); log_set_all_filter(stderr_target, 1); l23_ctx = talloc_named_const(NULL, 1, "layer2 context"); msgb_set_talloc_ctx(l23_ctx); handle_options(argc, argv); if (!debug_set) log_parse_category_mask(stderr_target, debug_default); log_set_log_level(stderr_target, LOGL_DEBUG); if (gsmtap_ip) { gsmtap_inst = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1); if (!gsmtap_inst) { fprintf(stderr, "Failed during gsmtap_init()\n"); exit(1); } gsmtap_source_add_sink(gsmtap_inst); } home = getenv("HOME"); if (home != NULL) { len = strlen(home) + 1 + sizeof(osmocomcfg); config_file = talloc_size(l23_ctx, len); if (config_file != NULL) snprintf(config_file, len, "%s/%s", home, osmocomcfg); } /* save the config file directory name */ config_dir = talloc_strdup(l23_ctx, config_file); config_dir = dirname(config_dir); if (use_mncc_sock) rc = l23_app_init(mncc_recv_socket, config_file, vty_port); else rc = l23_app_init(NULL, config_file, vty_port); if (rc) exit(rc); signal(SIGINT, sighandler); signal(SIGHUP, sighandler); signal(SIGTERM, sighandler); signal(SIGPIPE, sighandler); signal(SIGABRT, sighandler); signal(SIGUSR1, sighandler); signal(SIGUSR2, sighandler); if (daemonize) { printf("Running as daemon\n"); rc = osmo_daemonize(); if (rc) fprintf(stderr, "Failed to run as daemon\n"); } while (1) { l23_app_work(&quit); if (quit && llist_empty(&ms_list)) break; osmo_select_main(0); } l23_app_exit(); talloc_free(config_file); talloc_free(config_dir); talloc_report_full(l23_ctx, stderr); return 0; }
int bts_main(int argc, char **argv) { struct gsm_bts_role_bts *btsb; struct gsm_bts_trx *trx; struct e1inp_line *line; void *tall_msgb_ctx; int rc, i; printf("((*))\n |\n / \\ OsmoBTS\n"); tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context"); tall_msgb_ctx = talloc_pool(tall_bts_ctx, 100*1024); msgb_set_talloc_ctx(tall_msgb_ctx); bts_log_init(NULL); handle_options(argc, argv); bts = gsm_bts_alloc(tall_bts_ctx); if (!bts) { fprintf(stderr, "Failed to create BTS structure\n"); exit(1); } for (i = 1; i < trx_num; i++) { trx = gsm_bts_trx_alloc(bts); if (!trx) { fprintf(stderr, "Failed to create TRX structure\n"); exit(1); } } vty_init(&bts_vty_info); e1inp_vty_init(); bts_vty_init(bts, &bts_log_info); /* enable realtime priority for us */ if (rt_prio != -1) { struct sched_param param; memset(¶m, 0, sizeof(param)); param.sched_priority = rt_prio; rc = sched_setscheduler(getpid(), SCHED_RR, ¶m); if (rc != 0) { fprintf(stderr, "Setting SCHED_RR priority(%d) failed: %s\n", param.sched_priority, strerror(errno)); exit(1); } } if (gsmtap_ip) { gsmtap = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1); if (!gsmtap) { fprintf(stderr, "Failed during gsmtap_init()\n"); exit(1); } gsmtap_source_add_sink(gsmtap); } if (bts_init(bts) < 0) { fprintf(stderr, "unable to open bts\n"); exit(1); } abis_init(bts); rc = vty_read_config_file(config_file, NULL); if (rc < 0) { fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); exit(1); } write_pid_file("osmo-bts"); bts_controlif_setup(bts); rc = telnet_init(tall_bts_ctx, NULL, OSMO_VTY_PORT_BTS); if (rc < 0) { fprintf(stderr, "Error initializing telnet\n"); exit(1); } if (pcu_sock_init()) { fprintf(stderr, "PCU L1 socket failed\n"); exit(1); } signal(SIGINT, &signal_handler); //signal(SIGABRT, &signal_handler); signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); osmo_init_ignore_signals(); btsb = bts_role_bts(bts); if (!btsb->bsc_oml_host) { fprintf(stderr, "Cannot start BTS without knowing BSC OML IP\n"); exit(1); } line = abis_open(bts, btsb->bsc_oml_host, "sysmoBTS"); if (!line) { fprintf(stderr, "unable to connect to BSC\n"); exit(2); } if (daemonize) { rc = osmo_daemonize(); if (rc < 0) { perror("Error during daemonize"); exit(1); } } while (quit < 2) { log_reset_context(); osmo_select_main(0); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { char *gsmtap_host = "127.0.0.1"; int rc; int c, ret = 1; int skip_atr = 0; int keep_running = 0; int dump_usb = 0; int replay = 0; struct libusb_device_handle *devh; print_welcome(); while (1) { int option_index = 0; c = getopt_long(argc, argv, "i:ahkd:r:", opts, &option_index); if (c == -1) break; switch (c) { case 'h': print_help(); exit(0); break; case 'i': gsmtap_host = optarg; break; case 'a': skip_atr = 1; break; case 'k': keep_running = 1; break; case 'd': dump_usb = 1; dump_usb_file = fopen(optarg,"wb"); break; case 'r': replay = 1; dump_usb_file = fopen(optarg,"rb"); printf("replaying file %s...\n",optarg); break; } } rc = libusb_init(NULL); if (rc < 0) { fprintf(stderr, "libusb initialization failed\n"); goto close_exit; } g_gti = gsmtap_source_init(gsmtap_host, GSMTAP_UDP_PORT, 0); if (!g_gti) { perror("unable to open GSMTAP"); goto close_exit; } gsmtap_source_add_sink(g_gti); as = apdu_split_init(&apdu_out_cb, NULL); if (!as) goto release_exit; if (replay) { printf("done replaying file...\n"); replay_mainloop(dump_usb_file); fclose(dump_usb_file); } else { do { devh = libusb_open_device_with_vid_pid(NULL, SIMTRACE_USB_VENDOR, SIMTRACE_USB_PRODUCT); if (!devh) { fprintf(stderr, "can't open USB device\n"); goto close_exit; } rc = libusb_claim_interface(devh, 0); if (rc < 0) { fprintf(stderr, "can't claim interface; rc=%d\n", rc); goto close_exit; } run_mainloop(devh); ret = 0; libusb_release_interface(devh, 0); close_exit: if (devh) libusb_close(devh); if (keep_running) sleep(1); } while (keep_running); } release_exit: libusb_exit(NULL); return ret; }