aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-01-22 09:33:54 +0100
committerHarald Welte <laforge@gnumonks.org>2016-01-22 09:33:54 +0100
commit0048a788ddcbbc0efc6b232c62b8622cdd27c3ba (patch)
treecf2f6f8a870c4cc6713ce29a77cf273fad3918e7
parent32d681ab985fe6da9f9fd40758e1917fc6f387c0 (diff)
parent611ef23700619f0e8e3a7c0b87f4568c1c09a6c0 (diff)
Merge branch 'laforge/common-main'
-rw-r--r--include/osmo-bts/bts.h2
-rw-r--r--include/osmo-bts/bts_model.h5
-rw-r--r--src/common/Makefile.am2
-rw-r--r--src/common/abis.c38
-rw-r--r--src/common/bts_ctrl_lookup.c7
-rw-r--r--src/common/main.c332
-rw-r--r--src/common/oml.c3
-rw-r--r--src/common/pcu_sock.c2
-rw-r--r--src/common/support.c86
-rw-r--r--src/osmo-bts-octphy/l1_if.c6
-rw-r--r--src/osmo-bts-octphy/main.c239
-rw-r--r--src/osmo-bts-octphy/octphy_vty.c13
-rw-r--r--src/osmo-bts-sysmo/main.c327
-rw-r--r--src/osmo-bts-sysmo/sysmobts_ctrl.c2
-rw-r--r--src/osmo-bts-trx/Makefile.am4
-rw-r--r--src/osmo-bts-trx/main.c265
-rw-r--r--src/osmo-bts-trx/trx_vty.c5
-rw-r--r--tests/handover/handover_test.c1
-rw-r--r--tests/stubs.c2
-rw-r--r--tests/sysmobts/sysmobts_test.c2
20 files changed, 502 insertions, 841 deletions
diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index 0b91ccbc..9e211864 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -43,5 +43,7 @@ int trx_ms_pwr_ctrl_is_osmo(struct gsm_bts_trx *trx);
struct gsm_time *get_time(struct gsm_bts *bts);
+int bts_main(int argc, char **argv);
+
#endif /* _BTS_H */
diff --git a/include/osmo-bts/bts_model.h b/include/osmo-bts/bts_model.h
index ecbfc3d3..41b5e93b 100644
--- a/include/osmo-bts/bts_model.h
+++ b/include/osmo-bts/bts_model.h
@@ -42,4 +42,9 @@ int bts_model_l1sap_down(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap)
void bts_model_abis_close(struct gsm_bts *bts);
+int bts_model_ctrl_cmds_install(struct gsm_bts *bts);
+
+int bts_model_handle_options(int argc, char **argv);
+void bts_model_print_help();
+
#endif
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index d2580f93..e577eba6 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -8,4 +8,4 @@ libbts_a_SOURCES = gsm_data_shared.c sysinfo.c logging.c abis.c oml.c bts.c \
load_indication.c pcu_sock.c handover.c msg_utils.c \
load_indication.c pcu_sock.c handover.c msg_utils.c \
tx_power.c bts_ctrl_commands.c bts_ctrl_lookup.c \
- l1sap.c cbch.c power_control.c
+ l1sap.c cbch.c power_control.c main.c
diff --git a/src/common/abis.c b/src/common/abis.c
index 3b8a7af1..a08f9f3b 100644
--- a/src/common/abis.c
+++ b/src/common/abis.c
@@ -73,6 +73,8 @@ static struct e1inp_sign_link *sign_link_up(void *unit, struct e1inp_line *line,
enum e1inp_sign_type type)
{
struct e1inp_sign_link *sign_link = NULL;
+ struct gsm_bts_trx *trx;
+ int trx_nr;
switch (type) {
case E1INP_SIGN_OML:
@@ -84,17 +86,22 @@ static struct e1inp_sign_link *sign_link_up(void *unit, struct e1inp_line *line,
sign_link->trx = g_bts->c0;
bts_link_estab(g_bts);
break;
- case E1INP_SIGN_RSL:
- LOGP(DABIS, LOGL_INFO, "RSL Signalling link up\n");
- e1inp_ts_config_sign(&line->ts[E1INP_SIGN_RSL-1], line);
- sign_link = g_bts->c0->rsl_link =
- e1inp_sign_link_create(&line->ts[E1INP_SIGN_RSL-1],
- E1INP_SIGN_RSL, NULL, 0, 0);
- /* FIXME: This assumes there is only one TRX! */
- sign_link->trx = g_bts->c0;
- trx_link_estab(sign_link->trx);
- break;
default:
+ trx_nr = type - E1INP_SIGN_RSL;
+ LOGP(DABIS, LOGL_INFO, "RSL Signalling link for TRX%d up\n",
+ trx_nr);
+ trx = gsm_bts_trx_num(g_bts, trx_nr);
+ if (!trx) {
+ LOGP(DABIS, LOGL_ERROR, "TRX%d does not exixt!\n",
+ trx_nr);
+ break;
+ }
+ e1inp_ts_config_sign(&line->ts[type-1], line);
+ sign_link = trx->rsl_link =
+ e1inp_sign_link_create(&line->ts[type-1],
+ E1INP_SIGN_RSL, NULL, 0, 0);
+ sign_link->trx = trx;
+ trx_link_estab(trx);
break;
}
@@ -103,12 +110,15 @@ static struct e1inp_sign_link *sign_link_up(void *unit, struct e1inp_line *line,
static void sign_link_down(struct e1inp_line *line)
{
+ struct gsm_bts_trx *trx;
LOGP(DABIS, LOGL_ERROR, "Signalling link down\n");
- if (g_bts->c0->rsl_link) {
- e1inp_sign_link_destroy(g_bts->c0->rsl_link);
- g_bts->c0->rsl_link = NULL;
- trx_link_estab(g_bts->c0);
+ llist_for_each_entry(trx, &g_bts->trx_list, list) {
+ if (trx->rsl_link) {
+ e1inp_sign_link_destroy(trx->rsl_link);
+ trx->rsl_link = NULL;
+ trx_link_estab(trx);
+ }
}
if (g_bts->oml_link)
diff --git a/src/common/bts_ctrl_lookup.c b/src/common/bts_ctrl_lookup.c
index 3857ec39..f356913a 100644
--- a/src/common/bts_ctrl_lookup.c
+++ b/src/common/bts_ctrl_lookup.c
@@ -101,5 +101,12 @@ struct ctrl_handle *bts_controlif_setup(struct gsm_bts *bts)
return NULL;
}
+ rc = bts_model_ctrl_cmds_install(bts);
+ if (rc) {
+ /* FIXME: cleanup generic control commands */
+ /* FIXME: close control interface */
+ return NULL;
+ }
+
return hdl;
}
diff --git a/src/common/main.c b/src/common/main.c
new file mode 100644
index 00000000..d9fa7786
--- /dev/null
+++ b/src/common/main.c
@@ -0,0 +1,332 @@
+/* Main program for Osmocom BTS */
+
+/* (C) 2011-2015 by Harald Welte <laforge@gnumonks.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <sys/signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sched.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <osmocom/core/talloc.h>
+#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_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/l1sap.h>
+#include <osmo-bts/bts_model.h>
+#include <osmo-bts/pcu_if.h>
+#include <osmo-bts/control_if.h>
+
+int quit = 0;
+static const char *config_file = "osmo-bts.cfg";
+static int daemonize = 0;
+static int rt_prio = -1;
+static int trx_num = 1;
+static char *gsmtap_ip = 0;
+
+static void 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"
+ " -t --trx-num Set number of TRX (default=%d)\n",
+ trx_num
+ );
+ bts_model_print_help();
+}
+
+/* FIXME: finally get some option parsing code into libosmocore */
+static void handle_options(int argc, char **argv)
+{
+ char *argv_out[argc];
+ int argc_out = 0;
+
+ argv_out[argc_out++] = argv[0];
+
+ /* disable generation of error messages on encountering unknown
+ * options */
+ opterr = 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' },
+ /* FIXME: generic BTS app options */
+ { "gsmtap-ip", 1, 0, 'i' },
+ { "trx-num", 1, 0, 't' },
+ { "realtime", 1, 0, 'r' },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "-hc:d:Dc:sTVe:i:t:r:",
+ 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);
+ 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;
+ case 't':
+ trx_num = atoi(optarg);
+ if (trx_num < 1)
+ trx_num = 1;
+ break;
+ case '?':
+ case 1:
+ /* prepare argv[] for bts_model */
+ argv_out[argc_out++] = argv[optind-1];
+ break;
+ default:
+ break;
+ }
+ }
+
+ /* re-set opt-ind for new parsig round */
+ optind = 1;
+ /* enable error-checking for the following getopt call */
+ opterr = 1;
+ if (bts_model_handle_options(argc_out, argv_out)) {
+ print_help();
+ exit(1);
+ }
+}
+
+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;
+}
+
+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(&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);
+ }
+
+ 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);
+ }
+}
diff --git a/src/common/oml.c b/src/common/oml.c
index 35973d7b..7795cc6e 100644
--- a/src/common/oml.c
+++ b/src/common/oml.c
@@ -1116,7 +1116,8 @@ static int rx_oml_ipa_rsl_connect(struct gsm_bts_trx *trx, struct msgb *msg,
LOGP(DOML, LOGL_INFO, "Rx IPA RSL CONNECT IP=%s PORT=%u STREAM=0x%02x\n",
inet_ntoa(in), port, stream_id);
- rc = e1inp_ipa_bts_rsl_connect(oml_link->ts->line, inet_ntoa(in), port);
+ rc = e1inp_ipa_bts_rsl_connect_n(oml_link->ts->line, inet_ntoa(in), port,
+ trx->nr);
if (rc < 0) {
LOGP(DOML, LOGL_ERROR, "Error in abis_open(RSL): %d\n", rc);
return oml_fom_ack_nack(msg, NM_NACK_CANT_PERFORM);
diff --git a/src/common/pcu_sock.c b/src/common/pcu_sock.c
index f7d3651d..34c6e74b 100644
--- a/src/common/pcu_sock.c
+++ b/src/common/pcu_sock.c
@@ -44,7 +44,7 @@
uint32_t trx_get_hlayer1(struct gsm_bts_trx *trx);
extern struct gsm_network bts_gsmnet;
-extern int pcu_direct;
+int pcu_direct = 0;
static int avail_lai = 0, avail_nse = 0, avail_cell = 0, avail_nsvc[2] = {0, 0};
static const char *sapi_string[] = {
diff --git a/src/common/support.c b/src/common/support.c
deleted file mode 100644
index d47a6a99..00000000
--- a/src/common/support.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/* (C) 2011 by Andreas Eversberg <jolly@eversberg.eu>
- *
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <sys/types.h>
-#include <string.h>
-#include <osmocom/gsm/protocol/gsm_12_21.h>
-//#include <osmocom/bb/common/osmocom_data.h>
-#include <osmo-bts/support.h>
-
-struct bts_support bts_support;
-
-void bts_support_init(void)
-{
- struct bts_support *sup = &bts_support;
- int i;
-
- memset(sup, 0, sizeof(*sup));
-
- /* crypto supprot */
- sup->a5_1 = 0;
- sup->a5_2 = 0;
- sup->a5_3 = 0;
- sup->a5_4 = 0;
- sup->a5_5 = 0;
- sup->a5_6 = 0;
- sup->a5_7 = 0;
- /* set supported frequencies */
- for(i = 1; i <= 124; i++) // P-GSM
- sup->freq_map[i >> 3] |= (1 << (i & 7));
- for(i = 512; i <= 885; i++) // DCS
- sup->freq_map[i >> 3] |= (1 << (i & 7));
- for(i = 975; i <= 1023; i++) // E-GSM extension
- sup->freq_map[i >> 3] |= (1 << (i & 7));
- sup->freq_map[0] |= 1; // channel 0
- for(i = 955; i <= 974; i++) // R-GSM extension
- sup->freq_map[i >> 3] |= (1 << (i & 7));
- /* channel combinations */
- sup->chan_comb[NM_CHANC_mainBCCH] = 1;
- sup->chan_comb[NM_CHANC_BCCHComb] = 1;
- sup->chan_comb[NM_CHANC_SDCCH] = 1;
- sup->chan_comb[NM_CHANC_TCHFull] = 1;
- sup->chan_comb[NM_CHANC_TCHHalf] = 1;
- /* codec */
- sup->full_v1 = 1;
- sup->full_v2 = 1;
- sup->full_v3 = 1;
- sup->half_v1 = 1;
- sup->half_v3 = 1;
-}
-
-char *bts_support_comb_name(uint8_t chan_comb)
-{
- if (chan_comb == NM_CHANC_mainBCCH)
- return("BCCH");
- if (chan_comb == NM_CHANC_BCCHComb)
- return("BCCH+SDCCH/4");
- if (chan_comb == NM_CHANC_BCCH_CBCH)
- return("BCCH+CBCH+SDCCH/4");
- if (chan_comb == NM_CHANC_SDCCH)
- return("SDCCH/8");
- if (chan_comb == NM_CHANC_SDCCH_CBCH)
- return("SDCCH/8+CBCH");
- if (chan_comb == NM_CHANC_TCHFull)
- return("TCH/F");
- if (chan_comb == NM_CHANC_TCHHalf)
- return("TCH/H");
- return "Unknown";
-}
-
-
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 <osmocom/core/application.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/logging.h>
-#include <osmocom/core/gsmtap_util.h>
-#include <osmocom/core/gsmtap.h>
#include <osmo-bts/logging.h>
-#include <osmo-bts/abis.h>
#include <osmo-bts/bts.h>
#include <osmo-bts/vty.h>
-#include <osmo-bts/pcu_if.h>
#include <osmo-bts/l1sap.h>
#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(&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 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;
+}
diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c
index 72cd0ee6..d468a71f 100644
--- a/src/osmo-bts-sysmo/main.c
+++ b/src/osmo-bts-sysmo/main.c
@@ -1,6 +1,6 @@
/* Main program for Sysmocom BTS */
-/* (C) 2011-2013 by Harald Welte <laforge@gnumonks.org>
+/* (C) 2011-2015 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
@@ -38,17 +38,12 @@
#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>
#define SYSMOBTS_RF_LOCK_PATH "/var/lock/bts_rf_lock"
@@ -59,20 +54,60 @@
#include "hw_misc.h"
#include "oml_router.h"
-int pcu_direct = 0;
-
-static int quit = 0;
-static const char *config_file = "osmo-bts.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;
+
+/* Set the clock calibration to the value
+ * read from the eeprom.
+ */
+void clk_cal_use_eeprom(struct gsm_bts *bts)
+{
+ int rc;
+ struct femtol1_hdl *hdl;
+ eeprom_RfClockCal_t rf_clk;
+
+ hdl = bts->c0->role_bts.l1h;
+
+ if (!hdl || !hdl->clk_use_eeprom)
+ return;
+
+ rc = eeprom_ReadRfClockCal(&rf_clk);
+ if (rc != EEPROM_SUCCESS) {
+ LOGP(DL1C, LOGL_ERROR, "Failed to read from EEPROM.\n");
+ return;
+ }
+
+ hdl->clk_cal = rf_clk.iClkCor;
+ LOGP(DL1C, LOGL_NOTICE,
+ "Read clock calibration(%d) from EEPROM.\n", hdl->clk_cal);
+}
+
int bts_model_init(struct gsm_bts *bts)
{
+ struct gsm_bts_role_bts *btsb;
struct femtol1_hdl *fl1h;
+ struct stat st;
+ struct osmo_fd accept_fd, read_fd;
int rc;
+ btsb = bts_role_bts(bts);
+ btsb->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3);
+
+ clk_cal_use_eeprom(bts);
+
+ if (stat(SYSMOBTS_RF_LOCK_PATH, &st) == 0) {
+ LOGP(DL1C, LOGL_NOTICE, "Not starting BTS due to RF_LOCK file present\n");
+ exit(23);
+ }
+
+ 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 = l1if_open(bts->c0);
if (!fl1h) {
LOGP(DL1C, LOGL_FATAL, "Cannot open L1 Interface\n");
@@ -105,31 +140,6 @@ int bts_model_oml_estab(struct gsm_bts *bts)
return 0;
}
-/* Set the clock calibration to the value
- * read from the eeprom.
- */
-void clk_cal_use_eeprom(struct gsm_bts *bts)
-{
- int rc;
- struct femtol1_hdl *hdl;
- eeprom_RfClockCal_t rf_clk;
-
- hdl = bts->c0->role_bts.l1h;
-
- if (!hdl || !hdl->clk_use_eeprom)
- return;
-
- rc = eeprom_ReadRfClockCal(&rf_clk);
- if (rc != EEPROM_SUCCESS) {
- LOGP(DL1C, LOGL_ERROR, "Failed to read from EEPROM.\n");
- return;
- }
-
- hdl->clk_cal = rf_clk.iClkCor;
- LOGP(DL1C, LOGL_NOTICE,
- "Read clock calibration(%d) from EEPROM.\n", hdl->clk_cal);
-}
-
void bts_update_status(enum bts_global_status which, int on)
{
static uint64_t states = 0;
@@ -154,25 +164,15 @@ void bts_update_status(enum bts_global_status which, int on)
sysmobts_led_set(LED_RF_ACTIVE, led_rf_active_on);
}
-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"
+ printf(
" -p --dsp-trace Set DSP trace flags\n"
- " -r --realtime PRIO Use SCHED_RR with the specified priority\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"
- );
-}
+ );
+};
static void print_hwversion()
{
@@ -183,249 +183,52 @@ static void print_hwversion()
#endif
}
-/* 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' },
+ /* specific to this hardware */
{ "dsp-trace", 1, 0, 'p' },
{ "hw-version", 0, 0, 'w' },
{ "pcu-direct", 0, 0, 'M' },
- { "realtime", 1, 0, 'r' },
- { "gsmtap-ip", 1, 0, 'i' },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hc:d:Dc:sTVe:p:w:Mr:i:",
+ c = getopt_long(argc, argv, "p:w:M",
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);
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;
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;
- }
+ 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 sysmobts_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 rc;
-
- 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);
-
- 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);
- }
-
- clk_cal_use_eeprom(bts);
-
- if (stat(SYSMOBTS_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");
-
- bts_controlif_setup(bts);
- sysmobts_ctrlif_inst_cmds();
-
- 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();
-
- 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, "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);
- }
-}
-
-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-sysmo/sysmobts_ctrl.c b/src/osmo-bts-sysmo/sysmobts_ctrl.c
index dabb0106..8eee58c5 100644
--- a/src/osmo-bts-sysmo/sysmobts_ctrl.c
+++ b/src/osmo-bts-sysmo/sysmobts_ctrl.c
@@ -261,7 +261,7 @@ static int verify_clock_corr(struct ctrl_cmd *cmd, const char *value, void *data
}
#endif /* HW_SYSMOBTS_V1 */
-int sysmobts_ctrlif_inst_cmds(void)
+int bts_model_ctrl_cmds_install(struct gsm_bts *bts)
{
int rc = 0;
diff --git a/src/osmo-bts-trx/Makefile.am b/src/osmo-bts-trx/Makefile.am
index 024c013f..26bc8e2e 100644
--- a/src/osmo-bts-trx/Makefile.am
+++ b/src/osmo-bts-trx/Makefile.am
@@ -1,6 +1,6 @@
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
-AM_CFLAGS = -Wall -fno-strict-aliasing $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(ORTP_CFLAGS)
-LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(ORTP_LIBS)
+AM_CFLAGS = -Wall -fno-strict-aliasing $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(ORTP_CFLAGS)
+LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) $(ORTP_LIBS)
EXTRA_DIST = trx_if.h l1_if.h scheduler.h gsm0503_parity.h gsm0503_conv.h gsm0503_interleaving.h gsm0503_mapping.h gsm0503_coding.h gsm0503_tables.h loops.h amr.h
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index ae85abef..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,264 +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");
-
- 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);
}
-
diff --git a/src/osmo-bts-trx/trx_vty.c b/src/osmo-bts-trx/trx_vty.c
index 43c00f88..5da0c21f 100644
--- a/src/osmo-bts-trx/trx_vty.c
+++ b/src/osmo-bts-trx/trx_vty.c
@@ -419,3 +419,8 @@ int bts_model_vty_init(struct gsm_bts *bts)
return 0;
}
+
+int bts_model_ctrl_cmds_install(struct gsm_bts *bts)
+{
+ return 0;
+}
diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c
index 6d7e6d1e..8b299d06 100644
--- a/tests/handover/handover_test.c
+++ b/tests/handover/handover_test.c
@@ -40,7 +40,6 @@ static struct gsm_bts *bts;
struct gsm_bts_trx *trx;
int quit = 0;
uint8_t abis_mac[6] = { 0, 1, 2, 3, 4, 5 };
-const int pcu_direct = 0;
int modify_count = 0;
static void expect_phys_info(struct lapdm_entity *le)
diff --git a/tests/stubs.c b/tests/stubs.c
index f1ba5cc7..17354b72 100644
--- a/tests/stubs.c
+++ b/tests/stubs.c
@@ -5,8 +5,6 @@
* If we ever want to re-define such a symbol we can make them weak
* here.
*/
-int pcu_direct = 0;
-
int bts_model_chg_adm_state(struct gsm_bts *bts, struct gsm_abis_mo *mo,
void *obj, uint8_t adm_state)
{ return 0; }
diff --git a/tests/sysmobts/sysmobts_test.c b/tests/sysmobts/sysmobts_test.c
index def7a819..b835dc27 100644
--- a/tests/sysmobts/sysmobts_test.c
+++ b/tests/sysmobts/sysmobts_test.c
@@ -29,8 +29,6 @@
#include <stdio.h>
-int pcu_direct = 0;
-
static int direct_map[][3] = {
{ GSM_BAND_850, GsmL1_FreqBand_850, 128 },
{ GSM_BAND_900, GsmL1_FreqBand_900, 1 },