diff --git a/src/wtp/wtp_conf_uci.c b/src/wtp/wtp_conf_uci.c new file mode 100644 index 00000000..314881fb --- /dev/null +++ b/src/wtp/wtp_conf_uci.c @@ -0,0 +1,313 @@ + +#include +#include + +#include +#include +#include +#include +#include + + +#include "capwap/capwap.h" +#include "capwap/cw_log.h" +#include "wtp_conf.h" + + +#include + + + +int read_config(const char * filename){ + + 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; + + int rc = uci_load(ctx, "./wtpconf", &pkg ); + + if (rc) { + char * errstr; + uci_get_errorstr(ctx, &errstr, ""); + cw_log(LOG_ERR,"Fatal: Can't read config file: %s",errstr); + } + + struct uci_section * section; + section = uci_lookup_section(ctx,pkg,"wtp"); + if (!section) { + goto errX; + } + + +// struct uci_ptr * result; +// char str[123] = "@wtp[0].name"; +// rc = uci_lookup_ptr(ctx,&result,str,0); + + + printf ("RC = %d\n",rc); + + +// int rc = uci_load(&ctx, "wtp"); + char * errstr; + + return 0; + +errX: + uci_get_errorstr(ctx, &errstr, "Can't read config"); + cw_log(LOG_ERR,"Fatal: %s",errstr); + return 0; + +} + + + + + +/* +char * conf_primary_if=0; +char * conf_wtpname=0; +char * conf_dtls_psk=0; +char * conf_preferred_ac=0; +char * conf_dtls_cipher=0; + + +struct sockaddr_storage * conf_preferred_ac_sa=0; + + +char ** conf_ac_list; +int conf_ac_list_len; +char * conf_control_port=0; +uint8_t conf_macaddress[12]; +uint8_t conf_macaddress_len=0; + +long conf_max_discovery_interval=CONF_DEFAULT_MAX_DISCOVERY_INTERVAL; +long conf_discovery_interval=CONF_DEFAULT_DISCOVERY_INTERVAL; +long conf_silent_interval=CONF_DEFAULT_SILENT_INTERVAL; +long conf_max_discoveries=CONF_DEFAULT_MAX_DISCOVERIES; +long conf_echo_interval=CONF_DEFAULT_ECHO_INTERVAL; +long conf_max_retransmit=CONF_DEFAULT_MAX_RETRANSMIT; +long conf_retransmit_interval=CONF_DEFAULT_RETRANSMIT_INTERVAL; + +long conf_debug_level=CONF_DEFAULT_DEBUG_LEVEL; + + +int wtpconf_init() +{ + + + if (conf_preferred_ac){ + conf_preferred_ac_sa=malloc(sizeof(struct sockaddr_storage)); + if (sock_strtoaddr(conf_preferred_ac,conf_preferred_ac_sa)!=1) + { + cw_log(LOG_ERR,"Preferred AC, invalid address: %s",conf_preferred_ac); + free(conf_preferred_ac_sa); + conf_preferred_ac_sa=0; + } + else{ + if (sock_getport(conf_preferred_ac_sa)==0){ + sock_setport(conf_preferred_ac_sa,conf_control_port); + } + } + if (conf_preferred_ac_sa!=0){ + char str[100]; + sock_addrtostr(conf_preferred_ac_sa,str,100); + cw_log(LOG_INFO,"Preferred AC: %s\n",str); + } + } + +} + +#include + +char * get_prim(int family) +{ + struct ifaddrs *ifap,*ifa; + char * r = 0; + + getifaddrs(&ifap); + + for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_flags & IFF_LOOPBACK){ + continue; + } + + if (ifa->ifa_addr->sa_family != family) + continue; + + r = malloc(strlen(ifa->ifa_name)+1); + if (r) + strcpy(r,ifa->ifa_name); + break; + + } + freeifaddrs(ifap); + return r; +} + + +wtpconf_primary_if() +{ + if (!conf_primary_if){ + +#ifdef WITH_IPV6 + conf_primary_if = get_prim(AF_INET6); + if (!conf_primary_if) + conf_primary_if = get_prim(AF_INET); +#else + conf_primary_if = get_prim(AF_INET); +#endif + if (!conf_primary_if){ + cw_log(LOG_ERR,"Fatal: Unable to detect primary interface"); + return 0; + } + + } + if (!sock_getifhwaddr(conf_primary_if,conf_macaddress,&conf_macaddress_len)){ + cw_log(LOG_ERR,"Fatal: Unable to detect link layer address for %s\n",conf_primary_if); + return 0; + }; + +#ifdef WITH_CW_LOG_DEBUG + char str[128]; + sock_hwaddrtostr(conf_macaddress,conf_macaddress_len,str); + cw_log_debug0("Using primary interface: %s",conf_primary_if); + cw_log_debug0("Using primary mac address: %s",str); +#endif + return 1; +} + + + +char * default_ac_list[] = { + "255.255.255.255", + "224.0.1.140", +}; + +wtpconf_ac_list() +{ + if (conf_ac_list) + return 1; + + int i; + int len=0; + int bcrc; + struct sockaddr_storage bcaddr; + + bcrc = sock_getifaddr(conf_primary_if,AF_INET,IFF_BROADCAST,&bcaddr); + if (bcrc) + len++; + + int deflen = sizeof(default_ac_list)/sizeof(char*); + + len += deflen; + conf_ac_list = malloc(len*sizeof(char*)); + if (!conf_ac_list) + return 0; + + for (i=0; i0) + { + conf_ac_list=malloc(sizeof(char*)*n); + if (!conf_ac_list) + goto errX; + + conf_ac_list_len=0; + for (i=0; i