2010-06-30 06:33:01 +00:00
|
|
|
/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
|
2011-04-07 21:23:27 +00:00
|
|
|
* (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2009-2011 by On-Waves
|
2010-06-30 06:33:01 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* 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
|
2010-06-30 06:33:01 +00:00
|
|
|
* (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
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2010-06-30 06:33:01 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* 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/>.
|
2010-06-30 06:33:01 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-03-16 10:54:55 +00:00
|
|
|
#include <openbsc/bss.h>
|
2010-06-30 06:59:23 +00:00
|
|
|
#include <openbsc/debug.h>
|
2010-06-30 06:33:01 +00:00
|
|
|
#include <openbsc/gsm_data.h>
|
2010-09-16 09:26:35 +00:00
|
|
|
#include <openbsc/osmo_bsc.h>
|
2010-06-30 06:59:23 +00:00
|
|
|
#include <openbsc/osmo_bsc_rf.h>
|
2010-09-15 14:29:25 +00:00
|
|
|
#include <openbsc/osmo_msc_data.h>
|
|
|
|
#include <openbsc/signal.h>
|
2010-08-26 07:38:42 +00:00
|
|
|
#include <openbsc/vty.h>
|
2011-02-18 15:17:58 +00:00
|
|
|
#include <openbsc/ipaccess.h>
|
2014-08-20 21:47:15 +00:00
|
|
|
#include <openbsc/ctrl.h>
|
2010-06-30 06:33:01 +00:00
|
|
|
|
2014-08-20 21:47:15 +00:00
|
|
|
#include <osmocom/ctrl/control_cmd.h>
|
|
|
|
#include <osmocom/ctrl/control_if.h>
|
2011-07-22 15:55:42 +00:00
|
|
|
|
2011-05-12 14:02:07 +00:00
|
|
|
#include <osmocom/core/application.h>
|
2011-06-30 09:03:07 +00:00
|
|
|
#include <osmocom/core/linuxlist.h>
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2011-02-18 15:17:58 +00:00
|
|
|
#include <osmocom/gsm/protocol/gsm_12_21.h>
|
2010-06-30 06:59:23 +00:00
|
|
|
|
2012-03-16 10:54:55 +00:00
|
|
|
#include <osmocom/abis/abis.h>
|
|
|
|
|
2010-08-03 13:11:51 +00:00
|
|
|
#include <osmocom/sccp/sccp.h>
|
2010-07-29 18:53:14 +00:00
|
|
|
|
2010-06-30 06:59:23 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2010-09-15 14:29:25 +00:00
|
|
|
#include <signal.h>
|
2010-06-30 06:59:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2010-09-15 14:29:25 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2010-06-30 06:59:23 +00:00
|
|
|
|
2011-03-04 12:53:51 +00:00
|
|
|
#include "../../bscconfig.h"
|
2010-06-30 06:59:23 +00:00
|
|
|
|
2010-06-30 06:33:01 +00:00
|
|
|
struct gsm_network *bsc_gsmnet = 0;
|
2010-06-30 06:59:23 +00:00
|
|
|
static const char *config_file = "openbsc.cfg";
|
2011-06-04 07:32:35 +00:00
|
|
|
static const char *rf_ctrl = NULL;
|
2010-09-11 05:28:42 +00:00
|
|
|
extern const char *openbsc_copyright;
|
2010-08-25 17:43:54 +00:00
|
|
|
static int daemonize = 0;
|
2010-06-30 06:59:23 +00:00
|
|
|
|
|
|
|
static void print_usage()
|
|
|
|
{
|
2011-04-13 07:17:40 +00:00
|
|
|
printf("Usage: osmo-bsc\n");
|
2010-06-30 06:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_help()
|
|
|
|
{
|
|
|
|
printf(" Some useful help...\n");
|
|
|
|
printf(" -h --help this text\n");
|
2010-08-25 17:43:54 +00:00
|
|
|
printf(" -D --daemonize Fork the process into a background daemon\n");
|
2010-06-30 06:59:23 +00:00
|
|
|
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
|
|
|
|
printf(" -s --disable-color\n");
|
|
|
|
printf(" -T --timestamp. Print a timestamp in the debug output.\n");
|
|
|
|
printf(" -c --config-file filename The config file to use.\n");
|
|
|
|
printf(" -l --local=IP. The local address of the MGCP.\n");
|
|
|
|
printf(" -e --log-level number. Set a global loglevel.\n");
|
|
|
|
printf(" -r --rf-ctl NAME. A unix domain socket to listen for cmds.\n");
|
|
|
|
printf(" -t --testmode. A special mode to provoke failures at the MSC.\n");
|
|
|
|
}
|
|
|
|
|
2010-09-17 22:44:24 +00:00
|
|
|
static void handle_options(int argc, char **argv)
|
2010-06-30 06:59:23 +00:00
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
int option_index = 0, c;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"debug", 1, 0, 'd'},
|
2010-08-25 17:43:54 +00:00
|
|
|
{"daemonize", 0, 0, 'D'},
|
2010-06-30 06:59:23 +00:00
|
|
|
{"config-file", 1, 0, 'c'},
|
|
|
|
{"disable-color", 0, 0, 's'},
|
|
|
|
{"timestamp", 0, 0, 'T'},
|
|
|
|
{"local", 1, 0, 'l'},
|
|
|
|
{"log-level", 1, 0, 'e'},
|
|
|
|
{"rf-ctl", 1, 0, 'r'},
|
|
|
|
{"testmode", 0, 0, 't'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2010-08-25 17:43:54 +00:00
|
|
|
c = getopt_long(argc, argv, "hd:DsTc:e:r:t",
|
2010-06-30 06:59:23 +00:00
|
|
|
long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
print_usage();
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
case 's':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_use_color(osmo_stderr_target, 0);
|
2010-06-30 06:59:23 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_parse_category_mask(osmo_stderr_target, optarg);
|
2010-06-30 06:59:23 +00:00
|
|
|
break;
|
2010-08-25 17:43:54 +00:00
|
|
|
case 'D':
|
|
|
|
daemonize = 1;
|
|
|
|
break;
|
2010-06-30 06:59:23 +00:00
|
|
|
case 'c':
|
2014-06-12 09:19:38 +00:00
|
|
|
config_file = optarg;
|
2010-06-30 06:59:23 +00:00
|
|
|
break;
|
|
|
|
case 'T':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_print_timestamp(osmo_stderr_target, 1);
|
2010-06-30 06:59:23 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_log_level(osmo_stderr_target, atoi(optarg));
|
2010-06-30 06:59:23 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
2011-06-04 07:32:35 +00:00
|
|
|
rf_ctrl = optarg;
|
2010-06-30 06:59:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern enum node_type bsc_vty_go_parent(struct vty *vty);
|
|
|
|
|
|
|
|
static struct vty_app_info vty_info = {
|
2011-02-24 22:57:06 +00:00
|
|
|
.name = "OsmoBSC",
|
2010-06-30 06:59:23 +00:00
|
|
|
.version = PACKAGE_VERSION,
|
|
|
|
.go_parent_cb = bsc_vty_go_parent,
|
2010-08-26 07:38:42 +00:00
|
|
|
.is_config_node = bsc_vty_is_config_node,
|
2010-06-30 06:59:23 +00:00
|
|
|
};
|
|
|
|
|
2010-09-15 14:29:25 +00:00
|
|
|
extern int bsc_shutdown_net(struct gsm_network *net);
|
|
|
|
static void signal_handler(int signal)
|
|
|
|
{
|
2011-06-04 17:58:26 +00:00
|
|
|
struct osmo_msc_data *msc;
|
|
|
|
|
2010-09-15 14:29:25 +00:00
|
|
|
fprintf(stdout, "signal %u received\n", signal);
|
|
|
|
|
|
|
|
switch (signal) {
|
|
|
|
case SIGINT:
|
|
|
|
bsc_shutdown_net(bsc_gsmnet);
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL);
|
2010-09-15 14:29:25 +00:00
|
|
|
sleep(3);
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case SIGABRT:
|
|
|
|
/* in case of abort, we want to obtain a talloc report
|
|
|
|
* and then return to the caller, who will abort the process */
|
|
|
|
case SIGUSR1:
|
|
|
|
talloc_report(tall_vty_ctx, stderr);
|
|
|
|
talloc_report_full(tall_bsc_ctx, stderr);
|
|
|
|
break;
|
|
|
|
case SIGUSR2:
|
2011-08-15 13:53:00 +00:00
|
|
|
if (!bsc_gsmnet->bsc_data)
|
2010-09-15 14:29:25 +00:00
|
|
|
return;
|
2011-06-04 17:58:26 +00:00
|
|
|
llist_for_each_entry(msc, &bsc_gsmnet->bsc_data->mscs, entry)
|
|
|
|
bsc_msc_lost(msc->msc_con);
|
2010-09-15 14:29:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-30 06:33:01 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2011-06-04 17:58:26 +00:00
|
|
|
struct osmo_msc_data *msc;
|
2011-08-15 13:53:00 +00:00
|
|
|
struct osmo_bsc_data *data;
|
2010-06-30 06:59:23 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc");
|
2011-05-12 14:02:07 +00:00
|
|
|
|
|
|
|
osmo_init_logging(&log_info);
|
2010-06-30 06:59:23 +00:00
|
|
|
|
bsc: on-demand setup of nanoBTS and HSL femto sockets
The daemons set up nanoBTS and HSL femto sockets by default, ie. the
three sockets to support these two drivers are open even if we have
no BTS of that kind.
This patch enables on-demand socket creation, ie. we only enable them
if we have one BTS at least that requires it.
I added two new attributes to the gsm_bts object, they are:
* the start() function includes the code that we need to run to start
the BTS. This new function contains the socket creation in the
particular case of nanoBTS and HSL femto.
* the started boolean, which is used to know if we have already
started the BTS, ie. we have already invoked start().
Note that, I have splitted the bts_model_*_init() function into two
functions, the _init() functions that register the BTS driver
and the _start() functions that start BTS driver on-demand.
While I was at it, I added several changes/cleanups to this patch:
* Group all bts_model_*_init() calls into one function bts_init(),
which is called in the initialization path of osmo-nitb and
osmo-bsc.
* Add openbsc/bss.h that contains the declaration of
bsc_bootstrap_network, bsc_shutdown_net and bts_init.
* Add missing e1inp_init() in osmo-bsc.
* Fix missing declaration of hsl_setup in openbsc/e1_input.h
2011-05-14 09:32:48 +00:00
|
|
|
bts_init();
|
src: port openBSC over libosmo-abis
This is a big patch that ports openBSC over libosmo-abis.
Sorry, the changes that are included here are all dependent
of libosmo-abis, splitting them into smaller pieces would
leave the repository in some intermediate state, which is
not desired.
The main changes are:
- The directory libabis/ has been removed as it now lives in
libosmo-abis.
- new configuration file format for nanoBTS and HSL femto, we
need to define the virtual e1_line and attach it to the OML
link.
- all the existing BTS drivers (nanoBTS, hsl femto, Nokia site,
BS11 and rbs2000) now use the new libosmo-abis framework.
- use r232 input driver available in libosmo-abis for bs11_config.
- use ipa_msg_recv instead of old ipaccess_read_msg function.
- delete definition of gsm_e1_subslot and input_signal_data.
These structures now lives in libosmo-abis.
Most of this patch are deletions of libabis/ which has been
moved to libosmo-abis.
This patch also modifies openBSC to use all the new definitions
available in libosmocore and libosmo-abis. In order to do that,
we have replaced the following:
- DINP, DMI, DMIB and DMUX by their respective DL* correspondences.
- SS_GLOBAL by SS_L_GLOBAL
- SS_INPUT by SS_L_INPUT
- S_GLOBAL_SHUTDOWN by S_L_GLOBAL_SHUTDOWN
- SS_INPUT by SS_L_INPUT
- S_INP_* by S_L_INP_* sub-signals
- E1INP_NODE by L_E1INP_NODE vty node
This patch has been tested with:
- one nanoBTS
- the HSL femto with the examples available under libosmo-abis
- BS11 with both dahdi and misdn drivers.
2011-08-17 20:44:07 +00:00
|
|
|
libosmo_abis_init(tall_bsc_ctx);
|
2010-06-30 06:59:23 +00:00
|
|
|
|
|
|
|
/* enable filters */
|
|
|
|
|
|
|
|
/* This needs to precede handle_options() */
|
2010-09-11 05:28:42 +00:00
|
|
|
vty_info.copyright = openbsc_copyright;
|
2010-06-30 06:59:23 +00:00
|
|
|
vty_init(&vty_info);
|
2011-03-09 12:36:32 +00:00
|
|
|
bsc_vty_init(&log_info);
|
2010-06-30 06:59:23 +00:00
|
|
|
|
|
|
|
/* parse options */
|
|
|
|
handle_options(argc, argv);
|
|
|
|
|
|
|
|
/* seed the PRNG */
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2010-07-29 18:53:14 +00:00
|
|
|
/* initialize SCCP */
|
|
|
|
sccp_set_log_area(DSCCP);
|
|
|
|
|
2010-06-30 06:59:23 +00:00
|
|
|
|
|
|
|
rc = bsc_bootstrap_network(NULL, config_file);
|
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "Bootstrapping the network failed. exiting.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-09-16 09:26:35 +00:00
|
|
|
bsc_api_init(bsc_gsmnet, osmo_bsc_api());
|
2010-06-30 06:59:23 +00:00
|
|
|
|
2014-03-23 15:25:16 +00:00
|
|
|
bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, 4249);
|
2011-08-05 10:22:35 +00:00
|
|
|
if (!bsc_gsmnet) {
|
|
|
|
fprintf(stderr, "Failed to init the control interface. Exiting.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-07-22 15:55:42 +00:00
|
|
|
|
2011-10-28 12:23:48 +00:00
|
|
|
rc = bsc_ctrl_cmds_install(bsc_gsmnet);
|
2011-08-05 10:22:35 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "Failed to install control commands. Exiting.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-02-18 13:30:25 +00:00
|
|
|
|
2011-08-15 13:53:00 +00:00
|
|
|
data = bsc_gsmnet->bsc_data;
|
2011-06-04 07:32:35 +00:00
|
|
|
if (rf_ctrl)
|
|
|
|
bsc_replace_string(data, &data->rf_ctrl_name, rf_ctrl);
|
2011-04-07 21:23:27 +00:00
|
|
|
|
2014-02-07 19:07:51 +00:00
|
|
|
data->rf_ctrl = osmo_bsc_rf_create(data->rf_ctrl_name, bsc_gsmnet);
|
|
|
|
if (!data->rf_ctrl) {
|
|
|
|
fprintf(stderr, "Failed to create the RF service.\n");
|
|
|
|
exit(1);
|
2010-06-30 06:59:23 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 17:58:26 +00:00
|
|
|
llist_for_each_entry(msc, &bsc_gsmnet->bsc_data->mscs, entry) {
|
|
|
|
if (osmo_bsc_msc_init(msc) != 0) {
|
|
|
|
LOGP(DNAT, LOGL_ERROR, "Failed to start up. Exiting.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-09-15 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 17:58:26 +00:00
|
|
|
|
2010-11-03 15:40:03 +00:00
|
|
|
if (osmo_bsc_sccp_init(bsc_gsmnet) != 0) {
|
|
|
|
LOGP(DNM, LOGL_ERROR, "Failed to register SCCP.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-14 19:38:06 +00:00
|
|
|
if (osmo_bsc_audio_init(bsc_gsmnet) != 0) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "Failed to register audio support.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-09-15 14:29:25 +00:00
|
|
|
signal(SIGINT, &signal_handler);
|
|
|
|
signal(SIGABRT, &signal_handler);
|
|
|
|
signal(SIGUSR1, &signal_handler);
|
|
|
|
signal(SIGUSR2, &signal_handler);
|
2011-05-12 14:02:07 +00:00
|
|
|
osmo_init_ignore_signals();
|
2010-09-15 14:29:25 +00:00
|
|
|
|
2010-08-25 17:43:54 +00:00
|
|
|
if (daemonize) {
|
|
|
|
rc = osmo_daemonize();
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("Error during daemonize");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2010-06-30 06:59:23 +00:00
|
|
|
|
|
|
|
while (1) {
|
2011-05-06 10:11:23 +00:00
|
|
|
osmo_select_main(0);
|
2010-06-30 06:59:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-30 06:33:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|