diff --git a/src/ac/socklist.c b/src/ac/socklist.c index 6b78f205..75583841 100644 --- a/src/ac/socklist.c +++ b/src/ac/socklist.c @@ -282,7 +282,7 @@ int socklist_add_unicast(const char *addr, const char * port, int ac_proto) socklist[socklist_len].ac_proto=ac_proto; socklist_len++; - cw_log(LOG_INFO,"Bound to: %s (%i)\n",addr,sockfd); + cw_log(LOG_INFO,"Bound to: %s (%i)",addr,sockfd); } freeaddrinfo(res0); @@ -349,7 +349,7 @@ int socklist_add_broadcast(const char *addr, const char * port,int ac_proto) // printf ("sock proto %d\n",socklist[socklist_len].ac_proto); socklist_len++; - cw_log(LOG_INFO,"Bound to broadcast: %s:%s (%i,R:%i,I:%d)\n",addr,port,sockfd,rfd,socklist_len-1); + cw_log(LOG_INFO,"Bound to broadcast: %s:%s (%i,R:%i,I:%d)",addr,port,sockfd,rfd,socklist_len-1); } freeaddrinfo(res0); diff --git a/src/capwap/Makefile b/src/capwap/Makefile index c4068a0c..4225f34f 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -95,14 +95,6 @@ LWAPPCISCOOBJS = \ CAPWAPOBJS= \ - cwmsg_init_echo_request.o \ - cwmsg_addelem.o \ - cwmsg_vaddelem.o \ - cwmsg_addelem_ac_descriptor.o \ - cwmsg_addelem_wtp_descriptor.o \ - cwmsg_addelem_cw_local_ip_addr.o \ - cwmsg_addelem_mtu_discovery_padding.o \ - cwmsg_addelem_ac_timestamp.o \ cwmsg_addelem_maximum_message_length.o \ cwmsg_addelem_image_identifier.o \ cwmsg_send.o \ @@ -148,7 +140,15 @@ CAPWAPOBJS= \ # cwsend_unknow_response.o \ cw_send_configuration_update_response.o \ cwsend_echo_request.o \ - cw_send_echo_response.o \ + cwmsg_init_echo_request.o \ + cwmsg_addelem.o \ + cwmsg_vaddelem.o \ + cwmsg_addelem_ac_descriptor.o \ + cwmsg_addelem_wtp_descriptor.o \ + cwmsg_addelem_cw_local_ip_addr.o \ + cwmsg_addelem_mtu_discovery_padding.o \ + cwmsg_addelem_ac_timestamp.o \ +cw_send_echo_response.o \ cw_handle_echo_request.o \ cwsend_conf_status_response.o\ cw_readmsg_configuration_status_response.o \ diff --git a/src/capwap/action.h b/src/capwap/action.h index f6060641..e69ed35b 100644 --- a/src/capwap/action.h +++ b/src/capwap/action.h @@ -73,7 +73,7 @@ struct cw_action_out{ uint32_t item_id; uint32_t vendor_id; uint16_t elem_id; - + int (*init)(struct conn * conn, struct cw_action_out *a, uint8_t * dst); int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst); struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a); uint8_t mand; diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index 0ab861b8..dd7d7f46 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -962,6 +962,8 @@ int cw_in_check_img_data_req(struct conn *conn, struct cw_action_in *a, uint8_t int cw_out_wtp_board_data(struct conn *conn,struct cw_action_out * a,uint8_t *dst) ; void cw_init_request(struct conn *conn,int msg_id); +struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a); + diff --git a/src/capwap/capwap_action_helpers.c b/src/capwap/capwap_action_helpers.c index 5eef1d5f..627982d0 100644 --- a/src/capwap/capwap_action_helpers.c +++ b/src/capwap/capwap_action_helpers.c @@ -27,3 +27,25 @@ struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a) return cw_itemstore_get(conn->local,a->item_id); } + + +#include "capwap.h" +#include "capwap_items.h" + +#include "log.h" +#include "rand.h" + +struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a) +{ + 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 NULL; + } + + + return cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,4); +} + diff --git a/src/capwap/capwap_actions_ac.c b/src/capwap/capwap_actions_ac.c index 11941ddd..3d3e5d83 100644 --- a/src/capwap/capwap_actions_ac.c +++ b/src/capwap/capwap_actions_ac.c @@ -148,17 +148,17 @@ cw_action_out_t capwap_actions_ac_out[] = { /* AC Descriptor */ {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR, - cw_out_ac_descriptor, 0} + NULL,cw_out_ac_descriptor, 0} , /* AC Name */ {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_NAME, 0, - CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_outgoing} + CW_ELEM_AC_NAME, NULL, cw_out_generic, cw_out_get_outgoing} , /* List of CAPWAP Control IPv4 and IPv6 addresses */ {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, 0, - 0, cw_out_capwap_control_ip_addr_list, cw_out_get_outgoing} + 0, NULL, cw_out_capwap_control_ip_addr_list, cw_out_get_outgoing} , @@ -170,17 +170,17 @@ cw_action_out_t capwap_actions_ac_out[] = { /* Result Code */ {CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE, 0, - CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_outgoing, 1} + CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1} , /* AC Descriptor */ {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR, - cw_out_ac_descriptor, 0, 1} + NULL,cw_out_ac_descriptor, 0, 1} , /* AC Name */ {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_NAME, 0, - CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_outgoing} + CW_ELEM_AC_NAME, NULL, cw_out_generic, cw_out_get_outgoing} , @@ -194,7 +194,7 @@ cw_action_out_t capwap_actions_ac_out[] = { /* Result Code */ {CW_MSG_IMAGE_DATA_RESPONSE, CW_ITEM_RESULT_CODE, 0, - CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_outgoing, 1} + CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1} , diff --git a/src/capwap/capwap_actions_wtp.c b/src/capwap/capwap_actions_wtp.c index 2c42c8d6..1e88a3e4 100644 --- a/src/capwap/capwap_actions_wtp.c +++ b/src/capwap/capwap_actions_wtp.c @@ -89,13 +89,13 @@ cw_action_out_t capwap_actions_wtp_out[] = { /* AC Name */ {CW_MSG_DISCOVERY_REQUEST, CW_ITEM_DISCOVERY_TYPE, 0, - CW_ELEM_DISCOVERY_TYPE, cw_out_generic, cw_out_get_outgoing} + CW_ELEM_DISCOVERY_TYPE, NULL,cw_out_generic, cw_out_get_outgoing} , /* WTP Board Data */ {CW_MSG_DISCOVERY_REQUEST, CW_ITEM_WTP_BOARD_DATA, 0, - CW_ELEM_WTP_BOARD_DATA, cw_out_wtp_board_data, cw_out_get_outgoing} + CW_ELEM_WTP_BOARD_DATA, NULL,cw_out_wtp_board_data, cw_out_get_outgoing} , @@ -108,15 +108,26 @@ cw_action_out_t capwap_actions_wtp_out[] = { /* Location Data */ {CW_MSG_JOIN_REQUEST, CW_ITEM_LOCATION_DATA, 0, - CW_ELEM_LOCATION_DATA, cw_out_generic, cw_out_get_local,1} + CW_ELEM_LOCATION_DATA, NULL,cw_out_generic, cw_out_get_local,1} , + /* WTP Board Data */ + {CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_BOARD_DATA, 0, + CW_ELEM_WTP_BOARD_DATA, NULL,cw_out_wtp_board_data, cw_out_get_outgoing} + , + + /* WTP Name */ {CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_NAME, 0, - CW_ELEM_WTP_NAME, cw_out_generic, cw_out_get_local,1} + CW_ELEM_WTP_NAME, NULL,cw_out_generic, cw_out_get_local,1} , + /* Session ID */ + {CW_MSG_JOIN_REQUEST, CW_ITEM_SESSION_ID, 0, + CW_ELEM_SESSION_ID, NULL,cw_out_generic, cw_out_get_session_id,1} + , + {0, 0} }; diff --git a/src/capwap/cipwap_actions_ac.c b/src/capwap/cipwap_actions_ac.c index 14083d31..5546e654 100644 --- a/src/capwap/cipwap_actions_ac.c +++ b/src/capwap/cipwap_actions_ac.c @@ -56,13 +56,13 @@ cw_action_out_t cipwap_actions_ac_out[] = { /* AC Descriptor (Cisco) */ {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 , - CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0} + CW_ELEM_AC_DESCRIPTOR, NULL,cw_out_cisco_ac_descriptor, 0} , /* Cisco AP Timesync - Important to get the WTP a DTLS connection stablished*/ {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_TIMESTAMP, CW_VENDOR_ID_CISCO, - CW_CISCO_AP_TIMESYNC, cw_out_cisco_ap_timesync, 0} + CW_CISCO_AP_TIMESYNC, NULL,cw_out_cisco_ap_timesync, 0} , /* ------------------------------------------------------------------------------- @@ -71,7 +71,7 @@ cw_action_out_t cipwap_actions_ac_out[] = { /* AC Descriptor (Cisco) */ {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 , - CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0} + CW_ELEM_AC_DESCRIPTOR, NULL,cw_out_cisco_ac_descriptor, 0} , diff --git a/src/capwap/cw_out_generic.c b/src/capwap/cw_out_generic.c index d592f603..f295a8ce 100644 --- a/src/capwap/cw_out_generic.c +++ b/src/capwap/cw_out_generic.c @@ -18,6 +18,9 @@ int cw_put_item(uint8_t * dst, struct cw_item *item) return cw_put_word(dst, item->word); case CW_ITEMTYPE_DWORD: return cw_put_dword(dst, item->dword); + case CW_ITEMTYPE_BSTR: + return cw_put_bstr(dst,item->data); + } return 0; diff --git a/src/capwap/cw_put_msg.c b/src/capwap/cw_put_msg.c index 605325b8..1e49f87b 100644 --- a/src/capwap/cw_put_msg.c +++ b/src/capwap/cw_put_msg.c @@ -37,6 +37,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout) { + /* rawout is already initialized, so we can get msg type from buffer */ uint8_t *msgptr = rawout + cw_get_hdr_msg_offset(rawout); diff --git a/src/capwap/cw_rand.c b/src/capwap/cw_rand.c index 8d6b7a66..f91974c6 100644 --- a/src/capwap/cw_rand.c +++ b/src/capwap/cw_rand.c @@ -30,17 +30,17 @@ #include "cw_util.h" #include "log.h" -char * cw_rand_dev = "/dev/random"; +char *cw_rand_dev = "/dev/random"; -int cw_rand_r(uint8_t*dst, int len) +int cw_rand_r(uint8_t * dst, int len) { int rf; int l; - rf = open(cw_rand_dev, O_RDONLY | O_NDELAY); - if (rf<0){ + rf = open(cw_rand_dev, O_RDONLY | O_NDELAY); + if (rf < 0) { - cw_log(LOG_ERR,"Can't open %s: %s",cw_rand_dev,strerror(errno)); + cw_log(LOG_ERR, "Can't open %s: %s", cw_rand_dev, strerror(errno)); return 0; } @@ -48,8 +48,8 @@ int cw_rand_r(uint8_t*dst, int len) l = read(rf, dst, len); close(rf); - if ((l<0) && (errno != EAGAIN)){ - cw_log(LOG_ERR,"Cant read from %s: %s",cw_rand_dev,strerror(errno)); + if ((l < 0) && (errno != EAGAIN)) { + cw_log(LOG_ERR, "Cant read from %s: %s", cw_rand_dev, strerror(errno)); return 0; } @@ -58,25 +58,24 @@ int cw_rand_r(uint8_t*dst, int len) - -int cw_rand(uint8_t *dst, int len) +int cw_rand(uint8_t * dst, int len) { static uint32_t rinit = 0; - if (!rinit){ + if (!rinit) { - int l = cw_rand_r((uint8_t*)(&rinit),sizeof(uint32_t)); - if (ltype = CW_ITEMTYPE_BSTR; i->data = bstr_create(data, len); - return 1; + return i; } int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len) diff --git a/src/capwap/itemstore.h b/src/capwap/itemstore.h index 72035f59..c2aba3d0 100644 --- a/src/capwap/itemstore.h +++ b/src/capwap/itemstore.h @@ -74,7 +74,7 @@ extern cw_itemstore_t cw_itemstore_create(); extern int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n); extern int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str); extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr); -extern int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len); +extern cw_item_t * cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len); extern int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword); extern int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word); extern int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte); diff --git a/src/wtp/discovery.c b/src/wtp/discovery.c index 6ef18cad..8b361de7 100644 --- a/src/wtp/discovery.c +++ b/src/wtp/discovery.c @@ -114,7 +114,6 @@ static int run_discovery(struct conn *conn) time_t timer = cw_timer_start(0); - cw_itemstore_t discs; while (!cw_timer_timeout(timer) && conn->capwap_state == CW_STATE_DISCOVERY) { @@ -129,9 +128,16 @@ static int run_discovery(struct conn *conn) cw_log(LOG_ERROR,"Error reading messages: %s",strerror(errno)); break; } - discs = cw_itemstore_get_avltree(conn->remote, CW_ITEM_DISCOVERIES); } + cw_itemstore_t discs; + discs = cw_itemstore_get_avltree(conn->remote, CW_ITEM_DISCOVERIES); + + + if (!discs) { + cw_log(LOG_ERR,"No discovery responses received"); + return 0; + } int i; diff --git a/src/wtp/join.c b/src/wtp/join.c index 36da60c4..8580f908 100644 --- a/src/wtp/join.c +++ b/src/wtp/join.c @@ -187,7 +187,7 @@ int join() struct conn * conn = get_conn(); cw_aciplist_t iplist = cw_itemstore_get_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST); if (!iplist){ - cw_log(LOG_ERR,"No Ips to join controller."); + cw_log(LOG_ERR,"No IPs to join controller."); return 0; } diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index 65a4635e..e1cc5143 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -75,7 +75,6 @@ int main() cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube"); -cw_log(LOG_ERR,"Entetrente"); discovery(); join();