diff options
-rw-r--r-- | src/host/layer23/include/osmocom/bb/common/l23_app.h | 3 | ||||
-rw-r--r-- | src/host/layer23/src/common/main.c | 51 | ||||
-rw-r--r-- | src/host/layer23/src/misc/app_cell_log.c | 26 | ||||
-rw-r--r-- | src/host/layer23/src/misc/cell_log.c | 2 |
4 files changed, 69 insertions, 13 deletions
diff --git a/src/host/layer23/include/osmocom/bb/common/l23_app.h b/src/host/layer23/include/osmocom/bb/common/l23_app.h index 46141e13..fcfd4bdf 100644 --- a/src/host/layer23/include/osmocom/bb/common/l23_app.h +++ b/src/host/layer23/include/osmocom/bb/common/l23_app.h @@ -21,7 +21,10 @@ struct l23_app_info { const char *copyright; const char *contribution; + char *getopt_string; int (*cfg_supported)(); + int (*cfg_print_help)(); + int (*cfg_handle_opt)(int c,const char *optarg); }; extern struct l23_app_info *l23_app_info(); diff --git a/src/host/layer23/src/common/main.c b/src/host/layer23/src/common/main.c index 1f9afafa..a791ccf4 100644 --- a/src/host/layer23/src/common/main.c +++ b/src/host/layer23/src/common/main.c @@ -35,6 +35,7 @@ #include <osmocore/select.h> #include <osmocore/linuxlist.h> #include <osmocore/gsmtap_util.h> +#include <osmocore/utils.h> #include <arpa/inet.h> @@ -101,25 +102,46 @@ static void print_help() if (options & L23_OPT_DBG) printf(" -d --debug Change debug flags.\n"); + + if (app && app->cfg_print_help) + app->cfg_print_help(); +} + +static void build_config(char **opt, struct option **option) +{ + struct l23_app_info *app; + static struct option long_options[] = { + {"help", 0, 0, 'h'}, + {"socket", 1, 0, 's'}, + {"sap", 1, 0, 'S'}, + {"arfcn", 1, 0, 'a'}, + {"gsmtap-ip", 1, 0, 'i'}, + {"vty-port", 1, 0, 'v'}, + {"debug", 1, 0, 'd'}, + }; + + + app = l23_app_info(); + *opt = talloc_asprintf(l23_ctx, "hs:S:a:i:v:d:%s", + app && app->getopt_string ? app->getopt_string : ""); + *option = talloc_zero_array(l23_ctx, struct option, + ARRAY_SIZE(long_options) + 1); + memcpy(*option, long_options, sizeof(long_options)); } static void handle_options(int argc, char **argv) { struct sockaddr_in gsmtap; + struct l23_app_info *app = l23_app_info(); + struct option *long_options; + char *opt; + + build_config(&opt, &long_options); + while (1) { int option_index = 0, c; - static struct option long_options[] = { - {"help", 0, 0, 'h'}, - {"socket", 1, 0, 's'}, - {"sap", 1, 0, 'S'}, - {"arfcn", 1, 0, 'a'}, - {"gsmtap-ip", 1, 0, 'i'}, - {"vty-port", 1, 0, 'v'}, - {"debug", 1, 0, 'd'}, - {0, 0, 0, 0}, - }; - - c = getopt_long(argc, argv, "hs:S:a:i:v:d:", + + c = getopt_long(argc, argv, opt, long_options, &option_index); if (c == -1) break; @@ -153,9 +175,14 @@ static void handle_options(int argc, char **argv) log_parse_category_mask(stderr_target, optarg); break; default: + if (app && app->cfg_handle_opt) + app->cfg_handle_opt(c, optarg); break; } } + + talloc_free(opt); + talloc_free(long_options); } void sighandler(int sigset) diff --git a/src/host/layer23/src/misc/app_cell_log.c b/src/host/layer23/src/misc/app_cell_log.c index a72588f7..e80a7b25 100644 --- a/src/host/layer23/src/misc/app_cell_log.c +++ b/src/host/layer23/src/misc/app_cell_log.c @@ -30,7 +30,12 @@ #include <osmocom/bb/common/logging.h> #include <osmocom/bb/misc/cell_log.h> +#include <osmocore/talloc.h> + extern struct log_target *stderr_target; +extern void *l23_ctx; + +char *logname = "/var/log/osmocom.log"; int _scan_work(struct osmocom_ms *ms) { @@ -77,9 +82,30 @@ static int l23_cfg_supported() return L23_OPT_TAP | L23_OPT_DBG; } +static int l23_cfg_print_help() +{ + printf("\nApplication specific\n"); + printf(" -l --logfile LOGFILE Logfile for the cell log.\n"); + return 0; +} + +static int l23_cfg_handle(int c, const char *optarg) +{ + switch (c) { + case 'l': + logname = talloc_strdup(l23_ctx, optarg); + break; + } + + return 0; +} + static struct l23_app_info info = { .copyright = "Copyright (C) 2010 Andreas Eversberg\n", + .getopt_string = "l:", .cfg_supported = l23_cfg_supported, + .cfg_handle_opt = l23_cfg_handle, + .cfg_print_help = l23_cfg_print_help, }; struct l23_app_info *l23_app_info() diff --git a/src/host/layer23/src/misc/cell_log.c b/src/host/layer23/src/misc/cell_log.c index 1034ffad..ce68ef06 100644 --- a/src/host/layer23/src/misc/cell_log.c +++ b/src/host/layer23/src/misc/cell_log.c @@ -88,7 +88,7 @@ static double pm_gps_x, pm_gps_y, pm_gps_z; static int arfcn; static int rach_count; static FILE *logfp = NULL; -static char *logname = "/var/log/osmocom.log"; +extern char *logname; static struct gsm48_sysinfo sysinfo; |