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,8 +1,8 @@
#include "capwap/capwap.h"
#include "capwap/itemstore.h"
#include "capwap/mbag.h"
extern struct ac_status ac_global_status;
extern int ac_global_init();
extern cw_itemstore_t ac_config;
extern mbag_t ac_config;
extern struct cw_actiondef capwap_actions;

View File

@ -14,7 +14,7 @@ struct cw_ac_status ac_status;
struct cw_actiondef capwap_actions;
cw_itemstore_t ac_config;
mbag_t ac_config;
cw_aciplist_t get_aciplist()
@ -77,9 +77,9 @@ void release_iplist(void *arg,void *data)
int ac_global_init()
{
ac_config = cw_itemstore_create();
cw_itemstore_set_str(ac_config, CW_ITEM_AC_NAME, conf_acname);
cw_itemstore_set_ptr(ac_config, CW_ITEM_AC_STATUS, &ac_status);
ac_config = mbag_create();
mbag_set_str(ac_config, CW_ITEM_AC_NAME, conf_acname);
mbag_set_ptr(ac_config, CW_ITEM_AC_STATUS, &ac_status);
ac_status.stations = 0;
ac_status.limit = 1000;
@ -90,18 +90,18 @@ int ac_global_init()
ac_status.dtls_policy = CW_FLAG_DTLS_POLICY_C | CW_FLAG_DTLS_POLICY_D;
cw_itemstore_set_vendorstr(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0,
mbag_set_vendorstr(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0,
bstr_data(conf_hardware_version), bstr_len(conf_hardware_version));
cw_itemstore_set_vendorstr(ac_config, CW_ITEM_AC_SOFTWARE_VERSION, 0,
mbag_set_vendorstr(ac_config, CW_ITEM_AC_SOFTWARE_VERSION, 0,
bstr_data(conf_software_version), bstr_len(conf_software_version));
cw_itemstore_set_str(ac_config,CW_ITEM_AC_IMAGE_DIR,conf_image_dir);
mbag_set_str(ac_config,CW_ITEM_AC_IMAGE_DIR,conf_image_dir);
// cw_itemstore_set_avltree(ac_config, CW_ITEM_AC_IP_LIST, aciplist);
// mbag_set_avltree(ac_config, CW_ITEM_AC_IP_LIST, aciplist);
cw_itemstore_set_fun(ac_config, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, get_iplist,release_iplist,(void*)771);
mbag_set_fun(ac_config, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, get_iplist,release_iplist,(void*)771);
return 1;
}

View File

@ -131,15 +131,15 @@ conn->capwap_mode=CW_MODE_CIPWAP;
wtpman->conn->local = ac_config;
wtpman->conn->outgoing = cw_itemstore_create();
wtpman->conn->incomming = cw_itemstore_create();
wtpman->conn->outgoing = mbag_create();
wtpman->conn->incomming = mbag_create();
while (!cw_timer_timeout(timer)
&& wtpman->conn->capwap_state == CW_STATE_DISCOVERY) {
cw_read_messages(wtpman->conn);
}
struct cw_item *wn = cw_itemstore_get(wtpman->conn->incomming, CW_ITEM_WTP_NAME);
struct mbag_item *wn = mbag_get(wtpman->conn->incomming, CW_ITEM_WTP_NAME);
if (wn) {
//printf("WTP Name: %s\n", wn->data);
@ -293,10 +293,10 @@ static int wtpman_join(void *arg, time_t timer)
wtpman->conn->capwap_state = CW_STATE_JOIN;
wtpman->conn->actions = &capwap_actions;
// wtpman->conn->itemstore = cw_itemstore_create();
// wtpman->conn->itemstore = mbag_create();
wtpman->conn->outgoing = cw_itemstore_create();
wtpman->conn->incomming = cw_itemstore_create();
wtpman->conn->outgoing = mbag_create();
wtpman->conn->incomming = mbag_create();
wtpman->conn->local = ac_config;
@ -437,7 +437,7 @@ static void wtpman_run(void *arg)
if (conn->capwap_state == CW_STATE_IMAGE_DATA) {
/* Image upload */
const char *filename =
cw_itemstore_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME,NULL);
mbag_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME,NULL);
if (!filename) {
cw_log(LOG_ERR,
"Can't send image to %s. No Image Filename Item found.",
@ -458,13 +458,13 @@ static void wtpman_run(void *arg)
CLOCK_DEFINE(clk);
cw_clock_start(&clk);
cw_item_t *eof = cw_itemstore_set_const_ptr(conn->outgoing, CW_ITEM_IMAGE_FILEHANDLE,
mbag_item_t *eof = mbag_set_const_ptr(conn->outgoing, CW_ITEM_IMAGE_FILEHANDLE,
infile);
int rc=0;
while (conn->capwap_state == CW_STATE_IMAGE_DATA && rc==0 && eof!=NULL) {
rc = cw_send_request(conn, CW_MSG_IMAGE_DATA_REQUEST);
eof = cw_itemstore_get(conn->outgoing,CW_ITEM_IMAGE_FILEHANDLE);
eof = mbag_get(conn->outgoing,CW_ITEM_IMAGE_FILEHANDLE);
}

View File

@ -56,15 +56,6 @@ UTILOBJS= \
cw_setstr.o \
cw_is_printable.o \
cw_rand.o \
avltree.o \
avltree_get_node.o \
avltree_get.o \
avltree_del_all.o \
avltree_foreach_lr.o \
avltree_foreach_rl.o \
avltree_foreach_from_lr.o \
avliter_next.o \
avliter_seek.o \
stravltree.o \
intavltree.o \
cw_util.o \
@ -80,6 +71,9 @@ MAVLOBJS= \
mavl_del_all.o\
mavliter_seek.o \
mavliter_next.o \
mavl_get_node.o \
mavl_foreach.o \
mavl_foreach_lr.o \
utf8.o
# cw_foreach_msgelem.o \
@ -128,7 +122,6 @@ CAPWAPOBJS= \
capwap_strings_state.o \
capwap_strings_vendor.o \
capwap_strings_elem.o \
itemstore.o \
cw_in_vendor_specific_payload.o \
cw_in_wtp_board_data.o \
cw_in_check_disc_req.o \
@ -151,6 +144,23 @@ CAPWAPOBJS= \
cw_check_missing_mand.o \
md5sum.o \
format.o \
# avltree.o \
avltree_get_node.o \
avltree_get.o \
avltree_del_all.o \
avltree_foreach_lr.o \
avltree_foreach_rl.o \
avltree_foreach_from_lr.o \
avliter_next.o \
avliter_seek.o \
#acinfo.o \
@ -344,7 +354,7 @@ O:=$(OBJS);
OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS))
CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include
CFLAGS = -Werror -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include
#CFLAGS = -Wall -O3 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I/usr/local/include
CFLAGS += $(GNUTLS_CFLAGS) \

View File

@ -24,7 +24,7 @@
#include "avltree.h"
#include "conn.h"
#include "itemstore.h"
#include "mbag.h"
#include "strheap.h"
#include "intavltree.h"
@ -43,7 +43,8 @@ struct cw_action_in{
uint16_t elem_id;
int (*start)(struct conn *conn,struct cw_action_in *a,uint8_t*data,int len,struct sockaddr *from);
int (*end)(struct conn *conn,struct cw_action_in *a,uint8_t*elem,int len,struct sockaddr *from);
uint8_t itemtype;
// uint8_t itemtype;
const struct mbag_typedef * itemtype;
uint16_t item_id;
uint16_t min_len;
uint16_t max_len;
@ -76,9 +77,10 @@ struct cw_action_out{
uint16_t elem_id;
int (*init)(struct conn * conn, struct cw_action_out *a, uint8_t * dst);
int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst);
struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a);
struct mbag_item *(*get)(struct conn *conn,struct cw_action_out *a);
uint8_t mand;
uint8_t itemtype;
// uint8_t itemtype;
struct mbag_typedef * itemtype;
void *defval;
int xopt;

View File

@ -16,176 +16,29 @@
*/
/**
* @file
* @brief Yet another avl tree implementation!
*/
#ifndef __AVLTREE_H
#define __AVLTREE_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "mavl.h"
#include <stdint.h>
#define avltree mavl
#define avltree_get mavl_get
#define avltree_destroy mavl_destroy
#define avltree_create mavl_create
#define avltree_add mavl_add
#define avltree_del mavl_del
#define avltree_replace mavl_replace
#define avliter_foreach_from mavliter_foreach_from
#define avliter_foreach mavliter_foreach
#define avltree_foreach_asc mavl_foreach_asc
#define avliter_get mavliter_get
#define avltree_replace_data mavl_replace_data
#define avliter_seek mavliter_seek
#define avliter_seek_set mavliter_seek_set
#define avliter_next mavliter_next
#define avltree_del_all mavl_del_all
/** Maximum AVL Tree depth.
The number of nodes is calculated by 2^depth.
So a value of 32 should be enough for around 4
billion nodes. */
#define AVLTREE_MAX_DEPTH 32
/**
* Defines the structure of an AVL Node.
*/
struct avlnode {
void *data;
struct avlnode *left;
struct avlnode *right;
int bal;
};
/**
* AVL Tree
*/
struct avltree {
struct avlnode *root;
int (*cmp) (const void *, const void *);
void (*del) (void *);
int count;
};
typedef struct avltree * avltree_t;
void avlnode_destroy(struct avltree *t, struct avlnode *n);
struct avltree *avltree_create(int (*cmp) (const void *, const void *),
void (*del) (void *));
//void avltree_destroy(struct avltree *t);
void avltree_del_all(struct avltree *t);
void *avltree_del(struct avltree *t, void *data);
void *avltree_add(struct avltree *t, void *data);
void * avltree_get(struct avltree *t ,void *data);
struct avlnode *avltree_get_node(struct avltree *t, void *data);
extern int avltree_foreach_lr(struct avlnode *n, int (*callback) (void *, void *),
void *cbpriv);
extern int avltree_foreach_rl(struct avlnode *n, int (*callback) (void *, void *),
void *cbpriv);
int avltree_foreach_from_lr(struct avltree *t, struct avlnode *n, void *data,
int (*callback) (void *, void *), void *cbpriv);
//extern void avltree_foreach(struct avltree *t, int (*callback)(void *,void*),void *cbpriv,int dir);
static inline void *avltree_replace_data(struct avltree *t, void *data, int len)
{
void *df = avltree_get(t, data);
if (!df)
return NULL;
memcpy(df, data, len);
return df;
}
static inline void *avltree_replace(struct avltree *t,void *data){
struct avlnode * node = avltree_get_node(t,data);
if (node){
t->del(node->data);
return node->data=data;
}
return avltree_add(t,data);
}
static inline void avltree_destroy(struct avltree *t)
{
avltree_del_all(t);
free (t);
}
#define avltree_find(t,d) avltree_get(t,d)
#define avltree_insert(t,d) avltree_add(t,d)
//#define avltree_walk(t,dir) avltree_foreach(t,dir)
#define avltree_foreach_asc(t,cb,priv) avltree_foreach_lr((t)->root,cb,priv)
#define avltree_foreach_desc(t,cb,priv) avltree_foreach_rl((t)->root,cb,priv)
#define avltree_foreach_from_asc(t,d,cb,priv) avltree_foreach_from_lr(t,(t)->root,d,cb,priv);
struct avliter{
struct avlnode *stack[AVLTREE_MAX_DEPTH*2];
struct avlnode *cur;
int stack_ptr;
struct avlnode * root;
int (*cmp) (const void *, const void *);
};
typedef struct avliter avliter_t;
void * avliter_next(avliter_t *i);
static inline void * avliter_seek_set(struct avliter *i)
{
i->stack_ptr=0;
i->cur=i->root;
return avliter_next(i);
}
/**
* Init an AVL Tree Iterator.
*
* After initialization #avliter_next would return the first element.
* The behavior of #avliter_get would still be undefined.
* @param i AVL Iterator to initialize
* @param t correspondending AVL Tree
*
* @See avliter_t,
*/
static inline void avliter_init(avliter_t *i, avltree_t t){
i->root = t->root;
i->stack_ptr=0;
i->cmp=t->cmp;
}
/**
* Get the element, where AVL Iterator currently is positioned.
* @param i AVL Iterator
* @return element or NULL if not found.
*/
static inline void * avliter_get(avliter_t *i){
if(!i->cur)
return NULL;
return i->cur->data;
}
extern void * avliter_seek(avliter_t *i,void *d);
#define DEFINE_AVLITER(i,t)\
avliter_t i; avliter_init(&i,t)
#define avliter_foreach(i)\
for (avliter_seek_set(i); NULL != avliter_get(i); avliter_next(i))
#define avliter_foreach_from(i,from)\
for (avliter_seek(i,from); NULL != avliter_get(i); avliter_next(i))
#define avliter_foreach_asc(iter,val) \
while(NULL != (val = avliter_next(iter)))
#define DEFINE_AVLITER MAVLITER_DEFINE
#endif

View File

@ -932,7 +932,7 @@ extern struct cw_str capwap_strings_state[];
extern struct cw_str capwap_strings_vendor[];
extern struct cw_str capwap_strings_elem[];
extern struct cw_str capwap_strings_result[];
extern struct cw_str cw_item_strings[];
extern struct cw_str mbag_item_strings[];
@ -943,7 +943,7 @@ extern struct cw_str cw_item_strings[];
#define cw_strvendor(id) cw_strlist_get_str(capwap_strings_vendor,id)
#define cw_strresult(id) cw_strlist_get_str(capwap_strings_result,(id))
#define cw_stritem(id) cw_strlist_get_str(cw_item_strings,(id))
#define cw_stritem(id) cw_strlist_get_str(mbag_item_strings,(id))
/*
#define cw_strrc(rc) \
@ -1002,23 +1002,23 @@ extern int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action
uint8_t * data, int len, struct sockaddr *from);
//extern int cw_out_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //, struct cw_item *item);
extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //, struct mbag_item *item);
//extern int cw_out_ac_descriptor(struct conn *conn, uint32_t elem_id, uint8_t * dst,
//struct cw_item *item);
extern int cw_out_ac_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //,struct cw_item * item)
//struct mbag_item *item);
extern int cw_out_ac_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //,struct mbag_item * item)
extern int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
//extern int cw_out_capwap_control_ip_addrs(struct conn *conn, uint32_t elem_id,
// uint8_t * dst, struct cw_item *item);
// uint8_t * dst, struct mbag_item *item);
extern int cw_out_capwap_control_ip_addr_list(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
extern int cw_put_msg(struct conn *conn, uint8_t * rawout);
int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst); // ,struct cw_item * item)
int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst); // ,struct mbag_item * item)
struct cw_ac_status {
@ -1069,8 +1069,8 @@ int cw_register_actions_capwap_wtp(struct cw_actiondef *def);
int cw_in_set_state_none(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len);
struct cw_item *cw_out_get_outgoing(struct conn *conn, struct cw_action_out *a);
struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a);
struct mbag_item *cw_out_get_outgoing(struct conn *conn, struct cw_action_out *a);
struct mbag_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a);
extern int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len,struct sockaddr *from);
@ -1092,7 +1092,7 @@ int cw_in_check_img_data_resp(struct conn *conn, struct cw_action_in *a, uint8_t
int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
void cw_init_request(struct conn *conn, int msg_id);
struct cw_item *cw_out_get_session_id(struct conn *conn, struct cw_action_out *a);
struct mbag_item *cw_out_get_session_id(struct conn *conn, struct cw_action_out *a);

View File

@ -6,7 +6,7 @@
#define CW_ACTION_IN_80211_WTP_RADIO_INFORMATION \
CW_ELEM80211_WTP_RADIO_INFORMATION, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_STR, /* Type of element */ \
MBAG_STR, /* Type of element */ \
CW_ITEM_LOCATION_DATA, /* ID to use store */ \
5, 5 /* min/max length */

View File

@ -12,19 +12,19 @@ int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data
}
struct cw_item *cw_out_get_outgoing(struct conn *conn, struct cw_action_out *a)
struct mbag_item *cw_out_get_outgoing(struct conn *conn, struct cw_action_out *a)
{
return cw_itemstore_get(conn->outgoing, a->item_id);
return mbag_get(conn->outgoing, a->item_id);
}
struct cw_item *cw_out_get_incomming(struct conn *conn, struct cw_action_out *a)
struct mbag_item *cw_out_get_incomming(struct conn *conn, struct cw_action_out *a)
{
return cw_itemstore_get(conn->incomming, a->item_id);
return mbag_get(conn->incomming, a->item_id);
}
struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a)
struct mbag_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a)
{
return cw_itemstore_get(conn->local,a->item_id);
return mbag_get(conn->local,a->item_id);
}
@ -35,7 +35,7 @@ struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a)
#include "log.h"
#include "rand.h"
struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a)
struct mbag_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a)
{
uint8_t session_id[16];
@ -51,6 +51,6 @@ struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out *
cw_log(LOG_ERR,"Can't init session ID.");
return NULL;
}
return cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,slen);
return mbag_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,slen);
}

