Moved a lot of macros from capwap.h to cw.h

FossilOrigin-Name: 09114fbdffe3dd78d32f93da671f8f0cf9c40056a7b8f93114b12646f25db512
This commit is contained in:
7u83@mail.ru 2016-03-11 21:23:00 +00:00
parent 4a529fec12
commit d4ddbc0618
40 changed files with 385 additions and 413 deletions

View File

@ -14,8 +14,9 @@ GNUTLS_LIBS=-lgmp -lgnutls -lnettle
GNUTLS_LDFLAGS=-L../contrib/gnutls-${GNUTLS_VERSION}/lib/.libs/
else
GNUTLS_CFLAGS=
GNUTLS_LIBS=
GNUTLS_LDFLAGS=-lgnutls -lnettle -lgmp
GNUTLS_LIBS=-lgnutls -lnettle -lgmp
GNUTLS_LDFLAGS=
#-lgnutls -lnettle -lgmp
endif

View File

@ -116,11 +116,11 @@ LWAPPCISCOOBJS = \
# cw_tohex.o\
#capwap_parse_ctrlhdr.o \
# hdr_print.o \
CAPWAPOBJS= \
aciplist.o \
lwmsg_init.o \
hdr_print.o \
cw_cisco_id_to_str.o\
cw_strlist_get_str.o \
cw_strlist_get_id.o \
@ -147,6 +147,7 @@ CAPWAPOBJS= \
cw_in_check_generic_req.o \
cw_out_generic.o \
cw_out_wtp_descriptor.o \
cw_out_wtp_reboot_statistics.o \
cw_in_cisco_image_identifier.o\
cw_out_radio_operational_state.o\
cw_in_ac_descriptor.o\
@ -233,10 +234,10 @@ FRAGOBJS=fragman.o
# cw_in_wtp_descriptor.o \
# capwap_80211_actions_wtp.o \
# capwap_80211_actions_ac.o \
# capwap_actions_ac.o \
#capwap_actions_wtp.o \
CWACTION=action.o \
capwap_actions_ac.o \
capwap_actions_wtp.o \
cw_in_generic.o \
cw_in_generic2.o \
cw_out_wtp_board_data.o \

View File

@ -1,36 +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/>.
*/
#include "avltree.h"
static void avltree_del_all0(struct avltree *t ,struct avlnode * n)
{
if (!n)
return;
avltree_del_all0(t,n->left);
avltree_del_all0(t,n->right);
avlnode_destroy(t,n);
}
void avltree_del_all(struct avltree *t)
{
avltree_del_all0(t,t->root);
t->root=0;
}

View File

