From d8c8bd022e50b7173b5b47d0782fdf18cdde935b Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Wed, 28 Feb 2018 08:05:45 +0000 Subject: [PATCH 1/7] Work on ansi and clean Makefiles FossilOrigin-Name: 0805f78d34219a2aac597a313081ce869c389e6b5d471c65c7f43d0906c0a400 --- src/cw/acinfo_print.c | 78 ---------- src/cw/avliter_next.c | 69 --------- src/cw/avltree_foreach.c | 39 ----- src/cw/avltree_foreach_from_lr.c | 31 ---- src/cw/avltree_foreach_lr.c | 17 --- src/cw/avltree_foreach_node.c | 33 ----- src/cw/avltree_foreach_rl.c | 18 --- src/cw/avltree_get.c | 47 ------ src/cw/avltree_get_node.c | 39 ----- src/cw/bstr.h | 28 +--- src/cw/bstr16_create.c | 13 ++ src/cw/bstrv_create.c | 17 +++ src/cw/capwap_80211_actions.h | 13 -- src/cw/capwap_80211_actions_ac.c | 65 -------- src/cw/capwap_80211_actions_wtp.c | 64 -------- src/cw/conn_get_message.c | 78 ---------- src/cw/conn_prepare_image_data_request.c | 4 +- src/cw/conn_send_request.c | 7 +- src/cw/conn_wait_for_message.c | 37 ----- src/cw/cw_addelem_capwap_local_ip_addr.c | 3 +- .../cw_prepare_configuration_status_request.c | 37 ----- src/cw/cw_read_image_data_request.c | 5 +- src/cw/cw_readelem_ac_descriptor.c | 140 ------------------ src/cw/cw_readelem_cisco_wtp_radio_cfg.c | 7 +- src/cw/cw_readelem_maximum_message_length.c | 37 ----- src/cw/cw_readelem_statistics_timer.c | 4 +- .../cw_readmsg_configuration_status_request.c | 22 --- src/cw/cw_send_image_file.c | 102 ------------- src/cw/cwmsg_addelem_mtu_discovery_padding.c | 2 +- src/cw/item_strings.c | 16 -- ...w_put_80211_wtp_wlan_radio_configuration.c | 9 +- src/cw/lw_readelem_wtp_board_data.c | 4 +- src/cw/lw_readelem_wtp_name.c | 3 +- src/cw/mavl.h | 60 +------- src/cw/mavl_destroy.c | 9 ++ src/cw/mavl_replace.c | 12 ++ src/cw/mavl_replace_data.c | 12 ++ src/cw/mavliter_get.c | 14 ++ src/cw/mavliter_init.c | 19 +++ src/cw/mavliter_seek_set.c | 10 ++ src/cw/sock_getifaddr.c | 9 +- src/cw/wtpinfo_lwreadelem_wtp_descriptor.c | 59 -------- 42 files changed, 147 insertions(+), 1145 deletions(-) delete mode 100644 src/cw/acinfo_print.c delete mode 100644 src/cw/avliter_next.c delete mode 100644 src/cw/avltree_foreach.c delete mode 100644 src/cw/avltree_foreach_from_lr.c delete mode 100644 src/cw/avltree_foreach_lr.c delete mode 100644 src/cw/avltree_foreach_node.c delete mode 100644 src/cw/avltree_foreach_rl.c delete mode 100644 src/cw/avltree_get.c delete mode 100644 src/cw/avltree_get_node.c create mode 100644 src/cw/bstr16_create.c create mode 100644 src/cw/bstrv_create.c delete mode 100644 src/cw/capwap_80211_actions.h delete mode 100644 src/cw/capwap_80211_actions_ac.c delete mode 100644 src/cw/capwap_80211_actions_wtp.c delete mode 100644 src/cw/conn_get_message.c delete mode 100644 src/cw/conn_wait_for_message.c delete mode 100644 src/cw/cw_prepare_configuration_status_request.c delete mode 100644 src/cw/cw_readelem_ac_descriptor.c delete mode 100644 src/cw/cw_readelem_maximum_message_length.c delete mode 100644 src/cw/cw_readmsg_configuration_status_request.c delete mode 100644 src/cw/cw_send_image_file.c delete mode 100644 src/cw/item_strings.c create mode 100644 src/cw/mavl_destroy.c create mode 100644 src/cw/mavl_replace.c create mode 100644 src/cw/mavl_replace_data.c create mode 100644 src/cw/mavliter_get.c create mode 100644 src/cw/mavliter_init.c create mode 100644 src/cw/mavliter_seek_set.c delete mode 100644 src/cw/wtpinfo_lwreadelem_wtp_descriptor.c diff --git a/src/cw/acinfo_print.c b/src/cw/acinfo_print.c deleted file mode 100644 index 5dbebf36..00000000 --- a/src/cw/acinfo_print.c +++ /dev/null @@ -1,78 +0,0 @@ - -/** - * @file - * @breif defines acinfo_print function - */ - -#include -#include - -#include "capwap.h" -#include "sock.h" - -#include "acinfo.h" - -#include "cw_util.h" - - -/** - * Formats an acinfo object. - * - */ -int acinfo_print(char *str,const struct ac_info *acinfo) -{ - char *s = str; - - s+=sprintf(s,"\tAC name: %s\n",acinfo->ac_name); - - s+=sprintf(s,"\tHardware version: "); - s+=cw_format_version(s,acinfo->hardware_version,0,"-"); - s+=sprintf(s,"\n"); - - s+=sprintf(s,"\tSoftware version: "); - s+=cw_format_version(s,acinfo->software_version,0,"-"); - s+=sprintf(s,"\n"); - - s+=sprintf(s,"\tStations: %i\n",acinfo->stations); - s+=sprintf(s,"\tSation limit: %i\n",acinfo->limit); - s+=sprintf(s,"\tActive WTPs: %i\n",acinfo->active_wtps); - s+=sprintf(s,"\tMax WTPs: %i\n",acinfo->max_wtps); - char help[64]; - sock_addrtostr((struct sockaddr*)&acinfo->local_ip,help,64); - s+=sprintf(s,"\tLocal IP: %s\n",help); - s+=sprintf(s,"\tECN support: %s\n",acinfo->ecn_support==0 ? "limited" : "full"); - s+=sprintf(s,"\tRMAC support: %s\n",acinfo->rmac==1 ? "supported" : "not supported"); - - - help[0]=0; - if (acinfo->security & AC_SECURITY_S) - strcpy(help,"psk"); - if (acinfo->security & AC_SECURITY_X){ - if (strlen(help)) - strcat(help,"/"); - strcat(help,"X.509"); - } - if (!strlen(help)) - strcpy(help,"None"); - s+=sprintf(s,"\tSecurity: %s\n",help); - - help[0]=0; -/* if (acinfo->dtls_policy & AC_DTLS_POLICY_D){ - strcpy(help,"dtls"); - } - if (acinfo->dtls_policy & AC_DTLS_POLICY_C){ - if(strlen(help)) - strcat(help,"/"); - strcat(help,"clear"); - } -*/ if (!strlen(help)) - strcpy(help,"Not set"); - - s+=sprintf(s,"\tDTLS policy: %s\n",help); - - - return s-str; -} - - - diff --git a/src/cw/avliter_next.c b/src/cw/avliter_next.c deleted file mode 100644 index 5e97f332..00000000 --- a/src/cw/avliter_next.c +++ /dev/null @@ -1,69 +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 . - -*/ - -/** - *@file - *@brief Implementation of avliter_next - */ - -#include "avltree.h" - -/** - * Get the next element within an AVL Tree. - * @param i pointer to AVL Iterator - * @return the element or NULL if there is no next elemeent. - */ -void * avliter_next(avliter_t *i) -{ - - while ( i->stack_ptr) { - i->stack_ptr--; - i->cur=i->stack[i->stack_ptr]; - - if (!i->cur) - continue; - - if ((i->stack_ptr)&1) { - return i->cur->data; - } - break; - - } - - - if (!i->cur){ - return NULL; - } - - while(i->cur->left) { - /* push right branch */ - i->stack[i->stack_ptr++]=i->cur->right; - - /* push node */ - i->stack[i->stack_ptr++]=i->cur; - - i->cur=i->cur->left; - - } - - i->stack[i->stack_ptr++]=i->cur->right; - - return i->cur->data; -} - - diff --git a/src/cw/avltree_foreach.c b/src/cw/avltree_foreach.c deleted file mode 100644 index 795e7b77..00000000 --- a/src/cw/avltree_foreach.c +++ /dev/null @@ -1,39 +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" - -int avltree_foreach_rl(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv) -{ - if (!n) - return 1; - if (!avltree_foreach_rl(n->right,callback,cbpriv)) - return 0; - if (!callback(cbpriv,n->data)) - return 0; - return avltree_foreach_rl(n->left,callback,cbpriv); -} - -void avltree_foreach(struct avltree *t, int (*callback)(void *,void *),void * cbpriv,int dir) -{ - if (dir) - avltree_foreach_lr(t->root,callback,cbpriv); - else - avltree_foreach_rl(t->root,callback,cbpriv); -} - diff --git a/src/cw/avltree_foreach_from_lr.c b/src/cw/avltree_foreach_from_lr.c deleted file mode 100644 index f5d4cb22..00000000 --- a/src/cw/avltree_foreach_from_lr.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "avltree.h" - - -// XXX Function is buggy - -int avltree_foreach_from_lr(struct avltree *t, struct avlnode *n, void *data,int (*callback)(void *,void *),void *cbpriv) -{ - if (!n) - return 1; - - int rc=t->cmp(data,n->data); - if (rc<0){ - if(!avltree_foreach_from_lr(t,n->left,data,callback,cbpriv)) - return 0; - if (!callback(cbpriv,n->data)) - return 0; - return avltree_foreach_lr(n->right,callback,cbpriv); - } - - if (rc>0) { - avltree_foreach_from_lr(t,n->right,data,callback,cbpriv); - return 0; - } - - if (!callback(cbpriv,n->data)) - return 0; - - return avltree_foreach_lr(n->right,callback,cbpriv); -} - - diff --git a/src/cw/avltree_foreach_lr.c b/src/cw/avltree_foreach_lr.c deleted file mode 100644 index 599d7bd0..00000000 --- a/src/cw/avltree_foreach_lr.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "avltree.h" - - - -int avltree_foreach_lr(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv) -{ - if (!n) - return 1; - if (!avltree_foreach_lr(n->left,callback,cbpriv)) - return 0; - if (!callback(cbpriv,n->data)) - return 0; - return avltree_foreach_lr(n->right,callback,cbpriv); - -} - - diff --git a/src/cw/avltree_foreach_node.c b/src/cw/avltree_foreach_node.c deleted file mode 100644 index 5e0ada87..00000000 --- a/src/cw/avltree_foreach_node.c +++ /dev/null @@ -1,33 +0,0 @@ - - - -int avltree_foreach_lr_node(struct avltree *t, struct avlnode *n, void *data,int (*callback)(void *,void *),void *cbpriv) -{ - if (!n) - return 1; - - int rc=t->cmp(data,n->data); - if (rc<0){ - avltree_foreach_lr_node(t,n->left,data,callback,cbpriv); - callback(cbpriv,n->data); - avltree_foreach_lr(n->right, - return 0; - } - - if (rc>0) { - avltree_foreach_lr_node(t,n->right,data,callback,cbpriv); - return 0; - } - - return callback(cbpriv,n->data); - - - - -} - - -int avltree_foreach_2(struct avltree *t,void *data,int (*callback)(void *,void *),void *cbpriv) -{ - -} diff --git a/src/cw/avltree_foreach_rl.c b/src/cw/avltree_foreach_rl.c deleted file mode 100644 index 7ee82a8f..00000000 --- a/src/cw/avltree_foreach_rl.c +++ /dev/null @@ -1,18 +0,0 @@ - - - - -#include "avltree.h" - -int avltree_foreach_rl(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv) -{ - if (!n) - return 1; - if (!avltree_foreach_rl(n->right,callback,cbpriv)) - return 0; - if (!callback(cbpriv,n->data)) - return 0; - return avltree_foreach_rl(n->left,callback,cbpriv); -} - - diff --git a/src/cw/avltree_get.c b/src/cw/avltree_get.c deleted file mode 100644 index 62950050..00000000 --- a/src/cw/avltree_get.c +++ /dev/null @@ -1,47 +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 . -*/ - -/** - * @file - * @brief Implementation of avltree_get - */ - -#include - -#include "avltree.h" - -/** - * Get an AVL tree element. - * @param data Element to get - * @return pointer to element or NULL if not found. - */ -void * avltree_get(struct avltree *t ,void *data) -{ - struct avlnode *n = t->root; - while(n){ - int rc=t->cmp(data,n->data); - if (rc==0) - return n->data; - if (rc<0) - n=n->left; - else - n=n->right; - } - return NULL; -} - - diff --git a/src/cw/avltree_get_node.c b/src/cw/avltree_get_node.c deleted file mode 100644 index 8d3d3ff5..00000000 --- a/src/cw/avltree_get_node.c +++ /dev/null @@ -1,39 +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 - -#include "avltree.h" - - -struct avlnode * avltree_get_node(struct avltree *t ,void *data) -{ - struct avlnode *n = t->root; - while(n){ - int rc=t->cmp(data,n->data); - if (rc==0) - return n; - if (rc<0) - n=n->left; - else - n=n->right; - } - return NULL; -} - diff --git a/src/cw/bstr.h b/src/cw/bstr.h index 779656b4..3351a3db 100644 --- a/src/cw/bstr.h +++ b/src/cw/bstr.h @@ -130,16 +130,7 @@ static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len) */ -static inline uint8_t * bstr16_create(const uint8_t *data, uint16_t len) -{ - uint8_t * str = malloc(2+len*sizeof(uint8_t)); - if (!str) - return 0; - *((uint16_t*)str)=len; - memcpy(str+2,data,len); - return str; -} - +extern uint8_t * bstr16_create(const uint8_t *data, uint16_t len); uint8_t * bstr16_create_from_str(const char *s); extern uint8_t * bstr16_create_from_cfgstr(const char * s); @@ -182,25 +173,10 @@ typedef uint8_t * bstrv_t; (1+6+(n)*sizeof(uint8_t)) -static inline uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len) -{ - uint8_t * str = malloc(bstrv_size(len)); - if (!str) - return 0; - - bstrv_set_vendor_id(str,vendor_id); - bstrv_set_len(str,len); - memcpy(bstrv_data(str),data,len); - *(bstrv_data(str)+bstrv_len(str))=0; - return str; - -} - uint8_t * bstrv_create_from_str(uint32_t vendor_id,const char *s); +uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len); -//uint8_t * bstr16cfgstr(const char * s); - #endif diff --git a/src/cw/bstr16_create.c b/src/cw/bstr16_create.c new file mode 100644 index 00000000..4738e1b1 --- /dev/null +++ b/src/cw/bstr16_create.c @@ -0,0 +1,13 @@ +#include "bstr.h" + +uint8_t * bstr16_create(const uint8_t *data, uint16_t len) +{ + uint8_t * str = malloc(2+len*sizeof(uint8_t)); + if (!str) + return 0; + *((uint16_t*)str)=len; + memcpy(str+2,data,len); + return str; +} + + diff --git a/src/cw/bstrv_create.c b/src/cw/bstrv_create.c new file mode 100644 index 00000000..17bdadc3 --- /dev/null +++ b/src/cw/bstrv_create.c @@ -0,0 +1,17 @@ +#include "bstr.h" + +uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len) +{ + uint8_t * str = malloc(bstrv_size(len)); + if (!str) + return 0; + + bstrv_set_vendor_id(str,vendor_id); + bstrv_set_len(str,len); + memcpy(bstrv_data(str),data,len); + *(bstrv_data(str)+bstrv_len(str))=0; + return str; + +} + + diff --git a/src/cw/capwap_80211_actions.h b/src/cw/capwap_80211_actions.h deleted file mode 100644 index 09bbfa99..00000000 --- a/src/cw/capwap_80211_actions.h +++ /dev/null @@ -1,13 +0,0 @@ - - -#include "capwap80211.h" -#include "capwap_items.h" - -#define CW_ACTION_IN_80211_WTP_RADIO_INFORMATION \ - CW_ELEM80211_WTP_RADIO_INFORMATION, /* Element ID*/ \ - cw_in_radio_generic, 0, /* start/end callback */ \ - MBAG_DWORD, /* Type of element */ \ - CW_ITEM_LOCATION_DATA, /* ID to use store */ \ - 5, 5 /* min/max length */ - - diff --git a/src/cw/capwap_80211_actions_ac.c b/src/cw/capwap_80211_actions_ac.c deleted file mode 100644 index 5f66d457..00000000 --- a/src/cw/capwap_80211_actions_ac.c +++ /dev/null @@ -1,65 +0,0 @@ - - -#include "action.h" -#include "capwap_80211_actions.h" -#include "capwap80211.h" -#include "capwap.h" - - - - - - -cw_action_in_t capwap_80211_actions_ac_in[] = { - - /* -------------------------------------------------------- - * Discovery Resquest - */ - - {0, 0, CAPWAP_STATE_DISCOVERY, CAPWAP_MSG_DISCOVERY_REQUEST, - CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1} - , - /* -------------------------------------------------------- - * Discovery Resquest - */ - - {0, 0, CW_STATE_JOIN, CAPWAP_MSG_JOIN_REQUEST, - CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1} - , - - - - {0, 0, 0} -}; - - -cw_action_out_t capwap_80211_actions_ac_out[]={ - /* Radio Infos */ - {CAPWAP_MSG_DISCOVERY_RESPONSE, NULL /*CW_ELEM80211_WTP_RADIO_INFORMATION*/, 0, - CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1} - , - - /* Radio Infos */ - {CAPWAP_MSG_JOIN_RESPONSE, NULL /*CW_ELEM80211_WTP_RADIO_INFORMATION*/, 0, - CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1} - , - - {0,0,0} -}; - - -int cw_register_actions_capwap_80211_ac(struct cw_actiondef *def) -{ - - int rc; - rc=cw_actionlist_in_register_actions(def->in, capwap_80211_actions_ac_in); - rc+=cw_actionlist_out_register_actions(def->out, capwap_80211_actions_ac_out); - - rc+= cw_strheap_register_strings(def->strelem, capwap_strings_elem80211); - /*rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem); -*/ - - - return rc; -} - diff --git a/src/cw/capwap_80211_actions_wtp.c b/src/cw/capwap_80211_actions_wtp.c deleted file mode 100644 index fdc7147b..00000000 --- a/src/cw/capwap_80211_actions_wtp.c +++ /dev/null @@ -1,64 +0,0 @@ - - -#include "action.h" -#include "capwap_80211_actions.h" -#include "capwap80211.h" -#include "capwap.h" - - - - - - -cw_action_in_t capwap_80211_actions_wtp_in[] = { - - /* Discovery Response */ - {0, 0, CAPWAP_STATE_DISCOVERY, CAPWAP_MSG_DISCOVERY_RESPONSE, - CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1} - , - - /* Join Response */ - {0, 0, CW_STATE_JOIN, CAPWAP_MSG_JOIN_RESPONSE, - CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1} - , - - - {0, 0, 0} -}; - - -cw_action_out_t capwap_80211_actions_wtp_out[]={ - - /* -------------------------------------------------------- - * Discovery Resquest - */ - - /* 802.11 Radio Information */ - {CAPWAP_MSG_DISCOVERY_REQUEST, CW_ITEM_RADIO_INFOS /*CW_ELEM80211_WTP_RADIO_INFORMATION*/, 0, - CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1} - , - - /* -------------------------------------------------------- - * Join Resquest - */ - - /* 802.11 Radio Information */ - {CAPWAP_MSG_JOIN_REQUEST, CW_ITEM_RADIO_INFOS, 0, - CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1}, - - - {0,0,0} - - -}; - - -int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def) -{ - int rc; - rc=cw_actionlist_in_register_actions(def->in, capwap_80211_actions_wtp_in); - rc+=cw_actionlist_out_register_actions(def->out, capwap_80211_actions_wtp_out); - rc+=cw_strheap_register_strings(def->strelem, capwap_strings_elem80211); - return rc; -} - diff --git a/src/cw/conn_get_message.c b/src/cw/conn_get_message.c deleted file mode 100644 index ad3e25e6..00000000 --- a/src/cw/conn_get_message.c +++ /dev/null @@ -1,78 +0,0 @@ - - -#include -#include -#include - -#include "conn.h" -#include "cwrmsg.h" -#include "cw_log.h" -#include "capwap.h" -#include "sock.h" -#include "cw_util.h" - -struct args { - struct conn *conn; - struct cwrmsg *cwrmsg; -}; - -static int message_cb(void *p, uint8_t *rawmsg, int len) -{ - struct args *args = (struct args *) p; - struct conn *conn = args->conn; - memcpy(conn->cwrmsg_buffer, rawmsg, len); - -/* - - memcpy(&conn->cwrmsg, cwrmsg, sizeof(struct cwrmsg)); - conn->cwrmsg.msgelems = conn->cwrmsg_buffer; -*/ - args->cwrmsg = &conn->cwrmsg; - return 0; -} - - -int conn_msg_processor(struct conn *conn) -{ - uint8_t buf[2024]; - int len = 2024; - - int n = conn->read(conn, buf, len); - if (n<0 ) - return n; - - if (n > 0) - conn_process_packet(conn, buf, n, cw_process_msg, conn); - -} - - - - -uint8_t *conn_get_message(struct conn *conn) -{ - struct args args; - args.cwrmsg = 0; - args.conn = conn; - uint8_t buf[2024]; - int len = 2024; - - int n = conn->read(conn, buf, len); - if (n > 0) - conn_process_packet(conn, buf, n, message_cb, &args); - - - if (args.cwrmsg) { - cw_dbg(DBG_MSG,"Message recieved from %s",sock_addr2str(&conn->addr)); -/* - cw_dbg(DBG_MSG, - "Received message from %s, type=%d - %s, seq=%d", - sock_addr2str(&conn->addr), args.cwrmsg->type, - cw_msgtostr(args.cwrmsg->type), - args.cwrmsg->seqnum); - -*/ - } - - return conn->cwrmsg_buffer; -} diff --git a/src/cw/conn_prepare_image_data_request.c b/src/cw/conn_prepare_image_data_request.c index 39fadd98..7259b3ab 100644 --- a/src/cw/conn_prepare_image_data_request.c +++ b/src/cw/conn_prepare_image_data_request.c @@ -34,7 +34,7 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data /* for Cisco APs send image data in "LWAPP format" */ - if (conn->capwap_mode == CWMODE_CISCO) { +/* if (conn->capwap_mode == CWMODE_CISCO) { uint8_t type = 3; uint16_t checksum = htons(lw_checksum(data->data, data->len)); cwmsg_vaddelem(cwmsg, CW_ELEM_IMAGE_DATA, @@ -44,7 +44,7 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data NULL); return 0; } - +*/ /* standard capwap operation */ diff --git a/src/cw/conn_send_request.c b/src/cw/conn_send_request.c index 48bc426b..634766a5 100644 --- a/src/cw/conn_send_request.c +++ b/src/cw/conn_send_request.c @@ -23,7 +23,7 @@ #include "capwap.h" #include "cw_util.h" -#include "cw_log.h" +#include "log.h" /** * Send a request message and wait for its response @@ -32,6 +32,9 @@ * The message has to be prepared and put to conn->req_msg * */ + + +/* struct cwrmsg * conn_send_request(struct conn * conn) { int i; @@ -58,4 +61,4 @@ struct cwrmsg * conn_send_request(struct conn * conn) cw_dbg(DBG_MSG_ERR,"Max retransmit's reached, message type=%d,seq=%d",cwmsg->type,cwmsg->seqnum); return 0; } - +*/ diff --git a/src/cw/conn_wait_for_message.c b/src/cw/conn_wait_for_message.c deleted file mode 100644 index 7c00aa95..00000000 --- a/src/cw/conn_wait_for_message.c +++ /dev/null @@ -1,37 +0,0 @@ - -#include "conn.h" -#include "cw_util.h" - - -struct cwrmsg * conn_wait_for_message(struct conn * conn, time_t timer) -{ - struct cwrmsg * cwrmsg; - - - while (!cw_timer_timeout(timer)){ - cwrmsg = conn_get_message(conn); - - if (!cwrmsg){ - if (!conn_is_error(conn)) - continue; - - return 0; - } - - if (cwrmsg->type & 1){ - if (conn->request_handler){ - if (conn->request_handler(conn->request_handler_param)) - continue; - } - - - } - - return cwrmsg; - - } - - return 0; -} - - diff --git a/src/cw/cw_addelem_capwap_local_ip_addr.c b/src/cw/cw_addelem_capwap_local_ip_addr.c index deeb0b1a..a871193b 100644 --- a/src/cw/cw_addelem_capwap_local_ip_addr.c +++ b/src/cw/cw_addelem_capwap_local_ip_addr.c @@ -27,6 +27,7 @@ #include "cwmsg.h" #include "conn.h" +/* uint8_t * cw_addelem(uint8_t * buf,int type, uint8_t *elem, int len) { @@ -76,4 +77,4 @@ void cw_addelem_capwap_local_ip_addr(struct cwmsg *msg, int sock, int cw_mode) } - +*/ diff --git a/src/cw/cw_prepare_configuration_status_request.c b/src/cw/cw_prepare_configuration_status_request.c deleted file mode 100644 index d83eb581..00000000 --- a/src/cw/cw_prepare_configuration_status_request.c +++ /dev/null @@ -1,37 +0,0 @@ - -#include "capwap.h" -#include "lwapp_cisco.h" -#include "capwap_cisco.h" - - -#include "conn.h" -#include "wtpinfo.h" - -void cw_prepare_configuration_status_request(struct conn * conn, struct radioinfo * radioinfo, struct wtpinfo *wtpinfo) -{ - struct cwmsg * cwmsg = &conn->req_msg; - uint8_t * buffer = conn->req_buffer; - - cwmsg_init(cwmsg,buffer,CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST,conn_get_next_seqnum(conn),radioinfo); - cwmsg->capwap_mode=conn->capwap_mode; - - cwmsg_addelem_ac_name(cwmsg,(uint8_t *)"AC-iMaxi"); - - - cwmsg_addelem_cisco_ap_regulatory_domain(cwmsg,&wtpinfo->radioinfo[0]); - cwmsg_addelem_cisco_ap_regulatory_domain(cwmsg,&wtpinfo->radioinfo[1]); - - cwmsg_addelem_cisco_wtp_radio_cfg(cwmsg,&wtpinfo->radioinfo[0]); - cwmsg_addelem_cisco_wtp_radio_cfg(cwmsg,&wtpinfo->radioinfo[1]); - -/* - uint8_t mtu[2048]; - int l = lw_put_cisco_path_mtu(mtu,1485,1701); - - printf("Len = %d\n",l); - - cwmsg_addelem_vendor_specific_payload(cwmsg,LW_VENDOR_CISCO, - LW_ELEM_VENDOR_SPECIFIC,mtu,l); - -*/ -} diff --git a/src/cw/cw_read_image_data_request.c b/src/cw/cw_read_image_data_request.c index c6cfd8c9..e7deeaf4 100644 --- a/src/cw/cw_read_image_data_request.c +++ b/src/cw/cw_read_image_data_request.c @@ -24,7 +24,8 @@ #include "capwap.h" -#include "cw_log.h" +#include "log.h" +#include "dbg.h" #include "cw_util.h" #include @@ -54,7 +55,7 @@ static int imgdata_request(void * ptr,int type,uint8_t* msgelem,int len) cw_dbg_msgelem(CW_MSG_IMAGE_DATA_REQUEST, type, msgelem, len); - cw_dbg(DBG_ALL,"Reading image data req msgelem, type=%d - %s ,len=%d\n",type,cw_strelem(type),len); + //cw_dbg(DBG_ALL,"Reading image data req msgelem, type=%d - %s ,len=%d\n",type,cw_strelem(type),len); if (cw_readelem_image_identifier(ptr,type,msgelem,len)) return 1; diff --git a/src/cw/cw_readelem_ac_descriptor.c b/src/cw/cw_readelem_ac_descriptor.c deleted file mode 100644 index 362700f6..00000000 --- a/src/cw/cw_readelem_ac_descriptor.c +++ /dev/null @@ -1,140 +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 . - -*/ - -/** - * @file - * @brief cw_readelem_ac_descriptor is implemented here. - */ - -#include "capwap.h" -#include "acinfo.h" -#include "bstr.h" -#include "cw_log.h" - - -static int read_subelem_cisco(struct ac_info* acinfo,int subtype,uint8_t * elem, int len) -{ - switch (subtype) { - case 0: - /* hardware version */ - bstr_replace(&acinfo->hardware_version,bstr_create(elem,len)); - break; - case 1: - /* software version */ - bstr_replace(&acinfo->software_version,bstr_create(elem,len)); - break; - - default: - //printf("What? %d\n",subtype); - break; - - } - - return 1; -} - - -static int read_subelem(struct ac_info* acinfo,int subtype,uint8_t *elem, int len) -{ - switch (subtype){ - case 4: - /* hardware version */ - bstr_replace(&acinfo->hardware_version,bstr_create(elem,len)); - break; - case 5: - /* software version */ - bstr_replace(&acinfo->software_version,bstr_create(elem,len)); - break; - } - - return 1; -} - -/** - * Read CAPWAP message elment: AC Descriptor - * @param acinfo pointer to acinfo where the result is stored - * @param type message element type - * @param msgelem pointer to message element - * @param len length of message element - * @return 1 AC descriptor sucessfull read \n - * 0 not an ac descriptor message\n - * -1 an error has occured - */ -int cw_readelem_ac_descriptor(struct ac_info * acinfo,int type, uint8_t *msgelem, int len) -{ - if (type != CAPWAP_ELEM_AC_DESCRIPTOR) - return 0; - - if (len<12) - return -1; - - uint32_t val; - - /* read stations and limit */ - val = ntohl(*((uint32_t*)msgelem)); - acinfo->stations = val>>16; - acinfo->limit = val&0xffff; - - - /* read active wtps and max wtps */ - val = ntohl(*((uint32_t*)(msgelem+4))); - acinfo->active_wtps = val>>16; - acinfo->max_wtps = val&0xffff; - - /* read active wtps and max wtps */ - val = ntohl(*((uint32_t*)(msgelem+8))); - acinfo->security = val >>24; - acinfo->rmac= (val >> 16)&0xff; - acinfo->dtls_policy=val&0xf; - - int sub=12; - int sublen; - - - while (sub>16; - - cw_dbg(DBG_ELEM,"AC Descriptor sub-element vendor: %d, type:%d, len: %d",vendor,subtype,sublen); - switch (vendor) { - case 0: - read_subelem(acinfo,subtype,msgelem+sub,sublen); - break; - - case CW_VENDOR_ID_CISCO: - read_subelem_cisco(acinfo,subtype,msgelem+sub,sublen); - break; - - } - - if (sub+sublen>len) - return -1; - - sub+=sublen; - } - - return 1; -} - - diff --git a/src/cw/cw_readelem_cisco_wtp_radio_cfg.c b/src/cw/cw_readelem_cisco_wtp_radio_cfg.c index 2e962f00..a4879fde 100644 --- a/src/cw/cw_readelem_cisco_wtp_radio_cfg.c +++ b/src/cw/cw_readelem_cisco_wtp_radio_cfg.c @@ -1,4 +1,4 @@ - +/* #include "capwap_cisco.h" #include "cw_log.h" @@ -19,4 +19,7 @@ int cw_readelem_cisco_wtp_radio_cfg(int elem_id,uint8_t *elem, int len,struct ra ri->beacon_period = lw_get_word(elem+13); return 1; -} +} + + +*/ diff --git a/src/cw/cw_readelem_maximum_message_length.c b/src/cw/cw_readelem_maximum_message_length.c deleted file mode 100644 index dcf6bb53..00000000 --- a/src/cw/cw_readelem_maximum_message_length.c +++ /dev/null @@ -1,37 +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 "capwap.h" -#include "cw_util.h" -#include "log.h" - -int cw_readelem_maximum_message_length(uint16_t *dst, int type,uint8_t *msgelem, int len) -{ - if (type != CWMSGELEM_MAXIMUM_MESSAGE_LENGTH) - return 0; - - if (len!=2){ - cw_dbg(DBG_CW_RFC,"Discarding MAXIMUM_MESSAGE_LENTGH msgelem, wrong size, type=%d,len=%d",type,len); - return 0; - } - - *dst = ntohs(* ((uint16_t*)msgelem)); - return 1; -} - - diff --git a/src/cw/cw_readelem_statistics_timer.c b/src/cw/cw_readelem_statistics_timer.c index dc26c9c9..382e0d30 100644 --- a/src/cw/cw_readelem_statistics_timer.c +++ b/src/cw/cw_readelem_statistics_timer.c @@ -1,6 +1,6 @@ #include "capwap.h" -#include "cw_log.h" +#include "dbg.h" int cw_readelem_statistics_timer(uint16_t *timer, int type, uint8_t * msgelem, int len) { @@ -8,7 +8,7 @@ int cw_readelem_statistics_timer(uint16_t *timer, int type, uint8_t * msgelem, i return 0; if (len!=2){ - cw_dbg(DBG_CW_RFC,"Statistics timer msgelem has wrong size, type=%d,len=%d",type,len); + cw_dbg(DBG_RFC,"Statistics timer msgelem has wrong size, type=%d,len=%d",type,len); return 0; } *timer=*((uint16_t*)msgelem); diff --git a/src/cw/cw_readmsg_configuration_status_request.c b/src/cw/cw_readmsg_configuration_status_request.c deleted file mode 100644 index 41792941..00000000 --- a/src/cw/cw_readmsg_configuration_status_request.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "capwap.h" -#include "cw_log.h" - -int cw_readmsg_configuration_update_request(uint8_t *elems,int elems_len) -{ - uint8_t * elem; - - cw_foreach_elem(elem,elems,elems_len){ - - int type = cw_get_elem_type(elem); - int len = cw_get_elem_len(elem); - uint8_t *data = cw_get_elem_data(elem); - - cw_dbg_msgelem(CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, type, data, len); - - -// cw_readelem_vendor_specific_payload(elem,CW_MSG_CONFIGURATION_STATUS_RESPONSE, type,data,len ); - - } - - -} diff --git a/src/cw/cw_send_image_file.c b/src/cw/cw_send_image_file.c deleted file mode 100644 index 3e45bbf6..00000000 --- a/src/cw/cw_send_image_file.c +++ /dev/null @@ -1,102 +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 . - -*/ - - -/** - * @file - * @breif send image file - */ - -#include -#include -#include - - -#include "capwap.h" -#include "lwapp.h" - -#include "sock.h" -#include "cw_log.h" - - -/** - * Send an image file to an AP - * - */ -void cw_send_image_file(struct conn *conn) -{ - -/* - FILE *infile; - infile = fopen(filename, "rb"); - if (!infile) { - cw_log(LOG_ERR, "Can't open image file %s:%s", filename, strerror(errno)); - return; - } - - - cw_log(LOG_INFO, "Sending image file %s to %s", filename, sock_addr2str(&conn->addr)); -*/ - - - - - - - uint8_t buffer[1024]; /* buffer MUST be 1024 */ - - - struct cwimage_data data; - memset(&data,0,sizeof(struct cwimage_data)); - data.data = buffer; - - -/* - conn->request_handler = cw_handle_echo_request; - conn->request_handler_param = conn; -*/ - - int bl = 0; - - do { - - data.len = fread(buffer, 1, sizeof(buffer), infile); - - if (feof(infile)) - data.type = 2; - else - data.type = 1; - - cw_dbg(DBG_CW_IMG_DTL, "Sending img data request, block=%d, len=%d, ch=%d\n", bl, - data.len, lw_checksum(data.data, data.len)); - - - bl++; - - // conn_prepare_image_data_request(conn, &data, 0); - // cwrmsg = conn_send_request(conn); - - if (!cwrmsg) { - cw_log(LOG_ERR,"Error sneding image file to %s",sock_addr2str(&conn->addr)); - break; - } - - - } while (!feof(infile)); - -} diff --git a/src/cw/cwmsg_addelem_mtu_discovery_padding.c b/src/cw/cwmsg_addelem_mtu_discovery_padding.c index d0e29ce9..560e7f52 100644 --- a/src/cw/cwmsg_addelem_mtu_discovery_padding.c +++ b/src/cw/cwmsg_addelem_mtu_discovery_padding.c @@ -33,7 +33,7 @@ printf("MTU discovery len %d %d and pos %d:\n",conn->mtu,len,msg->pos); if (len < 0 ) return; - uint32_t val = CWMSGELEM_MTU_DISCOVERY_PADDING<<16|len; + uint32_t val = CW_ELEM_MTU_DISCOVERY_PADDING<<16|len; *((uint32_t*)(msg->msgelems+msg->pos))=htonl(val); memset(msg->msgelems+4+msg->pos,0xff,len); msg->pos+=4+len; diff --git a/src/cw/item_strings.c b/src/cw/item_strings.c deleted file mode 100644 index b0b47ba5..00000000 --- a/src/cw/item_strings.c +++ /dev/null @@ -1,16 +0,0 @@ - -#include "capwap_items.h" -#include "strheap.h" - -struct cw_str cw_item_strings[] = { - { CW_ITEM_WTP_HARDWARE_VERSION,"WTP Hardware Version"}, - { CW_ITEM_WTP_NAME, "WTP Name "}, - { CW_ITEM_AC_NAME, "AC Name "}, - { CW_ITEM_WTP_BOARD_VENDOR, "WTP Board Vendor"}, - { CW_ITEM_WTP_BOARD_MODELNO,"WTP Board Model No."}, - { CW_ITEM_WTP_BOARD_MACADDRESS, "WTP Board MAC Address"}, - { CW_ITEM_WTP_BOARD_ID,"WTP Board ID"}, - { CW_ITEM_WTP_GROUP_NAME,"WTP Group Name"}, - { CW_STR_STOP,"Unknown"} - -}; diff --git a/src/cw/lw_put_80211_wtp_wlan_radio_configuration.c b/src/cw/lw_put_80211_wtp_wlan_radio_configuration.c index 4e871379..04060f14 100644 --- a/src/cw/lw_put_80211_wtp_wlan_radio_configuration.c +++ b/src/cw/lw_put_80211_wtp_wlan_radio_configuration.c @@ -1,6 +1,7 @@ #include "lwapp.h" +/* int lw_put_80211_wtp_wlan_radio_configuration(uint8_t*dst,struct radioinfo *ri) { lw_put_byte(dst,ri->rid); @@ -9,18 +10,18 @@ int lw_put_80211_wtp_wlan_radio_configuration(uint8_t*dst,struct radioinfo *ri) lw_put_byte(dst+4,ri->cfp_period); lw_put_word(dst+5,ri->cfp_max_duration); - /* XXX catch rmac shorter or longer than 6*/ + // XXX catch rmac shorter or longer than 6 - lw_put_bstr(dst+7,ri->rmac); /* length MUST be 6 */ + lw_put_bstr(dst+7,ri->rmac); // length MUST be 6 lw_put_word(dst+13,ri->beacon_period); lw_put_byte(dst+15,ri->dtim_period); lw_put_data(dst+16,ri->country_str,4); lw_put_byte(dst+20,ri->max_bssid); - /* XXX not LWAP conform */ + // XXX not LWAP conform lw_put_data(dst+21,(uint8_t*)"DEAU990",7); return 21+7; } - +*/ diff --git a/src/cw/lw_readelem_wtp_board_data.c b/src/cw/lw_readelem_wtp_board_data.c index 1c0c0ab5..133a3409 100644 --- a/src/cw/lw_readelem_wtp_board_data.c +++ b/src/cw/lw_readelem_wtp_board_data.c @@ -6,7 +6,7 @@ #include #include "log.h" -#include "wtpinfo.h" +//#include "wtpinfo.h" #include "lwapp.h" @@ -26,7 +26,7 @@ int lw_readelem_wtp_board_data(struct wtpinfo *wtpinfo, int type, uint8_t *msgel return 0; if ( len != 46 ) { - cw_dbg(DBG_MSG_ERR,"LWAPP msg size wrong. (WTP BOARD DATA) must be 46"); +// cw_dbg(DBG_MSG_ERR,"LWAPP msg size wrong. (WTP BOARD DATA) must be 46"); return -1; } diff --git a/src/cw/lw_readelem_wtp_name.c b/src/cw/lw_readelem_wtp_name.c index e9d57f8b..a8a80bfe 100644 --- a/src/cw/lw_readelem_wtp_name.c +++ b/src/cw/lw_readelem_wtp_name.c @@ -26,6 +26,7 @@ #include "cw_util.h" #include "log.h" +#include "dbg.h" /** * Reads the LWAPP message element WTP Name @@ -42,7 +43,7 @@ int lw_readelem_wtp_name(uint8_t ** dst, int type, uint8_t * msgelem, int len) if (len>254){ - cw_dbg(DBG_MSG_ERR,"Truncating WTP_NAME msgelem to 254, wrong size, type=%d,len=%d",type,len); + cw_dbg(DBG_ELEM_ERR,"Truncating WTP_NAME msgelem to 254, wrong size, type=%d,len=%d",type,len); len=254; } diff --git a/src/cw/mavl.h b/src/cw/mavl.h index b0bd15b7..26590884 100644 --- a/src/cw/mavl.h +++ b/src/cw/mavl.h @@ -117,31 +117,12 @@ int mavl_foreach_from_lr(struct mavl *t, struct mavlnode *n, void *data, //extern void mavl_foreach(struct mavl *t, int (*callback)(void *,void*),void *cbpriv,int dir); -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; -} +void *mavl_replace_data(struct mavl *t, void *data, int len); -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); -} +void *mavl_replace(struct mavl *t,void *data); -static inline void mavl_destroy(struct mavl *t) -{ - mavl_del_all(t); - free (t); -} - +void mavl_destroy(struct mavl *t); @@ -169,41 +150,12 @@ typedef struct mavliter mavliter_t; void * mavliter_next(mavliter_t *i); -static inline void * mavliter_seek_set(struct mavliter *i) -{ - i->stack_ptr=0; - i->cur=i->root; - return mavliter_next(i); -} +void * mavliter_seek_set(struct mavliter *i); -/** - * Init an AVL Tree Iterator. - * - * After initialization #mavliter_next would return the first element. - * The behavior of #mavliter_get would still be undefined. - * @param i AVL Iterator to initialize - * @param t correspondending AVL Tree - * - * @See mavliter_t, - */ -static inline void mavliter_init(mavliter_t *i, mavl_t t){ - i->root = t->root; - i->stack_ptr=0; - i->cmp=t->cmp; -} +void mavliter_init(mavliter_t *i, mavl_t t); -/** - * Get the element, where AVL Iterator currently is positioned. - * @param i AVL Iterator - * @return element or NULL if not found. - */ -static inline void * mavliter_get(mavliter_t *i){ - if(!i->cur) - return NULL; - return i->cur->data; -} - +void * mavliter_get(mavliter_t *i); extern void * mavliter_seek(mavliter_t *i,void *d); diff --git a/src/cw/mavl_destroy.c b/src/cw/mavl_destroy.c new file mode 100644 index 00000000..391fa649 --- /dev/null +++ b/src/cw/mavl_destroy.c @@ -0,0 +1,9 @@ +#include "mavl.h" + +void mavl_destroy(struct mavl *t) +{ + mavl_del_all(t); + free (t); +} + + diff --git a/src/cw/mavl_replace.c b/src/cw/mavl_replace.c new file mode 100644 index 00000000..c6ea7037 --- /dev/null +++ b/src/cw/mavl_replace.c @@ -0,0 +1,12 @@ +#include "mavl.h" + +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); +} + + diff --git a/src/cw/mavl_replace_data.c b/src/cw/mavl_replace_data.c new file mode 100644 index 00000000..4e8e8c7f --- /dev/null +++ b/src/cw/mavl_replace_data.c @@ -0,0 +1,12 @@ +#include "mavl.h" + +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; +} + + diff --git a/src/cw/mavliter_get.c b/src/cw/mavliter_get.c new file mode 100644 index 00000000..66818d97 --- /dev/null +++ b/src/cw/mavliter_get.c @@ -0,0 +1,14 @@ +#include "mavl.h" + +/** + * Get the element, where AVL Iterator currently is positioned. + * @param i AVL Iterator + * @return element or NULL if not found. + */ +void * mavliter_get(mavliter_t *i){ + if(!i->cur) + return NULL; + return i->cur->data; +} + + diff --git a/src/cw/mavliter_init.c b/src/cw/mavliter_init.c new file mode 100644 index 00000000..b9c83f51 --- /dev/null +++ b/src/cw/mavliter_init.c @@ -0,0 +1,19 @@ +#include "mavl.h" + +/** + * Init an AVL Tree Iterator. + * + * After initialization #mavliter_next would return the first element. + * The behavior of #mavliter_get would still be undefined. + * @param i AVL Iterator to initialize + * @param t correspondending AVL Tree + * + * @See mavliter_t, + */ +void mavliter_init(mavliter_t *i, mavl_t t){ + i->root = t->root; + i->stack_ptr=0; + i->cmp=t->cmp; +} + + diff --git a/src/cw/mavliter_seek_set.c b/src/cw/mavliter_seek_set.c new file mode 100644 index 00000000..ca634c72 --- /dev/null +++ b/src/cw/mavliter_seek_set.c @@ -0,0 +1,10 @@ +#include "mavl.h" + +void * mavliter_seek_set(struct mavliter *i) +{ + i->stack_ptr=0; + i->cur=i->root; + return mavliter_next(i); +} + + diff --git a/src/cw/sock_getifaddr.c b/src/cw/sock_getifaddr.c index 5942dbe9..79ce5e2b 100644 --- a/src/cw/sock_getifaddr.c +++ b/src/cw/sock_getifaddr.c @@ -52,11 +52,10 @@ int sock_getifaddr(const char * ifname,int family, int type,struct sockaddr * sa memcpy (sa, ifa->ifa_addr, sock_addrlen(ifa->ifa_addr)); rc=1; break; - case IFF_BROADCAST: -// memcpy (sa, ifa->ifa_ifu.ifu_broadaddr, sock_addrlen(ifa->ifa_addr)); - memcpy (sa, ifa->ifa_broadaddr, sock_addrlen(ifa->ifa_addr)); - rc=1; - break; +// case IFF_BROADCAST: +// memcpy (sa, ifa->ifa_broadaddr, sock_addrlen(ifa->ifa_addr)); +// rc=1; +// break; default: break; diff --git a/src/cw/wtpinfo_lwreadelem_wtp_descriptor.c b/src/cw/wtpinfo_lwreadelem_wtp_descriptor.c deleted file mode 100644 index abadcafd..00000000 --- a/src/cw/wtpinfo_lwreadelem_wtp_descriptor.c +++ /dev/null @@ -1,59 +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 -#include - -#include "capwap.h" -#include "lwapp.h" - -#include "wtpinfo.h" - -#include "cw_util.h" - -int wtpinfo_lwreadelem_wtp_descriptor(struct wtpinfo * wtpinfo, int type, uint8_t *msgelem, int len) -{ - if (type != LW_ELEM_WTP_DESCRIPTOR) - return 0; - -/* if (len!=16) - return -1; -*/ - - char str[64]; - uint32_t hwversion=ntohl(*((uint32_t*)(msgelem))); - sprintf(str,"%08X",hwversion); - cw_setstr(&wtpinfo->hardware_version,(uint8_t*)str,strlen(str)); - - uint32_t swversion=ntohl(*((uint32_t*)(msgelem+4))); - sprintf(str,"%08X",swversion); - cw_setstr(&wtpinfo->software_version,(uint8_t*)str,strlen(str)); - - uint32_t btversion=ntohl(*((uint32_t*)(msgelem+8))); - sprintf(str,"%08X",btversion); - cw_setstr(&wtpinfo->bootloader_version,(uint8_t*)str,strlen(str)); - - uint32_t l=ntohl(*((uint32_t*)(msgelem+12))); - - wtpinfo->max_radios = l >> 24; - wtpinfo->radios_in_use = (l>>16) & 0xff; - - - return 1; -} - From a2851cdc4c19061348aa7234e9130d1afcc672b9 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Wed, 28 Feb 2018 08:46:08 +0000 Subject: [PATCH 2/7] new simplified Makefile FossilOrigin-Name: a1012388abc39936cf1bf5f7ff48bc721b7983e2342313d7d82afecbd486b267 --- src/cw/Makefile | 315 +----------------- src/cw/avliter_seek.c | 66 ---- src/cw/capwap_strings_item.c | 9 - src/cw/conn_detect_capwap.c | 35 -- src/cw/conn_get_response.c | 44 --- src/cw/conn_wait_for_request.c | 78 ----- src/cw/cw_get_mod_ac.c | 23 -- src/cw/cw_msg_init.c | 31 -- src/cw/cw_out_cisco_wtp_radio_cfg.c | 42 --- src/cw/cw_readelem_80211_wtp_radio_info.c | 51 --- src/cw/cw_readelem_radio_operational_state.c | 45 --- src/cw/cwmsg_addelem_80211_add_wlan.c | 40 --- ...delem_80211_wtp_wlan_radio_configuration.c | 21 -- src/cw/mbag_type_bin.c | 118 ------- src/cw/mbag_type_bstr.c | 5 - src/cw/sock_get_primary_if.c | 4 +- src/cw/wtpinfo_readelem_wtp_board_data.c | 73 ---- 17 files changed, 7 insertions(+), 993 deletions(-) delete mode 100644 src/cw/avliter_seek.c delete mode 100644 src/cw/capwap_strings_item.c delete mode 100644 src/cw/conn_detect_capwap.c delete mode 100644 src/cw/conn_get_response.c delete mode 100644 src/cw/conn_wait_for_request.c delete mode 100644 src/cw/cw_get_mod_ac.c delete mode 100644 src/cw/cw_msg_init.c delete mode 100644 src/cw/cw_out_cisco_wtp_radio_cfg.c delete mode 100644 src/cw/cw_readelem_80211_wtp_radio_info.c delete mode 100644 src/cw/cw_readelem_radio_operational_state.c delete mode 100644 src/cw/cwmsg_addelem_80211_add_wlan.c delete mode 100644 src/cw/lw_readelem_80211_wtp_wlan_radio_configuration.c delete mode 100644 src/cw/mbag_type_bin.c delete mode 100644 src/cw/mbag_type_bstr.c delete mode 100644 src/cw/wtpinfo_readelem_wtp_board_data.c diff --git a/src/cw/Makefile b/src/cw/Makefile index 4e497e70..f3968ec1 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -13,314 +13,9 @@ DNAME := $(LIBARCHDIR)/libcw.so LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib -SOCKOBJS=\ - sock_create.o\ - sock_copyaddr.o\ - sock_strtoaddr.o\ - sock_cmpaddr.o\ - sock_addrlen.o \ - sock_mwait.o\ - sock_addrtostr.o \ - sock_setport.o \ - sock_getport.o \ - sock_getifaddr.o \ - sock_getifhwaddr.o \ - sock_hwaddrtostr.o \ - sock_set_recvtimeout.o \ - sock_getbroadcastaddr.o \ - sock_addrinit.o \ - sock_set_dontfrag.o \ - sock_get_primary_if.o \ - sock_receive.o \ - sock_getifinfo.o \ - - -LOGOBJS=log.o \ - log_syslog.o \ - log_file.o \ - dbg_strings.o\ - dbg.o \ - - -WTPINFOOBJS =\ - #wtpinfo_print.o - #wtpinfo_set_location.o \ - wtpinfo_lwreadelem_wtp_descriptor.o \ - -UTILOBJS= \ - cw_setstr.o \ - cw_is_printable.o \ - cw_rand.o \ - stravltree.o \ - intavltree.o \ - cw_util.o \ - send.o \ - cw_read_wtp_descriptor.o \ - cw_read_wtp_descriptor_7.o \ - cw_read_wtp_descriptor_versions.o \ - cw_read_descriptor_subelems.o \ - cw_out_80211_supported_rates.o - -MAVLOBJS= \ - mavl_del.o \ - mavl_add.o \ - mavl_create.o\ - mavl_get.o\ - mavl_del_all.o\ - mavliter_seek.o \ - mavliter_next.o \ - mavl_get_node.o \ - mavl_foreach.o \ - mavl_foreach_lr.o \ - mavl_merge.o \ - mavl_create_conststr.o \ - mlist.o \ - cw_load_file.o \ - cw_save_file.o \ - cw_filename.o \ - message_set.o - - - -FORMATOBJS = \ - format_is_utf8.o \ - format_dot11_fc.o \ - -# lw_readelem_vendor_specific.o \ - - -# LWAPP objs -LWAPPOBJS = \ - lw_checksum.o \ - lw_put_ac_descriptor.o \ - lw_put_cisco_path_mtu.o \ - lw_elem_id_to_str.o \ - lw_msg_id_to_str.o \ - lw_cisco_id_to_str.o \ - lw_put_sockaddr.o \ - lw_put_image_data.o \ - lw_in_vendor_specific.o - - - #lw_put_80211_wtp_wlan_radio_configuration.o \ -# lw_readelem_wtp_name.o \ - lw_readelem_wtp_board_data.o \ - cw_log_debug.o \ - lw_vendor_id_to_str.o \ - - -# LWAPP cisco vendor specific objs -#//#LWAPPCISCOOBJS = \ -# lw_addelem.o - - -# cw_tohex.o\ -#capwap_parse_ctrlhdr.o \ - -# hdr_print.o \ - -CAPWAPOBJS= \ - cw_iplist.o \ - aciplist.o \ - lwmsg_init.o \ - cw_cisco_id_to_str.o\ - cw_strlist_get_str.o \ - cw_strlist_get_id.o \ - capwap_strings_msg.o \ - capwap_strings_elem80211.o\ - acpriolist.o\ - capwap_strings_state.o \ - capwap_strings_vendor.o \ - capwap_strings_elem.o \ - cw_in_vendor_specific_payload.o \ - cw_in_mtu_discovery_padding.o\ - cw_in_wtp_board_data.o \ - cw_in_check_disc_req.o \ - cw_in_check_chng_state_evnt_req.o\ - cw_in_check_disc_resp.o\ - cw_in_check_cfg_update_req.o\ - cw_in_check_join_req.o \ - cw_in_check_cipwap_join_req.o \ - cw_in_check_join_resp.o \ - cw_in_check_img_data_req_ac.o \ - cw_in_check_img_data_req_wtp.o \ - cw_in_check_img_data_resp.o \ - cw_in_check_generic_resp.o \ - cw_in_check_generic_req.o \ - cw_in_80211_mac_operation.o \ - cw_read_80211_mac_operation.o \ - cw_out_generic.o \ - cw_out_wtp_descriptor.o \ - cw_out_wtp_reboot_statistics.o \ - cw_in_wtp_reboot_statistics.o\ - cw_in_cisco_image_identifier.o\ - cw_put_radio_operational_states.o \ - cw_put_ac_status.o \ - cw_in_ac_descriptor.o\ - cw_read_ac_descriptor.o\ - cw_out_capwap_local_ip_address.o\ - cw_out_wtp_ip_address.o\ - cw_out_capwap_control_ip_addr_list.o \ - cw_in_capwap_control_ip_address.o\ - cw_in_capwap_local_ipv4_address.o \ - cw_in_capwap_local_ipv6_address.o \ - cw_in_radio_administrative_state.o \ - cw_in_radio_administrative_state_wtp.o \ - cw_radio_set_admin_state.o \ - cw_put_elem_radio_administrative_state.o\ - cw_put_elem_radio_operational_state.o \ - cw_out_radio_administrative_states.o\ - strheap.o \ - cw_check_missing_mand.o \ - md5sum.o \ - format.o \ -# action_sources.o \ -# cw_in_cisco_add_wlan.o -# cw_in_radio_operational_state.o\ - -DOT11OBJS = \ - dot11.o \ - dot11_beacon.o - -# cw_out_ac_descriptor.o \ - - -CAPWAP80211OBJS=\ - capwap80211_items.o\ - capwap80211_type_rateset.o \ - -# cw_out_radio_operational_states.o\ -# cw_out_radio_operational_states_7.o\ - -# -# SSL objects -# - -LIBS= - -ifeq ($(WITH_OPENSSL),1) -CFLAGS+=$(OPENSSL_CFLAGS) -CFLAGS+=-DWITH_OPENSSL -DTLSOBJS += dtls_openssl.o \ - dtls_openssl_accept.o \ - dtls_openssl_connect.o \ - dtls_openssl_get_cipher.o \ - dtls_openssl_bio.o -LIBS+=-lssl -endif - -ifeq ($(WITH_GNUTLS),1) -CFLAGS+=$(GNUTLS_CFLAGS) -CFLAGS+=-DWITH_GNUTLS -DTLSOBJS+= dtls_gnutls.o \ - dtls_gnutls_accept.o \ - dtls_gnutls_connect.o \ - dtls_gnutls_bio.o \ - dtls_gnutls_get_cipher.o \ - dtls_gnutls_get_peers_cert.o -LIBS+=-lgnutls -endif - -DTLSOBJS+=dtls_bio.o - -CONNOBJS= conn_create.o \ - conn_process_packet.o \ - conn_q_add_packet.o \ - conn_q_get_packet.o \ - conn_q_recv_packet.o \ - conn_recv_packet.o \ - conn_destroy.o \ - connlist.o \ - conn_create_noq.o \ - conn_init.o \ - conn_send_packet.o \ - conn_send_data_packet.o \ - netconn.o \ - cw_init_data_keep_alive_msg.o \ - conn_clear_upd.o - - -# conn_send_msg.o -#conn_get_message.o \ -# conn_send_response.o \ -# cw_prepare_configuration_status_request.o \ -# cw_prepare_change_state_event_request.o \ - conn_prepare_configuration_update_request.o \ - - - #bstr_to_str.o \ - -BSTROBJS= bstr_create.o \ - bstr_create_from_cfgstr.o \ - bstr16_create_from_cfgstr.o \ - bstr_replace.o \ - bstr16cfgstr.o \ - bstr16_create_from_str.o \ - bstr_create_from_str.o \ - bstrv_create_from_str.o - - - -FRAGOBJS=fragman.o - -CWACTION=action.o \ - cw_in_generic.o \ - cw_in_generic2.o \ - cw_out_wtp_board_data.o \ - cw_out_ac_name_with_priority.o \ - cw_in_ac_name_with_priority.o \ - cw_out_image_data.o \ - cipwap_strings_elem.o \ - capwap_strings_result.o\ - capwap_strings_board.o \ - cw_put_msg.o \ - cw_put_mbag_item.o \ - cw_put_local_ip_address.o \ - capwap_action_helpers.o \ - cw_put_image_data.o \ - cisco.o \ - radio.o \ - cw_in_radio_generic.o\ - cw_out_radio_generic.o \ - cw_out_radio_info.o \ - capwap_items.o \ - item.o \ - mod.o - -# cw_process_msg.o \ -# item_strings.o \ -# - -MBAGOBJS = \ - mbag.o\ - mbag_type_word.o\ - mbag_type_byte.o\ - mbag_type_vendorstr.o\ - mbag_type_sockaddr.o\ - mbag_type_dword.o\ - mbag_type_bstr16.o\ - mbag_type_mbag.o\ - mbag_set_from_buf.o\ - mbag_type_str.o \ - mbag_type_ptr.o \ - mbag_type_data.o \ - mbag_get_upd.o - - - - -OBJS=$(CONNOBJS) $(FRAGOBJS) $(SOCKOBJS) $(CAPWAPOBJS) $(WTPINFOOBJS) \ - $(LOGOBJS) $(UTILOBJS) $(DTLSOBJS) $(BSTROBJS) \ - $(LWAPPOBJS) \ - $(LWAPPCISCOOBJS) \ - $(CWACTION) \ - $(MAVLOBJS) \ - $(FORMATOBJS) \ - $(DOT11OBJS) \ - $(MBAGOBJS) \ - $(CAPWAP80211OBJS) - -O:=$(OBJS); +SRC=$(wildcard *.c) +OBJS=$(patsubst %.c,%.o,$(SRC)) +#O:=$(OBJS); OBJS:=$(patsubst %.o,$(OBJDIR)/%.o,$(OBJS)) @@ -328,7 +23,8 @@ OBJS:=$(patsubst %.o,$(OBJDIR)/%.o,$(OBJS)) all: $(SNAME) $(DNAME) -CFLAGS = -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ +#CFLAGS = -D_XOPEN_SOURCE=500 -std=c90 -pedantic -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ +CFLAGS = -D_XOPEN_SOURCE=500 -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ CFLAGS += $(GNUTLS_CFLAGS) \ -DWITH_CW_LOG \ @@ -355,7 +51,6 @@ $(DNAME) : $(OBJS) $(MODOBJS) @$(CC) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(MODOBJS) $(LIBS) - SRCS = $(OBJS:.o=.c) DEPS := $(OBJS:.o=.d) diff --git a/src/cw/avliter_seek.c b/src/cw/avliter_seek.c deleted file mode 100644 index d84b600e..00000000 --- a/src/cw/avliter_seek.c +++ /dev/null @@ -1,66 +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 . - -*/ - -/** - *@file - *@brief Implementation of avliter_seek - */ - - -#include "avltree.h" - -/** - * Set an AVL Iterator to a specific position. - * @param i AVL Iterator - * @param d element to search for - * @return element found or NULL if not found - */ -void * avliter_seek(avliter_t *i,void *d) -{ - if (!i->root) - return NULL; - - i->cur=i->root; - i->stack_ptr=0; - - int rc; - while(i->cur) { - - rc = i->cmp(d,i->cur->data); - if (rc==0){ - i->stack[i->stack_ptr++]=i->cur->right; - i->stack[i->stack_ptr++]=i->cur; - return avliter_next(i); - } - - if (rc<0) { - i->stack[i->stack_ptr++]=i->cur->right; - i->stack[i->stack_ptr++]=i->cur; - - i->cur=i->cur->left; - - } - if (rc>0) { - - i->cur=i->cur->right; - } - } - return NULL; -} - - diff --git a/src/cw/capwap_strings_item.c b/src/cw/capwap_strings_item.c deleted file mode 100644 index e70e2a39..00000000 --- a/src/cw/capwap_strings_item.c +++ /dev/null @@ -1,9 +0,0 @@ -struct cw_str capwap_strings_item[] = { - - {CW_ITEM_AC_DESCRIPTOR, "AC Descriptor"}, - {CW_ITEM_AC_IPV4_LIST, "AC IPv4 List"}, - {CW_ITEM_WTP_DESCRIPTOR,"WTP Descriptor"}, - - {CW_STR_STOP,"Unknown"} - -} diff --git a/src/cw/conn_detect_capwap.c b/src/cw/conn_detect_capwap.c deleted file mode 100644 index 99d122d1..00000000 --- a/src/cw/conn_detect_capwap.c +++ /dev/null @@ -1,35 +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 "capwap.h" -#include "wtpinfo.h" -#include "conn.h" -#include "log.h" -#include "sock.h" - -void conn_detect_capwap(struct conn * conn, struct wtpinfo * wtpinfo) -{ - if (wtpinfo->software_vendor_id == CW_VENDOR_ID_CISCO){ - cw_dbg(DBG_CW_INFO,"Setting capwap mode *Cisco* on connection %s",sock_addr2str(&conn->addr)); - conn->capwap_mode = CWMODE_CISCO; - return; - } - - conn->capwap_mode = CWMODE_STD; - -} diff --git a/src/cw/conn_get_response.c b/src/cw/conn_get_response.c deleted file mode 100644 index 388ebdd2..00000000 --- a/src/cw/conn_get_response.c +++ /dev/null @@ -1,44 +0,0 @@ - -#include "capwap.h" -#include "cw_log.h" -#include "sock.h" -#include "cw_util.h" - - -struct cwrmsg * conn_get_response(struct conn * conn) -{ - - - struct cwmsg * cwmsg = &conn->req_msg; - - int type = cwmsg->type+1; - - struct cwrmsg * cwrmsg; - - int i; - for (i=0; imax_retransmit; i++) { - - time_t r_timer = cw_timer_start(conn->retransmit_interval); - - while(!cw_timer_timeout(r_timer)){ - cwrmsg = conn_get_message(conn); - if (cwrmsg){ - cw_dbg(DBG_MSG,"Received message from %s, type=%d - %s" - ,sock_addr2str(&conn->addr),cwrmsg->type,cw_msgtostr(cwrmsg->type)); - if (cwrmsg->type == type){ - return cwrmsg; - } - - } - - if (conn->dtls_error) - return 0; - } - cw_dbg(DBG_MSG_ERR,"Retransmitting message, type=%d,seq=%d",cwmsg->type,cwmsg->seqnum); - conn_send_cwmsg(conn,&conn->req_msg); - - } - cw_dbg(DBG_MSG_ERR,"Max retransmit's reached, message type=%d,seq=%d",cwmsg->type,cwmsg->seqnum); - return 0; - -} diff --git a/src/cw/conn_wait_for_request.c b/src/cw/conn_wait_for_request.c deleted file mode 100644 index 8ab206f9..00000000 --- a/src/cw/conn_wait_for_request.c +++ /dev/null @@ -1,78 +0,0 @@ - -#include "conn.h" -#include "cw_log.h" -#include "sock.h" -#include "cw_util.h" - -struct rh_param{ - struct conn * conn; - int *msglist; - -}; - - -static int conn_rh(void *param) -{ - struct rh_param * p = (struct rh_param*)param; - int i; - int *msglist=p->msglist; - - -printf("Param %p\n",param); - - - for (i=0; msglist[i]!=-1; i++){ - if (msglist[i] == p->conn->cwrmsg.type ) - return 0; - - } - /* unexpected response here */ - cw_log(LOG_ERR,"Unexpected message from %s",sock_addr2str(&p->conn->addr)); - cwsend_unknown_response(p->conn,p->conn->cwrmsg.seqnum,p->conn->cwrmsg.type); - return 1; -} - - -struct cwrmsg * conn_wait_for_request(struct conn * conn, int *msglist, time_t timer) -{ - int (*request_handler_save) (void*); - void * request_handler_param_save; - - struct rh_param rh_param; - - - if (msglist){ - request_handler_save=conn->request_handler; - request_handler_param_save=conn->request_handler_param; - rh_param.conn=conn; - rh_param.msglist=msglist; - conn->request_handler=conn_rh; - conn->request_handler_param=&rh_param; - } - - - struct cwrmsg * cwrmsg; - while (!cw_timer_timeout(timer)){ - cwrmsg = conn_wait_for_message(conn,timer); - if (!cwrmsg){ - if (!conn_is_error(conn)) - continue; - break; - } - - /* response message? no action*/ - if (! (cwrmsg->type & 1) ) - continue; - - /* it's a request message */ - break; - } - - if (msglist){ - conn->request_handler=request_handler_save; - conn->request_handler_param=request_handler_param_save; - } - - return cwrmsg; -} - diff --git a/src/cw/cw_get_mod_ac.c b/src/cw/cw_get_mod_ac.c deleted file mode 100644 index adc782bc..00000000 --- a/src/cw/cw_get_mod_ac.c +++ /dev/null @@ -1,23 +0,0 @@ - -#include - - -#include "mod.h" - -#include - - -struct cw_Mod *(*mods_ac[])() = MODS_AC; - - -struct cw_Mod * cw_get_mod_ac(const char *name) -{ - int i; - for (i=0; mods_ac[i];i++){ - - struct cw_Mod * m = mods_ac[i](); - if (strcmp(m->name,name)==0) - return m; - } - return NULL; -} diff --git a/src/cw/cw_msg_init.c b/src/cw/cw_msg_init.c deleted file mode 100644 index af520a84..00000000 --- a/src/cw/cw_msg_init.c +++ /dev/null @@ -1,31 +0,0 @@ - -#include "conn.h" -#include "capwap.h" - - - -void cw_init(struct conn * conn, uint8_t *buffer, int type, int seqnum, struct radioinfo * radioinfo) -{ - - -} - - - -void cw_init_response(struct conn * conn, uint8_t *req) -{ - uint8_t *buffer=conn->resp_buffer; - int shbytes = cw_get_hdr_msg_offset(req); - int dhbytes; - memcpy(buffer,req,shbytes); - cw_set_hdr_hlen(buffer,2); - cw_set_hdr_flags(buffer,CAPWAP_FLAG_HDR_M,1); - dhbytes = cw_get_hdr_msg_offset(buffer); - - uint8_t * msgptr = req+shbytes; - uint8_t * dmsgptr = buffer+dhbytes; - - cw_set_msg_type(dmsgptr,cw_get_msg_type(msgptr)+1); - cw_set_msg_seqnum(dmsgptr,cw_get_msg_seqnum(msgptr)); - cw_set_msg_flags(dmsgptr,0); -} diff --git a/src/cw/cw_out_cisco_wtp_radio_cfg.c b/src/cw/cw_out_cisco_wtp_radio_cfg.c deleted file mode 100644 index 66ae21f9..00000000 --- a/src/cw/cw_out_cisco_wtp_radio_cfg.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "capwap.h" -#include "capwap_cisco.h" - -#include "itemstore.h" - -int cw_put_cisco_wtp_radio_cfg(uint8_t *dst, int rid, cw_itemstore radio) -{ - - cw_put_byte(dst,rid); - - cw_put_byte(dst+1,0); //? - cw_put_word(dst+2,cw_istore_get_word(radio,CW_RADIO_OCCUPANCY_LIMIT); - cw_put_byte(dst+4,cw_istore_get_byte(radio,CW_RADIO_CFP_PERIOD)); - - cw_put_word(dst+5,cw_istore_get_word(radio,CW_RADIO_CFP_MAX_DURATION,200); - - /* XXX catch rmac shorter or longer than 6*/ - - cw_put_bstr(dst+7,cw_istore_get_datari->rmac); /* length MUST be 6 */ - - cw_put_word(dst+13,200); // beacon period - cw_put_data(dst+15,cw_itemstore_get_datari->country_str,3); - cw_put_data(dst+18,ri->country_str2,3); - - cw_put_byte(dst+10+21,10); // gPeriod - - cw_put_dword(dst+10+22,0x3538); // ? - - return 28; //+cw_put_elem_vendor_hdr(dst,CW_VENDOR_ID_CISCO,CW_CISCO_WTP_RADIO_CFG,28); -} - - - - -int cw_out_cisco_wtp_radio_cfg(struct conn *conn, struct cw_action_out *a, uint8_t * dst) -{ - uint8_t *d = dst; - - - return 28+cw_put_elem_vendor_hdr(dst,CW_VENDOR_ID_CISCO,CW_CISCO_WTP_RADIO_CFG,28); -} - diff --git a/src/cw/cw_readelem_80211_wtp_radio_info.c b/src/cw/cw_readelem_80211_wtp_radio_info.c deleted file mode 100644 index b26984a9..00000000 --- a/src/cw/cw_readelem_80211_wtp_radio_info.c +++ /dev/null @@ -1,51 +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 - -#include "wtpinfo.h" -#include "capwap_80211.h" - -#include "cw_log.h" - - -int cw_readelem_80211_wtp_radio_info(void *dst,int type,uint8_t *msgelem, int len) -{ - if (type != CWMSGELEM_80211_WTP_RADIO_INFO) - return 0; - - if (len!=5){ - cw_dbg(DBG_MSG_ERR,"Discarding msgelem 80211_WTP_RADIO_INFO, wrong size, len=%d\n",len); - return 0; - } - - if (*msgelem <1 || *msgelem>31){ - cw_dbg(DBG_CW_RFC,"Non-standard conform radio id, val=%d (must be between 1 to 31, See RFC 5415"); - } - - -// int rid=*msgelem & 0x1f; - -/* - wtpinfo->radioinfo[rid].set=1; - wtpinfo->radioinfo[rid].rid=rid; - wtpinfo->radioinfo[rid].type=ntohl(*(uint32_t*)(msgelem+1)); -*/ - return 1; -} - diff --git a/src/cw/cw_readelem_radio_operational_state.c b/src/cw/cw_readelem_radio_operational_state.c deleted file mode 100644 index 6d5ba35b..00000000 --- a/src/cw/cw_readelem_radio_operational_state.c +++ /dev/null @@ -1,45 +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 "capwap.h" -#include "cw_log.h" - -int cw_readelem_radio_operational_state(struct radioinfo * radioinfo, int type,uint8_t *msgelem, int len) -{ - if (type != CW_ELEM_RADIO_OPERATIONAL_STATE) - return 0; - - if (len<3) - return 0; - - if (len!=3){ - cw_dbg(DBG_CW_RFC,"Radio operational state size != 3, RFC 5415"); - } - - - int radioid = msgelem[0]; - radioid&=0x1f; - radioinfo[radioid].state=msgelem[1]; - radioinfo[radioid].cause=msgelem[2]; - - - return 1; - - -} diff --git a/src/cw/cwmsg_addelem_80211_add_wlan.c b/src/cw/cwmsg_addelem_80211_add_wlan.c deleted file mode 100644 index 9ecd022a..00000000 --- a/src/cw/cwmsg_addelem_80211_add_wlan.c +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file - * @brief add wlan msg element implementation - */ - -#include "capwap.h" -#include "capwap_80211.h" - -#include "cwmsg.h" - -#include "bstr.h" - - -void cwmsg_addelem_80211_add_wlan(struct cwmsg *cwmsg,struct cwwlan *wlan) -{ - - uint16_t capab=htons(wlan->capab); - uint16_t keylen=htons(wlan->key_length); - - cwmsg_vaddelem(cwmsg,CW_ELEM_80211_ADD_WLAN, - &wlan->rid,1, - &wlan->wid,1, - &capab,2, - &wlan->key_index,1, - &wlan->key_status,1, - &keylen,2, - wlan->key,wlan->key_length, - wlan->group_tsc,6, - &wlan->qos,1, - &wlan->auth_type,1, - &wlan->mac_mode,1, - &wlan->tunnel_mode,1, - &wlan->suppress_ssid,1, - bstr_data(wlan->ssid),bstr_len(wlan->ssid), - NULL - - ); - -} - diff --git a/src/cw/lw_readelem_80211_wtp_wlan_radio_configuration.c b/src/cw/lw_readelem_80211_wtp_wlan_radio_configuration.c deleted file mode 100644 index 5569f473..00000000 --- a/src/cw/lw_readelem_80211_wtp_wlan_radio_configuration.c +++ /dev/null @@ -1,21 +0,0 @@ - - -#include "lwapp.h" - -int lw_readelem_80211_wtp_wlan_radio_configuration(int elem_id,uint8_t *elem, int len,struct radioinfo *ri) -{ - if (elem_id != LW_ELEM_80211_WLAN_RADIO_CONFIGURATION) - return 1; - - if (len<21){ - cw_dbg(DBG_ERR,"LWAPP Radio Cfg element too short, %d < 21",len); - return -1; - } - - ri->rid = lw_get_byte(elem); - ri->occupancy_limit = lw_get_word(elem+2); - - bstr_replace(ri->bssid,bstr_create(elem+7,6); - - -} diff --git a/src/cw/mbag_type_bin.c b/src/cw/mbag_type_bin.c deleted file mode 100644 index aeaf7500..00000000 --- a/src/cw/mbag_type_bin.c +++ /dev/null @@ -1,118 +0,0 @@ -#include - -#include "capwap80211_types.h" -#include "dot11.h" - - - - - -static int to_str(void *item,char *dst) -{ - mbag_item_t *it= item; - - uint8_t *data = (uint8_t*)it->data; - int n=*data; - data++; - - char *d=dst; - char *space=""; - int i; - for (i=0; idata=data; - - - return item; -} - -static struct mbag_item * get(const uint8_t *src,int len) -{ - - mbag_item_t * item = mbag_item_new(MBAG_BIN); - if (!item) - return NULL; - - uint8_t *data = malloc(len+1); - if (!data){ - free (item); - return NULL; - } - *data=len; - memcpy(data+1,src,len); - item->data=data; - return item; -} - - -const struct mbag_typedef capwap80211_type_rateset = { - .name = "Biary", - .del = free, - .from_str = from_str, - .to_str = to_str, - .get = get - -}; diff --git a/src/cw/mbag_type_bstr.c b/src/cw/mbag_type_bstr.c deleted file mode 100644 index 554b8dbe..00000000 --- a/src/cw/mbag_type_bstr.c +++ /dev/null @@ -1,5 +0,0 @@ -const struct mbag_typedef mbag_type_bstr = { - "bstr",free -}; - - diff --git a/src/cw/sock_get_primary_if.c b/src/cw/sock_get_primary_if.c index 375e06f9..5edeff2f 100644 --- a/src/cw/sock_get_primary_if.c +++ b/src/cw/sock_get_primary_if.c @@ -24,7 +24,7 @@ #include "sock.h" - +/* char * sock_get_primary_if(int family) { struct ifaddrs *ifap,*ifa; @@ -53,4 +53,4 @@ char * sock_get_primary_if(int family) return r; } - +*/ diff --git a/src/cw/wtpinfo_readelem_wtp_board_data.c b/src/cw/wtpinfo_readelem_wtp_board_data.c deleted file mode 100644 index 45c203b8..00000000 --- a/src/cw/wtpinfo_readelem_wtp_board_data.c +++ /dev/null @@ -1,73 +0,0 @@ - -#include -#include - - -#include "wtpinfo.h" - -#include "capwap.h" - -#include "cw_util.h" -#include "cw_log.h" - - - -static void wtpinfo_readsubelems_wtp_board_data(struct wtpinfo * wtpinfo,uint8_t * msgelem,int len) -{ - int i=0; - uint32_t val; - do { - val = ntohl(*((uint32_t*)(msgelem+i))); - int subtype= (val>>16)&0xffff; - int sublen = val&0xffff; - i+=4; - if (sublen+i>len){ - cw_dbg(DBG_ELEM,"WTP Board data sub-element too long, type=%d,len=%d",subtype,sublen); - return; - } - - cw_dbg(DBG_ELEM,"Reading WTP board data sub-element, type=%d, len=%d",subtype,sublen); - - switch(subtype){ - case CWBOARDDATA_MODELNO: - bstr_replace(&wtpinfo->model_no,bstr_create(msgelem+i,sublen)); - break; - case CWBOARDDATA_SERIALNO: - bstr_replace(&wtpinfo->serial_no,bstr_create(msgelem+i,sublen)); - break; - case CWBOARDDATA_MACADDRESS: - wtpinfo->macaddress=realloc(wtpinfo->macaddress,sublen); - memcpy(wtpinfo->macaddress,msgelem+i,sublen); - wtpinfo->macaddress_len=sublen; - break; - case CWBOARDDATA_BOARDID: - bstr_replace(&wtpinfo->board_id,bstr_create(msgelem+i,sublen)); - break; - case CWBOARDDATA_REVISION: - bstr_replace(&wtpinfo->board_revision,bstr_create(msgelem+i,sublen)); - default: - break; - } - i+=sublen; - - }while(ivendor_id = ntohl(*((uint32_t*)msgelem)); - wtpinfo_readsubelems_wtp_board_data(wtpinfo,msgelem+4,len-4); - return 1; -} - - From 3cbe9445c2ac1689faeb63b4666a88568594b128 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Thu, 1 Mar 2018 19:11:37 +0000 Subject: [PATCH 3/7] Some ansi work FossilOrigin-Name: 10506b615d76f4567d9de61f08327ffb056500265600b8666ce1e0f15cd1f74b --- src/ac/Makefile | 2 +- src/cw/Makefile | 2 +- src/cw/conn_prepare_image_data_request.c | 12 +- src/cw/cw_addelem_vendor_specific_payload.c | 48 ---- src/cw/cw_in_wtp_descriptor.c | 254 -------------------- src/cw/cw_read_wtp_descriptor.c | 48 ---- src/cw/hdr_print.c | 4 +- src/cw/lw_readelem_wtp_board_data.c | 39 --- src/cw/sock_get_primary_if.c | 3 +- 9 files changed, 13 insertions(+), 399 deletions(-) delete mode 100644 src/cw/cw_addelem_vendor_specific_payload.c delete mode 100644 src/cw/cw_in_wtp_descriptor.c delete mode 100644 src/cw/cw_read_wtp_descriptor.c delete mode 100644 src/cw/lw_readelem_wtp_board_data.c diff --git a/src/ac/Makefile b/src/ac/Makefile index 53bfbe2b..7b159270 100644 --- a/src/ac/Makefile +++ b/src/ac/Makefile @@ -80,7 +80,7 @@ all: $(AC_NAME) $(AC_NAME): $(AC_OBJS) # $(CC) $(AC_OBJS) ../mod/modload_ac.o -o $(AC_NAME) $(LDFLAGS) $(LIBS) - $(CC) $(AC_OBJS) -o $(AC_NAME) $(LDFLAGS) $(LIBS) + $(CC) $(AC_OBJS) -v -o $(AC_NAME) $(LDFLAGS) $(LIBS) clean: diff --git a/src/cw/Makefile b/src/cw/Makefile index f3968ec1..8e424f62 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -24,7 +24,7 @@ all: $(SNAME) $(DNAME) #CFLAGS = -D_XOPEN_SOURCE=500 -std=c90 -pedantic -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ -CFLAGS = -D_XOPEN_SOURCE=500 -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ +CFLAGS = -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ CFLAGS += $(GNUTLS_CFLAGS) \ -DWITH_CW_LOG \ diff --git a/src/cw/conn_prepare_image_data_request.c b/src/cw/conn_prepare_image_data_request.c index 7259b3ab..0b6d88de 100644 --- a/src/cw/conn_prepare_image_data_request.c +++ b/src/cw/conn_prepare_image_data_request.c @@ -19,7 +19,7 @@ #include "capwap.h" #include "lwapp.h" - +/* int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data, struct image_identifier *id) @@ -33,8 +33,8 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data - /* for Cisco APs send image data in "LWAPP format" */ -/* if (conn->capwap_mode == CWMODE_CISCO) { + // for Cisco APs send image data in "LWAPP format" + if (conn->capwap_mode == CWMODE_CISCO) { uint8_t type = 3; uint16_t checksum = htons(lw_checksum(data->data, data->len)); cwmsg_vaddelem(cwmsg, CW_ELEM_IMAGE_DATA, @@ -44,9 +44,9 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data NULL); return 0; } -*/ - /* standard capwap operation */ + + // standard capwap operation cwmsg_vaddelem(cwmsg,CW_ELEM_IMAGE_DATA, &data->type, sizeof(data->type), @@ -57,3 +57,5 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data return 0; } + +*/ diff --git a/src/cw/cw_addelem_vendor_specific_payload.c b/src/cw/cw_addelem_vendor_specific_payload.c deleted file mode 100644 index a6ea93e8..00000000 --- a/src/cw/cw_addelem_vendor_specific_payload.c +++ /dev/null @@ -1,48 +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 . - -*/ - - -/** - *@file - *@brief cw_addelem_vendor_specific_payload - */ - -#include "capwap.h" - -/** - * Add a Vendor Specific Payload message element to a buffer - * @param dst destination buffer - * @param vendor_id the vendor id - * @param type vendor specific message type - * @data pointer to data the will be put - * @len length of data - */ -int cw_addelem_vendor_specific_payload(uint8_t * dst, uint32_t vendor_id, - uint16_t type, uint8_t * data, uint16_t len) -{ - uint8_t *d = dst + 4; - - d += cw_put_dword(d, vendor_id); - d += cw_put_word(d, type); - d += cw_put_data(d, data, len); - - int l = d - dst; - cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, l - 4); - return l; - -} diff --git a/src/cw/cw_in_wtp_descriptor.c b/src/cw/cw_in_wtp_descriptor.c deleted file mode 100644 index 11ad24b7..00000000 --- a/src/cw/cw_in_wtp_descriptor.c +++ /dev/null @@ -1,254 +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 "capwap.h" -#include "capwap_items.h" - - -#include "cw_util.h" -#include "dbg.h" - -#include "sock.h" - - -static int _cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data, - int len, int silent) -{ - int i = 0; - while (i len) { - if (!silent) - cw_dbg(DBG_ELEM_ERR, - "WTP descriptor subelement to long, length=%d>%d", - i + 8, len); - return 0; - } - - uint32_t vendor_id = cw_get_dword(data + i); - uint32_t val = cw_get_dword(data + i + 4); - - int subtype = (val >> 16) & 0xffff; - int sublen = val & 0xffff; - i += 8; - - if (sublen + i > len) { - if (!silent) - cw_dbg(DBG_ELEM_ERR, - "WTP Descriptor sub-element too long, length = %d", - sublen); - return 0; - } - - if (!silent) { - char *dmp; - char *dmpmem = NULL; - if (cw_dbg_is_level(DBG_SUBELEM_DMP)) { - dmpmem = cw_dbg_mkdmp(data + i, sublen); - dmp = dmpmem; - } else - dmp = ""; - cw_dbg(DBG_SUBELEM, "WTP Descriptor subtype=%d,len=%d%s", subtype, - sublen, dmp); - - if (dmpmem) - free(dmpmem); - } - - switch (subtype) { - case CW_SUBELEM_WTP_HARDWARE_VERSION: -/* - mbag_set_dword(mbag, - CW_ITEM_WTP_HARDWARE_VENDOR, - vendor_id); - mbag_set_bstrn(mbag, - CW_ITEM_WTP_HARDWARE_VERSION, - data + i, sublen); -*/ - - mbag_set_bstrv(mbag, - CW_ITEM_WTP_HARDWARE_VERSION, - vendor_id, data + i, sublen); - - break; - case CW_SUBELEM_WTP_SOFTWARE_VERSION: - - mbag_set_bstrv(mbag, - CW_ITEM_WTP_SOFTWARE_VERSION, - vendor_id, data + i, sublen); -/* - mbag_set_dword(mbag, - CW_ITEM_WTP_SOFTWARE_VENDOR, - vendor_id); - mbag_set_bstrn(mbag, - CW_ITEM_WTP_SOFTWARE_VERSION, - data + i, sublen); - -*/ - break; - case CW_SUBELEM_WTP_BOOTLOADER_VERSION: - - mbag_set_bstrv(mbag, - CW_ITEM_WTP_BOOTLOADER_VERSION, - vendor_id, data + i, sublen); - -/* - mbag_set_dword(mbag, - CW_ITEM_WTP_BOOTLOADER_VENDOR, - vendor_id); - mbag_set_bstrn(mbag, - CW_ITEM_WTP_BOOTLOADER_VERSION, - data + i, sublen); -*/ - break; - default: - if (!silent) - cw_dbg(DBG_ELEM_ERR, - "Unknown WTP descriptor subelement, type = %d", - subtype); - break; - } - i += sublen; - - } //while (i < len); - - return 1; - -} - -static int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn, - struct cw_action_in *a, uint8_t * data, int len, - int silent) -{ - - - mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data)); - mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, - cw_get_byte(data + 1)); - - - /* Get number of encryption elements */ - int ncrypt = cw_get_byte(data + 2); - if (ncrypt == 0) { - if (conn->strict_capwap) { - if (!silent) - cw_dbg(DBG_ELEM_ERR, - "Bad WTP Descriptor, number of encryption elements is 0."); - return 0; - } - if (!silent) - cw_dbg(DBG_RFC, - "Non standard conform WTP Descriptor, number of encryptoin elements is 0."); - } - - int pos = 3; - int i; - for (i = 0; i < ncrypt; i++) { - // It's a dummy for now - pos += 3; - } - - return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); - -} - - - -/** - * Read WTP Descriptor in Cisco-Style (Draft 7) - */ - -static int cw_read_cisco_wtp_descriptor(mbag_t mbag, struct conn *conn, - struct cw_action_in *a, uint8_t * data, int len, - int silent) -{ - - mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data)); - mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, - cw_get_byte(data + 1)); - - - int pos = 2; - - /* Encryption element, for now dumy XXX */ - cw_get_word(data + pos + 2); - pos += 2; - - return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); - -} - - - - - - - - -int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data, - int len, struct sockaddr *from) -{ - mbag_t mbag = conn->incomming; - - return cw_read_wtp_descriptor(mbag, conn, a, data, len, 0); -} - - - -int cw_in_cipwap_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data, - int len, struct sockaddr *from) -{ - mbag_t mbag = conn->incomming; - - switch (conn->capwap_mode) { - case CW_MODE_CISCO: - return cw_read_cisco_wtp_descriptor(mbag, conn, a, data, len, - 0); - case CW_MODE_CIPWAP: - { - /* try to get the right WTP Descriptor */ - int rc; - rc = cw_read_wtp_descriptor(mbag, conn, a, data, len, - 1); - - if (rc) { - return cw_read_wtp_descriptor(mbag, conn, a, - data, len, 0); - } - - rc = cw_read_cisco_wtp_descriptor(mbag, conn, a, - data, len, 0); - if (rc) { - return cw_read_cisco_wtp_descriptor(mbag, - conn, a, data, - len, 0); - } - - return cw_read_wtp_descriptor(mbag, conn, a, data, - len, 0); - - } - default: - return cw_read_wtp_descriptor(mbag, conn, a, data, len, 0); - - - } - - return 0; -} diff --git a/src/cw/cw_read_wtp_descriptor.c b/src/cw/cw_read_wtp_descriptor.c deleted file mode 100644 index 152c938a..00000000 --- a/src/cw/cw_read_wtp_descriptor.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "cw.h" - -#include "capwap.h" -#include "capwap_items.h" -#include "dbg.h" - - -int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn, - struct cw_action_in *a, uint8_t * data, int len,struct cw_descriptor_subelem_def *allowed) -{ - - mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data)); - mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, cw_get_byte(data + 1)); - - - /* Get number of encryption elements */ - int ncrypt = cw_get_byte(data + 2); - if (ncrypt == 0) { - if (conn->strict_capwap) { - cw_dbg(DBG_ELEM_ERR, - "Bad WTP Descriptor, number of encryption elements is 0."); - return 0; - } - cw_dbg(DBG_RFC, - "Non standard conform WTP Descriptor, number of encryptoin elements is 0."); - } - - int pos = 3; - int i; - for (i = 0; i < ncrypt; i++) { - // It's a dummy for now - pos += 3; - } - - static struct cw_descriptor_subelem_def allowed_default[] = { - {0,CW_SUBELEM_WTP_HARDWARE_VERSION, CW_ITEM_WTP_HARDWARE_VERSION, 1024,1}, - {0,CW_SUBELEM_WTP_SOFTWARE_VERSION, CW_ITEM_WTP_SOFTWARE_VERSION, 1024,1}, - {0,CW_SUBELEM_WTP_BOOTLOADER_VERSION, CW_ITEM_WTP_SOFTWARE_VERSION, 1024,1}, - {0,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, CW_ITEM_WTP_SOFTWARE_VERSION, 1024,0}, - {0,0, NULL, 0,0} - }; - - if (!allowed) { - allowed=allowed_default; - } - - return cw_read_descriptor_subelems(conn->incomming, data + pos, len - pos, allowed); -} diff --git a/src/cw/hdr_print.c b/src/cw/hdr_print.c index d269cf69..cdb09a13 100644 --- a/src/cw/hdr_print.c +++ b/src/cw/hdr_print.c @@ -23,7 +23,7 @@ #include "capwap.h" #include "sock.h" - +/* int hdr_print(char *str, uint8_t *packet, int len) { @@ -119,3 +119,5 @@ int hdr_print(char *str, uint8_t *packet, int len) return s-str; } + +*/ diff --git a/src/cw/lw_readelem_wtp_board_data.c b/src/cw/lw_readelem_wtp_board_data.c deleted file mode 100644 index 133a3409..00000000 --- a/src/cw/lw_readelem_wtp_board_data.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @file - * @brief Implementation of lw_readelem_wtp_board_data - */ - -#include - -#include "log.h" -//#include "wtpinfo.h" - -#include "lwapp.h" - - -/** - * Read LWAPP board data element - * @param wtpinfo results are stored here - * @param type type of msg element (must be LWMSGELEM_WTP_BOARD_DATA) - * @param msgelem msg element data - * @param len length of msg element - * @return 0 if msg is not wtp board data\n - * 1 board data successful read - */ -int lw_readelem_wtp_board_data(struct wtpinfo *wtpinfo, int type, uint8_t *msgelem, int len) -{ - if (type != LW_ELEM_WTP_BOARD_DATA) - return 0; - - if ( len != 46 ) { -// cw_dbg(DBG_MSG_ERR,"LWAPP msg size wrong. (WTP BOARD DATA) must be 46"); - return -1; - } - -// uint16_t card_id = htonl( * ( (uint16_t*)(msgelem) ) ); -// uint16_t card_rev = htonl( * ( (uint16_t*)(msgelem +2 ) ) ); - - return 1; -} - - diff --git a/src/cw/sock_get_primary_if.c b/src/cw/sock_get_primary_if.c index 5edeff2f..d46502f0 100644 --- a/src/cw/sock_get_primary_if.c +++ b/src/cw/sock_get_primary_if.c @@ -24,7 +24,7 @@ #include "sock.h" -/* + char * sock_get_primary_if(int family) { struct ifaddrs *ifap,*ifa; @@ -53,4 +53,3 @@ char * sock_get_primary_if(int family) return r; } -*/ From 17c904ec5fca6001edf47f25e6394e82c08e4943 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Thu, 1 Mar 2018 20:33:16 +0000 Subject: [PATCH 4/7] Compiles now FossilOrigin-Name: 30eb185e57ed49871e3371ec4bdec4637b8ec27be59d199e4118bb20bff50c7d --- src/ac/Makefile | 2 +- src/cw/Makefile | 25 ++++++ ...onn_prepare_configuration_update_request.c | 12 --- src/cw/conn_prepare_request.c | 10 --- src/cw/cw_out_init_session_id.c | 24 ------ src/cw/cw_read_image_data_request.c | 76 ------------------- src/cw/cw_send_echo_response.c | 4 +- src/cw/cwmsg_addelem_vendor_cisco_mwar_addr.c | 58 -------------- 8 files changed, 28 insertions(+), 183 deletions(-) delete mode 100644 src/cw/conn_prepare_configuration_update_request.c delete mode 100644 src/cw/conn_prepare_request.c delete mode 100644 src/cw/cw_out_init_session_id.c delete mode 100644 src/cw/cw_read_image_data_request.c delete mode 100644 src/cw/cwmsg_addelem_vendor_cisco_mwar_addr.c diff --git a/src/ac/Makefile b/src/ac/Makefile index 7b159270..53bfbe2b 100644 --- a/src/ac/Makefile +++ b/src/ac/Makefile @@ -80,7 +80,7 @@ all: $(AC_NAME) $(AC_NAME): $(AC_OBJS) # $(CC) $(AC_OBJS) ../mod/modload_ac.o -o $(AC_NAME) $(LDFLAGS) $(LIBS) - $(CC) $(AC_OBJS) -v -o $(AC_NAME) $(LDFLAGS) $(LIBS) + $(CC) $(AC_OBJS) -o $(AC_NAME) $(LDFLAGS) $(LIBS) clean: diff --git a/src/cw/Makefile b/src/cw/Makefile index 8e424f62..f6a71c52 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -12,6 +12,31 @@ DNAME := $(LIBARCHDIR)/libcw.so LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib +LIBS= + +ifeq ($(WITH_OPENSSL),1) +CFLAGS+=$(OPENSSL_CFLAGS) +CFLAGS+=-DWITH_OPENSSL +DTLSOBJS += dtls_openssl.o \ + dtls_openssl_accept.o \ + dtls_openssl_connect.o \ + dtls_openssl_get_cipher.o \ + dtls_openssl_bio.o +LIBS+=-lssl +endif + +ifeq ($(WITH_GNUTLS),1) +CFLAGS+=$(GNUTLS_CFLAGS) +CFLAGS+=-DWITH_GNUTLS +DTLSOBJS+= dtls_gnutls.o \ + dtls_gnutls_accept.o \ + dtls_gnutls_connect.o \ + dtls_gnutls_bio.o \ + dtls_gnutls_get_cipher.o \ + dtls_gnutls_get_peers_cert.o +LIBS+=-lgnutls +endif + SRC=$(wildcard *.c) OBJS=$(patsubst %.c,%.o,$(SRC)) diff --git a/src/cw/conn_prepare_configuration_update_request.c b/src/cw/conn_prepare_configuration_update_request.c deleted file mode 100644 index 768b646d..00000000 --- a/src/cw/conn_prepare_configuration_update_request.c +++ /dev/null @@ -1,12 +0,0 @@ - - -#include "conn.h" -#include "capwap.h" - - -void conn_prepare_configuration_update_request(struct conn * conn) -{ - struct cwmsg * cwmsg = &conn->req_msg; - uint8_t * buffer = conn->req_buffer; - cwmsg_init(cwmsg,buffer,CW_MSG_CONFIGURATION_UPDATE_REQUEST,conn_get_next_seqnum(conn),0); -} diff --git a/src/cw/conn_prepare_request.c b/src/cw/conn_prepare_request.c deleted file mode 100644 index 165abeb0..00000000 --- a/src/cw/conn_prepare_request.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "conn.h" -#include "capwap.h" - -void conn_prepare_request(struct conn * conn, int type) -{ - struct cwmsg * cwmsg = &conn->req_msg; - uint8_t * buffer = conn->req_buffer; - cwmsg_init(cwmsg,buffer,type,conn_get_next_seqnum(conn),0); - cwmsg->capwap_mode=conn->capwap_mode; -} diff --git a/src/cw/cw_out_init_session_id.c b/src/cw/cw_out_init_session_id.c deleted file mode 100644 index 974a6b8f..00000000 --- a/src/cw/cw_out_init_session_id.c +++ /dev/null @@ -1,24 +0,0 @@ - - -#include "capwap.h" -#include "capwap_items.h" - -#include "log.h" -#include "rand.h" - -int cw_out_init_session_id(struct conn *conn,struct cw_action_out * a,uint8_t *dst) -{ - printf("Vendor ID: %d\n", a->vendor_id); - uint8_t session_id[16]; - int l = cw_rand(session_id,16); - if ( l!=16 ) { - cw_log(LOG_ERR,"Can't init session ID."); - return -1; - } - - - cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,16); - return 0; - -} - diff --git a/src/cw/cw_read_image_data_request.c b/src/cw/cw_read_image_data_request.c deleted file mode 100644 index e7deeaf4..00000000 --- a/src/cw/cw_read_image_data_request.c +++ /dev/null @@ -1,76 +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 . - -*/ - -/** - *@file - *@brief Image Data handling - */ -#include - -#include "capwap.h" - -#include "log.h" -#include "dbg.h" -#include "cw_util.h" - -#include - -int cw_readelem_image_identifier(struct cwimage_data *data, int type,uint8_t *msgelem, int len) -{ - if (type != CW_ELEM_IMAGE_IDENTIFIER) - return 0; - - data->vendor_id = ntohl(*((uint32_t*)msgelem)); - - if (len >= 1024) { - cw_dbg(DBG_MSG_ERR,"Image identifier too long (>1024), truncating"); - len = 1024; - } - - if ( data->identifier ){ - memcpy(data->identifier,msgelem,len); - *(data->identifier+len)=0; - } - - return 1; -} - -static int imgdata_request(void * ptr,int type,uint8_t* msgelem,int len) -{ - cw_dbg_msgelem(CW_MSG_IMAGE_DATA_REQUEST, type, msgelem, len); - - - //cw_dbg(DBG_ALL,"Reading image data req msgelem, type=%d - %s ,len=%d\n",type,cw_strelem(type),len); - - if (cw_readelem_image_identifier(ptr,type,msgelem,len)) - return 1; - - return 0; -} - - -/** - * Read an image data request message - */ -void cw_read_image_data_request(struct cwimage_data *data, uint8_t * msg, int len) -{ - cw_foreach_msgelem(msg,len,imgdata_request,data); -} - - - diff --git a/src/cw/cw_send_echo_response.c b/src/cw/cw_send_echo_response.c index d5a18adc..f88645e6 100644 --- a/src/cw/cw_send_echo_response.c +++ b/src/cw/cw_send_echo_response.c @@ -33,8 +33,8 @@ int cw_send_echo_response(struct conn * conn,int seqnum,struct radioinfo * radioinfo) { struct cwmsg * cwmsg = &conn->resp_msg; - cwmsg_init(cwmsg,conn->resp_buffer,CW_MSG_ECHO_RESPONSE,seqnum,radioinfo); +// cwmsg_init(cwmsg,conn->resp_buffer,CW_MSG_ECHO_RESPONSE,seqnum,radioinfo); - conn_send_response(conn,cwmsg,seqnum); +// conn_send_response(conn,cwmsg,seqnum); return 1; } diff --git a/src/cw/cwmsg_addelem_vendor_cisco_mwar_addr.c b/src/cw/cwmsg_addelem_vendor_cisco_mwar_addr.c deleted file mode 100644 index 6bacdc36..00000000 --- a/src/cw/cwmsg_addelem_vendor_cisco_mwar_addr.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include - -#include - - -#include "capwap.h" -#include "capwap_cisco.h" - -#include "cwmsg.h" -#include "conn.h" - - -#include "sock.h" - -void cwmsg_addelem_vendor_cisco_mwar_addr(struct cwmsg *msg, struct conn *conn) -{ - uint8_t data [7]; - - switch (((struct sockaddr*)&conn->addr)->sa_family){ - case AF_INET: - { - data[0]=2; /* mwar type */ - data[5]=0; - data[6]=0; - -printf("Adding mwar addr %s\n",sock_addr2str(&conn->addr)); - - struct sockaddr_in * sain = (struct sockaddr_in*)&conn->addr; - memcpy(data+1,(uint8_t*)&sain->sin_addr,4); - cwmsg_addelem_vendor_specific_payload(msg, CW_VENDOR_ID_CISCO, - CW_CISCO_MWAR_ADDR, - data,7); - - - break; - } - - -/* case AF_INET6: - { - int id; - if (cw_mode == CWMODE_CISCO) - id = CWMSGELEM_WTP_IPV6_IP_ADDR; - else - id = CWMSGELEM_CAPWAP_LOCAL_IPV6_ADDRESS; - struct sockaddr_in6 * sain = (struct sockaddr_in6*)&a; - return cwmsg_addelem(msg,id,(uint8_t*)&sain->sin6_addr,16); - } - break; -*/ - } - - - - -} From 4b6897c983c6f1e87db37de8190369636c18b343 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Thu, 1 Mar 2018 20:34:55 +0000 Subject: [PATCH 5/7] Readded FossilOrigin-Name: 79f96fb766d7b05f3856d5baacc3b8264287562a21115648f938b5404ba19c16 --- src/cw/cw_read_wtp_descriptor.c | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/cw/cw_read_wtp_descriptor.c diff --git a/src/cw/cw_read_wtp_descriptor.c b/src/cw/cw_read_wtp_descriptor.c new file mode 100644 index 00000000..152c938a --- /dev/null +++ b/src/cw/cw_read_wtp_descriptor.c @@ -0,0 +1,48 @@ +#include "cw.h" + +#include "capwap.h" +#include "capwap_items.h" +#include "dbg.h" + + +int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn, + struct cw_action_in *a, uint8_t * data, int len,struct cw_descriptor_subelem_def *allowed) +{ + + mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data)); + mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, cw_get_byte(data + 1)); + + + /* Get number of encryption elements */ + int ncrypt = cw_get_byte(data + 2); + if (ncrypt == 0) { + if (conn->strict_capwap) { + cw_dbg(DBG_ELEM_ERR, + "Bad WTP Descriptor, number of encryption elements is 0."); + return 0; + } + cw_dbg(DBG_RFC, + "Non standard conform WTP Descriptor, number of encryptoin elements is 0."); + } + + int pos = 3; + int i; + for (i = 0; i < ncrypt; i++) { + // It's a dummy for now + pos += 3; + } + + static struct cw_descriptor_subelem_def allowed_default[] = { + {0,CW_SUBELEM_WTP_HARDWARE_VERSION, CW_ITEM_WTP_HARDWARE_VERSION, 1024,1}, + {0,CW_SUBELEM_WTP_SOFTWARE_VERSION, CW_ITEM_WTP_SOFTWARE_VERSION, 1024,1}, + {0,CW_SUBELEM_WTP_BOOTLOADER_VERSION, CW_ITEM_WTP_SOFTWARE_VERSION, 1024,1}, + {0,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, CW_ITEM_WTP_SOFTWARE_VERSION, 1024,0}, + {0,0, NULL, 0,0} + }; + + if (!allowed) { + allowed=allowed_default; + } + + return cw_read_descriptor_subelems(conn->incomming, data + pos, len - pos, allowed); +} From 762ff8bce5758288a1f55c83b7fec5dcec64fe83 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Thu, 1 Mar 2018 23:12:38 +0000 Subject: [PATCH 6/7] Compiles with tcc FossilOrigin-Name: ec63b57d34761baede1254385a5abb4ed9d5f3becdbdab91ef596b4399d196fa --- src/Macros.mak | 27 +++++- src/ac/Makefile | 9 +- src/cw/Makefile | 26 ++---- src/cw/dbg.c | 3 + src/cw/dtls.h | 14 +-- src/cw/dtls_gnutls.c | 1 + src/cw/dtls_gnutls_accept.c | 1 + src/cw/dtls_gnutls_get_cipher.c | 2 +- src/cw/log_syslog.c | 1 + src/cw/mbag.c | 158 ++++++++++++++++++++++++++++++++ src/cw/mbag.h | 144 ++++------------------------- 11 files changed, 223 insertions(+), 163 deletions(-) diff --git a/src/Macros.mak b/src/Macros.mak index d58ae344..c99e06d1 100644 --- a/src/Macros.mak +++ b/src/Macros.mak @@ -19,7 +19,32 @@ endif ifndef ARCH - ARCH = $(shell $(CC) -dumpmachine) + ARCH = $(shell uname -m) endif +ifeq ($(CC),clang) +LDFLAGS += -g -L/usr/local/lib +CFLAGS += -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -fPIC -g -O0 -D_REENTRANT -I /usr/local/include -I../ +LD = gcc +endif + +ifeq ($(CC),gcc) +LDFLAGS += -g -L/usr/local/lib +CFLAGS += -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -fPIC -g -O0 -D_REENTRANT -I /usr/local/include -I../ +LD = gcc +endif + +ifeq ($(CC),tcc) +LDFLAGS += -g -L/usr/local/lib +CFLAGS += -Wall -Wunusupported -Wimplicit-function-declaration -I /usr/local/include -I../ +LD = tcc +endif + + + +CFLAGS += -DWITH_IPV6 -DWITH_RMAC_SUPPORT + + + + diff --git a/src/ac/Makefile b/src/ac/Makefile index 53bfbe2b..91a622cc 100644 --- a/src/ac/Makefile +++ b/src/ac/Makefile @@ -1,12 +1,13 @@ -include ../Macros.mak include ../Config.mak include ../ACConfig.mak -include ../Config.local.mak +-include ../ACConfig.local.mak +include ../Macros.mak LIBARCHDIR=../../lib/$(ARCH) -LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib -L$(LIBARCHDIR) +LDFLAGS+=-g -L/usr/local/lib -L$(LIBARCHDIR) CFLAGS += -W -g -O0 -D_REENTRANT -DIPV6 -I/usr/local/include -I../ -DSYS_ARCH=\"${ARCH}\" @@ -80,7 +81,7 @@ all: $(AC_NAME) $(AC_NAME): $(AC_OBJS) # $(CC) $(AC_OBJS) ../mod/modload_ac.o -o $(AC_NAME) $(LDFLAGS) $(LIBS) - $(CC) $(AC_OBJS) -o $(AC_NAME) $(LDFLAGS) $(LIBS) + $(LD) $(AC_OBJS) -o $(AC_NAME) $(LDFLAGS) $(LIBS) clean: @@ -90,6 +91,6 @@ clean_deps: $(AC_DEPS) deps: $(AC_SRC) - $(CC) -MD -E $(AC_SRCS) $(CFLAGS) >/dev/null + $(LD) -MD -E $(AC_SRCS) $(CFLAGS) >/dev/null -include $(AC_DEPS) diff --git a/src/cw/Makefile b/src/cw/Makefile index f6a71c52..fed02ce9 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -1,6 +1,6 @@ -include ../Macros.mak include ../CWConfig.mak -include ../Config.local.mak +include ../Macros.mak LIBDIR := ../../lib @@ -10,8 +10,6 @@ OBJDIR := ../../obj/cw/$(ARCH) SNAME := $(LIBARCHDIR)/libcw.a DNAME := $(LIBARCHDIR)/libcw.so -LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib - LIBS= ifeq ($(WITH_OPENSSL),1) @@ -40,24 +38,16 @@ endif SRC=$(wildcard *.c) OBJS=$(patsubst %.c,%.o,$(SRC)) -#O:=$(OBJS); - OBJS:=$(patsubst %.o,$(OBJDIR)/%.o,$(OBJS)) all: $(SNAME) $(DNAME) -#CFLAGS = -D_XOPEN_SOURCE=500 -std=c90 -pedantic -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ -CFLAGS = -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wall -fPIC -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../ - CFLAGS += $(GNUTLS_CFLAGS) \ -DWITH_CW_LOG \ -DWITH_CW_LOG_DEBUG \ - -DWITH_DTLS \ - $(XINCLUDE)\ - -I $(OPENSSLINC)\ - -Werror + -DWITH_DTLS $(OBJDIR)/%.o:%.c @@ -65,15 +55,15 @@ $(OBJDIR)/%.o:%.c @echo " $(CC) "$< @$(CC) -c $(CFLAGS) $< -o $@ -$(SNAME) : $(OBJS) $(MODOBJS) +$(SNAME) : $(OBJS) @mkdir -p $(LIBARCHDIR) - @echo " AR $(SNAME)" - @$(AR) rcs $(SNAME) $(OBJS) $(MODOBJS) + @echo " $(AR) $(SNAME)" + @$(AR) rcs $(SNAME) $(OBJS) -$(DNAME) : $(OBJS) $(MODOBJS) +$(DNAME) : $(OBJS) @mkdir -p $(LIBARCHDIR) - @echo " $(CC) $(DNAME)" - @$(CC) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(MODOBJS) $(LIBS) + @echo " $(LD) $(DNAME)" + @$(LD) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(LIBS) SRCS = $(OBJS:.o=.c) diff --git a/src/cw/dbg.c b/src/cw/dbg.c index f58884a8..b50fd782 100644 --- a/src/cw/dbg.c +++ b/src/cw/dbg.c @@ -25,6 +25,7 @@ * @file Debugging Functions * @brief Various debug functions. */ +#include #include "capwap.h" #include "dbg.h" @@ -39,6 +40,8 @@ #include "cw.h" #include "message_set.h" + + /** *@addtogroup DBG *@{ diff --git a/src/cw/dtls.h b/src/cw/dtls.h index baaf5c8f..1177e057 100644 --- a/src/cw/dtls.h +++ b/src/cw/dtls.h @@ -19,19 +19,7 @@ #define __CW_DTLS_H -#include -#include "conn.h" - - -struct dtls_ssl_cert -{ - int size; - int type; - uint8_t * data; -}; - -extern int dtls_bio_read(struct conn *conn, char *out, int maxlen); -extern int dtls_bio_write(struct conn * conn, const char *data, int len); +#include "dtls_common.h" diff --git a/src/cw/dtls_gnutls.c b/src/cw/dtls_gnutls.c index 103276a1..723f04d7 100644 --- a/src/cw/dtls_gnutls.c +++ b/src/cw/dtls_gnutls.c @@ -22,6 +22,7 @@ #include #include +#include "dtls_common.h" #include "dtls_gnutls.h" #include "conn.h" diff --git a/src/cw/dtls_gnutls_accept.c b/src/cw/dtls_gnutls_accept.c index c4fb174a..33ac8a3d 100644 --- a/src/cw/dtls_gnutls_accept.c +++ b/src/cw/dtls_gnutls_accept.c @@ -29,6 +29,7 @@ #include "log.h" #include "sock.h" #include "capwap.h" +#include "dtls_common.h" #include "dtls_gnutls.h" #include "timer.h" diff --git a/src/cw/dtls_gnutls_get_cipher.c b/src/cw/dtls_gnutls_get_cipher.c index 4a921d56..1b98e11a 100644 --- a/src/cw/dtls_gnutls_get_cipher.c +++ b/src/cw/dtls_gnutls_get_cipher.c @@ -1,5 +1,5 @@ - +#include "dtls_common.h" #include "dtls_gnutls.h" const char *dtls_gnutls_get_cipher(struct conn *conn) diff --git a/src/cw/log_syslog.c b/src/cw/log_syslog.c index 9bb8a683..628add20 100644 --- a/src/cw/log_syslog.c +++ b/src/cw/log_syslog.c @@ -16,6 +16,7 @@ */ +#include #include "log.h" diff --git a/src/cw/mbag.c b/src/cw/mbag.c index e2ff03e1..bb48b3b2 100644 --- a/src/cw/mbag.c +++ b/src/cw/mbag.c @@ -237,3 +237,161 @@ struct mbag_item *strmbag_item_create(mbag_t s, char *name) */ /**@}*/ + + + + + + + + + + + + + +int mbag_set(mbag_t t,mbag_item_t *is) +{ + mavl_del(t,is); + mavl_add(t,is); + return 1; + +/* + struct mbag_item *i = mavl_get(s, is); + if (i) { + mbag_del_data(i); + return i; + } + mavl_add(t,is); +*/ +} + +int mbag_set_byte(mbag_t s, const char *id, uint8_t byte) +{ + struct mbag_item *i = mbag_item_create(s, id); + if (!i) + return 0; + i->byte = byte; + i->type = &mbag_type_byte; + return 1; +} + +struct mbag_item * mbag_set_word(mbag_t s, const char *id, uint16_t word) +{ + struct mbag_item *i = mbag_item_create(s, id); + if (!i) + return 0; + i->word = word; + i->type = &mbag_type_word; + return i; +} + + + + +struct mbag_item * mbag_set_dword(mbag_t s, const char *id, uint32_t dword) +{ + struct mbag_item *i = mbag_item_create(s, id); + if (!i) + return NULL; + i->dword = dword; + i->type = &mtype_dword; + return i; +} + + +int mbag_i_set_mbag(mbag_t s, uint32_t id, mbag_t mbag) +{ + struct mbag_item *i = mbag_i_item_create(s, id); + if (!i) + return 0; + i->data = mbag; + i->type = &mbag_type_mbag; + return 1; +} + +int mbag_set_mbag(mbag_t s, const char *id, mbag_t mbag) +{ + struct mbag_item *i = mbag_item_create(s, id); + if (!i) + return 0; + i->data = mbag; + i->type = &mbag_type_mbag; + return 1; +} + +int mbag_set_data(mbag_t s, const char *id, const struct mbag_typedef *type, void *data) +{ + struct mbag_item *i = mbag_item_create(s, id); + if (!i) + return 0; + i->data = data; + i->type = type; + return 1; + + +} + + +bstrv_t mbag_set_bstrv(mbag_t s, const char *id, uint32_t vendor_id, + uint8_t * version, int len) +{ + mbag_item_t *i = mbag_item_create(s, id); + if (!i) + return NULL; + + i->type = MBAG_VENDORSTR; + i->data = bstrv_create(vendor_id,version,len); + return i->data; +} + + + + + + + + + + + + + +mbag_item_t *mbag_get(mbag_t s, const char *id) +{ + mbag_item_t i; + i.id = id; + i.type=0; + return mavl_get(s, &i); +} + + +mbag_item_t *mbag_i_get(mbag_t s, uint32_t id) +{ + mbag_item_t i; + i.iid = id; + i.type=0; + return mavl_get(s, &i); +} + + + +void mbag_del(mbag_t s,const char *id) +{ + mbag_item_t i; + i.id = id; + i.type=0; + mavl_del(s, &i); +} + +void * mbag_get_data(mbag_t s, const char *id, const struct mbag_typedef * type, void * def) +{ + struct mbag_item *i = mbag_get(s, id); + if (!i) + return def; + if (i->type != type) + return def; + return i->data; +} + + diff --git a/src/cw/mbag.h b/src/cw/mbag.h index 2a2d27b8..96d80761 100644 --- a/src/cw/mbag.h +++ b/src/cw/mbag.h @@ -176,100 +176,15 @@ struct mbag_item *mbag_item_create(mbag_t s, const char *id); struct mbag_item *mbag_i_item_create(mbag_t s, uint32_t id); -static inline int mbag_set(mbag_t t,mbag_item_t *is) -{ - mavl_del(t,is); - mavl_add(t,is); - return 1; - -/* - struct mbag_item *i = mavl_get(s, is); - if (i) { - mbag_del_data(i); - return i; - } - mavl_add(t,is); -*/ -} - -static inline int mbag_set_byte(mbag_t s, const char *id, uint8_t byte) -{ - struct mbag_item *i = mbag_item_create(s, id); - if (!i) - return 0; - i->byte = byte; - i->type = &mbag_type_byte; - return 1; -} - -static inline struct mbag_item * mbag_set_word(mbag_t s, const char *id, uint16_t word) -{ - struct mbag_item *i = mbag_item_create(s, id); - if (!i) - return 0; - i->word = word; - i->type = &mbag_type_word; - return i; -} - - - - -static inline struct mbag_item * mbag_set_dword(mbag_t s, const char *id, uint32_t dword) -{ - struct mbag_item *i = mbag_item_create(s, id); - if (!i) - return NULL; - i->dword = dword; - i->type = &mtype_dword; - return i; -} - - -static inline int mbag_i_set_mbag(mbag_t s, uint32_t id, mbag_t mbag) -{ - struct mbag_item *i = mbag_i_item_create(s, id); - if (!i) - return 0; - i->data = mbag; - i->type = &mbag_type_mbag; - return 1; -} - -static inline int mbag_set_mbag(mbag_t s, const char *id, mbag_t mbag) -{ - struct mbag_item *i = mbag_item_create(s, id); - if (!i) - return 0; - i->data = mbag; - i->type = &mbag_type_mbag; - return 1; -} - -static inline int mbag_set_data(mbag_t s, const char *id, const struct mbag_typedef *type, void *data) -{ - struct mbag_item *i = mbag_item_create(s, id); - if (!i) - return 0; - i->data = data; - i->type = type; - return 1; - - -} - - -static inline bstrv_t mbag_set_bstrv(mbag_t s, const char *id, uint32_t vendor_id, - uint8_t * version, int len) -{ - mbag_item_t *i = mbag_item_create(s, id); - if (!i) - return NULL; - - i->type = MBAG_VENDORSTR; - i->data = bstrv_create(vendor_id,version,len); - return i->data; -} +bstrv_t mbag_set_bstrv(mbag_t s, const char *id, uint32_t vendor_id, + uint8_t * version, int len); +int mbag_set_data(mbag_t s, const char *id, const struct mbag_typedef *type, void *data); +int mbag_set_mbag(mbag_t s, const char *id, mbag_t mbag); +int mbag_i_set_mbag(mbag_t s, uint32_t id, mbag_t mbag); +struct mbag_item * mbag_set_dword(mbag_t s, const char *id, uint32_t dword); +struct mbag_item * mbag_set_word(mbag_t s, const char *id, uint16_t word); +int mbag_set_byte(mbag_t s, const char *id, uint8_t byte); +int mbag_set(mbag_t t,mbag_item_t *is); mbag_item_t *mbag_item_new(mbagtype_t type); @@ -281,42 +196,19 @@ mbag_item_t *mbag_item_new(mbagtype_t type); #define mbag_set_bstr16(m,i,d) mbag_set_data(m,i,MBAG_BSTR16,d) -static inline mbag_item_t *mbag_get(mbag_t s, const char *id) -{ - mbag_item_t i; - i.id = id; - i.type=0; - return mavl_get(s, &i); -} - - -static inline mbag_item_t *mbag_i_get(mbag_t s, uint32_t id) -{ - mbag_item_t i; - i.iid = id; - i.type=0; - return mavl_get(s, &i); -} -static inline void mbag_del(mbag_t s,const char *id) -{ - mbag_item_t i; - i.id = id; - i.type=0; - mavl_del(s, &i); -} +void * mbag_get_data(mbag_t s, const char *id, const struct mbag_typedef * type, void * def); +void mbag_del(mbag_t s,const char *id); +mbag_item_t *mbag_i_get(mbag_t s, uint32_t id); +mbag_item_t *mbag_get(mbag_t s, const char *id); + + + + + -static inline void * mbag_get_data(mbag_t s, const char *id, const struct mbag_typedef * type, void * def) -{ - struct mbag_item *i = mbag_get(s, id); - if (!i) - return def; - if (i->type != type) - return def; - return i->data; -} #define mbag_get_bstr(m,i,d) mbag_get_data(m,i,MBAG_BSTR,d) #define mbag_get_bstr16(m,i,d) mbag_get_data(m,i,MBAG_BSTR16,d) From c3d07a30e90656ab965f3242c2de1b403d4693c9 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Thu, 1 Mar 2018 23:13:26 +0000 Subject: [PATCH 7/7] for tcc compiler FossilOrigin-Name: e92658b29c67652cb6c26acf4a9856bcb00373b326250547d496dfec35b6675f --- src/cw/dtls_common.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/cw/dtls_common.h diff --git a/src/cw/dtls_common.h b/src/cw/dtls_common.h new file mode 100644 index 00000000..ae268368 --- /dev/null +++ b/src/cw/dtls_common.h @@ -0,0 +1,13 @@ +#include +#include "conn.h" +struct dtls_ssl_cert +{ + int size; + int type; + uint8_t * data; +}; + +extern int dtls_bio_read(struct conn *conn, char *out, int maxlen); +extern int dtls_bio_write(struct conn * conn, const char *data, int len); + +