View File

@ -27,7 +27,7 @@
#define CW_ACTION_IN_LOCATION_DATA \
CW_ELEM_LOCATION_DATA, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_STR, /* Type of element */ \
MBAG_STR, /* Type of element */ \
CW_ITEM_LOCATION_DATA, /* ID to use store */ \
1, 1024 /* min/max length */
@ -35,42 +35,42 @@
#define CW_ACTION_IN_WTP_NAME \
CW_ELEM_WTP_NAME, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_STR, /* Type of element */ \
MBAG_STR, /* Type of element */ \
CW_ITEM_WTP_NAME, /* ID to use store */ \
1, 1024 /* min/max length */
#define CW_ACTION_IN_SESSION_ID \
CW_ELEM_SESSION_ID, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_BSTR, /* Type of element */ \
MBAG_BSTR, /* Type of element */ \
CW_ITEM_SESSION_ID, /* ID to use store */ \
16, 16 /* min/max length */
#define CW_ACTION_IN_IMAGE_IDENTIFIER \
CW_ELEM_IMAGE_IDENTIFIER, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_VENDORSTR, /* Type of element */ \
MBAG_VENDORSTR, /* Type of element */ \
CW_ITEM_IMAGE_IDENTIFIER, /* ID to use store */ \
5, 4096 /* min/max length */
#define CW_ACTION_IN_AC_NAME \
CW_ELEM_AC_NAME, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_STR, /* Type of element */ \
MBAG_STR, /* Type of element */ \
CW_ITEM_AC_NAME, /* ID to use store */ \
1, 512 /* min/max length */
#define CW_ACTION_IN_STATISTICS_TIMER \
CW_ELEM_STATISTICS_TIMER, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_DWORD, /* Type of element */ \
MBAG_DWORD, /* Type of element */ \
CW_ITEM_STATISTICS_TIMER, /* ID to use store */ \
1, 1024 /* min/max length */
#define CW_ACTION_IN_WTP_REBOOT_STATISTICS \
CW_ELEM_WTP_REBOOT_STATISTICS, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_DATA, /* Type of element */ \
MBAG_DATA, /* Type of element */ \
CW_ITEM_WTP_REBOOT_STATISTICS, /* ID to use store */ \
15, 15 /* min/max length */
@ -78,7 +78,7 @@
#define CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE \
CW_ELEM_WTP_FRAME_TUNNEL_MODE, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_BYTE, /* Type of element */ \
MBAG_BYTE, /* Type of element */ \
CW_ITEM_WTP_FRAME_TUNNEL_MODE, /* ID to use store */ \
1, 1 /* min/max length */
@ -86,7 +86,7 @@
#define CW_ACTION_IN_WTP_MAC_TYPE \
CW_ELEM_WTP_MAC_TYPE, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_BYTE, /* Type of element */ \
MBAG_BYTE, /* Type of element */ \
CW_ITEM_WTP_MAC_TYPE, /* ID to use store */ \
1, 1 /* min/max length */
@ -115,14 +115,14 @@
#define CW_ACTION_IN_CAPWAP_CONTROL_IPV4_ADDRESS \
CW_ELEM_CAPWAP_CONTROL_IPV4_ADDRESS, /* Element ID*/ \
cw_in_capwap_control_ipv4_address, 0, /* start/end callback */ \
CW_ITEMTYPE_AVLTREE, /* Type of element */ \
MBAG_AVLTREE, /* Type of element */ \
CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, /* ID to use store */ \
6, 6 /* min/max length */
#define CW_ACTION_IN_CAPWAP_CONTROL_IPV6_ADDRESS \
CW_ELEM_CAPWAP_CONTROL_IPV6_ADDRESS, /* Element ID*/ \
cw_in_capwap_control_iv4p_address, 0, /* start/end callback */ \
CW_ITEMTYPE_AVLTREE, /* Type of element */ \
MBAG_AVLTREE, /* Type of element */ \
CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, /* ID to use store */ \
18,18 /* min/max length */
@ -131,7 +131,7 @@
#define CW_ACTION_IN_AC_DESCRIPTOR \
CW_ELEM_AC_DESCRIPTOR, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_DATA, /* Type of element */ \
MBAG_DATA, /* Type of element */ \
CW_ITEM_AC_DESCRIPTOR, /* ID to use store */ \
12, 8192 /* min/max length */
@ -139,7 +139,7 @@
#define CW_ACTION_IN_RESULT_CODE \
CW_ELEM_RESULT_CODE, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_DWORD, /* Type of element */ \
MBAG_DWORD, /* Type of element */ \
CW_ITEM_RESULT_CODE, /* ID to use store */ \
4, 4 /* min/max length */

