aciplist in config file.
FossilOrigin-Name: 0ae2ea51cbbb8c346b811c5ed15b41fb1445a9e97b574379596be9333f051858
This commit is contained in:
119
src/wtp/cfg.c
119
src/wtp/cfg.c
@ -15,6 +15,8 @@
|
||||
#include "capwap/format.h"
|
||||
|
||||
#include "capwap/file.h"
|
||||
#include "capwap/aciplist.h"
|
||||
#include "capwap/sock.h"
|
||||
|
||||
|
||||
/* json putters */
|
||||
@ -22,6 +24,8 @@ int cfg_json_put_bstr16(char *dst,const char * name, mbag_item_t *i,int n);
|
||||
int cfg_json_put_vendorstr(char *dst,const char * name, mbag_item_t *i,int n);
|
||||
int cfg_json_put_dword(char *dst,const char * name, mbag_item_t *i,int n);
|
||||
int cfg_json_put_word(char *dst,const char * name, mbag_item_t *i,int n);
|
||||
int cfg_json_put_ac_ip_list(char *dst,const char * name, mbag_item_t *i,int n);
|
||||
|
||||
|
||||
//static int scn_obj(char *js, jsmntok_t *t, int (vcb)(char*js,jsmntok_t*t,struct mbag_itemdef *defs,mbag_t mbag), struct mbag_itemdef *defs,mbag_t mbag);
|
||||
|
||||
@ -90,7 +94,90 @@ static int skip(jsmntok_t *t)
|
||||
}
|
||||
}
|
||||
|
||||
int cfg_json_put_ac_ip_list(char *dst,const char * name, mbag_item_t *i,int n)
|
||||
{
|
||||
|
||||
char *d = dst;
|
||||
|
||||
cw_aciplist_t aciplist = i->data;
|
||||
|
||||
MAVLITER_DEFINE(it,aciplist);
|
||||
|
||||
memset(d,'\t',n);
|
||||
d+=n;
|
||||
d+=sprintf(d,"\"%s\":",name);
|
||||
|
||||
d+=sprintf(d,"[\n");
|
||||
const char * comma = "";
|
||||
mavliter_foreach(&it){
|
||||
cw_acip_t * acip = mavliter_get(&it);
|
||||
|
||||
d+=sprintf(d,"%s",comma);
|
||||
memset(d,'\t',n+1);
|
||||
d+=n+1;
|
||||
|
||||
d+=sprintf(d,"\"%s\"",sock_addr2str(&acip->ip));
|
||||
comma=",\n";
|
||||
|
||||
|
||||
}
|
||||
d+=sprintf(d,"\n");
|
||||
memset(d,'\t',n);
|
||||
d+=n;
|
||||
|
||||
d+=sprintf(d,"]");
|
||||
|
||||
return d-dst;
|
||||
}
|
||||
|
||||
int cfg_json_get_ac_ip_list(struct mbag_itemdef *idef,char *js, jsmntok_t *t,mbag_t mbag)
|
||||
{
|
||||
|
||||
printf("Get AC IP List len = %d\n",t->size);
|
||||
if (t->type != JSMN_ARRAY ) {
|
||||
printf("ac_ip_list is not a list\n");
|
||||
exit(0);
|
||||
|
||||
}
|
||||
int size = t->size;
|
||||
t++;
|
||||
|
||||
int i;
|
||||
|
||||
for (i=0; i<size; i++,t++){
|
||||
js[t->end]=0;
|
||||
|
||||
int rc;
|
||||
|
||||
cw_acip_t * acip;
|
||||
acip = malloc(sizeof(cw_acip_t));
|
||||
if (!acip)
|
||||
continue;
|
||||
|
||||
/* convert IPv4 adddress */
|
||||
rc = inet_pton(AF_INET, js+t->start, &(((struct sockaddr_in *)(&acip->ip))->sin_addr) );
|
||||
((struct sockaddr *)(&acip->ip))->sa_family=AF_INET;
|
||||
if (!rc) {
|
||||
/* If it's not an IPv4 adress, try IPv6 */
|
||||
rc = inet_pton(AF_INET6, js+t->start, &(((struct sockaddr_in6 *)(&acip->ip))->sin6_addr) );
|
||||
((struct sockaddr *)(&acip->ip))->sa_family=AF_INET6;
|
||||
}
|
||||
|
||||
if ( !rc ) {
|
||||
|
||||
printf("Not an IP adress: %s\n",js+t->start);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
cw_aciplist_t aciplist= mbag_get_mavl(mbag,CW_ITEM_AC_IP_LIST,cw_aciplist_create );
|
||||
mavl_replace(aciplist,acip);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -237,6 +324,7 @@ int bstr_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t)
|
||||
|
||||
|
||||
|
||||
int cfg_json_get_ac_ip_list(struct mbag_itemdef *idef,char *js, jsmntok_t *t,mbag_t mbag);
|
||||
|
||||
int wtp_board_data_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t,mbag_t mbag);
|
||||
int cfg_json_put_obj(char *dst,const char * name, mbag_item_t *i,int n);
|
||||
@ -254,6 +342,7 @@ struct mbag_itemdef general_cfg[] = {
|
||||
{CW_RADIO_BSSID, "bssid",cfg_json_get_bstr16,cfg_json_put_bstr16},
|
||||
{CW_ITEM_CAPWAP_TIMERS, "capwap_timers",cfg_json_get_word,cfg_json_put_word},
|
||||
{CW_ITEM_IDLE_TIMEOUT, "idle_timeout",cfg_json_get_dword,cfg_json_put_dword},
|
||||
{CW_ITEM_AC_IP_LIST,"ac_ip_list",cfg_json_get_ac_ip_list,cfg_json_put_ac_ip_list},
|
||||
|
||||
|
||||
|
||||
@ -372,9 +461,6 @@ int cfg_json_put_obj(char *dst,const char * name, mbag_item_t *i,int n)
|
||||
memset(d,'\t',n);
|
||||
d+=n;
|
||||
d+=sprintf(d,"\"%s\":",name);
|
||||
|
||||
printf("here we are %s\n",dst);
|
||||
|
||||
d+=mbag_tojson(d,i->data,board_data_cfg,n);
|
||||
return d-dst;
|
||||
|
||||
@ -436,7 +522,8 @@ int cfg_json_save()
|
||||
int n = mbag_tojson(dst,conn->config,general_cfg,0);
|
||||
|
||||
|
||||
//printf("Json: %s\n",dst);
|
||||
|
||||
|
||||
|
||||
cw_save_file("cfg.json",dst,n);
|
||||
|
||||
@ -506,7 +593,6 @@ int wtp_board_data_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t,mbag_t
|
||||
printf("Size: %d\n",t->size);
|
||||
return 0;
|
||||
}
|
||||
printf("BOARD DATA SCANER\n");
|
||||
|
||||
struct conn * conn = get_conn();
|
||||
mbag_t bd = mbag_get_mbag(conn->config,CW_ITEM_WTP_BOARD_DATA,NULL);
|
||||
@ -561,29 +647,6 @@ static int set_cfg(char *js,jsmntok_t *t,struct mbag_itemdef *defs,mbag_t mbag){
|
||||
|
||||
int setup_conf(struct conn *conn)
|
||||
{
|
||||
|
||||
/*
|
||||
FILE * infile = fopen("cfg.json","rb");
|
||||
if ( !infile ){
|
||||
perror("Can't open cfg.json");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fseek(infile,0,SEEK_END);
|
||||
int size = ftell(infile);
|
||||
|
||||
|
||||
char *jstr = malloc(size);
|
||||
if ( jstr==NULL){
|
||||
perror("Can't allocate memory");
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
fseek(infile,0,SEEK_SET);
|
||||
fread(jstr,1,size,infile);
|
||||
*/
|
||||
|
||||
size_t size;
|
||||
char *jstr = cw_load_file("cfg.json",&size);
|
||||
if (!jstr) {
|
||||
|
@ -9,6 +9,12 @@
|
||||
"serial_no":"2045"
|
||||
},
|
||||
"capwap_timers":"2590",
|
||||
"ac_ip_list":[
|
||||
"192.168.0.1",
|
||||
"192.168.0.13",
|
||||
"192.168.0.15",
|
||||
"fe80::219:dbff:fee0:9327"
|
||||
],
|
||||
"location_data":"Germany",
|
||||
"bssid":""
|
||||
}
|
@ -182,10 +182,12 @@ int wtpconf_ac_list()
|
||||
}
|
||||
|
||||
if (bcrc){
|
||||
char bcstr[100];
|
||||
sock_addrtostr((struct sockaddr*)&bcaddr,bcstr,100);
|
||||
char * c = strchr(bcstr,':');
|
||||
*c=0;
|
||||
// char bcstr[100];
|
||||
char *bcstr;
|
||||
// sock_addrtostr((struct sockaddr*)&bcaddr,bcstr,100);
|
||||
bcstr = sock_addr2str((struct sockaddr*)&bcaddr);
|
||||
// char * c = strchr(bcstr,':');
|
||||
// *c=0;
|
||||
conf_ac_list[i]=strdup(bcstr);
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ mavl_destroy(b);
|
||||
conn->config=mbag_create();
|
||||
|
||||
setup_conf(conn);
|
||||
|
||||
cfg_json_save();
|
||||
|
||||
mbag_t board_data = mbag_create();
|
||||
mbag_set_dword(board_data, CW_ITEM_WTP_BOARD_VENDOR, conf_vendor_id);
|
||||
@ -172,7 +172,7 @@ cw_set_msg_end_callback(conn,CW_STATE_CONFIGURE,CW_MSG_CONFIGURATION_STATUS_RESP
|
||||
|
||||
|
||||
|
||||
the_conn->strict_capwap=0;
|
||||
the_conn->strict_capwap=1;
|
||||
discovery();
|
||||
join();
|
||||
mavl_destroy(conn->incomming);
|
||||
|
Reference in New Issue
Block a user