aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcu_main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pcu_main.cpp')
-rw-r--r--src/pcu_main.cpp107
1 files changed, 101 insertions, 6 deletions
diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp
index 6c30c1e4..ee6f70c4 100644
--- a/src/pcu_main.cpp
+++ b/src/pcu_main.cpp
@@ -25,15 +25,28 @@
#include <gprs_debug.h>
#include <unistd.h>
#include <getopt.h>
+#include <signal.h>
+extern "C" {
+#include "pcu_vty.h"
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/vty/logging.h>
+}
struct gprs_rlcmac_bts *gprs_rlcmac_bts;
extern struct gprs_nsvc *nsvc;
uint16_t spoof_mcc = 0, spoof_mnc = 0;
+static int config_given = 0;
+static const char *config_file = "osmo-pcu.cfg";
+extern struct vty_app_info pcu_vty_info;
+void *tall_pcu_ctx;
+static int quit = 0;
static void print_help()
{
printf( "Some useful options:\n"
" -h --help this text\n"
+ " -c --config-file Specify the filename of the config "
+ "file\n"
" -m --mcc MCC use given MCC instead of value "
"provided by BTS\n"
" -n --mnc MNC use given MNC instead of value "
@@ -48,12 +61,13 @@ static void handle_options(int argc, char **argv)
int option_idx = 0, c;
static const struct option long_options[] = {
{ "help", 0, 0, 'h' },
+ { "config-file", 1, 0, 'c' },
{ "mcc", 1, 0, 'm' },
{ "mnc", 1, 0, 'n' },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hm:n:",
+ c = getopt_long(argc, argv, "hc:m:n:",
long_options, &option_idx);
if (c == -1)
break;
@@ -63,6 +77,10 @@ static void handle_options(int argc, char **argv)
print_help();
exit(0);
break;
+ case 'c':
+ config_file = strdup(optarg);
+ config_given = 1;
+ break;
case 'm':
spoof_mcc = atoi(optarg);
break;
@@ -77,16 +95,54 @@ static void handle_options(int argc, char **argv)
}
}
+void sighandler(int sigset)
+{
+ if (sigset == SIGHUP || sigset == SIGPIPE)
+ return;
+
+ fprintf(stderr, "Signal %d received.\n", sigset);
+
+ switch (sigset) {
+ case SIGINT:
+ /* If another signal is received afterwards, the program
+ * is terminated without finishing shutdown process.
+ */
+ signal(SIGINT, SIG_DFL);
+ signal(SIGHUP, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ signal(SIGPIPE, SIG_DFL);
+ signal(SIGABRT, SIG_DFL);
+ signal(SIGUSR1, SIG_DFL);
+ signal(SIGUSR2, SIG_DFL);
+
+ quit = 1;
+ 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:
+ case SIGUSR2:
+ talloc_report_full(tall_pcu_ctx, stderr);
+ break;
+ }
+}
+
int main(int argc, char *argv[])
{
struct gprs_rlcmac_bts *bts;
int rc;
- bts = gprs_rlcmac_bts = talloc_zero(NULL, struct gprs_rlcmac_bts);
+ tall_pcu_ctx = talloc_named_const(NULL, 1, "Osmo-PCU context");
+ if (!tall_pcu_ctx)
+ return -ENOMEM;
+
+ bts = gprs_rlcmac_bts = talloc_zero(tall_pcu_ctx,
+ struct gprs_rlcmac_bts);
if (!gprs_rlcmac_bts)
return -ENOMEM;
- gprs_rlcmac_bts->initial_cs = 1;
- bts->initial_cs = 1;
+ bts->fc_interval = 1;
+ bts->initial_cs_dl = bts->initial_cs_ul = 1;
bts->cs1 = 1;
bts->t3142 = 20;
bts->t3169 = 5;
@@ -96,22 +152,55 @@ int main(int argc, char *argv[])
bts->n3101 = 10;
bts->n3103 = 4;
bts->n3105 = 8;
+ bts->alpha = 10; /* a = 1.0 */
+
+ msgb_set_talloc_ctx(tall_pcu_ctx);
osmo_init_logging(&gprs_log_info);
+ vty_init(&pcu_vty_info);
+ pcu_vty_init(&gprs_log_info);
+
handle_options(argc, argv);
if ((!!spoof_mcc) + (!!spoof_mnc) == 1) {
fprintf(stderr, "--mcc and --mnc must be specified "
"together.\n");
exit(0);
}
+
+ rc = vty_read_config_file(config_file, NULL);
+ if (rc < 0 && config_given) {
+ fprintf(stderr, "Failed to parse the config file: '%s'\n",
+ config_file);
+ exit(1);
+ }
+ if (rc < 0)
+ fprintf(stderr, "No config file: '%s' Using default config.\n",
+ config_file);
+
+ rc = telnet_init(tall_pcu_ctx, NULL, 4240);
+ if (rc < 0) {
+ fprintf(stderr, "Error initializing telnet\n");
+ exit(1);
+ }
+
+ if (!bts->alloc_algorithm)
+ bts->alloc_algorithm = alloc_algorithm_b;
+
rc = pcu_l1if_open();
if (rc < 0)
return rc;
- while (1)
- {
+ signal(SIGINT, sighandler);
+ signal(SIGHUP, sighandler);
+ signal(SIGTERM, sighandler);
+ signal(SIGPIPE, sighandler);
+ signal(SIGABRT, sighandler);
+ signal(SIGUSR1, sighandler);
+ signal(SIGUSR2, sighandler);
+
+ while (!quit) {
osmo_gsm_timers_check();
osmo_gsm_timers_prepare();
osmo_gsm_timers_update();
@@ -119,8 +208,14 @@ int main(int argc, char *argv[])
osmo_select_main(0);
}
+ telnet_exit();
+
pcu_l1if_close();
+
talloc_free(gprs_rlcmac_bts);
+ talloc_report_full(tall_pcu_ctx, stderr);
+ talloc_free(tall_pcu_ctx);
+
return 0;
}