aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-litecell15/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/osmo-bts-litecell15/main.c')
-rw-r--r--src/osmo-bts-litecell15/main.c290
1 files changed, 34 insertions, 256 deletions
diff --git a/src/osmo-bts-litecell15/main.c b/src/osmo-bts-litecell15/main.c
index 6e8ca0d5..08513256 100644
--- a/src/osmo-bts-litecell15/main.c
+++ b/src/osmo-bts-litecell15/main.c
@@ -1,6 +1,7 @@
/* Main program for NuRAN Wireless Litecell 1.5 BTS */
/* Copyright (C) 2015 by Yves Godin <support@nuranwireless.com>
+ * Copyright (C) 2016 by Harald Welte <laforge@gnumonks.org>
*
* Based on sysmoBTS:
* (C) 2011-2013 by Harald Welte <laforge@gnumonks.org>
@@ -41,22 +42,16 @@
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/ports.h>
-#include <osmocom/core/gsmtap_util.h>
-#include <osmocom/core/gsmtap.h>
#include <osmo-bts/gsm_data.h>
#include <osmo-bts/logging.h>
-#include <osmo-bts/abis.h>
#include <osmo-bts/bts.h>
#include <osmo-bts/vty.h>
#include <osmo-bts/bts_model.h>
-#include <osmo-bts/pcu_if.h>
-#include <osmo-bts/control_if.h>
#include <osmo-bts/l1sap.h>
/*NTQD: Change how rx_nr is handle in multi-trx*/
-#define LC15BTS_RF_LOCK_PATH(NR) ((((NR))==1) ? "/var/lock/bts_rf_lock1" : "/var/lock/bts_rf_lock2")
-#define LC15BTS_PID_FILE(NR) ((((NR))==1) ? "osmo-bts1" : "osmo-bts2")
+#define LC15BTS_RF_LOCK_PATH "/var/lock/bts_rf_lock"
#include "utils.h"
#include "l1_if.h"
@@ -64,37 +59,33 @@
#include "oml_router.h"
#include "misc/lc15bts_bid.h"
-int pcu_direct = 0;
-
-static const char *config_file = "lc15bts.cfg";
-static int daemonize = 0;
+extern int pcu_direct;
static unsigned int dsp_trace = 0x00000000;
-static int rt_prio = -1;
-static char *gsmtap_ip = 0;
-static int trx_nr = 1;
int bts_model_init(struct gsm_bts *bts)
{
- struct lc15l1_hdl *fl1h;
+ struct gsm_bts_role_bts *btsb;
+ struct stat st;
+ static struct osmo_fd accept_fd, read_fd;
int rc;
- fl1h = l1if_open(bts->c0, trx_nr);
- if (!fl1h) {
- LOGP(DL1C, LOGL_FATAL, "Cannot open L1 Interface\n");
- return -EIO;
+ btsb = bts_role_bts(bts);
+ btsb->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3);
+
+ rc = oml_router_init(bts, OML_ROUTER_PATH, &accept_fd, &read_fd);
+ if (rc < 0) {
+ fprintf(stderr, "Error creating the OML router: %s rc=%d\n",
+ OML_ROUTER_PATH, rc);
+ exit(1);
}
- fl1h->dsp_trace_f = dsp_trace;
- bts->c0->role_bts.l1h = fl1h;
+ bts->c0->nominal_power = 37;
+ bts->c0->power_params.trx_p_max_out_mdBm = to_mdB(bts->c0->nominal_power);
- rc = lc15bts_get_nominal_power(bts->c0);
- if (rc < 0) {
- LOGP(DL1C, LOGL_NOTICE, "Cannot determine nominal "
- "transmit power. Assuming 37dBm.\n");
- rc = 37;
+ if (stat(LC15BTS_RF_LOCK_PATH, &st) == 0) {
+ LOGP(DL1C, LOGL_NOTICE, "Not starting BTS due to RF_LOCK file present\n");
+ exit(23);
}
- bts->c0->nominal_power = rc;
- bts->c0->power_params.trx_p_max_out_mdBm = to_mdB(rc);
bts_model_vty_init(bts);
@@ -134,24 +125,12 @@ void bts_update_status(enum bts_global_status which, int on)
lc15bts_led_set(led_rf_active_on ? LED_GREEN : LED_OFF);
}
-static void print_help()
+void 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"
- " -p --dsp-trace Set DSP trace flags\n"
- " -r --realtime PRIO Use SCHED_RR with the specified priority\n"
+ printf( " -p --dsp-trace Set DSP trace flags\n"
" -w --hw-version Print the targeted HW Version\n"
" -M --pcu-direct Force PCU to access message queue for "
"PDCH dchannel directly\n"
- " -i --gsmtap-ip The destination IP used for GSMTAP.\n"
- " -n --hw-trx-nr Hardware TRX number <1-2>\n"
);
}
@@ -178,254 +157,53 @@ static void print_hwversion()
printf(model_name);
}
-/* 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' },
{ "dsp-trace", 1, 0, 'p' },
{ "hw-version", 0, 0, 'w' },
{ "pcu-direct", 0, 0, 'M' },
- { "realtime", 1, 0, 'r' },
- { "gsmtap-ip", 1, 0, 'i' },
- { "hw-trx-nr", 1, 0, 'n' },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hc:d:Dc:sTVe:p:w:Mr:n:",
+ c = getopt_long(argc, argv, "p:wM",
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 = optarg;
- break;
- case 'T':
- log_set_print_timestamp(osmo_stderr_target, 1);
+ case 'p':
+ dsp_trace = strtoul(optarg, NULL, 16);
+#warning use dsp_trace!!!
break;
case 'M':
pcu_direct = 1;
break;
- case 'V':
- print_version(1);
- exit(0);
- break;
- case 'e':
- log_set_log_level(osmo_stderr_target, atoi(optarg));
- break;
- case 'p':
- dsp_trace = strtoul(optarg, NULL, 16);
- break;
case 'w':
print_hwversion();
exit(0);
break;
- case 'r':
- rt_prio = atoi(optarg);
- break;
- case 'i':
- gsmtap_ip = optarg;
- break;
- case 'n':
- trx_nr = atoi(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");
}
-extern int lc15bts_ctrlif_inst_cmds(void);
-
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;
- struct osmo_fd accept_fd, read_fd;
- int vty_port;
- int rc;
-
-
- tall_bts_ctx = talloc_named_const(NULL, 1, "lc15BTS context");
- tall_msgb_ctx = talloc_pool(tall_bts_ctx, 100*1024);
- 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(&param, 0, sizeof(param));
- param.sched_priority = rt_prio;
- rc = sched_setscheduler(getpid(), SCHED_RR, &param);
- 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);
- }
- 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(LC15BTS_RF_LOCK_PATH(trx_nr), &st) == 0) {
- LOGP(DL1C, LOGL_NOTICE, "Not starting BTS due to RF_LOCK file present\n");
- exit(23);
- }
- write_pid_file(LC15BTS_PID_FILE(trx_nr));
-
- bts_controlif_setup(bts);
-
- vty_port = (trx_nr == 1) ? OSMO_VTY_PORT_BTS : (OSMO_VTY_PORT_BTS + 1000);
- rc = telnet_init(tall_bts_ctx, NULL, vty_port);
- if (rc < 0) {
- fprintf(stderr, "Error initializing telnet\n");
- exit(1);
- }
-
- /* NTQD: For testing, we only support PCU on the first TRX */
- if (trx_nr == 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();
-
- rc = oml_router_init(bts, OML_ROUTER_PATH, &accept_fd, &read_fd);
- if (rc < 0) {
- fprintf(stderr, "Error creating the OML router: %s rc=%d\n",
- OML_ROUTER_PATH, rc);
- exit(1);
- }
-
- 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, "lc15BTS");
- 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 (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);
}