@ -39,7 +39,7 @@
#include "lwapp.h"
#include "strlist.h"
#include "cw.h"
//#include "cw.h"
/* capwap version and iana number */
@ -525,285 +525,6 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le
/* Use some macros from LWAPP */
/*
#define cw_put_byte lw_put_byte
#define cw_put_word lw_put_word
#define cw_put_dword lw_put_dword
#define cw_put_data lw_put_data
#define cw_put_bstr lw_put_bstr
#define cw_put_bstr16 lw_put_bstr16
#define cw_set_dword lw_set_dword
#define cw_get_byte lw_get_byte
#define cw_get_word lw_get_word
#define cw_get_dword lw_get_dword
*/
/* macro to isolate bits from a dword */
#define cw_get_dword_bits(src,start,len) ((~(0xFFFFFFFF<<len)) & (src >> (32 - start - len)))
/* macros to acces transport header values */
#define cw_get_hdr_preamble(th) (th[0])
#define cw_get_hdr_fragid(th) ((ntohl((((uint32_t*)th)[1]) >> 16) & 0xffff))
#define cw_get_hdr_fragoffset(th) ((ntohl((((uint32_t*)th)[1]) >> 3) & 0x1fff))
#define cw_get_hdr_rid(th) ((ntohl((((uint32_t*)th)[0]) >> 14) & 0x1f))
#define cw_get_hdr_wbid(th) ((ntohl(((uint32_t*)th)[0]) >> 9) & 0x1f)
#define cw_get_hdr_hlen(th) ((ntohl(((uint32_t*)th)[0]) >> 19) & 0x1f)
#define cw_get_hdr_rmac(th) (th+8)
#define cw_get_hdr_rmac_len(th) (*(th+8))
#define cw_get_hdr_rmac_size(th) cw_get_hdr_rmac_len(th)
#define cw_get_hdr_rmac_data(th) (th+9)
#define cw_get_hdr_flag_r1(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_R1 ) ? 1:0)
#define cw_get_hdr_flag_r2(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_R2 ) ? 1:0)
#define cw_get_hdr_flag_r3(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_R3 ) ? 1:0)
#define cw_get_hdr_flag_k(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_K ) ? 1:0)
#define cw_get_hdr_flag_m(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_M ) ? 1:0)
#define cw_get_hdr_flag_w(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_W ) ? 1:0)
#define cw_get_hdr_flag_l(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_L ) ? 1:0)
#define cw_get_hdr_flag_f(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_F ) ? 1:0)
#define cw_get_hdr_flag_t(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_T ) ? 1:0)
#define cw_get_hdr_msg_offset(th) (4*cw_get_hdr_hlen(th))
#define cw_get_hdr_msg_elems_offset(th) (cw_get_hdr_msg_offset(th)+8)
#define cw_set_hdr_preamble(th,v) ((*th)=v)
/**
* Set the HLEN field of a CAWAP Header
* @param th pointer to the header
* @param hlen value to set (Header Length)
*/
static inline void cw_set_hdr_hlen(uint8_t * th, int hlen)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 19) ^ 0xffffffff;
d |= ((hlen) & 0x1f) << 19;
cw_set_dword(th, d);
}
/**
* Set the WBID field of a CAWAP Header
* @param th pointer to the header
* @param wbid value to set (Wireless ID)
*/
static inline void cw_set_hdr_wbid(uint8_t * th, int wbid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 9) ^ 0xffffffff;
d |= ((wbid) & 0x1f) << 9;
cw_set_dword(th, d);
}
/**
* Set the RID field of a CAWAP Header
* @param th pointer to the header
* @param rid value to set (Radio ID)
*/
static inline void cw_set_hdr_rid(uint8_t * th, int rid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 14) ^ 0xffffffff;
d |= ((rid) & 0x1f) << 14;
cw_set_dword(th, d);
}
/**
* Set CAPWAP header flags
* @param th pointer to header
* @param flags list of flags to set or unset
* @param set 1=set flag, 0=unset flag
*/
#define cw_set_hdr_flags(th,flags,set) \
( set ? ((*((uint32_t*)th)) |= htonl(flags)) : ((*((uint32_t*)th)) &= (0xffffffff^htonl(flags))) )
#define cw_set_hdr_flag_f(th,set) cw_set_hdr_flag(th, CW_FLAG_HDR_F)
/* Macros for message headers */
#define cw_get_msg_id(msgptr) (cw_get_dword(msgptr))
#define cw_get_msg_type(msgptr) cw_get_msg_id(msgptr)
#define cw_get_msg_seqnum(msgptr) cw_get_byte( (msgptr) +4 )
#define cw_get_msg_elems_len(msgptr) ( cw_get_word( (msgptr) +5 )-3)
#define cw_get_msg_elems_ptr(msgptr) ((msgptr)+8)
#define cw_set_msg_id(msgptr,t) cw_put_dword(msgptr,t)
#define cw_set_msg_type(msgptr,t) cw_set_msg_id(msgptr,t)
#define cw_set_msg_seqnum(msgptr,s) cw_put_byte( (msgptr) +4,s);
#define cw_set_msg_elems_len(msgptr,n) (cw_put_word((msgptr)+5,((n)+3)))
#define cw_set_msg_flags(msgptr,f) (cw_put_byte( (msgptr)+7,f))
static inline uint8_t *cw_get_hdr_msg_elems_ptr(uint8_t * m)
{
return cw_get_msg_elems_ptr(m + cw_get_hdr_msg_offset(m));
}
static inline uint8_t *cw_get_hdr_msg_ptr(uint8_t * rawmsg)
{
return rawmsg + cw_get_hdr_msg_offset(rawmsg);
}
#define cw_get_hdr_msg_id(ptr)\
cw_get_msg_id(cw_get_hdr_msg_ptr(ptr))
#define cw_get_hdr_msg_type cw_get_hdr_msg_id
static inline int cw_get_hdr_msg_total_len(uint8_t * rawmsg)
{
int offset = cw_get_hdr_msg_offset(rawmsg);
return offset + cw_get_msg_elems_len(rawmsg + offset) + 8;
}
static inline int cw_set_hdr_rmac(uint8_t * th,bstr_t rmac)
{
if (!rmac){
cw_set_hdr_flags(th,CW_FLAG_HDR_M,0);
cw_set_hdr_hlen(th, 2);
return 0;
}
int rmac_len = bstr_len(rmac);
memcpy(cw_get_hdr_rmac(th),rmac,rmac_len+1);
cw_set_hdr_flags(th,CW_FLAG_HDR_M,1);
int hlen = 4+rmac_len/4;
if (rmac_len %4 != 0) {
hlen++;
}
cw_set_hdr_hlen(th,hlen);
return 1;
}
/**
* Get length of a CAPWAP message elemet
* @param e pointer to element (uint8_t*)
* @return length of element
*/
#define cw_get_elem_type(e) cw_get_word(e)
#define cw_get_elem_id(e) cw_get_elem_type(e)
/**
* Get type of a CAPWAP message element
* @pram e pointer to element (uint8_t*)
* @return type of element
*/
#define cw_get_elem_len(e) cw_get_word((e)+2)
/**
* Get a pointer to the data of a CAPWAP message element
* @param e pointer to message element
* @return pointer to data
*/
#define cw_get_elem_data(e) ((e)+4)
/**
* Iterate through message elements of a CAPWAP message
* @param i iterator witch points to the current element (uint8_t*)
* @param elems pointer to message elements (uint8_t*)
* @param len length of message element buffer
*
* You can use this macro like a for loop.
*
* uint8_t * i
* cw_foreach_elem(i,elem,len){
* ...
* print_message(i);
* ...
* }
*/
#define cw_foreach_elem(i,elems,len) for(i=elems; i<elems+len; i=i+4+cw_get_elem_len(i))
/**
* Put a message element header to buffer
* @param dst pointer to buffer (uint8_t)
* @param type tpe of message element
* @param len length of message element data
* @return the number bytes put (always 4)
*/
#define cw_put_elem_hdr(dst,type,len) \
(cw_put_dword(dst, (((uint32_t)type)<<16) | (len)),4)
/**
* Put a message element header for a message to contain a vendor specific payload
* @param dst pointer to destination buffer
* @param vendorid vendorid
* @param elemid element id of vendor specific data
* @len length of vendor specific data
* @return the number of bytes put (always 10)
*/
static inline int cw_put_elem_vendor_hdr(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
cw_put_elem_hdr(dst, CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_dword(dst + 4, vendorid);
cw_put_word(dst + 8, elemid);
return 10;
}
#define cw_put_sockaddr lw_put_sockaddr
int cw_put_image_data(uint8_t *dst,FILE *infile);
/**
* Add a message element to a buffer
* @param dst pointer to buffer
* @type message element type
* @data pointer to data
* @length of message element
* @return the number of bytes put
*/
static inline int cw_addelem(uint8_t * dst, uint16_t type, uint8_t * data, uint16_t len)
{
int l = cw_put_elem_hdr(dst, type, len);
return l + cw_put_data(dst + l, data, len);
}
static inline int cw_addelem_bstr(uint8_t * dst, uint16_t type, const bstr_t bstr)
{
return cw_addelem(dst, type, bstr_data(bstr), bstr_len(bstr));
}
static inline int cw_put_elem_result_code(uint8_t * dst, uint32_t code)
{
cw_put_dword(dst + 4, code);
return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4);
}
/*
static inline int cw_addelem_radio_operational_state(uint8_t * dst, struct radioinfo *ri)
@ -852,11 +573,7 @@ extern int cw_send_configuration_update_response(struct conn *conn, int seqnum,
struct radioinfo *radioinfo);
*/
//#define cw_addelem_ac_name(dst,name) \
// cw_addelem(dst,CW_ELEM_AC_NAME,name,strlen((char*)(name)))
//#define cw_addelem_session_id(dst,sessid)\
// cw_addelem_bstr(dst,CW_ELEM_SESSION_ID,sessid)
@ -984,24 +701,31 @@ struct cw_ac_status {
};
/**
* Put an cw_ac_stauts structure to a buffer
* @param dst destination buffer
* @param s #cw_ac_status to put
* @return number of bytes put
* This function is only useful (used) in conjunction with
* putting AC Descriptor message elements.
*@defgroup CAPWAP CAPWAP
*@{
*/
static inline int cw_put_ac_status(uint8_t * dst, struct cw_ac_status *s)
{
uint8_t *d = dst;
d += cw_put_dword(d, (s->stations << 16) | (s->limit));
d += cw_put_dword(d, (s->active_wtps << 16) | (s->max_wtps));
d += cw_put_dword(d,
(s->security << 24) | (s->rmac_field << 16) | (s->dtls_policy));
return d - dst;
}
/**
* CAWAP States
*/
enum capwap_states {
CW_STATE_NONE = 0,
/** Discovery State */
CW_STATE_DISCOVERY,
/** Join State */
CW_STATE_JOIN,
/** Config State */
CW_STATE_CONFIGURE,
/** Image Data Upload */
CW_STATE_IMAGE_DATA,
CW_STATE_UPDATE,
/** Run State */
CW_STATE_RUN
};
/**
*@}
*/