View File

@ -37,7 +37,7 @@ cw_action_in_t capwap_actions_ac_in[] = {
/* Element Discovery Type */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ELEM_DISCOVERY_TYPE,
cw_in_generic, 0, CW_ITEMTYPE_BYTE, CW_ITEM_DISCOVERY_TYPE, 1, 1, 1}
cw_in_generic, 0, MBAG_BYTE, CW_ITEM_DISCOVERY_TYPE, 1, 1, 1}
,
/* Element Frame Tunnel Mode */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST,

View File

@ -12,7 +12,7 @@
#define CW_ACTION_IN_CISCO_IMAGE_IDENTIFIER \
CW_ELEM_IMAGE_IDENTIFIER, /* Element ID*/ \
cw_in_cisco_image_identifier, 0, /* start/end callback */ \
CW_ITEMTYPE_VENDORSTR, /* Type of element */ \
MBAG_VENDORSTR, /* Type of element */ \
CW_ITEM_IMAGE_IDENTIFIER, /* ID to use store */ \
1, 4096 /* min/max length */
@ -28,14 +28,14 @@
#define CW_ACTION_IN_CIPWAP_SESSION_ID \
CW_ELEM_SESSION_ID, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_BSTR, /* Type of element */ \
MBAG_BSTR, /* Type of element */ \
CW_ITEM_SESSION_ID, /* ID to use store */ \
2, 16 /* min/max length */
#define CW_ACTION_IN_CIPWAP_AC_NAME \
CW_ELEM_AC_NAME, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_STR, /* Type of element */ \
MBAG_STR, /* Type of element */ \
CW_ITEM_AC_NAME, /* ID to use store */ \
0, 512 /* min/max length */
@ -49,11 +49,11 @@ cw_action_in_t cipwap_actions_ac_in[] = {
*/
{CW_VENDOR_ID_CISCO, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_CISCO_RAD_NAME,
cw_in_generic, 0, CW_ITEMTYPE_STR,CW_ITEM_WTP_NAME,1,512}
cw_in_generic, 0, MBAG_STR,CW_ITEM_WTP_NAME,1,512}
,
{CW_VENDOR_ID_CISCO, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_CISCO_AP_GROUP_NAME,
cw_in_generic, 0, CW_ITEMTYPE_STR,CW_ITEM_WTP_GROUP_NAME,1,512}
cw_in_generic, 0, MBAG_STR,CW_ITEM_WTP_GROUP_NAME,1,512}
,
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST,

View File

@ -37,7 +37,7 @@
#include "action.h"
#include "itemstore.h"
#include "mbag.h"
#include "intavltree.h"
#include "mbag.h"
@ -50,12 +50,14 @@ struct conn {
struct sockaddr_storage addr;
int recv_timeout;
cw_itemstore_t outgoing;
cw_itemstore_t incomming;
cw_itemstore_t remote;
cw_itemstore_t local;
mbag_t outgoing;
mbag_t incomming;
mbag_t remote;
mbag_t local;
mbag_t radios;
mbag_t config;
/** base_mac */
bstr_t base_rmac;

View File

@ -39,7 +39,7 @@ void conn_init(struct conn * conn)
conn->wait_dtls=CAPWAP_WAIT_DTLS;
conn->wait_join=CAPWAP_WAIT_JOIN;
conn->mtu_discovery=1;
conn->remote = cw_itemstore_create();
conn->remote = mbag_create();
conn->capwap_mode = CW_MODE_UNKNOWN;
conn->strict_capwap=1;
}

View File

