From c1ffe70955af97ef969645fdf1c0e8ed2e711003 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Mon, 25 Aug 2014 05:56:14 +0000 Subject: [PATCH] Work in progress ... FossilOrigin-Name: 33e1ed226e6651e85e45bdc2f54c9e0b616d51b13ec76d2df0e01c22ded791e6 --- src/Config.mak | 1 + src/ac/ac_main.c | 1 + src/ac/conf.c | 5 ++ src/ac/wtpman.c | 78 +++++++++++++++++-- src/capwap/Makefile | 9 ++- src/capwap/capwap.h | 2 +- src/capwap/conn.h | 4 +- src/capwap/cwmsg_addelem_ac_descriptor.c | 34 ++++++-- src/capwap/cwmsg_addelem_image_identifier.c | 17 ++++ .../cwread_change_state_event_request.c | 11 ++- .../cwread_configuration_status_request.c | 3 +- src/capwap/cwsend_join_response.c | 30 +++---- src/capwap/lw_checksum.c | 13 +++- 13 files changed, 170 insertions(+), 38 deletions(-) diff --git a/src/Config.mak b/src/Config.mak index ab7712b1..1ebf2e86 100644 --- a/src/Config.mak +++ b/src/Config.mak @@ -9,3 +9,4 @@ USE_CONTRIB_OPENSSL=1 CONF_LIBRARY=UCI USE_CONTRIB_UCI=1 +CC=clang diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index b8da6da8..42d0e5a8 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -40,6 +40,7 @@ int ac_run(); int main (int argc, const char * argv[]) { +// send_image_file(0,"/home/tube/Downloads/c1130-rcvk9w8-tar.124-25e.JAP.tar"); cw_log_name="AC-Tube"; diff --git a/src/ac/conf.c b/src/ac/conf.c index 2ddd01c4..5ca32137 100644 --- a/src/ac/conf.c +++ b/src/ac/conf.c @@ -530,6 +530,11 @@ static int conf_read_dbg_level(cfg_t *cfg) for (i=0; i @@ -158,6 +159,8 @@ struct cwrmsg * conn_send_request(struct conn * conn) struct cwrmsg * cwrmsg; struct cwmsg * cwmsg = &conn->req_msg; +printf("Retrans interval = %d\n",conn->retransmit_interval); +printf("Current Seqnum = %d\n",conn->seqnum); for (i=0; imax_retransmit; i++) { @@ -215,6 +218,11 @@ void send_image_file(struct conn * conn,const char * filename) return; } + + + + + cw_log(LOG_INFO,"Sending image file %s to %s",filename,sock_addr2str(&conn->addr)); struct cwrmsg * cwrmsg; @@ -223,15 +231,47 @@ void send_image_file(struct conn * conn,const char * filename) data.data = buffer; + conn->request_handler = conn_handle_echo_request; + conn->request_handler_param = conn; + +int bl=0; + +//fseek(infile,2703*1024,SEEK_SET); do{ + + + +int ai; +for (ai=0; ai<1024; ai++){ + printf("%02X ",buffer[ai]); + +} + data.len = fread(buffer,1,sizeof(buffer),infile); +//data.len=0; + + + + if (feof(infile)) data.type=2; else data.type=1; - printf("Send img data request\n"); - cwsend_image_data_request(conn,&data,0); - cwrmsg = conn_get_response(conn); + + if (data.len==0){ + printf("*******************************************len0************************************\n"); + } + + printf("Send img data request, block=%d, len=%d, ch=%d\n",bl,data.len,lw_checksum(data.data,data.len)); + +//exit(0); + + bl++; + + conn_prepare_image_data_request(conn,&data,0); + cwrmsg = conn_send_request(conn); + + if (cwrmsg){ printf("Got img data response\n"); } @@ -361,7 +401,6 @@ static void wtpman_run_run(void *arg) printf("Update now?\n"); - conn->seqnum=1; conn_prepare_request(conn,CWMSG_CONFIGURATION_UPDATE_REQUEST); cwmsg_addelem(&conn->req_msg,CWMSGELEM_WTP_NAME,(uint8_t*)"Tube7u83",strlen("Tube7u83")+1); @@ -441,6 +480,7 @@ static int wtpman_join(void *arg,time_t timer) int join_msgs[] = { CWMSG_JOIN_REQUEST, -1 }; struct cwrmsg * cwrmsg; cwrmsg = conn_wait_for_request(wtpman->conn, join_msgs, timer); + if (!cwrmsg){ if (conn_is_error(wtpman->conn)){ cw_dbg(DBG_CW_MSG_ERR,"DTLS connection closed while waiting for join request from %s.",CLIENT_IP); @@ -482,7 +522,9 @@ static int wtpman_join(void *arg,time_t timer) static void wtpman_run(void *arg) { struct wtpman * wtpman = (struct wtpman *)arg; - struct cwrmsg * cwrmsg = conn_get_message(wtpman->conn); + struct cwrmsg * cwrmsg; // = conn_get_message(wtpman->conn); + + wtpman->conn->seqnum=0; /* reject connections to our multi- or broadcast sockets */ if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET){ @@ -507,7 +549,31 @@ static void wtpman_run(void *arg) return; } - /* here the WTP has joined */ + /* here the WTP has joined, now image update or change state event */ + + int msgs[] = { CWMSG_IMAGE_DATA_REQUEST, CWMSG_CHANGE_STATE_EVENT_REQUEST, -1 }; + cwrmsg = conn_wait_for_request(wtpman->conn, msgs, timer); + + if (!cwrmsg){ + wtpman_remove(wtpman); + return; + } + + + switch (cwrmsg->type){ + case CWMSG_CHANGE_STATE_EVENT_REQUEST: + printf("Change state event\n!"); + break; + case CWMSG_IMAGE_DATA_REQUEST: + printf("Image update\n!"); + cwsend_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_SUCCESS); + // send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-rcvk9w8-tar.124-25e.JAO5.tar"); +// send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-k9w8-tar.124-25e.JAP.tar"); + send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-rcvk9w8-tar.124-25e.JAP.tar"); + + break; + } + printf("WTP is joined now\n"); diff --git a/src/capwap/Makefile b/src/capwap/Makefile index a074d18a..5e357311 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -1,3 +1,4 @@ +CC=clang ifndef CC CC=gcc endif @@ -81,7 +82,6 @@ CAPWAPOBJS= \ cwread_discovery_response.o \ cwsend_discovery_request.o \ cwread_image_data_request.o \ - cwsend_image_data_request.o \ cwsend_image_data_response.o \ cwsend_join_request.o \ cwsend_join_response.o \ @@ -122,8 +122,10 @@ CAPWAPOBJS= \ cw_readelem_radio_operational_state.o \ cw_readelem_statistics_timer.o \ cw_readelem_wtp_reboot_statistics.o\ - cwmsg_addelem_vendor_cisco_ap_timesync.o + cwmsg_addelem_vendor_cisco_ap_timesync.o \ + lw_checksum.o + # cwsend_image_data_request.o # cwmsg_set_control_header.o @@ -154,7 +156,8 @@ CONNOBJS= conn.o \ conn_get_message.o \ conn_get_response.o \ conn_prepare_configuration_update_request.o \ - conn_prepare_request.o + conn_prepare_request.o \ + conn_prepare_image_data_request.o diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index b34501ff..d90c4c99 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -318,7 +318,7 @@ extern int wtpinfo_set_radioinfo(struct wtpinfo * wtpinfo,uint8_t *msgelem, int struct image_data{ uint8_t * data; - int type; + uint8_t type; int len; }; diff --git a/src/capwap/conn.h b/src/capwap/conn.h index 8f5d0bc9..616c305c 100644 --- a/src/capwap/conn.h +++ b/src/capwap/conn.h @@ -169,9 +169,11 @@ void connlist_remove(struct connlist *cl,struct conn * conn); void connlist_destroy(struct connlist * cl); void conn_q_add_packet(struct conn * conn,uint8_t *packet,int len); - +struct image_identifier; +struct image_data; extern void conn_prepare_request(struct conn * conn, int type); +extern int conn_prepare_image_data_request(struct conn * conn, struct image_data *, struct image_identifier *id ); #define conn_is_error(conn) (conn->dtls_error) diff --git a/src/capwap/cwmsg_addelem_ac_descriptor.c b/src/capwap/cwmsg_addelem_ac_descriptor.c index c8a99ac5..77208939 100644 --- a/src/capwap/cwmsg_addelem_ac_descriptor.c +++ b/src/capwap/cwmsg_addelem_ac_descriptor.c @@ -28,10 +28,10 @@ void cwmsg_addelem_ac_descriptor(struct cwmsg *msg,struct ac_info * acinfo) *((uint32_t*)(acd+4))=htonl((acinfo->active_wtps<<16) | acinfo->max_wtps); *((uint32_t*)(acd+8))=htonl((acinfo->security<<24) | (acinfo->rmac<<16) | acinfo->dtls_policy ); + int len = 12; int sublen; - sublen = 4; *((uint32_t*)(acd+len))=htonl(CW_VENDOR_ID_CISCO); @@ -39,18 +39,36 @@ void cwmsg_addelem_ac_descriptor(struct cwmsg *msg,struct ac_info * acinfo) *((uint32_t*)(acd+len))=htonl((1<<16)|sublen); len+=4; *(acd+len)=7; len++; - *(acd+len)=3; len++; + *(acd+len)=4; len++; *(acd+len)=1; len++; *(acd+len)=72; len++; -/* *(acd+len)=5; len++; + *(acd+len)=5; len++; *(acd+len)=6; len++; *(acd+len)=7; len++; *(acd+len)=8; len++; -*/ + + + *((uint32_t*)(acd+len))=htonl(CW_VENDOR_ID_CISCO); + len+=4; + *((uint32_t*)(acd+len))=htonl((1<<16)|sublen); + len+=4; + *(acd+len)=7; len++; + *(acd+len)=3; len++; + *(acd+len)=1; len++; + *(acd+len)=72; len++; + *(acd+len)=5; len++; + *(acd+len)=6; len++; + *(acd+len)=7; len++; + *(acd+len)=8; len++; + + + + +goto b; /* software version subelement */ -/* *((uint32_t*)(acd+len))=htonl(CW_VENDOR_ID_CISCO); + *((uint32_t*)(acd+len))=htonl(CW_VENDOR_ID_CISCO); len+=4; sublen=strlen((const char*)acinfo->software_version); *((uint32_t*)(acd+len))=htonl((1<<16)|sublen); @@ -58,16 +76,16 @@ void cwmsg_addelem_ac_descriptor(struct cwmsg *msg,struct ac_info * acinfo) memcpy(acd+len,acinfo->software_version,sublen); len+=sublen; -*/ + /* hardware version subelement */ -/* *((uint32_t*)(acd+len))=htonl(CW_VENDOR_ID_CISCO); + *((uint32_t*)(acd+len))=htonl(CW_VENDOR_ID_CISCO); len+=4; sublen=strlen((const char*)acinfo->hardware_version); *((uint32_t*)(acd+len))=htonl((4<<16)|sublen); len+=4; memcpy(acd+len,acinfo->hardware_version,sublen); len+=sublen; -*/ +b: cwmsg_addelem(msg,CWMSGELEM_AC_DESCRIPTOR,acd,len); } diff --git a/src/capwap/cwmsg_addelem_image_identifier.c b/src/capwap/cwmsg_addelem_image_identifier.c index b08d5925..e24b4a83 100644 --- a/src/capwap/cwmsg_addelem_image_identifier.c +++ b/src/capwap/cwmsg_addelem_image_identifier.c @@ -1,3 +1,20 @@ +/* + 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 "cwmsg.h" diff --git a/src/capwap/cwread_change_state_event_request.c b/src/capwap/cwread_change_state_event_request.c index ff0f36d3..32169d08 100644 --- a/src/capwap/cwread_change_state_event_request.c +++ b/src/capwap/cwread_change_state_event_request.c @@ -16,6 +16,13 @@ */ +/** + * @file + * @brief Defines cwread_change_state_even_request function. + * + * Full text + */ + #include #include "capwap.h" @@ -48,7 +55,9 @@ foundX: return 1; } - +/** + * @brief Read elements of a Change State Event Request message. + */ int cwread_change_state_event_request(struct wtpinfo * wtpinfo, uint8_t * msg, int len) { int mand[] = { diff --git a/src/capwap/cwread_configuration_status_request.c b/src/capwap/cwread_configuration_status_request.c index addc0a29..e9d7dcf1 100644 --- a/src/capwap/cwread_configuration_status_request.c +++ b/src/capwap/cwread_configuration_status_request.c @@ -32,7 +32,8 @@ static int readelem(void * eparm,int type,uint8_t* msgelem,int len) { struct eparm * e = (struct eparm*)eparm; - cw_dbg(DBG_CW_MSGELEM,"Reading conf staus req msgelem, type=%d - %s ,len=%d\n",type,cw_msgelemtostr(type),len); +// cw_dbg(DBG_CW_MSGELEM,"Reading conf staus req msgelem, type=%d - %s ,len=%d\n",type,cw_msgelemtostr(type),len); + cw_dbg_msgelem(CWMSG_CONFIGURATION_STATUS_REQUEST, type, msgelem,len); /* mandatory elements */ if (cw_readelem_ac_name(&e->wtpinfo->ac_name,type,msgelem,len)) diff --git a/src/capwap/cwsend_join_response.c b/src/capwap/cwsend_join_response.c index d8b20939..4d66b98a 100644 --- a/src/capwap/cwsend_join_response.c +++ b/src/capwap/cwsend_join_response.c @@ -25,23 +25,23 @@ void cwsend_join_response(struct conn * conn,int seqnum, int rc, struct radioinf -// uint8_t buffer[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -// buffer[0]=0; /* Mwar Type */ -// buffer[1]=1; /* h/w version */ -// buffer[2]=2; /* h/w Release */ -// buffer[3]=0; /* h/w Maint */ -// buffer[4]=3; /* h/w Build */ + uint8_t buffer[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + buffer[0]=0; /* Mwar Type */ + buffer[1]=1; /* h/w version */ + buffer[2]=2; /* h/w Release */ + buffer[3]=0; /* h/w Maint */ + buffer[4]=3; /* h/w Build */ -// buffer[5]=5; /* s/w version */ -// buffer[6]=0; /* s/w Release */ -// buffer[7]=19; /* s/w Maint */ -// buffer[8]=3; /* s/w Build */ + buffer[5]=5; /* s/w version */ + buffer[6]=0; /* s/w Release */ + buffer[7]=19; /* s/w Maint */ + buffer[8]=3; /* s/w Build */ -// *((uint16_t*)(buffer+9))=htons(13); /* Active MS */ -// *((uint16_t*)(buffer+9+2))=htons(23); /* Supported MS */ -// *((uint16_t*)(buffer+9+4))=htons(5); /* Active RAD's */ -// *((uint16_t*)(buffer+9+6))=htons(15); /* Supported RAD's */ -// cwmsg_addelem_vendor_specific_payload(cwmsg,CW_VENDOR_ID_CISCO, 205, buffer,4); + *((uint16_t*)(buffer+9))=htons(13); /* Active MS */ + *((uint16_t*)(buffer+9+2))=htons(23); /* Supported MS */ + *((uint16_t*)(buffer+9+4))=htons(5); /* Active RAD's */ + *((uint16_t*)(buffer+9+6))=htons(15); /* Supported RAD's */ + cwmsg_addelem_vendor_specific_payload(cwmsg,CW_VENDOR_ID_CISCO, CWVENDOR_CISCO_MWAR, buffer,34); conn_send_response(conn,cwmsg,seqnum); diff --git a/src/capwap/lw_checksum.c b/src/capwap/lw_checksum.c index d9efb59b..4b3ec812 100644 --- a/src/capwap/lw_checksum.c +++ b/src/capwap/lw_checksum.c @@ -21,11 +21,16 @@ /** * Calculate the 16-bit checksum for LWAPP image data message * elements with opcode 3 - used by Cisco also in CAPWAP + * (But it's not always correct, the real algo might be another) */ uint16_t lw_checksum(uint8_t * d, int len) { int i; - uint32_t cs = 0xffff; +// uint32_t cs = 0xffff; + if (len==0) + return 0xffff; + + uint32_t cs = 0; for (i = 0; i < len; i += 2) { uint16_t w = d[i] << 8; @@ -36,5 +41,9 @@ uint16_t lw_checksum(uint8_t * d, int len) cs += cs >> 16; cs &= 0xffff; } - return (uint16_t) cs; + return (uint16_t) cs&0xffff; } + + + +