From 611ef23700619f0e8e3a7c0b87f4568c1c09a6c0 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 9 Jan 2016 12:34:18 +0100 Subject: merge bts-specific main function into common/main.c:bts_main() This removes a lot of copy+paste duplication between different BTS models. --- src/osmo-bts-octphy/l1_if.c | 6 + src/osmo-bts-octphy/main.c | 239 +++------------------------------------ src/osmo-bts-octphy/octphy_vty.c | 13 +++ 3 files changed, 34 insertions(+), 224 deletions(-) (limited to 'src/osmo-bts-octphy') diff --git a/src/osmo-bts-octphy/l1_if.c b/src/osmo-bts-octphy/l1_if.c index 6d8932e4..db6e032c 100644 --- a/src/osmo-bts-octphy/l1_if.c +++ b/src/osmo-bts-octphy/l1_if.c @@ -688,8 +688,14 @@ int bts_model_l1sap_down(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap) int bts_model_init(struct gsm_bts *bts) { + struct gsm_bts_role_bts *btsb; struct octphy_hdl *fl1h; + LOGP(DL1C, LOGL_NOTICE, "model_init()\n"); + + btsb = bts_role_bts(bts); + btsb->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3); + fl1h = talloc_zero(bts, struct octphy_hdl); if (!fl1h) return -ENOMEM; diff --git a/src/osmo-bts-octphy/main.c b/src/osmo-bts-octphy/main.c index 1cb7cfc2..1f516e4a 100644 --- a/src/osmo-bts-octphy/main.c +++ b/src/osmo-bts-octphy/main.c @@ -40,266 +40,57 @@ #include #include #include -#include -#include #include -#include #include #include -#include #include #include "l1_if.h" -int pcu_direct = 0; #define RF_LOCK_PATH "/var/lock/bts_rf_lock" -static const char *config_file = "osmo-bts.cfg"; -static int daemonize = 0; -static int rt_prio = -1; -static char *gsmtap_ip = 0; +extern int pcu_direct; -static void print_help() +static struct gsm_bts *bts; + +int bts_model_print_help() { - printf( "Some useful options:\n" - " -h --help this text\n" - " -d --debug MASK Enable debugging (e.g. -d DRSL:DOML:DLAPDM)\n" - " -D --daemonize For the process into a background daemon\n" - " -c --config-file Specify the filename of the config file\n" - " -s --disable-color Don't use colors in stderr log output\n" - " -T --timestamp Prefix every log line with a timestamp\n" - " -V --version Print version information and exit\n" - " -e --log-level Set a global log-level\n" - " -r --realtime PRIO Use SCHED_RR with the specified priority\n" - " -i --gsmtap-ip The destination IP used for GSMTAP.\n" - ); } -/* FIXME: finally get some option parsing code into libosmocore */ -static void handle_options(int argc, char **argv) +int bts_model_handle_options(int argc, char **argv) { + int num_errors = 0; + while (1) { int option_idx = 0, c; static const struct option long_options[] = { - /* FIXME: all those are generic Osmocom app options */ - { "help", 0, 0, 'h' }, - { "debug", 1, 0, 'd' }, - { "daemonize", 0, 0, 'D' }, - { "config-file", 1, 0, 'c' }, - { "disable-color", 0, 0, 's' }, - { "timestamp", 0, 0, 'T' }, - { "version", 0, 0, 'V' }, - { "log-level", 1, 0, 'e' }, - { "realtime", 1, 0, 'r' }, - { "gsmtap-ip", 1, 0, 'i' }, + /* specific to this hardware */ { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hc:d:Dc:sTVe:r:i:m:l:", + c = getopt_long(argc, argv, "", long_options, &option_idx); if (c == -1) break; switch (c) { - case 'h': - print_help(); - exit(0); - break; - case 's': - log_set_use_color(osmo_stderr_target, 0); - break; - case 'd': - log_parse_category_mask(osmo_stderr_target, optarg); - break; - case 'D': - daemonize = 1; - break; - case 'c': - config_file = strdup(optarg); - break; - case 'T': - log_set_print_timestamp(osmo_stderr_target, 1); - break; - case 'V': - print_version(1); - exit(0); - break; - case 'e': - log_set_log_level(osmo_stderr_target, atoi(optarg)); - break; - case 'r': - rt_prio = atoi(optarg); - break; - case 'i': - gsmtap_ip = optarg; - break; default: + num_errors++; break; } } -} - -static struct gsm_bts *bts; - -static void signal_handler(int signal) -{ - fprintf(stderr, "signal %u received\n", signal); - switch (signal) { - case SIGINT: - //osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL); - bts_shutdown(bts, "SIGINT"); - break; - case SIGABRT: - case SIGUSR1: - case SIGUSR2: - talloc_report_full(tall_bts_ctx, stderr); - break; - default: - break; - } + return num_errors; } -static int write_pid_file(char *procname) +void bts_model_abis_close(struct gsm_bts *bts) { - FILE *outf; - char tmp[PATH_MAX + 1]; - - snprintf(tmp, sizeof(tmp) - 1, "/var/run/%s.pid", procname); - tmp[PATH_MAX - 1] = '\0'; - - outf = fopen(tmp, "w"); - if (!outf) - return -1; - - fprintf(outf, "%d\n", getpid()); - - fclose(outf); - - return 0; + /* for now, we simply terminate the program and re-spawn */ + bts_shutdown(bts, "Abis close"); } int main(int argc, char **argv) { - struct stat st; - struct sched_param param; - struct gsm_bts_role_bts *btsb; - struct e1inp_line *line; - void *tall_msgb_ctx; - int rc; - - tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context"); - tall_msgb_ctx = talloc_named_const(tall_bts_ctx, 1, "msgb"); - msgb_set_talloc_ctx(tall_msgb_ctx); - - bts_log_init(NULL); - - bts = gsm_bts_alloc(tall_bts_ctx); - vty_init(&bts_vty_info); - e1inp_vty_init(); - bts_vty_init(bts, &bts_log_info); - - handle_options(argc, argv); - - /* enable realtime priority for us */ - if (rt_prio != -1) { - 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 to open bts\n"); - exit(1); - } - btsb = bts_role_bts(bts); - btsb->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3); - - 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); - } - - if (stat(RF_LOCK_PATH, &st) == 0) { - LOGP(DL1C, LOGL_NOTICE, - "Not starting BTS due to RF_LOCK file present\n"); - exit(23); - } - write_pid_file("osmo-bts"); - - rc = telnet_init(tall_bts_ctx, NULL, 4241); - 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(); - - 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, "OsmoBTS-OCTPHY"); - if (!line) { - fprintf(stderr, "unable to connect to BSC\n"); - exit(1); - } - - /* Open L1 interface */ - rc = l1if_open(bts->c0->role_bts.l1h); - if (rc < 0) { - LOGP(DL1C, LOGL_FATAL, "Cannot open L1 Interface\n"); - exit(1); - } - - if (daemonize) { - rc = osmo_daemonize(); - if (rc < 0) { - perror("Error during daemonize"); - exit(1); - } - } - - while (1) { - log_reset_context(); - osmo_select_main(0); - } - -} - -void bts_model_abis_close(struct gsm_bts *bts) -{ - /* for now, we simply terminate the program and re-spawn */ - bts_shutdown(bts, "Abis close"); + return bts_main(argc, argv); } diff --git a/src/osmo-bts-octphy/octphy_vty.c b/src/osmo-bts-octphy/octphy_vty.c index 55c9099c..dbc903a9 100644 --- a/src/osmo-bts-octphy/octphy_vty.c +++ b/src/osmo-bts-octphy/octphy_vty.c @@ -223,3 +223,16 @@ int bts_model_vty_init(struct gsm_bts *bts) return 0; } + +int bts_model_ctrl_cmds_install(struct gsm_bts *bts) +{ + /* FIXME: really ugly hack: We can only initialize the L1 intrface + * after reading the config file, and this is the only call-back after + * vty_read_config_fioe() at this point. Will be cleaned up with the + * phy interface generalization patches coming up soon as part of the + * multi-trx work */ + struct octphy_hdl *fl1h = bts->c0->role_bts.l1h; + l1if_open(fl1h); + + return 0; +} -- cgit v1.2.3