@ -10,7 +10,7 @@
#include "action.h"
#include "log.h"
#include "itemstore.h"
#include "mbag.h"
#include "capwap.h"
#include "capwap_items.h"
#include "aciplist.h"
@ -22,7 +22,7 @@ int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len,struct sockaddr *from)
{
cw_aciplist_t list =
cw_itemstore_get_avltree_c(conn->incomming,a->item_id,cw_aciplist_create);
mbag_get_avltree_c(conn->incomming,a->item_id,cw_aciplist_create);
if (!list) {
cw_log(LOG_ERR, "Error: Can't allocate CAWAP IP Adress List");

View File

@ -8,7 +8,7 @@
#include "sock.h" //tube
cw_get_wtp_name(struct conn *conn,struct sockaddr *addr)
void cw_get_wtp_name(struct conn *conn,struct sockaddr *addr)
{
}
@ -17,14 +17,15 @@ int cw_set_capwap_mode(struct conn *conn,int mode)
{
cw_dbg(DBG_INFO,"Setting CAPWAP mode to %d for %s",mode,sock_addr2str(&conn->addr));
conn->capwap_mode_out=mode;
return 1;
}
int cw_detect_capwap(struct conn *conn)
{
cw_itemstore_t is = conn->incomming;
mbag_t is = conn->incomming;
cw_item_t * item = cw_itemstore_get(is,CW_ITEM_WTP_SOFTWARE_VERSION);
mbag_item_t * item = mbag_get(is,CW_ITEM_WTP_SOFTWARE_VERSION);
if (item) {
vendorstr_t s = item->data;
uint32_t v = vendorstr_get_vendor_id(s);

View File

@ -30,10 +30,10 @@ int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * d
}
/* we have all AC information in the incomming buffer */
cw_itemstore_t discs;
mbag_t discs;
discs = cw_itemstore_get_avltree_c(conn->remote, CW_ITEM_DISCOVERIES,
cw_itemstore_create);
discs = mbag_get_avltree_c(conn->remote, CW_ITEM_DISCOVERIES,
mbag_create);
if ( !discs ) {
cw_log(LOG_ERR,"Can't allocate store for disc resp");
@ -41,8 +41,8 @@ int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * d
return -1;
}
cw_itemstore_set_avltree(discs,discs->count,conn->incomming);
conn->incomming = cw_itemstore_create();
mbag_set_avltree(discs,discs->count,conn->incomming);
conn->incomming = mbag_create();
return 0;

View File

@ -20,12 +20,12 @@ int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8
}
struct cw_item *i = cw_itemstore_get(conn->incomming,CW_ITEM_IMAGE_IDENTIFIER);
struct mbag_item *i = mbag_get(conn->incomming,CW_ITEM_IMAGE_IDENTIFIER);
if (i) {
uint32_t vendor_id = vendorstr_get_vendor_id(i->data);
const char * image_dir;
image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR,"./img");
image_dir = mbag_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR,"./img");
char * image_filename = malloc(6+vendorstr_len(i->data)+1+strlen(image_dir));
if (!image_filename)
@ -42,8 +42,8 @@ int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8
return CW_RESULT_IMAGE_DATA_ERROR;
}
cw_itemstore_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename);
cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
mbag_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename);
mbag_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
conn->capwap_state=CW_STATE_IMAGE_DATA;
return 0;
}

View File

@ -12,7 +12,7 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint
int len,struct sockaddr *from)
{
cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
mbag_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
conn->capwap_state=CW_STATE_IMAGE_DATA;
//usleep(100000);
return 0;
@ -31,12 +31,12 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint
}
struct cw_item *i = cw_itemstore_get(conn->incomming,CW_ITEM_IMAGE_IDENTIFIER);
struct mbag_item *i = mbag_get(conn->incomming,CW_ITEM_IMAGE_IDENTIFIER);
if (i) {
uint32_t vendor_id = vendorstr_get_vendor_id(i->data);
const char * image_dir;
image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR,"./img");
image_dir = mbag_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR,"./img");
char * image_filename = malloc(6+vendorstr_len(i->data)+1+strlen(image_dir));
if (!image_filename)
@ -53,8 +53,8 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint
return CW_RESULT_IMAGE_DATA_ERROR;
}
cw_itemstore_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename);
cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
mbag_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename);
mbag_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
conn->capwap_state=CW_STATE_IMAGE_DATA;
return 0;
}

View File

@ -23,7 +23,7 @@ int cw_in_check_img_data_resp(struct conn *conn, struct cw_action_in *a, uint8_t
cw_item_t * iresult = cw_itemstore_get(conn->incomming, CW_ITEM_RESULT_CODE);
mbag_item_t * iresult = mbag_get(conn->incomming, CW_ITEM_RESULT_CODE);
if ( iresult ) {
return iresult->dword;

View File

@ -24,7 +24,7 @@ int cw_in_check_join_req(struct conn *conn, struct cw_action_in *a, uint8_t * da
/* set result code to ok and change to configure state */
cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
mbag_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
conn->capwap_state = CW_STATE_CONFIGURE;
return 0;

View File

@ -24,14 +24,14 @@ int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a, uint8_t * d
cw_item_t * jresult = cw_itemstore_get(conn->incomming, CW_ITEM_RESULT_CODE);
mbag_item_t * jresult = mbag_get(conn->incomming, CW_ITEM_RESULT_CODE);
if ( jresult ) {
return jresult->dword;
}
/* set result code to ok and change to configure state */
// cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
// mbag_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
return 0;
}

View File

@ -1,7 +1,7 @@
#include "action.h"
#include "dbg.h"
#include "itemstore.h"
#include "mbag.h"
#include "capwap.h"
#include "capwap_cisco.h"
@ -30,8 +30,8 @@ int cw_in_cisco_image_identifier(struct conn *conn,struct cw_action_in * a,uint8
dstart=0;
}
// cw_itemstore_set(conn->remote,a->item_id,a->itemtype,data+dstart,len);
cw_itemstore_set_vendorstr(conn->incomming,a->item_id,vendor_id,data+dstart,len);
// mbag_set(conn->remote,a->item_id,a->itemtype,data+dstart,len);
mbag_set_vendorstr(conn->incomming,a->item_id,vendor_id,data+dstart,len);
return 1;
}

View File

@ -2,53 +2,68 @@
#include "action.h"
#include "dbg.h"
#include "log.h"
#include "itemstore.h"
#include "mbag.h"
#include "capwap.h"
int cw_in_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len,struct sockaddr *from)
int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
if (len<a->min_len) {
cw_dbg(DBG_ELEM_ERR,"%d (%s) message element too short, lan=%d, min len=%d", a->elem_id, cw_strelemp(conn->actions,a->elem_id),len,a->min_len);
if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, lan=%d, min len=%d",
a->elem_id, cw_strelemp(conn->actions, a->elem_id), len,
a->min_len);
return 0;
}
if (len>a->max_len) {
cw_dbg(DBG_ELEM_ERR,"%d (%s) message element too big, len=%d, max len=%d", a->elem_id, cw_strelemp(conn->actions,a->elem_id),len,a->max_len);
if (len > a->max_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too big, len=%d, max len=%d", a->elem_id,
cw_strelemp(conn->actions, a->elem_id), len, a->max_len);
return 0;
}
cw_itemstore_t itemstore = conn->incomming;
switch (a->itemtype) {
case CW_ITEMTYPE_BYTE:
cw_itemstore_set_byte(itemstore,a->item_id,*data);
break;
case CW_ITEMTYPE_WORD:
cw_itemstore_set_word(itemstore,a->item_id,cw_get_word(data));
break;
case CW_ITEMTYPE_DWORD:
cw_itemstore_set_dword(itemstore,a->item_id,cw_get_dword(data));
break;
case CW_ITEMTYPE_STR:
cw_itemstore_set_strn(itemstore,a->item_id,(char*)data,len);
break;
case CW_ITEMTYPE_BSTR:
cw_itemstore_set_bstrn(itemstore,a->item_id,data,len);
break;
case CW_ITEMTYPE_DATA:
cw_itemstore_set_data(itemstore,a->item_id,data,len);
break;
case CW_ITEMTYPE_VENDORSTR:
cw_itemstore_set_vendorstr(itemstore,a->item_id,
cw_get_dword(data),data+4,len-4);
default:
cw_log(LOG_ERR,"Can't handle item type %d in definition for incomming msg %d (%s) - %d, cw_in_generic.", a->itemtype,a->msg_id,cw_strmsg(a->msg_id), a->elem_id);
return 0;
}
mbag_t itemstore = conn->incomming;
if (a->itemtype == MBAG_BYTE) {
mbag_set_byte(itemstore, a->item_id, *data);
return 1;
}
if (a->itemtype == MBAG_WORD) {
mbag_set_word(itemstore, a->item_id, cw_get_word(data));
return 1;
}
if (a->itemtype == MBAG_DWORD) {
mbag_set_dword(itemstore, a->item_id, cw_get_dword(data));
return 1;
}
if (a->itemtype == MBAG_STR) {
mbag_set_strn(itemstore, a->item_id, (char *) data, len);
return 1;
}
if (a->itemtype == MBAG_BSTR) {
mbag_set_bstrn(itemstore, a->item_id, data, len);
return 1;
}
/* if (a->itemtype == MBAG_DATA) {
mbag_set_data(itemstore, a->item_id, data, len);
return 1;
}
*/
if (a->itemtype == MBAG_VENDORSTR) {
mbag_set_vendorstr(itemstore, a->item_id,
cw_get_dword(data), data + 4, len - 4);
return 1;
}
cw_log(LOG_ERR,
"Can't handle item type %d in definition for incomming msg %d (%s) - %d, cw_in_generic.",
a->itemtype, a->msg_id, cw_strmsg(a->msg_id), a->elem_id);
return 0;
return 1;
}

