WTP work...
FossilOrigin-Name: c770fa37c379da9fb78feebb463e2843ba8179e3f9026687dcfb44b4c7c47388
This commit is contained in:
223
src/wtp/cfg.c
223
src/wtp/cfg.c
@ -8,24 +8,99 @@
|
||||
|
||||
#include "jsmn.h"
|
||||
#include "wtp.h"
|
||||
#include "capwap/bstr.h"
|
||||
|
||||
struct cw_itemdef {
|
||||
int item_id;
|
||||
const char *cfgname;
|
||||
int (*setfun) (struct cw_itemdef *,char *js,jsmntok_t *t);
|
||||
int (*setfun) (struct cw_itemdef *,char *,jsmntok_t *);
|
||||
const char def;
|
||||
|
||||
};
|
||||
typedef struct cw_itemdef cfg_item_t;
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
CW_ITEMSPACE_DBG,
|
||||
CW_ITEMSPACE_WTP
|
||||
};
|
||||
|
||||
|
||||
int bstr16_local(struct cw_item_def *idef,char *js, jsmntok_t *t)
|
||||
static int scn_obj(char *js, jsmntok_t *t, int (vcb)(char*js,jsmntok_t*t) ) {
|
||||
int i;
|
||||
|
||||
if (t->type!=JSMN_OBJECT){
|
||||
printf("No object\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
if (t->size<3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
int j=1;
|
||||
for (i = 0; i < t->size; i++) {
|
||||
|
||||
j+=vcb(js,t+j);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int skip(jsmntok_t *t)
|
||||
{
|
||||
int item_id = idef=item_id;
|
||||
switch (t->type){
|
||||
case JSMN_OBJECT:
|
||||
{
|
||||
int e=t->end;
|
||||
int n=1;
|
||||
while (e>t->start) {
|
||||
t++;n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
default:
|
||||
return t->size+2;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int byte_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
|
||||
{
|
||||
printf("GET BYTE\n");
|
||||
// if (t->type != JSMN_STRING){
|
||||
// printf("Error: No Str: %s\n",str);
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
*(js+t->end)=0;
|
||||
const char * val = js+t->start;
|
||||
// *(js+(t+1)->end)=0;
|
||||
// const char * val = js+(t+1)->start;
|
||||
struct conn * conn = get_conn();
|
||||
|
||||
cw_itemstore_set_byte(conn->local,idef->item_id,atoi(val));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int bstr16_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
|
||||
{
|
||||
int item_id = idef->item_id;
|
||||
struct conn * conn = get_conn();
|
||||
|
||||
*(js+t->end)=0;
|
||||
@ -37,14 +112,34 @@ int bstr16_local(struct cw_item_def *idef,char *js, jsmntok_t *t)
|
||||
}
|
||||
// *(js+t->end)=0;
|
||||
printf("Set str: %d %s\n", item_id,str);
|
||||
cw_itemstore_set_bstr16n(conn->local,item_id,js+t->start,t->end-t->start);
|
||||
cw_itemstore_set_bstr16n(conn->local,item_id,(uint8_t*)js+t->start,t->end-t->start);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wtp_board_data_local(struct cw_itemdef *idef,char *js, jsmntok_t *t);
|
||||
|
||||
struct cw_itemdef cfg[] = {
|
||||
|
||||
|
||||
|
||||
|
||||
struct cw_itemdef general_cfg[] = {
|
||||
{CW_ITEM_WTP_HARDWARE_VERSION, "hardware_version",bstr16_local},
|
||||
{CW_ITEM_WTP_SOFTWARE_VERSION, "software_version",bstr16_local},
|
||||
{CW_ITEM_WTP_BOARD_MODELNO, "modelno",bstr16_local},
|
||||
{CW_ITEM_WTP_BOARD_DATA,"wtp_board_data",wtp_board_data_local},
|
||||
{CW_ITEM_WTP_FRAME_TUNNEL_MODE,"frame_tunnel_mode",byte_local},
|
||||
{CW_ITEM_WTP_MAC_TYPE,"mac_type",byte_local},
|
||||
{CW_ITEM_LOCATION_DATA,"location_data",bstr16_local},
|
||||
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct cw_itemdef board_data_cfg[] = {
|
||||
{CW_ITEM_WTP_BOARD_MODELNO, "model_no",NULL},
|
||||
{CW_ITEM_WTP_BOARD_SERIALNO, "serial_no",NULL},
|
||||
{CW_ITEM_WTP_BOARD_VENDOR, "vendor_id",NULL},
|
||||
|
||||
{0, 0, 0}
|
||||
};
|
||||
@ -54,7 +149,8 @@ struct cw_itemdef cfg[] = {
|
||||
|
||||
|
||||
|
||||
struct cw_itemdef * get_cfg(const char *key){
|
||||
|
||||
struct cw_itemdef * get_cfg(struct cw_itemdef *cfg,const char *key){
|
||||
int i=0;
|
||||
for (i=0; cfg[i].item_id; i++){
|
||||
if ( !strcmp(key,cfg[i].cfgname )) {
|
||||
@ -64,61 +160,94 @@ struct cw_itemdef * get_cfg(const char *key){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int scn_obj(jsmntok_t *t, int i)
|
||||
static int wtp_board_data_cb(char *js,jsmntok_t *t)
|
||||
{
|
||||
printf("VB BOARD DATA!!!\n");
|
||||
struct conn * conn = get_conn();
|
||||
cw_itemstore_t bd = cw_itemstore_get_avltree(conn->local,CW_ITEM_WTP_BOARD_DATA);
|
||||
if (!bd){
|
||||
bd = cw_itemstore_create();
|
||||
if (!bd){
|
||||
return skip(t+1);
|
||||
}
|
||||
cw_itemstore_set_avltree(conn->local,CW_ITEM_WTP_BOARD_DATA,bd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
*(js+t->end)=0;
|
||||
const char * key = js+t->start;
|
||||
*(js+(t+1)->end)=0;
|
||||
const char * val = js+(t+1)->start;
|
||||
|
||||
|
||||
struct conn *get_conn();
|
||||
struct cw_itemdef * idef = get_cfg(board_data_cfg,key);
|
||||
|
||||
if (!idef){
|
||||
return skip(t+1);
|
||||
}
|
||||
|
||||
if (idef->item_id == CW_ITEM_WTP_BOARD_VENDOR){
|
||||
cw_itemstore_set_dword(bd,CW_ITEM_WTP_BOARD_VENDOR,atoi(val));
|
||||
|
||||
}
|
||||
else{
|
||||
bstr16_t v = bstr16cfgstr(val);
|
||||
cw_itemstore_set_bstr16n(bd,idef->item_id,bstr16_data(v),bstr16_len(v));
|
||||
free(v);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return skip(t+1);
|
||||
|
||||
}
|
||||
|
||||
int wtp_board_data_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
|
||||
{
|
||||
printf("Local board data\n");
|
||||
|
||||
if ( t->type != JSMN_OBJECT ) {
|
||||
printf("Error: wtp_board_data is no object\n");
|
||||
printf("Size: %d\n",t->size);
|
||||
return 0;
|
||||
}
|
||||
printf("Scanni\n");
|
||||
scn_obj(js, t,wtp_board_data_cb);
|
||||
return skip(t+1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int set_cfg(char *js,jsmntok_t *t){
|
||||
|
||||
*(js+t->end)=0;
|
||||
const char * key = js+t->start;
|
||||
*(js+(t+1)->end)=0;
|
||||
//const char * val = js+(t+1)->start;
|
||||
|
||||
if ( t->type != JSMN_STRING ) {
|
||||
printf("Error - No String: %s\n",key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct cw_itemdef * idef = get_cfg(key);
|
||||
if(!idef){
|
||||
printf("Error - not found: %s\n",key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct cw_itemdef * idef = get_cfg(general_cfg,key);
|
||||
|
||||
// printf("Key: %s\n",key);
|
||||
// printf("Val: %s\n",val);
|
||||
|
||||
if(!idef)
|
||||
return skip(t+1);
|
||||
|
||||
if ( !idef->setfun) {
|
||||
printf("Error no setfun: %s\n",key);
|
||||
|
||||
}
|
||||
else{
|
||||
idef->setfun(idef->item_id,js,t+1);
|
||||
idef->setfun(idef,js,t+1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
static int read_obj(char *js, jsmntok_t *t ) {
|
||||
int i;
|
||||
|
||||
if (t->type!=JSMN_OBJECT){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (t->size<3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 1; i < t->size; i++) {
|
||||
i+=set_cfg(js,t+i);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
return skip(t+1);
|
||||
|
||||
}
|
||||
|
||||
@ -156,13 +285,7 @@ int setup_conf(struct conn *conn)
|
||||
printf("Parser failed\n");
|
||||
}
|
||||
|
||||
read_obj(jstr, t);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int i;
|
||||
scn_obj(jstr, t,set_cfg);
|
||||
|
||||
|
||||
|
||||
@ -170,10 +293,16 @@ int setup_conf(struct conn *conn)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
for (i = 0; cfg[i].item_id != CW_ITEM_NONE; i++) {
|
||||
printf("ItemName: %s\n", cfg[i].cfgname); //.cfgname)
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,15 +1,31 @@
|
||||
{
|
||||
|
||||
|
||||
"dbg":[o1,o2,o3],
|
||||
"Tube" : "tabbe",
|
||||
|
||||
"hardware_version": "12345",
|
||||
"software_version": "98765",
|
||||
"vendor_id": 40909,
|
||||
"modelno": "2045",
|
||||
"comment": "** The following is debug info **",
|
||||
"location_data": "Berlin",
|
||||
|
||||
"frame_tunnel_mode": "4",
|
||||
"mac_type": 2,
|
||||
|
||||
|
||||
|
||||
"wtp_board_data" : {
|
||||
"vendor_id": 4232704,
|
||||
"model_no": "Tobias Herre",
|
||||
"serial_no": "2045",
|
||||
},
|
||||
|
||||
|
||||
"acname_with_priority": {
|
||||
"1":"Master-AC",
|
||||
"2":"Cisco-AC"
|
||||
},
|
||||
"comment": "** The following is debug info **"
|
||||
"dbg":[o1,o2,o3]
|
||||
|
||||
"ac": {
|
||||
"Master-AC": {
|
||||
|
||||
@ -19,6 +35,7 @@
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
int configure()
|
||||
{
|
||||
/*
|
||||
|
||||
struct conn * conn = get_conn();
|
||||
struct wtpinfo * wtpinfo = get_wtpinfo();
|
||||
/* struct wtpinfo * wtpinfo = get_wtpinfo();
|
||||
|
||||
struct radioinfo *rip = &(wtpinfo->radioinfo[0]);
|
||||
|
||||
|
@ -32,7 +32,7 @@ int image_update()
|
||||
return 0;
|
||||
}
|
||||
|
||||
cw_dbg(DBG_ELEM,"Ready to receive image ...\n");
|
||||
cw_dbg(DBG_INFO,"Ready to receive image ...");
|
||||
|
||||
conn->capwap_state=CW_STATE_IMAGE_DATA;
|
||||
rc=-11;
|
||||
|
@ -182,6 +182,8 @@ int run_join(struct conn * conn)
|
||||
int join()
|
||||
{
|
||||
struct conn * conn = get_conn();
|
||||
conn->capwap_mode=CW_MODE_CISCO;
|
||||
|
||||
cw_aciplist_t iplist = cw_itemstore_get_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
|
||||
if (!iplist){
|
||||
cw_log(LOG_ERR,"No IPs to join controller.");
|
||||
|
@ -29,7 +29,13 @@ struct conn *the_conn;
|
||||
struct cw_actiondef capwap_actions;
|
||||
|
||||
|
||||
bstr_t get_base_rmac()
|
||||
{
|
||||
// static uint8_t rm[8]={0x00,0x4a,0x99,0x02,0xfa,0xc0};
|
||||
|
||||
static uint8_t rm[8]={0x00,0x3a,0x99,0x02,0xfa,0xc0};
|
||||
return bstr_create(rm,6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -64,11 +70,14 @@ int main()
|
||||
conn->outgoing = cw_itemstore_create();
|
||||
conn->incomming = cw_itemstore_create();
|
||||
conn->local = cw_itemstore_create();
|
||||
conn->base_rmac=get_base_rmac();
|
||||
conn->capwap_mode = CW_MODE_CISCO;
|
||||
|
||||
|
||||
setup_conf(conn);
|
||||
|
||||
|
||||
/*
|
||||
cw_itemstore_t board_data = cw_itemstore_create();
|
||||
cw_itemstore_set_dword(board_data, CW_ITEM_WTP_BOARD_VENDOR, conf_vendor_id);
|
||||
|
||||
@ -78,11 +87,11 @@ int main()
|
||||
cw_itemstore_set_bstr16n(board_data, CW_ITEM_WTP_BOARD_SERIALNO,
|
||||
bstr_data(conf_serial_no), bstr_len(conf_serial_no));
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
cw_itemstore_set_avltree(conn->outgoing, CW_ITEM_WTP_BOARD_DATA, board_data);
|
||||
// cw_itemstore_set_avltree(conn->outgoing, CW_ITEM_WTP_BOARD_DATA, board_data);
|
||||
|
||||
cw_acpriolist_t acprios = cw_acpriolist_create();
|
||||
cw_acpriolist_set(acprios,"Master AC",strlen("Master AC"),1);
|
||||
@ -100,7 +109,7 @@ int main()
|
||||
the_conn->strict_capwap=0;
|
||||
discovery();
|
||||
join();
|
||||
image_update();
|
||||
//image_update();
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user