2008-12-23 20:25:15 +00:00
|
|
|
/* A hackish minimal BSC (+MSC +HLR) implementation */
|
|
|
|
|
2010-01-12 09:46:27 +00:00
|
|
|
/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
|
2009-01-02 22:04:43 +00:00
|
|
|
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
|
2008-12-23 20:25:15 +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
|
2008-12-23 20:25:15 +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.
|
2008-12-23 20:25:15 +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/>.
|
2008-12-23 20:25:15 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-12-26 00:05:11 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
2008-12-26 10:20:07 +00:00
|
|
|
#include <errno.h>
|
2009-01-01 01:50:32 +00:00
|
|
|
#include <signal.h>
|
2009-01-02 00:40:15 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2008-12-27 12:46:51 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2008-12-28 02:26:27 +00:00
|
|
|
#include <openbsc/db.h>
|
2011-05-12 14:02:07 +00:00
|
|
|
#include <osmocom/core/application.h>
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/select.h>
|
|
|
|
#include <osmocom/core/process.h>
|
2008-12-26 20:25:35 +00:00
|
|
|
#include <openbsc/debug.h>
|
2009-02-09 18:13:26 +00:00
|
|
|
#include <openbsc/e1_input.h>
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2009-11-30 18:37:18 +00:00
|
|
|
#include <openbsc/signal.h>
|
2010-06-30 06:30:35 +00:00
|
|
|
#include <openbsc/osmo_msc.h>
|
2011-02-19 15:48:17 +00:00
|
|
|
#include <openbsc/sms_queue.h>
|
2010-08-26 07:38:42 +00:00
|
|
|
#include <openbsc/vty.h>
|
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
|
|
|
#include <openbsc/bss.h>
|
2011-05-24 11:25:38 +00:00
|
|
|
#include <openbsc/mncc.h>
|
2010-05-16 18:52:23 +00:00
|
|
|
|
2011-03-04 12:53:51 +00:00
|
|
|
#include "../../bscconfig.h"
|
2010-05-16 18:52:23 +00:00
|
|
|
|
2008-12-28 14:14:56 +00:00
|
|
|
/* MCC and MNC for the Location Area Identifier */
|
2009-08-17 04:55:10 +00:00
|
|
|
struct gsm_network *bsc_gsmnet = 0;
|
2008-12-28 22:51:39 +00:00
|
|
|
static const char *database_name = "hlr.sqlite3";
|
2009-08-10 06:39:27 +00:00
|
|
|
static const char *config_file = "openbsc.cfg";
|
2010-05-16 18:52:23 +00:00
|
|
|
extern const char *openbsc_copyright;
|
2010-08-25 17:43:54 +00:00
|
|
|
static int daemonize = 0;
|
2010-12-23 00:31:07 +00:00
|
|
|
static int use_mncc_sock = 0;
|
2009-12-23 04:29:04 +00:00
|
|
|
|
|
|
|
/* timer to store statistics */
|
|
|
|
#define DB_SYNC_INTERVAL 60, 0
|
2011-05-06 10:11:06 +00:00
|
|
|
static struct osmo_timer_list db_sync_timer;
|
2009-12-23 04:29:04 +00:00
|
|
|
|
2009-01-02 00:40:15 +00:00
|
|
|
static void create_pcap_file(char *file)
|
|
|
|
{
|
|
|
|
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
|
|
|
int fd = open(file, O_WRONLY|O_TRUNC|O_CREAT, mode);
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("Failed to open file for pcap");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-31 12:14:16 +00:00
|
|
|
e1_set_pcap_fd(fd);
|
2009-01-02 00:40:15 +00:00
|
|
|
}
|
|
|
|
|
2008-12-27 12:46:51 +00:00
|
|
|
static void print_usage()
|
|
|
|
{
|
|
|
|
printf("Usage: bsc_hack\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_help()
|
|
|
|
{
|
|
|
|
printf(" Some useful help...\n");
|
2009-08-08 14:12:58 +00:00
|
|
|
printf(" -h --help this text\n");
|
2008-12-27 12:46:51 +00:00
|
|
|
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
|
2010-08-25 17:43:54 +00:00
|
|
|
printf(" -D --daemonize Fork the process into a background daemon\n");
|
2009-08-10 06:39:27 +00:00
|
|
|
printf(" -c --config-file filename The config file to use.\n");
|
2010-03-25 01:41:38 +00:00
|
|
|
printf(" -s --disable-color\n");
|
2008-12-28 22:51:39 +00:00
|
|
|
printf(" -l --database db-name The database to use\n");
|
2010-03-25 01:41:38 +00:00
|
|
|
printf(" -a --authorize-everyone. Authorize every new subscriber. Dangerous!.\n");
|
2009-01-02 00:40:15 +00:00
|
|
|
printf(" -p --pcap file The filename of the pcap file\n");
|
2009-08-12 19:52:11 +00:00
|
|
|
printf(" -T --timestamp Prefix every log line with a timestamp\n");
|
2010-03-25 01:41:38 +00:00
|
|
|
printf(" -V --version. Print the version of OpenBSC.\n");
|
2009-12-18 14:05:02 +00:00
|
|
|
printf(" -P --rtp-proxy Enable the RTP Proxy code inside OpenBSC\n");
|
2010-03-25 01:39:15 +00:00
|
|
|
printf(" -e --log-level number. Set a global loglevel.\n");
|
2010-12-23 00:31:07 +00:00
|
|
|
printf(" -m --mncc-sock Disable built-in MNCC handler and offer socket\n");
|
2008-12-27 12:46:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 22:44:24 +00:00
|
|
|
static void handle_options(int argc, char **argv)
|
2008-12-27 12:46:51 +00:00
|
|
|
{
|
|
|
|
while (1) {
|
2009-06-20 20:36:41 +00:00
|
|
|
int option_index = 0, c;
|
2008-12-27 12:46:51 +00:00
|
|
|
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'},
|
2009-08-10 06:39:27 +00:00
|
|
|
{"config-file", 1, 0, 'c'},
|
2008-12-28 14:14:56 +00:00
|
|
|
{"disable-color", 0, 0, 's'},
|
2008-12-28 22:51:39 +00:00
|
|
|
{"database", 1, 0, 'l'},
|
2008-12-30 16:18:18 +00:00
|
|
|
{"authorize-everyone", 0, 0, 'a'},
|
2009-01-02 00:40:15 +00:00
|
|
|
{"pcap", 1, 0, 'p'},
|
2009-06-09 20:21:57 +00:00
|
|
|
{"timestamp", 0, 0, 'T'},
|
2010-03-22 16:09:32 +00:00
|
|
|
{"version", 0, 0, 'V' },
|
2009-07-28 16:25:29 +00:00
|
|
|
{"rtp-proxy", 0, 0, 'P'},
|
2010-03-25 01:39:15 +00:00
|
|
|
{"log-level", 1, 0, 'e'},
|
2010-12-23 00:31:07 +00:00
|
|
|
{"mncc-sock", 0, 0, 'm'},
|
2008-12-27 12:46:51 +00:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2010-12-23 00:31:07 +00:00
|
|
|
c = getopt_long(argc, argv, "hd:Dsl:ar:p:TPVc:e:m",
|
2008-12-27 12:46:51 +00:00
|
|
|
long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
print_usage();
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
2008-12-28 14:14:56 +00:00
|
|
|
case 's':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_use_color(osmo_stderr_target, 0);
|
2008-12-27 12:46:51 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_parse_category_mask(osmo_stderr_target, optarg);
|
2008-12-27 12:46:51 +00:00
|
|
|
break;
|
2010-08-25 17:43:54 +00:00
|
|
|
case 'D':
|
|
|
|
daemonize = 1;
|
|
|
|
break;
|
2009-01-06 18:09:02 +00:00
|
|
|
case 'l':
|
2008-12-28 22:51:39 +00:00
|
|
|
database_name = strdup(optarg);
|
|
|
|
break;
|
2009-08-10 06:39:27 +00:00
|
|
|
case 'c':
|
|
|
|
config_file = strdup(optarg);
|
|
|
|
break;
|
2009-01-02 00:40:15 +00:00
|
|
|
case 'p':
|
|
|
|
create_pcap_file(optarg);
|
|
|
|
break;
|
2009-06-09 20:21:57 +00:00
|
|
|
case 'T':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_print_timestamp(osmo_stderr_target, 1);
|
2009-06-09 20:21:57 +00:00
|
|
|
break;
|
2009-07-28 16:25:29 +00:00
|
|
|
case 'P':
|
|
|
|
ipacc_rtp_direct = 0;
|
|
|
|
break;
|
2010-03-25 01:39:15 +00:00
|
|
|
case 'e':
|
2011-05-12 14:02:07 +00:00
|
|
|
log_set_log_level(osmo_stderr_target, atoi(optarg));
|
2010-03-25 01:39:15 +00:00
|
|
|
break;
|
2010-12-23 00:31:07 +00:00
|
|
|
case 'm':
|
|
|
|
use_mncc_sock = 1;
|
|
|
|
break;
|
2010-03-22 16:09:32 +00:00
|
|
|
case 'V':
|
2010-05-16 17:20:24 +00:00
|
|
|
print_version(1);
|
2010-03-22 16:09:32 +00:00
|
|
|
exit(0);
|
|
|
|
break;
|
2008-12-27 12:46:51 +00:00
|
|
|
default:
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-24 09:51:56 +00:00
|
|
|
extern void *tall_vty_ctx;
|
2009-01-01 01:50:32 +00:00
|
|
|
static void signal_handler(int signal)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "signal %u received\n", signal);
|
|
|
|
|
|
|
|
switch (signal) {
|
2009-08-06 15:43:50 +00:00
|
|
|
case SIGINT:
|
2009-08-17 04:55:10 +00:00
|
|
|
bsc_shutdown_net(bsc_gsmnet);
|
2011-05-06 10:12:31 +00:00
|
|
|
osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL);
|
2009-08-06 15:43:50 +00:00
|
|
|
sleep(3);
|
|
|
|
exit(0);
|
2009-01-01 01:50:32 +00:00
|
|
|
break;
|
2009-08-06 22:29:44 +00:00
|
|
|
case SIGABRT:
|
|
|
|
/* in case of abort, we want to obtain a talloc report
|
|
|
|
* and then return to the caller, who will abort the process */
|
2009-06-20 20:36:41 +00:00
|
|
|
case SIGUSR1:
|
2009-12-24 09:51:56 +00:00
|
|
|
talloc_report(tall_vty_ctx, stderr);
|
2009-06-20 20:36:41 +00:00
|
|
|
talloc_report_full(tall_bsc_ctx, stderr);
|
|
|
|
break;
|
2009-12-24 09:51:56 +00:00
|
|
|
case SIGUSR2:
|
|
|
|
talloc_report_full(tall_vty_ctx, stderr);
|
|
|
|
break;
|
2009-01-01 01:50:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-23 04:29:04 +00:00
|
|
|
/* timer handling */
|
2011-05-06 10:13:10 +00:00
|
|
|
static int _db_store_counter(struct osmo_counter *counter, void *data)
|
2009-12-23 04:29:04 +00:00
|
|
|
{
|
|
|
|
return db_store_counter(counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void db_sync_timer_cb(void *data)
|
|
|
|
{
|
|
|
|
/* store counters to database and re-schedule */
|
2011-05-06 10:13:10 +00:00
|
|
|
osmo_counters_for_each(_db_store_counter, NULL);
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_schedule(&db_sync_timer, DB_SYNC_INTERVAL);
|
2009-12-23 04:29:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 15:48:17 +00:00
|
|
|
void talloc_ctx_init(void);
|
2010-01-10 17:01:52 +00:00
|
|
|
|
2010-06-08 08:11:06 +00:00
|
|
|
extern enum node_type bsc_vty_go_parent(struct vty *vty);
|
2010-05-25 21:31:39 +00:00
|
|
|
|
|
|
|
static struct vty_app_info vty_info = {
|
|
|
|
.name = "OpenBSC",
|
|
|
|
.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-05-25 21:31:39 +00:00
|
|
|
};
|
|
|
|
|
2008-12-26 00:05:11 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2009-02-09 18:13:26 +00:00
|
|
|
int rc;
|
|
|
|
|
2010-05-25 21:31:39 +00:00
|
|
|
vty_info.copyright = openbsc_copyright;
|
|
|
|
|
2009-06-20 20:36:41 +00:00
|
|
|
tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc");
|
2009-08-15 00:30:58 +00:00
|
|
|
talloc_ctx_init();
|
2009-08-13 11:52:14 +00:00
|
|
|
on_dso_load_token();
|
2009-08-16 11:18:51 +00:00
|
|
|
on_dso_load_rrlp();
|
2009-12-16 23:31:10 +00:00
|
|
|
on_dso_load_ho_dec();
|
2011-05-12 14:02:07 +00:00
|
|
|
|
|
|
|
osmo_init_logging(&log_info);
|
2009-12-22 21:32:51 +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();
|
2011-02-05 12:54:41 +00:00
|
|
|
e1inp_init();
|
|
|
|
|
2010-05-16 18:52:23 +00:00
|
|
|
/* This needs to precede handle_options() */
|
2010-05-25 21:31:39 +00:00
|
|
|
vty_init(&vty_info);
|
2011-03-09 12:36:32 +00:00
|
|
|
bsc_vty_init(&log_info);
|
2010-05-16 18:52:23 +00:00
|
|
|
|
2010-05-31 13:42:53 +00:00
|
|
|
/* parse options */
|
|
|
|
handle_options(argc, argv);
|
|
|
|
|
2010-12-23 00:31:07 +00:00
|
|
|
/* internal MNCC handler or MNCC socket? */
|
|
|
|
if (use_mncc_sock) {
|
|
|
|
rc = bsc_bootstrap_network(mncc_sock_from_cc, config_file);
|
|
|
|
if (rc >= 0)
|
|
|
|
mncc_sock_init(bsc_gsmnet);
|
|
|
|
} else
|
|
|
|
rc = bsc_bootstrap_network(int_mncc_recv, config_file);
|
2010-05-16 17:20:24 +00:00
|
|
|
if (rc < 0)
|
|
|
|
exit(1);
|
2010-06-30 06:30:35 +00:00
|
|
|
bsc_api_init(bsc_gsmnet, msc_bsc_api());
|
2010-05-16 17:20:24 +00:00
|
|
|
|
2009-02-24 22:36:20 +00:00
|
|
|
/* seed the PRNG */
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2009-08-17 04:55:10 +00:00
|
|
|
if (db_init(database_name)) {
|
|
|
|
printf("DB: Failed to init database. Please check the option settings.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf("DB: Database initialized.\n");
|
|
|
|
|
|
|
|
if (db_prepare()) {
|
|
|
|
printf("DB: Failed to prepare database.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf("DB: Database prepared.\n");
|
|
|
|
|
2009-12-23 04:29:04 +00:00
|
|
|
/* setup the timer */
|
|
|
|
db_sync_timer.cb = db_sync_timer_cb;
|
|
|
|
db_sync_timer.data = NULL;
|
2011-05-06 10:11:06 +00:00
|
|
|
osmo_timer_schedule(&db_sync_timer, DB_SYNC_INTERVAL);
|
2009-12-23 04:29:04 +00:00
|
|
|
|
2009-08-06 15:43:50 +00:00
|
|
|
signal(SIGINT, &signal_handler);
|
2009-01-01 01:50:32 +00:00
|
|
|
signal(SIGABRT, &signal_handler);
|
2009-06-20 20:36:41 +00:00
|
|
|
signal(SIGUSR1, &signal_handler);
|
2009-12-24 09:51:56 +00:00
|
|
|
signal(SIGUSR2, &signal_handler);
|
2011-05-12 14:02:07 +00:00
|
|
|
osmo_init_ignore_signals();
|
2009-01-01 01:50:32 +00:00
|
|
|
|
2010-12-24 12:48:27 +00:00
|
|
|
/* start the SMS queue */
|
2010-12-25 16:43:03 +00:00
|
|
|
if (sms_queue_start(bsc_gsmnet, 20) != 0)
|
2010-12-24 12:48:27 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-08-25 17:43:54 +00:00
|
|
|
if (daemonize) {
|
|
|
|
rc = osmo_daemonize();
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("Error during daemonize");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-26 00:05:11 +00:00
|
|
|
while (1) {
|
2010-03-26 13:28:59 +00:00
|
|
|
log_reset_context();
|
2011-05-06 10:11:23 +00:00
|
|
|
osmo_select_main(0);
|
2008-12-26 00:05:11 +00:00
|
|
|
}
|
|
|
|
}
|