View File

@ -26,14 +26,14 @@
#include "capwap.h"
#include "capwap_items.h"
#include "itemstore.h"
#include "mbag.h"
#include "cw_util.h"
#include "dbg.h"
static void readsubelems_wtp_board_data(cw_itemstore_t itemstore, uint8_t * msgelem,
static void readsubelems_wtp_board_data(mbag_t itemstore, uint8_t * msgelem,
int len)
{
if (len<4)
@ -58,28 +58,28 @@ static void readsubelems_wtp_board_data(cw_itemstore_t itemstore, uint8_t * msge
switch (subtype) {
case CW_BOARDDATA_MODELNO:
cw_itemstore_set_bstrn(itemstore,
mbag_set_bstrn(itemstore,
CW_ITEM_WTP_BOARD_MODELNO,
msgelem + i, sublen);
break;
case CW_BOARDDATA_SERIALNO:
cw_itemstore_set_bstrn(itemstore,
mbag_set_bstrn(itemstore,
CW_ITEM_WTP_BOARD_SERIALNO,
msgelem + i, sublen);
break;
case CW_BOARDDATA_MACADDRESS:
cw_itemstore_set_bstrn(itemstore,
mbag_set_bstrn(itemstore,
CW_ITEM_WTP_BOARD_MACADDRESS,
msgelem + i, sublen);
break;
case CW_BOARDDATA_BOARDID:
cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID,
mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID,
msgelem + i, sublen);
break;
case CW_BOARDDATA_REVISION:
cw_itemstore_set_bstrn(itemstore,
mbag_set_bstrn(itemstore,
CW_ITEM_WTP_BOARD_REVISION,
msgelem + i, sublen);
default:
@ -105,8 +105,8 @@ int cw_in_wtp_board_data(struct conn *conn, struct cw_action_in *a, uint8_t * da
return 0;
}
cw_itemstore_t itemstore = conn->incomming;
cw_itemstore_set_dword(itemstore, CW_ITEM_WTP_BOARD_VENDOR, cw_get_dword(data));
mbag_t itemstore = conn->incomming;
mbag_set_dword(itemstore, CW_ITEM_WTP_BOARD_VENDOR, cw_get_dword(data));
readsubelems_wtp_board_data(itemstore, data + 4, len - 4);

View File

@ -28,7 +28,7 @@
#include "sock.h"
static int cw_read_wtp_descriptor_versions(cw_itemstore_t itemstore, uint8_t * data,
static int cw_read_wtp_descriptor_versions(mbag_t itemstore, uint8_t * data,
int len, int silent)
{
int i = 0;
@ -74,33 +74,33 @@ static int cw_read_wtp_descriptor_versions(cw_itemstore_t itemstore, uint8_t * d
switch (subtype) {
case CW_SUBELEM_WTP_HARDWARE_VERSION:
cw_itemstore_set_dword(itemstore,
mbag_set_dword(itemstore,
CW_ITEM_WTP_HARDWARE_VENDOR,
vendor_id);
cw_itemstore_set_bstrn(itemstore,
mbag_set_bstrn(itemstore,
CW_ITEM_WTP_HARDWARE_VERSION,
data + i, sublen);
break;
case CW_SUBELEM_WTP_SOFTWARE_VERSION:
cw_itemstore_set_vendorstr(itemstore,
mbag_set_vendorstr(itemstore,
CW_ITEM_WTP_SOFTWARE_VERSION,
vendor_id, data + i, sublen);
/*
cw_itemstore_set_dword(itemstore,
mbag_set_dword(itemstore,
CW_ITEM_WTP_SOFTWARE_VENDOR,
vendor_id);
cw_itemstore_set_bstrn(itemstore,
mbag_set_bstrn(itemstore,
CW_ITEM_WTP_SOFTWARE_VERSION,
data + i, sublen);
*/
break;
case CW_SUBELEM_WTP_BOOTLOADER_VERSION:
cw_itemstore_set_dword(itemstore,
mbag_set_dword(itemstore,
CW_ITEM_WTP_BOOTLOADER_VENDOR,
vendor_id);
cw_itemstore_set_bstrn(itemstore,
mbag_set_bstrn(itemstore,
CW_ITEM_WTP_BOOTLOADER_VERSION,
data + i, sublen);
break;
@ -119,14 +119,14 @@ static int cw_read_wtp_descriptor_versions(cw_itemstore_t itemstore, uint8_t * d
}
static int cw_read_wtp_descriptor(cw_itemstore_t itemstore, struct conn *conn,
static int cw_read_wtp_descriptor(mbag_t itemstore, struct conn *conn,
struct cw_action_in *a, uint8_t * data, int len,
int silent)
{
cw_itemstore_set_byte(itemstore, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
cw_itemstore_set_byte(itemstore, CW_ITEM_WTP_RADIOS_IN_USE,
mbag_set_byte(itemstore, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
mbag_set_byte(itemstore, CW_ITEM_WTP_RADIOS_IN_USE,
cw_get_byte(data + 1));
@ -161,13 +161,13 @@ static int cw_read_wtp_descriptor(cw_itemstore_t itemstore, struct conn *conn,
* Read WTP Descriptor in Cisco-Style (Draft 7)
*/
static int cw_read_cisco_wtp_descriptor(cw_itemstore_t itemstore, struct conn *conn,
static int cw_read_cisco_wtp_descriptor(mbag_t itemstore, struct conn *conn,
struct cw_action_in *a, uint8_t * data, int len,
int silent)
{
cw_itemstore_set_byte(itemstore, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
cw_itemstore_set_byte(itemstore, CW_ITEM_WTP_RADIOS_IN_USE,
mbag_set_byte(itemstore, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
mbag_set_byte(itemstore, CW_ITEM_WTP_RADIOS_IN_USE,
cw_get_byte(data + 1));
@ -191,7 +191,7 @@ static int cw_read_cisco_wtp_descriptor(cw_itemstore_t itemstore, struct conn *c
int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len, struct sockaddr *from)
{
cw_itemstore_t itemstore = conn->incomming;
mbag_t itemstore = conn->incomming;
return cw_read_wtp_descriptor(itemstore, conn, a, data, len, 0);
}
@ -201,7 +201,7 @@ int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * da
int cw_in_cipwap_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len, struct sockaddr *from)
{
cw_itemstore_t itemstore = conn->incomming;
mbag_t itemstore = conn->incomming;
switch (conn->capwap_mode) {
case CW_MODE_CISCO:

View File

@ -1,7 +1,7 @@
#include "log.h"
#include "conn.h"
#include "itemstore.h"
#include "mbag.h"
#include "capwap_items.h"
#include "capwap.h"
@ -23,8 +23,8 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst
{
uint8_t *d = dst+4;
struct cw_item * i;
i = cw_itemstore_get(conn->local,CW_ITEM_AC_STATUS);
struct mbag_item * i;
i = mbag_get(conn->local,CW_ITEM_AC_STATUS);
if (!i) {
cw_log(LOG_ERR,"Can't send AC Descriptor, no AC Status Item found");
@ -35,7 +35,7 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst
i = cw_itemstore_get(conn->local,CW_ITEM_AC_HARDWARE_VERSION);
i = mbag_get(conn->local,CW_ITEM_AC_HARDWARE_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_AC_HARDWARE_VERSION,i->data);
}
@ -44,7 +44,7 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst
}
i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION);
i = mbag_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,i->data);

View File

@ -43,7 +43,7 @@ static int put_ip(void *priv, void *data)
int cw_out_capwap_control_ip_addr_list(struct conn *conn,struct cw_action_out *a,uint8_t *dst)
{
struct cw_item * item = cw_itemstore_get(conn->local,a->item_id);
struct mbag_item * item = mbag_get(conn->local,a->item_id);
if ( !item ) {
cw_log(LOG_ERR, "Can't send CAPWAP Local IPv4/IPv6 Address, not found");
@ -51,13 +51,13 @@ int cw_out_capwap_control_ip_addr_list(struct conn *conn,struct cw_action_out *a
}
cw_aciplist_t aciplist = (cw_aciplist_t) cw_item_get_data_ptr(item);
cw_aciplist_t aciplist = (cw_aciplist_t) mbag_item_get_data_ptr(item);
uint8_t *d = dst;
cw_aciplist_foreach(aciplist, put_ip, &d);
cw_item_release_data_ptr(item,aciplist);
mbag_item_release_data_ptr(item,aciplist);
return d-dst;
}

View File

@ -1,7 +1,7 @@
#include "log.h"
#include "conn.h"
#include "itemstore.h"
#include "mbag.h"
#include "capwap_items.h"
#include "capwap.h"
@ -10,8 +10,8 @@ int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_
{
uint8_t *d = dst+4;
struct cw_item * i;
i = cw_itemstore_get(conn->local,CW_ITEM_AC_STATUS);
struct mbag_item * i;
i = mbag_get(conn->local,CW_ITEM_AC_STATUS);
if (!i) {
cw_log(LOG_ERR,"Can't send AC Descriptor, no AC Status Item found");
@ -21,7 +21,7 @@ int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_
d+=cw_put_ac_status(d ,(struct cw_ac_status*)(i->data));
i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION);
i = mbag_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION);
if ( i ) {
d += cw_put_version(d,5,i->data);

View File

@ -8,42 +8,47 @@
#include "log.h"
int cw_put_item(uint8_t * dst, struct cw_item *item)
int cw_put_item(uint8_t * dst, struct mbag_item *item)
{
switch (item->type) {
case CW_ITEMTYPE_STR:
return cw_put_data(dst, item->data, strlen((char *) item->data));
case CW_ITEMTYPE_BYTE:
return cw_put_byte(dst, item->byte);
case CW_ITEMTYPE_WORD:
return cw_put_word(dst, item->word);
case CW_ITEMTYPE_DWORD:
return cw_put_dword(dst, item->dword);
case CW_ITEMTYPE_BSTR:
return cw_put_bstr(dst, item->data);
case CW_ITEMTYPE_BSTR16:
return cw_put_bstr16(dst,item->data);
case CW_ITEMTYPE_VENDORSTR:
{
int l=0;
l+=cw_put_dword(dst, vendorstr_get_vendor_id(item->data));
l+=cw_put_data(dst+4, vendorstr_data(item->data),vendorstr_len(item->data));
return l;
}
default:
cw_log(LOG_ERR,"No method to put items of type %d",item->type);
if (MBAG_STR == item->type ){
return cw_put_data(dst, item->data, strlen((char *) item->data));
}
if (MBAG_BYTE == item->type){
return cw_put_byte(dst, item->byte);
}
if (MBAG_WORD == item->type){
return cw_put_word(dst, item->word);
}
if (MBAG_DWORD == item->type){
return cw_put_dword(dst, item->dword);
}
if (MBAG_BSTR == item->type) {
return cw_put_bstr(dst, item->data);
}
if ( MBAG_BSTR16 == item->type)
return cw_put_bstr16(dst,item->data);
if (MBAG_VENDORSTR == item->type)
{
int l=0;
l+=cw_put_dword(dst, vendorstr_get_vendor_id(item->data));
l+=cw_put_data(dst+4, vendorstr_data(item->data),vendorstr_len(item->data));
return l;
}
cw_log(LOG_ERR,"No method to put items of type %d",item->type);
return 0;
}
int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // ,struct cw_item * item)
int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // ,struct mbag_item * item)
{
/* Get the item to put */
struct cw_item *item = NULL;
struct mbag_item *item = NULL;
if (a->get) {
item = a->get(conn, a);
}

View File

@ -19,7 +19,7 @@
int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
cw_item_t * item = cw_itemstore_get(conn->outgoing,CW_ITEM_IMAGE_FILEHANDLE);
mbag_item_t * item = mbag_get(conn->outgoing,CW_ITEM_IMAGE_FILEHANDLE);
if (!item) {
cw_log(LOG_ERR,"Can't put element Image Data, no image filehandle found");
return 0;

View File

@ -1,22 +1,22 @@
#include "log.h"
#include "conn.h"
#include "itemstore.h"
#include "mbag.h"
#include "capwap_items.h"
#include "capwap.h"
int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
cw_itemstore_t board_data =
cw_itemstore_get_avltree(conn->local, CW_ITEM_WTP_BOARD_DATA);
mbag_t board_data =
mbag_get_avltree(conn->local, CW_ITEM_WTP_BOARD_DATA);
if (!board_data) {
cw_log(LOG_ERR, "Error: Can't send WTP Board Data element. WTP Board Data is not defined.");
return 0;
}
struct cw_item *i;
i = cw_itemstore_get(board_data, CW_ITEM_WTP_BOARD_VENDOR);
struct mbag_item *i;
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_VENDOR);
if (!i) {
cw_log(LOG_ERR,
"Error: Can't send WTP Board Data element - no vendor defined");
@ -26,7 +26,7 @@ int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t *
uint8_t *d = dst + 4;
d += cw_put_dword(d, i->dword);
i = cw_itemstore_get(board_data, CW_ITEM_WTP_BOARD_MODELNO);
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_MODELNO);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_MODELNO);
d += cw_put_word(d, bstr16_len(i->data));
@ -36,7 +36,7 @@ int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t *
"Error: Can't set sub-element \"WTP Model Number\" in WTP Board Data.");
}
i = cw_itemstore_get(board_data, CW_ITEM_WTP_BOARD_SERIALNO);
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_SERIALNO);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_SERIALNO);
d += cw_put_word(d, bstr16_len(i->data));
@ -47,21 +47,21 @@ int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t *
}
i = cw_itemstore_get(board_data, CW_ITEM_WTP_BOARD_ID);
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_ID);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_BOARDID);
d += cw_put_word(d, bstr16_len(i->data));
d += cw_put_data(d, bstr16_data(i->data), bstr16_len(i->data));
}
i = cw_itemstore_get(board_data, CW_ITEM_WTP_BOARD_REVISION);
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_REVISION);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_REVISION);
d += cw_put_word(d, bstr16_len(i->data));
d += cw_put_data(d, bstr16_data(i->data), bstr16_len(i->data));
}
i = cw_itemstore_get(board_data, CW_ITEM_WTP_BOARD_MACADDRESS);
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_MACADDRESS);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_MACADDRESS);
d += cw_put_word(d, bstr_len(i->data));

View File

@ -1,7 +1,7 @@
#include "log.h"
#include "conn.h"
#include "itemstore.h"
//#include "itemstore.h"
#include "capwap_items.h"
#include "capwap.h"
@ -28,6 +28,9 @@ return 2;
int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
mbag_t mbag = conn->config;
// XXX Dummy WTP Descriptor Header
uint8_t *d = dst+4;
@ -35,8 +38,8 @@ int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t *
d+=cw_put_byte(d,2); //radios in use
d+=cw_put_encryption_subelems(d);
cw_item_t * i;
i = cw_itemstore_get(conn->local,CW_ITEM_WTP_HARDWARE_VERSION);
mbag_item_t * i;
i = mbag_get(mbag,CW_ITEM_WTP_HARDWARE_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_HARDWARE_VERSION,i->data);
}
@ -44,7 +47,7 @@ int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t *
cw_log(LOG_ERR, "Can't send Hardware Version in WTP Descriptor, not set.");
}
i = cw_itemstore_get(conn->local,CW_ITEM_WTP_SOFTWARE_VERSION);
i = mbag_get(mbag,CW_ITEM_WTP_SOFTWARE_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_SOFTWARE_VERSION,i->data);
}

View File

@ -498,25 +498,26 @@ void cw_dbg_colored(int level, const char *file, int line, const char *format, .
int cw_is_utf8(unsigned char *str, size_t len);
int cw_format_item(char *dst,cw_item_t * item)
int cw_format_item(char *dst,mbag_item_t * item)
{
*dst=0;
switch (item->type) {
case CW_ITEMTYPE_BSTR16:
if (item->type==MBAG_BSTR16){
strncpy(dst,bstr16_data(item->data),bstr16_len(item->data));
*(dst+bstr16_len(item->data))=0;
return bstr16_len(item->data);
}
return 0;
}
void dbg_istore_dmp(cw_itemstore_t s)
/*
void dbg_istore_dmp(mbag_t s)
{
DEFINE_AVLITER(it,s);
avliter_foreach(&it) {
cw_item_t *i = avliter_get(&it);
mbag_item_t *i = avliter_get(&it);
char buffer[1000];
@ -532,7 +533,7 @@ void dbg_istore_dmp(cw_itemstore_t s)
}
*/
/**@}*/

View File

@ -23,6 +23,8 @@
#ifndef __CW_FORMAT_H
#define __CW_FORMAT_H
#include "capwap.h"
extern int cw_format_hex_bytes(char *dst, const char *format, const char *delim,
const uint8_t * src, int len);

View File

@ -1,299 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include "itemstore.h"
#include "capwap.h"
static inline void cw_itemstore_del_data(void *e)
{
struct cw_item *item = (struct cw_item *) e;
switch (item->type) {
case CW_ITEMTYPE_DATA:
case CW_ITEMTYPE_STR:
case CW_ITEMTYPE_BSTR:
case CW_ITEMTYPE_BSTR16:
case CW_ITEMTYPE_VENDORSTR:
case CW_ITEMTYPE_FUN:
free(item->data);
break;
case CW_ITEMTYPE_AVLTREE:
avltree_destroy(item->data);
}
}
static void cw_itemstore_del(void *e)
{
cw_itemstore_del_data(e);
free(e);
}
static int cw_itemstore_cmp(const void *x1, const void *x2)
{
return ((struct cw_item *) x1)->id - ((struct cw_item *) x2)->id;
}
cw_itemstore_t cw_itemstore_create()
{
return avltree_create(cw_itemstore_cmp, cw_itemstore_del);
}
struct cw_item *cw_item_create(cw_itemstore_t s, uint32_t id)
{
struct cw_item is;
is.id = id;
struct cw_item *i = avltree_get(s, &is);
if (i) {
cw_itemstore_del_data(i);
return i;
}
i = malloc(sizeof(struct cw_item));
if (!i)
return 0;
i->id = id;
return avltree_add(s, i);
}
int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->byte = byte;
i->type = CW_ITEMTYPE_BYTE;
return 1;
}
int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->word = word;
i->type = CW_ITEMTYPE_WORD;
return 1;
}
int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->dword = dword;
i->type = CW_ITEMTYPE_DWORD;
return 1;
}
int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_STR;
i->data = strdup(str);
return 1;
}
int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t *data, int len)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_DATA;
i->data = malloc(len);
if(!i->data)
return 1;
memcpy(i->data,data,len);
return 1;
}
int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_STR;
i->data = strndup(str, n);
return 1;
}
int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_DATA;
i->data = ptr;
return 1;
}
cw_item_t * cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return NULL;
i->type = CW_ITEMTYPE_BSTR;
i->data = bstr_create(data, len);
return i;
}
int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_BSTR16;
i->data = bstr16_create(data, len);
return 1;
}
cw_item_t * cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_CONST_DATA;
i->data = ptr;
return i;
}
int cw_itemstore_set_vendorstr(cw_itemstore_t s, uint32_t id, uint32_t vendor_id,
uint8_t * vendorstr, int len)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_VENDORSTR;
i->data = vendorstr_create(vendor_id,vendorstr,len);
return 1;
}
int cw_itemstore_set_avltree(cw_itemstore_t s, uint32_t id, struct avltree *t)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_AVLTREE;
i->data = t;
return 1;
}
struct cw_item_fundef {
void *(*get) (void *arg);
void (*free) (void *arg, void *data);
void *arg;
};
int cw_itemstore_set_fun(cw_itemstore_t s, uint32_t id,
void *(*funget) (void *arg),
void (*funfree) (void *arg, void *data), void *arg)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
struct cw_item_fundef *fundef = malloc(sizeof(struct cw_item_fundef));
i->data = fundef;
if (!fundef)
return 0;
fundef->get = funget;
fundef->free = funfree;
fundef->arg = arg;
i->type=CW_ITEMTYPE_FUN;
return 1;
}
void *cw_item_get_data_ptr(struct cw_item *item)
{
switch (item->type) {
case CW_ITEMTYPE_FUN:
{
struct cw_item_fundef *fundef =
(struct cw_item_fundef *) item->data;
if (!fundef)
return NULL;
return fundef->get(fundef->arg);
}
}
return item->data;
}
void cw_item_release_data_ptr(struct cw_item *item, void *data)
{
switch (item->type) {
case CW_ITEMTYPE_FUN:
{
struct cw_item_fundef *fundef =
(struct cw_item_fundef *) item->data;
if (!fundef)
return;
if (!fundef->free)
return;
return fundef->free(fundef->arg, data);
}
}
}
int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len)
{
switch (item_type) {
case CW_ITEMTYPE_BYTE:
cw_itemstore_set_byte(itemstore,item_id,*data);
break;
case CW_ITEMTYPE_WORD:
cw_itemstore_set_word(itemstore,item_id,*data);
break;
case CW_ITEMTYPE_DWORD:
cw_itemstore_set_dword(itemstore,item_id,*data);
break;
case CW_ITEMTYPE_STR:
cw_itemstore_set_strn(itemstore,item_id,(char*)data,len);
break;
case CW_ITEMTYPE_BSTR:
cw_itemstore_set_bstrn(itemstore,item_id,data,len);
break;
case CW_ITEMTYPE_DATA:
cw_itemstore_set_data(itemstore,item_id,data,len);
break;
case CW_ITEMTYPE_VENDORSTR:
cw_itemstore_set_vendorstr(itemstore,item_id,
cw_get_dword(data),data+4,len-4);
}
return 0;
}

