logging: Add vty to allow definition/storage of debug levels
Note: This requires new libosomocore that allows to compile VTY headers with C++.
This commit is contained in:
parent
1294256d65
commit
ebde64f258
|
@ -33,7 +33,8 @@ libgprs_la_SOURCES = \
|
||||||
gprs_rlcmac_sched.cpp \
|
gprs_rlcmac_sched.cpp \
|
||||||
gsm_timer.cpp \
|
gsm_timer.cpp \
|
||||||
bitvector.cpp \
|
bitvector.cpp \
|
||||||
pcu_l1_if.cpp
|
pcu_l1_if.cpp \
|
||||||
|
pcu_vty.c
|
||||||
|
|
||||||
if ENABLE_SYSMOBTS
|
if ENABLE_SYSMOBTS
|
||||||
libgprs_la_SOURCES += \
|
libgprs_la_SOURCES += \
|
||||||
|
@ -56,7 +57,8 @@ noinst_HEADERS = \
|
||||||
pcuif_proto.h \
|
pcuif_proto.h \
|
||||||
pcu_l1_if.h \
|
pcu_l1_if.h \
|
||||||
gsm_timer.h \
|
gsm_timer.h \
|
||||||
bitvector.h
|
bitvector.h \
|
||||||
|
pcu_vty.h
|
||||||
|
|
||||||
RLCMACTest_SOURCES = RLCMACTest.cpp
|
RLCMACTest_SOURCES = RLCMACTest.cpp
|
||||||
RLCMACTest_LDADD = \
|
RLCMACTest_LDADD = \
|
||||||
|
|
|
@ -25,15 +25,26 @@
|
||||||
#include <gprs_debug.h>
|
#include <gprs_debug.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.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;
|
struct gprs_rlcmac_bts *gprs_rlcmac_bts;
|
||||||
extern struct gprs_nsvc *nsvc;
|
extern struct gprs_nsvc *nsvc;
|
||||||
uint16_t spoof_mcc = 0, spoof_mnc = 0;
|
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 void print_help()
|
static void print_help()
|
||||||
{
|
{
|
||||||
printf( "Some useful options:\n"
|
printf( "Some useful options:\n"
|
||||||
" -h --help this text\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 "
|
" -m --mcc MCC use given MCC instead of value "
|
||||||
"provided by BTS\n"
|
"provided by BTS\n"
|
||||||
" -n --mnc MNC use given MNC instead of value "
|
" -n --mnc MNC use given MNC instead of value "
|
||||||
|
@ -48,12 +59,13 @@ static void handle_options(int argc, char **argv)
|
||||||
int option_idx = 0, c;
|
int option_idx = 0, c;
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
{ "help", 0, 0, 'h' },
|
{ "help", 0, 0, 'h' },
|
||||||
|
{ "config-file", 1, 0, 'c' },
|
||||||
{ "mcc", 1, 0, 'm' },
|
{ "mcc", 1, 0, 'm' },
|
||||||
{ "mnc", 1, 0, 'n' },
|
{ "mnc", 1, 0, 'n' },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "hm:n:",
|
c = getopt_long(argc, argv, "hc:m:n:",
|
||||||
long_options, &option_idx);
|
long_options, &option_idx);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
@ -63,6 +75,10 @@ static void handle_options(int argc, char **argv)
|
||||||
print_help();
|
print_help();
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
config_file = strdup(optarg);
|
||||||
|
config_given = 1;
|
||||||
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
spoof_mcc = atoi(optarg);
|
spoof_mcc = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
@ -82,7 +98,12 @@ int main(int argc, char *argv[])
|
||||||
struct gprs_rlcmac_bts *bts;
|
struct gprs_rlcmac_bts *bts;
|
||||||
int rc;
|
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)
|
if (!gprs_rlcmac_bts)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
gprs_rlcmac_bts->initial_cs = 1;
|
gprs_rlcmac_bts->initial_cs = 1;
|
||||||
|
@ -99,12 +120,32 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
osmo_init_logging(&gprs_log_info);
|
osmo_init_logging(&gprs_log_info);
|
||||||
|
|
||||||
|
vty_init(&pcu_vty_info);
|
||||||
|
pcu_vty_init(&gprs_log_info);
|
||||||
|
|
||||||
handle_options(argc, argv);
|
handle_options(argc, argv);
|
||||||
if ((!!spoof_mcc) + (!!spoof_mnc) == 1) {
|
if ((!!spoof_mcc) + (!!spoof_mnc) == 1) {
|
||||||
fprintf(stderr, "--mcc and --mnc must be specified "
|
fprintf(stderr, "--mcc and --mnc must be specified "
|
||||||
"together.\n");
|
"together.\n");
|
||||||
exit(0);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
rc = pcu_l1if_open();
|
rc = pcu_l1if_open();
|
||||||
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
@ -121,6 +162,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
pcu_l1if_close();
|
pcu_l1if_close();
|
||||||
talloc_free(gprs_rlcmac_bts);
|
talloc_free(gprs_rlcmac_bts);
|
||||||
|
talloc_free(tall_pcu_ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue