From 49f69810e9eb6e8ab7418e0e8d869d673c962159 Mon Sep 17 00:00:00 2001 From: "Wolfgang A. Mozart" Date: Sat, 27 Oct 2018 16:35:04 +0200 Subject: [PATCH 01/20] removing reference to uesoftmodem from load_configmodule (don't understand why this dependence is there in fist place. Also makes unitary sims break) --- common/config/config_load_configmodule.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c index 2c6700c73e..a41f395edd 100644 --- a/common/config/config_load_configmodule.c +++ b/common/config/config_load_configmodule.c @@ -201,13 +201,9 @@ int i; /* default */ if (cfgparam == NULL) { - tmpflags = tmpflags | CONFIG_NOOOPT; - if (strstr(argv[0],"uesoftmodem") == NULL) { - cfgparam = CONFIG_LIBCONFIGFILE ":" DEFAULT_CFGFILENAME; - } else { - cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ; - } - } + tmpflags = tmpflags | CONFIG_NOOOPT; + cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ; + } /* parse the config parameters to set the config source */ i = sscanf(cfgparam,"%m[^':']:%ms",&cfgmode,&modeparams); -- GitLab From d7e7d008068709efdc87694a3aa49cd7c3710d30 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 30 Oct 2018 15:11:01 +0100 Subject: [PATCH 02/20] removing use of a default config file --- common/config/config_load_configmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c index a41f395edd..ea6dc3fa86 100644 --- a/common/config/config_load_configmodule.c +++ b/common/config/config_load_configmodule.c @@ -209,13 +209,13 @@ int i; i = sscanf(cfgparam,"%m[^':']:%ms",&cfgmode,&modeparams); if (i< 0) { fprintf(stderr,"[CONFIG] %s, %d, sscanf error parsing config source %s: %s\n", __FILE__, __LINE__,cfgparam, strerror(errno)); - exit(-1); + exit(-1) ; } else if ( i == 1 ) { /* -O argument doesn't contain ":" separator, assume -O option, default cfgmode to libconfig with one parameter, the path to the configuration file */ modeparams=cfgmode; - cfgmode=strdup(CONFIG_LIBCONFIGFILE); + cfgmode=NULL; //strdup(CONFIG_LIBCONFIGFILE); } cfgptr = malloc(sizeof(configmodule_interface_t)); -- GitLab From 2811dc7c0def3dd94424400bb6d99833a2986253 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 30 Oct 2018 15:11:50 +0100 Subject: [PATCH 03/20] adding params_libconfig to compilation of phy_simulators --- cmake_targets/build_oai | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 3954827c09..37f8d711db 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -651,6 +651,9 @@ function main() { compilations \ lte-simulators coding \ libcoding.so $dbin/libcoding.so + compilations \ + phy_simulators $config_libconfig_shlib \ + lib$config_libconfig_shlib.so $dbin/lib$config_libconfig_shlib.so fi # Core simulators -- GitLab From 18ec5d8047a33cf15eb5d0710d6c53e7e5f3e355 Mon Sep 17 00:00:00 2001 From: frtabu Date: Fri, 2 Nov 2018 15:58:01 +0100 Subject: [PATCH 04/20] abort execution when an unknown option is passed via the command line: add config_check_cmdlineopt API to config module, create lte-softmodem-common.c source to remove duplicate code in lte-softmodem.c and lte-uesoftmodem.c, fix segfaults in exec_function of lte-uesoftmodem --- cmake_targets/CMakeLists.txt | 5 +- common/config/config_cmdline.c | 44 ++- common/config/config_load_configmodule.c | 13 +- common/config/config_load_configmodule.h | 10 +- common/config/config_paramdesc.h | 3 +- common/config/config_userapi.c | 20 +- common/config/config_userapi.h | 4 +- common/utils/LOG/log.c | 26 +- common/utils/LOG/log.h | 12 +- openair2/ENB_APP/enb_config.c | 18 +- openair2/LAYER2/MAC/eNB_scheduler.c | 6 +- openair2/LAYER2/MAC/ue_procedures.c | 3 +- openair2/RRC/LTE/MESSAGES/asn1_msg.c | 374 ++---------------- openair3/NAS/UE/EMM/Authentication.c | 9 +- .../UE/EMM/SAP/EmmDeregisteredNormalService.c | 6 +- targets/COMMON/create_tasks.c | 4 +- targets/RT/USER/lte-ru.c | 26 +- targets/RT/USER/lte-softmodem-common.c | 126 ++++++ targets/RT/USER/lte-softmodem.c | 178 ++------- targets/RT/USER/lte-softmodem.h | 155 +++++--- targets/RT/USER/lte-ue.c | 17 +- targets/RT/USER/lte-uesoftmodem.c | 179 +++------ targets/RT/USER/rfsim.c | 1 - 23 files changed, 488 insertions(+), 751 deletions(-) create mode 100644 targets/RT/USER/lte-softmodem-common.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index f205e3f5fa..143cd6fc7b 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -630,7 +630,6 @@ add_boolean_option(ENABLE_VCD True "always true now, time measurem add_boolean_option(ENABLE_VCD_FIFO True "time measurements of proc calls and var displays sent to FIFO (one more thread)") add_boolean_option(LINUX False "used in weird memcpy() in pdcp.c ???") add_boolean_option(LINUX_LIST False "used only in lists.c: either use OAI implementation of lists or Linux one (should be True, but it is False") -add_boolean_option(LOG_NO_THREAD True "Disable thread for log, seems always set to true") add_boolean_option(OPENAIR_LTE True "Seems legacy: keep it to true") ########################## @@ -1927,6 +1926,7 @@ add_executable(lte-softmodem ${OPENAIR_TARGETS}/RT/USER/lte-enb.c ${OPENAIR_TARGETS}/RT/USER/lte-ru.c ${OPENAIR_TARGETS}/RT/USER/lte-softmodem.c + ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c ${OPENAIR2_DIR}/ENB_APP/NB_IoT_interface.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c ${OPENAIR_TARGETS}/COMMON/create_tasks.c @@ -1966,6 +1966,7 @@ add_executable(lte-softmodem-nos1 ${OPENAIR_TARGETS}/RT/USER/lte-enb.c ${OPENAIR_TARGETS}/RT/USER/lte-ru.c ${OPENAIR_TARGETS}/RT/USER/lte-softmodem.c + ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c ${OPENAIR2_DIR}/ENB_APP/NB_IoT_interface.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c ${OPENAIR_TARGETS}/COMMON/create_tasks.c @@ -2003,6 +2004,7 @@ add_executable(lte-uesoftmodem ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c ${OPENAIR_TARGETS}/RT/USER/lte-ue.c ${OPENAIR_TARGETS}/RT/USER/lte-uesoftmodem.c + ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c ${OPENAIR_TARGETS}/RT/USER/lte-ru.c ${OPENAIR_TARGETS}/RT/USER/rfsim.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c @@ -2041,6 +2043,7 @@ add_executable(lte-uesoftmodem-nos1 ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c ${OPENAIR_TARGETS}/RT/USER/lte-ue.c ${OPENAIR_TARGETS}/RT/USER/lte-uesoftmodem.c + ${OPENAIR_TARGETS}/RT/USER/lte-softmodem-common.c ${OPENAIR_TARGETS}/RT/USER/lte-ru.c ${OPENAIR_TARGETS}/RT/USER/rfsim.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c diff --git a/common/config/config_cmdline.c b/common/config/config_cmdline.c index 3bd41cf6cc..c28cf33758 100644 --- a/common/config/config_cmdline.c +++ b/common/config/config_cmdline.c @@ -140,12 +140,43 @@ char defbool[2]="1"; return optisset; } +int config_check_cmdlineopt(char *prefix) +{ +int unknowndetected=0; +char testprefix[CONFIG_MAXOPTLENGTH]=""; +int finalcheck = 0; + + if (prefix != NULL) { + if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0) + finalcheck = 1; + else if (strlen(prefix) > 0) { + sprintf(testprefix,"--%s.",prefix); + } + } + + for (int i=1; iargc ; i++) { + if ( !finalcheck && strstr(config_get_if()->argv[i],testprefix) == NULL ) continue; + if ( !finalcheck && testprefix[0]==0 && index(config_get_if()->argv[i],'.') != NULL) continue; + if ( !finalcheck && config_get_if()->argv[i][0] == '-' && isdigit(config_get_if()->argv[i][1])) continue; + if ( (config_get_if()->argv_info[i] & CONFIG_CMDLINEOPT_PROCESSED) == 0 ) { + fprintf(stderr,"[CONFIG] unknown option: %s\n", + config_get_if()->argv[i] ); + unknowndetected++; + } + } + + + printf_cmdl("[CONFIG] %i unknown option(s) in command line starting with %s (section %s)\n", + unknowndetected,testprefix,((prefix==NULL)?"":prefix)); + return unknowndetected; +} /* parse_cmdline*/ + int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) { int c = config_get_if()->argc; int i,j; char *pp; - char cfgpath[512]; /* 512 should be enough for the sprintf below */ + char cfgpath[CONFIG_MAXOPTLENGTH]; j = 0; i = 0; @@ -155,6 +186,7 @@ int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) if (strncmp(oneargv, "-h",2) == 0 || strncmp(oneargv, "--help",6) == 0 ) { char *tokctx; pp=strtok_r(oneargv, "_",&tokctx); + config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; if (pp == NULL || strcasecmp(pp,config_get_if()->argv[i] ) == 0 ) { if( prefix == NULL) { config_printhelp(cfgoptions,numoptions); @@ -189,6 +221,7 @@ int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) ((strlen(oneargv) > 2) && (strcmp(oneargv + 2,cfgpath ) == 0 )) ) { char *valptr=NULL; int ret; + config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; if (c > 0) { pp = config_get_if()->argv[i+1]; if (pp != NULL ) { @@ -204,6 +237,7 @@ int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) j += processoption(&(cfgoptions[n]), valptr); if ( valptr != NULL ) { i++; + config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; c--; } break; @@ -215,5 +249,13 @@ int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) c--; } /* fin du while */ printf_cmdl("[CONFIG] %s %i options set from command line\n",((prefix == NULL) ? "(root)":prefix),j); + if ( !(CONFIG_ISFLAGSET( CONFIG_NOCHECKUNKOPT )) ) { + i=config_check_cmdlineopt(prefix); + if (i > 0) { + fprintf(stderr,"[CONFIG] %i unknown options for section %s detected in command line\n", + i,((prefix==NULL)?"\"root section\"":prefix)); + exit_fun(" Exiting after detecting errors in command line \n"); + } + } return j; } /* parse_cmdline*/ diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c index ea6dc3fa86..7c8c61135b 100644 --- a/common/config/config_load_configmodule.c +++ b/common/config/config_load_configmodule.c @@ -178,12 +178,14 @@ char *strtokctx=NULL; char *atoken; uint32_t tmpflags=0; int i; +int OoptIdx=-1; /* first parse the command line to look for the -O option */ for (i = 0;iargv_info = calloc(sizeof(int32_t), argc); + cfgptr->argv_info[0] |= CONFIG_CMDLINEOPT_PROCESSED; + if (OoptIdx >= 0) { + cfgptr->argv_info[OoptIdx] |= CONFIG_CMDLINEOPT_PROCESSED; + cfgptr->argv_info[OoptIdx+1] |= CONFIG_CMDLINEOPT_PROCESSED; + } cfgptr->rtflags = cfgptr->rtflags | tmpflags; cfgptr->argc = argc; diff --git a/common/config/config_load_configmodule.h b/common/config/config_load_configmodule.h index ff3fa80f4e..1f4ebde92d 100644 --- a/common/config/config_load_configmodule.h +++ b/common/config/config_load_configmodule.h @@ -37,6 +37,7 @@ #include #include #include "common/config/config_paramdesc.h" +#include "common/utils/T/T.h" #define CONFIG_MAX_OOPT_PARAMS 10 // maximum number of parameters in the -O option (-O :P1:P2... #define CONFIG_MAX_ALLOCATEDPTRS 1024 // maximum number of parameters that can be dynamicaly allocated in the config module @@ -44,12 +45,14 @@ #define CONFIG_LIBCONFIGFILE "libconfig" // use libconfig file #define CONFIG_CMDLINEONLY "cmdline" // use only command line options #define DEFAULT_CFGFILENAME "oai.conf" // default config file - -/* rtflags bit position definitions */ +/* bit position definition for the argv_info mask of the configmodule_interface_t structure */ +#define CONFIG_CMDLINEOPT_PROCESSED (1<<0) // command line option has been processed +/* bit position definitions for the rtflags mask of the configmodule_interface_t structure*/ #define CONFIG_PRINTPARAMS 1 // print parameters values while processing #define CONFIG_DEBUGPTR (1<<1) // print memory allocation/free debug messages #define CONFIG_DEBUGCMDLINE (1<<2) // print command line processing messages -#define CONFIG_NOABORTONCHKF (1<<3) // disable abort execution when parameter checking function fails +#define CONFIG_NOCHECKUNKOPT (1<<3) // disable check unprocessed (so invalid) command line options +#define CONFIG_NOABORTONCHKF (1<<4) // disable abort execution when parameter checking function fails #define CONFIG_NOEXITONHELP (1<<19) // do not exit after printing help #define CONFIG_HELP (1<<20) // print help message #define CONFIG_ABORT (1<<21) // config failed,abort execution @@ -62,6 +65,7 @@ typedef struct configmodule_interface { int argc; char **argv; + uint32_t *argv_info; char *cfgmode; int num_cfgP; char *cfgP[CONFIG_MAX_OOPT_PARAMS]; diff --git a/common/config/config_paramdesc.h b/common/config/config_paramdesc.h index c65e298dfb..60ab00a5ed 100644 --- a/common/config/config_paramdesc.h +++ b/common/config/config_paramdesc.h @@ -38,7 +38,7 @@ #define MAX_OPTNAME_SIZE 64 - +#define CONFIG_MAXOPTLENGTH 512 /* max full option length, full option name exemple: (prefix1.[].prefix2.optname */ /* parameter flags definitions */ @@ -55,7 +55,6 @@ #define PARAMFLAG_PARAMSET (1 << 16) // parameter has been explicitely set in get functions #define PARAMFLAG_PARAMSETDEF (1 << 17) // parameter has been set to default value in get functions - /* checkedparam_t is possibly used in paramdef_t for specific parameter value validation */ #define CONFIG_MAX_NUMCHECKVAL 20 typedef struct paramdef paramdef_t; diff --git a/common/config/config_userapi.c b/common/config/config_userapi.c index 0ec2e23790..d6e4beeaf5 100644 --- a/common/config/config_userapi.c +++ b/common/config/config_userapi.c @@ -197,20 +197,20 @@ int config_get(paramdef_t *params,int numparams, char *prefix) { int ret= -1; -if (CONFIG_ISFLAGSET(CONFIG_ABORT)) { + if (CONFIG_ISFLAGSET(CONFIG_ABORT)) { fprintf(stderr,"[CONFIG] config_get, section %s skipped, config module not properly initialized\n",prefix); return ret; -} -configmodule_interface_t *cfgif = config_get_if(); + } + configmodule_interface_t *cfgif = config_get_if(); if (cfgif != NULL) { - ret = config_get_if()->get(params, numparams,prefix); - if (ret >= 0) { - config_process_cmdline(params,numparams,prefix); - config_execcheck(params,numparams,prefix); - } - return ret; + ret = config_get_if()->get(params, numparams,prefix); + if (ret >= 0) { + config_process_cmdline(params,numparams,prefix); + config_execcheck(params,numparams,prefix); + } + return ret; } -return ret; + return ret; } int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix) diff --git a/common/config/config_userapi.h b/common/config/config_userapi.h index 2b40f8401b..f4b592bafb 100644 --- a/common/config/config_userapi.h +++ b/common/config/config_userapi.h @@ -55,7 +55,9 @@ extern void config_assign_processedint(paramdef_t *cfgoption, int val); extern void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val); extern int config_assign_ipv4addr(paramdef_t *cfgoptions, char *ipv4addr); -/* apis to get parameters, to be used by oai modules, at configuration time */ +/* apis to get/check parameters, to be used by oai modules, at configuration time */ +#define CONFIG_CHECKALLSECTIONS "ALLSECTIONS" +extern int config_check_cmdlineopt(char *prefix); extern int config_get(paramdef_t *params,int numparams, char *prefix); extern int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix); diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index d6dd97e34f..a65aa1e4a5 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -39,9 +39,6 @@ #include "vcd_signal_dumper.h" #include "assertions.h" -#if defined(ENABLE_ITTI) -# include "intertask_interface.h" -#endif # include # include @@ -242,7 +239,7 @@ void log_getconfig(log_t *g_log) { paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_debug[sizeof(log_maskmap)/sizeof(mapping)]; paramdef_t logparams_dump[sizeof(log_maskmap)/sizeof(mapping)]; - + CONFIG_SETRTFLAG(CONFIG_NOCHECKUNKOPT); int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX); if (ret <0) { fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); @@ -319,6 +316,7 @@ void log_getconfig(log_t *g_log) { logparams_dump[i].numelt = 0; } config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); + CONFIG_CLEARRTFLAG(CONFIG_NOCHECKUNKOPT); config_get( logparams_dump,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); /* set the debug mask according to the debug parameters values */ for (int i=0; log_maskmap[i].name != NULL ; i++) { @@ -358,6 +356,14 @@ int computed_compidx=compidx; return computed_compidx; } +int isLogInitDone (void){ + if (g_log == NULL) + return 0; + if (!(g_log->flag & FLAG_INITIALIZED)) + return 0; + return 1; +} + int logInit (void) { int i; @@ -437,6 +443,7 @@ int logInit (void) for (i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); } + g_log->flag = g_log->flag | FLAG_INITIALIZED; printf("log init done\n"); return 0; @@ -656,13 +663,12 @@ int is_newline( char *str, int size) void logClean (void) { int i; - LOG_UI(PHY,"\n"); - - - - for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - close_component_filelog(i); + if(isLogInitDone()) { + LOG_UI(PHY,"\n"); + for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { + close_component_filelog(i); + } } } diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index 767c1dbb35..2a7a51a0a6 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -115,12 +115,11 @@ extern "C" { * @{*/ -#define FLAG_NOCOLOR 0x0001 /*!< \brief use colors in log messages, depending on level */ -#define FLAG_THREAD 0x0008 /*!< \brief display thread name in log messages */ -#define FLAG_LEVEL 0x0010 /*!< \brief display log level in log messages */ -#define FLAG_FUNCT 0x0020 -#define FLAG_FILE_LINE 0x0040 -#define FLAG_TIME 0x0100 +#define FLAG_NOCOLOR 0x0001 /*!< \brief use colors in log messages, depending on level */ +#define FLAG_THREAD 0x0008 /*!< \brief display thread name in log messages */ +#define FLAG_LEVEL 0x0010 /*!< \brief display log level in log messages */ +#define FLAG_TIME 0x0100 +#define FLAG_INITIALIZED 0x8000 #define SET_LOG_OPTION(O) g_log->flag = (g_log->flag | O) #define CLEAR_LOG_OPTION(O) g_log->flag = (g_log->flag & (~O)) @@ -283,6 +282,7 @@ extern log_t *g_log; # include "log_if.h" /*----------------------------------------------------------------------------*/ int logInit (void); +int isLogInitDone (void); void logRecord_mt(const char *file, const char *func, int line,int comp, int level, const char *format, ...) __attribute__ ((format (printf, 6, 7))); void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ); int set_log(int component, int level); diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c index 74494ba818..9cbfb8741e 100644 --- a/openair2/ENB_APP/enb_config.c +++ b/openair2/ENB_APP/enb_config.c @@ -289,7 +289,7 @@ void RCconfig_L1(void) { } }// j=0..num_inst - printf("Initializing northbound interface for L1\n"); + LOG_I(ENB_APP,"Initializing northbound interface for L1\n"); l1_north_init_eNB(); } else { LOG_I(PHY,"No " CONFIG_STRING_L1_LIST " configuration found"); @@ -360,16 +360,16 @@ void RCconfig_macrlc() { RC.mac[j]->eth_params_s.remote_portd = *(MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTD_IDX].iptr); RC.mac[j]->eth_params_s.transp_preference = ETH_UDP_MODE; sf_ahead = 2; // Cannot cope with 4 subframes betweem RX and TX - set it to 2 - printf("**************** vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc); + LOG_I(ENB_APP,"**************** vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc); configure_nfapi_vnf(RC.mac[j]->eth_params_s.my_addr, RC.mac[j]->eth_params_s.my_portc); - printf("**************** RETURNED FROM configure_nfapi_vnf() vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc); + LOG_I(ENB_APP,"**************** RETURNED FROM configure_nfapi_vnf() vnf_port:%d\n", RC.mac[j]->eth_params_s.my_portc); } else { // other midhaul AssertFatal(1==0,"MACRLC %d: %s unknown southbound midhaul\n",j,*(MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr)); } if (strcmp(*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr), "default") == 0) { global_scheduler_mode=SCHED_MODE_DEFAULT; - printf("sched mode = default %d [%s]\n",global_scheduler_mode,*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr)); + LOG_I(ENB_APP,"sched mode = default %d [%s]\n",global_scheduler_mode,*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr)); } else if (strcmp(*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr), "fairRR") == 0) { global_scheduler_mode=SCHED_MODE_FAIR_RR; printf("sched mode = fairRR %d [%s]\n",global_scheduler_mode,*(MacRLC_ParamList.paramarray[j][MACRLC_SCHED_MODE_IDX].strptr)); @@ -550,7 +550,7 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) { enb_id = *(ENBParamList.paramarray[i][ENB_ENB_ID_IDX].uptr); } - printf("RRC %d: Southbound Transport %s\n",i,*(ENBParamList.paramarray[i][ENB_TRANSPORT_S_PREFERENCE_IDX].strptr)); + LOG_I(ENB_APP,"RRC %d: Southbound Transport %s\n",i,*(ENBParamList.paramarray[i][ENB_TRANSPORT_S_PREFERENCE_IDX].strptr)); if (strcmp(*(ENBParamList.paramarray[i][ENB_TRANSPORT_S_PREFERENCE_IDX].strptr), "local_mac") == 0) { } else if (strcmp(*(ENBParamList.paramarray[i][ENB_TRANSPORT_S_PREFERENCE_IDX].strptr), "cudu") == 0) { @@ -2494,8 +2494,7 @@ int RCconfig_X2(MessageDef *msg_p, uint32_t i) { int RCconfig_parallel(void) { char *parallel_conf = NULL; char *worker_conf = NULL; - extern char *parallel_config; - extern char *worker_config; + paramdef_t ThreadParams[] = THREAD_CONF_DESC; paramlist_def_t THREADParamList = {THREAD_CONFIG_STRING_THREAD_STRUCT,NULL,0}; config_getlist( &THREADParamList,NULL,0,NULL); @@ -2514,9 +2513,10 @@ int RCconfig_parallel(void) { worker_conf = strdup("WORKER_ENABLE"); } - if(parallel_config == NULL) set_parallel_conf(parallel_conf); - if(worker_config == NULL) set_worker_conf(worker_conf); + set_parallel_conf(parallel_conf); + set_worker_conf(worker_conf); + return 0; } diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c index 866855c456..8648fa5771 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler.c +++ b/openair2/LAYER2/MAC/eNB_scheduler.c @@ -30,7 +30,7 @@ */ #include "assertions.h" - +#include "targets/RT/USER/lte-softmodem.h" #include "LAYER2/MAC/mac.h" #include "LAYER2/MAC/mac_extern.h" @@ -64,7 +64,7 @@ #define DEBUG_eNB_SCHEDULER 1 extern RAN_CONTEXT_t RC; -extern int phy_test; + uint16_t pdcch_order_table[6] = { 31, 31, 511, 2047, 2047, 8191 }; @@ -660,7 +660,7 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP, if ((subframeP == 0) && (frameP & 3) == 0) schedule_mib(module_idP, frameP, subframeP); - if (phy_test == 0){ + if (get_softmodem_params()->phy_test == 0){ // This schedules SI for legacy LTE and eMTC starting in subframeP schedule_SI(module_idP, frameP, subframeP); // This schedules Paging in subframeP diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index 3d86187e88..207815b122 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -65,7 +65,6 @@ #define DEBUG_HEADER_PARSING 1 #define ENABLE_MAC_PAYLOAD_DEBUG 1 -extern uint8_t usim_test; extern UL_IND_t *UL_INFO; @@ -2020,7 +2019,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, { // Workaround for issue in OAI eNB or EPC which are not able to process SRB2 message multiplexed with SRB1 on the same MAC PDU - if ((usim_test == 0) && (lcid == DCCH1) + if (( get_softmodem_params()->usim_test == 0) && (lcid == DCCH1) && (lcid_rlc_pdu_count == 0) && (num_sdus)) { // Skip SRB2 multiplex if at least one SRB1 SDU is already multiplexed diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c index 8d0992f17a..02f0e059e0 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c @@ -39,7 +39,7 @@ #include #include /* for _ASN_DEFAULT_STACK_MAX */ #include - +#include "targets/RT/USER/lte-softmodem.h" #include "assertions.h" #include "LTE_RRCConnectionRequest.h" #include "LTE_UL-CCCH-Message.h" @@ -99,7 +99,7 @@ typedef struct xer_sprint_string_s { } xer_sprint_string_t; extern unsigned char NB_eNB_INST; -extern uint8_t usim_test; + extern RAN_CONTEXT_t RC; @@ -247,26 +247,7 @@ uint8_t do_MIB(rrc_eNB_carrier_data_t *carrier, uint32_t N_RB_DL, uint32_t phich AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); - /* -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_BCH_Message, (void *) &mib)) > 0) { - MessageDef *msg_p; - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, enb_module_idP, msg_p); - } - } -# endif -#endif - */ if (enc_rval.encoded==-1) { return(-1); } @@ -470,7 +451,7 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, (*sib1)->cellSelectionInfo.q_RxLevMin=-65; (*sib1)->cellSelectionInfo.q_RxLevMinOffset=NULL; //(*sib1)->p_Max = CALLOC(1, sizeof(P_Max_t)); - //*((*sib1)->p_Max) = 23; + // *((*sib1)->p_Max) = 23; (*sib1)->freqBandIndicator = #if defined(ENABLE_ITTI) configuration->eutra_band[CC_id]; @@ -513,9 +494,10 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, (*sib1)->systemInfoValueTag=0; // (*sib1).nonCriticalExtension = calloc(1,sizeof(*(*sib1).nonCriticalExtension)); -#ifdef XER_PRINT - xer_fprint(stdout, &asn_DEF_BCCH_DL_SCH_Message, (void*)bcch_message); -#endif + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout, &asn_DEF_LTE_BCCH_DL_SCH_Message, (void*)bcch_message); + } + enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_BCCH_DL_SCH_Message, NULL, (void*)bcch_message, @@ -524,23 +506,7 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[10000]; - size_t message_string_size; - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size); - itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p); - } - } -# endif -#endif LOG_D(RRC,"[eNB] SystemInformationBlockType1 Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -1371,24 +1337,6 @@ uint8_t do_SIB23(uint8_t Mod_id, enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[15000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p); - } - } -# endif -#endif LOG_D(RRC,"[eNB] SystemInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -1449,7 +1397,9 @@ uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv) rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.spare.size=1; rrcConnectionRequest->criticalExtensions.choice.rrcConnectionRequest_r8.spare.bits_unused = 7; - + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout, &asn_DEF_LTE_UL_CCCH_Message, (void*)&ul_ccch_msg); + } enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_CCCH_Message, NULL, (void*)&ul_ccch_msg, @@ -1458,24 +1408,6 @@ uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv) AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_UL_CCCH_Message, (void *) &ul_ccch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_CCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_ul_ccch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_ul_ccch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p); - } - } -# endif -#endif LOG_D(RRC,"[UE] RRCConnectionRequest Encoded %zd bits (%zd bytes) \n",enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -1626,28 +1558,9 @@ uint8_t do_SidelinkUEInformation(uint8_t Mod_id, uint8_t *buffer, LTE_SL_Destin AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) { - MessageDef *msg_p; + LOG_D(RRC,"SidelinkUEInformation Encoded %d bits (%d bytes)\n",(uint32_t)enc_rval.encoded,(uint32_t)((enc_rval.encoded+7)/8)); - msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p); - } - } -# endif -#endif - -#ifdef USER_MODE - LOG_D(RRC,"SidelinkUEInformation Encoded %d bits (%d bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); -#endif return((enc_rval.encoded+7)/8); @@ -1699,7 +1612,9 @@ uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uin rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.registeredMME->mmec.size=1; rrcConnectionSetupComplete->criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8.registeredMME->mmec.bits_unused=0; */ - + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void*)&ul_dcch_msg); + } enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message, NULL, (void*)&ul_dcch_msg, @@ -1708,24 +1623,6 @@ uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uin AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p); - } - } -# endif -#endif LOG_D(RRC,"RRCConnectionSetupComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -1760,7 +1657,9 @@ do_RRCConnectionReconfigurationComplete( rrcConnectionReconfigurationComplete->criticalExtensions.present = LTE_RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8; rrcConnectionReconfigurationComplete->criticalExtensions.choice.rrcConnectionReconfigurationComplete_r8.nonCriticalExtension=NULL; - + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void*)&ul_dcch_msg); + } enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message, NULL, (void*)&ul_dcch_msg, @@ -1769,24 +1668,6 @@ do_RRCConnectionReconfigurationComplete( AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } - } -# endif -#endif LOG_D(RRC,"RRCConnectionReconfigurationComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -2182,24 +2063,7 @@ do_RRCConnectionSetup( enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } - } -# endif -#endif LOG_D(RRC,"RRCConnectionSetup Encoded %zd bits (%zd bytes) \n", enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -2257,24 +2121,7 @@ do_SecurityModeCommand( enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } - } -# endif -#endif LOG_D(RRC,"[eNB %d] securityModeCommand for UE %x Encoded %zd bits (%zd bytes)\n", ctxt_pP->module_id, @@ -2337,24 +2184,6 @@ do_UECapabilityEnquiry( enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } - } -# endif -#endif LOG_D(RRC,"[eNB %d] UECapabilityRequest for UE %x Encoded %zd bits (%zd bytes)\n", ctxt_pP->module_id, @@ -2546,24 +2375,6 @@ do_RRCConnectionReconfiguration( xer_fprint(stdout,&asn_DEF_LTE_DL_DCCH_Message,(void*)&dl_dcch_msg); } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[30000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } - } -# endif -#endif LOG_I(RRC,"RRCConnectionReconfiguration Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); // for (i=0;i<30;i++) @@ -2755,33 +2566,10 @@ do_RRCConnectionReestablishment( 100); if(enc_rval.encoded == -1) { - LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n", + LOG_E(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } - } -# endif -#endif - -#ifdef USER_MODE - LOG_D(RRC,"RRCConnectionReestablishment Encoded %zd bits (%zd bytes)\n", - enc_rval.encoded,(enc_rval.encoded+7)/8); -#endif return((enc_rval.encoded+7)/8); } @@ -2817,28 +2605,11 @@ do_RRCConnectionReestablishmentReject( 100); if(enc_rval.encoded == -1) { - LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n", + LOG_E(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) { - MessageDef *msg_p; - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p); - } - } -# endif -#endif LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %zd bits (%zd bytes)\n", enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -2884,24 +2655,6 @@ do_RRCConnectionReject( enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p); - } - } -# endif -#endif LOG_D(RRC,"RRCConnectionReject Encoded %zd bits (%zd bytes)\n", enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -3078,24 +2831,6 @@ uint8_t do_MBSFNAreaConfig(uint8_t Mod_id, enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_MCCH_Message, (void *) &mcch_message)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_MCCH, message_string_size); - msg_p->ittiMsg.rrc_dl_mcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_mcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p); - } - } -# endif -#endif LOG_D(RRC,"[eNB] MCCH Message Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); @@ -3199,6 +2934,10 @@ uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_ ASN_SEQUENCE_ADD(&measResultListEUTRA2->list,measresulteutra2); measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells->choice.measResultListEUTRA=*(measResultListEUTRA2); + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void*)&ul_dcch_msg); + } + enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message, NULL, @@ -3211,26 +2950,7 @@ uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_ enc_rval.failed_type->name, enc_rval.encoded); return -1; } -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p); - } - } -# endif -#endif - printf("Measurement Report Encoded %zu bits (%zu bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); return((enc_rval.encoded+7)/8); } @@ -3255,26 +2975,6 @@ uint8_t do_DLInformationTransfer(uint8_t Mod_id, uint8_t **buffer, uint8_t trans encoded = uper_encode_to_new_buffer (&asn_DEF_LTE_DL_DCCH_Message, NULL, (void*) &dl_dcch_msg, (void **) buffer); - /* -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[10000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *)&dl_dcch_msg)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, Mod_id, msg_p); - } - } -# endif -#endif - */ return encoded; } @@ -3476,7 +3176,7 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname) // UE_EUTRA_Capability->measParameters.bandListEUTRA.list.count = 0; // no measurements on other bands // UE_EUTRA_Capability->featureGroupIndicators // null - if(usim_test == 1) + if(get_softmodem_params()->usim_test == 1) { // featureGroup is mandatory for CMW tests // featureGroup is filled only for usim-test mode @@ -3519,33 +3219,7 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname) AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if defined(DISABLE_XER_SPRINT) - { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_UE_EUTRA_CAPABILITY); - memcpy (&msg_p->ittiMsg, (void *) UE_EUTRA_Capability, sizeof(RrcUeEutraCapability)); - - itti_send_msg_to_task (TASK_UNKNOWN, NB_eNB_INST, msg_p); - } -# else - { - char message_string[10000]; - size_t message_string_size; - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability)) > 0) { - MessageDef *msg_p; - - msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UE_EUTRA_CAPABILITY, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_ue_eutra_capability.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_ue_eutra_capability.text, message_string, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, msg_p); - } - } -# endif -#endif UECapability.sdu_size = (enc_rval.encoded + 7) / 8; LOG_I(PHY, "[RRC]UE Capability encoded, %d bytes (%zd bits)\n", diff --git a/openair3/NAS/UE/EMM/Authentication.c b/openair3/NAS/UE/EMM/Authentication.c index 5b10e60893..850f97150a 100644 --- a/openair3/NAS/UE/EMM/Authentication.c +++ b/openair3/NAS/UE/EMM/Authentication.c @@ -68,14 +68,9 @@ Description Defines the authentication EMM procedure executed by the #include "usim_api.h" #include "secu_defs.h" #include "Authentication.h" +#include "targets/RT/USER/lte-softmodem.h" -/****************************************************************************/ -/**************** E X T E R N A L D E F I N I T I O N S ****************/ -/****************************************************************************/ - -extern uint8_t usim_test; - /****************************************************************************/ /******************* L O C A L D E F I N I T I O N S *******************/ /****************************************************************************/ @@ -211,7 +206,7 @@ int emm_proc_authentication_request(nas_user_t *user, int native_ksi, int ksi, * of the core network by means of the received AUTN parameter and * request the USIM to compute RES, CK and IK for given RAND */ - if(usim_test == 0) + if(get_softmodem_params()->usim_test == 0) { rc = usim_api_authenticate(&user->usim_data, rand, autn, &auts, &res, &ck, &ik); } diff --git a/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c b/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c index fe18a98d38..f77c2921a3 100644 --- a/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c +++ b/openair3/NAS/UE/EMM/SAP/EmmDeregisteredNormalService.c @@ -47,7 +47,7 @@ Description Implements the EPS Mobility Management procedures executed #include "commonDef.h" #include "networkDef.h" #include "nas_log.h" - +#include "targets/RT/USER/lte-softmodem.h" #include "emm_proc.h" #include @@ -55,7 +55,7 @@ Description Implements the EPS Mobility Management procedures executed /****************************************************************************/ /**************** E X T E R N A L D E F I N I T I O N S ****************/ /****************************************************************************/ -extern uint8_t usim_test; + /****************************************************************************/ /******************* L O C A L D E F I N I T I O N S *******************/ @@ -110,7 +110,7 @@ int EmmDeregisteredNormalService(nas_user_t *user, const emm_reg_t *evt) /* * Initiate the attach procedure for EPS services */ - if(usim_test == 0) + if(get_softmodem_params()->usim_test == 0) { rc = emm_proc_attach(user, EMM_ATTACH_TYPE_EPS); } diff --git a/targets/COMMON/create_tasks.c b/targets/COMMON/create_tasks.c index 0d306ee50b..047d8b4037 100644 --- a/targets/COMMON/create_tasks.c +++ b/targets/COMMON/create_tasks.c @@ -23,6 +23,7 @@ # include "intertask_interface.h" # include "create_tasks.h" # include "common/utils/LOG/log.h" +# include "targets/RT/USER/lte-softmodem.h" # ifdef OPENAIR2 # if defined(ENABLE_USE_MME) @@ -43,7 +44,6 @@ # endif # include "enb_app.h" -extern int emulate_rf; int create_tasks(uint32_t enb_nb) { @@ -79,7 +79,7 @@ int create_tasks(uint32_t enb_nb) LOG_E(S1AP, "Create task for S1AP failed\n"); return -1; } - if(!emulate_rf){ + if(!(get_softmodem_params()->emulate_rf)){ if (itti_create_task (TASK_UDP, udp_eNB_task, NULL) < 0) { LOG_E(UDP_, "Create task for UDP failed\n"); return -1; diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c index 4a0d2d5266..3f0fe77647 100644 --- a/targets/RT/USER/lte-ru.c +++ b/targets/RT/USER/lte-ru.c @@ -90,6 +90,7 @@ #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" #include "enb_config.h" +#include "targets/RT/USER/lte-softmodem.h" //#include "PHY/TOOLS/time_meas.h" /* these variables have to be defined before including ENB_APP/enb_paramdef.h */ @@ -117,16 +118,14 @@ static int DEFENBS[] = {0}; #include "pdcp.h" extern volatile int oai_exit; -extern int emulate_rf; -extern int numerology; -extern clock_source_t clock_source; + extern PARALLEL_CONF_t get_thread_parallel_conf(void); extern WORKER_CONF_t get_thread_worker_conf(void); extern void phy_init_RU(RU_t*); extern void phy_free_RU(RU_t*); -void init_RU(char*); + void stop_RU(int nb_ru); void do_ru_sync(RU_t *ru); @@ -699,6 +698,7 @@ static void* emulatedRF_thread(void* param) { RU_proc_t *proc = (RU_proc_t *) param; int microsec = 500; // length of time to sleep, in miliseconds struct timespec req = {0}; + int numerology = get_softmodem_params()->numerology; req.tv_sec = 0; req.tv_nsec = (numerology>0)? ((microsec * 1000L)/numerology):(microsec * 1000L)*2; cpu_set_t cpuset; @@ -743,7 +743,7 @@ void rx_rf(RU_t *ru,int *frame,int *subframe) { VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, 1 ); old_ts = proc->timestamp_rx; - if(emulate_rf){ + if(get_softmodem_params()->emulate_rf){ wait_on_condition(&proc->mutex_emulateRF,&proc->cond_emulateRF,&proc->instance_cnt_emulateRF,"emulatedRF_thread"); release_thread(&proc->mutex_emulateRF,&proc->instance_cnt_emulateRF,"emulatedRF_thread"); rxs = fp->samples_per_tti; @@ -1352,7 +1352,7 @@ void fill_rf_config(RU_t *ru, char *rf_config_file) { LTE_DL_FRAME_PARMS *fp = &ru->frame_parms; openair0_config_t *cfg = &ru->openair0_cfg; //printf("////////////////numerology in config = %d\n",numerology); - + int numerology = get_softmodem_params()->numerology; if(fp->N_RB_DL == 100) { if(numerology == 0){ if (fp->threequarter_fs) { @@ -1411,7 +1411,7 @@ void fill_rf_config(RU_t *ru, char *rf_config_file) { cfg->num_rb_dl=fp->N_RB_DL; cfg->tx_num_channels=ru->nb_tx; cfg->rx_num_channels=ru->nb_rx; - cfg->clock_source=clock_source; + cfg->clock_source=get_softmodem_params()->clock_source; for (i=0; inb_tx; i++) { @@ -1561,7 +1561,7 @@ static void* ru_thread_tx( void* param ) { // do OFDM if needed if ((ru->fh_north_asynch_in == NULL) && (ru->feptx_ofdm)) ru->feptx_ofdm(ru); - if(!emulate_rf){ + if(!(get_softmodem_params()->emulate_rf)){ // do outgoing fronthaul (south) if needed if ((ru->fh_north_asynch_in == NULL) && (ru->fh_south_out)) ru->fh_south_out(ru); @@ -1613,7 +1613,7 @@ static void* ru_thread( void* param ) { LOG_I(PHY,"Starting RU %d (%s,%s),\n",ru->idx,eNB_functions[ru->function],eNB_timing[ru->if_timing]); - if(emulate_rf){ + if(get_softmodem_params()->emulate_rf){ fill_rf_config(ru,ru->rf_config_file); init_frame_parms(&ru->frame_parms,1); phy_init_RU(ru); @@ -1659,7 +1659,7 @@ static void* ru_thread( void* param ) { wait_sync("ru_thread"); - if(!emulate_rf){ + if(!(get_softmodem_params()->emulate_rf)){ // Start RF device if any if (ru->start_rf) { if (ru->start_rf(ru) != 0) @@ -1794,7 +1794,7 @@ static void* ru_thread( void* param ) { // do OFDM if needed if ((ru->fh_north_asynch_in == NULL) && (ru->feptx_ofdm)) ru->feptx_ofdm(ru); - if(!emulate_rf){ + if(!(get_softmodem_params()->emulate_rf)){ // do outgoing fronthaul (south) if needed if ((ru->fh_north_asynch_in == NULL) && (ru->fh_south_out)) ru->fh_south_out(ru); @@ -1817,7 +1817,7 @@ static void* ru_thread( void* param ) { printf( "Exiting ru_thread \n"); - if (!emulate_rf){ + if (!(get_softmodem_params()->emulate_rf)){ if (ru->stop_rf != NULL) { if (ru->stop_rf(ru) != 0) LOG_E(HW,"Could not stop the RF device\n"); @@ -2198,7 +2198,7 @@ void init_RU_proc(RU_t *ru) { pthread_create( &proc->pthread_rf_tx, NULL, rf_tx, (void*)ru ); #endif - if(emulate_rf) + if(get_softmodem_params()->emulate_rf) pthread_create( &proc->pthread_emulateRF, attr_emulateRF, emulatedRF_thread, (void*)proc ); if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) diff --git a/targets/RT/USER/lte-softmodem-common.c b/targets/RT/USER/lte-softmodem-common.c new file mode 100644 index 0000000000..4eb0d3e888 --- /dev/null +++ b/targets/RT/USER/lte-softmodem-common.c @@ -0,0 +1,126 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file lte-softmodem-common.c + * \brief Top-level threads for eNodeB + * \author Nokia BellLabs France, francois Taburet + * \date 2012 + * \version 0.1 + * \company Eurecom + * \email: francois.taburet@nokia-bell-labs.com + * \note + * \warning + */ + +#include "lte-softmodem.h" +#include "UTIL/OPT/opt.h" +#include "common/config/config_userapi.h" +#include "common/utils/load_module_shlib.h" +static softmodem_params_t softmodem_params; + +uint64_t get_softmodem_optmask(void) { + return softmodem_params.optmask; +} + +uint64_t set_softmodem_optmask(uint64_t bitmask) { + softmodem_params.optmask = softmodem_params.optmask | bitmask; + return softmodem_params.optmask; +} + +softmodem_params_t* get_softmodem_params(void) { + return &softmodem_params; +} + +void set_parallel_conf(char *parallel_conf) +{ + if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0) softmodem_params.thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD; + else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0) softmodem_params.thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT; + else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0) softmodem_params.thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT; + printf("[CONFIG] parallel conf is set to %d\n",softmodem_params.thread_struct.parallel_conf); +} +void set_worker_conf(char *worker_conf) +{ + if(strcmp(worker_conf,"WORKER_DISABLE")==0) softmodem_params.thread_struct.worker_conf = WORKER_DISABLE; + else if(strcmp(worker_conf,"WORKER_ENABLE")==0) softmodem_params.thread_struct.worker_conf = WORKER_ENABLE; + printf("[CONFIG] worker conf is set to %d\n",softmodem_params.thread_struct.worker_conf); +} +PARALLEL_CONF_t get_thread_parallel_conf(void) +{ + return softmodem_params.thread_struct.parallel_conf; +} +WORKER_CONF_t get_thread_worker_conf(void) +{ + return softmodem_params.thread_struct.worker_conf; +} +void get_common_options(void) +{ +char *parallel_config=NULL; +char *worker_config=NULL; + + +uint32_t online_log_messages; +uint32_t glog_level ; +uint32_t start_telnetsrv; +uint32_t noS1; +uint32_t nokrnmod; +uint32_t nonbiot; +paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; +paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; + + + + config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); + + if (strlen(in_path) > 0) { + opt_type = OPT_PCAP; + opt_enabled=1; + printf("Enabling OPT for PCAP with the following file %s \n",in_path); + } + if (strlen(in_ip) > 0) { + opt_enabled=1; + opt_type = OPT_WIRESHARK; + printf("Enabling OPT for wireshark for local interface"); + } + + config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL); + + if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) { + set_glog_onlinelog(online_log_messages); + } + if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) { + set_glog(glog_level); + } + if (start_telnetsrv) { + load_module_shlib("telnetsrv",NULL,0,NULL); + } + + if (noS1) { + set_softmodem_optmask(SOFTMODEM_NOS1_BIT); + } + if (nokrnmod) { + set_softmodem_optmask(SOFTMODEM_NOKRNMOD_BIT); + } + if (nonbiot) { + set_softmodem_optmask(SOFTMODEM_NONBIOT_BIT); + } + if(parallel_config != NULL) set_parallel_conf(parallel_config); + if(worker_config != NULL) set_worker_conf(worker_config); +} diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c index 03a461454f..00ae350ea2 100644 --- a/targets/RT/USER/lte-softmodem.c +++ b/targets/RT/USER/lte-softmodem.c @@ -19,7 +19,7 @@ * contact@openairinterface.org */ -/*! \file lte-enb.c +/*! \file lte-softmodem.c * \brief Top-level threads for eNodeB * \author R. Knopp, F. Kaltenberger, Navid Nikaein * \date 2012 @@ -133,26 +133,13 @@ volatile int start_UE = 0; #endif volatile int oai_exit = 0; -clock_source_t clock_source = internal; -static int wait_for_sync = 0; - -unsigned int mmapped_dma=0; -int single_thread_flag = 0; - -static int8_t threequarter_fs=0; - uint32_t downlink_frequency[MAX_NUM_CCs][4]; int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; - -// This is a dummy declaration (dlsch_demodulation.c is no longer compiled for eNodeB) -int16_t dlsch_demod_shift = 0; - int UE_scan = 1; int UE_scan_carrier = 0; runmode_t mode = normal_txrx; int simL1flag; -int snr_dB; FILE *input_fd=NULL; @@ -171,11 +158,6 @@ double rx_gain_off = 0.0; double sample_rate=30.72e6; double bw = 10.0e6; -char rf_config_file[1024]; - -int chain_offset=0; -int phy_test = 0; -uint8_t usim_test = 0; uint8_t dci_Format = 0; uint8_t agregation_Level =0xFF; @@ -190,16 +172,12 @@ int rx_input_level_dBm; #ifdef XFORMS extern int otg_enabled; -static char do_forms=0; #else int otg_enabled; #endif //int number_of_cards = 1; -uint32_t target_dl_mcs = 28; //maximum allowed mcs -uint32_t target_ul_mcs = 20; -uint32_t timing_advance = 0; uint8_t exit_missed_slots=1; uint64_t num_missed_slots=0; // counter for the number of missed slots @@ -207,58 +185,16 @@ uint64_t num_missed_slots=0; // counter for the number of missed slots extern void reset_opp_meas(void); extern void print_opp_meas(void); -extern PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, - uint8_t UE_id, - uint8_t abstraction_flag); extern void init_eNB_afterRU(void); int transmission_mode=1; -int emulate_rf = 0; -int numerology = 0; -char *parallel_config = NULL; -char *worker_config = NULL; - -static THREAD_STRUCT thread_struct; -void set_parallel_conf(char *parallel_conf) -{ - if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0) thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT; - printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf); -} -void set_worker_conf(char *worker_conf) -{ - if(strcmp(worker_conf,"WORKER_DISABLE")==0) thread_struct.worker_conf = WORKER_DISABLE; - else if(strcmp(worker_conf,"WORKER_ENABLE")==0) thread_struct.worker_conf = WORKER_ENABLE; - printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf); -} -PARALLEL_CONF_t get_thread_parallel_conf(void) -{ - return thread_struct.parallel_conf; -} -WORKER_CONF_t get_thread_worker_conf(void) -{ - return thread_struct.worker_conf; -} - -/* struct for ethernet specific parameters given in eNB conf file */ -eth_params_t *eth_params; double cpuf; -extern char uecap_xer[1024]; -char uecap_xer_in=0; -int oaisim_flag=0; -threads_t threads= {-1,-1,-1,-1,-1,-1,-1}; - -/* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed - * this is very hackish - find a proper solution - */ -uint8_t abstraction_flag=0; /* forward declarations */ void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]); @@ -314,7 +250,7 @@ unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe) { return (dcoff_i_rxfe + (dcoff_q_rxfe<<8)); } -#if !defined(ENABLE_ITTI) + void signal_handler(int sig) { void *array[10]; size_t size; @@ -328,26 +264,13 @@ void signal_handler(int sig) { backtrace_symbols_fd(array, size, 2); exit(-1); } else { - printf("trying to exit gracefully...\n"); - oai_exit = 1; + printf("Linux signal %s...\n",strsignal(sig)); + exit_function(__FILE__, __FUNCTION__, __LINE__,"softmodem starting exit procedure\n"); + + } } -#endif -#define KNRM "\x1B[0m" -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define KBLU "\x1B[34m" -#define RESET "\033[0m" -#if defined(ENABLE_ITTI) -void signal_handler_itti(int sig) { - // Call exit function - char msg[256]; - memset(msg, 0, 256); - sprintf(msg, "caught signal %s\n", strsignal(sig)); - exit_function(__FILE__, __FUNCTION__, __LINE__, msg); -} -#endif void exit_function(const char* file, const char* function, const int line, const char* s) { @@ -520,42 +443,12 @@ void *l2l1_task(void *arg) { #endif -static void get_options(unsigned int *start_msc) { +static void get_options(void) { - int tddflag, nonbiotflag; - - - uint32_t online_log_messages; - uint32_t glog_level ; - uint32_t start_telnetsrv; - paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; - paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP); - config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); - - if (strlen(in_path) > 0) { - opt_type = OPT_PCAP; - opt_enabled=1; - printf("Enabling OPT for PCAP with the following file %s \n",in_path); - } - if (strlen(in_ip) > 0) { - opt_enabled=1; - opt_type = OPT_WIRESHARK; - printf("Enabling OPT for wireshark for local interface"); - } + get_common_options(); CONFIG_CLEARRTFLAG(CONFIG_NOEXITONHELP); - config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL); - - if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) { - set_glog_onlinelog(online_log_messages); - } - if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) { - set_glog(glog_level); - } - if (start_telnetsrv) { - load_module_shlib("telnetsrv",NULL,0,NULL); - } if ( !(CONFIG_ISFLAGSET(CONFIG_ABORT)) ) { memset((void*)&RC,0,sizeof(RC)); @@ -563,7 +456,7 @@ static void get_options(unsigned int *start_msc) { RCConfig(); NB_eNB_INST = RC.nb_inst; printf("Configuration: nb_rrc_inst %d, nb_L1_inst %d, nb_ru %d\n",NB_eNB_INST,RC.nb_L1_inst,RC.nb_RU); - if (nonbiotflag <= 0) { + if (!SOFTMODEM_NONBIOT) { load_NB_IoT(); printf(" nb_nbiot_rrc_inst %d, nb_nbiot_L1_inst %d, nb_nbiot_macrlc_inst %d\n", RC.nb_nb_iot_rrc_inst, RC.nb_nb_iot_L1_inst, RC.nb_nb_iot_macrlc_inst); @@ -572,8 +465,7 @@ static void get_options(unsigned int *start_msc) { RC.nb_nb_iot_rrc_inst=RC.nb_nb_iot_L1_inst=RC.nb_nb_iot_macrlc_inst=0; } } - if(parallel_config != NULL) set_parallel_conf(parallel_config); - if(worker_config != NULL) set_worker_conf(worker_config); + } @@ -803,8 +695,6 @@ int main( int argc, char **argv ) #if defined (XFORMS) int ret; #endif - unsigned int start_msc=0; - if ( load_configmodule(argc,argv) == NULL) { exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); } @@ -818,7 +708,8 @@ int main( int argc, char **argv ) printf("Reading in command-line options\n"); - get_options (&start_msc); + CONFIG_SETRTFLAG(CONFIG_NOCHECKUNKOPT); + get_options (); if (CONFIG_ISFLAGSET(CONFIG_ABORT) ) { fprintf(stderr,"Getting configuration failed\n"); exit(-1); @@ -826,11 +717,16 @@ int main( int argc, char **argv ) #if T_TRACER + T_Config_Init(); #endif - - + ret=config_check_cmdlineopt(NULL); + if (ret != 0) { + LOG_E(ENB_APP, "%i unknown options in command line\n",ret); + exit_fun(""); + } + CONFIG_CLEARRTFLAG(CONFIG_NOCHECKUNKOPT); //randominit (0); set_taus_seed (0); @@ -848,7 +744,7 @@ int main( int argc, char **argv ) itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); // initialize mscgen log after ITTI - if (start_msc) { + if (get_softmodem_params()->start_msc) { load_module_shlib("msc",NULL,0,&msc_interface); } MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX); @@ -867,17 +763,14 @@ int main( int argc, char **argv ) #endif #endif -#if !defined(ENABLE_ITTI) + // to make a graceful exit when ctrl-c is pressed signal(SIGSEGV, signal_handler); signal(SIGINT, signal_handler); -#endif + signal(SIGTERM, signal_handler); + signal(SIGABRT, signal_handler); + -#if defined(ENABLE_ITTI) - signal(SIGINT, signal_handler_itti); - signal(SIGTERM, signal_handler_itti); - signal(SIGABRT, signal_handler_itti); -#endif check_clock(); @@ -887,11 +780,6 @@ int main( int argc, char **argv ) LOG_I(HW, "Version: %s\n", PACKAGE_VERSION); - - - - printf("Before CC \n"); - printf("Runtime table\n"); fill_modeled_runtime_table(runtime_phy_rx,runtime_phy_tx); @@ -973,7 +861,7 @@ int main( int argc, char **argv ) printf("XFORMS\n"); - if (do_forms==1) { + if (get_softmodem_params()->do_forms==1) { fl_initialize (&argc, argv, NULL, 0, 0); form_stats_l2 = create_form_stats_form(); @@ -1044,8 +932,8 @@ int main( int argc, char **argv ) number_of_cards = 1; printf("RC.nb_L1_inst:%d\n", RC.nb_L1_inst); if (RC.nb_L1_inst > 0) { - printf("Initializing eNB threads single_thread_flag:%d wait_for_sync:%d\n", single_thread_flag,wait_for_sync); - init_eNB(single_thread_flag,wait_for_sync); + printf("Initializing eNB threads single_thread_flag:%d wait_for_sync:%d\n", get_softmodem_params()->single_thread_flag,get_softmodem_params()->wait_for_sync); + init_eNB(get_softmodem_params()->single_thread_flag,get_softmodem_params()->wait_for_sync); // for (inst=0;inst0) { printf("Initializing RU threads\n"); - init_RU(rf_config_file); + init_RU(get_softmodem_params()->rf_config_file); for (ru_id=0;ru_idrf_map.card=0; - RC.ru[ru_id]->rf_map.chain=CC_id+chain_offset; + RC.ru[ru_id]->rf_map.chain=CC_id+(get_softmodem_params()->chain_offset); } } @@ -1102,6 +990,12 @@ int main( int argc, char **argv ) pthread_cond_broadcast(&sync_cond); pthread_mutex_unlock(&sync_mutex); + ret=config_check_cmdlineopt(CONFIG_CHECKALLSECTIONS); + if (ret != 0) { + LOG_E(ENB_APP, "%i unknown options in command line (invalid section name)\n",ret); + exit_fun(""); + } + // wait for end of program printf("TYPE TO TERMINATE\n"); //getchar(); @@ -1124,7 +1018,7 @@ int main( int argc, char **argv ) #ifdef XFORMS printf("waiting for XFORMS thread\n"); - if (do_forms==1) { + if (get_softmodem_params()->do_forms==1) { pthread_join(forms_thread,&status); fl_hide_form(form_stats->stats_form); fl_free_form(form_stats->stats_form); diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h index 96ab799c3d..6d182b16cf 100644 --- a/targets/RT/USER/lte-softmodem.h +++ b/targets/RT/USER/lte-softmodem.h @@ -95,7 +95,8 @@ #define CONFIG_HLP_EMULATE_RF "Emulated RF enabled(disable by defult)\n" #define CONFIG_HLP_PARALLEL_CMD "three config for level of parallelism 'PARALLEL_SINGLE_THREAD', 'PARALLEL_RU_L1_SPLIT', or 'PARALLEL_RU_L1_TRX_SPLIT'\n" #define CONFIG_HLP_WORKER_CMD "two option for worker 'WORKER_DISABLE' or 'WORKER_ENABLE'\n" - +#define CONFIG_HLP_NOS1 "Disable s1 interface\n" +#define CONFIG_HLP_NOKRNMOD "(noS1 only): Use tun instead of namesh module \n" #define CONFIG_HLP_DISABLNBIOT "disable nb-iot, even if defined in config\n" #define CONFIG_HLP_USRP_ARGS "set the arguments to identify USRP (same syntax as in UHD)\n" @@ -130,29 +131,48 @@ #define CMDLINE_DUMPMEMORY_IDX 7 /*------------------------------------------------------------------------------------------------------------------------------------------*/ +#define START_MSC softmodem_params.start_msc +/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters specific to UE */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters specific to UE */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ #define CMDLINE_UEPARAMS_DESC { \ -{"siml1", CONFIG_HLP_SIML1, PARAMFLAG_BOOL, iptr:&simL1flag, defintval:0, TYPE_INT, 0}, \ -{"U", CONFIG_HLP_NUMUE, 0, u8ptr:&NB_UE_INST, defuintval:1, TYPE_UINT, 0}, \ -{"ue-rxgain", CONFIG_HLP_UERXG, 0, dblptr:&(rx_gain[0][0]), defdblval:130, TYPE_DOUBLE, 0}, \ -{"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, dblptr:&rx_gain_off, defdblval:0, TYPE_DOUBLE, 0}, \ -{"ue-txgain", CONFIG_HLP_UETXG, 0, dblptr:&(tx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ -{"ue-nb-ant-rx", CONFIG_HLP_UENANTR, 0, u8ptr:&nb_antenna_rx, defuintval:1, TYPE_UINT8, 0}, \ -{"ue-nb-ant-tx", CONFIG_HLP_UENANTT, 0, u8ptr:&nb_antenna_tx, defuintval:1, TYPE_UINT8, 0}, \ -{"ue-scan-carrier", CONFIG_HLP_UESCAN, PARAMFLAG_BOOL, iptr:&UE_scan_carrier, defintval:0, TYPE_INT, 0}, \ -{"ue-max-power", NULL, 0, iptr:&(tx_max_power[0]), defintval:23, TYPE_INT, 0}, \ -{"emul-iface", CONFIG_HLP_EMULIFACE, 0, strptr:&emul_iface, defstrval:"lo", TYPE_STRING, 100}, \ -{"L2-emul", NULL, 0, u8ptr:&nfapi_mode, defuintval:3, TYPE_UINT8, 0}, \ -{"num-ues", NULL, 0, u8ptr:&(NB_UE_INST), defuintval:1, TYPE_UINT8, 0}, \ -{"r" , CONFIG_HLP_PRB, 0, u8ptr:&(frame_parms[0]->N_RB_DL), defintval:25, TYPE_UINT8, 0}, \ -{"dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ -{"usrp-args", CONFIG_HLP_USRP_ARGS, 0, strptr:(char **)&usrp_args, defstrval:"type=b200", TYPE_STRING, 0}, \ -{"usrp-clksrc", CONFIG_HLP_USRP_CLK_SRC,0, strptr:(char **)&usrp_clksrc, defstrval:"internal", TYPE_STRING, 0} \ - } +{"siml1", CONFIG_HLP_SIML1, PARAMFLAG_BOOL, iptr:&simL1flag, defintval:0, TYPE_INT, 0}, \ +{"U", CONFIG_HLP_NUMUE, 0, u8ptr:&NB_UE_INST, defuintval:1, TYPE_UINT, 0}, \ +{"ue-rxgain", CONFIG_HLP_UERXG, 0, dblptr:&(rx_gain[0][0]), defdblval:130, TYPE_DOUBLE, 0}, \ +{"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, dblptr:&rx_gain_off, defdblval:0, TYPE_DOUBLE, 0}, \ +{"ue-txgain", CONFIG_HLP_UETXG, 0, dblptr:&(tx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ +{"ue-nb-ant-rx", CONFIG_HLP_UENANTR, 0, u8ptr:&nb_antenna_rx, defuintval:1, TYPE_UINT8, 0}, \ +{"ue-nb-ant-tx", CONFIG_HLP_UENANTT, 0, u8ptr:&nb_antenna_tx, defuintval:1, TYPE_UINT8, 0}, \ +{"ue-scan-carrier", CONFIG_HLP_UESCAN, PARAMFLAG_BOOL, iptr:&UE_scan_carrier, defintval:0, TYPE_INT, 0}, \ +{"ue-max-power", NULL, 0, iptr:&(tx_max_power[0]), defintval:23, TYPE_INT, 0}, \ +{"emul-iface", CONFIG_HLP_EMULIFACE, 0, strptr:&emul_iface, defstrval:"lo", TYPE_STRING, 100}, \ +{"L2-emul", NULL, 0, u8ptr:&nfapi_mode, defuintval:3, TYPE_UINT8, 0}, \ +{"num-ues", NULL, 0, u8ptr:&(NB_UE_INST), defuintval:1, TYPE_UINT8, 0}, \ +{"r" , CONFIG_HLP_PRB, 0, u8ptr:&(frame_parms[0]->N_RB_DL), defintval:25, TYPE_UINT8, 0}, \ +{"dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ +{"usrp-args", CONFIG_HLP_USRP_ARGS, 0, strptr:(char **)&usrp_args, defstrval:"type=b200",TYPE_STRING, 0}, \ +{"usrp-clksrc", CONFIG_HLP_USRP_CLK_SRC,0, strptr:(char **)&usrp_clksrc, defstrval:"internal", TYPE_STRING, 0}, \ +{"mmapped-dma", CONFIG_HLP_DMAMAP, PARAMFLAG_BOOL, uptr:&mmapped_dma, defintval:0, TYPE_INT, 0}, \ +{"clock", CONFIG_HLP_CLK, 0, uptr:&clock_source, defintval:0, TYPE_UINT, 0}, \ +{"s" , CONFIG_HLP_SNR, 0, iptr:&snr_dB, defintval:25, TYPE_INT, 0}, \ +{"T" , CONFIG_HLP_TDD, PARAMFLAG_BOOL, iptr:&tddflag, defintval:0, TYPE_INT, 0}, \ +{"A", CONFIG_HLP_TADV, 0, iptr:&(timingadv), defintval:0, TYPE_INT, 0} \ +} + +/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters specific to UE threads */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*-------------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_UETHREADSPARAMS_DESC { \ +{"threadIQ", NULL, 0, iptr:&(threads.iq), defintval:1, TYPE_INT, 0}, \ +{"threadOneSubframe", NULL, 0, iptr:&(threads.one), defintval:1, TYPE_INT, 0}, \ +{"threadTwoSubframe", NULL, 0, iptr:&(threads.two), defintval:1, TYPE_INT, 0}, \ +{"threadThreeSubframe", NULL, 0, iptr:&(threads.three), defintval:1, TYPE_INT, 0}, \ +{"threadSlot1ProcOne", NULL, 0, iptr:&(threads.slot1_proc_one), defintval:1, TYPE_INT, 0}, \ +{"threadSlot1ProcTwo", NULL, 0, iptr:&(threads.slot1_proc_two), defintval:1, TYPE_INT, 0}, \ +} #define DEFAULT_DLF 2680000000 @@ -160,40 +180,38 @@ /* command line parameters common to eNodeB and UE */ /* optname helpstr paramflags XXXptr defXXXval type numelt */ /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define RF_CONFIG_FILE softmodem_params.rf_config_file +#define PHY_TEST softmodem_params.phy_test +#define WAIT_FOR_SYNC softmodem_params.wait_for_sync +#define SINGLE_THREAD_FLAG softmodem_params.single_thread_flag +#define CHAIN_OFFSET softmodem_params.chain_offset +#define DO_FORMS softmodem_params.do_forms +#define NUMEROLOGY softmodem_params.numerology +#define EMULATE_RF softmodem_params.emulate_rf +#define CLOCK_SOURCE softmodem_params.clock_source +#define USIM_TEST softmodem_params.usim_test #define CMDLINE_PARAMS_DESC { \ -{"rf-config-file", CONFIG_HLP_RFCFGF, 0, strptr:(char **)&rf_config_file, defstrval:NULL, TYPE_STRING, sizeof(rf_config_file)}, \ +{"rf-config-file", CONFIG_HLP_RFCFGF, 0, strptr:(char **)&RF_CONFIG_FILE, defstrval:NULL, TYPE_STRING, sizeof(RF_CONFIG_FILE)}, \ {"ulsch-max-errors", CONFIG_HLP_ULMAXE, 0, uptr:&ULSCH_max_consecutive_errors, defuintval:0, TYPE_UINT, 0}, \ -{"phy-test", CONFIG_HLP_PHYTST, PARAMFLAG_BOOL, iptr:&phy_test, defintval:0, TYPE_INT, 0}, \ -{"usim-test", CONFIG_HLP_USIM, PARAMFLAG_BOOL, u8ptr:&usim_test, defintval:0, TYPE_UINT8, 0}, \ -{"mmapped-dma", CONFIG_HLP_DMAMAP, PARAMFLAG_BOOL, uptr:&mmapped_dma, defintval:0, TYPE_INT, 0}, \ -{"clock", CONFIG_HLP_CLK, 0, uptr:&clock_source, defintval:0, TYPE_UINT, 0}, \ -{"wait-for-sync", NULL, PARAMFLAG_BOOL, iptr:&wait_for_sync, defintval:0, TYPE_INT, 0}, \ -{"single-thread-enable", CONFIG_HLP_NOSNGLT, PARAMFLAG_BOOL, iptr:&single_thread_flag, defintval:0, TYPE_INT, 0}, \ -{"threadIQ", NULL, 0, iptr:&(threads.iq), defintval:1, TYPE_INT, 0}, \ -{"threadOneSubframe", NULL, 0, iptr:&(threads.one), defintval:1, TYPE_INT, 0}, \ -{"threadTwoSubframe", NULL, 0, iptr:&(threads.two), defintval:1, TYPE_INT, 0}, \ -{"threadThreeSubframe", NULL, 0, iptr:&(threads.three), defintval:1, TYPE_INT, 0}, \ -{"threadSlot1ProcOne", NULL, 0, iptr:&(threads.slot1_proc_one), defintval:1, TYPE_INT, 0}, \ -{"threadSlot1ProcTwo", NULL, 0, iptr:&(threads.slot1_proc_two), defintval:1, TYPE_INT, 0}, \ -{"dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ -{"A" , CONFIG_HLP_TADV, 0, uptr:&timing_advance, defintval:0, TYPE_UINT, 0}, \ +{"phy-test", CONFIG_HLP_PHYTST, PARAMFLAG_BOOL, iptr:&PHY_TEST, defintval:0, TYPE_INT, 0}, \ +{"usim-test", CONFIG_HLP_USIM, PARAMFLAG_BOOL, u8ptr:&USIM_TEST, defintval:0, TYPE_UINT8, 0}, \ +{"emulate-rf" , CONFIG_HLP_EMULATE_RF, PARAMFLAG_BOOL, iptr:&EMULATE_RF, defintval:0, TYPE_INT, 0}, \ +{"clock", CONFIG_HLP_CLK, 0, uptr:&CLOCK_SOURCE, defintval:0, TYPE_UINT, 0}, \ +{"wait-for-sync", NULL, PARAMFLAG_BOOL, iptr:&WAIT_FOR_SYNC, defintval:0, TYPE_INT, 0}, \ +{"single-thread-enable", CONFIG_HLP_NOSNGLT, PARAMFLAG_BOOL, iptr:&SINGLE_THREAD_FLAG, defintval:0, TYPE_INT, 0}, \ {"C" , CONFIG_HLP_DLF, 0, uptr:&(downlink_frequency[0][0]), defuintval:2680000000, TYPE_UINT, 0}, \ -{"a" , CONFIG_HLP_CHOFF, 0, iptr:&chain_offset, defintval:0, TYPE_INT, 0}, \ -{"d" , CONFIG_HLP_SOFTS, PARAMFLAG_BOOL, uptr:(uint32_t *)&do_forms, defintval:0, TYPE_INT8, 0}, \ -{"E" , CONFIG_HLP_TQFS, PARAMFLAG_BOOL, i8ptr:&threequarter_fs, defintval:0, TYPE_INT8, 0}, \ -{"m" , CONFIG_HLP_DLMCS, 0, uptr:&target_dl_mcs, defintval:0, TYPE_UINT, 0}, \ -{"t" , CONFIG_HLP_ULMCS, 0, uptr:&target_ul_mcs, defintval:0, TYPE_UINT, 0}, \ +{"a" , CONFIG_HLP_CHOFF, 0, iptr:&CHAIN_OFFSET, defintval:0, TYPE_INT, 0}, \ +{"d" , CONFIG_HLP_SOFTS, PARAMFLAG_BOOL, uptr:(uint32_t *)&DO_FORMS, defintval:0, TYPE_INT8, 0}, \ {"W" , CONFIG_HLP_L2MONW, 0, strptr:(char **)&in_ip, defstrval:"127.0.0.1", TYPE_STRING, sizeof(in_ip)}, \ {"P" , CONFIG_HLP_L2MONP, 0, strptr:(char **)&in_path, defstrval:"/tmp/oai_opt.pcap", TYPE_STRING, sizeof(in_path)}, \ {"q" , CONFIG_HLP_STMON, PARAMFLAG_BOOL, iptr:&opp_enabled, defintval:0, TYPE_INT, 0}, \ {"S" , CONFIG_HLP_MSLOTS, PARAMFLAG_BOOL, u8ptr:&exit_missed_slots, defintval:1, TYPE_UINT8, 0}, \ -{"T" , CONFIG_HLP_TDD, PARAMFLAG_BOOL, iptr:&tddflag, defintval:0, TYPE_INT, 0}, \ -{"s" , CONFIG_HLP_SNR, 0, iptr:&snr_dB, defintval:25, TYPE_INT, 0}, \ -{"numerology" , CONFIG_HLP_NUMEROLOGY, PARAMFLAG_BOOL, iptr:&numerology, defintval:0, TYPE_INT, 0}, \ -{"emulate-rf" , CONFIG_HLP_EMULATE_RF, PARAMFLAG_BOOL, iptr:&emulate_rf, defintval:0, TYPE_INT, 0}, \ +{"numerology" , CONFIG_HLP_NUMEROLOGY, PARAMFLAG_BOOL, iptr:&NUMEROLOGY, defintval:0, TYPE_INT, 0}, \ {"parallel-config", CONFIG_HLP_PARALLEL_CMD,0, strptr:(char **)¶llel_config, defstrval:NULL, TYPE_STRING, 0}, \ {"worker-config", CONFIG_HLP_WORKER_CMD, 0, strptr:(char **)&worker_config, defstrval:NULL, TYPE_STRING, 0}, \ -{"nbiot-disable", CONFIG_HLP_DISABLNBIOT, PARAMFLAG_BOOL, iptr:&nonbiotflag, defintval:0, TYPE_INT, 0} \ +{"noS1", CONFIG_HLP_NOS1, PARAMFLAG_BOOL, uptr:&noS1, defintval:0, TYPE_INT, 0}, \ +{"nokrnmod", CONFIG_HLP_NOKRNMOD, PARAMFLAG_BOOL, uptr:&nokrnmod, defintval:0, TYPE_INT, 0}, \ +{"nbiot-disable", CONFIG_HLP_DISABLNBIOT, PARAMFLAG_BOOL, uptr:&nonbiot, defuintval:0, TYPE_INT, 0}, \ } #define CONFIG_HLP_FLOG "Enable online log \n" @@ -204,11 +222,12 @@ /* command line parameters for LOG utility */ /* optname helpstr paramflags XXXptr defXXXval type numelt */ /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define START_MSC softmodem_params.start_msc #define CMDLINE_LOGPARAMS_DESC { \ {"R" , CONFIG_HLP_FLOG, 0, uptr:&online_log_messages, defintval:1, TYPE_INT, 0}, \ {"g" , CONFIG_HLP_LOGL, 0, uptr:&glog_level, defintval:0, TYPE_UINT, 0}, \ {"telnetsrv", CONFIG_HLP_TELN, PARAMFLAG_BOOL, uptr:&start_telnetsrv, defintval:0, TYPE_UINT, 0}, \ -{"msc", CONFIG_HLP_MSC, PARAMFLAG_BOOL, uptr:start_msc, defintval:0, TYPE_UINT, 0}, \ +{"msc", CONFIG_HLP_MSC, PARAMFLAG_BOOL, uptr:&START_MSC, defintval:0, TYPE_UINT, 0}, \ } #define CMDLINE_ONLINELOG_IDX 0 #define CMDLINE_GLOGLEVEL_IDX 1 @@ -217,6 +236,38 @@ /***************************************************************************************************************************************/ /* */ +#include "threads_t.h" + +#define SOFTMODEM_NOS1_BIT (1<<0) +#define SOFTMODEM_NOKRNMOD_BIT (1<<1) +#define SOFTMODEM_NONBIOT_BIT (1<<2) +typedef struct { + uint64_t optmask; + THREAD_STRUCT thread_struct; + char rf_config_file[1024]; + int phy_test; + uint8_t usim_test; + int emulate_rf; + int wait_for_sync; //eNodeB only + int single_thread_flag; //eNodeB only + int chain_offset; + uint32_t do_forms; + int numerology; + unsigned int start_msc; + int nonbiotflag; + uint32_t clock_source; + int hw_timing_advance; +} softmodem_params_t; + +#define SOFTMODEM_NOS1 ( get_softmodem_optmask() & SOFTMODEM_NOS1_BIT) +#define SOFTMODEM_NOKRNMOD ( get_softmodem_optmask() & SOFTMODEM_NOKRNMOD_BIT) +#define SOFTMODEM_NONBIOT ( get_softmodem_optmask() & SOFTMODEM_NONBIOT_BIT) +extern uint64_t get_softmodem_optmask(void); +extern uint64_t set_softmodem_optmask(uint64_t bitmask); +extern void get_common_options(void); +extern softmodem_params_t* get_softmodem_params(void); + +uint64_t get_pdcp_optmask(void); extern pthread_cond_t sync_cond; extern pthread_mutex_t sync_mutex; extern int sync_var; @@ -244,8 +295,8 @@ extern volatile int start_eNB; extern volatile int start_UE; #endif -#include "threads_t.h" -extern threads_t threads; + + // In lte-enb.c extern void init_eNB(int single_thread_flag,int wait_for_sync); @@ -253,7 +304,7 @@ extern void stop_eNB(int); extern void kill_eNB_proc(int inst); // In lte-ru.c -extern void init_RU(const char*); +extern void init_RU(char*); extern void stop_ru(RU_t *ru); extern void init_RU_proc(RU_t *ru); extern void stop_RU(int nb_ru); @@ -270,7 +321,7 @@ extern void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, c extern void reset_opp_meas(void); extern void print_opp_meas(void); -extern void init_fep_thread(PHY_VARS_eNB *, pthread_attr_t *); + extern void init_td_thread(PHY_VARS_eNB *); extern void init_te_thread(PHY_VARS_eNB *); extern void kill_td_thread(PHY_VARS_eNB *); diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index fa67165693..784c14fa4d 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -58,8 +58,8 @@ #include "UTIL/MATH/oml.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" - - +#include "lte-softmodem.h" +#include "common/config/config_userapi.h" #include "T.h" extern double cpuf; @@ -158,12 +158,21 @@ static const eutra_band_t eutra_bands[] = { }; - +threads_t threads= {-1,-1,-1,-1,-1,-1,-1}; pthread_t main_ue_thread; pthread_attr_t attr_UE_thread; struct sched_param sched_param_UE_thread; + +void get_uethreads_params(void) { + paramdef_t cmdline_threadsparams[] =CMDLINE_UETHREADSPARAMS_DESC; + + + config_process_cmdline( cmdline_threadsparams,sizeof(cmdline_threadsparams)/sizeof(paramdef_t),NULL); +} + + void phy_init_lte_ue_transport(PHY_VARS_UE *ue,int absraction_flag); PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, @@ -179,7 +188,7 @@ PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, memcpy(&(ue->frame_parms), frame_parms, sizeof(LTE_DL_FRAME_PARMS)); } - + ue->hw_timing_advance=get_softmodem_params()->hw_timing_advance; ue->Mod_id = UE_id; ue->mac_enabled = 1; diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 3071544133..2306dbc725 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -19,7 +19,7 @@ * contact@openairinterface.org */ -/*! \file lte-enb.c +/*! \file lte-uesoftmodem.c * \brief Top-level threads for eNodeB * \author R. Knopp, F. Kaltenberger, Navid Nikaein * \date 2012 @@ -34,9 +34,6 @@ #define _GNU_SOURCE /* See feature_test_macros(7) */ #include - -#include "T.h" - #include "rt_wrapper.h" @@ -76,8 +73,6 @@ #include "UTIL/MATH/oml.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" -#include "enb_config.h" -//#include "PHY/TOOLS/time_meas.h" #ifndef OPENAIR2 #include "UTIL/OTG/otg_vars.h" @@ -95,7 +90,7 @@ #endif #include "lte-softmodem.h" -RAN_CONTEXT_t RC; + /* temporary compilation wokaround (UE/eNB split */ uint16_t sf_ahead; @@ -136,12 +131,10 @@ volatile int start_UE = 0; volatile int oai_exit = 0; clock_source_t clock_source = internal; -static int wait_for_sync = 0; + unsigned int mmapped_dma=0; -int single_thread_flag=1; -static int8_t threequarter_fs=0; uint32_t downlink_frequency[MAX_NUM_CCs][4]; int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; @@ -175,11 +168,6 @@ double bw = 10.0e6; static int tx_max_power[MAX_NUM_CCs]; /* = {0,0}*/; -char rf_config_file[1024]; - -int chain_offset=0; -int phy_test = 0; -uint8_t usim_test = 0; uint8_t dci_Format = 0; uint8_t agregation_Level =0xFF; @@ -194,60 +182,33 @@ int rx_input_level_dBm; #ifdef XFORMS extern int otg_enabled; -static char do_forms=0; -#else -int otg_enabled; #endif //int number_of_cards = 1; static LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; -uint32_t target_dl_mcs = 28; //maximum allowed mcs -uint32_t target_ul_mcs = 20; -uint32_t timing_advance = 0; + uint8_t exit_missed_slots=1; uint64_t num_missed_slots=0; // counter for the number of missed slots - +/* prototypes from function implemented in lte-ue.c, probably should be elsewhere in a include + file */ extern void init_UE_stub_single_thread(int nb_inst,int eMBMS_active, int uecap_xer_in, char *emul_iface); extern PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, uint8_t UE_id, uint8_t abstraction_flag); +extern void get_uethreads_params(void); int transmission_mode=1; -int emulate_rf = 0; -int numerology = 0; -char *parallel_config = NULL; -char *worker_config = NULL; + char* usrp_args=NULL; char* usrp_clksrc=NULL; -static THREAD_STRUCT thread_struct; -void set_parallel_conf(char *parallel_conf) -{ - if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0) thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT; - printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf); -} -void set_worker_conf(char *worker_conf) -{ - if(strcmp(worker_conf,"WORKER_DISABLE")==0) thread_struct.worker_conf = WORKER_DISABLE; - else if(strcmp(worker_conf,"WORKER_ENABLE")==0) thread_struct.worker_conf = WORKER_ENABLE; - printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf); -} -PARALLEL_CONF_t get_thread_parallel_conf(void) -{ - return thread_struct.parallel_conf; -} -WORKER_CONF_t get_thread_worker_conf(void) -{ - return thread_struct.worker_conf; -} + /* struct for ethernet specific parameters given in eNB conf file */ eth_params_t *eth_params; @@ -260,7 +221,7 @@ extern char uecap_xer[1024]; char uecap_xer_in=0; int oaisim_flag=0; -threads_t threads= {-1,-1,-1,-1,-1,-1,-1}; + /* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed * this is very hackish - find a proper solution @@ -321,7 +282,8 @@ unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe) { return (dcoff_i_rxfe + (dcoff_q_rxfe<<8)); } -#if !defined(ENABLE_ITTI) + + void signal_handler(int sig) { void *array[10]; size_t size; @@ -335,17 +297,13 @@ void signal_handler(int sig) { backtrace_symbols_fd(array, size, 2); exit(-1); } else { - printf("trying to exit gracefully...\n"); - oai_exit = 1; + char msg[64]; + sprintf(msg,"Received linux signal %s...\n",strsignal(sig)); + exit_function(__FILE__, __FUNCTION__, __LINE__,msg); + + } } -#endif -#define KNRM "\x1B[0m" -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define KBLU "\x1B[34m" -#define RESET "\033[0m" - void exit_function(const char* file, const char* function, const int line, const char* s) @@ -353,9 +311,8 @@ void exit_function(const char* file, const char* function, const int line, const int CC_id; logClean(); - if (s != NULL) { - printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, s); - } + printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, ((s==NULL)?"":s)); + oai_exit = 1; @@ -369,7 +326,8 @@ void exit_function(const char* file, const char* function, const int line, const sleep(1); //allow lte-softmodem threads to exit first #if defined(ENABLE_ITTI) - itti_terminate_tasks (TASK_UNKNOWN); + if(PHY_vars_UE_g != NULL ) + itti_terminate_tasks (TASK_UNKNOWN); #endif exit(1); } @@ -496,50 +454,27 @@ void *l2l1_task(void *arg) { extern int16_t dlsch_demod_shift; -static void get_options(unsigned int *start_msc) { +static void get_options(void) { int CC_id; - int tddflag, nonbiotflag; + int tddflag; char *loopfile=NULL; int dumpframe; - uint32_t online_log_messages; - uint32_t glog_level; - uint32_t start_telnetsrv; - - paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; - paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; + int timingadv; set_default_frame_parms(frame_parms); CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP); - config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); - - if (strlen(in_path) > 0) { - opt_type = OPT_PCAP; - opt_enabled=1; - printf("Enabling OPT for PCAP with the following file %s \n",in_path); - } - if (strlen(in_ip) > 0) { - opt_enabled=1; - opt_type = OPT_WIRESHARK; - printf("Enabling OPT for wireshark for local interface"); - } - - config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL); - if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) { - set_glog_onlinelog(online_log_messages); - } - if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) { - set_glog(glog_level); - } - if (start_telnetsrv) { - load_module_shlib("telnetsrv",NULL,0,NULL); - } +/* unknown parameters on command line will be checked in main + after all init have been performed */ + CONFIG_SETRTFLAG(CONFIG_NOCHECKUNKOPT); + get_common_options(); + get_uethreads_params(); paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC; paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC; config_process_cmdline( cmdline_uemodeparams,sizeof(cmdline_uemodeparams)/sizeof(paramdef_t),NULL); - CONFIG_CLEARRTFLAG(CONFIG_NOEXITONHELP); + config_process_cmdline( cmdline_ueparams,sizeof(cmdline_ueparams)/sizeof(paramdef_t),NULL); if (loopfile != NULL) { printf("Input file for hardware emulation: %s",loopfile); @@ -547,7 +482,7 @@ static void get_options(unsigned int *start_msc) { input_fd = fopen(loopfile,"r"); AssertFatal(input_fd != NULL,"Please provide a valid input file\n"); } - + get_softmodem_params()->hw_timing_advance = timingadv; if ( (cmdline_uemodeparams[CMDLINE_CALIBUERX_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue; if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXMED_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_med; if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXBYP_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_byp; @@ -609,8 +544,6 @@ static void get_options(unsigned int *start_msc) { if(nfapi_mode!=3) uecap_xer_in=1; } *//* UE with config file */ - if(parallel_config != NULL) set_parallel_conf(parallel_config); - if(worker_config != NULL) set_worker_conf(worker_config); } @@ -735,7 +668,7 @@ void init_openair0(LTE_DL_FRAME_PARMS *frame_parms,int rxgain) { openair0_cfg[card].rx_gain[i] = rxgain - rx_gain_off; - openair0_cfg[card].configFilename = rf_config_file; + openair0_cfg[card].configFilename = get_softmodem_params()->rf_config_file; printf("Card %d, channel %d, Setting tx_gain %f, rx_gain %f, tx_freq %f, rx_freq %f\n", card,i, openair0_cfg[card].tx_gain[i], openair0_cfg[card].rx_gain[i], @@ -818,7 +751,6 @@ int main( int argc, char **argv ) int CC_id; uint8_t abstraction_flag=0; - unsigned int start_msc=0; // Default value for the number of UEs. It will hold, // if not changed from the command line option --num-ues @@ -845,10 +777,11 @@ int main( int argc, char **argv ) printf("Reading in command-line options\n"); - for (int i=0;istart_msc) { load_module_shlib("msc",NULL,0,&msc_interface); } MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX); @@ -921,12 +844,11 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con pdcp_pc5_socket_init(); #endif -#if !defined(ENABLE_ITTI) // to make a graceful exit when ctrl-c is pressed signal(SIGSEGV, signal_handler); signal(SIGINT, signal_handler); -#endif - + signal(SIGTERM, signal_handler); + signal(SIGABRT, signal_handler); check_clock(); @@ -954,7 +876,7 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con PHY_vars_UE_g[i][CC_id] = init_ue_vars(frame_parms[CC_id], i,abstraction_flag); - if (phy_test==1) + if (get_softmodem_params()->phy_test==1) PHY_vars_UE_g[i][CC_id]->mac_enabled = 0; else PHY_vars_UE_g[i][CC_id]->mac_enabled = 1; @@ -983,12 +905,12 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con init_UE_stub_single_thread(NB_UE_INST,eMBMS_active,uecap_xer_in,emul_iface); } else { - init_UE(NB_UE_INST,eMBMS_active,uecap_xer_in,0,phy_test,UE_scan,UE_scan_carrier,mode,(int)rx_gain[0][0],tx_max_power[0], + init_UE(NB_UE_INST,eMBMS_active,uecap_xer_in,0,get_softmodem_params()->phy_test,UE_scan,UE_scan_carrier,mode,(int)rx_gain[0][0],tx_max_power[0], frame_parms[0]); } - if (phy_test==0) { + if (get_softmodem_params()->phy_test==0) { printf("Filling UE band info\n"); fill_ue_band_info(); dl_phy_sync_success (0, 0, 0, 1); @@ -998,7 +920,7 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con number_of_cards = 1; for(CC_id=0; CC_idrf_map.card=0; - PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+chain_offset; + PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+(get_softmodem_params()->chain_offset); } } @@ -1128,7 +1050,7 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con printf("XFORMS\n"); - if (do_forms==1) { + if (get_softmodem_params()->do_forms==1) { fl_initialize (&argc, argv, NULL, 0, 0); form_stats = create_form_stats_form(); @@ -1157,7 +1079,12 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con } #endif - + ret=config_check_cmdlineopt(CONFIG_CHECKALLSECTIONS); + if (ret != 0) { + LOG_E(ENB_APP, "%i unknown options in command line (invalid section name)\n",ret); + exit_fun(""); + } + printf("Sending sync to all threads (%p,%p,%p)\n",&sync_var,&sync_cond,&sync_mutex); @@ -1195,7 +1122,7 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con #ifdef XFORMS printf("waiting for XFORMS thread\n"); - if (do_forms==1) { + if (get_softmodem_params()->do_forms==1) { pthread_join(forms_thread,&status); fl_hide_form(form_stats->stats_form); fl_free_form(form_stats->stats_form); diff --git a/targets/RT/USER/rfsim.c b/targets/RT/USER/rfsim.c index cdf8f1ad0d..37ce9f92ea 100644 --- a/targets/RT/USER/rfsim.c +++ b/targets/RT/USER/rfsim.c @@ -62,7 +62,6 @@ sim_t sim; void init_ru_devices(void); -void init_RU(const char*); void *rfsim_top(void *n_frames); void wait_RUs(void) -- GitLab From 8dd62b32e3edf5b0d78baea47d97cba1f244ee64 Mon Sep 17 00:00:00 2001 From: frtabu Date: Fri, 2 Nov 2018 17:29:05 +0100 Subject: [PATCH 05/20] fix bad build_oai directive to compile libconfig for phy-simulators, fix load_configmodule crash because config source not set. --- cmake_targets/build_oai | 2 +- common/config/config_load_configmodule.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 37f8d711db..51d6ac6d01 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -652,7 +652,7 @@ function main() { lte-simulators coding \ libcoding.so $dbin/libcoding.so compilations \ - phy_simulators $config_libconfig_shlib \ + lte-simulators $config_libconfig_shlib \ lib$config_libconfig_shlib.so $dbin/lib$config_libconfig_shlib.so fi diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c index 7c8c61135b..cfb6e38440 100644 --- a/common/config/config_load_configmodule.c +++ b/common/config/config_load_configmodule.c @@ -201,12 +201,20 @@ int OoptIdx=-1; cfgparam = getenv("OAI_CONFIGMODULE"); } -/* default */ +/* default different for UE and softmodem because UE doesn't use config file*/ +/* and -O option is not mandatory for UE */ +/* phy simulators behave as UE */ +/* test of exec name would better be replaced by a parameter to the l */ +/* oad_configmodule function */ if (cfgparam == NULL) { tmpflags = tmpflags | CONFIG_NOOOPT; - cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ; + if (strstr(argv[0],"uesoftmodem") == NULL || strstr(argv[0],"lsim") == NULL) { + cfgparam = CONFIG_LIBCONFIGFILE ":" DEFAULT_CFGFILENAME; + } else { + cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ; + } } - + /* parse the config parameters to set the config source */ i = sscanf(cfgparam,"%m[^':']:%ms",&cfgmode,&modeparams); if (i< 0) { @@ -215,9 +223,9 @@ int OoptIdx=-1; } else if ( i == 1 ) { /* -O argument doesn't contain ":" separator, assume -O option, default cfgmode to libconfig - with one parameter, the path to the configuration file */ + with one parameter, the path to the configuration file cfgmode must not be NULL */ modeparams=cfgmode; - cfgmode=NULL; //strdup(CONFIG_LIBCONFIGFILE); + cfgmode=strdup(CONFIG_LIBCONFIGFILE); } cfgptr = calloc(sizeof(configmodule_interface_t),1); -- GitLab From df6030540a374cdb9b40def26ebb3cd41da28b3e Mon Sep 17 00:00:00 2001 From: frtabu Date: Mon, 5 Nov 2018 11:28:25 +0100 Subject: [PATCH 06/20] reduce compilation warnings in noS1 build to try to pass CI --- openair2/ENB_APP/enb_app.c | 12 ++++++++---- openair2/RRC/LTE/rrc_eNB.c | 7 ++++++- targets/COMMON/create_tasks.c | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c index 37bcd36653..35871b15d2 100644 --- a/openair2/ENB_APP/enb_app.c +++ b/openair2/ENB_APP/enb_app.c @@ -43,10 +43,14 @@ # include "s1ap_eNB.h" # include "sctp_eNB_task.h" # include "gtpv1u_eNB_task.h" -# else -# define EPC_MODE_ENABLED 0 -# endif - +/* temporary warning removale while implementing noS1 */ +/* as config option */ +# else +# ifdef EPC_MODE_ENABLED +# undef EPC_MODE_ENABLED +# endif +# define EPC_MODE_ENABLED 0 +# endif # include "x2ap_eNB.h" # include "x2ap_messages_types.h" # define X2AP_ENB_REGISTER_RETRY_DELAY 10 diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c index e8c52f72f5..6f269b93cb 100644 --- a/openair2/RRC/LTE/rrc_eNB.c +++ b/openair2/RRC/LTE/rrc_eNB.c @@ -85,8 +85,13 @@ # else # include "../../S1AP/s1ap_eNB.h" # endif +/* temporary warning removale while implementing noS1 */ +/* as config option */ #else -# define EPC_MODE_ENABLED 0 +# ifdef EPC_MODE_ENABLED +# undef EPC_MODE_ENABLED +# endif +# define EPC_MODE_ENABLED 0 #endif #include "pdcp.h" diff --git a/targets/COMMON/create_tasks.c b/targets/COMMON/create_tasks.c index 047d8b4037..2c27cc29e8 100644 --- a/targets/COMMON/create_tasks.c +++ b/targets/COMMON/create_tasks.c @@ -33,7 +33,12 @@ # include "nas_ue_task.h" # include "udp_eNB_task.h" # include "gtpv1u_eNB_task.h" +/* temporary warning removale while implementing noS1 */ +/* as config option */ # else +# ifdef EPC_MODE_ENABLED +# undef EPC_MODE_ENABLED +# endif # define EPC_MODE_ENABLED 0 # endif # if ENABLE_RAL -- GitLab From d151ce6feb8fe73da39f3c8cf2870a9bbd45c0c4 Mon Sep 17 00:00:00 2001 From: frtabu Date: Mon, 5 Nov 2018 17:28:00 +0100 Subject: [PATCH 07/20] Add a parameter to load_configmodule API to allow an exec to specify that it may be run with only command line options --- cmake_targets/build_oai | 6 +++--- common/config/config_load_configmodule.c | 8 ++++---- common/config/config_load_configmodule.h | 5 +++-- openair1/SIMULATION/LTE_PHY/dlsim.c | 2 +- openair1/SIMULATION/LTE_PHY/ulsim.c | 2 +- targets/RT/USER/lte-softmodem.c | 2 +- targets/RT/USER/lte-uesoftmodem.c | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 51d6ac6d01..c6f8199af2 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -651,9 +651,9 @@ function main() { compilations \ lte-simulators coding \ libcoding.so $dbin/libcoding.so - compilations \ - lte-simulators $config_libconfig_shlib \ - lib$config_libconfig_shlib.so $dbin/lib$config_libconfig_shlib.so +# compilations \ +# lte-simulators $config_libconfig_shlib \ +# lib$config_libconfig_shlib.so $dbin/lib$config_libconfig_shlib.so fi # Core simulators diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c index cfb6e38440..15211aec8a 100644 --- a/common/config/config_load_configmodule.c +++ b/common/config/config_load_configmodule.c @@ -169,7 +169,7 @@ int config_cmdlineonly_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) return numdefvals; } -configmodule_interface_t *load_configmodule(int argc, char **argv) +configmodule_interface_t *load_configmodule(int argc, char **argv, uint32_t initflags) { char *cfgparam=NULL; char *modeparams=NULL; @@ -208,10 +208,10 @@ int OoptIdx=-1; /* oad_configmodule function */ if (cfgparam == NULL) { tmpflags = tmpflags | CONFIG_NOOOPT; - if (strstr(argv[0],"uesoftmodem") == NULL || strstr(argv[0],"lsim") == NULL) { - cfgparam = CONFIG_LIBCONFIGFILE ":" DEFAULT_CFGFILENAME; + if ( initflags & CONFIG_ENABLECMDLINEONLY) { + cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ; } else { - cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ; + cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ;cfgparam = CONFIG_LIBCONFIGFILE ":" DEFAULT_CFGFILENAME; } } diff --git a/common/config/config_load_configmodule.h b/common/config/config_load_configmodule.h index 1f4ebde92d..d98e825095 100644 --- a/common/config/config_load_configmodule.h +++ b/common/config/config_load_configmodule.h @@ -106,8 +106,9 @@ extern configmodule_interface_t *cfgptr; #define printf_params(...) if ( (cfgptr->rtflags & (CONFIG_PRINTPARAMS)) != 0 ) { printf ( __VA_ARGS__ ); } #define printf_ptrs(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 ) { printf ( __VA_ARGS__ ); } #define printf_cmdl(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGCMDLINE)) != 0 ) { printf ( __VA_ARGS__ ); } - -extern configmodule_interface_t *load_configmodule(int argc, char **argv); + +#define CONFIG_ENABLECMDLINEONLY (1<<1) +extern configmodule_interface_t *load_configmodule(int argc, char **argv, uint32_t initflags); extern void end_configmodule(void); #endif /* INCLUDE_CONFIG_LOADCONFIGMODULE_H */ diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c index 0f4655eb2c..246bdd7007 100644 --- a/openair1/SIMULATION/LTE_PHY/dlsim.c +++ b/openair1/SIMULATION/LTE_PHY/dlsim.c @@ -988,7 +988,7 @@ int main(int argc, char **argv) if (transmission_mode>1) pa=dBm3; printf("dlsim: tmode %d, pa %d\n",transmission_mode,pa); - AssertFatal(load_configmodule(argc,argv) != NULL, + AssertFatal(load_configmodule(argc,argv, CONFIG_ENABLECMDLINEONLY) != NULL, "cannot load configuration module, exiting\n"); logInit(); set_glog_onlinelog(true); diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c index c015063b60..53a2c22f15 100644 --- a/openair1/SIMULATION/LTE_PHY/ulsim.c +++ b/openair1/SIMULATION/LTE_PHY/ulsim.c @@ -429,7 +429,7 @@ int main(int argc, char **argv) { cpu_freq_GHz = (double)get_cpu_freq_GHz(); cpuf = cpu_freq_GHz; printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz); - AssertFatal(load_configmodule(argc,argv) != NULL, + AssertFatal(load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) != NULL, "cannot load configuration module, exiting\n"); logInit(); // enable these lines if you need debug info diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c index 00ae350ea2..4cf257f353 100644 --- a/targets/RT/USER/lte-softmodem.c +++ b/targets/RT/USER/lte-softmodem.c @@ -695,7 +695,7 @@ int main( int argc, char **argv ) #if defined (XFORMS) int ret; #endif - if ( load_configmodule(argc,argv) == NULL) { + if ( load_configmodule(argc,argv,0) == NULL) { exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); } diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 2306dbc725..593b64ea40 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -761,7 +761,7 @@ int main( int argc, char **argv ) #endif start_background_system(); - if ( load_configmodule(argc,argv) == NULL) { + if ( load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) == NULL) { exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); } @@ -887,7 +887,7 @@ int main( int argc, char **argv ) if (simL1flag==1) { - AssertFatal(NULL!=load_configmodule(argc,argv), + AssertFatal(NULL!=load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY), "[SOFTMODEM] Error, configuration module init failed\n"); RCConfig_sim(); -- GitLab From 0a829e3eebbff10d8dc96860dd0ab300806a3ad5 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Tue, 6 Nov 2018 11:37:49 +0100 Subject: [PATCH 08/20] CI: removing obsolete options from CI scenarios Signed-off-by: Raphael Defosseux --- ci-scripts/xml_files/enb_usrp210_band7.xml | 6 +++--- ci-scripts/xml_files/enb_usrpb210_band40.xml | 6 +++--- ci-scripts/xml_files/if4p5_usrp210_band40.xml | 12 ++++++------ ci-scripts/xml_files/if4p5_usrp210_band7.xml | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ci-scripts/xml_files/enb_usrp210_band7.xml b/ci-scripts/xml_files/enb_usrp210_band7.xml index 0785ad815d..c408dc7882 100644 --- a/ci-scripts/xml_files/enb_usrp210_band7.xml +++ b/ci-scripts/xml_files/enb_usrp210_band7.xml @@ -40,19 +40,19 @@ Initialize_eNB Initialize eNB (FDD/Band7/5MHz) - -O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf Initialize_eNB Initialize eNB (FDD/Band7/10MHz) - -O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf Initialize_eNB Initialize eNB (FDD/Band7/20MHz) - -O ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf diff --git a/ci-scripts/xml_files/enb_usrpb210_band40.xml b/ci-scripts/xml_files/enb_usrpb210_band40.xml index 1af1c319cf..53a0dc9380 100644 --- a/ci-scripts/xml_files/enb_usrpb210_band40.xml +++ b/ci-scripts/xml_files/enb_usrpb210_band40.xml @@ -43,19 +43,19 @@ Initialize_eNB Initialize eNB (TDD/Band40/5MHz) - -O ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf Initialize_eNB Initialize eNB (TDD/Band40/10MHz/info) - -O ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf Initialize_eNB Initialize eNB (TDD/Band40/20MHz/info) - -O ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40.xml b/ci-scripts/xml_files/if4p5_usrp210_band40.xml index 9c1b721bef..b7877009fd 100644 --- a/ci-scripts/xml_files/if4p5_usrp210_band40.xml +++ b/ci-scripts/xml_files/if4p5_usrp210_band40.xml @@ -46,42 +46,42 @@ Initialize_eNB Initialize RRU (TDD/Band40) - -O ci-scripts/conf_files/rru.tdd.band40.conf --codingw --fepw + -O ci-scripts/conf_files/rru.tdd.band40.conf 0 Initialize_eNB Initialize RCC (TDD/Band40/5MHz) - -O ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf 1 Initialize_eNB Initialize RRU (TDD/Band40) - -O ci-scripts/conf_files/rru.tdd.band40.conf --codingw --fepw + -O ci-scripts/conf_files/rru.tdd.band40.conf 0 Initialize_eNB Initialize RCC (TDD/Band40/10MHz/info) - -O ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf 1 Initialize_eNB Initialize RRU (TDD/Band40) - -O ci-scripts/conf_files/rru.tdd.band40.conf --codingw --fepw + -O ci-scripts/conf_files/rru.tdd.band40.conf 0 Initialize_eNB Initialize RCC (TDD/Band40/20MHz/info) - -O ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf 1 diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7.xml b/ci-scripts/xml_files/if4p5_usrp210_band7.xml index a3e5ecd72c..9ca3a113bf 100644 --- a/ci-scripts/xml_files/if4p5_usrp210_band7.xml +++ b/ci-scripts/xml_files/if4p5_usrp210_band7.xml @@ -44,42 +44,42 @@ Initialize_eNB Initialize RRU (FDD/Band7) - -O ci-scripts/conf_files/rru.fdd.band7.conf --codingw --fepw + -O ci-scripts/conf_files/rru.fdd.band7.conf 1 Initialize_eNB Initialize RCC (FDD/Band7/5MHz) - -O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf 0 Initialize_eNB Initialize RRU (FDD/Band7) - -O ci-scripts/conf_files/rru.fdd.band7.conf --codingw --fepw + -O ci-scripts/conf_files/rru.fdd.band7.conf 1 Initialize_eNB Initialize RCC (FDD/Band7/10MHz) - -O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf 0 Initialize_eNB Initialize RRU (FDD/Band7) - -O ci-scripts/conf_files/rru.fdd.band7.conf --codingw --fepw + -O ci-scripts/conf_files/rru.fdd.band7.conf 1 Initialize_eNB Initialize RCC (FDD/Band7/20MHz) - -O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf --codingw --fepw + -O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf 0 -- GitLab From 00f4890b14b917fe80010b30072b1cf04f3c4815 Mon Sep 17 00:00:00 2001 From: frtabu Date: Fri, 16 Nov 2018 17:53:51 +0100 Subject: [PATCH 09/20] write logging tool documentation --- common/utils/DOC/loader/devusage.md | 7 +- common/utils/LOG/DOC/arch.md | 9 + common/utils/LOG/DOC/devusage.md | 119 +++++++++++ common/utils/LOG/DOC/log.md | 19 ++ common/utils/LOG/DOC/rtusage.md | 265 ++++++++++++++++++++++++ common/utils/telnetsrv/DOC/telnetlog.md | 3 +- 6 files changed, 417 insertions(+), 5 deletions(-) create mode 100644 common/utils/LOG/DOC/arch.md create mode 100644 common/utils/LOG/DOC/devusage.md create mode 100644 common/utils/LOG/DOC/log.md create mode 100644 common/utils/LOG/DOC/rtusage.md diff --git a/common/utils/DOC/loader/devusage.md b/common/utils/DOC/loader/devusage.md index 4b82e18362..915075c361 100644 --- a/common/utils/DOC/loader/devusage.md +++ b/common/utils/DOC/loader/devusage.md @@ -1,7 +1,6 @@ -The configuration module objectives are -1. Allow easy parameters management in oai, helping the development of a flexible, modularized and fully configurable softmodem. -1. Use a common configuration API in all oai modules -1. Allow development of alternative configuration sources without modifying the oai code. Today the only delivered configuration source is the libconfig format configuration file. +The loader objectives are +1. provides a common mechanism to prevent an executable to include code that is only used under specific configurations, without rebuilding the code +1. Provide a common mechanism to allow to choose between different implementations of a given set of functions, without rebuilding the code As a developer you may need to look at these sections: diff --git a/common/utils/LOG/DOC/arch.md b/common/utils/LOG/DOC/arch.md new file mode 100644 index 0000000000..f774655771 --- /dev/null +++ b/common/utils/LOG/DOC/arch.md @@ -0,0 +1,9 @@ +# logging facility source files + +The oai logging facility is implemented in two source files, located in [common/utils](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils) +1. [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/log.c) contains logging implementation +1. [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/log.h) is the logging facility include file containing both private and public data type definitions. It also contain API prototypes. + + +[logging facility main page](log.md) +[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) \ No newline at end of file diff --git a/common/utils/LOG/DOC/devusage.md b/common/utils/LOG/DOC/devusage.md new file mode 100644 index 0000000000..2d5582ff7c --- /dev/null +++ b/common/utils/LOG/DOC/devusage.md @@ -0,0 +1,119 @@ +### logging facility usage +The logging facility objectives are +1. provide a common console tracing mechanism +1. Allow a flexible activation of console traces, by configuration or dynamically at any time while code is running. + +Once the logging facility has been initialized and configured developpers use C preprocessor macros to include console messages in their code. At execution time, these traces will be printed or not to the console depending on the configuration, as described [here](rtusage.md). The logging facility also defines preprocessor macros to include condtional code, to dump memory blocks (buffers, messages...). + +All macros are defined in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) include file, which must be included in any source file using the logging facility macros. + + [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) also includes the prototypes of the functions that have to be called to initialize, configure or get the status of console logs. + +#### console messages macros +```C +LOG_E(,,,...) +LOG_W(,,,...) +LOG_I(,,,...) +LOG_D(,,,...) +LOG_T(,,,...) +) +``` +these macros are used in place of the printf C function. The additionnal ***component*** parameter identifies the functionnal module which generates the message. At run time, the message will only be printed if the configured log level for the component is greater or equal than the macro level used in the code. + +| macro | level letter | level value | level name | +|:---------|:---------------|:---------------|----------------:| +| LOG_E | E | 0 | error | +| LOG_W | W | 1 | warning | +| LOG_I | I | 2 | informational | +| LOG_D | D | 3 | debug | +| LOG_T | T | 4 | trace | + +component list is defined as an `enum` in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h). A new component can be defined by adding an item in this type, it must also be defined in the T tracer [T_messages.txt ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/T/T_messages.txt). + +Most oai sources are including LOG macros. + +#### conditional code macros + +```C +LOG_DEBUGFLAG() +``` +this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md) +```C +if ( LOG_DEBUGFLAG() { +/* + the code below is only executed if the corresponding + _debug option is set. + */ +...................... +...................... +} +``` +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c#L396) + +#### memory dump macros +```C +LOG_DUMPFLAG() +``` +this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md). It is mainly provided to surround LOG_M macros or direct calls to `log_dump`which otherwise would be unconditionals. +```C +if ( LOG_DUMPFLAG() { +/* + the code below is only executed if the corresponding + _dump option is set. + */ +LOG_M(............. +LOG_M(............. +log_dump(... +} + +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205) +#### matlab format dump +```C +LOG_M(file, vector, data, len, dec, format) +``` +|argument| type| description | +|:-----------|:-------|-----------------:| +| file | char* |path to the fle which will contain the dump | +|vector |char * |name of the dump, printed at the top of the dump file | +|data| void *| pointer to the memory to be dumpped | +|len | int | length of the data to be dumpped, in `dec` unit| +| dec| int | length of each data item.Interpretation depends on format| +|format| int | defines the type of data to be dumped| + +This macro can be used to dump a buffer in a format that can be used for analyze via tools like matlab or octave. **It must be surrounded by LOG_DEBUGFLAG or LOG_DUMPFLAG macros, to prevent the dump to be built unconditionally.** The LOG_M macro points to the `write_file_matlab` function implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). **This function should be revisited for more understandable implementation and ease of use (format parameter ???)** +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205) + +#### hexadecimal format dump +```C +LOG_DUMPMSG(c, f, b, s, x...) +``` +dumps a memory region if the corresponding debug flag `f` is set as explained here [run time usage page](rtusage.md) + +|argument| type| description | +|:-----------|:-------|-----------------:| +| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments | +|f |int |flag used to filter the dump depending on the logs configuration. flag list is defined by the LOG_MASKMAP_INIT macro in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) | +|b| void *| pointer to the memory to be dumpped | +|s | int | length of the data to be dumpped in char| +| x...| printf format and arguments| text string to be printed at the top of the dump| + +This macro can be used to conditionaly dump a buffer, bytes by bytes, giving the integer value of each byte in hexadecimal form. +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/RRC/LTE/rrc_eNB.c#L1181) + +This macro points to the `log_dump` function, implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). This function can also dump buffers containing `double` data via the LOG_UDUMPMSG macro + +```C +LOG_UDUMPMSG(c, b, s, f, x...) +``` +|argument| type| description | +|:-----------|:-------|-----------------:| +| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments | +|b| void *| pointer to the memory to be dumpped | +|s | int | length of the data to be dumpped in char| +|f| int | format of dumped data LOG_DUMP_CHAR or LOG_DUMP_DOUBLE| +| x...| printf format and arguments| text string to be printed at the top of the dump| + +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/SIMULATION/LTE_PHY/dlsim.c#L1974) + +[logging facility main page](log.md) +[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) diff --git a/common/utils/LOG/DOC/log.md b/common/utils/LOG/DOC/log.md new file mode 100644 index 0000000000..d7a94d5bbd --- /dev/null +++ b/common/utils/LOG/DOC/log.md @@ -0,0 +1,19 @@ +# OAI console logging facility + +oai includes a console logging facility that any component should use when writting informational or debugging messages to the softmodem or uesoftmodem stdout stream. +By default, this facility is included at build-time and activated at run-time. The T Tracer and the Logging facility share common options for activation: + +- To disable the logging facility (and T Tracer) at build-time use the *--disable-T-Tracer* switch: + +```bash +/build_oai --disable-T-Tracer +``` +- To use the the T-Tracer instead of the console logging facility, use the command line option *T_stdout*. *T_stdout* is a boolean option, which, when set to 0 (false) disable the console logging facility. All stdout messages are then sent to the T-Tracer. + +## Documentation + +* [runtime usage](rtusage.md) +* [developer usage](config/devusage.md) +* [module architecture](arch.md) + +[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) diff --git a/common/utils/LOG/DOC/rtusage.md b/common/utils/LOG/DOC/rtusage.md new file mode 100644 index 0000000000..60835bafaf --- /dev/null +++ b/common/utils/LOG/DOC/rtusage.md @@ -0,0 +1,265 @@ +## configuring the logging facility +The logging facility is fully configurable and it uses the [config module](../../../config/config.md) to get its parameters at init time. The [telnet server](../../telnetsrv/DOC/telnetsrv.md) includes a set of commands which can be used to dynamically modify the logging facility behavior + +All logging facility parameters are defined in the log_config section. Some parameters are global to the logging facility, they modify the way messages are printed to stdout. Conversely, some parameters are specific to a component and only modify the behavior for messages issued by a given component. A third type of parameters can be used to activate conditional debug code or dump messages or buffers. + +### global parameters + +| name | type | default | description | +|:---:|:---:|:---:|:----| +| `global_log_level` | `pre-defined string of char` | `info` | Allows printing of messages up to the specified level. Available levels, from lower to higher are `error`,`warn`,`info`,`debug`,`trace` | +| `global_log_online` | `boolean` | 1 (=true) | If false, all console messages are discarded, whatever their level | +| `global_log_options` | `list of pre-defined string of char` | | 3 options can be specified to trigger the information added in the header of the message: `nocolor`, disable color usage in log messages, usefull when redirecting logs to a file, where escape sequences used for color selection can be annoying, `level`, add a one letter level id in the message header (T,D,I,W,E for trace, debug, info, warning, error),`thread`, add the thread name in the message header| + +### Component specific parameters +| name | type | default | description | +|:---:|:---:|:---:|:----| +| `_log_level` | `boolean` | global log level, as defined by the `global_log_level ` parameter) | +| `_log_infile` | `boolean` | 0 = false| Triggers the redirection of log messages printed by the specified component in a file. The file path and name is /tmp/.[extension] the extension is optional and component dependant, it can be `log `, `dat `, `txt `| + +The list of components defined within oai can be retrieved from the [config module](../../../config/config.md) traces, when asking for config module debugging info on the command line: + +```bash +./lte-softmodem -O libconfig::dbgl5 + +[LIBCONFIG] log_config.global_log_level: "info" +[CONFIG] global_log_online: 1 +[CONFIG] log_config.global_log_online set to default value +[LIBCONFIG] log_config: 3/3 parameters successfully set, (1 to default value) +[LIBCONFIG] global_log_options[0]: nocolor +[LIBCONFIG] global_log_options[1]: level +[LIBCONFIG] global_log_options[2]: thread +[CONFIG] log_config 1 options set from command line +[LIBCONFIG] log_config.phy_log_level: "info" +[LIBCONFIG] log_config.mac_log_level: "info" +[CONFIG] log_config.sim_log_level set to default value "info" +[CONFIG] log_config.ocg_log_level set to default value "info" +[CONFIG] log_config.omg_log_level set to default value "info" +[CONFIG] log_config.opt_log_level set to default value "info" +[CONFIG] log_config.otg_log_level set to default value "info" +[CONFIG] log_config.otg_latency_log_level set to default value "info" +[CONFIG] log_config.otg_latency_bg_log_level set to default value "info" +[CONFIG] log_config.otg_gp_log_level set to default value "info" +[CONFIG] log_config.otg_gp_bg_log_level set to default value "info" +[CONFIG] log_config.otg_jitter_log_level set to default value "info" +[LIBCONFIG] log_config.rlc_log_level: "info" +[LIBCONFIG] log_config.pdcp_log_level: "info" +[LIBCONFIG] log_config.rrc_log_level: "info" +[CONFIG] log_config.nas_log_level set to default value "info" +[CONFIG] log_config.perf_log_level set to default value "info" +[CONFIG] log_config.oip_log_level set to default value "info" +[CONFIG] log_config.cli_log_level set to default value "info" +[CONFIG] log_config.msc_log_level set to default value "info" +[CONFIG] log_config.ocm_log_level set to default value "info" +[CONFIG] log_config.udp_log_level set to default value "info" +[CONFIG] log_config.gtpv1u_log_level set to default value "info" +[CONFIG] log_config.comp23?_log_level set to default value "info" +[CONFIG] log_config.s1ap_log_level set to default value "info" +[CONFIG] log_config.sctp_log_level set to default value "info" +[LIBCONFIG] log_config.hw_log_level: "info" +[CONFIG] log_config.osa_log_level set to default value "info" +[CONFIG] log_config.eral_log_level set to default value "info" +[CONFIG] log_config.mral_log_level set to default value "info" +[CONFIG] log_config.enb_app_log_level set to default value "info" +[CONFIG] log_config.flexran_agent_log_level set to default value "info" +[CONFIG] log_config.tmr_log_level set to default value "info" +[CONFIG] log_config.usim_log_level set to default value "info" +[CONFIG] log_config.localize_log_level set to default value "info" +[CONFIG] log_config.x2ap_log_level set to default value "info" +[CONFIG] log_config.loader_log_level set to default value "info" +[CONFIG] log_config.asn_log_level set to default value "info" +[LIBCONFIG] log_config: 38/38 parameters successfully set, (32 to default value) +[CONFIG] log_config 0 options set from command line +[CONFIG] phy_log_infile: 0 +[CONFIG] log_config.phy_log_infile set to default value +[CONFIG] mac_log_infile: 0 +[CONFIG] log_config.mac_log_infile set to default value +[CONFIG] sim_log_infile: 0 +[CONFIG] log_config.sim_log_infile set to default value +[CONFIG] ocg_log_infile: 0 +[CONFIG] log_config.ocg_log_infile set to default value +[CONFIG] omg_log_infile: 0 +[CONFIG] log_config.omg_log_infile set to default value +[CONFIG] opt_log_infile: 0 +[CONFIG] log_config.opt_log_infile set to default value +[CONFIG] otg_log_infile: 0 +[CONFIG] log_config.otg_log_infile set to default value +[CONFIG] otg_latency_log_infile: 0 +[CONFIG] log_config.otg_latency_log_infile set to default value +[CONFIG] otg_latency_bg_log_infile: 0 +[CONFIG] log_config.otg_latency_bg_log_infile set to default value +[CONFIG] otg_gp_log_infile: 0 +[CONFIG] log_config.otg_gp_log_infile set to default value +[CONFIG] otg_gp_bg_log_infile: 0 +[CONFIG] log_config.otg_gp_bg_log_infile set to default value +[CONFIG] otg_jitter_log_infile: 0 +[CONFIG] log_config.otg_jitter_log_infile set to default value +[CONFIG] rlc_log_infile: 0 +[CONFIG] log_config.rlc_log_infile set to default value +[CONFIG] pdcp_log_infile: 0 +[CONFIG] log_config.pdcp_log_infile set to default value +[CONFIG] rrc_log_infile: 0 +[CONFIG] log_config.rrc_log_infile set to default value +[CONFIG] nas_log_infile: 0 +[CONFIG] log_config.nas_log_infile set to default value +[CONFIG] perf_log_infile: 0 +[CONFIG] log_config.perf_log_infile set to default value +[CONFIG] oip_log_infile: 0 +[CONFIG] log_config.oip_log_infile set to default value +[CONFIG] cli_log_infile: 0 +[CONFIG] log_config.cli_log_infile set to default value +[CONFIG] msc_log_infile: 0 +[CONFIG] log_config.msc_log_infile set to default value +[CONFIG] ocm_log_infile: 0 +[CONFIG] log_config.ocm_log_infile set to default value +[CONFIG] udp_log_infile: 0 +[CONFIG] log_config.udp_log_infile set to default value +[CONFIG] gtpv1u_log_infile: 0 +[CONFIG] log_config.gtpv1u_log_infile set to default value +[CONFIG] comp23?_log_infile: 0 +[CONFIG] log_config.comp23?_log_infile set to default value +[CONFIG] s1ap_log_infile: 0 +[CONFIG] log_config.s1ap_log_infile set to default value +[CONFIG] sctp_log_infile: 0 +[CONFIG] log_config.sctp_log_infile set to default value +[CONFIG] hw_log_infile: 0 +[CONFIG] log_config.hw_log_infile set to default value +[CONFIG] osa_log_infile: 0 +[CONFIG] log_config.osa_log_infile set to default value +[CONFIG] eral_log_infile: 0 +[CONFIG] log_config.eral_log_infile set to default value +[CONFIG] mral_log_infile: 0 +[CONFIG] log_config.mral_log_infile set to default value +[CONFIG] enb_app_log_infile: 0 +[CONFIG] log_config.enb_app_log_infile set to default value +[CONFIG] flexran_agent_log_infile: 0 +[CONFIG] log_config.flexran_agent_log_infile set to default value +[CONFIG] tmr_log_infile: 0 +[CONFIG] log_config.tmr_log_infile set to default value +[CONFIG] usim_log_infile: 0 +[CONFIG] log_config.usim_log_infile set to default value +[CONFIG] localize_log_infile: 0 +[CONFIG] log_config.localize_log_infile set to default value +[CONFIG] x2ap_log_infile: 0 +[CONFIG] log_config.x2ap_log_infile set to default value +[CONFIG] loader_log_infile: 0 +[CONFIG] log_config.loader_log_infile set to default value +[CONFIG] asn_log_infile: 0 +[CONFIG] log_config.asn_log_infile set to default value +[LIBCONFIG] log_config: 38/38 parameters successfully set, (38 to default value) +[CONFIG] log_config 0 options set from command line +[CONFIG] PRACH_debug: 0 +[CONFIG] log_config.PRACH_debug set to default value +[CONFIG] RU_debug: 0 +[CONFIG] log_config.RU_debug set to default value +[CONFIG] UE_PHYPROC_debug: 0 +[CONFIG] log_config.UE_PHYPROC_debug set to default value +[CONFIG] LTEESTIM_debug: 0 +[CONFIG] log_config.LTEESTIM_debug set to default value +[CONFIG] DLCELLSPEC_debug: 0 +[CONFIG] log_config.DLCELLSPEC_debug set to default value +[CONFIG] ULSCH_debug: 0 +[CONFIG] log_config.ULSCH_debug set to default value +[CONFIG] RRC_debug: 0 +[CONFIG] log_config.RRC_debug set to default value +[CONFIG] PDCP_debug: 0 +[CONFIG] log_config.PDCP_debug set to default value +[CONFIG] DFT_debug: 0 +[CONFIG] log_config.DFT_debug set to default value +[CONFIG] ASN1_debug: 0 +[CONFIG] log_config.ASN1_debug set to default value +[CONFIG] CTRLSOCKET_debug: 0 +[CONFIG] log_config.CTRLSOCKET_debug set to default value +[CONFIG] SECURITY_debug: 0 +[CONFIG] log_config.SECURITY_debug set to default value +[CONFIG] NAS_debug: 0 +[CONFIG] log_config.NAS_debug set to default value +[CONFIG] RLC_debug: 0 +[CONFIG] log_config.RLC_debug set to default value +[CONFIG] UE_TIMING_debug: 0 +[CONFIG] log_config.UE_TIMING_debug set to default value +[LIBCONFIG] log_config: 15/15 parameters successfully set, (15 to default value) +[CONFIG] log_config 0 options set from command line +[CONFIG] PRACH_dump: 0 +[CONFIG] log_config.PRACH_dump set to default value +[CONFIG] RU_dump: 0 +[CONFIG] log_config.RU_dump set to default value +[CONFIG] UE_PHYPROC_dump: 0 +[CONFIG] log_config.UE_PHYPROC_dump set to default value +[CONFIG] LTEESTIM_dump: 0 +[CONFIG] log_config.LTEESTIM_dump set to default value +[CONFIG] DLCELLSPEC_dump: 0 +[CONFIG] log_config.DLCELLSPEC_dump set to default value +[CONFIG] ULSCH_dump: 0 +[CONFIG] log_config.ULSCH_dump set to default value +[CONFIG] RRC_dump: 0 +[CONFIG] log_config.RRC_dump set to default value +[CONFIG] PDCP_dump: 0 +[CONFIG] log_config.PDCP_dump set to default value +[CONFIG] DFT_dump: 0 +[CONFIG] log_config.DFT_dump set to default value +[CONFIG] ASN1_dump: 0 +[CONFIG] log_config.ASN1_dump set to default value +[CONFIG] CTRLSOCKET_dump: 0 +[CONFIG] log_config.CTRLSOCKET_dump set to default value +[CONFIG] SECURITY_dump: 0 +[CONFIG] log_config.SECURITY_dump set to default value +[CONFIG] NAS_dump: 0 +[CONFIG] log_config.NAS_dump set to default value +[CONFIG] RLC_dump: 0 +[CONFIG] log_config.RLC_dump set to default value +[CONFIG] UE_TIMING_dump: 0 +[CONFIG] log_config.UE_TIMING_dump set to default value +[LIBCONFIG] log_config: 15/15 parameters successfully set, (15 to default value) +[CONFIG] log_config 0 options set from command line +log init done + +``` +It can also be retrieved when using the telnet server, as explained [below](### Using the telnet server to configure the logging facility) + +### parameters to activate conditional code +| name | type | default | description | +|:---:|:---:|:---:|:----| +| `_debug` | `boolean` | 0 = false | Triggers the activation of conditional code identified by the specified flag. +| `_dump` | `boolean` | 0 = false| Triggers buffer dump, on the console in text form or in a file in matlab format, depending on the developper choice and forcasted usage| + +### Using the configuration file to configure the logging facility +The following example sets all components log level to info, exept for hw,phy,mac,rlc,pdcp,rrc which log levels are set to error or warning. +```bash + log_config : + { + global_log_level ="info"; + hw_log_level ="error"; + phy_log_level ="error"; + mac_log_level ="warn"; + rlc_log_level ="error" + pdcp_log_level ="error"; + rrc_log_level ="error"; + }; +``` +### Using the command line to configure the logging facility +Command line parameter values supersedes values specified in the configuration file. +```bash +./lte-softmodem -O --log_config.global_log_options nocolor,level,thread --log_config.prach_log_level debug --log_config.PRACH_debug +``` +In this example to get all the debug PRACH messages it is necessary to also set the PRACH_debug flag. This is a choice from the developper. +The log messages will be printed whithout color and the header will include the lmessage evel and the thread name: +```bash +[PHY]I ru thread Time in secs now: 104652566 +[PHY]I ru thread Time in secs last pps: 91827117 +[PHY]I ru thread RU 0 rf device ready +[PHY]I ru thread RU 0 no asynch_south interface +[MAC]E rxtx processing SCHED_MODE=0 +[PHY]I lte-softmodem PRACH (eNB) : running rx_prach for subframe 1, prach_FreqOffset 2, prach_ConfigIndex 0 , rootSequenceIndex 0 +[PHY]I lte-softmodem prach_I0 = 0.0 dB +[PHY]I rxtx processing max_I0 21, min_I0 0 +[PHY]I lte-softmodem PRACH (eNB) : running rx_prach for subframe 1, prach_FreqOffset 2, prach_ConfigIndex 0 , rootSequenceIndex 0 +[PHY]I lte-softmodem PRACH (eNB) : running rx_prach for subframe 1, prach_FreqOffset 2, prach_ConfigIndex 0 , rootSequenceIndex 0 +``` + +### Using the telnet server to configure the logging facility +The telnet server includes a `log` command which can be used to dymically modify the logging facility configuration parameters. +[telnet server ***softmodem log*** commands](../../telnetsrv/DOC/telnetlog.md) + +[logging facility main page](log.md) +[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) diff --git a/common/utils/telnetsrv/DOC/telnetlog.md b/common/utils/telnetsrv/DOC/telnetlog.md index 7c1d4f0384..0faaf9c02e 100644 --- a/common/utils/telnetsrv/DOC/telnetlog.md +++ b/common/utils/telnetsrv/DOC/telnetlog.md @@ -92,4 +92,5 @@ Connection closed by foreign host. ``` [oai telnetserver home](telnetsrv.md) -[oai telnetserver usage home](telnetusage.md) \ No newline at end of file +[oai telnetserver usage home](telnetusage.md) +[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) \ No newline at end of file -- GitLab From 2f8c3d6eaaafae786bcf02e9786d1276303925a6 Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Fri, 16 Nov 2018 18:04:49 +0100 Subject: [PATCH 10/20] fix broken links --- common/utils/LOG/DOC/arch.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/utils/LOG/DOC/arch.md b/common/utils/LOG/DOC/arch.md index f774655771..348216983b 100644 --- a/common/utils/LOG/DOC/arch.md +++ b/common/utils/LOG/DOC/arch.md @@ -1,8 +1,8 @@ # logging facility source files -The oai logging facility is implemented in two source files, located in [common/utils](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils) -1. [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/log.c) contains logging implementation -1. [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/log.h) is the logging facility include file containing both private and public data type definitions. It also contain API prototypes. +The oai logging facility is implemented in two source files, located in [common/utils/LOG](LOG) +1. [log.c](../log.c) contains logging implementation +1. [log.h](../log.h) is the logging facility include file containing both private and public data type definitions. It also contain API prototypes. [logging facility main page](log.md) -- GitLab From 382981b7576ced16d957e4096b206260550285f0 Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Fri, 16 Nov 2018 18:05:54 +0100 Subject: [PATCH 11/20] fix broken link --- common/utils/LOG/DOC/log.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/LOG/DOC/log.md b/common/utils/LOG/DOC/log.md index d7a94d5bbd..121e227f3d 100644 --- a/common/utils/LOG/DOC/log.md +++ b/common/utils/LOG/DOC/log.md @@ -13,7 +13,7 @@ By default, this facility is included at build-time and activated at run-time. T ## Documentation * [runtime usage](rtusage.md) -* [developer usage](config/devusage.md) +* [developer usage](devusage.md) * [module architecture](arch.md) [oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) -- GitLab From 220080741eef482ec8451c956ad24d59ab586a4f Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Fri, 16 Nov 2018 19:31:58 +0100 Subject: [PATCH 12/20] Update devusage.md --- common/utils/LOG/DOC/devusage.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/utils/LOG/DOC/devusage.md b/common/utils/LOG/DOC/devusage.md index 2d5582ff7c..f3d972a05d 100644 --- a/common/utils/LOG/DOC/devusage.md +++ b/common/utils/LOG/DOC/devusage.md @@ -115,5 +115,7 @@ LOG_UDUMPMSG(c, b, s, f, x...) [example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/SIMULATION/LTE_PHY/dlsim.c#L1974) +### logging facility APIs + [logging facility main page](log.md) [oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) -- GitLab From 682be3e2b4a5f4d58272e197a605ecd7596a6b5d Mon Sep 17 00:00:00 2001 From: frtabu Date: Mon, 19 Nov 2018 11:27:43 +0100 Subject: [PATCH 13/20] completing logging facility doc --- common/utils/LOG/DOC/addconsoletrace.md | 110 ++++++++++++++++++++++ common/utils/LOG/DOC/configurelog.md | 49 ++++++++++ common/utils/LOG/DOC/devusage.md | 116 +----------------------- 3 files changed, 163 insertions(+), 112 deletions(-) create mode 100644 common/utils/LOG/DOC/addconsoletrace.md create mode 100644 common/utils/LOG/DOC/configurelog.md diff --git a/common/utils/LOG/DOC/addconsoletrace.md b/common/utils/LOG/DOC/addconsoletrace.md new file mode 100644 index 0000000000..502e9d39d2 --- /dev/null +++ b/common/utils/LOG/DOC/addconsoletrace.md @@ -0,0 +1,110 @@ +### Adding console traces in oai code +#### console messages macros +```C +LOG_E(,,,...) +LOG_W(,,,...) +LOG_I(,,,...) +LOG_D(,,,...) +LOG_T(,,,...) +) +``` +these macros are used in place of the printf C function. The additionnal ***component*** parameter identifies the functionnal module which generates the message. At run time, the message will only be printed if the configured log level for the component is greater or equal than the macro level used in the code. + +| macro | level letter | level value | level name | +|:---------|:---------------|:---------------|----------------:| +| LOG_E | E | 0 | error | +| LOG_W | W | 1 | warning | +| LOG_I | I | 2 | informational | +| LOG_D | D | 3 | debug | +| LOG_T | T | 4 | trace | + +component list is defined as an `enum` in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h). A new component can be defined by adding an item in this type, it must also be defined in the T tracer [T_messages.txt ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/T/T_messages.txt). + +Most oai sources are including LOG macros. + +#### conditional code macros + +```C +LOG_DEBUGFLAG() +``` +this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md) +```C +if ( LOG_DEBUGFLAG() { +/* + the code below is only executed if the corresponding + _debug option is set. + */ +...................... +...................... +} +``` +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c#L396) + +#### memory dump macros +```C +LOG_DUMPFLAG() +``` +this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md). It is mainly provided to surround LOG_M macros or direct calls to `log_dump`which otherwise would be unconditionals. +```C +if ( LOG_DUMPFLAG() { +/* + the code below is only executed if the corresponding + _dump option is set. + */ +LOG_M(............. +LOG_M(............. +log_dump(... +} + +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205) +#### matlab format dump +```C +LOG_M(file, vector, data, len, dec, format) +``` +|argument| type| description | +|:-----------|:-------|-----------------:| +| file | char* |path to the fle which will contain the dump | +|vector |char * |name of the dump, printed at the top of the dump file | +|data| void *| pointer to the memory to be dumpped | +|len | int | length of the data to be dumpped, in `dec` unit| +| dec| int | length of each data item.Interpretation depends on format| +|format| int | defines the type of data to be dumped| + +This macro can be used to dump a buffer in a format that can be used for analyze via tools like matlab or octave. **It must be surrounded by LOG_DEBUGFLAG or LOG_DUMPFLAG macros, to prevent the dump to be built unconditionally.** The LOG_M macro points to the `write_file_matlab` function implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). **This function should be revisited for more understandable implementation and ease of use (format parameter ???)** +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205) + +#### hexadecimal format dump +```C +LOG_DUMPMSG(c, f, b, s, x...) +``` +dumps a memory region if the corresponding debug flag `f` is set as explained here [run time usage page](rtusage.md) + +|argument| type| description | +|:-----------|:-------|-----------------:| +| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments | +|f |int |flag used to filter the dump depending on the logs configuration. flag list is defined by the LOG_MASKMAP_INIT macro in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) | +|b| void *| pointer to the memory to be dumpped | +|s | int | length of the data to be dumpped in char| +| x...| printf format and arguments| text string to be printed at the top of the dump| + +This macro can be used to conditionaly dump a buffer, bytes by bytes, giving the integer value of each byte in hexadecimal form. +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/RRC/LTE/rrc_eNB.c#L1181) + +This macro points to the `log_dump` function, implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). This function can also dump buffers containing `double` data via the LOG_UDUMPMSG macro + +```C +LOG_UDUMPMSG(c, b, s, f, x...) +``` +|argument| type| description | +|:-----------|:-------|-----------------:| +| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments | +|b| void *| pointer to the memory to be dumpped | +|s | int | length of the data to be dumpped in char| +|f| int | format of dumped data LOG_DUMP_CHAR or LOG_DUMP_DOUBLE| +| x...| printf format and arguments| text string to be printed at the top of the dump| + +[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/SIMULATION/LTE_PHY/dlsim.c#L1974) + +[logging facility developer main page](ldevusage.md) +[logging facility main page](log.md) +[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) \ No newline at end of file diff --git a/common/utils/LOG/DOC/configurelog.md b/common/utils/LOG/DOC/configurelog.md new file mode 100644 index 0000000000..ee8c0972e6 --- /dev/null +++ b/common/utils/LOG/DOC/configurelog.md @@ -0,0 +1,49 @@ +### Initializing and configuring the logging facility + +#### logging facility APIs +```C +int logInit (void); +``` +Allocate the internal data used by the logging utility, set the configuration, using the [configuration module](../../../config/DOC/config.md) + +```C +void logClean (void) +``` +Reset console attributes (color settings) and possibly close opened log files. Logging facility is still usable after this call, the internal data are not freed. + +```C +int set_log(int component, int level) +void set_glog(int level) +``` +Set a component or all components logiing level. Messages which level is lower than this level are not printed to the console. + +```C +void set_glog_onlinelog(int enable) +``` +Enable or disable all logging messages. Even error level messages are discarded, which is not advised. This can be usefull to temporarily workaround high rate of logging messages. + +```C +void set_component_filelog(int comp) +void close_component_filelog(int comp) +``` + +Redirect or reset to stdout the output stream used by the logging facility. When the output stream is redirected to a file, it is created under /tmp with a hard-coded filename including the componemt name. + +```C +SET_LOG_DEBUG(flag) +CLEAR_LOG_DEBUG(flag) +SET_LOG_DUMP(flag) +CLEAR_LOG_DUMP(flag) +``` + These macros are used to set or clear the corresponding bit flag, trigerring the activation or un-activation of conditional code or memory dumps generation. + +Example of using the logging utility APIs can be found, for initialization and cleanup, in [lte-softmodem.c](../../../../targets/RT/USER/lte-softmodem.c) and in the [telnet server log command implementation](../../telnetsrv/telnetsrv_proccmd.c) for a complete access to the logging facility features. + +#### components and debug flags definitions + +Adding a new component is just adding an item in the `comp_name_t` enum defined in [log.h](../log.h) . You must also declare it in the T Tracer facility [message fefinitions](../../T/T_messages.txt). +To add a flag than can then be used for adding conditional code or memory dumps you have to add the flag definition in the `LOG_MASKMAP_INIT` macro, in [log.h](../log.h). + +[logging facility developer main page](ldevusage.md) +[logging facility main page](log.md) +[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) \ No newline at end of file diff --git a/common/utils/LOG/DOC/devusage.md b/common/utils/LOG/DOC/devusage.md index f3d972a05d..0e68be4414 100644 --- a/common/utils/LOG/DOC/devusage.md +++ b/common/utils/LOG/DOC/devusage.md @@ -1,121 +1,13 @@ -### logging facility usage +### logging facility developer usage The logging facility objectives are 1. provide a common console tracing mechanism 1. Allow a flexible activation of console traces, by configuration or dynamically at any time while code is running. -Once the logging facility has been initialized and configured developpers use C preprocessor macros to include console messages in their code. At execution time, these traces will be printed or not to the console depending on the configuration, as described [here](rtusage.md). The logging facility also defines preprocessor macros to include condtional code, to dump memory blocks (buffers, messages...). +Most developpers will only use the log macros to add console messages to the code. The logging facility also provides an api that is used for initialization and configuration. -All macros are defined in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) include file, which must be included in any source file using the logging facility macros. +[Adding console traces in oaicode](addconsoletrace.md) +[Configuring the logging facility](configurelog.md) - [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) also includes the prototypes of the functions that have to be called to initialize, configure or get the status of console logs. - -#### console messages macros -```C -LOG_E(,,,...) -LOG_W(,,,...) -LOG_I(,,,...) -LOG_D(,,,...) -LOG_T(,,,...) -) -``` -these macros are used in place of the printf C function. The additionnal ***component*** parameter identifies the functionnal module which generates the message. At run time, the message will only be printed if the configured log level for the component is greater or equal than the macro level used in the code. - -| macro | level letter | level value | level name | -|:---------|:---------------|:---------------|----------------:| -| LOG_E | E | 0 | error | -| LOG_W | W | 1 | warning | -| LOG_I | I | 2 | informational | -| LOG_D | D | 3 | debug | -| LOG_T | T | 4 | trace | - -component list is defined as an `enum` in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h). A new component can be defined by adding an item in this type, it must also be defined in the T tracer [T_messages.txt ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/T/T_messages.txt). - -Most oai sources are including LOG macros. - -#### conditional code macros - -```C -LOG_DEBUGFLAG() -``` -this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md) -```C -if ( LOG_DEBUGFLAG() { -/* - the code below is only executed if the corresponding - _debug option is set. - */ -...................... -...................... -} -``` -[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c#L396) - -#### memory dump macros -```C -LOG_DUMPFLAG() -``` -this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md). It is mainly provided to surround LOG_M macros or direct calls to `log_dump`which otherwise would be unconditionals. -```C -if ( LOG_DUMPFLAG() { -/* - the code below is only executed if the corresponding - _dump option is set. - */ -LOG_M(............. -LOG_M(............. -log_dump(... -} - -[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205) -#### matlab format dump -```C -LOG_M(file, vector, data, len, dec, format) -``` -|argument| type| description | -|:-----------|:-------|-----------------:| -| file | char* |path to the fle which will contain the dump | -|vector |char * |name of the dump, printed at the top of the dump file | -|data| void *| pointer to the memory to be dumpped | -|len | int | length of the data to be dumpped, in `dec` unit| -| dec| int | length of each data item.Interpretation depends on format| -|format| int | defines the type of data to be dumped| - -This macro can be used to dump a buffer in a format that can be used for analyze via tools like matlab or octave. **It must be surrounded by LOG_DEBUGFLAG or LOG_DUMPFLAG macros, to prevent the dump to be built unconditionally.** The LOG_M macro points to the `write_file_matlab` function implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). **This function should be revisited for more understandable implementation and ease of use (format parameter ???)** -[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205) - -#### hexadecimal format dump -```C -LOG_DUMPMSG(c, f, b, s, x...) -``` -dumps a memory region if the corresponding debug flag `f` is set as explained here [run time usage page](rtusage.md) - -|argument| type| description | -|:-----------|:-------|-----------------:| -| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments | -|f |int |flag used to filter the dump depending on the logs configuration. flag list is defined by the LOG_MASKMAP_INIT macro in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) | -|b| void *| pointer to the memory to be dumpped | -|s | int | length of the data to be dumpped in char| -| x...| printf format and arguments| text string to be printed at the top of the dump| - -This macro can be used to conditionaly dump a buffer, bytes by bytes, giving the integer value of each byte in hexadecimal form. -[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/RRC/LTE/rrc_eNB.c#L1181) - -This macro points to the `log_dump` function, implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). This function can also dump buffers containing `double` data via the LOG_UDUMPMSG macro - -```C -LOG_UDUMPMSG(c, b, s, f, x...) -``` -|argument| type| description | -|:-----------|:-------|-----------------:| -| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments | -|b| void *| pointer to the memory to be dumpped | -|s | int | length of the data to be dumpped in char| -|f| int | format of dumped data LOG_DUMP_CHAR or LOG_DUMP_DOUBLE| -| x...| printf format and arguments| text string to be printed at the top of the dump| - -[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/SIMULATION/LTE_PHY/dlsim.c#L1974) - -### logging facility APIs [logging facility main page](log.md) [oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) -- GitLab From 3df8f96bba15acdef401fdb1fd871024115172b2 Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Mon, 19 Nov 2018 11:30:54 +0100 Subject: [PATCH 14/20] fix wrong formatting --- common/utils/LOG/DOC/devusage.md | 1 + 1 file changed, 1 insertion(+) diff --git a/common/utils/LOG/DOC/devusage.md b/common/utils/LOG/DOC/devusage.md index 0e68be4414..d7790917fc 100644 --- a/common/utils/LOG/DOC/devusage.md +++ b/common/utils/LOG/DOC/devusage.md @@ -6,6 +6,7 @@ The logging facility objectives are Most developpers will only use the log macros to add console messages to the code. The logging facility also provides an api that is used for initialization and configuration. [Adding console traces in oaicode](addconsoletrace.md) + [Configuring the logging facility](configurelog.md) -- GitLab From 884d4b631d2c4023558ad70b5a605d3a966b22a3 Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Mon, 19 Nov 2018 11:34:38 +0100 Subject: [PATCH 15/20] fix broken link --- common/utils/LOG/DOC/addconsoletrace.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/LOG/DOC/addconsoletrace.md b/common/utils/LOG/DOC/addconsoletrace.md index 502e9d39d2..d850ac1036 100644 --- a/common/utils/LOG/DOC/addconsoletrace.md +++ b/common/utils/LOG/DOC/addconsoletrace.md @@ -105,6 +105,6 @@ LOG_UDUMPMSG(c, b, s, f, x...) [example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/SIMULATION/LTE_PHY/dlsim.c#L1974) -[logging facility developer main page](ldevusage.md) +[logging facility developer main page](devusage.md) [logging facility main page](log.md) [oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) \ No newline at end of file -- GitLab From 0f0665e9e7f88cb6b9cb1c0cab68b027e0a97276 Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Mon, 19 Nov 2018 11:35:37 +0100 Subject: [PATCH 16/20] fix broken link --- common/utils/LOG/DOC/configurelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/LOG/DOC/configurelog.md b/common/utils/LOG/DOC/configurelog.md index ee8c0972e6..c671c043bd 100644 --- a/common/utils/LOG/DOC/configurelog.md +++ b/common/utils/LOG/DOC/configurelog.md @@ -44,6 +44,6 @@ Example of using the logging utility APIs can be found, for initialization and c Adding a new component is just adding an item in the `comp_name_t` enum defined in [log.h](../log.h) . You must also declare it in the T Tracer facility [message fefinitions](../../T/T_messages.txt). To add a flag than can then be used for adding conditional code or memory dumps you have to add the flag definition in the `LOG_MASKMAP_INIT` macro, in [log.h](../log.h). -[logging facility developer main page](ldevusage.md) +[logging facility developer main page](devusage.md) [logging facility main page](log.md) [oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) \ No newline at end of file -- GitLab From a86ca815411e8ee9990fbe4d3855f6ba5e097cad Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Mon, 19 Nov 2018 13:17:23 +0100 Subject: [PATCH 17/20] Update arch.md --- common/utils/LOG/DOC/arch.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/utils/LOG/DOC/arch.md b/common/utils/LOG/DOC/arch.md index 348216983b..a472107d50 100644 --- a/common/utils/LOG/DOC/arch.md +++ b/common/utils/LOG/DOC/arch.md @@ -4,6 +4,9 @@ The oai logging facility is implemented in two source files, located in [common/ 1. [log.c](../log.c) contains logging implementation 1. [log.h](../log.h) is the logging facility include file containing both private and public data type definitions. It also contain API prototypes. +The logging facility doesn't create any thread, all api's are executed in the context of the caller. The tracing macro's LOG_ are all using the logRecord_mt function to output the messages. To keep this function thread safe it must perform a single system call the output stream. The buffer used to build the message must be specific to the calling thread, which is today enforced by using a variable in the logRecord_mt stack. + +Data used by the logging utility are defined by the `log_t` structure which is allocated at init time, when calling the `logInit` function. [logging facility main page](log.md) [oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home) \ No newline at end of file -- GitLab From 117e2a145ef47ae091a05b94b8887ff7d7163285 Mon Sep 17 00:00:00 2001 From: Francois TABURET Date: Mon, 19 Nov 2018 13:20:14 +0100 Subject: [PATCH 18/20] Update arch.md --- common/utils/LOG/DOC/arch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/LOG/DOC/arch.md b/common/utils/LOG/DOC/arch.md index a472107d50..b9302927be 100644 --- a/common/utils/LOG/DOC/arch.md +++ b/common/utils/LOG/DOC/arch.md @@ -4,7 +4,7 @@ The oai logging facility is implemented in two source files, located in [common/ 1. [log.c](../log.c) contains logging implementation 1. [log.h](../log.h) is the logging facility include file containing both private and public data type definitions. It also contain API prototypes. -The logging facility doesn't create any thread, all api's are executed in the context of the caller. The tracing macro's LOG_ are all using the logRecord_mt function to output the messages. To keep this function thread safe it must perform a single system call the output stream. The buffer used to build the message must be specific to the calling thread, which is today enforced by using a variable in the logRecord_mt stack. +The logging facility doesn't create any thread, all api's are executed in the context of the caller. The tracing macro's `LOG_` are all using the logRecord_mt function to output the messages. To keep this function thread safe it must perform a single system call to the output stream. The buffer used to build the message must be specific to the calling thread, which is today enforced by using a variable in the logRecord_mt stack. Data used by the logging utility are defined by the `log_t` structure which is allocated at init time, when calling the `logInit` function. -- GitLab From e6cd6ba21f05ea6e3160fa3c054dbcdbb940c6d0 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Tue, 20 Nov 2018 13:03:31 +0100 Subject: [PATCH 19/20] T: minor: fix typo --- common/utils/T/genids.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/utils/T/genids.c b/common/utils/T/genids.c index 8e5adbf587..112fe9de5a 100644 --- a/common/utils/T/genids.c +++ b/common/utils/T/genids.c @@ -24,11 +24,11 @@ int new_unique_id(char *s, char *input_file) if (unique_ids_size == unique_ids_maxsize) { unique_ids_maxsize += 256; unique_ids = realloc(unique_ids, unique_ids_maxsize * sizeof(char *)); - if (unique_ids == NULL) { printf("erorr: out of memory\n"); abort(); } + if (unique_ids == NULL) { printf("error: out of memory\n"); abort(); } } unique_ids[unique_ids_size] = strdup(s); if (unique_ids[unique_ids_size] == NULL) - { printf("erorr: out of memory\n"); abort(); } + { printf("error: out of memory\n"); abort(); } unique_ids_size++; qsort(unique_ids, unique_ids_size, sizeof(char *), cmp); return 1; @@ -44,7 +44,7 @@ void putname(int c) bufname_maxsize += 256; bufname = realloc(bufname, bufname_maxsize); if (bufname == NULL) - { printf("erorr: memory allocation error\n"); exit(1); } + { printf("error: memory allocation error\n"); exit(1); } } bufname[bufname_size] = c; bufname_size++; -- GitLab From 55732deb80ac341ef92b278aa04379001e94abac Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Thu, 22 Nov 2018 15:03:27 +0100 Subject: [PATCH 20/20] Astyling the common files Signed-off-by: Raphael Defosseux --- common/config/config_cmdline.c | 419 ++++++++------- common/config/config_load_configmodule.c | 489 +++++++++--------- common/config/config_load_configmodule.h | 25 +- common/config/config_paramdesc.h | 141 +++-- common/config/config_userapi.c | 576 +++++++++++---------- common/config/config_userapi.h | 6 +- common/utils/LOG/log.c | 626 +++++++++++------------ common/utils/LOG/log.h | 344 +++++++------ common/utils/T/genids.c | 127 +++-- 9 files changed, 1420 insertions(+), 1333 deletions(-) diff --git a/common/config/config_cmdline.c b/common/config/config_cmdline.c index c28cf33758..7fca12540d 100644 --- a/common/config/config_cmdline.c +++ b/common/config/config_cmdline.c @@ -20,7 +20,7 @@ */ /*! \file common/config/cmdline/config_libconfig.c - * \brief configuration module, command line parsing implementation + * \brief configuration module, command line parsing implementation * \author Francois TABURET * \date 2017 * \version 0.1 @@ -39,223 +39,244 @@ #include "config_userapi.h" -int parse_stringlist(paramdef_t *cfgoptions, char *val) -{ -char *atoken; -char *tokctx; -char *tmpval=strdup(val); -int numelt=0; - - cfgoptions->numelt=0; - - atoken=strtok_r(tmpval, ",",&tokctx); - while(atoken != NULL) { - numelt++ ; - atoken=strtok_r(NULL, ",",&tokctx); - } - free(tmpval); - config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt); - cfgoptions->numelt=numelt; - - atoken=strtok_r(val, ",",&tokctx); - for( int i=0; inumelt && atoken != NULL ; i++) { - config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(atoken)+1); - sprintf(cfgoptions->strlistptr[i],"%s",atoken); - printf_params("[LIBCONFIG] %s[%i]: %s\n", cfgoptions->optname,i,cfgoptions->strlistptr[i]); - atoken=strtok_r(NULL, ",",&tokctx); - } - return (cfgoptions->numelt > 0); +int parse_stringlist(paramdef_t *cfgoptions, char *val) { + char *atoken; + char *tokctx; + char *tmpval=strdup(val); + int numelt=0; + cfgoptions->numelt=0; + atoken=strtok_r(tmpval, ",",&tokctx); + + while(atoken != NULL) { + numelt++ ; + atoken=strtok_r(NULL, ",",&tokctx); + } + + free(tmpval); + config_check_valptr(cfgoptions,(char **)&(cfgoptions->strlistptr), sizeof(char *) * numelt); + cfgoptions->numelt=numelt; + atoken=strtok_r(val, ",",&tokctx); + + for( int i=0; inumelt && atoken != NULL ; i++) { + config_check_valptr(cfgoptions,&(cfgoptions->strlistptr[i]),strlen(atoken)+1); + sprintf(cfgoptions->strlistptr[i],"%s",atoken); + printf_params("[LIBCONFIG] %s[%i]: %s\n", cfgoptions->optname,i,cfgoptions->strlistptr[i]); + atoken=strtok_r(NULL, ",",&tokctx); + } + + return (cfgoptions->numelt > 0); } - -int processoption(paramdef_t *cfgoptions, char *value) -{ -char *tmpval = value; -int optisset=0; -char defbool[2]="1"; - - - if ( value == NULL) { - if( (cfgoptions->paramflags &PARAMFLAG_BOOL) == 0 ) { /* not a boolean, argument required */ - fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname); - return 0; - } else { /* boolean value option without argument, set value to true*/ - tmpval = defbool; - } - } - switch(cfgoptions->type) - { - case TYPE_STRING: - if (cfgoptions->numelt == 0 ) { - config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(tmpval)+1); - sprintf(*(cfgoptions->strptr), "%s",tmpval); - } else { - sprintf( (char *)(cfgoptions->strptr), "%s",tmpval); - } - printf_cmdl("[CONFIG] %s set to %s from command line\n", cfgoptions->optname, tmpval); - optisset=1; - break; - - case TYPE_STRINGLIST: - optisset=parse_stringlist(cfgoptions,tmpval); - break; - case TYPE_UINT32: - case TYPE_INT32: - case TYPE_UINT16: - case TYPE_INT16: - case TYPE_UINT8: - case TYPE_INT8: - config_check_valptr(cfgoptions, (char **)&(cfgoptions->iptr),sizeof(int32_t)); - config_assign_int(cfgoptions,cfgoptions->optname,(int32_t)strtol(tmpval,NULL,0)); - optisset=1; - break; - case TYPE_UINT64: - case TYPE_INT64: - config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t)); - *(cfgoptions->i64ptr)=strtoll(tmpval,NULL,0); - printf_cmdl("[CONFIG] %s set to %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr)); - optisset=1; - break; - case TYPE_UINTARRAY: - case TYPE_INTARRAY: - - break; - case TYPE_DOUBLE: - config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double)); - *(cfgoptions->dblptr) = strtof(tmpval,NULL); - printf_cmdl("[CONFIG] %s set to %lf from command line\n", cfgoptions->optname, *(cfgoptions->dblptr)); - optisset=1; - break; - - case TYPE_IPV4ADDR: - - break; - - default: - fprintf(stderr,"[CONFIG] command line, %s type %i not supported\n",cfgoptions->optname, cfgoptions->type); - break; - } /* switch on param type */ - if (optisset == 1) { - cfgoptions->paramflags = cfgoptions->paramflags | PARAMFLAG_PARAMSET; - } - return optisset; + +int processoption(paramdef_t *cfgoptions, char *value) { + char *tmpval = value; + int optisset=0; + char defbool[2]="1"; + + if ( value == NULL) { + if( (cfgoptions->paramflags &PARAMFLAG_BOOL) == 0 ) { /* not a boolean, argument required */ + fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname); + return 0; + } else { /* boolean value option without argument, set value to true*/ + tmpval = defbool; + } + } + + switch(cfgoptions->type) { + case TYPE_STRING: + if (cfgoptions->numelt == 0 ) { + config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(tmpval)+1); + sprintf(*(cfgoptions->strptr), "%s",tmpval); + } else { + sprintf( (char *)(cfgoptions->strptr), "%s",tmpval); + } + + printf_cmdl("[CONFIG] %s set to %s from command line\n", cfgoptions->optname, tmpval); + optisset=1; + break; + + case TYPE_STRINGLIST: + optisset=parse_stringlist(cfgoptions,tmpval); + break; + + case TYPE_UINT32: + case TYPE_INT32: + case TYPE_UINT16: + case TYPE_INT16: + case TYPE_UINT8: + case TYPE_INT8: + config_check_valptr(cfgoptions, (char **)&(cfgoptions->iptr),sizeof(int32_t)); + config_assign_int(cfgoptions,cfgoptions->optname,(int32_t)strtol(tmpval,NULL,0)); + optisset=1; + break; + + case TYPE_UINT64: + case TYPE_INT64: + config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(uint64_t)); + *(cfgoptions->i64ptr)=strtoll(tmpval,NULL,0); + printf_cmdl("[CONFIG] %s set to %lli from command line\n", cfgoptions->optname, (long long)*(cfgoptions->i64ptr)); + optisset=1; + break; + + case TYPE_UINTARRAY: + case TYPE_INTARRAY: + break; + + case TYPE_DOUBLE: + config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double)); + *(cfgoptions->dblptr) = strtof(tmpval,NULL); + printf_cmdl("[CONFIG] %s set to %lf from command line\n", cfgoptions->optname, *(cfgoptions->dblptr)); + optisset=1; + break; + + case TYPE_IPV4ADDR: + break; + + default: + fprintf(stderr,"[CONFIG] command line, %s type %i not supported\n",cfgoptions->optname, cfgoptions->type); + break; + } /* switch on param type */ + + if (optisset == 1) { + cfgoptions->paramflags = cfgoptions->paramflags | PARAMFLAG_PARAMSET; + } + + return optisset; } -int config_check_cmdlineopt(char *prefix) -{ -int unknowndetected=0; -char testprefix[CONFIG_MAXOPTLENGTH]=""; -int finalcheck = 0; - - if (prefix != NULL) { - if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0) - finalcheck = 1; - else if (strlen(prefix) > 0) { - sprintf(testprefix,"--%s.",prefix); - } - } - - for (int i=1; iargc ; i++) { - if ( !finalcheck && strstr(config_get_if()->argv[i],testprefix) == NULL ) continue; - if ( !finalcheck && testprefix[0]==0 && index(config_get_if()->argv[i],'.') != NULL) continue; - if ( !finalcheck && config_get_if()->argv[i][0] == '-' && isdigit(config_get_if()->argv[i][1])) continue; - if ( (config_get_if()->argv_info[i] & CONFIG_CMDLINEOPT_PROCESSED) == 0 ) { - fprintf(stderr,"[CONFIG] unknown option: %s\n", - config_get_if()->argv[i] ); - unknowndetected++; - } +int config_check_cmdlineopt(char *prefix) { + int unknowndetected=0; + char testprefix[CONFIG_MAXOPTLENGTH]=""; + int finalcheck = 0; + + if (prefix != NULL) { + if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0) + finalcheck = 1; + else if (strlen(prefix) > 0) { + sprintf(testprefix,"--%s.",prefix); } + } + + for (int i=1; iargc ; i++) { + if ( !finalcheck && strstr(config_get_if()->argv[i],testprefix) == NULL ) continue; + + if ( !finalcheck && testprefix[0]==0 && index(config_get_if()->argv[i],'.') != NULL) continue; + + if ( !finalcheck && config_get_if()->argv[i][0] == '-' && isdigit(config_get_if()->argv[i][1])) continue; + + if ( (config_get_if()->argv_info[i] & CONFIG_CMDLINEOPT_PROCESSED) == 0 ) { + fprintf(stderr,"[CONFIG] unknown option: %s\n", + config_get_if()->argv[i] ); + unknowndetected++; + } + } - printf_cmdl("[CONFIG] %i unknown option(s) in command line starting with %s (section %s)\n", unknowndetected,testprefix,((prefix==NULL)?"":prefix)); - return unknowndetected; + return unknowndetected; } /* parse_cmdline*/ -int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) -{ +int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) { int c = config_get_if()->argc; int i,j; char *pp; char cfgpath[CONFIG_MAXOPTLENGTH]; - j = 0; i = 0; - while (c > 0 ) { - char *oneargv = strdup(config_get_if()->argv[i]); /* we use strtok_r which modifies its string paramater, and we don't want argv to be modified */ - /* first check help options, either --help, -h or --help_
*/ - if (strncmp(oneargv, "-h",2) == 0 || strncmp(oneargv, "--help",6) == 0 ) { - char *tokctx; - pp=strtok_r(oneargv, "_",&tokctx); + + while (c > 0 ) { + char *oneargv = strdup(config_get_if()->argv[i]); /* we use strtok_r which modifies its string paramater, and we don't want argv to be modified */ + + /* first check help options, either --help, -h or --help_
*/ + if (strncmp(oneargv, "-h",2) == 0 || strncmp(oneargv, "--help",6) == 0 ) { + char *tokctx; + pp=strtok_r(oneargv, "_",&tokctx); + config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; + + if (pp == NULL || strcasecmp(pp,config_get_if()->argv[i] ) == 0 ) { + if( prefix == NULL) { + config_printhelp(cfgoptions,numoptions); + + if ( ! ( CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP))) + exit_fun("[CONFIG] Exiting after displaying help\n"); + } + } else { + pp=strtok_r(NULL, " ",&tokctx); + + if ( prefix != NULL && pp != NULL && strncasecmp(prefix,pp,strlen(pp)) == 0 ) { + printf ("Help for %s section:\n",prefix); + config_printhelp(cfgoptions,numoptions); + + if ( ! (CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP))) { + fprintf(stderr,"[CONFIG] %s %i section %s:", __FILE__, __LINE__, prefix); + exit_fun(" Exiting after displaying help\n"); + } + } + } + } + + /* now, check for non help options */ + if (oneargv[0] == '-') { + for(int n=0; n 2) && (strcmp(oneargv + 2,cfgpath ) == 0 )) ) { + char *valptr=NULL; + int ret; + config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; + + if (c > 0) { + pp = config_get_if()->argv[i+1]; + + if (pp != NULL ) { + ret = strlen(pp); + + if (ret > 0 ) { + if (pp[0] != '-') + valptr=pp; + else if ( ret > 1 && pp[0] == '-' && isdigit(pp[1]) ) + valptr=pp; + } + } + } + + j += processoption(&(cfgoptions[n]), valptr); + + if ( valptr != NULL ) { + i++; config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; - if (pp == NULL || strcasecmp(pp,config_get_if()->argv[i] ) == 0 ) { - if( prefix == NULL) { - config_printhelp(cfgoptions,numoptions); - if ( ! ( CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP))) - exit_fun("[CONFIG] Exiting after displaying help\n"); - } - } else { - pp=strtok_r(NULL, " ",&tokctx); - if ( prefix != NULL && pp != NULL && strncasecmp(prefix,pp,strlen(pp)) == 0 ) { - printf ("Help for %s section:\n",prefix); - config_printhelp(cfgoptions,numoptions); - if ( ! (CONFIG_ISFLAGSET(CONFIG_NOEXITONHELP))) { - fprintf(stderr,"[CONFIG] %s %i section %s:", __FILE__, __LINE__, prefix); - exit_fun(" Exiting after displaying help\n"); - } - } - } + c--; + } + + break; } + } /* for n... */ + } /* if (oneargv[0] == '-') */ + + free(oneargv); + i++; + c--; + } /* fin du while */ - /* now, check for non help options */ - if (oneargv[0] == '-') { - for(int n=0;n 2) && (strcmp(oneargv + 2,cfgpath ) == 0 )) ) { - char *valptr=NULL; - int ret; - config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; - if (c > 0) { - pp = config_get_if()->argv[i+1]; - if (pp != NULL ) { - ret = strlen(pp); - if (ret > 0 ) { - if (pp[0] != '-') - valptr=pp; - else if ( ret > 1 && pp[0] == '-' && isdigit(pp[1]) ) - valptr=pp; - } - } - } - j += processoption(&(cfgoptions[n]), valptr); - if ( valptr != NULL ) { - i++; - config_get_if()->argv_info[i] |= CONFIG_CMDLINEOPT_PROCESSED; - c--; - } - break; - } - } /* for n... */ - } /* if (oneargv[0] == '-') */ - free(oneargv); - i++; - c--; - } /* fin du while */ printf_cmdl("[CONFIG] %s %i options set from command line\n",((prefix == NULL) ? "(root)":prefix),j); + if ( !(CONFIG_ISFLAGSET( CONFIG_NOCHECKUNKOPT )) ) { - i=config_check_cmdlineopt(prefix); - if (i > 0) { - fprintf(stderr,"[CONFIG] %i unknown options for section %s detected in command line\n", - i,((prefix==NULL)?"\"root section\"":prefix)); - exit_fun(" Exiting after detecting errors in command line \n"); - } + i=config_check_cmdlineopt(prefix); + + if (i > 0) { + fprintf(stderr,"[CONFIG] %i unknown options for section %s detected in command line\n", + i,((prefix==NULL)?"\"root section\"":prefix)); + exit_fun(" Exiting after detecting errors in command line \n"); + } } - return j; + + return j; } /* parse_cmdline*/ diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c index 15211aec8a..e20672aa02 100644 --- a/common/config/config_load_configmodule.c +++ b/common/config/config_load_configmodule.c @@ -20,7 +20,7 @@ */ /*! \file common/config/config_load_configmodule.c - * \brief configuration module, load the shared library implementing the configuration module + * \brief configuration module, load the shared library implementing the configuration module * \author Francois TABURET * \date 2017 * \version 0.1 @@ -42,293 +42,314 @@ #include "config_userapi.h" #define CONFIG_SHAREDLIBFORMAT "libparams_%s.so" -int load_config_sharedlib(configmodule_interface_t *cfgptr) -{ -void *lib_handle; -char fname[128]; -char libname[FILENAME_MAX]; -int st; +int load_config_sharedlib(configmodule_interface_t *cfgptr) { + void *lib_handle; + char fname[128]; + char libname[FILENAME_MAX]; + int st; + st=0; + sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgptr->cfgmode); + lib_handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); + + if (!lib_handle) { + fprintf(stderr,"[CONFIG] %s %d Error calling dlopen(%s): %s\n",__FILE__, __LINE__, libname,dlerror()); + st = -1; + } else { + sprintf (fname,"config_%s_init",cfgptr->cfgmode); + cfgptr->init = dlsym(lib_handle,fname); + + if (cfgptr->init == NULL ) { + printf("[CONFIG] %s %d no function %s for config mode %s\n", + __FILE__, __LINE__,fname, cfgptr->cfgmode); + } else { + st=cfgptr->init(cfgptr->cfgP,cfgptr->num_cfgP); + printf("[CONFIG] function %s returned %i\n", + fname, st); + } - st=0; - sprintf(libname,CONFIG_SHAREDLIBFORMAT,cfgptr->cfgmode); + sprintf (fname,"config_%s_get",cfgptr->cfgmode); + cfgptr->get = dlsym(lib_handle,fname); - lib_handle = dlopen(libname,RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); - if (!lib_handle) { - fprintf(stderr,"[CONFIG] %s %d Error calling dlopen(%s): %s\n",__FILE__, __LINE__, libname,dlerror()); + if (cfgptr->get == NULL ) { + printf("[CONFIG] %s %d no function %s for config mode %s\n", + __FILE__, __LINE__,fname, cfgptr->cfgmode); st = -1; - } else { - sprintf (fname,"config_%s_init",cfgptr->cfgmode); - cfgptr->init = dlsym(lib_handle,fname); - - if (cfgptr->init == NULL ) { - printf("[CONFIG] %s %d no function %s for config mode %s\n", - __FILE__, __LINE__,fname, cfgptr->cfgmode); - } else { - st=cfgptr->init(cfgptr->cfgP,cfgptr->num_cfgP); - printf("[CONFIG] function %s returned %i\n", - fname, st); - } + } - sprintf (fname,"config_%s_get",cfgptr->cfgmode); - cfgptr->get = dlsym(lib_handle,fname); - if (cfgptr->get == NULL ) { - printf("[CONFIG] %s %d no function %s for config mode %s\n", - __FILE__, __LINE__,fname, cfgptr->cfgmode); - st = -1; - } - - sprintf (fname,"config_%s_getlist",cfgptr->cfgmode); - cfgptr->getlist = dlsym(lib_handle,fname); - if (cfgptr->getlist == NULL ) { - printf("[CONFIG] %s %d no function %s for config mode %s\n", - __FILE__, __LINE__,fname, cfgptr->cfgmode); - st = -1; - } + sprintf (fname,"config_%s_getlist",cfgptr->cfgmode); + cfgptr->getlist = dlsym(lib_handle,fname); + + if (cfgptr->getlist == NULL ) { + printf("[CONFIG] %s %d no function %s for config mode %s\n", + __FILE__, __LINE__,fname, cfgptr->cfgmode); + st = -1; + } - sprintf (fname,"config_%s_end",cfgptr->cfgmode); - cfgptr->end = dlsym(lib_handle,fname); - if (cfgptr->getlist == NULL ) { - printf("[CONFIG] %s %d no function %s for config mode %s\n", - __FILE__, __LINE__,fname, cfgptr->cfgmode); - } - } - - return st; + sprintf (fname,"config_%s_end",cfgptr->cfgmode); + cfgptr->end = dlsym(lib_handle,fname); + + if (cfgptr->getlist == NULL ) { + printf("[CONFIG] %s %d no function %s for config mode %s\n", + __FILE__, __LINE__,fname, cfgptr->cfgmode); + } + } + + return st; } /*-----------------------------------------------------------------------------------*/ /* from here: interface implementtion of the configuration module */ int nooptfunc(void) { - return 0; + return 0; }; -int config_cmdlineonly_getlist(paramlist_def_t *ParamList, - paramdef_t *params, int numparams, char *prefix) -{ - ParamList->numelt = 0; - return 0; +int config_cmdlineonly_getlist(paramlist_def_t *ParamList, + paramdef_t *params, int numparams, char *prefix) { + ParamList->numelt = 0; + return 0; } -int config_cmdlineonly_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) -{ +int config_cmdlineonly_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) { int defval; int fatalerror=0; int numdefvals=0; - - - for(int i=0;i option, default cfgmode to libconfig + with one parameter, the path to the configuration file cfgmode must not be NULL */ + modeparams=cfgmode; + cfgmode=strdup(CONFIG_LIBCONFIGFILE); + } + + cfgptr = calloc(sizeof(configmodule_interface_t),1); + cfgptr->argv_info = calloc(sizeof(int32_t), argc); + cfgptr->argv_info[0] |= CONFIG_CMDLINEOPT_PROCESSED; + + if (OoptIdx >= 0) { + cfgptr->argv_info[OoptIdx] |= CONFIG_CMDLINEOPT_PROCESSED; + cfgptr->argv_info[OoptIdx+1] |= CONFIG_CMDLINEOPT_PROCESSED; + } + + cfgptr->rtflags = cfgptr->rtflags | tmpflags; + cfgptr->argc = argc; + cfgptr->argv = argv; + cfgptr->cfgmode=strdup(cfgmode); + cfgptr->num_cfgP=0; + atoken=strtok_r(modeparams,":",&strtokctx); + + while ( cfgptr->num_cfgP< CONFIG_MAX_OOPT_PARAMS && atoken != NULL) { + /* look for debug level in the config parameters, it is commom to all config mode + and will be removed frome the parameter array passed to the shared module */ + char *aptr; + aptr=strcasestr(atoken,"dbgl"); + + if (aptr != NULL) { + cfgptr->rtflags = cfgptr->rtflags | strtol(aptr+4,NULL,0); + } else { + cfgptr->cfgP[cfgptr->num_cfgP] = strdup(atoken); + cfgptr->num_cfgP++; + } + + atoken = strtok_r(NULL,":",&strtokctx); + } + + printf("[CONFIG] get parameters from %s ",cfgmode); + + for (i=0; inum_cfgP; i++) { + printf("%s ",cfgptr->cfgP[i]); + } + + printf(", debug flags: 0x%08x\n",cfgptr->rtflags); + + if (strstr(cfgparam,CONFIG_CMDLINEONLY) == NULL) { + i=load_config_sharedlib(cfgptr); + + if (i == 0) { + printf("[CONFIG] config module %s loaded\n",cfgmode); + Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].uptr=&(cfgptr->rtflags); + config_get(Config_Params,CONFIG_PARAMLENGTH(Config_Params), CONFIG_SECTIONNAME ); } else { - cfgparam = CONFIG_CMDLINEONLY ":dbgl0" ;cfgparam = CONFIG_LIBCONFIGFILE ":" DEFAULT_CFGFILENAME; + fprintf(stderr,"[CONFIG] %s %d config module \"%s\" couldn't be loaded\n", __FILE__, __LINE__,cfgmode); + cfgptr->rtflags = cfgptr->rtflags | CONFIG_HELP | CONFIG_ABORT; } + } else { + cfgptr->init = (configmodule_initfunc_t)nooptfunc; + cfgptr->get = config_cmdlineonly_get; + cfgptr->getlist = config_cmdlineonly_getlist; + cfgptr->end = (configmodule_endfunc_t)nooptfunc; + } + + if (modeparams != NULL) free(modeparams); + + if (cfgmode != NULL) free(cfgmode); + + if (CONFIG_ISFLAGSET(CONFIG_ABORT)) { + config_printhelp(Config_Params,CONFIG_PARAMLENGTH(Config_Params)); + // exit(-1); } - -/* parse the config parameters to set the config source */ - i = sscanf(cfgparam,"%m[^':']:%ms",&cfgmode,&modeparams); - if (i< 0) { - fprintf(stderr,"[CONFIG] %s, %d, sscanf error parsing config source %s: %s\n", __FILE__, __LINE__,cfgparam, strerror(errno)); - exit(-1) ; - } - else if ( i == 1 ) { - /* -O argument doesn't contain ":" separator, assume -O option, default cfgmode to libconfig - with one parameter, the path to the configuration file cfgmode must not be NULL */ - modeparams=cfgmode; - cfgmode=strdup(CONFIG_LIBCONFIGFILE); - } - - cfgptr = calloc(sizeof(configmodule_interface_t),1); - cfgptr->argv_info = calloc(sizeof(int32_t), argc); - cfgptr->argv_info[0] |= CONFIG_CMDLINEOPT_PROCESSED; - if (OoptIdx >= 0) { - cfgptr->argv_info[OoptIdx] |= CONFIG_CMDLINEOPT_PROCESSED; - cfgptr->argv_info[OoptIdx+1] |= CONFIG_CMDLINEOPT_PROCESSED; - } - - cfgptr->rtflags = cfgptr->rtflags | tmpflags; - cfgptr->argc = argc; - cfgptr->argv = argv; - cfgptr->cfgmode=strdup(cfgmode); - cfgptr->num_cfgP=0; - atoken=strtok_r(modeparams,":",&strtokctx); - while ( cfgptr->num_cfgP< CONFIG_MAX_OOPT_PARAMS && atoken != NULL) { - /* look for debug level in the config parameters, it is commom to all config mode - and will be removed frome the parameter array passed to the shared module */ - char *aptr; - aptr=strcasestr(atoken,"dbgl"); - if (aptr != NULL) { - cfgptr->rtflags = cfgptr->rtflags | strtol(aptr+4,NULL,0); - - } else { - cfgptr->cfgP[cfgptr->num_cfgP] = strdup(atoken); - cfgptr->num_cfgP++; - } - atoken = strtok_r(NULL,":",&strtokctx); - } - - - printf("[CONFIG] get parameters from %s ",cfgmode); - for (i=0;inum_cfgP; i++) { - printf("%s ",cfgptr->cfgP[i]); - } - printf(", debug flags: 0x%08x\n",cfgptr->rtflags); - - if (strstr(cfgparam,CONFIG_CMDLINEONLY) == NULL) { - i=load_config_sharedlib(cfgptr); - if (i == 0) { - printf("[CONFIG] config module %s loaded\n",cfgmode); - Config_Params[CONFIGPARAM_DEBUGFLAGS_IDX].uptr=&(cfgptr->rtflags); - config_get(Config_Params,CONFIG_PARAMLENGTH(Config_Params), CONFIG_SECTIONNAME ); - } else { - fprintf(stderr,"[CONFIG] %s %d config module \"%s\" couldn't be loaded\n", __FILE__, __LINE__,cfgmode); - cfgptr->rtflags = cfgptr->rtflags | CONFIG_HELP | CONFIG_ABORT; - } - } else { - cfgptr->init = (configmodule_initfunc_t)nooptfunc; - cfgptr->get = config_cmdlineonly_get; - cfgptr->getlist = config_cmdlineonly_getlist; - cfgptr->end = (configmodule_endfunc_t)nooptfunc; - } - - - - if (modeparams != NULL) free(modeparams); - if (cfgmode != NULL) free(cfgmode); - if (CONFIG_ISFLAGSET(CONFIG_ABORT)) { - config_printhelp(Config_Params,CONFIG_PARAMLENGTH(Config_Params)); -// exit(-1); - } - return cfgptr; + + return cfgptr; } /* free memory allocated when reading parameters */ /* config module could be initialized again after this call */ -void end_configmodule(void) -{ +void end_configmodule(void) { if (cfgptr != NULL) { - if (cfgptr->end != NULL) { - printf ("[CONFIG] calling config module end function...\n"); - cfgptr->end(); - } + if (cfgptr->end != NULL) { + printf ("[CONFIG] calling config module end function...\n"); + cfgptr->end(); + } - printf ("[CONFIG] free %u config value pointers\n",cfgptr->numptrs); - for(int i=0; inumptrs ; i++) { - if (cfgptr->ptrs[i] != NULL) { - free(cfgptr->ptrs[i]); - cfgptr->ptrs[i]=NULL; - } + printf ("[CONFIG] free %u config value pointers\n",cfgptr->numptrs); + + for(int i=0; inumptrs ; i++) { + if (cfgptr->ptrs[i] != NULL) { + free(cfgptr->ptrs[i]); + cfgptr->ptrs[i]=NULL; } - cfgptr->numptrs=0; + } + + cfgptr->numptrs=0; } } /* free all memory used by config module */ /* should be called only at program exit */ -void free_configmodule(void) -{ +void free_configmodule(void) { if (cfgptr != NULL) { - end_configmodule(); - if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode); - printf ("[CONFIG] free %u config parameter pointers\n",cfgptr->num_cfgP); - for (int i=0; inum_cfgP; i++) { - if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]); - } + end_configmodule(); + + if( cfgptr->cfgmode != NULL) free(cfgptr->cfgmode); + printf ("[CONFIG] free %u config parameter pointers\n",cfgptr->num_cfgP); + + for (int i=0; inum_cfgP; i++) { + if ( cfgptr->cfgP[i] != NULL) free(cfgptr->cfgP[i]); + } - free(cfgptr); - cfgptr=NULL; + free(cfgptr); + cfgptr=NULL; } } diff --git a/common/config/config_load_configmodule.h b/common/config/config_load_configmodule.h index d98e825095..2f5c055a00 100644 --- a/common/config/config_load_configmodule.h +++ b/common/config/config_load_configmodule.h @@ -20,8 +20,8 @@ */ /*! \file common/config/config_load_configmodule.h - * \brief: configuration module, include file to be used by the source code calling the - * configuration module initialization + * \brief: configuration module, include file to be used by the source code calling the + * configuration module initialization * \author Francois TABURET * \date 2017 * \version 0.1 @@ -31,7 +31,7 @@ * \warning */ #ifndef INCLUDE_CONFIG_LOADCONFIGMODULE_H -#define INCLUDE_CONFIG_LOADCONFIGMODULE_H +#define INCLUDE_CONFIG_LOADCONFIGMODULE_H #include @@ -61,8 +61,7 @@ typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP); typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix); typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix); typedef void(*configmodule_endfunc_t)(void); -typedef struct configmodule_interface -{ +typedef struct configmodule_interface { int argc; char **argv; uint32_t *argv_info; @@ -75,7 +74,7 @@ typedef struct configmodule_interface configmodule_endfunc_t end; uint32_t numptrs; uint32_t rtflags; - char *ptrs[CONFIG_MAX_ALLOCATEDPTRS]; + char *ptrs[CONFIG_MAX_ALLOCATEDPTRS]; } configmodule_interface_t; #ifdef CONFIG_LOADCONFIG_MAIN @@ -85,17 +84,17 @@ static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbgl[debugfl debugflags can also be defined in the config_libconfig section of the config file\n \ debugflags: mask, 1->print parameters, 2->print memory allocations debug messages\n \ 4->print command line processing debug messages\n "; - + #define CONFIG_SECTIONNAME "config" #define CONFIGPARAM_DEBUGFLAGS_IDX 0 static paramdef_t Config_Params[] = { -/*-----------------------------------------------------------------------------------------------------------------------*/ -/* config parameters for config module */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*-----------------------------------------------------------------------------------------------------------------------*/ -{"debugflags", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_MASK, 0}, + /*-----------------------------------------------------------------------------------------------------------------------*/ + /* config parameters for config module */ + /* optname helpstr paramflags XXXptr defXXXval type numelt */ + /*-----------------------------------------------------------------------------------------------------------------------*/ + {"debugflags", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_MASK, 0}, }; #else @@ -104,7 +103,7 @@ extern configmodule_interface_t *cfgptr; #define printf_params(...) if ( (cfgptr->rtflags & (CONFIG_PRINTPARAMS)) != 0 ) { printf ( __VA_ARGS__ ); } -#define printf_ptrs(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 ) { printf ( __VA_ARGS__ ); } +#define printf_ptrs(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 ) { printf ( __VA_ARGS__ ); } #define printf_cmdl(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGCMDLINE)) != 0 ) { printf ( __VA_ARGS__ ); } #define CONFIG_ENABLECMDLINEONLY (1<<1) diff --git a/common/config/config_paramdesc.h b/common/config/config_paramdesc.h index 60ab00a5ed..627c232f85 100644 --- a/common/config/config_paramdesc.h +++ b/common/config/config_paramdesc.h @@ -59,78 +59,77 @@ #define CONFIG_MAX_NUMCHECKVAL 20 typedef struct paramdef paramdef_t; typedef union checkedparam { - struct { - int (*f1)(paramdef_t *param); /* check an integer against a list of authorized values */ - int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values */ - int num_okintval; /* number of valid values in the checkingval array */ - } s1; - struct { - int (*f1a)(paramdef_t *param); /* check an integer against a list of authorized values and set param value */ - /* to the corresponding item in setintval array (mainly for RRC params) */ - int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values in config file */ - int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */ - int num_okintval; /* number of valid values in the checkingval array */ - } s1a; - struct { - int (*f2)(paramdef_t *param); /* check an integer against an authorized range, defined by its min and max value */ - int okintrange[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store min and max values */ - - } s2; - struct { - int (*f3)(paramdef_t *param); /* check a string against a list of authorized values */ - char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */ - int num_okstrval; /* number of valid values in the checkingval array */ - } s3; - struct { - int (*f3a)(paramdef_t *param); /* check a string against a list of authorized values and set param value */ - /* to the corresponding item in setintval array (mainly for RRC params) */ - char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */ - int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */ - int num_okstrval; /* number of valid values in the checkingval array */ - } s3a; - struct { - int (*f4)(paramdef_t *param); /* generic check function, no arguments but the param description */ - - } s4; - struct { - void (*checkfunc)(void) ; - } s5; + struct { + int (*f1)(paramdef_t *param); /* check an integer against a list of authorized values */ + int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values */ + int num_okintval; /* number of valid values in the checkingval array */ + } s1; + struct { + int (*f1a)(paramdef_t *param); /* check an integer against a list of authorized values and set param value */ + /* to the corresponding item in setintval array (mainly for RRC params) */ + int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values in config file */ + int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */ + int num_okintval; /* number of valid values in the checkingval array */ + } s1a; + struct { + int (*f2)(paramdef_t *param); /* check an integer against an authorized range, defined by its min and max value */ + int okintrange[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store min and max values */ + + } s2; + struct { + int (*f3)(paramdef_t *param); /* check a string against a list of authorized values */ + char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */ + int num_okstrval; /* number of valid values in the checkingval array */ + } s3; + struct { + int (*f3a)(paramdef_t *param); /* check a string against a list of authorized values and set param value */ + /* to the corresponding item in setintval array (mainly for RRC params) */ + char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */ + int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */ + int num_okstrval; /* number of valid values in the checkingval array */ + } s3a; + struct { + int (*f4)(paramdef_t *param); /* generic check function, no arguments but the param description */ + + } s4; + struct { + void (*checkfunc)(void) ; + } s5; } checkedparam_t; /* paramdef is used to describe a parameter, array of paramdef_t strustures is used as the main parameter in */ /* config apis used to retrieve parameters values */ -typedef struct paramdef -{ - char optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */ - char *helpstr; /* help string */ - unsigned int paramflags; /* value is a "ored" combination of above PARAMFLAG_XXXX values */ - union { /* pointer to the parameter value, completed by the config module */ - char **strptr; - char **strlistptr; - uint8_t *u8ptr; - int8_t *i8ptr; - uint16_t *u16ptr; - int16_t *i16ptr; - uint32_t *uptr; - int32_t *iptr; - uint64_t *u64ptr; - int64_t *i64ptr; - double *dblptr; - void *voidptr; - } ; - union { /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */ - char *defstrval; - char **defstrlistval; - uint32_t defuintval; - int defintval; - uint64_t defint64val; - int *defintarrayval; - double defdblval; - } ; - char type; /* parameter value type, as listed below as TYPE_XXXX macro */ - int numelt; /* number of elements in a list or array parameters or max size of string value */ - checkedparam_t *chkPptr; /* possible pointer to the structure containing the info used to check parameter values */ - int *processedvalue; /* used to store integer values computed from string original value */ +typedef struct paramdef { + char optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */ + char *helpstr; /* help string */ + unsigned int paramflags; /* value is a "ored" combination of above PARAMFLAG_XXXX values */ + union { /* pointer to the parameter value, completed by the config module */ + char **strptr; + char **strlistptr; + uint8_t *u8ptr; + int8_t *i8ptr; + uint16_t *u16ptr; + int16_t *i16ptr; + uint32_t *uptr; + int32_t *iptr; + uint64_t *u64ptr; + int64_t *i64ptr; + double *dblptr; + void *voidptr; + } ; + union { /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */ + char *defstrval; + char **defstrlistval; + uint32_t defuintval; + int defintval; + uint64_t defint64val; + int *defintarrayval; + double defdblval; + } ; + char type; /* parameter value type, as listed below as TYPE_XXXX macro */ + int numelt; /* number of elements in a list or array parameters or max size of string value */ + checkedparam_t *chkPptr; /* possible pointer to the structure containing the info used to check parameter values */ + int *processedvalue; /* used to store integer values computed from string original value */ } paramdef_t; #define TYPE_INT TYPE_INT32 @@ -160,9 +159,9 @@ typedef struct paramdef #define ANY_IPV4ADDR_STRING "0.0.0.0" typedef struct paramlist_def { - char listname[MAX_OPTNAME_SIZE]; - paramdef_t **paramarray; - int numelt ; + char listname[MAX_OPTNAME_SIZE]; + paramdef_t **paramarray; + int numelt ; } paramlist_def_t; /* macro helpers for module users */ diff --git a/common/config/config_userapi.c b/common/config/config_userapi.c index d6e4beeaf5..afbe1ae887 100644 --- a/common/config/config_userapi.c +++ b/common/config/config_userapi.c @@ -44,409 +44,449 @@ #include "config_userapi.h" -configmodule_interface_t *config_get_if(void) -{ - if (cfgptr == NULL) { - fprintf(stderr,"[CONFIG] %s %d config module not initialized\n",__FILE__, __LINE__); - exit(-1); - } - return cfgptr; +configmodule_interface_t *config_get_if(void) { + if (cfgptr == NULL) { + fprintf(stderr,"[CONFIG] %s %d config module not initialized\n",__FILE__, __LINE__); + exit(-1); + } + + return cfgptr; } -char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) -{ - if (ptr == NULL ) { - ptr = malloc(sizeof(char *)); - if (ptr != NULL) { - *ptr=NULL; - cfgoptions->strptr=ptr; - if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) { - config_get_if()->ptrs[config_get_if()->numptrs] = (char *)ptr; - config_get_if()->numptrs++; - } - } else { - fprintf(stderr, "[CONFIG] %s %d option %s, cannot allocate pointer: %s \n", - __FILE__, __LINE__, cfgoptions->optname, strerror(errno)); - exit(-1); - } - } - printf_ptrs("[CONFIG] %s ptr: 0x%08lx requested size: %i\n",cfgoptions->optname,(uintptr_t)(ptr),length); - if(cfgoptions->numelt > 0 && PARAM_ISSCALAR(cfgoptions) ) { /* already allocated */ - if (*ptr != NULL) { - return *ptr; - } else { - fprintf(stderr,"[CONFIG] %s %d option %s, definition error: value pointer is NULL, declared as %i bytes allocated\n", - __FILE__, __LINE__,cfgoptions->optname, cfgoptions->numelt); - exit(-1); - } - } - - if (*ptr == NULL) { - *ptr = malloc(length); - if ( *ptr != NULL) { - memset(*ptr,0,length); - if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) { - config_get_if()->ptrs[config_get_if()->numptrs] = *ptr; - config_get_if()->numptrs++; - } - } else { - fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__); - exit(-1); - } - } - return *ptr; +char *config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) { + if (ptr == NULL ) { + ptr = malloc(sizeof(char *)); + + if (ptr != NULL) { + *ptr=NULL; + cfgoptions->strptr=ptr; + + if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) { + config_get_if()->ptrs[config_get_if()->numptrs] = (char *)ptr; + config_get_if()->numptrs++; + } + } else { + fprintf(stderr, "[CONFIG] %s %d option %s, cannot allocate pointer: %s \n", + __FILE__, __LINE__, cfgoptions->optname, strerror(errno)); + exit(-1); + } + } + + printf_ptrs("[CONFIG] %s ptr: 0x%08lx requested size: %i\n",cfgoptions->optname,(uintptr_t)(ptr),length); + + if(cfgoptions->numelt > 0 && PARAM_ISSCALAR(cfgoptions) ) { /* already allocated */ + if (*ptr != NULL) { + return *ptr; + } else { + fprintf(stderr,"[CONFIG] %s %d option %s, definition error: value pointer is NULL, declared as %i bytes allocated\n", + __FILE__, __LINE__,cfgoptions->optname, cfgoptions->numelt); + exit(-1); + } + } + + if (*ptr == NULL) { + *ptr = malloc(length); + + if ( *ptr != NULL) { + memset(*ptr,0,length); + + if ( (cfgoptions->paramflags & PARAMFLAG_NOFREE) == 0) { + config_get_if()->ptrs[config_get_if()->numptrs] = *ptr; + config_get_if()->numptrs++; + } + } else { + fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__); + exit(-1); + } + } + + return *ptr; } -void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val) -{ -int tmpval=val; +void config_assign_int(paramdef_t *cfgoptions, char *fullname, int val) { + int tmpval=val; + if ( ((cfgoptions->paramflags &PARAMFLAG_BOOL) != 0) && tmpval >0) { - tmpval =1; + tmpval =1; } + switch (cfgoptions->type) { - case TYPE_UINT8: - *(cfgoptions->u8ptr) = (uint8_t)tmpval; - printf_params("[CONFIG] %s: %u\n", fullname, (uint8_t)tmpval); - break; - case TYPE_INT8: - *(cfgoptions->i8ptr) = (int8_t)tmpval; - printf_params("[CONFIG] %s: %i\n", fullname, (int8_t)tmpval); - break; - case TYPE_UINT16: - *(cfgoptions->u16ptr) = (uint16_t)tmpval; - printf_params("[CONFIG] %s: %hu\n", fullname, (uint16_t)tmpval); - break; - case TYPE_INT16: - *(cfgoptions->i16ptr) = (int16_t)tmpval; - printf_params("[CONFIG] %s: %hi\n", fullname, (int16_t)tmpval); - break; - case TYPE_UINT32: - *(cfgoptions->uptr) = (uint32_t)tmpval; - printf_params("[CONFIG] %s: %u\n", fullname, (uint32_t)tmpval); - break; - case TYPE_MASK: - *(cfgoptions->uptr) = *(cfgoptions->uptr) | (uint32_t)tmpval; - printf_params("[CONFIG] %s: 0x%08x\n", fullname, (uint32_t)tmpval); - break; - case TYPE_INT32: - *(cfgoptions->iptr) = (int32_t)tmpval; - printf_params("[CONFIG] %s: %i\n", fullname, (int32_t)tmpval); - break; - default: - fprintf (stderr,"[CONFIG] %s %i type %i non integer parameter %s not assigned\n",__FILE__, __LINE__,cfgoptions->type,fullname); - break; + case TYPE_UINT8: + *(cfgoptions->u8ptr) = (uint8_t)tmpval; + printf_params("[CONFIG] %s: %u\n", fullname, (uint8_t)tmpval); + break; + + case TYPE_INT8: + *(cfgoptions->i8ptr) = (int8_t)tmpval; + printf_params("[CONFIG] %s: %i\n", fullname, (int8_t)tmpval); + break; + + case TYPE_UINT16: + *(cfgoptions->u16ptr) = (uint16_t)tmpval; + printf_params("[CONFIG] %s: %hu\n", fullname, (uint16_t)tmpval); + break; + + case TYPE_INT16: + *(cfgoptions->i16ptr) = (int16_t)tmpval; + printf_params("[CONFIG] %s: %hi\n", fullname, (int16_t)tmpval); + break; + + case TYPE_UINT32: + *(cfgoptions->uptr) = (uint32_t)tmpval; + printf_params("[CONFIG] %s: %u\n", fullname, (uint32_t)tmpval); + break; + + case TYPE_MASK: + *(cfgoptions->uptr) = *(cfgoptions->uptr) | (uint32_t)tmpval; + printf_params("[CONFIG] %s: 0x%08x\n", fullname, (uint32_t)tmpval); + break; + + case TYPE_INT32: + *(cfgoptions->iptr) = (int32_t)tmpval; + printf_params("[CONFIG] %s: %i\n", fullname, (int32_t)tmpval); + break; + + default: + fprintf (stderr,"[CONFIG] %s %i type %i non integer parameter %s not assigned\n",__FILE__, __LINE__,cfgoptions->type,fullname); + break; } } void config_assign_processedint(paramdef_t *cfgoption, int val) { - cfgoption->processedvalue = malloc(sizeof(int)); - if ( cfgoption->processedvalue != NULL) { - *(cfgoption->processedvalue) = val; - } else { - fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__); - exit(-1); - } + cfgoption->processedvalue = malloc(sizeof(int)); + + if ( cfgoption->processedvalue != NULL) { + *(cfgoption->processedvalue) = val; + } else { + fprintf (stderr,"[CONFIG] %s %d malloc error\n",__FILE__, __LINE__); + exit(-1); + } } int config_get_processedint(paramdef_t *cfgoption) { - int ret; - if ( cfgoption->processedvalue != NULL) { - ret=*(cfgoption->processedvalue); - free( cfgoption->processedvalue); - cfgoption->processedvalue=NULL; - printf_params("[CONFIG] %s: set from %s to %i\n",cfgoption->optname, *(cfgoption->strptr), ret); - } else { - fprintf (stderr,"[CONFIG] %s %d %s has no processed integer availablle\n",__FILE__, __LINE__, cfgoption->optname); - ret=0; - } -return ret; + int ret; + + if ( cfgoption->processedvalue != NULL) { + ret=*(cfgoption->processedvalue); + free( cfgoption->processedvalue); + cfgoption->processedvalue=NULL; + printf_params("[CONFIG] %s: set from %s to %i\n",cfgoption->optname, *(cfgoption->strptr), ret); + } else { + fprintf (stderr,"[CONFIG] %s %d %s has no processed integer availablle\n",__FILE__, __LINE__, cfgoption->optname); + ret=0; + } + + return ret; } -void config_printhelp(paramdef_t *params,int numparams) -{ - for (int i=0 ; is4.f4 != NULL) { - st += params[i].chkPptr->s4.f4(&(params[i])); - } - } - if (st != 0) { - fprintf(stderr,"[CONFIG] config_execcheck: section %s %i parameters with wrong value\n", prefix, -st); - if ( CONFIG_ISFLAGSET(CONFIG_NOABORTONCHKF) == 0) { - exit_fun("exit because configuration failed\n"); - } - } -return st; +int config_execcheck(paramdef_t *params,int numparams, char *prefix) { + int st=0; + + for (int i=0 ; is4.f4 != NULL) { + st += params[i].chkPptr->s4.f4(&(params[i])); + } + } + + if (st != 0) { + fprintf(stderr,"[CONFIG] config_execcheck: section %s %i parameters with wrong value\n", prefix, -st); + + if ( CONFIG_ISFLAGSET(CONFIG_NOABORTONCHKF) == 0) { + exit_fun("exit because configuration failed\n"); + } + } + + return st; } -int config_get(paramdef_t *params,int numparams, char *prefix) -{ -int ret= -1; +int config_get(paramdef_t *params,int numparams, char *prefix) { + int ret= -1; if (CONFIG_ISFLAGSET(CONFIG_ABORT)) { fprintf(stderr,"[CONFIG] config_get, section %s skipped, config module not properly initialized\n",prefix); return ret; } + configmodule_interface_t *cfgif = config_get_if(); + if (cfgif != NULL) { ret = config_get_if()->get(params, numparams,prefix); + if (ret >= 0) { config_process_cmdline(params,numparams,prefix); config_execcheck(params,numparams,prefix); } + return ret; } + return ret; } -int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix) -{ +int config_getlist(paramlist_def_t *ParamList, paramdef_t *params, int numparams, char *prefix) { if (CONFIG_ISFLAGSET(CONFIG_ABORT)) { fprintf(stderr,"[CONFIG] config_get skipped, config module not properly initialized\n"); return -1; } + if (!config_get_if()) return -1; const int ret = config_get_if()->getlist(ParamList, params, numparams, prefix); + if (ret >= 0 && params) { char *newprefix; + if (prefix) { int rc = asprintf(&newprefix, "%s.%s", prefix, ParamList->listname); + if (rc < 0) newprefix = NULL; } else { newprefix = ParamList->listname; } + char cfgpath[MAX_OPTNAME_SIZE*2 + 6]; /* prefix.listname.[listindex] */ + for (int i = 0; i < ParamList->numelt; ++i) { // TODO config_process_cmdline? sprintf(cfgpath, "%s.[%i]", newprefix, i); config_execcheck(ParamList->paramarray[i], numparams, cfgpath); } + if (prefix) free(newprefix); } + return ret; } -int config_isparamset(paramdef_t *params,int paramidx) -{ +int config_isparamset(paramdef_t *params,int paramidx) { if ((params[paramidx].paramflags & PARAMFLAG_PARAMSET) != 0) { - return 1; + return 1; } else { - return 0; + return 0; } } void print_intvalueerror(paramdef_t *param, char *fname, int *okval, int numokval) { - fprintf(stderr,"[CONFIG] %s: %s: %i invalid value, authorized values:\n ", - fname,param->optname, (int)*(param->uptr)); - for ( int i=0; ioptname, (int)*(param->uptr)); + + for ( int i=0; ichkPptr->s1.num_okintval ; i++) { - if( *(param->uptr) == param->chkPptr->s1.okintval[i] ) { - return 0; - } - } - print_intvalueerror(param,"config_check_intval", param->chkPptr->s1.okintval,param->chkPptr->s1.num_okintval); + +int config_check_intval(paramdef_t *param) { + if ( param == NULL ) { + fprintf(stderr,"[CONFIG] config_check_intval: NULL param argument\n"); return -1; + } + + for ( int i=0; ichkPptr->s1.num_okintval ; i++) { + if( *(param->uptr) == param->chkPptr->s1.okintval[i] ) { + return 0; + } + } + + print_intvalueerror(param,"config_check_intval", param->chkPptr->s1.okintval,param->chkPptr->s1.num_okintval); + return -1; } -int config_check_modify_integer(paramdef_t *param) -{ - - for (int i=0; i < param->chkPptr->s1a.num_okintval ; i++) { - if (*(param->uptr) == param->chkPptr->s1a.okintval[i] ) { - printf_params("[CONFIG] %s: read value %i, set to %i\n",param->optname,*(param->uptr),param->chkPptr->s1a.setintval [i]); - *(param->uptr) = param->chkPptr->s1a.setintval [i]; - return 0; - } - } - print_intvalueerror(param,"config_check_modify_integer", param->chkPptr->s1a.okintval,param->chkPptr->s1a.num_okintval); - return -1; +int config_check_modify_integer(paramdef_t *param) { + for (int i=0; i < param->chkPptr->s1a.num_okintval ; i++) { + if (*(param->uptr) == param->chkPptr->s1a.okintval[i] ) { + printf_params("[CONFIG] %s: read value %i, set to %i\n",param->optname,*(param->uptr),param->chkPptr->s1a.setintval [i]); + *(param->uptr) = param->chkPptr->s1a.setintval [i]; + return 0; + } + } + + print_intvalueerror(param,"config_check_modify_integer", param->chkPptr->s1a.okintval,param->chkPptr->s1a.num_okintval); + return -1; } -int config_check_intrange(paramdef_t *param) -{ - if( *(param->iptr) >= param->chkPptr->s2.okintrange[0] && *(param->iptr) <= param->chkPptr->s2.okintrange[1] ) { - return 0; - } - fprintf(stderr,"[CONFIG] config_check_intrange: %s: %i invalid value, authorized range: %i %i\n", - param->optname, (int)*(param->uptr), param->chkPptr->s2.okintrange[0], param->chkPptr->s2.okintrange[1]); - return -1; +int config_check_intrange(paramdef_t *param) { + if( *(param->iptr) >= param->chkPptr->s2.okintrange[0] && *(param->iptr) <= param->chkPptr->s2.okintrange[1] ) { + return 0; + } + + fprintf(stderr,"[CONFIG] config_check_intrange: %s: %i invalid value, authorized range: %i %i\n", + param->optname, (int)*(param->uptr), param->chkPptr->s2.okintrange[0], param->chkPptr->s2.okintrange[1]); + return -1; } void print_strvalueerror(paramdef_t *param, char *fname, char **okval, int numokval) { - fprintf(stderr,"[CONFIG] %s: %s: %s invalid value, authorized values:\n ", - fname,param->optname, *(param->strptr)); - for ( int i=0; ioptname, *(param->strptr)); + + for ( int i=0; ichkPptr->s3.num_okstrval ; i++) { - if( strcasecmp(*(param->strptr),param->chkPptr->s3.okstrval[i] ) == 0) { - return 0; - } - } - print_strvalueerror(param, "config_check_strval", param->chkPptr->s3.okstrval, param->chkPptr->s3.num_okstrval); + +int config_check_strval(paramdef_t *param) { + if ( param == NULL ) { + fprintf(stderr,"[CONFIG] config_check_strval: NULL param argument\n"); return -1; -} + } -int config_checkstr_assign_integer(paramdef_t *param) -{ + for ( int i=0; ichkPptr->s3.num_okstrval ; i++) { + if( strcasecmp(*(param->strptr),param->chkPptr->s3.okstrval[i] ) == 0) { + return 0; + } + } + print_strvalueerror(param, "config_check_strval", param->chkPptr->s3.okstrval, param->chkPptr->s3.num_okstrval); + return -1; +} - for (int i=0; i < param->chkPptr->s3a.num_okstrval ; i++) { - if (strcasecmp(*(param->strptr),param->chkPptr->s3a.okstrval[i] ) == 0) { - config_assign_processedint(param, param->chkPptr->s3a.setintval[i]); - return 0; - } - } - print_strvalueerror(param, "config_check_strval", param->chkPptr->s3a.okstrval, param->chkPptr->s3a.num_okstrval); +int config_checkstr_assign_integer(paramdef_t *param) { + for (int i=0; i < param->chkPptr->s3a.num_okstrval ; i++) { + if (strcasecmp(*(param->strptr),param->chkPptr->s3a.okstrval[i] ) == 0) { + config_assign_processedint(param, param->chkPptr->s3a.setintval[i]); + return 0; + } + } - return -1; + print_strvalueerror(param, "config_check_strval", param->chkPptr->s3a.okstrval, param->chkPptr->s3a.num_okstrval); + return -1; } -int config_setdefault_string(paramdef_t *cfgoptions, char *prefix) -{ +int config_setdefault_string(paramdef_t *cfgoptions, char *prefix) { int status = 0; + if( cfgoptions->defstrval != NULL) { - status=1; - - if (cfgoptions->numelt == 0 ) { - config_check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *)); - config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(cfgoptions->defstrval)+1); - sprintf(*(cfgoptions->strptr), "%s",cfgoptions->defstrval); - printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, *(cfgoptions->strptr)); - } else { - sprintf((char *)*(cfgoptions->strptr), "%s",cfgoptions->defstrval); - printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (char *)*(cfgoptions->strptr)); - } + status=1; + + if (cfgoptions->numelt == 0 ) { + config_check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *)); + config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(cfgoptions->defstrval)+1); + sprintf(*(cfgoptions->strptr), "%s",cfgoptions->defstrval); + printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, *(cfgoptions->strptr)); + } else { + sprintf((char *)*(cfgoptions->strptr), "%s",cfgoptions->defstrval); + printf_params("[CONFIG] %s.%s set to default value \"%s\"\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (char *)*(cfgoptions->strptr)); + } } + return status; } -int config_setdefault_stringlist(paramdef_t *cfgoptions, char *prefix) -{ +int config_setdefault_stringlist(paramdef_t *cfgoptions, char *prefix) { int status = 0; + if( cfgoptions->defstrlistval != NULL) { - cfgoptions->strlistptr=cfgoptions->defstrlistval; - status=1; - for(int j=0; jnumelt; j++) - printf_params("[CONFIG] %s.%s[%i] set to default value %s\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname,j, cfgoptions->strlistptr[j]); + cfgoptions->strlistptr=cfgoptions->defstrlistval; + status=1; + + for(int j=0; jnumelt; j++) + printf_params("[CONFIG] %s.%s[%i] set to default value %s\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname,j, cfgoptions->strlistptr[j]); } + return status; } -int config_setdefault_int(paramdef_t *cfgoptions, char *prefix) -{ +int config_setdefault_int(paramdef_t *cfgoptions, char *prefix) { int status = 0; config_check_valptr(cfgoptions, (char **)(&(cfgoptions->iptr)),sizeof(int32_t)); + if( ((cfgoptions->paramflags & PARAMFLAG_MANDATORY) == 0)) { - config_assign_int(cfgoptions,cfgoptions->optname,cfgoptions->defintval); - status=1; - printf_params("[CONFIG] %s.%s set to default value\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname); + config_assign_int(cfgoptions,cfgoptions->optname,cfgoptions->defintval); + status=1; + printf_params("[CONFIG] %s.%s set to default value\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname); } + return status; -} +} -int config_setdefault_int64(paramdef_t *cfgoptions, char *prefix) -{ +int config_setdefault_int64(paramdef_t *cfgoptions, char *prefix) { int status = 0; config_check_valptr(cfgoptions, (char **)&(cfgoptions->i64ptr),sizeof(long long)); + if( ((cfgoptions->paramflags & PARAMFLAG_MANDATORY) == 0)) { - *(cfgoptions->u64ptr)=cfgoptions->defuintval; - status=1; - printf_params("[CONFIG] %s.%s set to default value %llu\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (long long unsigned)(*(cfgoptions->u64ptr))); + *(cfgoptions->u64ptr)=cfgoptions->defuintval; + status=1; + printf_params("[CONFIG] %s.%s set to default value %llu\n", ((prefix == NULL) ? "" : prefix), cfgoptions->optname, (long long unsigned)(*(cfgoptions->u64ptr))); } + return status; } -int config_setdefault_intlist(paramdef_t *cfgoptions, char *prefix) -{ - int status = 0; +int config_setdefault_intlist(paramdef_t *cfgoptions, char *prefix) { + int status = 0; + if( cfgoptions->defintarrayval != NULL) { - config_check_valptr(cfgoptions,(char **)&(cfgoptions->iptr), sizeof(int32_t*)); + config_check_valptr(cfgoptions,(char **)&(cfgoptions->iptr), sizeof(int32_t *)); cfgoptions->iptr=cfgoptions->defintarrayval; status=1; + for (int j=0; jnumelt ; j++) { - printf_params("[CONFIG] %s[%i] set to default value %i\n",cfgoptions->optname ,j,(int)cfgoptions->iptr[j]); + printf_params("[CONFIG] %s[%i] set to default value %i\n",cfgoptions->optname ,j,(int)cfgoptions->iptr[j]); } } + return status; } -int config_setdefault_double(paramdef_t *cfgoptions, char *prefix) -{ +int config_setdefault_double(paramdef_t *cfgoptions, char *prefix) { int status = 0; config_check_valptr(cfgoptions, (char **)&(cfgoptions->dblptr),sizeof(double)); + if( ((cfgoptions->paramflags & PARAMFLAG_MANDATORY) == 0)) { - *(cfgoptions->u64ptr)=cfgoptions->defdblval; - status=1; - printf_params("[CONFIG] %s set to default value %lf\n",cfgoptions->optname , *(cfgoptions->dblptr)); + *(cfgoptions->u64ptr)=cfgoptions->defdblval; + status=1; + printf_params("[CONFIG] %s set to default value %lf\n",cfgoptions->optname , *(cfgoptions->dblptr)); } + return status; -} +} -int config_assign_ipv4addr(paramdef_t *cfgoptions, char *ipv4addr) -{ +int config_assign_ipv4addr(paramdef_t *cfgoptions, char *ipv4addr) { config_check_valptr(cfgoptions,(char **)&(cfgoptions->uptr), sizeof(int)); - int rst=inet_pton(AF_INET, ipv4addr ,cfgoptions->uptr ); + int rst=inet_pton(AF_INET, ipv4addr ,cfgoptions->uptr ); + if (rst == 1 && *(cfgoptions->uptr) > 0) { - printf_params("[CONFIG] %s: %s\n",cfgoptions->optname, ipv4addr); - return 1; + printf_params("[CONFIG] %s: %s\n",cfgoptions->optname, ipv4addr); + return 1; } else { - if ( strncmp(ipv4addr,ANY_IPV4ADDR_STRING,sizeof(ANY_IPV4ADDR_STRING)) == 0) { - printf_params("[CONFIG] %s:%s (INADDR_ANY) \n",cfgoptions->optname,ipv4addr); - *cfgoptions->uptr=INADDR_ANY; - return 1; - } else { - fprintf(stderr,"[CONFIG] %s not valid for %s \n", ipv4addr, cfgoptions->optname); - return -1; - } + if ( strncmp(ipv4addr,ANY_IPV4ADDR_STRING,sizeof(ANY_IPV4ADDR_STRING)) == 0) { + printf_params("[CONFIG] %s:%s (INADDR_ANY) \n",cfgoptions->optname,ipv4addr); + *cfgoptions->uptr=INADDR_ANY; + return 1; + } else { + fprintf(stderr,"[CONFIG] %s not valid for %s \n", ipv4addr, cfgoptions->optname); + return -1; + } } + return 0; } -int config_setdefault_ipv4addr(paramdef_t *cfgoptions, char *prefix) -{ +int config_setdefault_ipv4addr(paramdef_t *cfgoptions, char *prefix) { int status = 0; - + if (cfgoptions->defstrval != NULL) { - status = config_assign_ipv4addr(cfgoptions, cfgoptions->defstrval); + status = config_assign_ipv4addr(cfgoptions, cfgoptions->defstrval); } + return status; -} +} diff --git a/common/config/config_userapi.h b/common/config/config_userapi.h index f4b592bafb..5542148343 100644 --- a/common/config/config_userapi.h +++ b/common/config/config_userapi.h @@ -20,7 +20,7 @@ */ /*! \file common/config/config_userapi.h - * \brief: configuration module, include file to be used by the source code calling the + * \brief: configuration module, include file to be used by the source code calling the * configuration module to access configuration parameters * \author Francois TABURET * \date 2017 @@ -31,7 +31,7 @@ * \warning */ #ifndef INCLUDE_CONFIG_USERAPI_H -#define INCLUDE_CONFIG_USERAPI_H +#define INCLUDE_CONFIG_USERAPI_H #include "config_load_configmodule.h" #ifdef __cplusplus @@ -48,7 +48,7 @@ extern "C" #define CONFIG_ISPARAMFLAGSET(P,F) ( !!(P.paramflags & F)) /* utility functions, to be used by configuration module and/or configuration libraries */ extern configmodule_interface_t *config_get_if(void); -extern char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ; +extern char *config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ; extern void config_printhelp(paramdef_t *,int numparams); extern int config_process_cmdline(paramdef_t *params,int numparams, char *prefix); extern void config_assign_processedint(paramdef_t *cfgoption, int val); diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index a65aa1e4a5..98f4b19f20 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -72,16 +72,14 @@ char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL char *log_level_highlight_end[] = {LOG_RESET,LOG_RESET,LOG_RESET, LOG_RESET,LOG_RESET}; /*!< \brief Optional end-format strings for highlighting */ -int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format) -{ - +int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format) { FILE *fp=NULL; int i; if (data == NULL) - return -1; - //printf("Writing %d elements of type %d to %s\n",length,format,fname); + return -1; + //printf("Writing %d elements of type %d to %s\n",length,format,fname); if (format == 10 || format ==11 || format == 12 || format == 13 || format == 14) { fp = fopen(fname,"a+"); @@ -89,8 +87,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, fp = fopen(fname,"w+"); } - - if (fp== NULL) { printf("[OPENAIR][FILE OUTPUT] Cannot open file %s\n",fname); return(-1); @@ -99,121 +95,108 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, if (format != 10 && format !=11 && format != 12 && format != 13 && format != 14) fprintf(fp,"%s = [",vname); - switch (format) { - case 0: // real 16-bit - - for (i=0; i 0)) - fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); - else if (i == 2*(length-1)) - fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]); - else if (i == 0) - fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + break; + case 8: // complex double + for (i=0; i 0)) + fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + else if (i == 2*(length-1)) + fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]); + else if (i == 0) + fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + } - if((i <(length-1))&& (i > 0)) - fprintf(fp,"%d,",((short *)data)[i]); - else if (i == (length-1)) - fprintf(fp,"%d;",((short *)data)[i]); - else if (i == 0) - fprintf(fp,"\n%d,",((short *)data)[i]); - } + break; - printf("\n eren: length :%d",length); - break; + case 11 : //case eren 16 bit real for channel magnitudes: + for (i=0; i 0)) + fprintf(fp,"%d,",((short *)data)[i]); + else if (i == (length-1)) + fprintf(fp,"%d;",((short *)data)[i]); + else if (i == 0) + fprintf(fp,"\n%d,",((short *)data)[i]); + } - case 12 : // case eren for log2_maxh real unsigned 8 bit - fprintf(fp,"%d \n",((unsigned char *)&data)[0]); - break; + printf("\n eren: length :%d",length); + break; + case 12 : // case eren for log2_maxh real unsigned 8 bit + fprintf(fp,"%d \n",((unsigned char *)&data)[0]); + break; } if (format != 10 && format !=11 && format !=12 && format != 13 && format != 15) { @@ -232,8 +215,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, void log_getconfig(log_t *g_log) { char *gloglevel = NULL; int consolelog ; - - paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC; paramdef_t logparams_level[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS]; @@ -241,131 +222,146 @@ void log_getconfig(log_t *g_log) { paramdef_t logparams_dump[sizeof(log_maskmap)/sizeof(mapping)]; CONFIG_SETRTFLAG(CONFIG_NOCHECKUNKOPT); int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX); + if (ret <0) { - fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); - return; - } + fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); + return; + } -/* set LOG display options (enable/disable color, thread name, level ) */ + /* set LOG display options (enable/disable color, thread name, level ) */ for(int i=0; iflag = g_log->flag | log_options[j].value; - break; - } else if (log_options[j+1].name == NULL){ - fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]); - exit(-1); - } - } - } - -/* build the parameter array for setting per component log level and infile options */ + for(int j=0; log_options[j].name != NULL ; j++) { + if (strcmp(logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i],log_options[j].name) == 0) { + g_log->flag = g_log->flag | log_options[j].value; + break; + } else if (log_options[j+1].name == NULL) { + fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]); + exit(-1); + } + } + } + + /* build the parameter array for setting per component log level and infile options */ memset(logparams_level, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); + for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { if(g_log->log_component[i].name == NULL) { - g_log->log_component[i].name = malloc(16); - sprintf((char *)g_log->log_component[i].name,"comp%i?",i); - logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD; - logparams_level[i].paramflags = PARAMFLAG_DONOTREAD; + g_log->log_component[i].name = malloc(16); + sprintf((char *)g_log->log_component[i].name,"comp%i?",i); + logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD; + logparams_level[i].paramflags = PARAMFLAG_DONOTREAD; } + sprintf(logparams_level[i].optname, LOG_CONFIG_LEVEL_FORMAT, g_log->log_component[i].name); sprintf(logparams_logfile[i].optname, LOG_CONFIG_LOGFILE_FORMAT, g_log->log_component[i].name); -/* workaround: all log options in existing configuration files use lower case component names - where component names include uppercase char in log.h.... */ - for (int j=0 ; jlog_component[i].level = map_str_to_int(log_level_names, *(logparams_level[i].strptr)); set_log(i, g_log->log_component[i].level); + if (*(logparams_logfile[i].uptr) == 1) - set_component_filelog(i); + set_component_filelog(i); } -/* build then read the debug and dump parameter array */ - for (int i=0;log_maskmap[i].name != NULL ; i++) { - sprintf(logparams_debug[i].optname, LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name); - sprintf(logparams_dump[i].optname, LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name); - logparams_debug[i].defuintval = 0; - logparams_debug[i].type = TYPE_UINT; - logparams_debug[i].paramflags = PARAMFLAG_BOOL; - logparams_debug[i].uptr = NULL; - logparams_debug[i].chkPptr = NULL; - logparams_debug[i].numelt = 0; - logparams_dump[i].defuintval = 0; - logparams_dump[i].type = TYPE_UINT; - logparams_dump[i].paramflags = PARAMFLAG_BOOL; - logparams_dump[i].uptr = NULL; - logparams_dump[i].chkPptr = NULL; - logparams_dump[i].numelt = 0; + /* build then read the debug and dump parameter array */ + for (int i=0; log_maskmap[i].name != NULL ; i++) { + sprintf(logparams_debug[i].optname, LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name); + sprintf(logparams_dump[i].optname, LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name); + logparams_debug[i].defuintval = 0; + logparams_debug[i].type = TYPE_UINT; + logparams_debug[i].paramflags = PARAMFLAG_BOOL; + logparams_debug[i].uptr = NULL; + logparams_debug[i].chkPptr = NULL; + logparams_debug[i].numelt = 0; + logparams_dump[i].defuintval = 0; + logparams_dump[i].type = TYPE_UINT; + logparams_dump[i].paramflags = PARAMFLAG_BOOL; + logparams_dump[i].uptr = NULL; + logparams_dump[i].chkPptr = NULL; + logparams_dump[i].numelt = 0; } + config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); CONFIG_CLEARRTFLAG(CONFIG_NOCHECKUNKOPT); config_get( logparams_dump,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); -/* set the debug mask according to the debug parameters values */ + + /* set the debug mask according to the debug parameters values */ for (int i=0; log_maskmap[i].name != NULL ; i++) { if (*(logparams_debug[i].uptr) ) - g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value; + g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value; + if (*(logparams_dump[i].uptr) ) - g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value; - } -/* log globally enabled/disabled */ + g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value; + } + + /* log globally enabled/disabled */ set_glog_onlinelog(consolelog); } -int register_log_component(char *name, char *fext, int compidx) -{ -int computed_compidx=compidx; +int register_log_component(char *name, char *fext, int compidx) { + int computed_compidx=compidx; if (strlen(fext) > 3) { - fext[3]=0; /* limit log file extension to 3 chars */ + fext[3]=0; /* limit log file extension to 3 chars */ } + if (compidx < 0) { /* this is not a pre-defined component */ - for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) { - if (g_log->log_component[i].name == NULL) { - computed_compidx=i; - break; - } + for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) { + if (g_log->log_component[i].name == NULL) { + computed_compidx=i; + break; } + } } + if (computed_compidx >= 0 && computed_compidx log_component[computed_compidx].name = strdup(name); - g_log->log_component[computed_compidx].stream = stdout; - g_log->log_component[computed_compidx].filelog = 0; - g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/.%s */ - sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); + g_log->log_component[computed_compidx].name = strdup(name); + g_log->log_component[computed_compidx].stream = stdout; + g_log->log_component[computed_compidx].filelog = 0; + g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/.%s */ + sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); } else { - fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name); + fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name); } -return computed_compidx; + + return computed_compidx; } -int isLogInitDone (void){ - if (g_log == NULL) - return 0; - if (!(g_log->flag & FLAG_INITIALIZED)) - return 0; - return 1; +int isLogInitDone (void) { + if (g_log == NULL) + return 0; + + if (!(g_log->flag & FLAG_INITIALIZED)) + return 0; + + return 1; } -int logInit (void) -{ +int logInit (void) { int i; g_log = calloc(1, sizeof(log_t)); @@ -373,10 +369,8 @@ int logInit (void) perror ("cannot allocated memory for log generation module \n"); exit(EXIT_FAILURE); } - memset(g_log,0,sizeof(log_t)); - - + memset(g_log,0,sizeof(log_t)); register_log_component("PHY","log",PHY); register_log_component("MAC","log",MAC); register_log_component("OPT","log",OPT); @@ -392,144 +386,121 @@ int logInit (void) register_log_component("OTG_JITTER","dat",OTG_JITTER); register_log_component("OCG","",OCG); register_log_component("PERF","",PERF); - register_log_component("OIP","",OIP); - register_log_component("CLI","",CLI); - register_log_component("MSC","log",MSC); - register_log_component("OCM","log",OCM); - register_log_component("HW","",HW); - register_log_component("OSA","",OSA); - register_log_component("eRAL","",RAL_ENB); - register_log_component("mRAL","",RAL_UE); - register_log_component("ENB_APP","log",ENB_APP); - register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT); - register_log_component("TMR","",TMR); - register_log_component("USIM","txt",USIM); - register_log_component("SIM","txt",SIM); - + register_log_component("OIP","",OIP); + register_log_component("CLI","",CLI); + register_log_component("MSC","log",MSC); + register_log_component("OCM","log",OCM); + register_log_component("HW","",HW); + register_log_component("OSA","",OSA); + register_log_component("eRAL","",RAL_ENB); + register_log_component("mRAL","",RAL_UE); + register_log_component("ENB_APP","log",ENB_APP); + register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT); + register_log_component("TMR","",TMR); + register_log_component("USIM","txt",USIM); + register_log_component("SIM","txt",SIM); /* following log component are used for the localization*/ register_log_component("LOCALIZE","log",LOCALIZE); register_log_component("NAS","log",NAS); register_log_component("UDP","",UDP_); - - register_log_component("GTPV1U","",GTPU); - - register_log_component("S1AP","",S1AP); register_log_component("X2AP","",X2AP); - - register_log_component("SCTP","",SCTP); register_log_component("X2AP","",X2AP); register_log_component("LOADER","log",LOADER); register_log_component("ASN","log",ASN); - - for (int i=0 ; log_level_names[i].name != NULL ; i++) - g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name - - - - + g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name g_log->filelog_name = "/tmp/openair.log"; - log_getconfig(g_log); - - // set all unused component items to 0, they are for non predefined components for (i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); + memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); } + g_log->flag = g_log->flag | FLAG_INITIALIZED; printf("log init done\n"); - return 0; } char *log_getthreadname(char *threadname, int bufsize) { + int rt = pthread_getname_np(pthread_self(), threadname,bufsize) ; -int rt = pthread_getname_np(pthread_self(), threadname,bufsize) ; - if (rt == 0) - { - return threadname; - } else { - return "thread?"; - } + if (rt == 0) { + return threadname; + } else { + return "thread?"; + } } static int log_header(char *log_buffer, int buffsize, int comp, int level,const char *format) { char threadname[PR_SET_NAME]; -return snprintf(log_buffer, buffsize , "%s%s[%s]%c %s %s%s", - log_level_highlight_end[level], - ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]), - g_log->log_component[comp].name, - ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '), - ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""), - format, - log_level_highlight_end[level]); + return snprintf(log_buffer, buffsize , "%s%s[%s]%c %s %s%s", + log_level_highlight_end[level], + ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]), + g_log->log_component[comp].name, + ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '), + ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""), + format, + log_level_highlight_end[level]); } -void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char* format, ... ) - { +void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char *format, ... ) { char log_buffer[MAX_LOG_TOTAL]; va_list args; - va_start(args, format); - - - - log_header(log_buffer,MAX_LOG_TOTAL ,comp, level,format); g_log->log_component[comp].vprint(g_log->log_component[comp].stream,log_buffer, args); va_end(args); - - } -void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ) { -va_list args; -char *wbuf; +void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... ) { + va_list args; + char *wbuf; + switch(datatype) { + case LOG_DUMP_DOUBLE: + wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); + break; + + case LOG_DUMP_CHAR: + default: + wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL); + break; + } - switch(datatype) { - case LOG_DUMP_DOUBLE: - wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); - break; - case LOG_DUMP_CHAR: - default: - wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL); - break; + if (wbuf != NULL) { + va_start(args, format); + int pos=log_header(wbuf,MAX_LOG_TOTAL ,component, OAILOG_INFO,""); + int pos2=vsprintf(wbuf+pos,format, args); + pos=pos+pos2; + va_end(args); + + for (int i=0; ilog_component[component].print(g_log->log_component[component].stream,wbuf); free(wbuf); - } + } } -int set_log(int component, int level) -{ +int set_log(int component, int level) { /* Checking parameters */ DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS), component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS); @@ -537,38 +508,34 @@ int set_log(int component, int level) OAILOG_ERR); if ( g_log->log_component[component].level != OAILOG_DISABLE ) - g_log->log_component[component].savedlevel = g_log->log_component[component].level; - g_log->log_component[component].level = level; + g_log->log_component[component].savedlevel = g_log->log_component[component].level; + g_log->log_component[component].level = level; return 0; } -void set_glog(int level) -{ +void set_glog(int level) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { - set_log(c, level); + set_log(c, level); } - } -void set_glog_onlinelog(int enable) -{ +void set_glog_onlinelog(int enable) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { - if ( enable ) { - g_log->log_component[c].level = g_log->log_component[c].savedlevel; - g_log->log_component[c].vprint = vfprintf; - g_log->log_component[c].print = fprintf; - g_log->log_component[c].stream = stdout; - } else { - g_log->log_component[c].level = OAILOG_DISABLE; - } - } + if ( enable ) { + g_log->log_component[c].level = g_log->log_component[c].savedlevel; + g_log->log_component[c].vprint = vfprintf; + g_log->log_component[c].print = fprintf; + g_log->log_component[c].stream = stdout; + } else { + g_log->log_component[c].level = OAILOG_DISABLE; + } + } } -void set_glog_filelog(int enable) -{ -static FILE *fptr; +void set_glog_filelog(int enable) { + static FILE *fptr; if ( enable ) { fptr = fopen(g_log->filelog_name,"w"); @@ -581,33 +548,35 @@ static FILE *fptr; } else { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { g_log->log_component[c].filelog = 0; + if (fptr != NULL) { fclose(fptr); } + g_log->log_component[c].stream = stdout; - } - } + } + } } -void set_component_filelog(int comp) -{ - if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { - g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); - } - g_log->log_component[comp].vprint = vfprintf; - g_log->log_component[comp].print = fprintf; - g_log->log_component[comp].filelog = 1; +void set_component_filelog(int comp) { + if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { + g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); + } + + g_log->log_component[comp].vprint = vfprintf; + g_log->log_component[comp].print = fprintf; + g_log->log_component[comp].filelog = 1; } -void close_component_filelog(int comp) -{ - g_log->log_component[comp].filelog = 0; - if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) { - fclose(g_log->log_component[comp].stream); - g_log->log_component[comp].stream = stdout; - } - g_log->log_component[comp].vprint = vfprintf; - g_log->log_component[comp].print = fprintf; - +void close_component_filelog(int comp) { + g_log->log_component[comp].filelog = 0; + + if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) { + fclose(g_log->log_component[comp].stream); + g_log->log_component[comp].stream = stdout; + } + + g_log->log_component[comp].vprint = vfprintf; + g_log->log_component[comp].print = fprintf; } /* @@ -615,8 +584,7 @@ void close_component_filelog(int comp) * with string value NULL */ /* map a string to an int. Takes a mapping array and a string as arg */ -int map_str_to_int(mapping *map, const char *str) -{ +int map_str_to_int(mapping *map, const char *str) { while (1) { if (map->name == NULL) { return(-1); @@ -631,8 +599,7 @@ int map_str_to_int(mapping *map, const char *str) } /* map an int to a string. Takes a mapping array and a value */ -char *map_int_to_str(mapping *map, int val) -{ +char *map_int_to_str(mapping *map, int val) { while (1) { if (map->name == NULL) { return NULL; @@ -646,8 +613,7 @@ char *map_int_to_str(mapping *map, int val) } } -int is_newline( char *str, int size) -{ +int is_newline( char *str, int size) { int i; for ( i = 0; i < size; i++ ) { @@ -660,84 +626,65 @@ int is_newline( char *str, int size) return 0; } -void logClean (void) -{ +void logClean (void) { int i; if(isLogInitDone()) { LOG_UI(PHY,"\n"); + for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { close_component_filelog(i); } } } - -#ifdef LOG_TEST -int main(int argc, char *argv[]) -{ +#ifdef LOG_TEST +int main(int argc, char *argv[]) { logInit(); - - test_log(); - return 1; } -int test_log(void) -{ +int test_log(void) { LOG_ENTER(MAC); // because the default level is DEBUG LOG_I(EMU, "1 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "1 debug MAC \n"); LOG_W(MAC, "1 warning MAC \n"); - set_log(EMU, OAILOG_INFO); set_log(MAC, OAILOG_WARNING); - LOG_I(EMU, "2 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_E(MAC, "2 error MAC\n"); LOG_D(MAC, "2 debug MAC \n"); LOG_W(MAC, "2 warning MAC \n"); LOG_I(MAC, "2 info MAC \n"); - - set_log(MAC, OAILOG_NOTICE); - LOG_ENTER(MAC); LOG_I(EMU, "3 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "3 debug MAC \n"); LOG_W(MAC, "3 warning MAC \n"); LOG_I(MAC, "3 info MAC \n"); - set_log(MAC, LOG_DEBUG); set_log(EMU, LOG_DEBUG); - LOG_ENTER(MAC); LOG_I(EMU, "4 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "4 debug MAC \n"); LOG_W(MAC, "4 warning MAC \n"); LOG_I(MAC, "4 info MAC \n"); - - set_log(MAC, LOG_DEBUG); set_log(EMU, LOG_DEBUG); - LOG_I(LOG, "5 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "5 debug MAC \n"); LOG_W(MAC, "5 warning MAC \n"); LOG_I(MAC, "5 info MAC \n"); - - set_log(MAC, LOG_TRACE); set_log(EMU, LOG_TRACE); - LOG_ENTER(MAC); LOG_I(LOG, "6 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); @@ -745,7 +692,6 @@ int test_log(void) LOG_W(MAC, "6 warning MAC \n"); LOG_I(MAC, "6 info MAC \n"); LOG_EXIT(MAC); - return 0; } #endif diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index 2a7a51a0a6..d0aa4a47c8 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -45,11 +45,11 @@ #include #include #ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS + #define __STDC_FORMAT_MACROS #endif #include #ifndef _GNU_SOURCE -#define _GNU_SOURCE + #define _GNU_SOURCE #endif #include #include "T.h" @@ -126,11 +126,11 @@ extern "C" { /** @defgroup macros to identify a debug entity * @ingroup each macro is a bit mask where the unique bit set identifies an entity to be debugged - * it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro + * it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro * is used to map a character string name to each debug bit, it allows to set or clear * the corresponding bit via the defined name, from the configuration or from the telnet * server. - * @brief + * @brief * @{*/ #define DEBUG_PRACH (1<<0) #define DEBUG_RU (1<<1) @@ -149,22 +149,22 @@ extern "C" { #define LOG_MASKMAP_INIT {\ - {"PRACH", DEBUG_PRACH},\ - {"RU", DEBUG_RU},\ - {"UE_PHYPROC", DEBUG_UE_PHYPROC},\ - {"LTEESTIM", DEBUG_LTEESTIM},\ - {"DLCELLSPEC", DEBUG_DLCELLSPEC},\ - {"ULSCH", DEBUG_ULSCH},\ - {"RRC", DEBUG_RRC},\ - {"PDCP", DEBUG_PDCP},\ - {"DFT", DEBUG_DFT},\ - {"ASN1", DEBUG_ASN1},\ - {"CTRLSOCKET", DEBUG_CTRLSOCKET},\ - {"SECURITY", DEBUG_SECURITY},\ - {"NAS", DEBUG_NAS},\ - {"UE_TIMING", UE_TIMING},\ - {NULL,-1}\ -} + {"PRACH", DEBUG_PRACH},\ + {"RU", DEBUG_RU},\ + {"UE_PHYPROC", DEBUG_UE_PHYPROC},\ + {"LTEESTIM", DEBUG_LTEESTIM},\ + {"DLCELLSPEC", DEBUG_DLCELLSPEC},\ + {"ULSCH", DEBUG_ULSCH},\ + {"RRC", DEBUG_RRC},\ + {"PDCP", DEBUG_PDCP},\ + {"DFT", DEBUG_DFT},\ + {"ASN1", DEBUG_ASN1},\ + {"CTRLSOCKET", DEBUG_CTRLSOCKET},\ + {"SECURITY", DEBUG_SECURITY},\ + {"NAS", DEBUG_NAS},\ + {"UE_TIMING", UE_TIMING},\ + {NULL,-1}\ + } @@ -177,46 +177,46 @@ extern "C" { typedef enum { - MIN_LOG_COMPONENTS = 0, - PHY = MIN_LOG_COMPONENTS, - MAC, - SIM, - OCG, - OMG, - OPT, - OTG, - OTG_LATENCY, - OTG_LATENCY_BG, - OTG_GP, - OTG_GP_BG, - OTG_JITTER, - RLC, - PDCP, - RRC, - NAS, - PERF, - OIP, - CLI, - MSC, - OCM, - UDP_, - GTPU, - SPGW, - S1AP, - SCTP, - HW, - OSA, - RAL_ENB, - RAL_UE, - ENB_APP, - FLEXRAN_AGENT, - TMR, - USIM, - LOCALIZE, - X2AP, - LOADER, - ASN, - MAX_LOG_PREDEF_COMPONENTS, + MIN_LOG_COMPONENTS = 0, + PHY = MIN_LOG_COMPONENTS, + MAC, + SIM, + OCG, + OMG, + OPT, + OTG, + OTG_LATENCY, + OTG_LATENCY_BG, + OTG_GP, + OTG_GP_BG, + OTG_JITTER, + RLC, + PDCP, + RRC, + NAS, + PERF, + OIP, + CLI, + MSC, + OCM, + UDP_, + GTPU, + SPGW, + S1AP, + SCTP, + HW, + OSA, + RAL_ENB, + RAL_UE, + ENB_APP, + FLEXRAN_AGENT, + TMR, + USIM, + LOCALIZE, + X2AP, + LOADER, + ASN, + MAX_LOG_PREDEF_COMPONENTS, } comp_name_t; @@ -225,42 +225,42 @@ comp_name_t; typedef struct { - char *name; /*!< \brief string name of item */ - int value; /*!< \brief integer value of mapping */ + char *name; /*!< \brief string name of item */ + int value; /*!< \brief integer value of mapping */ } mapping; typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap ); typedef int(*log_print_func_t)(FILE *stream, const char *format, ... ); typedef struct { - const char *name; - int level; - int savedlevel; - int flag; - int filelog; - char *filelog_name; - FILE *stream; - log_vprint_func_t vprint; - log_print_func_t print; - /* SR: make the log buffer component relative */ - char log_buffer[MAX_LOG_TOTAL]; + const char *name; + int level; + int savedlevel; + int flag; + int filelog; + char *filelog_name; + FILE *stream; + log_vprint_func_t vprint; + log_print_func_t print; + /* SR: make the log buffer component relative */ + char log_buffer[MAX_LOG_TOTAL]; } log_component_t; typedef struct { - log_component_t log_component[MAX_LOG_COMPONENTS]; - char level2string[NUM_LOG_LEVEL]; - int flag; - char* filelog_name; - uint64_t debug_mask; - uint64_t dump_mask; + log_component_t log_component[MAX_LOG_COMPONENTS]; + char level2string[NUM_LOG_LEVEL]; + int flag; + char *filelog_name; + uint64_t debug_mask; + uint64_t dump_mask; } log_t; #if defined(ENABLE_ITTI) typedef enum log_instance_type_e { - LOG_INSTANCE_UNKNOWN, - LOG_INSTANCE_ENB, - LOG_INSTANCE_UE, + LOG_INSTANCE_UNKNOWN, + LOG_INSTANCE_ENB, + LOG_INSTANCE_UE, } log_instance_type_t; void log_set_instance_type (log_instance_type_t instance); @@ -271,9 +271,9 @@ void log_set_instance_type (log_instance_type_t instance); log_t *g_log; #else #ifdef __cplusplus - extern "C" { +extern "C" { #endif -extern log_t *g_log; + extern log_t *g_log; #ifdef __cplusplus } #endif @@ -284,7 +284,7 @@ extern log_t *g_log; int logInit (void); int isLogInitDone (void); void logRecord_mt(const char *file, const char *func, int line,int comp, int level, const char *format, ...) __attribute__ ((format (printf, 6, 7))); -void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ); +void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... ); int set_log(int component, int level); void set_glog(int level); @@ -327,22 +327,22 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int #define LOG_CONFIG_DUMP_FORMAT "%s_dump" #define LOG_CONFIG_HELP_OPTIONS " list of comma separated options to enable log module behavior. Available options: \n"\ - " nocolor: disable color usage in log messages\n"\ - " level: add log level indication in log messages\n"\ - " thread: add threads names in log messages\n" - + " nocolor: disable color usage in log messages\n"\ + " level: add log level indication in log messages\n"\ + " thread: add threads names in log messages\n" + + - /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* LOG globalconfiguration parameters */ -/* optname help paramflags XXXptr defXXXval type numelt */ +/* LOG globalconfiguration parameters */ +/* optname help paramflags XXXptr defXXXval type numelt */ /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ #define LOG_GLOBALPARAMS_DESC { \ -{LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0, strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \ -{LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0, iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \ -{LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0, strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \ -} + {LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0, strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \ + {LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0, iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \ + {LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0, strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \ + } #define LOG_OPTIONS_IDX 2 /*----------------------------------------------------------------------------------*/ @@ -354,23 +354,23 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int #define LOG_DUMP_DOUBLE 1 // debugging macros #define LOG_F LOG_I /* because LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */ -# if T_TRACER - /* per component, level dependant macros */ -# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0) -# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) -# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0) -# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0) -# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0) - /* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */ +# if T_TRACER +/* per component, level dependant macros */ +# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0) +# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) +# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0) +# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0) +# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0) +/* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */ # define LOG_DUMPMSG(c, f, b, s, x...) do { if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x) ;} while (0) /* */ # define nfapi_log(FILE, FNC, LN, COMP, LVL, F...) do { if (T_stdout) { logRecord_mt(__FILE__, __FUNCTION__, __LINE__,COMP, LVL, F) ;}} while (0) /* */ - /* bitmask dependant macros, to isolate debugging code */ +/* bitmask dependant macros, to isolate debugging code */ # define LOG_DEBUGFLAG(D) (g_log->debug_mask & D) - /* bitmask dependant macros, to generate debug file such as matlab file or message dump */ +/* bitmask dependant macros, to generate debug file such as matlab file or message dump */ # define LOG_DUMPFLAG(D) (g_log->dump_mask & D) # define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)/* */ - /* define variable only used in LOG macro's */ +/* define variable only used in LOG macro's */ # define LOG_VAR(A,B) A B # else /* T_TRACER: remove all debugging and tracing messages, except errors */ # define LOG_I(c, x...) /* */ @@ -380,15 +380,15 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int # define LOG_T(c, x...) /* */ # define LOG_DUMPMSG(c, b, s, x...) /* */ -# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) +# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) # define LOG_DEBUGFLAG(D) ( 0 ) -# define LOG_DUMPFLAG(D) ( 0 ) -# define LOG_M(file, vector, data, len, dec, format) +# define LOG_DUMPFLAG(D) ( 0 ) +# define LOG_M(file, vector, data, len, dec, format) # define LOG_VAR(A,B) # endif /* T_TRACER */ /* avoid warnings for variables only used in LOG macro's but set outside debug section */ -#define GCC_NOTUSED __attribute__((unused)) -#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B +#define GCC_NOTUSED __attribute__((unused)) +#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B /* unfiltered macros, usefull for simulators or messages at init time, before log is configured */ #define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0) @@ -420,78 +420,82 @@ static __inline__ uint64_t rdtsc(void) { extern double cpuf; -static inline uint64_t checkTCPU(int timeout, char * file, int line) { - static uint64_t __thread lastCPUTime=0; - static uint64_t __thread last=0; - uint64_t cur=rdtsc(); - struct timespec CPUt; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt); - uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000; - double microCycles=(double)(cpuf*1000); - int duration=(int)((cur-last)/microCycles); - if ( last!=0 && duration > timeout ) { - //struct timespec ts; - //clock_gettime(CLOCK_MONOTONIC, &ts); - printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line, - duration, timeout, (long long)CPUTime-lastCPUTime ); - } - last=cur; - lastCPUTime=CPUTime; - return cur; +static inline uint64_t checkTCPU(int timeout, char *file, int line) { + static uint64_t __thread lastCPUTime=0; + static uint64_t __thread last=0; + uint64_t cur=rdtsc(); + struct timespec CPUt; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt); + uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000; + double microCycles=(double)(cpuf*1000); + int duration=(int)((cur-last)/microCycles); + + if ( last!=0 && duration > timeout ) { + //struct timespec ts; + //clock_gettime(CLOCK_MONOTONIC, &ts); + printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line, + duration, timeout, (long long)CPUTime-lastCPUTime ); + } + + last=cur; + lastCPUTime=CPUTime; + return cur; } -static inline unsigned long long checkT(int timeout, char * file, int line) { - static unsigned long long __thread last=0; - unsigned long long cur=rdtsc(); - int microCycles=(int)(cpuf*1000); - int duration=(int)((cur-last)/microCycles); - if ( last!=0 && duration > timeout ) - printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line, - duration, timeout); - last=cur; - return cur; +static inline unsigned long long checkT(int timeout, char *file, int line) { + static unsigned long long __thread last=0; + unsigned long long cur=rdtsc(); + int microCycles=(int)(cpuf*1000); + int duration=(int)((cur-last)/microCycles); + + if ( last!=0 && duration > timeout ) + printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line, + duration, timeout); + + last=cur; + return cur; } typedef struct m { - uint64_t iterations; - uint64_t sum; - uint64_t maxArray[11]; + uint64_t iterations; + uint64_t sum; + uint64_t maxArray[11]; } Meas; -static inline void printMeas(char * txt, Meas *M, int period) { - if (M->iterations%period == 0 ) { - char txt2[512]; - sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%" - PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n", - txt, - M->sum/M->iterations, - M->iterations, - M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5], - M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]); +static inline void printMeas(char *txt, Meas *M, int period) { + if (M->iterations%period == 0 ) { + char txt2[512]; + sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%" + PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n", + txt, + M->sum/M->iterations, + M->iterations, + M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5], + M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]); #if DISABLE_LOG_X - printf("%s",txt2); + printf("%s",txt2); #else - LOG_W(PHY, "%s",txt2); + LOG_W(PHY, "%s",txt2); #endif - } + } } -static inline int cmpint(const void* a, const void* b) { - uint64_t* aa=(uint64_t*)a; - uint64_t* bb=(uint64_t*)b; - return (int)(*aa-*bb); +static inline int cmpint(const void *a, const void *b) { + uint64_t *aa=(uint64_t *)a; + uint64_t *bb=(uint64_t *)b; + return (int)(*aa-*bb); } -static inline void updateTimes(uint64_t start, Meas *M, int period, char * txt) { - if (start!=0) { - uint64_t end=rdtsc(); - long long diff=(end-start)/(cpuf*1000); - M->maxArray[0]=diff; - M->sum+=diff; - M->iterations++; - qsort(M->maxArray, 11, sizeof(uint64_t), cmpint); - printMeas(txt,M,period); - } +static inline void updateTimes(uint64_t start, Meas *M, int period, char *txt) { + if (start!=0) { + uint64_t end=rdtsc(); + long long diff=(end-start)/(cpuf*1000); + M->maxArray[0]=diff; + M->sum+=diff; + M->iterations++; + qsort(M->maxArray, 11, sizeof(uint64_t), cmpint); + printMeas(txt,M,period); + } } #define check(a) do { checkT(a,__FILE__,__LINE__); } while (0) diff --git a/common/utils/T/genids.c b/common/utils/T/genids.c index 112fe9de5a..a130988262 100644 --- a/common/utils/T/genids.c +++ b/common/utils/T/genids.c @@ -8,27 +8,35 @@ char **unique_ids; int unique_ids_size; int unique_ids_maxsize; -int cmp(const void *p1, const void *p2) -{ - return strcmp(*(char * const *)p1, *(char * const *)p2); +int cmp(const void *p1, const void *p2) { + return strcmp(*(char *const *)p1, *(char *const *)p2); } /* return 1 if s was not already known, 0 if it was */ -int new_unique_id(char *s, char *input_file) -{ +int new_unique_id(char *s, char *input_file) { if (unique_ids_size) - if (bsearch(&s, unique_ids, unique_ids_size, sizeof(char *), cmp) != NULL) { - printf("error: ID %s is not unique in %s\n", s, input_file); - return 0; - } + if (bsearch(&s, unique_ids, unique_ids_size, sizeof(char *), cmp) != NULL) { + printf("error: ID %s is not unique in %s\n", s, input_file); + return 0; + } + if (unique_ids_size == unique_ids_maxsize) { unique_ids_maxsize += 256; unique_ids = realloc(unique_ids, unique_ids_maxsize * sizeof(char *)); - if (unique_ids == NULL) { printf("error: out of memory\n"); abort(); } + + if (unique_ids == NULL) { + printf("error: out of memory\n"); + abort(); + } } + unique_ids[unique_ids_size] = strdup(s); - if (unique_ids[unique_ids_size] == NULL) - { printf("error: out of memory\n"); abort(); } + + if (unique_ids[unique_ids_size] == NULL) { + printf("error: out of memory\n"); + abort(); + } + unique_ids_size++; qsort(unique_ids, unique_ids_size, sizeof(char *), cmp); return 1; @@ -38,14 +46,17 @@ char *bufname; int bufname_size; int bufname_maxsize; -void putname(int c) -{ +void putname(int c) { if (bufname_size == bufname_maxsize) { bufname_maxsize += 256; bufname = realloc(bufname, bufname_maxsize); - if (bufname == NULL) - { printf("error: memory allocation error\n"); exit(1); } + + if (bufname == NULL) { + printf("error: memory allocation error\n"); + exit(1); + } } + bufname[bufname_size] = c; bufname_size++; } @@ -54,42 +65,54 @@ char *bufvalue; int bufvalue_size; int bufvalue_maxsize; -void putvalue(int c) -{ +void putvalue(int c) { if (bufvalue_size == bufvalue_maxsize) { bufvalue_maxsize += 256; bufvalue = realloc(bufvalue, bufvalue_maxsize); - if (bufvalue == NULL) - { printf("error: memory allocation error\n"); exit(1); } + + if (bufvalue == NULL) { + printf("error: memory allocation error\n"); + exit(1); + } } + bufvalue[bufvalue_size] = c; bufvalue_size++; } -void smash_spaces(FILE *f) -{ +void smash_spaces(FILE *f) { int c; + while (1) { c = fgetc(f); + if (isspace(c)) continue; + if (c == ' ') continue; + if (c == '\t') continue; + if (c == '\n') continue; + if (c == 10 || c == 13) continue; + if (c == '#') { while (1) { c = fgetc(f); + if (c == '\n' || c == EOF) break; } + continue; } + break; } + if (c != EOF) ungetc(c, f); } -void get_line(FILE *f, char **name, char **value) -{ +void get_line(FILE *f, char **name, char **value) { int c; bufname_size = 0; bufvalue_size = 0; @@ -97,23 +120,39 @@ void get_line(FILE *f, char **name, char **value) *value = NULL; smash_spaces(f); c = fgetc(f); - while (!(c == '=' || isspace(c) || c == EOF)) { putname(c); c = fgetc(f); } + + while (!(c == '=' || isspace(c) || c == EOF)) { + putname(c); + c = fgetc(f); + } + if (c == EOF) return; + putname(0); + while (!(c == EOF || c == '=')) c = fgetc(f); + if (c == EOF) return; + smash_spaces(f); c = fgetc(f); - while (!(c == 10 || c == 13 || c == EOF)) { putvalue(c); c = fgetc(f); } + + while (!(c == 10 || c == 13 || c == EOF)) { + putvalue(c); + c = fgetc(f); + } + putvalue(0); + if (bufname_size <= 1) return; + if (bufvalue_size <= 1) return; + *name = bufname; *value = bufvalue; } -int main(int n, char **v) -{ +int main(int n, char **v) { FILE *in; FILE *out; char *name; @@ -121,36 +160,54 @@ int main(int n, char **v) char *in_name; char *out_name; - if (n != 3) { printf("error: gimme \n"); exit(1); } + if (n != 3) { + printf("error: gimme \n"); + exit(1); + } n = 0; - in_name = v[1]; out_name = v[2]; + in = fopen(in_name, "r"); + + if (in == NULL) { + perror(in_name); + exit(1); + } - in = fopen(in_name, "r"); if (in == NULL) { perror(in_name); exit(1); } - out = fopen(out_name, "w"); if (out == NULL) { perror(out_name); exit(1); } + out = fopen(out_name, "w"); + + if (out == NULL) { + perror(out_name); + exit(1); + } fprintf(out, "/* generated file, do not edit by hand */\n\n"); while (1) { get_line(in, &name, &value); + if (name == NULL) break; + if (isspace(value[strlen(value)-1])) { printf("error: bad value '%s' (no space at the end please!)\n", value); unlink(out_name); exit(1); } + if (!strcmp(name, "ID")) { - if (!new_unique_id(value, in_name)) { unlink(out_name); exit(1); } + if (!new_unique_id(value, in_name)) { + unlink(out_name); + exit(1); + } + fprintf(out, "#define T_%s T_ID(%d)\n", value, n); n++; } } - fprintf(out, "#define T_NUMBER_OF_IDS %d\n", n); + fprintf(out, "#define T_NUMBER_OF_IDS %d\n", n); fclose(in); fclose(out); - return 0; } -- GitLab