View File

@ -1,174 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CFGSTORE_H
#define __CFGSTORE_H
#include <stdint.h>
#include "avltree.h"
#include "bstr.h"
/**
* Item types supported in item store
*/
typedef enum {
CW_ITEMTYPE_NONE = 0,
CW_ITEMTYPE_BYTE,
CW_ITEMTYPE_WORD,
CW_ITEMTYPE_DWORD,
CW_ITEMTYPE_DATA,
CW_ITEMTYPE_CONST_DATA,
CW_ITEMTYPE_STR,
CW_ITEMTYPE_BSTR,
CW_ITEMTYPE_BSTR16,
/** Vendor string contains a Vendor ID, followed by bstr16 data, containing
the string. */
CW_ITEMTYPE_VENDORSTR,
CW_ITEMTYPE_AVLTREE,
CW_ITEMTYPE_FUN,
} cw_itemtype_t;
struct cw_item {
uint32_t id;
uint8_t type;
union {
void *data;
uint8_t byte;
uint16_t word;
uint32_t dword;
};
};
typedef struct cw_item cw_item_t;
typedef struct avltree *cw_itemstore_t;
static inline struct cw_item *cw_itemstore_get(cw_itemstore_t s, uint32_t id)
{
struct cw_item i;
i.id = id;
return avltree_get(s, &i);
}
extern cw_itemstore_t cw_itemstore_create();
extern cw_item_t * cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr);
extern int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n);
extern int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str);
extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr);
extern cw_item_t * cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len);
extern int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword);
extern int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word);
extern int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte);
extern int cw_itemstore_set_vendorstr(cw_itemstore_t s, uint32_t id,
uint32_t vendor_id, uint8_t * vendorstr, int len);
int cw_itemstore_set_avltree(cw_itemstore_t s, uint32_t id, struct avltree *t);
int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len);
extern int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t * data,
int len);
static inline char *cw_itemstore_get_str(cw_itemstore_t s, uint32_t id, char *def)
{
struct cw_item *i = cw_itemstore_get(s, id);
if (!i)
return def;
return i->data;
};
static inline struct avltree *cw_itemstore_get_avltree(cw_itemstore_t s, uint32_t id)
{
struct cw_item *i = cw_itemstore_get(s, id);
if (!i)
return NULL;
if (i->type != CW_ITEMTYPE_AVLTREE)
return NULL;
return i->data;
}
static inline struct avltree *cw_itemstore_get_avltree_c(cw_itemstore_t s, uint32_t id,
struct avltree *(creator) ())
{
struct avltree *avltree = cw_itemstore_get_avltree(s, id);
if (avltree){
return avltree;
}
avltree = creator();
if (!avltree)
return NULL;
cw_itemstore_set_avltree(s, id, avltree);
return avltree;
}
extern void *cw_item_get_data_ptr(struct cw_item *item);
extern void cw_item_release_data_ptr(struct cw_item *item, void *data);
int cw_itemstore_set_fun(cw_itemstore_t s, uint32_t id,
void *(*funget) (void *arg),
void (*funfree) (void *arg, void *data), void *arg);
int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type,
uint8_t * data, int len);
struct cw_item *cw_item_create(cw_itemstore_t s, uint32_t id);
static inline void * cw_istore_get_data(cw_itemstore_t s,int id,void *def)
{
struct cw_item *i = cw_itemstore_get(s, id);
if (!i)
return def;
return i->data;
}
static inline uint8_t cw_istore_get_byte(cw_itemstore_t s, uint32_t id, uint8_t def)
{
struct cw_item *i = cw_itemstore_get(s, id);
if (!i)
return def;
return i->byte;
}
static inline uint16_t cw_istore_get_word(cw_itemstore_t s, uint32_t id, uint8_t def)
{
struct cw_item *i = cw_itemstore_get(s, id);
if (!i)
return def;
return i->word;
}
#define cw_istore_get_bstr(s,id,def) cw_istore_get_data(s,id,def)
#endif