View File

@ -28,7 +28,7 @@
#include <time.h>
#include "lwapp.h"
#include "capwap.h"
#include "cw.h"
#define CW_CISCO_MWAR_ADDR LW_ELEM_AC_ADDRESS /* 2 */
#define CW_CISCO_RAD 3

View File

@ -21,7 +21,7 @@
#include <string.h>
#include <errno.h>
#include "capwap.h"
#include "cw.h"
#include "dbg.h"
#include "log.h"

View File

@ -9,6 +9,7 @@
#include "action.h"
#include "lw.h"
#include "capwap.h"
/**
* @defgroup CW CW
@ -66,6 +67,280 @@
/**
* Macro to isolate bits from a dword
* @param src dword to isolate bits from
* @param start start position
* @len number of bits
*/
#define cw_get_dword_bits(src,start,len) ((~(0xFFFFFFFF<<len)) & (src >> (32 - start - len)))
/* macros to acces transport header values */
#define cw_get_hdr_preamble(th) (th[0])
#define cw_get_hdr_fragid(th) ((ntohl((((uint32_t*)th)[1]) >> 16) & 0xffff))
#define cw_get_hdr_fragoffset(th) ((ntohl((((uint32_t*)th)[1]) >> 3) & 0x1fff))
#define cw_get_hdr_rid(th) ((ntohl((((uint32_t*)th)[0]) >> 14) & 0x1f))
#define cw_get_hdr_wbid(th) ((ntohl(((uint32_t*)th)[0]) >> 9) & 0x1f)
#define cw_get_hdr_hlen(th) ((ntohl(((uint32_t*)th)[0]) >> 19) & 0x1f)
#define cw_get_hdr_rmac(th) (th+8)
#define cw_get_hdr_rmac_len(th) (*(th+8))
#define cw_get_hdr_rmac_size(th) cw_get_hdr_rmac_len(th)
#define cw_get_hdr_rmac_data(th) (th+9)
#define cw_get_hdr_flag_r1(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_R1 ) ? 1:0)
#define cw_get_hdr_flag_r2(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_R2 ) ? 1:0)
#define cw_get_hdr_flag_r3(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_R3 ) ? 1:0)
#define cw_get_hdr_flag_k(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_K ) ? 1:0)
#define cw_get_hdr_flag_m(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_M ) ? 1:0)
#define cw_get_hdr_flag_w(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_W ) ? 1:0)
#define cw_get_hdr_flag_l(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_L ) ? 1:0)
#define cw_get_hdr_flag_f(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_F ) ? 1:0)
#define cw_get_hdr_flag_t(th) ((ntohl( *((uint32_t*)th)) & CWTH_FLAGS_T ) ? 1:0)
#define cw_get_hdr_msg_offset(th) (4*cw_get_hdr_hlen(th))
#define cw_get_hdr_msg_elems_offset(th) (cw_get_hdr_msg_offset(th)+8)
#define cw_set_hdr_preamble(th,v) ((*th)=v)
/**
* Set the HLEN field of a CAWAP Header
* @param th pointer to the header
* @param hlen value to set (Header Length)
*/
static inline void cw_set_hdr_hlen(uint8_t * th, int hlen)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 19) ^ 0xffffffff;
d |= ((hlen) & 0x1f) << 19;
cw_set_dword(th, d);
}
/**
* Set the WBID field of a CAWAP Header
* @param th pointer to the header
* @param wbid value to set (Wireless ID)
*/
static inline void cw_set_hdr_wbid(uint8_t * th, int wbid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 9) ^ 0xffffffff;
d |= ((wbid) & 0x1f) << 9;
cw_set_dword(th, d);
}
/**
* Set the RID field of a CAWAP Header
* @param th pointer to the header
* @param rid value to set (Radio ID)
*/
static inline void cw_set_hdr_rid(uint8_t * th, int rid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 14) ^ 0xffffffff;
d |= ((rid) & 0x1f) << 14;
cw_set_dword(th, d);
}
/**
* Set CAPWAP header flags
* @param th pointer to header
* @param flags list of flags to set or unset
* @param set 1=set flag, 0=unset flag
*/
#define cw_set_hdr_flags(th,flags,set) \
( set ? ((*((uint32_t*)th)) |= htonl(flags)) : ((*((uint32_t*)th)) &= (0xffffffff^htonl(flags))) )
#define cw_set_hdr_flag_f(th,set) cw_set_hdr_flag(th, CW_FLAG_HDR_F)
/* Macros for message headers */
#define cw_get_msg_id(msgptr) (cw_get_dword(msgptr))
#define cw_get_msg_type(msgptr) cw_get_msg_id(msgptr)
#define cw_get_msg_seqnum(msgptr) cw_get_byte( (msgptr) +4 )
#define cw_get_msg_elems_len(msgptr) ( cw_get_word( (msgptr) +5 )-3)
#define cw_get_msg_elems_ptr(msgptr) ((msgptr)+8)
#define cw_set_msg_id(msgptr,t) cw_put_dword(msgptr,t)
#define cw_set_msg_type(msgptr,t) cw_set_msg_id(msgptr,t)
#define cw_set_msg_seqnum(msgptr,s) cw_put_byte( (msgptr) +4,s);
#define cw_set_msg_elems_len(msgptr,n) (cw_put_word((msgptr)+5,((n)+3)))
#define cw_set_msg_flags(msgptr,f) (cw_put_byte( (msgptr)+7,f))
static inline uint8_t *cw_get_hdr_msg_elems_ptr(uint8_t * m)
{
return cw_get_msg_elems_ptr(m + cw_get_hdr_msg_offset(m));
}
static inline uint8_t *cw_get_hdr_msg_ptr(uint8_t * rawmsg)
{
return rawmsg + cw_get_hdr_msg_offset(rawmsg);
}
#define cw_get_hdr_msg_id(ptr)\
cw_get_msg_id(cw_get_hdr_msg_ptr(ptr))
#define cw_get_hdr_msg_type cw_get_hdr_msg_id
static inline int cw_get_hdr_msg_total_len(uint8_t * rawmsg)
{
int offset = cw_get_hdr_msg_offset(rawmsg);
return offset + cw_get_msg_elems_len(rawmsg + offset) + 8;
}
static inline int cw_set_hdr_rmac(uint8_t * th,bstr_t rmac)
{
if (!rmac){
cw_set_hdr_flags(th,CW_FLAG_HDR_M,0);
cw_set_hdr_hlen(th, 2);
return 0;
}
int rmac_len = bstr_len(rmac);
memcpy(cw_get_hdr_rmac(th),rmac,rmac_len+1);
cw_set_hdr_flags(th,CW_FLAG_HDR_M,1);
int hlen = 4+rmac_len/4;
if (rmac_len %4 != 0) {
hlen++;
}
cw_set_hdr_hlen(th,hlen);
return 1;
}
/**
* Get length of a CAPWAP message elemet
* @param e pointer to element (uint8_t*)
* @return length of element
*/
#define cw_get_elem_type(e) cw_get_word(e)
/**
* Alias for #cw_get_elem_type
*/
#define cw_get_elem_id(e) cw_get_elem_type(e)
/**
* Get type of a CAPWAP message element
* @pram e pointer to element (uint8_t*)
* @return type of element
*/
#define cw_get_elem_len(e) cw_get_word((e)+2)
/**
* Get a pointer to the data of a CAPWAP message element
* @param e pointer to message element
* @return pointer to data
*/
#define cw_get_elem_data(e) ((e)+4)
/**
* Iterate through message elements of a CAPWAP message
* @param i iterator witch points to the current element (uint8_t*)
* @param elems pointer to message elements (uint8_t*)
* @param len length of message element buffer
*
* You can use this macro like a for loop.
*
* uint8_t * i
* cw_foreach_elem(i,elem,len){
* ...
* print_message(i);
* ...
* }
*/
#define cw_foreach_elem(i,elems,len) for(i=elems; i<elems+len; i=i+4+cw_get_elem_len(i))
/**
* Put a message element header to buffer
* @param dst pointer to buffer (uint8_t)
* @param type tpe of message element
* @param len length of message element data
* @return the number bytes put (always 4)
*/
#define cw_put_elem_hdr(dst,type,len) \
(cw_put_dword(dst, (((uint32_t)type)<<16) | (len)),4)
/**
* Put a message element header for a message to contain a vendor specific payload
* @param dst pointer to destination buffer
* @param vendorid vendorid
* @param elemid element id of vendor specific data
* @len length of vendor specific data
* @return the number of bytes put (always 10)
*/
static inline int cw_put_elem_vendor_hdr(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
cw_put_elem_hdr(dst, CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_dword(dst + 4, vendorid);
cw_put_word(dst + 8, elemid);
return 10;
}
#define cw_put_sockaddr lw_put_sockaddr
int cw_put_image_data(uint8_t *dst,FILE *infile);
/**
* Add a message element to a buffer
* @param dst pointer to buffer
* @type message element type
* @data pointer to data
* @length of message element
* @return the number of bytes put
*/
static inline int cw_addelem(uint8_t * dst, uint16_t type, uint8_t * data, uint16_t len)
{
int l = cw_put_elem_hdr(dst, type, len);
return l + cw_put_data(dst + l, data, len);
}
static inline int cw_addelem_bstr(uint8_t * dst, uint16_t type, const bstr_t bstr)
{
return cw_addelem(dst, type, bstr_data(bstr), bstr_len(bstr));
}
static inline int cw_put_elem_result_code(uint8_t * dst, uint32_t code)
{
cw_put_dword(dst + 4, code);
return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4);
}
static inline int cw_put_version(uint8_t * dst, uint16_t subelem_id, bstrv_t v)
{
uint8_t *d = dst;
@ -76,6 +351,29 @@ static inline int cw_put_version(uint8_t * dst, uint16_t subelem_id, bstrv_t v)
}
/**
* Put an cw_ac_stauts structure to a buffer
* @param dst destination buffer
* @param s #cw_ac_status to put
* @return number of bytes put
* This function is only useful (used) in conjunction with
* putting AC Descriptor message elements.
*/
static inline int cw_put_ac_status(uint8_t * dst, struct cw_ac_status *s)
{
uint8_t *d = dst;
d += cw_put_dword(d, (s->stations << 16) | (s->limit));
d += cw_put_dword(d, (s->active_wtps << 16) | (s->max_wtps));
d += cw_put_dword(d,
(s->security << 24) | (s->rmac_field << 16) | (s->dtls_policy));
return d - dst;
}
extern int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn,
struct cw_action_in *a, uint8_t * data, int len);
@ -133,33 +431,6 @@ extern int cw_out_capwap_local_ip_address(struct conn *conn, struct cw_action_ou
*/
/**
*@defgroup CAPWAP CAPWAP
*@{
*/
/**
* CAWAP States
*/
enum capwap_states {
CW_STATE_NONE = 0,
/** Discovery State */
CW_STATE_DISCOVERY,
/** Join State */
CW_STATE_JOIN,
/** Config State */
CW_STATE_CONFIGURE,
/** Image Data Upload */
CW_STATE_IMAGE_DATA,
CW_STATE_UPDATE,
/** Run State */
CW_STATE_RUN
};
/**
*@}
*/
/**

View File

@ -1,5 +1,5 @@
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "dbg.h"
#include "mbag.h"

View File

@ -3,7 +3,7 @@
#include "dbg.h"
#include "log.h"
#include "mbag.h"
#include "capwap.h"
#include "cw.h"
#include "acpriolist.h"

View File

@ -32,7 +32,7 @@
#include "action.h"
#include "log.h"
#include "mbag.h"
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "aciplist.h"
#include "sock.h"

View File

@ -3,7 +3,7 @@
#include "dbg.h"
#include "log.h"
#include "mbag.h"
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"

View File

@ -3,7 +3,7 @@
#include "dbg.h"
#include "log.h"
#include "mbag.h"
#include "capwap.h"
#include "cw.h"
int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,

View File

@ -3,7 +3,7 @@
#include "dbg.h"
#include "log.h"
#include "mbag.h"
#include "capwap.h"
#include "cw.h"
#include "item.h"

View File

@ -3,7 +3,7 @@
#include "dbg.h"
#include "log.h"
#include "mbag.h"
#include "capwap.h"
#include "cw.h"
#include "radio.h"

View File

@ -1,5 +1,5 @@
#include "capwap.h"
#include "cw.h"
#include "dbg.h"
#include "log.h"

View File

@ -22,7 +22,7 @@
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "mbag.h"

View File

@ -1,6 +1,6 @@
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "dbg.h"

View File

@ -1,7 +1,7 @@
#include "log.h"
#include "capwap.h"
#include "cw.h"
#include "aciplist.h"
#include "sock.h"

View File

@ -27,12 +27,11 @@
#include <arpa/inet.h>
#include <string.h>
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "dbg.h"
#include "log.h"
#include "capwap.h"
#include "conn.h"

View File

@ -1,7 +1,7 @@
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "dbg.h"

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <errno.h>
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "log.h"

View File

@ -1,5 +1,5 @@
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "capwap80211.h"
#include "radio.h"

View File

@ -1,5 +1,5 @@
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "dbg.h"

View File

@ -3,11 +3,12 @@
#include "mbag.h"
#include "capwap_items.h"
#include "capwap.h"
#include "cw.h"
int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
mbag_t board_data =
mbag_get_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA,NULL);

View File

@ -1,5 +1,5 @@
#include "capwap.h"
#include "cw.h"

View File

@ -21,7 +21,7 @@
* @brief implementation of cw_put_msg.
*/
#include "capwap.h"
#include "cw.h"
#include "capwap_items.h"
#include "conn.h"
@ -73,6 +73,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
cw_action_out_t *ae=(cw_action_out_t*)e->data;
DBGX("Put %d %i %p\n",ae->msg_id,ae->elem_id,ae->item_id);
printf("Put %d %i %s\n",ae->msg_id,ae->elem_id,ae->item_id);
DBGX("Elem ID %s",ae->item_id);
if ( ae->item_id ) {
DBGX("Item ID: %s %p",ae->item_id,CW_ITEM_NONE);
@ -84,8 +85,13 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
}
if (ae->out) {
int l=0;
printf("Out Call with len =%d\n",len);
l= ae->out(conn, ae, dst+len);
printf("Returned len = %d\n",l);
len +=l;

View File

@ -17,7 +17,7 @@ int cw_read_wtp_descriptor_7(mbag_t mbag, struct conn *conn,
int pos = 2;
/* Encryption element, for now dumy XXX */
cw_get_word(data + pos + 2);
//cw_get_word(data + pos + 2);
pos += 2;
return cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos);

View File

@ -25,7 +25,7 @@
#ifndef __CW_FORMAT_H
#define __CW_FORMAT_H
#include "capwap.h"
#include "cw.h"
extern int cw_format_hex_bytes(char *dst, const char *format, const char *delim,

View File

@ -443,10 +443,10 @@ static inline mavl_t mbag_get_mbag_c(mbag_t s, const char *id,
static inline int mbag_inc_word(mbag_t s, const char * id)
static inline int mbag_inc_word(mbag_t s, const char * id,int n)
{
uint16_t w = mbag_get_word(s,id,0);
mbag_set_word(s,id,w+1);
mbag_set_word(s,id,w+n);
return 1;
}

View File

@ -1,7 +1,7 @@
#include <errno.h>
#include "conn.h"
#include "capwap.h"
#include "cw.h"
#include "log.h"
#include "dbg.h"
#include "sock.h"

View File

@ -17,7 +17,7 @@
*/
#include "cw/capwap.h"
#include "cw/cw.h"
#include "cw/action.h"
#include "cw/capwap_items.h"
#include "cw/strheap.h"

View File

@ -1,4 +1,4 @@
#include "cw/capwap.h"
#include "cw/cw.h"
#include "cw/action.h"
#include "cw/capwap_items.h"
@ -215,19 +215,18 @@ static cw_action_out_t actions_out[] = {
.elem_id = CW_ELEM_WTP_BOARD_DATA,
.item_id = CW_ITEM_WTP_BOARD_DATA,
.out = cw_out_wtp_board_data,
.get = cw_out_get_outgoing,
// .get = cw_out_get_config,
.mand = 1
}
,
/* WTP Descriptor */
{
.msg_id = CW_MSG_DISCOVERY_REQUEST,
.elem_id = CW_ELEM_WTP_DESCRIPTOR,
.item_id = CW_ITEM_WTP_DESCRIPTOR,
.out = capwap_out_wtp_descriptor,
//.get = cw_out_get_outgoing,
//.get = cw_out_get_config,
.mand = 1
}

View File

@ -22,7 +22,7 @@
#include "cw/capwap.h"
#include "cw/cw.h"
#include "cw/capwap_items.h"
#include "cw/mbag.h"

View File

@ -31,6 +31,10 @@ int capwap_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_
// XXX Dummy WTP Descriptor Header
uint8_t *d = dst+4;
int n =conn->radios->count;
printf("radio count %d\n",n);
d+=cw_put_byte(d,conn->radios->count); //max radios
d+=cw_put_byte(d,2); //radios in use

View File

@ -4,7 +4,7 @@
#include "cw/dbg.h"
#include "cw/action.h"
#include "cw/capwap.h"
#include "cw/cw.h"
#include "mod_capwap80211.h"

View File

@ -3,7 +3,7 @@
#include "cw/mbag.h"
#include "cw/capwap_items.h"
#include "cw/capwap.h"
#include "cw/cw.h"
int cisco_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst)

View File

@ -1,5 +1,5 @@
#include "cw/capwap.h"
#include "cw/cw.h"
#include "cw/mod.h"
#include "cw/log.h"
#include "cw/dbg.h"

View File

@ -25,6 +25,8 @@ CFLAGS += -O0 -Wall -Wno-unused-variable -Werror -g
LDFLAGS += -L../contrib/jsmn -L../../src/lib/$(ARCH)
CONFOBJS = wtp_conf.o
LIBS+=-lcapwap
LIBS+=-lcapwap80211
LIBS+=-lcisco
@ -33,7 +35,7 @@ LIBS+=-lnl-3
LIBS+=-lnl-genl-3
LIBS+=-ljsmn
CONFOBJS = wtp_conf.o
ifeq ($(CONF_LIBRARY),UCI)
CFLAGS+=-DWITH_UCI
@ -63,7 +65,6 @@ endif
#HA_FILES += ../contrib/hostap/src/drivers/driver_nl80211.o
HA_INCS += -I$(INCLUDE_DIR)/libnl-tiny

View File

@ -240,6 +240,9 @@ static int cw_run_discovery(struct conn *conn, const char *acaddr)
int discovery()
{
struct conn *conn = get_conn();
printf("Raqddios = %d\n",conn->radios->count);
cw_run_discovery(conn, "255.255.255.255");
conn->capwap_state=CW_STATE_JOIN;
return 1;

View File

@ -69,22 +69,23 @@ void update_reboot_stats(struct conn * conn, int cause)
mbag_t rs = mbag_get_mbag(conn->config,CW_ITEM_WTP_REBOOT_STATISTICS,NULL);
uint16_t rv;
printf("Loaded mbag %p\n",rs);
switch (cause){
case CW_REBOOT_TYPE_NOT_SUPPORTED:
break;
case CW_REBOOT_TYPE_AC_INITIATED:
mbag_inc_word(rs,CW_ITEM_REBOOT_AC_INITIATED_COUNT);
mbag_inc_word(rs,CW_ITEM_REBOOT_AC_INITIATED_COUNT,1);
break;
case CW_REBOOT_TYPE_OTHER_FAILURE:
mbag_inc_word(rs,CW_ITEM_REBOOT_OTHER_FAILURE_COUNT);
mbag_inc_word(rs,CW_ITEM_REBOOT_OTHER_FAILURE_COUNT,1);
break;
}
mbag_inc_word(rs,CW_ITEM_REBOOT_COUNT,1);
mbag_set_byte(rs,CW_ITEM_REBOOT_LAST_FAILURE_TYPE,cause);
cfg_to_json();
}
@ -92,7 +93,6 @@ void update_reboot_stats(struct conn * conn, int cause)
static void sig_handler(int sig)
{
struct conn * conn = the_conn; //get_conn();
printf("Ctrl+C pressed, updating reboot statistics for %p\n",conn);
update_reboot_stats(conn, CW_REBOOT_TYPE_OTHER_FAILURE);
exit(0);
@ -206,8 +206,6 @@ int main()
mbag_set_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, board_data);
mbag_t reboot_statistics = mbag_create();
mbag_set_mbag(conn->config, CW_ITEM_WTP_REBOOT_STATISTICS,reboot_statistics);
@ -245,7 +243,7 @@ int main()
if (!join())
return -1;
mavl_destroy(conn->incomming);
// mavl_del_all(conn->incomming);
conn->incomming = conn->config;
if (!configure())
return -1;