Introducing mavl and mbag.

FossilOrigin-Name: 383bc0c7d65716c38a10aea87ab94c240e581cd2193f55fdfcbe644ef3dec0ff
This commit is contained in:
7u83@mail.ru
2015-04-19 21:27:44 +00:00
parent 341e098a6d
commit 381c910eec
46 changed files with 772 additions and 987 deletions

View File

@ -1,4 +1,4 @@
#include "capwap/itemstore.h"
#include "capwap/mbag.h"
#include "capwap/capwap_items.h"
#include "capwap/conn.h"
#include "capwap/bstr.h"
@ -11,14 +11,25 @@
#include "capwap/bstr.h"
#include "capwap/radio.h"
struct cw_itemdef {
#include "capwap/mavl.h"
#include "capwap/format.h"
/* json putters */
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);
struct mbag_itemdef {
int item_id;
const char *cfgname;
int (*setfun) (struct cw_itemdef *,char *,jsmntok_t *);
const char def;
int (*setfun) (struct mbag_itemdef *,char *,jsmntok_t *);
int (*tojsonfun) (char *dst,const char *name, mbag_item_t *i,int n);
};
typedef struct cw_itemdef cfg_item_t;
typedef struct mbag_itemdef cfg_item_t;
@ -77,7 +88,7 @@ static int skip(jsmntok_t *t)
int byte_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
int byte_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t)
{
printf("GET BYTE\n");
// if (t->type != JSMN_STRING){
@ -91,50 +102,61 @@ printf("GET BYTE\n");
// const char * val = js+(t+1)->start;
struct conn * conn = get_conn();
cw_itemstore_set_byte(conn->local,idef->item_id,atoi(val));
mbag_set_byte(conn->local,idef->item_id,atoi(val));
return 0;
}
int vendorstr_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
int cfg_json_get_vendorstr(struct mbag_itemdef *idef,char *js, jsmntok_t *t)
{
int item_id = idef->item_id;
struct conn * conn = get_conn();
int item_id = idef->item_id;
*(js+t->end)=0;
char *str = js+t->start;
if (t->type != JSMN_ARRAY || t->type!=2){
printf("Error: No ARRAY or to short: %s\n",str);
exit(1);
return 0;
}
// *(js+t->end)=0;
char * val = js+(t+1)->start;
*(js+(t+1)->end)=0;
printf("Val: %s\n",val);
uint32_t vendor_id = atoi(val);
str = (uint8_t*)js+(t+2)->start;
str = (char*)(js+(t+2)->start);
*((t+2)->end+js)=0;
bstr16_t v = bstr16cfgstr(str);
printf("Vendor: %d %s\n",vendor_id,str);
cw_itemstore_set_vendorstr(conn->local,item_id,vendor_id,bstr16_data(v),bstr16_len(v));
mbag_set_vendorstr(conn->config,item_id,vendor_id,bstr16_data(v),bstr16_len(v));
free(v);
return 0;
}
int cfg_json_get_bstr16(struct mbag_itemdef *idef,char *js, jsmntok_t *t)
{
struct conn * conn = get_conn();
int item_id = idef->item_id;
*(js+t->end)=0;
// char *str = js+t->start;
if (t->type != JSMN_STRING){
return 0;
}
*(js+t->end)=0;
bstr16_t b = bstr16cfgstr(js+t->start);
mbag_set_bstr16(conn->config,item_id,b);
return 0;
}
int bstr16_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
int bstr16_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t)
{
int item_id = idef->item_id;
struct conn * conn = get_conn();
@ -148,11 +170,11 @@ int bstr16_local(struct cw_itemdef *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,(uint8_t*)js+t->start,t->end-t->start);
mbag_set_bstr16n(conn->local,item_id,(uint8_t*)js+t->start,t->end-t->start);
return 0;
}
int bstr_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
int bstr_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t)
{
int item_id = idef->item_id;
struct conn * conn = get_conn();
@ -169,7 +191,7 @@ int bstr_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
bstr16_t v = bstr16cfgstr(str);
cw_itemstore_set_bstrn(conn->local,item_id,bstr16_data(v),bstr16_len(v)); //(uint8_t*)js+t->start,t->end-t->start);
mbag_set_bstrn(conn->local,item_id,bstr16_data(v),bstr16_len(v)); //(uint8_t*)js+t->start,t->end-t->start);
free (v);
return 0;
}
@ -177,22 +199,23 @@ int bstr_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
int wtp_board_data_local(struct cw_itemdef *idef,char *js, jsmntok_t *t);
int wtp_board_data_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t);
struct cw_itemdef general_cfg[] = {
{CW_ITEM_AC_NAME, "ac_name",bstr16_local},
{CW_ITEM_WTP_NAME, "wtp_name",bstr16_local},
{CW_ITEM_WTP_HARDWARE_VERSION, "hardware_version",vendorstr_local},
{CW_ITEM_WTP_SOFTWARE_VERSION, "software_version",vendorstr_local},
struct mbag_itemdef general_cfg[] = {
{CW_ITEM_WTP_NAME, "wtp_name",cfg_json_get_bstr16,cfg_json_put_bstr16},
{CW_ITEM_LOCATION_DATA,"location_data",cfg_json_get_bstr16,cfg_json_put_bstr16},
{CW_ITEM_WTP_HARDWARE_VERSION, "hardware_version",cfg_json_get_vendorstr,cfg_json_put_vendorstr},
{CW_ITEM_WTP_SOFTWARE_VERSION, "software_version",cfg_json_get_vendorstr,cfg_json_put_vendorstr},
{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},
{CW_ITEM_WTP_GROUP_NAME,"group_name",bstr16_local},
{CW_RADIO_BSSID,"bssid",bstr_local},
@ -201,7 +224,7 @@ struct cw_itemdef general_cfg[] = {
struct cw_itemdef board_data_cfg[] = {
struct mbag_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},
@ -209,13 +232,116 @@ struct cw_itemdef board_data_cfg[] = {
{0, 0, 0}
};
struct mbag_itemdef * get_idef_by_id(struct mbag_itemdef *cfg,uint32_t id){
int i=0;
for (i=0; cfg[i].item_id; i++){
if ( cfg[i].item_id == id) {
return &cfg[i];
}
}
return NULL;
}
int cfg_json_put_bstr16(char *dst,const char * name, mbag_item_t *i,int n)
{
if (i->type != MBAG_BSTR16){
return 0;
}
char *d = dst;
memset(d,'\t',n);
d+=n;
d+=sprintf(d,"\"%s\":",name);
d+=sprintf(d,"\"%.*s\"",bstr16_len(i->data),bstr16_data(i->data));
return d-dst;
}
int cfg_json_put_vendorstr(char *dst,const char * name, mbag_item_t *i,int n)
{
if (i->type != MBAG_VENDORSTR){
return 0;
}
char *d = dst;
memset(d,'\t',n);
d+=n;
d+=sprintf(d,"\"%s\":",name);
d+=sprintf(d,"[\"%d\",",vendorstr_get_vendor_id(i->data));
if (cw_is_utf8(vendorstr_data(i->data),vendorstr_len(i->data))){
d+=sprintf(d,"\"%.*s\"",vendorstr_len(i->data),vendorstr_data(i->data));
}
else{
d+=sprintf(d,"\".x");
d+=cw_format_hex(d,vendorstr_data(i->data),vendorstr_len(i->data));
d+=sprintf(d,"\"");
}
d+=sprintf(d,"]");
// d+=sprintf(d,"\"%.*s\",\n",bstr16_len(i->data),bstr16_data(i->data));
return d-dst;
}
int mbag_tojson(char *dst, mbag_t m, int n)
{
char *d;
d = dst;
printf("MBAG COUNT: %d\n",m->count);
memset(dst,'\t',n);
d+=n;
d+=sprintf(d,"%s","{\n");
MAVLITER_DEFINE(it,m);
const char * delim = "";
mavliter_foreach(&it) {
mbag_item_t * i = mavliter_get(&it);
struct mbag_itemdef * idef = get_idef_by_id(general_cfg,i->id);
if (idef==0){
d+=sprintf(d,"NOJai\n");
continue;
}
if (!idef->tojsonfun)
continue;
d+=sprintf(d,"%s",delim);
delim=",\n";
d+=idef->tojsonfun(d,idef->cfgname,i,n+1);
}
d+=sprintf(d,"\n");
d+=sprintf(d,"%s","}\n");
memset(dst,'\t',n);
d+=n;
return d-dst;
}
tester()
{
struct conn * conn = get_conn();
char dst[4096];
mbag_tojson(dst,conn->config,0);
printf("Json resilt:\n%s",dst);
exit(0);
struct cw_itemdef * get_cfg(struct cw_itemdef *cfg,const char *key){
}
struct mbag_itemdef * get_cfg(struct mbag_itemdef *cfg,const char *key){
int i=0;
for (i=0; cfg[i].item_id; i++){
if ( !strcmp(key,cfg[i].cfgname )) {
@ -227,15 +353,14 @@ struct cw_itemdef * get_cfg(struct cw_itemdef *cfg,const char *key){
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);
mbag_t bd = mbag_get_avltree(conn->local,CW_ITEM_WTP_BOARD_DATA);
if (!bd){
bd = cw_itemstore_create();
bd = mbag_create();
if (!bd){
return skip(t+1);
}
cw_itemstore_set_avltree(conn->local,CW_ITEM_WTP_BOARD_DATA,bd);
mbag_set_avltree(conn->local,CW_ITEM_WTP_BOARD_DATA,bd);
}
@ -248,19 +373,19 @@ printf("VB BOARD DATA!!!\n");
struct conn *get_conn();
struct cw_itemdef * idef = get_cfg(board_data_cfg,key);
struct mbag_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));
mbag_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));
mbag_set_bstr16n(bd,idef->item_id,bstr16_data(v),bstr16_len(v));
free(v);
}
@ -271,7 +396,7 @@ printf("VB BOARD DATA!!!\n");
}
int wtp_board_data_local(struct cw_itemdef *idef,char *js, jsmntok_t *t)
int wtp_board_data_local(struct mbag_itemdef *idef,char *js, jsmntok_t *t)
{
printf("Local board data\n");
@ -296,7 +421,7 @@ static int set_cfg(char *js,jsmntok_t *t){
struct cw_itemdef * idef = get_cfg(general_cfg,key);
struct mbag_itemdef * idef = get_cfg(general_cfg,key);
// printf("Key: %s\n",key);
// printf("Val: %s\n",val);
@ -354,9 +479,9 @@ int setup_conf(struct conn *conn)
void dbg_istore_dmp(cw_itemstore_t s);
//void dbg_istore_dmp(mbag_t s);
dbg_istore_dmp(conn->local);
//dbg_istore_dmp(conn->local);

View File

@ -1,52 +1,7 @@
{
"dbg":[o1,o2,o3],
"hardware_version": ["4232704",".x01000000"],
"software_version": ["4232704",".x08006E00"],
"comment": "** The following is debug info **",
"location_data": "China",
"frame_tunnel_mode": "4",
"mac_type": 2,
"group_name" : "XGroup",
"wtp_name" : "TubeWTP",
"ac_name" : "LAC_AC",
"bssid": ".x003a9902fac0",
"wtp_board_data" : {
"vendor_id": "4232704",
"model_no": "AIR-LAP1131AG-E-K9",
"serial_no": "2045"
},
"acname_with_priority": {
"1":"Master-AC",
"2":"Cisco-AC"
},
"ac": {
"Master-AC": {
}
"Cisco-AC": {
}
}
"radios": {
"1": {
"domain"
}
}
}
"wtp_name":"TubeWTP",
"hardware_version":["4232704",".x01000000"],
"software_version":["4232704",".x08006e00"],
"location_data":"China"
}

View File

@ -43,7 +43,7 @@
cw_aciplist_t cw_select_ac(struct conn *conn, cw_itemstore_t dis)
cw_aciplist_t cw_select_ac(struct conn *conn, mbag_t dis)
{
cw_aciplist_t aciplist = cw_aciplist_create();
@ -55,16 +55,16 @@ cw_aciplist_t cw_select_ac(struct conn *conn, cw_itemstore_t dis)
/* get the AC Name with Priority list */
cw_acpriolist_t priolist;
priolist = cw_itemstore_get_avltree(conn->local, CW_ITEM_AC_PRIO_LIST);
priolist = mbag_get_avltree(conn->local, CW_ITEM_AC_PRIO_LIST);
cw_aciplist_t resultlist=cw_aciplist_create();
DEFINE_AVLITER(i, dis);
avliter_foreach(&i){
cw_itemstore_t ac = ((cw_item_t *) (avliter_get(&i)))->data;
mbag_t ac = ((mbag_item_t *) (avliter_get(&i)))->data;
char *ac_name = cw_itemstore_get_str(ac, CW_ITEM_AC_NAME,NULL);
char *ac_name = mbag_get_str(ac, CW_ITEM_AC_NAME,NULL);
int prio = 256;
if (ac_name) {
@ -77,7 +77,7 @@ cw_aciplist_t cw_select_ac(struct conn *conn, cw_itemstore_t dis)
}
cw_aciplist_t acips =
cw_itemstore_get_avltree(ac, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
mbag_get_avltree(ac, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
DEFINE_AVLITER(i2, acips);
avliter_foreach(&i2){
@ -100,10 +100,11 @@ cw_aciplist_t cw_select_ac(struct conn *conn, cw_itemstore_t dis)
static int run_discovery(struct conn *conn)
{
// conn->incomming = cw_itemstore_create();
// conn->incomming = mbag_create();
conn->capwap_state = CW_STATE_DISCOVERY;
cw_itemstore_set_byte(conn->outgoing, CW_ITEM_DISCOVERY_TYPE,
mbag_set_byte(conn->outgoing, CW_ITEM_DISCOVERY_TYPE,
CW_DISCOVERY_TYPE_UNKNOWN);
@ -117,7 +118,7 @@ static int run_discovery(struct conn *conn)
while (!cw_timer_timeout(timer)
&& conn->capwap_state == CW_STATE_DISCOVERY) {
avltree_del_all(conn->incomming);
mavl_del_all(conn->incomming);
int rc = cw_read_from(conn);
@ -130,9 +131,9 @@ static int run_discovery(struct conn *conn)
}
}
cw_itemstore_t discs;
discs = cw_itemstore_get_avltree(conn->remote, CW_ITEM_DISCOVERIES);
mbag_t discs;
discs = mbag_get_avltree(conn->remote, CW_ITEM_DISCOVERIES);
printf("discs = %p\n",discs);
if (!discs) {
cw_log(LOG_ERR,"No discovery responses received");
@ -141,17 +142,26 @@ static int run_discovery(struct conn *conn)
int i;
cw_aciplist_t list = cw_select_ac(conn, discs);
printf("List is %p\n",list);
DEFINE_AVLITER(ii,list);
avliter_foreach(&ii){
cw_acip_t * ip = avliter_get(&ii);
printf("Have an IOP\n");
}
avltree_del_all(conn->remote);
printf("Nitems: %d\n",conn->remote->count);
printf("DEl: %p\n",conn->remote);
cw_itemstore_set_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST,list);
//mavl_del_all(conn->remote);
mbag_set_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST,list);
return 0;
}

View File

@ -17,7 +17,7 @@ int image_update()
const char *ii = "/c1130";
cw_itemstore_set_vendorstr(conn->outgoing, CW_ITEM_IMAGE_IDENTIFIER,
mbag_set_vendorstr(conn->outgoing, CW_ITEM_IMAGE_IDENTIFIER,
CW_VENDOR_ID_CISCO, (uint8_t *) ii, strlen(ii));

View File

@ -15,6 +15,7 @@
#include "capwap/dtls.h"
#include "capwap/aciplist.h"
#include "capwap/capwap_items.h"
#include "capwap/mbag.h"
/*
#define acinfo_log acinfo_log_
@ -184,7 +185,7 @@ 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);
cw_aciplist_t iplist = mbag_get_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
if (!iplist){
cw_log(LOG_ERR,"No IPs to join controller.");
return 0;

View File

@ -45,6 +45,9 @@ bstr_t get_base_rmac()
int main()
{
wtpconf_preinit();
if (!read_config("./wtp_uci.conf")) {
@ -59,6 +62,12 @@ int main()
mbag_t b = mbag_create();
mbag_set_byte(b,1,99);
mbag_set_avltree(b,2,mbag_create());
mavl_destroy(b);
dtls_init();
@ -88,43 +97,44 @@ int main()
////cw_register_actions_capwap_80211_wtp(&capwap_actions);
conn->actions = &capwap_actions;
conn->outgoing = cw_itemstore_create();
conn->incomming = cw_itemstore_create();
conn->local = cw_itemstore_create();
conn->outgoing = mbag_create();
conn->incomming = mbag_create();
conn->local = mbag_create();
conn->base_rmac=get_base_rmac();
conn->capwap_mode = CW_MODE_CISCO;
conn->config=mbag_create();
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);
mbag_t board_data = mbag_itemstore_create();
mbag_set_dword(board_data, CW_ITEM_WTP_BOARD_VENDOR, conf_vendor_id);
cw_itemstore_set_bstrn(board_data, CW_ITEM_WTP_BOARD_MACADDRESS, conf_macaddress,
mbag_set_bstrn(board_data, CW_ITEM_WTP_BOARD_MACADDRESS, conf_macaddress,
conf_macaddress_len);
cw_itemstore_set_bstr16n(board_data, CW_ITEM_WTP_BOARD_SERIALNO,
mbag_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);
// mbag_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);
cw_acpriolist_set(acprios,"AC8new",strlen("AC8new"),12);
cw_itemstore_set_avltree(conn->local,CW_ITEM_AC_PRIO_LIST,acprios);
mbag_set_avltree(conn->local,CW_ITEM_AC_PRIO_LIST,acprios);
cw_itemstore_set_str(conn->local,CW_ITEM_LOCATION_DATA,"Berlin");
// cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube");
mbag_set_str(conn->local,CW_ITEM_LOCATION_DATA,"Berlin");
// mbag_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube");
cw_itemstore_set_byte(conn->local,CW_ITEM_WTP_MAC_TYPE,0);
cw_itemstore_set_byte(conn->local,CW_ITEM_WTP_FRAME_TUNNEL_MODE,0);
mbag_set_byte(conn->local,CW_ITEM_WTP_MAC_TYPE,0);
mbag_set_byte(conn->local,CW_ITEM_WTP_FRAME_TUNNEL_MODE,0);
the_conn->strict_capwap=0;