From 673f59a651e14c918298cc183ba74798699adcdf Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Fri, 4 Mar 2016 20:01:38 +0000 Subject: [PATCH] Moved some functions from lwapp.h to lw.h, capwap.h to cw.h ... FossilOrigin-Name: 8b6f76655e93cdb212b833ec890772b57e53723cf30b4fa9635130701890b0f2 --- src/cw/Makefile | 3 +- src/cw/capwap.h | 14 +++----- src/cw/cw.h | 43 ++++++++++++++++++----- src/cw/cw_in_wtp_descriptor.c | 6 ++-- src/cw/cw_out_ac_descriptor.c | 3 ++ src/cw/cw_out_wtp_descriptor.c | 3 ++ src/cw/lw.h | 63 ++++++++++++++++++++++++++++++++++ src/cw/lw_addelem.c | 1 + src/cw/lw_put_ac_descriptor.c | 1 + src/cw/lw_put_cisco_path_mtu.c | 1 + src/cw/lw_put_image_data.c | 1 + src/cw/lwapp.h | 10 ++++++ src/wtp/image_update.c | 2 +- src/wtp/wtp_main.c | 2 +- 14 files changed, 129 insertions(+), 24 deletions(-) diff --git a/src/cw/Makefile b/src/cw/Makefile index 674ee1b4..52a6199e 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -224,6 +224,8 @@ BSTROBJS= bstr_create.o \ FRAGOBJS=fragman.o +# cw_in_wtp_descriptor.o \ + CWACTION=action.o \ capwap_actions_ac.o \ capwap_actions_wtp.o \ @@ -231,7 +233,6 @@ CWACTION=action.o \ capwap_80211_actions_ac.o \ cw_in_generic.o \ cw_in_generic2.o \ - cw_in_wtp_descriptor.o \ cw_out_wtp_board_data.o \ cw_out_ac_name_with_priority.o \ cw_in_ac_name_with_priority.o \ diff --git a/src/cw/capwap.h b/src/cw/capwap.h index f772a050..cae9d834 100644 --- a/src/cw/capwap.h +++ b/src/cw/capwap.h @@ -39,7 +39,7 @@ #include "lwapp.h" #include "strlist.h" - +#include "cw.h" /* capwap version and iana number */ @@ -605,6 +605,7 @@ 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 @@ -619,6 +620,8 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le #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))) @@ -1081,15 +1084,6 @@ static inline int cw_put_ac_status(uint8_t * dst, struct cw_ac_status *s) } -static inline int cw_put_version(uint8_t * dst, uint16_t subelem_id, uint8_t * v) -{ - uint8_t *d = dst; - d += cw_put_dword(d, bstrv_get_vendor_id(v)); - d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v)); - d += cw_put_data(d, bstrv_data(v), bstrv_len(v)); - return d - dst; -} - int cw_register_actions_capwap_ac(struct cw_actiondef *def); diff --git a/src/cw/cw.h b/src/cw/cw.h index d954d659..2ffe4402 100644 --- a/src/cw/cw.h +++ b/src/cw/cw.h @@ -1,6 +1,9 @@ #ifndef __CW_H #define __CW_H +#include + +#include "bstr.h" #include "mbag.h" #include "conn.h" #include "action.h" @@ -12,14 +15,7 @@ * @{ */ -extern int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn, - struct cw_action_in *a, uint8_t * data, int len); -extern int cw_read_wtp_descriptor_7(mbag_t mbag, struct conn *conn, - struct cw_action_in *a, uint8_t * data, int len); - -extern int cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data, - int len); /* Use some macros from LWAPP */ @@ -29,7 +25,7 @@ extern int cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data, */ #define cw_put_byte lw_put_byte /** - * Put a word to an output buffee. + * Put a word to an output buffer. * see #lw_put_word */ #define cw_put_word lw_put_word @@ -38,6 +34,37 @@ extern int cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * 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 + + + +static inline int cw_put_version(uint8_t * dst, uint16_t subelem_id, bstrv_t v) +{ + uint8_t *d = dst; + d += cw_put_dword(d, bstrv_get_vendor_id(v)); + d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v)); + d += cw_put_data(d, bstrv_data(v), bstrv_len(v)); + 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); + +extern int cw_read_wtp_descriptor_7(mbag_t mbag, struct conn *conn, + struct cw_action_in *a, uint8_t * data, int len); + +extern int cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data, + int len); + + + + + /** *@} diff --git a/src/cw/cw_in_wtp_descriptor.c b/src/cw/cw_in_wtp_descriptor.c index f9966cd2..11ad24b7 100644 --- a/src/cw/cw_in_wtp_descriptor.c +++ b/src/cw/cw_in_wtp_descriptor.c @@ -27,7 +27,7 @@ #include "sock.h" -static int cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data, +static int _cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data, int len, int silent) { int i = 0; @@ -164,7 +164,7 @@ static int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn, pos += 3; } - return cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); + return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); } @@ -190,7 +190,7 @@ static int cw_read_cisco_wtp_descriptor(mbag_t mbag, struct conn *conn, cw_get_word(data + pos + 2); pos += 2; - return cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); + return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); } diff --git a/src/cw/cw_out_ac_descriptor.c b/src/cw/cw_out_ac_descriptor.c index d49871a3..87146487 100644 --- a/src/cw/cw_out_ac_descriptor.c +++ b/src/cw/cw_out_ac_descriptor.c @@ -6,6 +6,9 @@ #include "capwap.h" +#include "cw.h" + + /* int cw_put_subelem_version(uint8_t *dst,uint16_t subelem_id, uint32_t vendor_id,bstr16_t data) { diff --git a/src/cw/cw_out_wtp_descriptor.c b/src/cw/cw_out_wtp_descriptor.c index e4c99301..db9e5701 100644 --- a/src/cw/cw_out_wtp_descriptor.c +++ b/src/cw/cw_out_wtp_descriptor.c @@ -5,6 +5,9 @@ #include "capwap_items.h" #include "capwap.h" +#include "cw.h" + + static int cw_put_encryption_subelems(uint8_t *dst,int capwap_mode) { if (capwap_mode==CW_MODE_CISCO){ diff --git a/src/cw/lw.h b/src/cw/lw.h index 595cea92..41bf9743 100644 --- a/src/cw/lw.h +++ b/src/cw/lw.h @@ -57,6 +57,69 @@ #define lw_get_dword(src) \ (ntohl( *((uint32_t*)(src)))) + + + +/* the following functions are defined as static inline and not as + macro to avoid any side effects */ + + +/** + * Put some bytes to an output buffer + * @param dst Destination + * @param data Data to put + * @len length of data (iini bytes) + * @return The number of bytes put + */ +static inline int lw_put_data(uint8_t*dst,const uint8_t*data,uint16_t len) +{ + memcpy(dst,data,len); + return len; +} + +/** + * Put a #bstr_t to an output buffer + * @param dst Destination + * @param b bstr to put + * @return The number of bytes put + */ +static inline int lw_put_bstr(uint8_t * dst, const bstr_t b){ + lw_put_data(dst,bstr_data(b),bstr_len(b)); + return bstr_len(b); +} + +/** + * Put a #bstr16_t to an output buffer + * @param dst Destination + * @param b bstr16 to put + * @return The number of bytes put + */ +static inline int lw_put_bstr16(uint8_t * dst, const bstr16_t b){ + lw_put_data(dst,bstr16_data(b),bstr16_len(b)); + return bstr16_len(b); +} + + +/** + * Put a string to an output buffer + * @param dst Output buffer + * @param str zero-terminated string to put + * @return number of bytes put + */ +static inline int lw_put_str(uint8_t*dst,const uint8_t *str) { + return lw_put_data(dst,str,strlen((char*)str)); +} + + +static inline int lw_put_elem_hdr(uint8_t *dst,uint8_t type,uint16_t len) +{ + *dst=type; + *((uint16_t*)(dst+1)) = htons(len); + return 3; +} + + + /** * @} */ diff --git a/src/cw/lw_addelem.c b/src/cw/lw_addelem.c index 724ab891..336d86a5 100644 --- a/src/cw/lw_addelem.c +++ b/src/cw/lw_addelem.c @@ -3,6 +3,7 @@ #include "lwapp.h" #include "lwapp_cisco.h" +#include "lw.h" diff --git a/src/cw/lw_put_ac_descriptor.c b/src/cw/lw_put_ac_descriptor.c index 07567dea..f2bd51cd 100644 --- a/src/cw/lw_put_ac_descriptor.c +++ b/src/cw/lw_put_ac_descriptor.c @@ -1,6 +1,7 @@ #include #include "lwapp.h" +#include "lw.h" int lw_put_ac_descriptor(uint8_t * dst) { diff --git a/src/cw/lw_put_cisco_path_mtu.c b/src/cw/lw_put_cisco_path_mtu.c index e6525cc0..726fe1c1 100644 --- a/src/cw/lw_put_cisco_path_mtu.c +++ b/src/cw/lw_put_cisco_path_mtu.c @@ -22,6 +22,7 @@ */ #include "lwapp_cisco.h" +#include "lw.h" /** * Put message element data for Cisco vendor specific LWAPP message diff --git a/src/cw/lw_put_image_data.c b/src/cw/lw_put_image_data.c index 8622ea59..effcb743 100644 --- a/src/cw/lw_put_image_data.c +++ b/src/cw/lw_put_image_data.c @@ -1,4 +1,5 @@ #include "lwapp.h" +#include "lw.h" int lw_put_image_data(uint8_t *dst,FILE *infile) { diff --git a/src/cw/lwapp.h b/src/cw/lwapp.h index 7c99998d..ea9987b2 100644 --- a/src/cw/lwapp.h +++ b/src/cw/lwapp.h @@ -186,6 +186,7 @@ #define lw_foreach_elem(d,msg,len) for(d=msg; doutgoing, CW_ITEM_IMAGE_IDENTIFIER, + mbag_set_bstrv(conn->outgoing, CW_ITEM_IMAGE_IDENTIFIER, CW_VENDOR_ID_CISCO, (uint8_t *) ii, strlen(ii)); diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index 60b842cc..936ca5f1 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -172,7 +172,7 @@ conn->config=mbag_create(); mbag_set_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, board_data); -// hw = vendorstr_create(conf_vendor_id,conf_hardware_version +// hw = bstrv_create(conf_vendor_id,conf_hardware_version //mbag_set_bstr16(conn->config, CW_ITEM_WTP_HARDWARE_VERSION,conf_hardware_version); //mbag_set_bstr16(conn->config, CW_ITEM_WTP_SOFTWARE_VERSION,conf_software_version);