From d4ddbc061899ceb8a4c28504bbd056463b69c1fb Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Fri, 11 Mar 2016 21:23:00 +0000 Subject: [PATCH] Moved a lot of macros from capwap.h to cw.h FossilOrigin-Name: 09114fbdffe3dd78d32f93da671f8f0cf9c40056a7b8f93114b12646f25db512 --- src/Macros.mak | 5 +- src/cw/Makefile | 7 +- src/cw/avltree_del_all.c | 36 --- src/cw/capwap.h | 322 ++----------------- src/cw/capwap_cisco.h | 2 +- src/cw/conn_process_packet.c | 2 +- src/cw/cw.h | 325 ++++++++++++++++++-- src/cw/cw_in_ac_descriptor.c | 2 +- src/cw/cw_in_ac_name_with_priority.c | 2 +- src/cw/cw_in_capwap_control_ip_address.c | 2 +- src/cw/cw_in_cisco_add_wlan.c | 2 +- src/cw/cw_in_generic.c | 2 +- src/cw/cw_in_generic2.c | 2 +- src/cw/cw_in_radio_administrative_state.c | 2 +- src/cw/cw_in_vendor_specific_payload.c | 2 +- src/cw/cw_in_wtp_board_data.c | 2 +- src/cw/cw_out_ac_name_with_priority.c | 2 +- src/cw/cw_out_capwap_control_ip_addr_list.c | 2 +- src/cw/cw_out_capwap_local_ip_address.c | 3 +- src/cw/cw_out_generic.c | 2 +- src/cw/cw_out_image_data.c | 2 +- src/cw/cw_out_radio_info.c | 2 +- src/cw/cw_out_radio_operational_state.c | 2 +- src/cw/cw_out_wtp_board_data.c | 3 +- src/cw/cw_put_image_data.c | 2 +- src/cw/cw_put_msg.c | 8 +- src/cw/cw_read_wtp_descriptor_7.c | 2 +- src/cw/format.h | 2 +- src/cw/mbag.h | 4 +- src/cw/send.c | 2 +- src/mod/capwap/capwap_actions_ac.c | 2 +- src/mod/capwap/capwap_actions_wtp.c | 7 +- src/mod/capwap/capwap_in_wtp_board_data.c | 2 +- src/mod/capwap/capwap_out_wtp_descriptor.c | 4 + src/mod/capwap80211/mod_capwap80211_ac.c | 2 +- src/mod/cisco/cisco_out_ac_descriptor.c | 2 +- src/mod/cisco/mod_cisco_ac.c | 2 +- src/wtp/Makefile | 5 +- src/wtp/discovery.c | 3 + src/wtp/wtp_main.c | 14 +- 40 files changed, 385 insertions(+), 413 deletions(-) delete mode 100644 src/cw/avltree_del_all.c diff --git a/src/Macros.mak b/src/Macros.mak index 01ad2659..4e93eaf5 100644 --- a/src/Macros.mak +++ b/src/Macros.mak @@ -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 diff --git a/src/cw/Makefile b/src/cw/Makefile index 1602e37b..1b55cd8b 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -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 \ diff --git a/src/cw/avltree_del_all.c b/src/cw/avltree_del_all.c deleted file mode 100644 index 7f0d5927..00000000 --- a/src/cw/avltree_del_all.c +++ /dev/null @@ -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 . - -*/ - -#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; -} - - diff --git a/src/cw/capwap.h b/src/cw/capwap.h index 72ff45b2..f31a5ec0 100644 --- a/src/cw/capwap.h +++ b/src/cw/capwap.h @@ -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<> (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; istations << 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 +}; +/** + *@} + */ diff --git a/src/cw/capwap_cisco.h b/src/cw/capwap_cisco.h index ead10b23..c91f49f3 100644 --- a/src/cw/capwap_cisco.h +++ b/src/cw/capwap_cisco.h @@ -28,7 +28,7 @@ #include #include "lwapp.h" -#include "capwap.h" +#include "cw.h" #define CW_CISCO_MWAR_ADDR LW_ELEM_AC_ADDRESS /* 2 */ #define CW_CISCO_RAD 3 diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c index 67f75a13..5fb86dfe 100644 --- a/src/cw/conn_process_packet.c +++ b/src/cw/conn_process_packet.c @@ -21,7 +21,7 @@ #include #include -#include "capwap.h" +#include "cw.h" #include "dbg.h" #include "log.h" diff --git a/src/cw/cw.h b/src/cw/cw.h index 7dcb5ef1..80788a62 100644 --- a/src/cw/cw.h +++ b/src/cw/cw.h @@ -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<> (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; istations << 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 -}; - -/** - *@} - */ - /** diff --git a/src/cw/cw_in_ac_descriptor.c b/src/cw/cw_in_ac_descriptor.c index ce38f086..860e7250 100644 --- a/src/cw/cw_in_ac_descriptor.c +++ b/src/cw/cw_in_ac_descriptor.c @@ -1,5 +1,5 @@ -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "dbg.h" #include "mbag.h" diff --git a/src/cw/cw_in_ac_name_with_priority.c b/src/cw/cw_in_ac_name_with_priority.c index 8de0c304..dda3c14c 100644 --- a/src/cw/cw_in_ac_name_with_priority.c +++ b/src/cw/cw_in_ac_name_with_priority.c @@ -3,7 +3,7 @@ #include "dbg.h" #include "log.h" #include "mbag.h" -#include "capwap.h" +#include "cw.h" #include "acpriolist.h" diff --git a/src/cw/cw_in_capwap_control_ip_address.c b/src/cw/cw_in_capwap_control_ip_address.c index f9f5db57..3e542f32 100644 --- a/src/cw/cw_in_capwap_control_ip_address.c +++ b/src/cw/cw_in_capwap_control_ip_address.c @@ -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" diff --git a/src/cw/cw_in_cisco_add_wlan.c b/src/cw/cw_in_cisco_add_wlan.c index 710a8d4d..2a0a5fbb 100644 --- a/src/cw/cw_in_cisco_add_wlan.c +++ b/src/cw/cw_in_cisco_add_wlan.c @@ -3,7 +3,7 @@ #include "dbg.h" #include "log.h" #include "mbag.h" -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" diff --git a/src/cw/cw_in_generic.c b/src/cw/cw_in_generic.c index 72dbc4c9..8e7bffb8 100644 --- a/src/cw/cw_in_generic.c +++ b/src/cw/cw_in_generic.c @@ -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, diff --git a/src/cw/cw_in_generic2.c b/src/cw/cw_in_generic2.c index 83bc71d0..b395eda1 100644 --- a/src/cw/cw_in_generic2.c +++ b/src/cw/cw_in_generic2.c @@ -3,7 +3,7 @@ #include "dbg.h" #include "log.h" #include "mbag.h" -#include "capwap.h" +#include "cw.h" #include "item.h" diff --git a/src/cw/cw_in_radio_administrative_state.c b/src/cw/cw_in_radio_administrative_state.c index 1e52f7a9..043755ba 100644 --- a/src/cw/cw_in_radio_administrative_state.c +++ b/src/cw/cw_in_radio_administrative_state.c @@ -3,7 +3,7 @@ #include "dbg.h" #include "log.h" #include "mbag.h" -#include "capwap.h" +#include "cw.h" #include "radio.h" diff --git a/src/cw/cw_in_vendor_specific_payload.c b/src/cw/cw_in_vendor_specific_payload.c index 8c185494..79b3a353 100644 --- a/src/cw/cw_in_vendor_specific_payload.c +++ b/src/cw/cw_in_vendor_specific_payload.c @@ -1,5 +1,5 @@ -#include "capwap.h" +#include "cw.h" #include "dbg.h" #include "log.h" diff --git a/src/cw/cw_in_wtp_board_data.c b/src/cw/cw_in_wtp_board_data.c index 5847b3c9..5d55afaa 100644 --- a/src/cw/cw_in_wtp_board_data.c +++ b/src/cw/cw_in_wtp_board_data.c @@ -22,7 +22,7 @@ -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "mbag.h" diff --git a/src/cw/cw_out_ac_name_with_priority.c b/src/cw/cw_out_ac_name_with_priority.c index 2541bd13..b5e5b351 100644 --- a/src/cw/cw_out_ac_name_with_priority.c +++ b/src/cw/cw_out_ac_name_with_priority.c @@ -1,6 +1,6 @@ -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "dbg.h" diff --git a/src/cw/cw_out_capwap_control_ip_addr_list.c b/src/cw/cw_out_capwap_control_ip_addr_list.c index 9b758b26..36dfe4e1 100644 --- a/src/cw/cw_out_capwap_control_ip_addr_list.c +++ b/src/cw/cw_out_capwap_control_ip_addr_list.c @@ -1,7 +1,7 @@ #include "log.h" -#include "capwap.h" +#include "cw.h" #include "aciplist.h" #include "sock.h" diff --git a/src/cw/cw_out_capwap_local_ip_address.c b/src/cw/cw_out_capwap_local_ip_address.c index 3aa1259c..3be7716a 100644 --- a/src/cw/cw_out_capwap_local_ip_address.c +++ b/src/cw/cw_out_capwap_local_ip_address.c @@ -27,12 +27,11 @@ #include #include -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "dbg.h" #include "log.h" -#include "capwap.h" #include "conn.h" diff --git a/src/cw/cw_out_generic.c b/src/cw/cw_out_generic.c index bd14149a..32bc9fe7 100644 --- a/src/cw/cw_out_generic.c +++ b/src/cw/cw_out_generic.c @@ -1,7 +1,7 @@ -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "dbg.h" diff --git a/src/cw/cw_out_image_data.c b/src/cw/cw_out_image_data.c index 9ff4e326..2308d5a2 100644 --- a/src/cw/cw_out_image_data.c +++ b/src/cw/cw_out_image_data.c @@ -1,7 +1,7 @@ #include #include -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "log.h" diff --git a/src/cw/cw_out_radio_info.c b/src/cw/cw_out_radio_info.c index fe7548a1..6e931749 100644 --- a/src/cw/cw_out_radio_info.c +++ b/src/cw/cw_out_radio_info.c @@ -1,5 +1,5 @@ -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "capwap80211.h" #include "radio.h" diff --git a/src/cw/cw_out_radio_operational_state.c b/src/cw/cw_out_radio_operational_state.c index 20ea9659..7d03864e 100644 --- a/src/cw/cw_out_radio_operational_state.c +++ b/src/cw/cw_out_radio_operational_state.c @@ -1,5 +1,5 @@ -#include "capwap.h" +#include "cw.h" #include "capwap_items.h" #include "dbg.h" diff --git a/src/cw/cw_out_wtp_board_data.c b/src/cw/cw_out_wtp_board_data.c index be69c2fc..a5d3ef77 100644 --- a/src/cw/cw_out_wtp_board_data.c +++ b/src/cw/cw_out_wtp_board_data.c @@ -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); diff --git a/src/cw/cw_put_image_data.c b/src/cw/cw_put_image_data.c index ac9bbbb3..b18fe04b 100644 --- a/src/cw/cw_put_image_data.c +++ b/src/cw/cw_put_image_data.c @@ -1,5 +1,5 @@ -#include "capwap.h" +#include "cw.h" diff --git a/src/cw/cw_put_msg.c b/src/cw/cw_put_msg.c index e7e62ec1..fe5432c6 100644 --- a/src/cw/cw_put_msg.c +++ b/src/cw/cw_put_msg.c @@ -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; diff --git a/src/cw/cw_read_wtp_descriptor_7.c b/src/cw/cw_read_wtp_descriptor_7.c index ee8654b2..7e3b7bee 100644 --- a/src/cw/cw_read_wtp_descriptor_7.c +++ b/src/cw/cw_read_wtp_descriptor_7.c @@ -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); diff --git a/src/cw/format.h b/src/cw/format.h index e9d89292..d476d4bb 100644 --- a/src/cw/format.h +++ b/src/cw/format.h @@ -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, diff --git a/src/cw/mbag.h b/src/cw/mbag.h index d38ad486..14bfa0af 100644 --- a/src/cw/mbag.h +++ b/src/cw/mbag.h @@ -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; } diff --git a/src/cw/send.c b/src/cw/send.c index 1cc9edd7..4ee7ecc1 100644 --- a/src/cw/send.c +++ b/src/cw/send.c @@ -1,7 +1,7 @@ #include #include "conn.h" -#include "capwap.h" +#include "cw.h" #include "log.h" #include "dbg.h" #include "sock.h" diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c index 7123a77c..273e61f7 100644 --- a/src/mod/capwap/capwap_actions_ac.c +++ b/src/mod/capwap/capwap_actions_ac.c @@ -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" diff --git a/src/mod/capwap/capwap_actions_wtp.c b/src/mod/capwap/capwap_actions_wtp.c index 65144ac5..ce512c10 100644 --- a/src/mod/capwap/capwap_actions_wtp.c +++ b/src/mod/capwap/capwap_actions_wtp.c @@ -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 } diff --git a/src/mod/capwap/capwap_in_wtp_board_data.c b/src/mod/capwap/capwap_in_wtp_board_data.c index fc0dcb5f..d79c08cc 100644 --- a/src/mod/capwap/capwap_in_wtp_board_data.c +++ b/src/mod/capwap/capwap_in_wtp_board_data.c @@ -22,7 +22,7 @@ -#include "cw/capwap.h" +#include "cw/cw.h" #include "cw/capwap_items.h" #include "cw/mbag.h" diff --git a/src/mod/capwap/capwap_out_wtp_descriptor.c b/src/mod/capwap/capwap_out_wtp_descriptor.c index 167bc513..dda93783 100644 --- a/src/mod/capwap/capwap_out_wtp_descriptor.c +++ b/src/mod/capwap/capwap_out_wtp_descriptor.c @@ -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 diff --git a/src/mod/capwap80211/mod_capwap80211_ac.c b/src/mod/capwap80211/mod_capwap80211_ac.c index 2dcf0972..4be4a618 100644 --- a/src/mod/capwap80211/mod_capwap80211_ac.c +++ b/src/mod/capwap80211/mod_capwap80211_ac.c @@ -4,7 +4,7 @@ #include "cw/dbg.h" #include "cw/action.h" -#include "cw/capwap.h" +#include "cw/cw.h" #include "mod_capwap80211.h" diff --git a/src/mod/cisco/cisco_out_ac_descriptor.c b/src/mod/cisco/cisco_out_ac_descriptor.c index 5c912ab2..225356f3 100644 --- a/src/mod/cisco/cisco_out_ac_descriptor.c +++ b/src/mod/cisco/cisco_out_ac_descriptor.c @@ -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) diff --git a/src/mod/cisco/mod_cisco_ac.c b/src/mod/cisco/mod_cisco_ac.c index ba4f785b..3f837e4f 100644 --- a/src/mod/cisco/mod_cisco_ac.c +++ b/src/mod/cisco/mod_cisco_ac.c @@ -1,5 +1,5 @@ -#include "cw/capwap.h" +#include "cw/cw.h" #include "cw/mod.h" #include "cw/log.h" #include "cw/dbg.h" diff --git a/src/wtp/Makefile b/src/wtp/Makefile index 213666f0..21bbddee 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -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 diff --git a/src/wtp/discovery.c b/src/wtp/discovery.c index 34ac20b2..ab337e7a 100644 --- a/src/wtp/discovery.c +++ b/src/wtp/discovery.c @@ -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; diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index 0b67ec60..20905b33 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -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;