2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2014-07-22 07:11:57 +02:00
|
|
|
#include <stdio.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2014-07-22 07:11:57 +02:00
|
|
|
//#include <confuse.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "capwap/capwap.h"
|
|
|
|
#include "capwap/cw_log.h"
|
2014-07-22 07:11:57 +02:00
|
|
|
#include "capwap/cw_util.h"
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "wtp_conf.h"
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
|
|
|
|
#include "capwap/sock.h"
|
2014-09-14 22:46:14 +02:00
|
|
|
#include "capwap/cw_log.h"
|
|
|
|
|
2015-03-12 23:21:57 +01:00
|
|
|
#include "capwap/bstr.h"
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
char * conf_primary_if=0;
|
|
|
|
char * conf_wtpname=0;
|
|
|
|
char * conf_dtls_psk=0;
|
2014-08-02 10:54:41 +02:00
|
|
|
char * conf_sslkeyfilename=0;
|
|
|
|
char * conf_sslcertfilename=0;
|
|
|
|
char * conf_sslkeypass=0;
|
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
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;
|
2014-07-22 07:11:57 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
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;
|
|
|
|
|
2015-02-03 08:18:39 +01:00
|
|
|
long conf_dbg_level=CONF_DEFAULT_DEBUG_LEVEL;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-18 20:34:35 +01:00
|
|
|
int conf_mtu_discovery=CONF_DEFAULT_MTU_DISCOVERY;
|
|
|
|
int conf_mtu=0;
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-01 16:55:45 +01:00
|
|
|
uint32_t conf_vendor_id;
|
|
|
|
uint32_t * conf_bootloader_vendor_id;
|
|
|
|
uint8_t * conf_bootloader_version;
|
|
|
|
uint32_t * conf_software_vendor_id;
|
|
|
|
uint8_t * conf_software_version;
|
|
|
|
uint32_t * conf_hardware_vendor_id;
|
|
|
|
uint8_t * conf_hardware_version;
|
|
|
|
|
|
|
|
uint8_t * conf_model_no;
|
2015-03-12 23:21:57 +01:00
|
|
|
uint8_t * conf_serial_no;
|
2015-02-01 16:55:45 +01:00
|
|
|
|
|
|
|
|
2015-03-14 21:41:50 +01:00
|
|
|
|
|
|
|
bstr_t conf_board_id;
|
|
|
|
bstr_t conf_board_revision;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-08 21:07:55 +01:00
|
|
|
LONGSTRS conf_timer_cfgstrs[] = {
|
|
|
|
"max_discovery_interval",&conf_max_discovery_interval,
|
|
|
|
"discovery_interval",&conf_discovery_interval,
|
|
|
|
"max_discoveries",&conf_max_discoveries,
|
|
|
|
"silent_interval",&conf_silent_interval,
|
|
|
|
0,0
|
|
|
|
};
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
int wtpconf_primary_if()
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
#ifdef WITH_IPV6
|
|
|
|
conf_primary_if = sock_get_primary_if(AF_INET6);
|
|
|
|
if (!conf_primary_if)
|
|
|
|
conf_primary_if = sock_get_primary_if(AF_INET);
|
|
|
|
#else
|
|
|
|
conf_primary_if = get_primary_if(AF_INET);
|
|
|
|
#endif
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
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.",conf_primary_if);
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2014-09-14 22:46:14 +02:00
|
|
|
cw_dbg(DBG_CW_INFO, "Primary interface: %s, mac address: %s.",
|
2014-07-22 07:11:57 +02:00
|
|
|
conf_primary_if,
|
2014-07-28 07:09:05 +02:00
|
|
|
sock_hwaddr2str(conf_macaddress,conf_macaddress_len)
|
2014-07-22 07:11:57 +02:00
|
|
|
);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
return 1;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
int wtpconf_name()
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2014-07-22 07:11:57 +02:00
|
|
|
if (conf_wtpname)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
char name[64];
|
2014-07-28 07:09:05 +02:00
|
|
|
sprintf(name,"WTP%s",sock_hwaddr2idstr(conf_macaddress,conf_macaddress_len));
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
conf_wtpname = (char*)cw_setstr((uint8_t**)&conf_wtpname,(uint8_t*)name,strlen(name));
|
|
|
|
if (!conf_wtpname)
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
|
2014-09-14 22:46:14 +02:00
|
|
|
cw_dbg(DBG_CW_INFO,"Using self assigned wtp name: %s",conf_wtpname);
|
2014-07-22 07:11:57 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
char * default_ac_list[] = {
|
2015-03-12 23:21:57 +01:00
|
|
|
// "192.168.0.255",
|
2015-01-18 20:34:35 +01:00
|
|
|
"255.255.255.255",
|
2014-09-14 22:46:14 +02:00
|
|
|
// "224.0.1.140",
|
2015-03-12 23:21:57 +01:00
|
|
|
// "192.168.0.12"
|
2014-07-11 22:12:11 +02:00
|
|
|
};
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
int wtpconf_ac_list()
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
|
|
|
if (conf_ac_list)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int len=0;
|
|
|
|
int bcrc;
|
|
|
|
struct sockaddr_storage bcaddr;
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
bcrc = sock_getifaddr(conf_primary_if,AF_INET,IFF_BROADCAST,(struct sockaddr*)&bcaddr);
|
2014-07-11 22:12:11 +02:00
|
|
|
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; i<deflen; i++){
|
|
|
|
conf_ac_list[i]=strdup(default_ac_list[i]);
|
|
|
|
if (!conf_ac_list[i])
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bcrc){
|
|
|
|
char bcstr[100];
|
2014-07-22 07:11:57 +02:00
|
|
|
sock_addrtostr((struct sockaddr*)&bcaddr,bcstr,100);
|
2014-07-11 22:12:11 +02:00
|
|
|
char * c = strchr(bcstr,':');
|
|
|
|
*c=0;
|
|
|
|
conf_ac_list[i]=strdup(bcstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
conf_ac_list_len=len;
|
|
|
|
#ifdef WITH_CW_LOG_DEBUG
|
|
|
|
for (i=0; i<conf_ac_list_len; i++){
|
2015-02-08 21:07:55 +01:00
|
|
|
cw_dbg(DBG_CW_INFO,"Using AC: %s\n",conf_ac_list[i]);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int wtpconf_preinit()
|
|
|
|
{
|
|
|
|
conf_control_port=strdup(CAPWAP_CONTROL_PORT_STR);
|
|
|
|
conf_dtls_cipher=strdup(CONF_DEFAULT_DTLS_CIPHER);
|
|
|
|
|
2015-02-01 16:55:45 +01:00
|
|
|
|
|
|
|
conf_vendor_id = CONF_DEFAULT_VENDOR_ID;
|
2015-03-12 23:21:57 +01:00
|
|
|
conf_software_version = bstr_create_from_cfgstr(CONF_DEFAULT_SOFTWARE_VERSION);
|
|
|
|
conf_serial_no = bstr_create_from_cfgstr(CONF_DEFAULT_SERIAL_NO);
|
2015-02-01 16:55:45 +01:00
|
|
|
|
2015-03-14 21:41:50 +01:00
|
|
|
conf_board_id = bstr_create_from_cfgstr(CONF_DEFAULT_BOARD_ID);
|
|
|
|
conf_board_revision = bstr_create_from_cfgstr(CONF_DEFAULT_BOARD_REVISION);
|
2014-07-22 07:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int wtpconf_init()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!wtpconf_primary_if()){
|
|
|
|
cw_log(LOG_ERR,"Fatal: Error initialing primary interface.");
|
|
|
|
goto errX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wtpconf_ac_list()){
|
|
|
|
cw_log(LOG_ERR,"Fatal: Error initialiing ac list.");
|
|
|
|
goto errX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wtpconf_name()){
|
|
|
|
cw_log(LOG_ERR,"Fatal: Cant't set wtp name.");
|
|
|
|
goto errX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
errX:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
if (conf_preferred_ac){
|
|
|
|
conf_preferred_ac_sa=malloc(sizeof(struct sockaddr_storage));
|
|
|
|
if (sock_strtoaddr(conf_preferred_ac,(struct sockaddr*)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((struct sockaddr*)conf_preferred_ac_sa)==0){
|
|
|
|
sock_setport((struct sockaddr*)conf_preferred_ac_sa,conf_control_port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (conf_preferred_ac_sa!=0){
|
|
|
|
char str[100];
|
|
|
|
sock_addrtostr((struct sockaddr*)conf_preferred_ac_sa,str,100);
|
|
|
|
cw_log(LOG_INFO,"Preferred AC: %s\n",str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-07-11 22:12:11 +02:00
|
|
|
int read_config(const char * filename){
|
|
|
|
int i,n;
|
|
|
|
|
|
|
|
|
|
|
|
conf_control_port=strdup(CAPWAP_CONTROL_PORT_STR);
|
|
|
|
conf_dtls_cipher=strdup(CONF_DEFAULT_DTLS_CIPHER);
|
|
|
|
|
|
|
|
cfg_opt_t opts[] = {
|
|
|
|
CFG_SIMPLE_STR("wtp_name",&conf_wtpname),
|
|
|
|
CFG_SIMPLE_STR("dtls_psk",&conf_dtls_psk),
|
|
|
|
CFG_SIMPLE_STR("preferred_ac",&conf_preferred_ac),
|
|
|
|
CFG_SIMPLE_STR("primary_if",&conf_primary_if),
|
|
|
|
CFG_SIMPLE_STR("dtls_cipher",&conf_dtls_cipher),
|
|
|
|
CFG_STR_LIST("ac_list", "{}", CFGF_NONE),
|
|
|
|
CFG_SIMPLE_STR("control_port",&conf_control_port),
|
|
|
|
CFG_SIMPLE_INT("discovery_interval",&conf_discovery_interval),
|
|
|
|
CFG_SIMPLE_INT("max_discovery_interval",&conf_max_discovery_interval),
|
|
|
|
CFG_SIMPLE_INT("max_discoveries",&conf_max_discoveries),
|
|
|
|
CFG_SIMPLE_INT("silent_interval",&conf_silent_interval),
|
|
|
|
CFG_SIMPLE_INT("debug_level",&conf_debug_level),
|
|
|
|
CFG_SIMPLE_INT("max_retransmit",&conf_max_retransmit),
|
|
|
|
CFG_SIMPLE_INT("retransmit_interval",&conf_retransmit_interval),
|
|
|
|
CFG_SIMPLE_INT("echo_interval",&conf_echo_interval),
|
|
|
|
|
|
|
|
|
|
|
|
CFG_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
cfg_t *cfg;
|
|
|
|
cfg = cfg_init(opts, 0);
|
|
|
|
|
|
|
|
cfg_parse(cfg, filename);
|
|
|
|
|
|
|
|
|
|
|
|
n = cfg_size(cfg, "ac_list");
|
|
|
|
if (n>0)
|
|
|
|
{
|
|
|
|
conf_ac_list=malloc(sizeof(char*)*n);
|
|
|
|
if (!conf_ac_list)
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
conf_ac_list_len=0;
|
|
|
|
for (i=0; i<n; i++){
|
|
|
|
char * str = cfg_getnstr(cfg,"ac_list",i);
|
|
|
|
conf_ac_list[conf_ac_list_len]=malloc(strlen(str)+1);
|
|
|
|
if(conf_ac_list) {
|
|
|
|
strcpy(conf_ac_list[conf_ac_list_len],str);
|
|
|
|
conf_ac_list_len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!wtpconf_primary_if())
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
if (!wtpconf_ac_list()){
|
|
|
|
printf("ac list error\n");
|
|
|
|
goto errX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// wtpconf_init();
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
errX:
|
|
|
|
cfg_free(cfg);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2014-07-22 07:11:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
*/
|