2014-07-20 19:34:14 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
|
2014-09-06 07:56:53 +02:00
|
|
|
#include <uci.h>
|
|
|
|
|
2014-07-20 19:34:14 +02:00
|
|
|
#include "capwap/capwap.h"
|
|
|
|
#include "capwap/cw_log.h"
|
|
|
|
#include "wtp_conf.h"
|
|
|
|
|
2014-09-06 07:56:53 +02:00
|
|
|
#include "capwap/cw_log.h"
|
2014-07-20 19:34:14 +02:00
|
|
|
|
2015-02-01 16:55:45 +01:00
|
|
|
#include "capwap/bstr.h"
|
|
|
|
|
2014-07-20 19:34:14 +02:00
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
static struct uci_section * get_anon_section(struct uci_package * pkg, const char *type)
|
2014-07-20 21:51:45 +02:00
|
|
|
{
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
struct uci_element * e;
|
|
|
|
struct uci_list * l = &pkg->sections;
|
|
|
|
|
|
|
|
uci_foreach_element(l,e){
|
|
|
|
struct uci_section *s = (struct uci_section*)e;
|
|
|
|
if (!s->anonymous)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(s->type,type)==0){
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
2014-07-20 21:51:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-03 08:17:01 +01:00
|
|
|
static void set_dbg_opt(struct uci_context *ctx,struct uci_section * section,int opt,const char * optstr)
|
|
|
|
{
|
|
|
|
const char *str = uci_lookup_option_string(ctx,section,optstr);
|
|
|
|
if (!str)
|
|
|
|
return;
|
|
|
|
if ((strcmp(str,"1")==0) || (strcmp(str,"true")==0))
|
|
|
|
conf_dbg_level |= opt;
|
|
|
|
|
|
|
|
if ((strcmp(str,"0")==0) || (strcmp(str,"false")==0))
|
|
|
|
conf_dbg_level &= ((-1)^opt);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void read_dbg_options(struct uci_context *ctx, struct uci_section *section)
|
|
|
|
{
|
|
|
|
|
2015-02-08 13:33:30 +01:00
|
|
|
int i;
|
|
|
|
for (i=0; cw_dbg_cfgstrs[i].name; i++) {
|
|
|
|
set_dbg_opt(ctx,section,cw_dbg_cfgstrs[i].level,cw_dbg_cfgstrs[i].name);
|
|
|
|
|
|
|
|
}
|
2015-02-08 21:07:55 +01:00
|
|
|
}
|
2015-02-08 13:33:30 +01:00
|
|
|
|
2015-02-08 21:07:55 +01:00
|
|
|
static void read_timers(struct uci_context *ctx,struct uci_section *section)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; conf_timer_cfgstrs[i].name; i++) {
|
|
|
|
|
|
|
|
const char *str = uci_lookup_option_string(ctx,section,conf_timer_cfgstrs[i].name);
|
|
|
|
if ( str ) {
|
|
|
|
*(conf_timer_cfgstrs[i].value)=atol(str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-02-08 13:33:30 +01:00
|
|
|
|
2015-02-03 08:17:01 +01:00
|
|
|
}
|
2014-07-20 21:51:45 +02:00
|
|
|
|
2014-07-20 19:34:14 +02:00
|
|
|
int read_config(const char * filename){
|
|
|
|
|
2014-09-06 10:54:58 +02:00
|
|
|
|
2014-07-20 19:34:14 +02:00
|
|
|
struct uci_context * ctx;
|
|
|
|
|
|
|
|
ctx = uci_alloc_context();
|
|
|
|
if (!ctx){
|
|
|
|
cw_log(LOG_ERR,"Fatal: Can't create uci ctx, can't read config file");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct uci_package * pkg;
|
2014-07-22 07:11:57 +02:00
|
|
|
|
|
|
|
if (filename == NULL){
|
2015-01-18 20:59:55 +01:00
|
|
|
filename = "wtp_uci.conf";
|
2014-07-22 07:11:57 +02:00
|
|
|
}
|
2014-09-06 10:54:58 +02:00
|
|
|
cw_dbg(DBG_ALL,"Reading config file %s",filename);
|
2014-07-22 07:11:57 +02:00
|
|
|
|
2014-07-20 21:51:45 +02:00
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
int rc = uci_load(ctx, filename, &pkg );
|
|
|
|
|
|
|
|
if (rc == UCI_ERR_NOTFOUND){
|
2014-09-06 07:56:53 +02:00
|
|
|
cw_dbg(DBG_CW_INFO,"Config file '%s' not found, running without config",filename);
|
2014-07-22 07:11:57 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2014-07-20 19:34:14 +02:00
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
char * errstr;
|
|
|
|
uci_get_errorstr(ctx, &errstr, "");
|
|
|
|
cw_log(LOG_ERR,"Fatal: Can't read config file: %s",errstr);
|
2014-07-22 07:11:57 +02:00
|
|
|
return 0;
|
|
|
|
|
2014-07-20 19:34:14 +02:00
|
|
|
}
|
2014-07-20 21:51:45 +02:00
|
|
|
|
2015-02-03 08:17:01 +01:00
|
|
|
|
|
|
|
struct uci_section * section;
|
|
|
|
|
|
|
|
section = get_anon_section(pkg,"dbg");
|
|
|
|
read_dbg_options(ctx,section);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
section = get_anon_section(pkg,"wtp");
|
2014-07-20 19:34:14 +02:00
|
|
|
if (!section) {
|
2015-02-01 16:55:45 +01:00
|
|
|
cw_dbg(DBG_CW_INFO,"No 'wtp' section found, running without config");
|
2014-07-22 07:11:57 +02:00
|
|
|
return 1;
|
2014-07-20 19:34:14 +02:00
|
|
|
}
|
2014-07-20 21:51:45 +02:00
|
|
|
|
2015-02-08 21:07:55 +01:00
|
|
|
read_timers(ctx,section);
|
2014-07-20 21:51:45 +02:00
|
|
|
|
|
|
|
const char *str;
|
|
|
|
str = uci_lookup_option_string(ctx,section,"name");
|
2015-01-18 20:33:35 +01:00
|
|
|
if (str)
|
|
|
|
conf_wtpname = strdup(str);
|
2014-07-20 19:34:14 +02:00
|
|
|
|
2015-01-18 20:33:35 +01:00
|
|
|
str = uci_lookup_option_string(ctx,section,"mtu");
|
2015-01-18 20:59:55 +01:00
|
|
|
if (str)
|
2015-01-18 20:33:35 +01:00
|
|
|
conf_mtu = atoi(str);
|
2015-01-18 20:59:55 +01:00
|
|
|
|
|
|
|
str = uci_lookup_option_string(ctx,section,"mtu_discovery");
|
|
|
|
if (str)
|
|
|
|
conf_mtu_discovery = atoi(str);
|
2015-02-01 16:55:45 +01:00
|
|
|
|
|
|
|
str = uci_lookup_option_string(ctx,section,"ssl_key");
|
|
|
|
if (str)
|
|
|
|
conf_sslkeyfilename=strdup(str);
|
|
|
|
|
|
|
|
str = uci_lookup_option_string(ctx,section,"ssl_cert");
|
|
|
|
if (str)
|
|
|
|
conf_sslcertfilename=strdup(str);
|
|
|
|
|
2015-03-12 23:21:57 +01:00
|
|
|
|
|
|
|
str = uci_lookup_option_string(ctx,section,"ssl_cipher");
|
|
|
|
if (str)
|
|
|
|
conf_dtls_cipher=strdup(str);
|
|
|
|
|
|
|
|
|
2015-02-01 16:55:45 +01:00
|
|
|
str = uci_lookup_option_string(ctx,section,"vendor_id");
|
|
|
|
if (str)
|
|
|
|
conf_vendor_id=atoi(str);
|
|
|
|
|
|
|
|
str = uci_lookup_option_string(ctx,section,"software_version");
|
|
|
|
if (str){
|
|
|
|
uint8_t * s = bstr_create_from_cfgstr(str);
|
|
|
|
bstr_replace(&conf_software_version,s);
|
|
|
|
}
|
|
|
|
|
2015-03-14 10:15:12 +01:00
|
|
|
str = uci_lookup_option_string(ctx,section,"hardware_version");
|
|
|
|
if (str){
|
|
|
|
uint8_t * s = bstr_create_from_cfgstr(str);
|
|
|
|
bstr_replace(&conf_hardware_version,s);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = uci_lookup_option_string(ctx,section,"bootloader_version");
|
|
|
|
if (str){
|
|
|
|
uint8_t * s = bstr_create_from_cfgstr(str);
|
|
|
|
bstr_replace(&conf_bootloader_version,s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-14 21:41:50 +01:00
|
|
|
str = uci_lookup_option_string(ctx,section,"board_id");
|
|
|
|
if (str){
|
|
|
|
uint8_t * s = bstr_create_from_cfgstr(str);
|
|
|
|
bstr_replace(&conf_board_id,s);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = uci_lookup_option_string(ctx,section,"board_revision");
|
|
|
|
if (str){
|
|
|
|
uint8_t * s = bstr_create_from_cfgstr(str);
|
|
|
|
bstr_replace(&conf_board_revision,s);
|
|
|
|
}
|
|
|
|
|
2015-03-14 10:15:12 +01:00
|
|
|
|
2015-03-12 23:21:57 +01:00
|
|
|
str = uci_lookup_option_string(ctx,section,"serial_no");
|
|
|
|
if (str){
|
|
|
|
uint8_t * s = bstr_create_from_cfgstr(str);
|
|
|
|
bstr_replace(&conf_serial_no,s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-01 16:55:45 +01:00
|
|
|
str = uci_lookup_option_string(ctx,section,"model_no");
|
|
|
|
if (str){
|
|
|
|
uint8_t * s = bstr_create_from_cfgstr(str);
|
|
|
|
bstr_replace(&conf_model_no,s);
|
|
|
|
}
|
|
|
|
|
2014-07-20 19:34:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|