aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-trx/main.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-01-09 12:34:18 +0100
committerHarald Welte <laforge@gnumonks.org>2016-01-22 09:09:09 +0100
commit611ef23700619f0e8e3a7c0b87f4568c1c09a6c0 (patch)
tree56caf4c258a6cc155a3c08dd2a17dd3c40cabe80 /src/osmo-bts-trx/main.c
parenta0192b859ba9230c84381cbf065816760da62ba7 (diff)
merge bts-specific main function into common/main.c:bts_main()
This removes a lot of copy+paste duplication between different BTS models.
Diffstat (limited to 'src/osmo-bts-trx/main.c')
-rw-r--r--src/osmo-bts-trx/main.c267
1 files changed, 21 insertions, 246 deletions
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index 13851095..6c2dabf7 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -1,6 +1,6 @@
/* Main program for OsmoBTS-TRX */
-/* (C) 2011 by Harald Welte <laforge@gnumonks.org>
+/* (C) 2011-2015 by Harald Welte <laforge@gnumonks.org>
* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
*
* All Rights Reserved
@@ -39,6 +39,7 @@
#include <osmocom/core/application.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/logging.h>
+#include <osmocom/vty/ports.h>
#include <osmocom/core/gsmtap.h>
#include <osmocom/core/gsmtap_util.h>
#include <osmocom/core/bits.h>
@@ -51,27 +52,21 @@
#include <osmo-bts/bts_model.h>
#include <osmo-bts/pcu_if.h>
#include <osmo-bts/l1sap.h>
+#include <osmo-bts/control_if.h>
#include "l1_if.h"
#include "trx_if.h"
#include "scheduler.h"
-const int pcu_direct = 0;
-
-int quit = 0;
-static const char *config_file = "osmo-bts.cfg";
-static int daemonize = 0;
-static char *gsmtap_ip = 0;
-static int rt_prio = -1;
-static int trx_num = 1;
-char *software_version = "0.0";
-char *bsc_host = "localhost";
-char *bts_id = "1801/0";
-
int bts_model_init(struct gsm_bts *bts)
{
void *l1h;
struct gsm_bts_trx *trx;
+ struct gsm_bts_role_bts *btsb = bts_role_bts(bts);
+
+ btsb->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2);
+ if (!settsc_enabled && !setbsic_enabled)
+ settsc_enabled = setbsic_enabled = 1;
llist_for_each_entry(trx, &bts->trx_list, list) {
l1h = l1if_open(trx);
@@ -106,266 +101,46 @@ uint32_t trx_get_hlayer1(struct gsm_bts_trx *trx)
return 0;
}
-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"
- " -t --trx-num Set number of TRX (default=%d)\n"
- " -i --gsmtap-ip The destination IP used for GSMTAP.\n"
- " -r --realtime PRIO Set realtime scheduler with given prio\n"
+ printf(
" -I --local-trx-ip Local IP for transceiver to connect (default=%s)\n"
- ,trx_num, transceiver_ip);
+ , transceiver_ip
+ );
}
-/* 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' },
- { "trx-num", 1, 0, 't' },
- { "gsmtap-ip", 1, 0, 'i' },
- { "realtime", 1, 0, 'r' },
+ /* specific to this hardware */
{ "local-trx-ip", 1, 0, 'I' },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hc:d:Dc:sTVe:t:i:r:I:",
+ c = getopt_long(argc, argv, "I:",
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 't':
- trx_num = atoi(optarg);
- if (trx_num < 1)
- trx_num = 1;
- break;
- case 'i':
- gsmtap_ip = optarg;
- break;
- case 'r':
- rt_prio = atoi(optarg);
- break;
case 'I':
transceiver_ip = strdup(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);
- if (!quit)
- bts_shutdown(bts, "SIGINT");
- quit++;
- break;
- case SIGABRT:
- case SIGUSR1:
- case SIGUSR2:
- talloc_report_full(tall_bts_ctx, stderr);
- break;
- default:
- break;
- }
-}
-
-static int write_pid_file(char *procname)
-{
- 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;
+ return num_errors;
}
int 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_named_const(tall_bts_ctx, 1, "msgb");
- 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 TRX structure\n");
- exit(1);
- }
- }
-
- vty_init(&bts_vty_info);
- e1inp_vty_init();
- bts_vty_init(bts, &bts_log_info);
-
- 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);
-
- 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);
- }
-
- 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 (!settsc_enabled && !setbsic_enabled)
- settsc_enabled = setbsic_enabled = 1;
-
- write_pid_file("osmo-bts");
-
- bts_controlif_setup(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, "sysmoBTS");
- if (!line) {
- fprintf(stderr, "unable to connect to BSC\n");
- exit(1);
- }
-
- if (daemonize) {
- rc = osmo_daemonize();
- if (rc < 0) {
- perror("Error during daemonize");
- exit(1);
- }
- }
-
- if (rt_prio != -1) {
- struct sched_param schedp;
-
- /* high priority scheduling required for handling bursts */
- memset(&schedp, 0, sizeof(schedp));
- schedp.sched_priority = rt_prio;
- rc = sched_setscheduler(0, SCHED_RR, &schedp);
- if (rc) {
- fprintf(stderr, "Error setting SCHED_RR with prio %d\n",
- rt_prio);
- }
- }
-
- while (quit < 2) {
- log_reset_context();
- osmo_select_main(0);
- }
-
-#if 0
- telnet_exit();
-
- talloc_report_full(tall_bts_ctx, stderr);
-#endif
-
- return 0;
+ return bts_main(argc, argv);
}
-