View File

@ -206,6 +206,30 @@ extern void * mavliter_seek(mavliter_t *i,void *d);
#define mavliter_foreach_asc(iter,val) \
while(NULL != (val = mavliter_next(iter)))
/*
static inline void *mavl_replace_data(struct mavl *t, void *data, int len)
{
void *df = mavl_get(t, data);
if (!df)
return NULL;
memcpy(df, data, len);
return df;
}
static inline void *mavl_replace(struct mavl *t,void *data){
struct mavlnode * node = mavl_get_node(t,data);
if (node){
t->del(node->data);
return node->data=data;
}
return mavl_add(t,data);
}
*/
/** @} */

View File

@ -13,6 +13,12 @@ const struct mbag_typedef mbag_type_dword = {
NULL
};
const struct mbag_typedef mbag_type_const_data = {
NULL
};
const struct mbag_typedef mbag_type_bstr = {
free
};
@ -21,12 +27,36 @@ const struct mbag_typedef mbag_type_bstr16 = {
free
};
const struct mbag_typedef mbag_type_str = {
free
};
const struct mbag_typedef mbag_type_vendorstr = {
free
};
void free_avltree(void*t){
mbag_item_t *i = (mbag_item_t *) t;
printf("the mavl deleer %p\n",i->data);
mavl_destroy(i->data);
printf("jo\n");
}
const struct mbag_typedef mbag_type_avltree = {
free_avltree
};
static void mbag_type_mbag_del(void *i)
{
struct mbag_item *x = (struct mbag_item*)i;
printf("MBAG DELETE %p\n",x->data);
mavl_destroy(((struct mbag_item*)i)->data);
mavl_destroy(x->data);
}
const struct mbag_typedef mbag_type_mbag = {
@ -36,13 +66,17 @@ const struct mbag_typedef mbag_type_mbag = {
static void mbag_del_data(struct mbag_item *i)
{
if (i->type->del)
printf("Deling: %p\n",i->data);
if (i->type->del) {
printf("Calling deler\n");
i->type->del(i);
}
}
static void mbag_del_fun(void *e)
{
mbag_del_data(e);
free(e);
}

View File

@ -28,6 +28,7 @@
#include <stdint.h>
#include "mavl.h"
#include "bstr.h"
struct mbag_item;
@ -36,6 +37,8 @@ struct mbag_typedef{
void (*del)(void*);
};
typedef const struct mbagtype_def * mbagtype_t;
struct mbag_item{
@ -60,6 +63,11 @@ extern const struct mbag_typedef mbag_type_dword;
extern const struct mbag_typedef mbag_type_mbag;
extern const struct mbag_typedef mbag_type_bstr;
extern const struct mbag_typedef mbag_type_bstr16;
extern const struct mbag_typedef mbag_type_vendorstr;
extern const struct mbag_typedef mbag_type_str;
extern const struct mbag_typedef mbag_type_avltree;
extern const struct mbag_typedef mbag_type_const_data;
#define MBAG_BYTE (&mbag_type_byte)
@ -68,7 +76,13 @@ extern const struct mbag_typedef mbag_type_bstr16;
#define MBAG_MBAG (&mbag_type_mbag)
#define MBAG_BSTR (&mbag_type_bstr)
#define MBAG_BSTR16 (&mbag_type_bstr16)
#define MBAG_VENDORSTR (&mbag_type_vendorstr)
#define MBAG_STR (&mbag_type_str)
#define MBAG_DATA MBAG_STR
#define MBAG_AVLTREE (&mbag_type_avltree)
#define MBAG_FUN MBAG_STR
#define MBAG_CONST_DATA (&mbag_type_const_data)
extern mbag_t mbag_create();
@ -121,7 +135,7 @@ static inline int mbag_set_mbag(mbag_t s, uint32_t id, mbag_t mbag)
return 1;
}
static inline int mbag_set_data(mbag_t s, uint32_t id, struct mbag_typedef *type, void *data)
static inline int mbag_set_data(mbag_t s, uint32_t id, const struct mbag_typedef *type, void *data)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
@ -133,6 +147,23 @@ static inline int mbag_set_data(mbag_t s, uint32_t id, struct mbag_typedef *type
}
static inline int mbag_set_vendorstr(mbag_t s, uint32_t id, uint32_t vendor_id,
uint8_t * vendorstr, int len)
{
mbag_item_t *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_VENDORSTR;
i->data = vendorstr_create(vendor_id,vendorstr,len);
return 1;
}
#define mbag_set_bstr(m,i,d) mbag_set_data(m,i,MBAG_BSTR,d)
#define mbag_set_bstr16(m,i,d) mbag_set_data(m,i,MBAG_BSTR16,d)
@ -218,9 +249,183 @@ static inline mbag_t mbag_get_mbag(mbag_t s, uint32_t id, mbag_t def)
return i->data;
}
static inline mbag_item_t * mbag_set_bstrn(mbag_t s, uint32_t id, uint8_t * data, int len)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return NULL;
i->type = MBAG_BSTR;
i->data = bstr_create(data, len);
return i;
}
static inline struct avltree *mbag_get_avltree(mbag_t s, uint32_t id)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return NULL;
if (i->type != MBAG_AVLTREE)
return NULL;
return i->data;
}
static inline int mbag_set_avltree(mbag_t s, uint32_t id, struct avltree *t)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_AVLTREE;
i->data = t;
printf("Adding AVL %p to %p\n",t,s);
return 1;
}
static inline struct avltree *mbag_get_avltree_c(mbag_t s, uint32_t id,
struct avltree *(creator) ())
{
struct avltree *avltree = mbag_get_avltree(s, id);
if (avltree){
return avltree;
}
avltree = creator();
if (!avltree)
return NULL;
mbag_set_avltree(s, id, avltree);
return avltree;
}
/** @} */
static inline char *mbag_get_str(mbag_t s, uint32_t id, char *def)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return def;
return i->data;
};
static inline int mbag_set_str(mbag_t s, uint32_t id, const char *str)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_STR;
i->data = strdup(str);
return 1;
}
struct mbag_item_fundef {
void *(*get) (void *arg);
void (*free) (void *arg, void *data);
void *arg;
};
static inline void *mbag_item_get_data_ptr(struct mbag_item *item)
{
if (item->type == MBAG_FUN )
{
struct mbag_item_fundef *fundef =
(struct mbag_item_fundef *) item->data;
if (!fundef)
return NULL;
return fundef->get(fundef->arg);
}
return item->data;
}
static inline void mbag_item_release_data_ptr(struct mbag_item *item, void *data)
{
if (item->type == MBAG_FUN)
{
struct mbag_item_fundef *fundef =
(struct mbag_item_fundef *) item->data;
if (!fundef)
return;
if (!fundef->free)
return;
return fundef->free(fundef->arg, data);
}
}
static inline int mbag_set_strn(mbag_t s, uint32_t id, const char *str, int n)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_STR;
i->data = strndup(str, n);
return 1;
}
static inline int mbag_set_bstr16n(mbag_t s, uint32_t id, uint8_t * data, int len)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_BSTR16;
i->data = bstr16_create(data, len);
return 1;
}
static inline mbag_item_t * mbag_set_const_ptr(mbag_t s, uint32_t id, void *ptr)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_CONST_DATA;
i->data = ptr;
return i;
}
static inline int mbag_set_ptr(mbag_t s, uint32_t id, void *ptr)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_DATA;
i->data = ptr;
return 1;
}
static inline int mbag_set_fun(mbag_t s, uint32_t id,
void *(*funget) (void *arg),
void (*funfree) (void *arg, void *data), void *arg)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
struct mbag_item_fundef *fundef = malloc(sizeof(struct mbag_item_fundef));
i->data = fundef;
if (!fundef)
return 0;
fundef->get = funget;
fundef->free = funfree;
fundef->arg = arg;
i->type=MBAG_FUN;
return 1;
}
#endif

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;