diff --git a/src/ac/ac_global.c b/src/ac/ac_global.c index 2b931f83..1acb10a5 100644 --- a/src/ac/ac_global.c +++ b/src/ac/ac_global.c @@ -68,14 +68,11 @@ cw_aciplist_t get_aciplist() void * get_iplist(void * arg) { - printf("************************************************************************************\n"); - printf("The ist an iplist getter\n"); return get_aciplist(); } void release_iplist(void *arg,void *data) { - printf("And an releaser\n"); } int ac_global_init() diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index a0602a0d..21cadd30 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -29,6 +29,7 @@ #include "wtplist.h" #include "capwap/dtls.h" #include "capwap/log.h" +#include "capwap/dbg.h" #include "conf.h" #include "capwap/sock.h" @@ -137,7 +138,7 @@ int main (int argc, const char * argv[]) cw_log(LOG_INFO,"Starting AC-Tube, Name=%s, ID=%s",conf_acname,conf_acid); - cw_dbg_opt_detail=DBG_DETAIL_ASC_DMP; + cw_dbg_opt_display=DBG_DISP_ASC_DMP | DBG_DISP_COLORS; cw_register_actions_cipwap_ac(&capwap_actions); @@ -305,7 +306,7 @@ void process_cw_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer, char hdrstr[1024]; hdr_print(hdrstr,buffer,len); - cw_dbg(DBG_CW_PKT_IN,"Header for packet from %s\n%s",sock_addr2str(addr),hdrstr); +// cw_dbg(DBG_CW_PKT_IN,"Header for packet from %s\n%s",sock_addr2str(addr),hdrstr); @@ -317,7 +318,7 @@ void process_cw_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer, #else if (preamble != CAPWAP_PACKET_PREAMBLE ){ #endif - cw_dbg(DBG_CW_PKT_ERR,"Discarding packet, wrong preamble, preamble = 0x%01X",preamble); + cw_dbg(DBG_PKT_ERR,"Discarding packet, wrong preamble, preamble = 0x%01X",preamble); return; } @@ -428,10 +429,10 @@ void process_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer, int #ifdef WITH_CW_LOG_DEBUG char str[100]; sock_addrtostr(addr,str,100); - cw_dbg(DBG_CW_PKT_IN,"Received packet from %s, len = %i, via %s\n",sock_addr2str(addr),len, - socklist[index].type==SOCKLIST_UNICAST_SOCKET ? "unicast":"bcast/mcast"); +// cw_dbg(DBG_PKT_IN,"Received packet from %s, len = %i, via %s\n",sock_addr2str(addr),len, +// socklist[index].type==SOCKLIST_UNICAST_SOCKET ? "unicast":"bcast/mcast"); - cw_dbg_dmp(DBG_CW_PKT_DMP,buffer,len,"Dump ..."); +// cw_dbg_dmp(DBG_CW_PKT_DMP,buffer,len,"Dump ..."); // cw_dbg_dmp(buffer,len,"Packet data for packet, recevied from %s",str); #endif diff --git a/src/ac/conf.c b/src/ac/conf.c index 84fa5db5..98ee4cc8 100644 --- a/src/ac/conf.c +++ b/src/ac/conf.c @@ -27,6 +27,7 @@ #include "conf.h" #include "capwap/log.h" +#include "capwap/dbg.h" #include "capwap/cw_util.h" uint8_t conf_macaddress[12]; @@ -537,12 +538,13 @@ static int conf_read_strings( cfg_t * cfg, char * name, char ***dst,int *len) } +/* struct conf_dbg_level_names{ const char *name; int level; }; - +*/ static int conf_read_dbg_level(cfg_t *cfg) @@ -555,7 +557,7 @@ static int conf_read_dbg_level(cfg_t *cfg) for (i=0; i #include "capwap/log.h" +#include "capwap/dbg.h" #include "conf.h" @@ -18,7 +19,7 @@ int db_init() { const char * filename="ac.sqlite3"; - cw_dbg(DBG_CW_INFO,"Init sqlite3 db: %s",filename); + cw_dbg(DBG_INFO,"Init sqlite3 db: %s",filename); int rc = sqlite3_open(filename,&handle); if (rc) { @@ -46,7 +47,7 @@ static sqlite3_stmt * ping_stmt; int db_start() { - cw_dbg(DBG_CW_INFO,"Start sqlite3 db"); + cw_dbg(DBG_INFO,"Start sqlite3 db"); sqlite3_stmt *stmt; int rc = sqlite3_prepare_v2(handle, "INSERT INTO acs (acid,acname) VALUES (?,?);",-1,&stmt,0); diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index 72e4d0b3..b2a597cc 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -15,6 +15,7 @@ #include "wtpman.h" #include "conf.h" #include "capwap/log.h" +#include "capwap/timer.h" #include "conf.h" @@ -35,6 +36,8 @@ #include "capwap/dtls.h" +#include "capwap/dbg.h" + extern struct cw_actiondef capwap_actions; @@ -91,7 +94,7 @@ static void wtpman_remove(struct wtpman *wtpman) int check_discovery(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len) { printf("Discovery END!!!\n"); - conn->capwap_state=CW_STATE_NONE; + conn->capwap_state = CW_STATE_NONE; return 0; } @@ -173,7 +176,7 @@ static void wtpman_run_discovery(void *arg) char wtpinfostr[8192]; wtpinfo_print(wtpinfostr, &wtpman->wtpinfo); - cw_dbg(DBG_CW_INFO, "Discovery request gave us the follwing WTP Info:\n%s", + cw_dbg(DBG_INFO, "Discovery request gave us the follwing WTP Info:\n%s", wtpinfostr); @@ -190,7 +193,7 @@ static void wtpman_run_discovery(void *arg) /* char wtpinfostr[8192]; wtpinfo_print(wtpinfostr,&wtpman->wtpinfo); - cw_dbg(DBG_CW_INFO,"Discovery request gave us the follwing WTP Info:\n%s",wtpinfostr); + cw_dbg(DBG_INFO,"Discovery request gave us the follwing WTP Info:\n%s",wtpinfostr); */ cwsend_discovery_response(wtpman->conn, cwrmsg->seqnum, &radioinfo, acinfo, @@ -223,8 +226,8 @@ static int wtpman_establish_dtls(void *arg) wtpman->conn->dtls_cert_file = conf_sslcertfilename; wtpman->conn->dtls_key_pass = conf_sslkeypass; wtpman->conn->dtls_verify_peer = conf_dtls_verify_peer; - cw_dbg(DBG_DTLS, "DTLS - Using key file %s", wtpman->conn->dtls_key_file); - cw_dbg(DBG_DTLS, "DTLS - Using cert file %s", + cw_dbg(DBG_DTLS, "Using key file %s", wtpman->conn->dtls_key_file); + cw_dbg(DBG_DTLS, "Using cert file %s", wtpman->conn->dtls_cert_file); dtls_ok = 1; } @@ -258,12 +261,11 @@ static int wtpman_establish_dtls(void *arg) FILE *f; f = fopen("pcert.der", "wb"); - printf("Calling peers cert\n"); cert = dtls_get_peers_cert(wtpman->conn, 0); - printf("Back from peers cert\n"); - printf("Have Peers Cert: %p, %d\n", cert.data, cert.size); - fwrite(cert.data, 1, cert.size, f); +// printf("Have Peers Cert: %p, %d\n", cert.data, cert.size); +// fwrite(cert.data, 1, cert.size, f); + fclose(f); return 1; @@ -284,6 +286,11 @@ static int wtpman_join(void *arg, time_t timer) wtpman->conn->outgoing = ac_config; wtpman->conn->incomming = cw_itemstore_create(); + wtpman->conn->local = cw_itemstore_create(); + + struct conn * conn = wtpman->conn; + + cw_dbg(DBG_INFO,"Join State - %s",sock_addr2str(&conn->addr)); while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CW_STATE_JOIN) { int rc = cw_read_messages(wtpman->conn); @@ -292,13 +299,13 @@ static int wtpman_join(void *arg, time_t timer) } } - if (wtpman->conn->capwap_state==CW_STATE_JOIN){ + if (wtpman->conn->capwap_state == CW_STATE_JOIN) { cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.", sock_addr2str(&wtpman->conn->addr), wtpman->conn->wait_dtls); return 0; } - + return 1; @@ -384,280 +391,76 @@ static void wtpman_run(void *arg) State is Image update */ - - while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CW_STATE_CONFIGURE) { - int rc = cw_read_messages(wtpman->conn); + int rc = 0; + while (!cw_timer_timeout(timer) + && wtpman->conn->capwap_state == CW_STATE_CONFIGURE) { + rc = cw_read_messages(wtpman->conn); if (rc < 0) { - break; + if (errno != EAGAIN) + break; } } + if (!rc) { + cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc)); + } + struct conn *conn = wtpman->conn; - - - exit(0); - - - - - - - - -/* - - - - - - do { - int cfg_status_msgs[] = - { CW_MSG_IMAGE_DATA_REQUEST, CW_MSG_CONFIGURATION_STATUS_REQUEST, - -1 }; - cwrmsg = conn_wait_for_request(wtpman->conn, cfg_status_msgs, timer); - - if (!cwrmsg) { - cw_dbg(DBG_MSG_ERR, - "No conf status or img data request from %s after %d seconds, WTP died.", - sock_addr2str(&wtpman->conn->addr), - wtpman->conn->wait_join); - wtpman_remove(wtpman); + if (conn->capwap_state == CW_STATE_IMAGE_DATA) { + /* Image upload */ + const char *filename = + cw_itemstore_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME); + if (!filename) { + cw_log(LOG_ERR, + "Can't send image to %s. No Image Filename Item found.", + sock_addr2str(&conn->addr)); + return; + } + cw_dbg(DBG_INFO, "Sending image file '%s' to '%s'.", filename, + sock_addr2str(&conn->addr)); + FILE *infile = fopen(filename, "rb"); + if (infile == NULL) { + cw_log(LOG_ERR, "Can't open image %s: %s", + sock_addr2str(&conn->addr), strerror(errno)); return; } - // Image data request, the WTP wants an update - if (cwrmsg->type == CW_MSG_IMAGE_DATA_REQUEST) { - int rc = wtpman_send_image_file(wtpman, cwrmsg); - if (rc) { - wtpman_remove(wtpman); - return; - } + cw_itemstore_set_const_ptr(conn->outgoing, CW_ITEM_IMAGE_FILEHANDLE, + infile); + + clock_t clk = cw_clock_start(); + int rc=0; + while (conn->capwap_state == CW_STATE_IMAGE_DATA && !feof(infile) && rc==0) { + rc = cw_send_request(conn, CW_MSG_IMAGE_DATA_REQUEST); } - } while (cwrmsg->type != CW_MSG_CONFIGURATION_STATUS_REQUEST); - - - - printf("Have Masseg %d\n", cwrmsg->type); - cwread_configuration_status_request(&wtpman->wtpinfo, cwrmsg->msgelems, - cwrmsg->msgelems_len); - int result_code = 0; - struct ac_info *acinfo = get_acinfo(); - struct radioinfo rinf; - cwsend_conf_status_response(wtpman->conn, cwrmsg->seqnum, result_code, &rinf, - acinfo, &wtpman->wtpinfo); - printf("Send the respi but sleep\n"); - - - printf("Next thoing\n"); - int change_status_msgs[] = - { CW_MSG_IMAGE_DATA_REQUEST, CW_MSG_CHANGE_STATE_EVENT_REQUEST, -1 }; - cwrmsg = conn_wait_for_request(wtpman->conn, change_status_msgs, timer); - printf("Done\n"); - - if (!cwrmsg) { - wtpman_remove(wtpman); - return; - } - - - - switch (cwrmsg->type) { - case CW_MSG_CHANGE_STATE_EVENT_REQUEST: - { - printf("Change state event\n!"); - struct radioinfo ri; - cwsend_change_state_event_response(wtpman->conn, - cwrmsg->seqnum, &ri); - } - break; - case CW_MSG_IMAGE_DATA_REQUEST: - printf("Image update\n!"); - //cwread_image_data_request(0,cwrmsg->msgelems,cwrmsg->msgelems_len); - - - //cwsend_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_SUCCESS); - - //send_image_file(wtpman->conn,"/tftpboot/c1130-k9w7-tar.default"); - - // send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-k9w7-tar.123-8.JEA3.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"); -*/ - -/* - struct radioinfo * radioinfo; - - - - cwrmsg = wtpman_wait_for_message(wtpman,timer); - if (!cwrmsg){ - cw_dbg(DBG_CW_MSG_ERR,"No config or update request from %s after %d seconds, WTP died.", - sock_addr2str(&wtpman->conn->addr),wtpman->conn->wait_join); - wtpman_remove(wtpman); - return; - } - - printf("CWR TYPE %d\n",cwrmsg->type); - exit(0); - -*/ - -// cwread_configuration_status_request(&wtpman->wtpinfo,cwrmsg->msgelems, cwrmsg->msgelems_len); -// cwsend_conf_status_response(wtpman->conn,cwrmsg->seqnum,result_code,&radioinfo,acinfo,&wtpman->wtpinfo); - -/* - char wtpinfostr[8192]; - wtpinfo_print(wtpinfostr, &wtpman->wtpinfo); - cw_dbg(DBG_ALL, "WTP conf_status\n%s", wtpinfostr); - - printf("Run run run run run\n"); - wtpman_run_run(wtpman); - exit(0); -*/ - -/* -int ii; -for (ii=0; ii<3; ii++){ - cwrmsg = wtpman_wait_for_message(wtpman,timer); - if (cwrmsg){ - if (cwrmsg->type == CWMSG_CHANGE_STATE_EVENT_REQUEST){ - cwread_change_state_event_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len); - cwsend_change_state_event_response(wtpman->conn,cwrmsg->seqnum,wtpman->wtpinfo.radioinfo); + if (rc) { + cw_log(LOG_ERR,"Image download RC: %s",cw_strrc(rc)); } - } -} -*/ - -/* - wtpman_run_run(wtpman); - - exit(0); - - - if (cwrmsg->type == CW_MSG_IMAGE_DATA_REQUEST) { - cwread_image_data_request(0, cwrmsg->msgelems, cwrmsg->msgelems_len); - cwsend_image_data_response(wtpman->conn, cwrmsg->seqnum, - CW_RESULT_FAILURE); - } - -*/ - - - - -/* - printf("Sending image file\n"); - send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-rcvk9w8-tar.124-25e.JAO5.tar"); - printf("Back from sending image file\n"); -*/ - exit(0); - - -/* - timer = cw_timer_start(30); - cwrmsg = wtpman_wait_for_message(wtpman, timer); - - if (cwrmsg) - printf("I have got a message of type %d\n", cwrmsg->type); - - if (cwrmsg->type == CW_MSG_IMAGE_DATA_REQUEST) { - cwread_image_data_request(0, cwrmsg->msgelems, cwrmsg->msgelems_len); - cwsend_image_data_response(wtpman->conn, cwrmsg->seqnum, - CW_RESULT_FAILURE); - } - - -*/ - - - - -// char wtpinfostr[8192]; -// wtpinfo_print(wtpinfostr,&wtpman->wtpinfo); -// cw_log_debug0("WTP joined\n%s",wtpinfostr); - -//exit(0); -/* - int msg_counter = 0; - while (1) { - struct cwrmsg *cwrmsg = conn_get_message(wtpman->conn); - - - - - - - if (!cwrmsg) { - msg_counter++; - if (msg_counter < CAPWAP_ECHO_INTERVAL * 2) - continue; - - // cw_log_debug0("WTP died"); - wtpman_remove(wtpman); - return; + else { + cw_dbg(DBG_INFO,"Image '%s' sucessful sent to %s in %0.1f seconds.", + filename,sock_addr2str(&conn->addr),cw_clock_stop(clk)); + conn->capwap_state=CW_STATE_NONE; } - -*/ -/* -if (cwrmsg->type == CWMSG_CONFIGURATION_STATUS_REQUEST){ - process_conf_status_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len); -{ - char wtpinfostr[8192]; - wtpinfo_print(wtpinfostr,&wtpman->wtpinfo); - cw_dbg(DBG_CW_INFO,"Join request gave us the follwing WTP Info:\n%s",wtpinfostr); - - cwsend_conf_status_response(wtpman->conn,cwrmsg->seqnum,result_code,&radioinfo,acinfo,&wtpman->wtpinfo); -} - - -} -*/ - -/* - msg_counter = 0; - - - if (cwrmsg->type == CW_MSG_ECHO_REQUEST) { - cwsend_echo_response(wtpman->conn, cwrmsg->seqnum, - wtpman->wtpinfo.radioinfo); - } -*/ - -// printf("Got msg: %i\n",cwrmsg->type); - -} + + fclose(infile); - -// process_discovery(wtpman,cwrmsg); - - -/* - while (1) { - uint8_t *packet = conn_q_get_packet(wtpman->conn); -// int len = *( (uint32_t*)(packet)); - - -// conn_process_packet(wtpman->conn,packet+4,len); - free(packet); } -*/ + + + return; +} + + void wtpman_destroy(struct wtpman *wtpman) { if (wtpman->conn) @@ -754,11 +557,11 @@ void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t * packet, int len) void wtpman_start(struct wtpman *wtpman, int dtlsmode) { if (dtlsmode) { - cw_dbg(DBG_CW_INFO, "Starting wtpman in DTLS mode"); + cw_dbg(DBG_INFO, "Starting wtpman in DTLS mode"); pthread_create(&wtpman->thread, NULL, (void *) &wtpman_run, (void *) wtpman); } else { - cw_dbg(DBG_CW_INFO, "Starting wtpman in non-dtls mode"); + cw_dbg(DBG_INFO, "Starting wtpman in non-dtls mode"); pthread_create(&wtpman->thread, NULL, (void *) &wtpman_run_discovery, (void *) wtpman); } diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 4225f34f..b98b1875 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -38,8 +38,8 @@ LOGOBJS=log.o \ log_syslog.o \ log_file.o \ cw_log_debug.o \ - cw_log_str2dbglevel.o \ - cw_dbg_elem.o + cw_dbg_elem.o \ + dbg_strings.o @@ -74,7 +74,6 @@ LWAPPOBJS = \ lw_checksum.o \ lw_put_ac_descriptor.o \ lw_put_cisco_path_mtu.o \ - lw_readelem_wtp_name.o \ lw_put_80211_wtp_wlan_radio_configuration.o \ lw_readelem_vendor_specific.o \ lw_vendor_id_to_str.o \ @@ -83,6 +82,8 @@ LWAPPOBJS = \ lw_cisco_id_to_str.o \ lw_put_sockaddr.o \ +# lw_readelem_wtp_name.o \ + lw_readelem_wtp_board_data.o \ # LWAPP cisco vendor specific objs @@ -95,20 +96,17 @@ LWAPPCISCOOBJS = \ CAPWAPOBJS= \ - cwmsg_addelem_maximum_message_length.o \ - cwmsg_addelem_image_identifier.o \ cwmsg_send.o \ wtpinfo.o \ aciplist.o \ - acinfo.o \ acinfo_print.o \ lwmsg_init.o \ wtpinfo_lwreadelem_wtp_descriptor.o \ hdr_print.o \ cwmsg_addelem_vendor_cisco_mwar_addr.o \ - lw_readelem_wtp_board_data.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\ @@ -122,9 +120,12 @@ CAPWAPOBJS= \ cw_in_check_disc_resp.o\ cw_in_check_join_req.o \ cw_in_check_join_resp.o \ - cw_in_check_img_data_req.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_out_generic.o \ cw_out_ac_descriptor.o \ + cw_out_wtp_descriptor.o \ cw_out_cisco_ac_descriptor.o \ cw_out_cisco_ap_timesync.o \ cw_in_cisco_image_identifier.o\ @@ -137,12 +138,15 @@ CAPWAPOBJS= \ format.o \ + #acinfo.o \ # cwsend_unknow_response.o \ cw_send_configuration_update_response.o \ cwsend_echo_request.o \ cwmsg_init_echo_request.o \ cwmsg_addelem.o \ cwmsg_vaddelem.o \ + cw_log_str2dbglevel.o \ + cwmsg_addelem_maximum_message_length.o \ cwmsg_addelem_ac_descriptor.o \ cwmsg_addelem_wtp_descriptor.o \ cwmsg_addelem_cw_local_ip_addr.o \ @@ -157,6 +161,7 @@ cw_readelem_maximum_message_length.o \ cw_readelem_result_code.o\ cw_readelem_ac_name.o \ cw_readelem_ac_descriptor.o \ + conn_detect_capwap.o \ cw_readelem_radio_administrative_state.o \ cw_readelem_radio_operational_state.o \ cw_readelem_statistics_timer.o \ @@ -164,6 +169,7 @@ cw_readelem_maximum_message_length.o \ cw_readelem_vendor_specific_payload.o \ cw_readelem_capwap_local_ip_addr.o \ cw_readelem_wtp_reboot_statistics.o\ + cwmsg_addelem_image_identifier.o \ conn_get_response.o \ # cwsend_change_state_event_response.o \ cwread_discovery_response.o \ @@ -174,6 +180,7 @@ cw_readelem_maximum_message_length.o \ cwread_wtp_event_request.o \ process_conf_status_request.o \ cw_readelem_ecn_support.o \ + conn_wait_for_message.o \ # wtpinfo_readelem_wtp_mac_type.o \ # wtpinfo_readelem_wtp_descriptor.o \ @@ -251,7 +258,6 @@ endif DTLSOBJS+=dtls_bio.o CONNOBJS= conn_create.o \ - conn_detect_capwap.o \ conn_send_packet.o \ conn_process_packet.o \ conn_q_add_packet.o \ @@ -266,7 +272,6 @@ CONNOBJS= conn_create.o \ cw_prepare_configuration_status_request.o \ cw_prepare_change_state_event_request.o \ conn_prepare_request.o \ - conn_wait_for_message.o \ conn_init.o \ conn_send_msg.o #conn_get_message.o \ @@ -288,6 +293,7 @@ CWACTION=action.o \ cw_in_generic.o \ cw_in_wtp_descriptor.o \ cw_out_wtp_board_data.o \ + cw_out_image_data.o \ cipwap_actions_ac.o \ cipwap_strings_elem.o \ capwap_strings_result.o\ @@ -311,7 +317,7 @@ O:=$(OBJS); OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS)) CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -CFLAGS = -Wall -O3 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I/usr/local/include +#CFLAGS = -Wall -O3 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I/usr/local/include CFLAGS += $(GNUTLS_CFLAGS) \ -DWITH_CW_LOG \ diff --git a/src/capwap/action.c b/src/capwap/action.c index 1e3e9e66..0412f962 100644 --- a/src/capwap/action.c +++ b/src/capwap/action.c @@ -137,11 +137,12 @@ static int cw_action_out_cmp(const void *elem1, const void *elem2) */ void *cw_actionlist_add(struct avltree *t, void *a, size_t s) { + void *r = avltree_replace_data(t, a, sizeof(struct cw_action_in)); if (r) return r; - void *an = malloc(sizeof(struct cw_action_in)); + void *an = malloc(s); if (!an) return NULL; diff --git a/src/capwap/action.h b/src/capwap/action.h index e69ed35b..f36d11f2 100644 --- a/src/capwap/action.h +++ b/src/capwap/action.h @@ -78,7 +78,9 @@ struct cw_action_out{ struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a); uint8_t mand; uint8_t itemtype; + void *defval; + int xopt; }; @@ -99,7 +101,7 @@ struct cw_actiondef{ cw_strheap_t strmsg; cw_strheap_t strelem; - + }; diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index dd7d7f46..f3eca5b4 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -34,7 +34,7 @@ #include "conn.h" #include "lwapp.h" -#include "strheap.h" +#include "strlist.h" /* capwap version and iana number */ #define CW_VERSION 0 @@ -86,7 +86,7 @@ enum capwap_states { /** * CAWAP header flags. - */ + */ #define CW_FLAG_HDR_R1 0x01 /* bit 0 reserved 1 */ #define CW_FLAG_HDR_R2 0x02 /* bit 1 reserved 2 */ #define CW_FLAG_HDR_R3 0x04 /* bit 2 reserved 3 */ @@ -478,15 +478,15 @@ extern int cw_readelem_vendor_specific_payload(void *data, int msgtype, int elem 14 Image Data Error (Invalid Checksum) */ -#define CW_RESULT_IMAGE_DATA_IVALID_LENGTH 15 //Image Data Error (Invalid Data Length) +#define CW_RESULT_IMAGE_DATA_IVALID_LENGTH 15 //Image Data Error (Invalid Data Length) -#define CW_RESULT_IMAGE_DATA_OTHER_ERROR 16 //Image Data Error (Other Error) +#define CW_RESULT_IMAGE_DATA_ERROR 16 //Image Data Error (Other Error) /* 17 Image Data Error (Image Already Present) */ - -#define CW_RESULT_MSG_INVALID_IN_CURRENT_STATE 18 -#define CW_RESULT_MSG_UNRECOGNIZED 19 + +#define CW_RESULT_MSG_INVALID_IN_CURRENT_STATE 18 +#define CW_RESULT_MSG_UNRECOGNIZED 19 #define CW_RESULT_MISSING_MAND_ELEM 20 /* @@ -571,36 +571,39 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le * Set the HLEN field of a CAWAP Header * @param th pointer to the header * @param hlen velue to set (max. 5 bits) - */ -static inline void cw_set_hdr_hlen(uint8_t *th,int hlen){ + */ +static inline void cw_set_hdr_hlen(uint8_t * th, int hlen) +{ uint32_t d = cw_get_dword(th); d &= (0x1f << 19) ^ 0xffffffff; - d |= ((hlen) & 0x1f) <<19; - cw_set_dword(th,d); + d |= ((hlen) & 0x1f) << 19; + cw_set_dword(th, d); } /** * Set the WBID field of a CAWAP Header * @param th pointer to the header * @param hlen velue to set (max. 5 bits) - */ -static inline void cw_set_hdr_wbid(uint8_t *th,int wbid){ + */ +static inline void cw_set_hdr_wbid(uint8_t * th, int wbid) +{ uint32_t d = cw_get_dword(th); d &= (0x1f << 9) ^ 0xffffffff; - d |= ((wbid) & 0x1f) <<9; - cw_set_dword(th,d); + d |= ((wbid) & 0x1f) << 9; + cw_set_dword(th, d); } /** * Set the RID field of a CAWAP Header * @param th pointer to the header * @param hlen velue to set (max. 5 bits) - */ -static inline void cw_set_hdr_rid(uint8_t *th,int rid){ + */ +static inline void cw_set_hdr_rid(uint8_t * th, int rid) +{ uint32_t d = cw_get_dword(th); d &= (0x1f << 9) ^ 0xffffffff; - d |= ((rid) & 0x1f) <<14; - cw_set_dword(th,d); + d |= ((rid) & 0x1f) << 14; + cw_set_dword(th, d); } @@ -641,7 +644,7 @@ static inline uint8_t *cw_get_hdr_msg_elems_ptr(uint8_t * m) return cw_get_msg_elems_ptr(m + cw_get_hdr_msg_offset(m)); } -static inline uint8_t * cw_get_hdr_msg_ptr(uint8_t *rawmsg) +static inline uint8_t *cw_get_hdr_msg_ptr(uint8_t * rawmsg) { return rawmsg + cw_get_hdr_msg_offset(rawmsg); } @@ -654,7 +657,7 @@ static inline int cw_get_hdr_msg_total_len(uint8_t * rawmsg) { int offset = cw_get_hdr_msg_offset(rawmsg); - return offset + cw_get_msg_elems_len(rawmsg + offset)+8 ; + return offset + cw_get_msg_elems_len(rawmsg + offset) + 8; } /** @@ -855,16 +858,23 @@ extern struct cw_str capwap_strings_result[]; #define cw_strresult(id) cw_strlist_get_str(capwap_strings_result,(id)) -static inline const char * cw_strelemp_(cw_strheap_t h, int msg_id) { - const char * rc = cw_strheap_get(h,msg_id); +#define cw_strrc(rc) \ + ((rc)<0 ? ((rc)!=EAGAIN ? strerror(errno):"Timed out"): cw_strresult(rc)) + + + + + +static inline const char *cw_strelemp_(cw_strheap_t h, int msg_id) +{ + const char *rc = cw_strheap_get(h, msg_id); if (rc) return rc; - return cw_strheap_get(h,CW_STR_STOP); + return cw_strheap_get(h, CW_STR_STOP); } #define cw_strelemp(p,id) cw_strelemp_((p)->strelem,id) -extern const char *cw_strlist_get_str(struct cw_str *s, int id); @@ -882,22 +892,27 @@ extern int cw_in_wtp_board_data(struct conn *conn, struct cw_action_in *a, uint8 int len); extern int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len); -extern int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a, uint8_t * data, - int len); +extern int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a, + uint8_t * data, int len); //extern int cw_out_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len); -extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //, struct cw_item *item); +extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //, struct cw_item *item); //extern int cw_out_ac_descriptor(struct conn *conn, uint32_t elem_id, uint8_t * dst, //struct cw_item *item); -extern int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst); //,struct cw_item * item) +extern int cw_out_ac_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //,struct cw_item * item) +extern int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, + uint8_t * dst); + //extern int cw_out_capwap_control_ip_addrs(struct conn *conn, uint32_t elem_id, -// uint8_t * dst, struct cw_item *item); +// uint8_t * dst, struct cw_item *item); -extern int cw_out_capwap_control_ip_addr_list(struct conn *conn,struct cw_action_out *a,uint8_t *dst) ; +extern int cw_out_capwap_control_ip_addr_list(struct conn *conn, struct cw_action_out *a, + uint8_t * dst); extern int cw_put_msg(struct conn *conn, uint8_t * rawout); +int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst); // ,struct cw_item * item) struct cw_ac_status { @@ -918,23 +933,25 @@ struct cw_ac_status { * This function is only useful (used) in conjunction with * putting AC Descriptor message elements. */ -static inline int cw_put_ac_status(uint8_t *dst, struct cw_ac_status *s){ - uint8_t *d=dst; +static inline int cw_put_ac_status(uint8_t * dst, struct cw_ac_status *s) +{ + uint8_t *d = dst; - d += cw_put_dword (d, (s->stations << 16) | (s->limit) ); - d += cw_put_dword (d, (s->active_wtps <<16) | (s->max_wtps) ); - d += cw_put_dword (d, (s->security<<24) | (s->rmac_field<<16) | (s->dtls_policy)); - return d-dst; + d += cw_put_dword(d, (s->stations << 16) | (s->limit)); + d += cw_put_dword(d, (s->active_wtps << 16) | (s->max_wtps)); + d += cw_put_dword(d, + (s->security << 24) | (s->rmac_field << 16) | (s->dtls_policy)); + return d - dst; } -static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint8_t *v) +static inline int cw_put_version(uint8_t * dst, uint16_t subelem_id, uint8_t * v) { - uint8_t *d=dst; - d += cw_put_dword(d,vendorstr_get_vendor_id(v)); - d += cw_put_dword(d, (subelem_id<<16) | vendorstr_len(v)); - d += cw_put_data(d,vendorstr_data(v),vendorstr_len(v)); - return d-dst; + uint8_t *d = dst; + d += cw_put_dword(d, vendorstr_get_vendor_id(v)); + d += cw_put_dword(d, (subelem_id << 16) | vendorstr_len(v)); + d += cw_put_data(d, vendorstr_data(v), vendorstr_len(v)); + return d - dst; } @@ -944,53 +961,36 @@ int cw_register_actions_cipwap_ac(struct cw_actiondef *def); int cw_register_actions_capwap_wtp(struct cw_actiondef *def); -int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len); +int cw_in_set_state_none(struct conn *conn, struct cw_action_in *a, uint8_t * data, + int len); struct cw_item *cw_out_get_outgoing(struct conn *conn, struct cw_action_out *a); struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a); -extern int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data, - int len); +extern int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a, + uint8_t * data, int len); -extern int cw_in_check_disc_req(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len); +extern int cw_in_check_disc_req(struct conn *conn, struct cw_action_in *a, uint8_t * data, + int len); int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data, + int len); + +int cw_check_missing_mand(cw_action_in_t ** out, struct conn *conn, cw_action_in_t * a); +int cw_in_check_join_req(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len); +extern int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, + uint8_t * data, int len); +extern int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, + uint8_t * data, int len); +int cw_in_check_img_data_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data, + int len); -int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_in_t *a); -int cw_in_check_join_req(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len); -int cw_in_check_img_data_req(struct conn *conn, struct cw_action_in *a, uint8_t * data, - int len); +int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst); -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); +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); -/** - * @defgroup TimerFunctions Timer functions - * @{ - */ - -/** - * Start a timer. - * @param t number of seconds until the timer expires - * @return timer value to initialize a variable of time_t - * - * Example: time_t timer = cw_timer_start(60); - */ -#define cw_timer_start(t) (time(NULL)+t) - -/** - * Check if a timer is expired. - * @param t an time_t variable intializes by #cw_timer_start - * @return 0=timer is not expired\n 1=timer is expired. - */ -#define cw_timer_timeout(t) (time(NULL)>t ? 1 : 0) - -/** @} */ - - -int cw_send_request(struct conn *conn,int msg_id); +int cw_send_request(struct conn *conn, int msg_id); #endif diff --git a/src/capwap/capwap_action_helpers.c b/src/capwap/capwap_action_helpers.c index 627982d0..e792a34d 100644 --- a/src/capwap/capwap_action_helpers.c +++ b/src/capwap/capwap_action_helpers.c @@ -37,15 +37,12 @@ struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a) 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); + return cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,16); } diff --git a/src/capwap/capwap_actions_ac.c b/src/capwap/capwap_actions_ac.c index 3d3e5d83..8858368d 100644 --- a/src/capwap/capwap_actions_ac.c +++ b/src/capwap/capwap_actions_ac.c @@ -127,13 +127,26 @@ cw_action_in_t capwap_actions_ac_in[] = { /* Message: Image Data Request - in Config State */ {0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST, 0, - 0, cw_in_check_img_data_req} + 0, cw_in_check_img_data_req_ac} , {0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST, CW_ACTION_IN_IMAGE_IDENTIFIER, 0} , + /* ------------------------------------------------------------------------------- */ + + /* Message Image Data Response IN */ + {0, 0, CW_STATE_IMAGE_DATA, CW_MSG_IMAGE_DATA_RESPONSE, 0, + 0, cw_in_check_img_data_resp } + , + + /* Element: Result Code */ + {0, 0, CW_STATE_IMAGE_DATA, CW_MSG_IMAGE_DATA_RESPONSE, + CW_ACTION_IN_RESULT_CODE, 1} + + , + @@ -198,6 +211,21 @@ cw_action_out_t capwap_actions_ac_out[] = { , + /* ------------------------------------------------------------------------------- + * Image Data Request OUT + */ + + {CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_NONE} + , + /* Image Data */ + {CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_IMAGE_FILEHANDLE, 0, + CW_ELEM_IMAGE_DATA, NULL,cw_out_image_data, cw_out_get_outgoing,0} + , + + + + + /* End of list */ {0, 0} @@ -224,7 +252,6 @@ int cw_register_actions_capwap_ac(struct cw_actiondef *def) rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem); - printf("Registered %d strings\n", rc); return 1; } diff --git a/src/capwap/capwap_actions_wtp.c b/src/capwap/capwap_actions_wtp.c index 1e88a3e4..be9e46be 100644 --- a/src/capwap/capwap_actions_wtp.c +++ b/src/capwap/capwap_actions_wtp.c @@ -68,6 +68,26 @@ cw_action_in_t capwap_actions_wtp_in[] = { CW_ACTION_IN_RESULT_CODE, 1} , + /* ------------------------------------------------------------------------------- */ + + /* Message Image Data Response */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_RESPONSE, 0, + 0, cw_in_check_img_data_resp } + , + + /* Element: Result Code */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_RESPONSE, + CW_ACTION_IN_RESULT_CODE, 1} + + , + + /* ------------------------------------------------------------------------------- */ + + /* Message Image Data Request */ + {0, 0, CW_STATE_IMAGE_DATA, CW_MSG_IMAGE_DATA_REQUEST, 0, + 0, cw_in_check_img_data_req_wtp } + , + @@ -113,21 +133,60 @@ cw_action_out_t capwap_actions_wtp_out[] = { /* 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} + CW_ELEM_WTP_BOARD_DATA, NULL,cw_out_wtp_board_data, cw_out_get_outgoing,1} , - + /* WTP Descriptor */ + {CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_DESCRIPTOR, 0, + CW_ELEM_WTP_DESCRIPTOR, NULL,cw_out_wtp_descriptor, NULL,1} + , + /* WTP Name */ {CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_NAME, 0, CW_ELEM_WTP_NAME, NULL,cw_out_generic, cw_out_get_local,1} , + /* WTP MAC Type */ + {CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_MAC_TYPE, 0, + CW_ELEM_WTP_MAC_TYPE, NULL,cw_out_generic, cw_out_get_local,1} + , + + /* WTP MAC Type */ + {CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_FRAME_TUNNEL_MODE, 0, + CW_ELEM_WTP_FRAME_TUNNEL_MODE, 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} , + + /* ------------------------------------------------------------------------------- + * Image Data Request OUT + */ + + {CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_NONE} + , + /* Image Identifier */ + {CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_IMAGE_IDENTIFIER, 0, + CW_ELEM_IMAGE_IDENTIFIER, NULL,cw_out_generic, cw_out_get_outgoing,0} + , + + + /* ------------------------------------------------------------------------------- + * Image Data Response OUT + */ + {CW_MSG_IMAGE_DATA_RESPONSE, CW_ITEM_NONE} + , + + /* Result Code */ + {CW_MSG_IMAGE_DATA_RESPONSE, CW_ITEM_RESULT_CODE, 0, + CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1} + , + + + {0, 0} }; @@ -151,7 +210,6 @@ int cw_register_actions_capwap_wtp(struct cw_actiondef *def) rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem); - printf("Registered %d strings\n", rc); return 1; } diff --git a/src/capwap/capwap_items.h b/src/capwap/capwap_items.h index 906b2a6a..e245620d 100644 --- a/src/capwap/capwap_items.h +++ b/src/capwap/capwap_items.h @@ -53,9 +53,10 @@ enum capwap_items { /* Other Items */ CW_ITEM_AC_IMAGE_DIR, /* Path where WTP images are stored */ - CW_ITEM_WTP_IMAGE_FILENAME, /* Full path of image filename */ + CW_ITEM_IMAGE_FILENAME, /* Full path of image filename */ CW_ITEM_DISCOVERIES, - CW_ITEM_AC_PRIO_LIST /* AC Name with Priority list */ + CW_ITEM_AC_PRIO_LIST, /* AC Name with Priority list */ + CW_ITEM_IMAGE_FILEHANDLE /* FILE handle for uploading and downloading images */ }; diff --git a/src/capwap/capwap_strings_result.c b/src/capwap/capwap_strings_result.c index 2af810e6..19bf81bc 100644 --- a/src/capwap/capwap_strings_result.c +++ b/src/capwap/capwap_strings_result.c @@ -6,6 +6,7 @@ struct cw_str capwap_strings_result[] = { {CW_RESULT_SUCCESS,"Success"}, /* 0 */ {CW_RESULT_MISSING_AC_LIST,"AC List Message Element MUST be Present"}, /* 1 */ {CW_RESULT_SUCCESS_NAT,"Success - NAT Detected"}, /* 2 */ + {CW_RESULT_IMAGE_DATA_ERROR,"Image Data Error (Unspecified)"}, /* 16 */ {CW_RESULT_MISSING_MAND_ELEM,"Missing Mandatory Message Element"}, /* 20 */ {CW_STR_STOP,"Unknown Result Code"} diff --git a/src/capwap/capwap_strings_state.c b/src/capwap/capwap_strings_state.c index 51f8ca42..cdaad00a 100644 --- a/src/capwap/capwap_strings_state.c +++ b/src/capwap/capwap_strings_state.c @@ -5,6 +5,7 @@ struct cw_str capwap_strings_state[] = { { CW_STATE_JOIN,"Join" }, { CW_STATE_RUN,"Run" }, { CW_STATE_CONFIGURE,"Configure" }, -{ CW_STR_STOP,"Undefined" } +{ CW_STATE_IMAGE_DATA,"Image Data" }, +{ CW_STR_STOP,"Undefined" }, }; diff --git a/src/capwap/conn_process_packet.c b/src/capwap/conn_process_packet.c index 1268cdfb..2f9fe1c4 100644 --- a/src/capwap/conn_process_packet.c +++ b/src/capwap/conn_process_packet.c @@ -173,7 +173,8 @@ static int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) "Message type %d (%s) unexpected/illigal in %s State, discarding.", as.msg_id, cw_strmsg(as.msg_id), cw_strstate(conn->capwap_state)); - return 0; + errno=EAGAIN; + return -1; } /* Request message not found in current state, check if we know @@ -339,65 +340,61 @@ static int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen, -//int conn_process_packet(struct conn *conn, uint8_t * packet, int len, -// int (*cb) (void *, uint8_t *, int), void *cbarg) int conn_process_packet(struct conn *conn, uint8_t * packet, int len) { + /* log this packet */ + cw_dbg_pkt(DBG_PKT_IN,conn, packet, len); + if (len < 8) { /* packet too short */ - cw_dbg(DBG_CW_PKT_ERR, + cw_dbg(DBG_PKT_ERR, "Discarding packet from %s, packet too short, len=%d", sock_addr2str(&conn->addr), len); - return 0; + errno = EAGAIN; + return -1; } int preamble = cw_get_hdr_preamble(packet); if ((preamble & 0xf0) != CW_VERSION) { /* wrong version */ - cw_dbg(DBG_CW_PKT_ERR, + cw_dbg(DBG_PKT_ERR, "Discarding packet from %s, wrong version, version=%d", sock_addr2str(&conn->addr), (preamble & 0xf0) >> 8); - return 0; + errno=EAGAIN; + return -1; } if (preamble & 0xf) { - /* decode dtls */ - return 0; + /* dtls encoded, this shuold never happen here */ + cw_dbg(DBG_PKT_ERR, + "Discarding packet from %s, encrypted data, after encryption ...", + sock_addr2str(&conn->addr)); + errno = EAGAIN; + return -1; } - /* log this packet */ - cw_dbg_packet(conn, packet, len); - int offs = cw_get_hdr_msg_offset(packet); int payloadlen = len - offs; if (payloadlen < 0) { - cw_dbg(DBG_CW_PKT_ERR, + cw_dbg(DBG_PKT_ERR, "Discarding packet from %s, header length greater than len, hlen=%d", sock_addr2str(&conn->addr), offs); /* EINVAL */ return 0; } -/* - struct cwrmsg cwrmsg; - cwrmsg.wbid=(val>>9) & 0x1f; - cwrmsg.rid=(val>>14) & 0x1f; -*/ - -//printf ("Offs is %d RML is %d\n",offs,cw_get_hdr_rmac_len(packet)); - /* Check Radio MAC if preset */ if (cw_get_hdr_flag_m(packet)) { if (cw_get_hdr_rmac_len(packet) + 8 > offs) { /* wrong rmac size */ - cw_dbg(DBG_CW_PKT_ERR, + cw_dbg(DBG_PKT_ERR, "Discarding packet, wrong R-MAC size, size=%d", *(packet + 8)); return 0; @@ -415,7 +412,7 @@ int conn_process_packet(struct conn *conn, uint8_t * packet, int len) if (f == NULL) return 0; - cw_dbg_packet(conn, f + 4, *(uint32_t *) f); +// cw_dbg_packet(conn, f + 4, *(uint32_t *) f); // extern int cw_process_msg(struct conn * conn,uint8_t*msg,int len); @@ -445,6 +442,9 @@ int conn_process_packet(struct conn *conn, uint8_t * packet, int len) //} //msg_4*((val >> 19) & 0x1f); + + cw_dbg_msg(DBG_MSG_IN,conn,packet,len); + return process_message(conn, packet, len, NULL,NULL); } @@ -462,7 +462,7 @@ int cw_read_messages(struct conn *conn) return n; if (n > 0) { - printf("Have a packet with %d bytes\n",n); +// printf("Have a packet with %d bytes\n",n); return conn_process_packet(conn, buf, n); } //printf("DTLS_ERROR: %d\n",conn->dtls_error); diff --git a/src/capwap/conn_q_add_packet.c b/src/capwap/conn_q_add_packet.c index 996ad29b..319004d4 100644 --- a/src/capwap/conn_q_add_packet.c +++ b/src/capwap/conn_q_add_packet.c @@ -19,8 +19,9 @@ #include #include -#include "log.h" +#include "dbg.h" #include "conn.h" +#include "sock.h" void conn_q_add_packet(struct conn * conn,uint8_t *packet,int len) @@ -31,7 +32,8 @@ void conn_q_add_packet(struct conn * conn,uint8_t *packet,int len) if (conn->qrpos==qwpos){ /* no buffers, discard packet */ - cw_dbg(DBG_CW_PKT_ERR, "Discarding packet, no queue buffers left"); + cw_dbg(DBG_PKT_ERR, "Discarding packe from %s, no queue buffers left", + sock_addr2str(&conn->addr)); return; } diff --git a/src/capwap/conn_send_msg.c b/src/capwap/conn_send_msg.c index bf8ca231..22802a2c 100644 --- a/src/capwap/conn_send_msg.c +++ b/src/capwap/conn_send_msg.c @@ -1,7 +1,7 @@ #include "conn.h" #include "capwap.h" -#include "log.h" +#include "dbg.h" #include "sock.h" @@ -10,7 +10,7 @@ int conn_send_msg(struct conn * conn, uint8_t *rawmsg) int packetlen = cw_get_hdr_msg_total_len(rawmsg); - uint8_t * msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg); + //uint8_t * msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg); /* Zyxel doesn't count msg element length from @@ -34,12 +34,13 @@ int conn_send_msg(struct conn * conn, uint8_t *rawmsg) cw_put_dword(ptr+4, conn->fragid<<16 | fragoffset<<3 ); + //XXX { char h[200]; hdr_print(h,ptr,mtu); - cw_dbg(DBG_CW_PKT_OUT,"Sending capwap packet to %s:\n%s",sock_addr2str(&conn->addr),h); + cw_dbg(DBG_PKT_OUT,"Sending capwap packet to %s:\n%s",sock_addr2str(&conn->addr),h); } - cw_dbg_dmp(DBG_CW_PKT_DMP,ptr,mtu,"Sending packet ..."); + cw_dbg_dmp(DBG_PKT_DMP,ptr,mtu,"Sending packet ..."); if (conn->write(conn,ptr,mtu)<0) @@ -86,12 +87,12 @@ int conn_send_msg(struct conn * conn, uint8_t *rawmsg) } - cw_dbg_dmp(DBG_CW_PKT_DMP,ptr,packetlen,"Sending packet ..."); + cw_dbg_dmp(DBG_PKT_DMP,ptr,packetlen,"Sending packet ..."); //return conn->write(conn,ptr,msglen-fragoffset*8+hlen); -printf("Send packet len %p %d\n",ptr,packetlen); +//printf("Send packet len %p %d\n",ptr,packetlen); return conn->write(conn,ptr,packetlen); } diff --git a/src/capwap/cw_check_missing_mand.c b/src/capwap/cw_check_missing_mand.c index fbefdc7e..0b6990e2 100644 --- a/src/capwap/cw_check_missing_mand.c +++ b/src/capwap/cw_check_missing_mand.c @@ -9,7 +9,7 @@ struct args { struct avltree *mand; int n; }; - +/* static int check_mand_cb(void *priv, void *val) { @@ -47,7 +47,7 @@ return 1; return 1; } - +*/ int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_in_t *a) { diff --git a/src/capwap/cw_foreach_msgelem.c b/src/capwap/cw_foreach_msgelem.c index 3240ed9b..24cd9272 100644 --- a/src/capwap/cw_foreach_msgelem.c +++ b/src/capwap/cw_foreach_msgelem.c @@ -40,10 +40,11 @@ int cw_foreach_msgelem(uint8_t * msgelems, int len, elen = val & 0xffff; if (i + elen + 4 > len) { +/* printf("***************************************************************************\n"); printf("Type: %d\n",type); printf("Bumm %d %d\n",i+elen+4,len); - +*/ return 0; } diff --git a/src/capwap/cw_in_check_disc_req.c b/src/capwap/cw_in_check_disc_req.c index 156b7e54..82818dbd 100644 --- a/src/capwap/cw_in_check_disc_req.c +++ b/src/capwap/cw_in_check_disc_req.c @@ -20,7 +20,7 @@ int cw_in_check_disc_req(struct conn *conn, struct cw_action_in *a, uint8_t * da /* if mandatory elements are missing send no discovery response */ if (n) { - cw_dbg(DBG_CW_INFO, + cw_dbg(DBG_MSG_ERR, "Ignoring Discovery Request from %s - missing mandatory elements.", sock_addr2str(&conn->addr)); return -1; diff --git a/src/capwap/cw_in_check_disc_resp.c b/src/capwap/cw_in_check_disc_resp.c index de48e518..2c503f3f 100644 --- a/src/capwap/cw_in_check_disc_resp.c +++ b/src/capwap/cw_in_check_disc_resp.c @@ -13,12 +13,12 @@ int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * d int n = cw_check_missing_mand(mlist, conn, a); cw_dbg_missing_mand(DBG_ELEM, conn, mlist, n, a); - cw_dbg(DBG_CW_INFO,"This response came from: %s\n",sock_addr2str(&conn->addr)); + //cw_dbg(DBG_INFO,"This response came from: %s",sock_addr2str(&conn->addr)); /* if mandatory elements are missing, ignore this response */ if (n) { - cw_dbg(DBG_CW_INFO, + cw_dbg(DBG_MSG_ERR, "Ignoring Discovery Response from %s - missing mandatory elements.", sock_addr2str(&conn->addr)); return -1; diff --git a/src/capwap/cw_in_check_img_data_req.c b/src/capwap/cw_in_check_img_data_req_ac.c similarity index 61% rename from src/capwap/cw_in_check_img_data_req.c rename to src/capwap/cw_in_check_img_data_req_ac.c index aaa15ab1..cfa81cba 100644 --- a/src/capwap/cw_in_check_img_data_req.c +++ b/src/capwap/cw_in_check_img_data_req_ac.c @@ -7,7 +7,7 @@ #include "capwap_items.h" -int cw_in_check_img_data_req(struct conn *conn, struct cw_action_in *a, uint8_t * data, +int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len) { /* Check for mandatory elements */ @@ -25,11 +25,13 @@ int cw_in_check_img_data_req(struct conn *conn, struct cw_action_in *a, uint8_t uint32_t vendor_id = vendorstr_get_vendor_id(i->data); const char * image_dir; - //XXX image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR); + image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR); + if ( !image_dir ) + image_dir="./img/"; //XXX char * image_filename = malloc(6+vendorstr_len(i->data)+1+strlen(image_dir)); if (!image_filename) - return CW_RESULT_IMAGE_DATA_OTHER_ERROR; + return CW_RESULT_IMAGE_DATA_ERROR; sprintf(image_filename,"%s%04X/%s",image_dir,vendor_id,vendorstr_data(i->data)); @@ -39,21 +41,17 @@ int cw_in_check_img_data_req(struct conn *conn, struct cw_action_in *a, uint8_t cw_log(LOG_WARNING,"Can't open image file: %s - %s - requestet by WTP", image_filename,strerror(errno)); free(image_filename); - return CW_RESULT_IMAGE_DATA_OTHER_ERROR; + return CW_RESULT_IMAGE_DATA_ERROR; } - cw_itemstore_set_str(conn->outgoing,CW_ITEM_WTP_IMAGE_FILENAME,image_filename); - + cw_itemstore_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename); + cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0); + conn->capwap_state=CW_STATE_IMAGE_DATA; + return 0; } - /* set result code to ok and change to configure state */ -// cw_itemstore_set_dword(conn->local,CW_ITEM_RESULT_CODE,0); -// conn->capwap_state = CW_STATE_CONFIGURE; - cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0); - conn->capwap_state=CW_STATE_IMAGE_DATA; - - return 0; + return CW_RESULT_IMAGE_DATA_ERROR; } diff --git a/src/capwap/cw_in_check_join_req.c b/src/capwap/cw_in_check_join_req.c index 048fe26f..d24d6083 100644 --- a/src/capwap/cw_in_check_join_req.c +++ b/src/capwap/cw_in_check_join_req.c @@ -9,8 +9,6 @@ int cw_in_check_join_req(struct conn *conn, struct cw_action_in *a, uint8_t * da int len) { - printf("join req checker\n"); - cw_action_in_t * mlist[60]; /* Check for mandatory elements */ diff --git a/src/capwap/cw_in_cisco_image_identifier.c b/src/capwap/cw_in_cisco_image_identifier.c index 655c2dcb..b055bbd8 100644 --- a/src/capwap/cw_in_cisco_image_identifier.c +++ b/src/capwap/cw_in_cisco_image_identifier.c @@ -1,6 +1,6 @@ #include "action.h" -#include "log.h" +#include "dbg.h" #include "itemstore.h" #include "capwap.h" diff --git a/src/capwap/cw_in_generic.c b/src/capwap/cw_in_generic.c index 3a01bcc0..9f6787fd 100644 --- a/src/capwap/cw_in_generic.c +++ b/src/capwap/cw_in_generic.c @@ -1,6 +1,6 @@ #include "action.h" -#include "log.h" +#include "dbg.h" #include "itemstore.h" #include "capwap.h" diff --git a/src/capwap/cw_in_vendor_specific_payload.c b/src/capwap/cw_in_vendor_specific_payload.c index 9786a6a4..ff38c6bf 100644 --- a/src/capwap/cw_in_vendor_specific_payload.c +++ b/src/capwap/cw_in_vendor_specific_payload.c @@ -1,5 +1,6 @@ #include "capwap.h" +#include "dbg.h" #include "log.h" #include "sock.h" //Tube /** @@ -20,10 +21,10 @@ int cw_in_vendor_specific_payload(struct conn *conn,struct cw_action_in * a,uint af = cw_actionlist_in_get(conn->actions->in,&as); -cw_dbg(DBG_ELEM,"From might be: %s\n",sock_addr2str(&conn->addr)); +//cw_dbg(DBG_ELEM,"From might be: %s\n",sock_addr2str(&conn->addr)); if (!af) { - cw_log(DBG_ELEM,"Can't handle Vendor Specific Payload %s/%d, in msg %d (%s) in %s state.", + cw_dbg(DBG_ELEM,"Can't handle Vendor Specific Payload %s/%d, in msg %d (%s) in %s state.", cw_strvendor(as.vendor_id), as.elem_id,as.msg_id,cw_strmsg(as.msg_id),cw_strstate(as.capwap_state)); return 0; diff --git a/src/capwap/cw_in_wtp_board_data.c b/src/capwap/cw_in_wtp_board_data.c index 5cfd429a..f5ef673d 100644 --- a/src/capwap/cw_in_wtp_board_data.c +++ b/src/capwap/cw_in_wtp_board_data.c @@ -29,7 +29,7 @@ #include "itemstore.h" #include "cw_util.h" -#include "log.h" +#include "dbg.h" diff --git a/src/capwap/cw_in_wtp_descriptor.c b/src/capwap/cw_in_wtp_descriptor.c index c3e316ab..7489aab0 100644 --- a/src/capwap/cw_in_wtp_descriptor.c +++ b/src/capwap/cw_in_wtp_descriptor.c @@ -23,7 +23,7 @@ #include "wtpinfo.h" #include "cw_util.h" -#include "log.h" +#include "dbg.h" @@ -43,7 +43,7 @@ static int readelem_wtp_descriptor(struct conn *conn, struct cw_action_in *a, ui int i; if (ncrypt == 0 ){ /* non-conform */ - cw_dbg(DBG_CW_RFC,"Non-standard-conform WTP descriptor detected (See RFC 5415)"); + cw_dbg(DBG_RFC,"Non-standard-conform WTP descriptor detected (See RFC 5415)"); if (!cq) i=3; else @@ -102,7 +102,7 @@ int cw_in_wtp_descriptor(struct conn *conn,struct cw_action_in * a,uint8_t *data { int rc =readelem_wtp_descriptor(conn, a,data,len,0); if (rc==-1){ - cw_dbg(DBG_CW_RFC,"Bad WTP descriptor, trying cisco hack"); + cw_dbg(DBG_RFC,"Bad WTP descriptor, trying cisco hack"); rc =readelem_wtp_descriptor(conn, a,data,len,1); } diff --git a/src/capwap/cw_log_debug.c b/src/capwap/cw_log_debug.c index 44ccd03c..0eb03f9a 100644 --- a/src/capwap/cw_log_debug.c +++ b/src/capwap/cw_log_debug.c @@ -34,10 +34,7 @@ #include "cw_util.h" - -int cw_dbg_opt_detail = 0; -int cw_dbg_opt_level = 0; - +#include "dbg.h" int cw_log_debug_level = 0; @@ -56,7 +53,7 @@ void cw_log_dbg_(int level, const char *file, int line, const char *format, ...) vsprintf(buf, format, args); va_end(args); - if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS) + if (cw_dbg_opt_display & DBG_DISP_LINE_NUMBERS) cw_log(LOG_DEBUG, "%s:%d: %s", file, line, buf); else cw_log(LOG_DEBUG, buf); diff --git a/src/capwap/cw_out_ac_descriptor.c b/src/capwap/cw_out_ac_descriptor.c index 54880376..5b6ad966 100644 --- a/src/capwap/cw_out_ac_descriptor.c +++ b/src/capwap/cw_out_ac_descriptor.c @@ -36,12 +36,11 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst i = cw_itemstore_get(conn->outgoing,CW_ITEM_AC_HARDWARE_VERSION); - if ( i ) { d += cw_put_version(d,CW_SUBELEM_AC_HARDWARE_VERSION,i->data); } else { - cw_dbg(DBG_ELEM_ERR, "Can't send hard version in AC descriptor, not set."); + cw_log(LOG_ERR, "Can't send hard version in AC descriptor, not set."); } @@ -51,7 +50,7 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,i->data); } else { - cw_dbg(DBG_ELEM_ERR, "Can't send software version in AC descriptor, not set."); + cw_log(LOG_ERR, "Can't send software version in AC descriptor, not set."); } int len = d-dst-4; diff --git a/src/capwap/cw_out_cisco_ac_descriptor.c b/src/capwap/cw_out_cisco_ac_descriptor.c index e2c13049..fc5cb8e5 100644 --- a/src/capwap/cw_out_cisco_ac_descriptor.c +++ b/src/capwap/cw_out_cisco_ac_descriptor.c @@ -27,7 +27,7 @@ int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_ d += cw_put_version(d,1,i->data); } else { - cw_dbg(DBG_ELEM_ERR, "Can't send software version in AC descriptor, not set."); + cw_log(LOG_ERR, "Can't set Software Version in AC descriptor, No value defined."); } int len = d-dst-4; diff --git a/src/capwap/cw_out_generic.c b/src/capwap/cw_out_generic.c index f295a8ce..a79e130f 100644 --- a/src/capwap/cw_out_generic.c +++ b/src/capwap/cw_out_generic.c @@ -4,6 +4,7 @@ #include "capwap.h" #include "capwap_items.h" +#include "dbg.h" #include "log.h" @@ -19,8 +20,17 @@ int cw_put_item(uint8_t * dst, struct cw_item *item) case CW_ITEMTYPE_DWORD: return cw_put_dword(dst, item->dword); case CW_ITEMTYPE_BSTR: - return cw_put_bstr(dst,item->data); - + return cw_put_bstr(dst, item->data); + case CW_ITEMTYPE_VENDORSTR: + { + int l=0; + l+=cw_put_dword(dst, vendorstr_get_vendor_id(item->data)); + l+=cw_put_data(dst+4, vendorstr_data(item->data),vendorstr_len(item->data)); + return l; + } + default: + cw_log(LOG_ERR,"No method to put items of type %d",item->type); + } return 0; @@ -45,8 +55,17 @@ int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // int len; if (!item) { if (a->mand) { - cw_log(LOG_ERR, "Error: Cannot send mandatory message element %d - (%s)", - a->elem_id, cw_strelemp(conn->actions, a->elem_id)); + cw_log(LOG_ERR, + "Can't put mandatory element %d - (%s) into %s. No value found.", + a->elem_id, cw_strelemp(conn->actions, a->elem_id) + , cw_strmsg(a->msg_id) + ); + } + else{ + cw_dbg(DBG_ELEM,"No output for elemnt %d -(%s) in %s. Item %d not found.", + a->elem_id, cw_strelemp(conn->actions, a->elem_id) + , cw_strmsg(a->msg_id),a->item_id); + } return 0; } else { diff --git a/src/capwap/cw_out_wtp_board_data.c b/src/capwap/cw_out_wtp_board_data.c index 2ce30a47..96782522 100644 --- a/src/capwap/cw_out_wtp_board_data.c +++ b/src/capwap/cw_out_wtp_board_data.c @@ -64,7 +64,7 @@ int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t * d += cw_put_data(d, bstr_data(i->data), bstr_len(i->data)); } - int l = d - dst; - return l + cw_put_elem_hdr(dst, CW_ELEM_WTP_BOARD_DATA, l - 4); + int l = d - dst-4; + return l + cw_put_elem_hdr(dst, CW_ELEM_WTP_BOARD_DATA, l ); } diff --git a/src/capwap/cw_put_msg.c b/src/capwap/cw_put_msg.c index 1e49f87b..b05f8915 100644 --- a/src/capwap/cw_put_msg.c +++ b/src/capwap/cw_put_msg.c @@ -26,6 +26,7 @@ #include "conn.h" #include "log.h" +#include "dbg.h" /** @@ -66,21 +67,37 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout) int len = 0; while(NULL != (ae=avliter_next(&i))) { - printf("Put %d %d\n",ae->msg_id,ae->elem_id); + //printf("Put %d %d\n",ae->msg_id,ae->elem_id); if (ae->msg_id != as.msg_id) { /* Element is from next msg, close action */ break; } - if (ae->out) { - len += ae->out(conn, ae, dst+len); + int l=0; + l= ae->out(conn, ae, dst+len); + len +=l; +// cw_dbg_elem_colored(DBG_ELEM, conn, ae->msg_id, ae->elem_id, +// dst+len-l,l); + } + +//cw_dbg_elem_colored(DBG_ELEM,"Adding element %d to msg %d, len = %d",ae->msg_id,ae->elem_id,l); }; cw_set_msg_elems_len(msgptr, len); + + if (as.msg_id) { + /* It's a request, so we have to set seqnum */ + int s = conn_get_next_seqnum(conn); + cw_set_msg_seqnum(msgptr,s); +// printf("Set seqnum to : %d\n",s); + + } + + return len; } diff --git a/src/capwap/cw_send_image_file.c b/src/capwap/cw_send_image_file.c index 86e770f4..3e45bbf6 100644 --- a/src/capwap/cw_send_image_file.c +++ b/src/capwap/cw_send_image_file.c @@ -38,7 +38,7 @@ * Send an image file to an AP * */ -void cw_send_image_file(struct conn *conn, FILE *infile) +void cw_send_image_file(struct conn *conn) { /* @@ -53,8 +53,14 @@ void cw_send_image_file(struct conn *conn, FILE *infile) cw_log(LOG_INFO, "Sending image file %s to %s", filename, sock_addr2str(&conn->addr)); */ - struct cwrmsg *cwrmsg; + + + + + uint8_t buffer[1024]; /* buffer MUST be 1024 */ + + struct cwimage_data data; memset(&data,0,sizeof(struct cwimage_data)); data.data = buffer; @@ -82,8 +88,8 @@ void cw_send_image_file(struct conn *conn, FILE *infile) bl++; - conn_prepare_image_data_request(conn, &data, 0); - cwrmsg = conn_send_request(conn); + // 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)); diff --git a/src/capwap/cw_strlist_get_str.c b/src/capwap/cw_strlist_get_str.c index 960bfdb6..83239b0a 100644 --- a/src/capwap/cw_strlist_get_str.c +++ b/src/capwap/cw_strlist_get_str.c @@ -1,4 +1,5 @@ -#include "capwap.h" + +#include "strlist.h" const char * cw_strlist_get_str(struct cw_str *s,int id) { diff --git a/src/capwap/cw_util.c b/src/capwap/cw_util.c index 1b2b55d7..13a74d89 100644 --- a/src/capwap/cw_util.c +++ b/src/capwap/cw_util.c @@ -23,6 +23,7 @@ #include "log.h" #include "capwap.h" +/* void cw_mand_elem_found(int *l,int type) { if (!cw_dbg_is_level(DBG_CW_RFC)) @@ -37,7 +38,9 @@ void cw_mand_elem_found(int *l,int type) } } +*/ +/* void cw_get_missing_mand_elems(char *dst, int *l) { if (!cw_dbg_is_level(DBG_CW_RFC)) @@ -54,6 +57,7 @@ void cw_get_missing_mand_elems(char *dst, int *l) } } +*/ /* int cw_is_missing_mand_elems(int *l) diff --git a/src/capwap/dbg.c b/src/capwap/dbg.c index 6720f9a6..d40dbb3c 100644 --- a/src/capwap/dbg.c +++ b/src/capwap/dbg.c @@ -21,31 +21,133 @@ #include "sock.h" #include "log.h" +#include "strlist.h" +#include "format.h" +#include "capwap.h" + + +void (*cw_dbg_cb) (int level, const char *format, ...) = CW_LOG_DEFAULT_LOG; +void (*cw_dbg_vcb) (int level, const char *fromat, va_list args) = CW_LOG_DEFAULT_VLOG; + + + +uint32_t cw_dbg_opt_display = 0; +uint32_t cw_dbg_opt_level = 0; + + /** * Put a list of missing mandatory message elements to debug output */ -void cw_dbg_missing_mand(int level,struct conn *conn,cw_action_in_t ** ml,int n,cw_action_in_t *a) +void cw_dbg_missing_mand(int level, struct conn *conn, cw_action_in_t ** ml, int n, + cw_action_in_t * a) { - if (!cw_dbg_is_level(DBG_ELEM) || n==0) + if (!cw_dbg_is_level(DBG_ELEM) || n == 0) return; char buffer[2000]; - char *p=buffer; + char *p = buffer; int i; - char *delim=""; - for(i=0; iactions,ml[i]->elem_id)); + char *delim = ""; + for (i = 0; i < n; i++) { + p += sprintf(p, "%s", delim); + delim = ", "; + p += sprintf(p, "%s", cw_strelemp(conn->actions, ml[i]->elem_id)); } - cw_dbg(DBG_ELEM,"Missing mandatory elements: [%s]",buffer); + cw_dbg(DBG_ELEM, "Missing mandatory elements: [%s]", buffer); +} + +int cw_format_pkt(char *dst,int level,struct conn *conn, uint8_t * packet, int len) +{ + char *s=dst; + switch (level) { + case DBG_PKT_IN: + s+=sprintf(s,"From %s",sock_addr2str(&conn->addr)); + break; + case DBG_PKT_OUT: + s+=sprintf(s,"To %s",sock_addr2str(&conn->addr)); + break; + } + s+=sprintf(s," l=%d: ",len); + + int preamble = cw_get_hdr_preamble(packet); + if (preamble==01){ + s+=sprintf(s," (encrypted)"); + return s-dst; + } + + if (len<4) + goto abort; + + + if (cw_get_hdr_flag_f(packet)){ + s+=sprintf(s," (fragmented)"); + } + + int hlen = cw_get_hdr_hlen(packet); + int rid = cw_get_hdr_rid(packet); + int wbid = cw_get_hdr_wbid(packet); + s+=sprintf(s," H:%d R:%02d W:%02d",hlen,rid,wbid); + + + s+=sprintf(s," Flgs:"); + s+=cw_format_hdr_flags(s,packet); + + if (len<8) + goto abort; + int frag_id = cw_get_hdr_fragid(packet); + int frag_offs = cw_get_hdr_fragoffset(packet); + s+=sprintf(s," Frag/Offs: %d/%d",frag_id,frag_offs); + + return s-dst; + + + +abort: + s+=sprintf(s," Incomplete..."); + return s-dst; + +} + +void cw_dbg_pkt(int level,struct conn *conn, uint8_t * packet, int len) +{ + if (!cw_dbg_is_level(level)) + return; + + char buf[1024]; + cw_format_pkt(buf,level,conn,packet,len); + cw_dbg(level,"%s",buf); +} + + +void cw_dbg_msg(int level,struct conn *conn, uint8_t * packet, int len) +{ + if (!cw_dbg_is_level(level)) + return; + + char buf[1024]; + char *s = buf; + + + + uint8_t * msgptr = cw_get_hdr_msg_ptr(packet); + int pplen = len - (msgptr-packet); + + int msg_id=cw_get_msg_id(msgptr); + s+=sprintf(s,"%s Message type %d",cw_strmsg(msg_id),msg_id); + s+=sprintf(s,"from %s ",sock_addr2str(&conn->addr)); + s+=sprintf(s,", Seqnum: %d ElemLen: %d",cw_get_msg_seqnum(msgptr),cw_get_msg_elems_len(msgptr)); + +abort: + cw_dbg(level,"%s",buf); } -void cw_dbg_packet(struct conn *conn, uint8_t * packet, int len) + +void cw_dbg_packet_m(struct conn *conn, uint8_t * packet, int len) { - if (!cw_dbg_is_level(DBG_CW_PKT_IN || DBG_CW_PKT_OUT)) + if (!cw_dbg_is_level(DBG_PKT_IN | DBG_PKT_OUT)) return; @@ -54,24 +156,24 @@ void cw_dbg_packet(struct conn *conn, uint8_t * packet, int len) hdr_print(hdr, packet, len); - if (!cw_dbg_is_level(DBG_CW_PKT_DMP)) { - cw_dbg(DBG_CW_PKT_IN, "Processing capwap packet from %s, len=%d\n%s", + if (!cw_dbg_is_level(DBG_PKT_DMP)) { + cw_dbg(DBG_PKT_IN, "Processing capwap packet from %s, len=%d\n%s", sock_addr2str(&conn->addr), len, hdr); return; } - cw_dbg_dmp(DBG_CW_PKT_DMP, packet, len, + cw_dbg_dmp(DBG_PKT_DMP, packet, len, "Processing packet from %s, len=%d\n%s\n\tDump:", sock_addr2str(&conn->addr), len, hdr); } -void cw_log_dbg_dmp_(int level, const char *file, int line, +void cw_dbg_dmp_(int level, const char *file, int line, const uint8_t * data, int len, const char *format, ...) { - +return; if (!(level & cw_dbg_opt_level)) return; @@ -83,14 +185,14 @@ void cw_log_dbg_dmp_(int level, const char *file, int line, int tlen = 0; int md; - if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) + if (cw_dbg_opt_display & DBG_DISP_ASC_DMP) md = 2; else md = 1; - char *dst = malloc(md * (len * 3 + (rows * 2) + 8 + maxtlen)); + char *dst = malloc(2*(md * (len * 3 + (rows * 2) + 8 + maxtlen))); if (!dst) return; @@ -118,7 +220,7 @@ void cw_log_dbg_dmp_(int level, const char *file, int line, for (i = 0; i < len; i++) { sprintf(pdst, "%02X ", data[i] & 0xff); - if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) { + if (cw_dbg_opt_display & DBG_DISP_ASC_DMP) { int c = data[i] & 0xff; if (c < 0x20 || c > 0x80) c = '.'; @@ -129,7 +231,7 @@ void cw_log_dbg_dmp_(int level, const char *file, int line, pdst += 3; if ((i + 1) % rowlen == 0) { int l; - if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) { + if (cw_dbg_opt_display & DBG_DISP_ASC_DMP) { *ascdst = 0; l = sprintf(pdst, " | %s\n\t", asc_buffer); ascdst = asc_buffer; @@ -142,17 +244,18 @@ void cw_log_dbg_dmp_(int level, const char *file, int line, } - if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) { + if (cw_dbg_opt_display & DBG_DISP_ASC_DMP) { *ascdst = 0; if (strlen(asc_buffer)) pdst += sprintf(pdst, " | %s", asc_buffer); } - if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS) - cw_log(LOG_DEBUG, "%s:%d: %s", file, line, dst); - else - cw_log(LOG_DEBUG, dst); + if (cw_dbg_opt_display & DBG_DISP_LINE_NUMBERS) + cw_log_cb(LOG_DEBUG, "%s:%d: %s", file, line, dst); + else{ + cw_log_cb(LOG_DEBUG, "%s",dst); + } free(dst); return; @@ -160,3 +263,166 @@ void cw_log_dbg_dmp_(int level, const char *file, int line, + +/** + * print debug info for message elements + */ + +void cw_dbg_elem_colored(int level, struct conn *conn, int msg, int msgelem, + const uint8_t * msgbuf, int len) +{ + if (!cw_dbg_is_level(level)) + return; + + const char *elemname; + char vendorname[256]; + char vendor_details[265]; + *vendor_details = 0; + + if (msgelem == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) { + uint32_t vendor_id = ntohl(*((uint32_t *) msgbuf)); + int type = ntohs(*((uint16_t *) (msgbuf + 4))); + cw_format_vendor(vendor_details, vendor_id, type, msgbuf); + sprintf(vendorname, "%s/%s/%s", + cw_strelemp(conn->actions, msgelem), + (char *) lw_vendor_id_to_str(vendor_id), vendor_details); + elemname = vendorname; + + } else { + elemname = cw_strelemp(conn->actions, msgelem); + } + + + if (!cw_dbg_is_level(DBG_ELEM_DMP)) + cw_dbg(DBG_ELEM, + "%s, CAWPAP element: %d (%s), len=%d%s", + cw_strmsg(msg), msgelem, elemname, len, ""); + + else + cw_dbg_dmp(DBG_ELEM, msgbuf, len, + "%s, CAPWAP element: %d (%s), len=%d%s\n\tDump ...", + cw_strmsg(msg), msgelem, elemname, len, ""); +} + + + + + +static struct cw_str color_on[] = { + { DBG_PKT_IN, "\x1b[33m" }, + { CW_STR_STOP, "" } +}; +static struct cw_str color_ontext[] = { + + { CW_STR_STOP, "" } +}; + + +static struct cw_str color_off[] = { + + { CW_STR_STOP, "\033[22;39m" } +}; + +static struct cw_str prefix[] = { + { DBG_INFO, " Info -" }, + { DBG_PKT_IN, " Pkt IN -" }, + { CW_STR_STOP, "" } +}; + + + + +static const char * get_dbg_color_on(int level){ + if ( ! (cw_dbg_opt_display & DBG_DISP_COLORS ) ) + return ""; + return cw_strlist_get_str(color_on,level); +} + +static const char * get_dbg_color_off(int level){ + if ( ! (cw_dbg_opt_display & DBG_DISP_COLORS ) ) + return ""; + return cw_strlist_get_str(color_off,level); +} + +static const char * get_dbg_prefix(int level){ + return cw_strlist_get_str(prefix,level); + +} + +static const char * get_dbg_color_ontext(int level){ + if ( ! (cw_dbg_opt_display & DBG_DISP_COLORS ) ) + return ""; + return cw_strlist_get_str(color_ontext,level); + +} + + + +/* + +void cw_log_colored(int level, const char *format, ...) +{ + char fbuf[1024]; + + sprintf(fbuf, "%s%s%s: %s%s", + get_log_color_on(level), + get_log_prefix(level), + get_log_color_ontext(level), + format, + get_log_color_off(level) + ); + + + va_list args; + va_start(args, format); + cw_log_vcb(level,fbuf,args); + va_end(args); + +} + +*/ + + + + +void cw_dbg_colored(int level, const char *file, int line, const char *format, ...) +{ + + if (!(level & cw_dbg_opt_level)) + return; + + char fbuf[1024]; + + sprintf(fbuf, "DBG:%s%s %s%s%s", + get_dbg_color_on(level), + get_dbg_prefix(level), + get_dbg_color_ontext(level), + format, + get_dbg_color_off(level) + ); + + + va_list args; + va_start(args, format); + cw_log_vcb(level,fbuf,args); + va_end(args); + + +return; + + + + char buf[2048]; + +// va_list args; + va_start(args, format); + vsprintf(buf, format, args); + va_end(args); + + if (cw_dbg_opt_display & DBG_DISP_LINE_NUMBERS) + cw_log(LOG_DEBUG, "%s:%d: %s", file, line, buf); + else + cw_log(LOG_DEBUG, buf); +} + + diff --git a/src/capwap/dbg.h b/src/capwap/dbg.h index 14b22f0e..5f58ea51 100644 --- a/src/capwap/dbg.h +++ b/src/capwap/dbg.h @@ -30,18 +30,82 @@ void cw_dbg_packet(struct conn *conn, uint8_t * packet, int len); #endif - - /** * @defgroup DebugOptions Dbug Options * @{ */ -#define CW_DBG_PKT_IN 0x00000001 /* Headers of incoming CAPWAP packets */ -#define CW_DBG_PKT_OUT 0x00000002 /* Headers of outgoing CAPWAP packets */ +#define DBG_PKT_IN 0x00000001 /* Headers of incoming CAPWAP packets */ +#define DBG_PKT_OUT 0x00000002 /* Headers of outgoing CAPWAP packets */ +#define DBG_PKT_ERR 0x00000004 /* Error of packets */ +#define DBG_PKT_DMP 0x00000008 /* Dump packts */ + + +#define DBG_MSG_IN 0x00000010 /* Parsed CAPWAP/LWAPP messages */ +#define DBG_MSG_OUT 0x00000020 /* Parsed CAPWAP/LWAPP messages */ + +#define DBG_ELEM 0x00000000 /* Show message elements */ +#define DBG_ELEM_DMP 0x00000000 /* Dump message elements */ + +#define DBG_INFO 0x00000000 +#define DBG_RFC 0x00000080 /* RCF-realted CAPWAP errors */ + + +#define DBG_MSG_ERR 0x00000000 /* Errors in CAPWAP messages */ +#define DBG_ELEM_ERR 0x00000000 + +/* driver specific debugs */ +#define DBG_DRV 0x00010000 +#define DBG_DRV_ERR 0x00020000 + +/* DTLS debugs */ +#define DBG_DTLS 0x10000000 +#define DBG_DTLS_DETAIL 0x20000000 +#define DBG_DTLS_BIO 0x40000000 +#define DBG_DTLS_BIO_DMP 0x80000000 + +#define DBG_ALL 0xffffffff +#define DBG_PKT_INOUT (DBG_CW_PKT_IN | DBG_CW_PKT_OUT) + + +#define DBG_DISP_LINE_NUMBERS 0x00000001 +#define DBG_DISP_ASC_DMP 0x00000002 +#define DBG_DISP_COLORS 0x00000004 + + +#define DBG_DETAIL_ALL 0xffffffff +#define DBG_ERR (DBG_MSG_ERR | DBG_CW_PKT_ERR) /**@}*/ + + +extern uint32_t cw_dbg_opt_display; +extern uint32_t cw_dbg_opt_level; +extern struct cw_str cw_dbg_strings[]; + + +/**@}*/ + + +#define cw_dbg(type,...) cw_dbg_colored(type,__FILE__,__LINE__,__VA_ARGS__) +#define cw_dbg_dmp(type,...) cw_dbg_dmp_(type,__FILE__,__LINE__,__VA_ARGS__) + + +void cw_dbg_colored(int level, const char *file, int line, const char *format, ...); +void cw_dbg_dmp_(int level, const char *file, int line, + const uint8_t * data, int len, const char *format, ...); + + +extern void cw_dbg_elem_colored(int level, struct conn *conn, int msg, int msgelem, + const uint8_t * msgbuf, int len); + +void cw_dbg_pkt(int level,struct conn *conn, uint8_t * packet, int len); +void cw_dbg_msg(int level,struct conn *conn, uint8_t * packet, int len); + + + + diff --git a/src/capwap/cw_log_str2dbglevel.c b/src/capwap/dbg_strings.c similarity index 89% rename from src/capwap/cw_log_str2dbglevel.c rename to src/capwap/dbg_strings.c index 5cb7c589..34aed7eb 100644 --- a/src/capwap/cw_log_str2dbglevel.c +++ b/src/capwap/dbg_strings.c @@ -19,9 +19,21 @@ #include -#include "log.h" +#include "dbg.h" +struct cw_str cw_dbg_strings[] = { + { DBG_INFO, "info" }, + { DBG_PKT_IN, "pkt_in" }, + { DBG_PKT_OUT, "pkt_out" }, + { CW_STR_STOP, NULL } +}; + + + + + +/* struct cw_dbg_cfgstrs cw_dbg_cfgstrs[] = { {"info",DBG_CW_INFO}, @@ -50,7 +62,9 @@ struct cw_dbg_cfgstrs cw_dbg_cfgstrs[] = { {0,0} }; +*/ +/* int cw_log_str2dbglevel(const char * str) { int i; @@ -60,4 +74,4 @@ int cw_log_str2dbglevel(const char * str) } return 0; } - +*/ diff --git a/src/capwap/dtls_bio.c b/src/capwap/dtls_bio.c index b554487a..d037089d 100644 --- a/src/capwap/dtls_bio.c +++ b/src/capwap/dtls_bio.c @@ -25,6 +25,7 @@ #include #include "log.h" +#include "dbg.h" #include "dtls.h" diff --git a/src/capwap/dtls_gnutls.c b/src/capwap/dtls_gnutls.c index ba5096a7..7a57deb5 100644 --- a/src/capwap/dtls_gnutls.c +++ b/src/capwap/dtls_gnutls.c @@ -25,11 +25,13 @@ #include "conn.h" #include "log.h" +#include "dbg.h" #include "cw_util.h" +#include "timer.h" int dtls_gnutls_init() { - cw_dbg(DBG_CW_INFO,"Init SSL library - using GnuTLS %s",gnutls_check_version(NULL)); + cw_dbg(DBG_INFO,"Init SSL library - using GnuTLS %s",gnutls_check_version(NULL)); gnutls_global_init(); return 1; } diff --git a/src/capwap/dtls_gnutls_accept.c b/src/capwap/dtls_gnutls_accept.c index deb55407..146c838a 100644 --- a/src/capwap/dtls_gnutls_accept.c +++ b/src/capwap/dtls_gnutls_accept.c @@ -25,10 +25,12 @@ #include "conn.h" +#include "dbg.h" #include "log.h" #include "sock.h" #include "capwap.h" #include "dtls_gnutls.h" +#include "timer.h" int dtls_gnutls_accept(struct conn *conn) diff --git a/src/capwap/dtls_gnutls_bio.c b/src/capwap/dtls_gnutls_bio.c index b01e9a78..9ddae9f1 100644 --- a/src/capwap/dtls_gnutls_bio.c +++ b/src/capwap/dtls_gnutls_bio.c @@ -24,6 +24,7 @@ #include "dtls.h" #include "dtls_gnutls.h" #include "capwap.h" +#include "timer.h" diff --git a/src/capwap/dtls_gnutls_connect.c b/src/capwap/dtls_gnutls_connect.c index 996150b6..3c34ec62 100644 --- a/src/capwap/dtls_gnutls_connect.c +++ b/src/capwap/dtls_gnutls_connect.c @@ -7,6 +7,7 @@ #include "conn.h" #include "log.h" +#include "dbg.h" diff --git a/src/capwap/dtls_openssl.c b/src/capwap/dtls_openssl.c index 3defeba1..42358f68 100644 --- a/src/capwap/dtls_openssl.c +++ b/src/capwap/dtls_openssl.c @@ -23,9 +23,13 @@ #include "dtls_openssl.h" +#include "capwap.h" +#include "dbg.h" #include "log.h" + #include "cw_util.h" +#include "rand.h" #include "conn.h" #include "sock.h" @@ -120,7 +124,7 @@ int pem_passwd_cb(char *buf, int size, int rwflag, void *password) int dtls_openssl_init() { const char * version = SSLeay_version(SSLEAY_VERSION); - cw_dbg(DBG_CW_INFO,"Init SSL library - %s",version); + cw_dbg(DBG_INFO,"Init SSL library - %s",version); SSL_load_error_strings(); int rc = SSL_library_init(); return rc; diff --git a/src/capwap/dtls_openssl_bio.c b/src/capwap/dtls_openssl_bio.c index e2fd6a8f..034947f8 100644 --- a/src/capwap/dtls_openssl_bio.c +++ b/src/capwap/dtls_openssl_bio.c @@ -5,6 +5,7 @@ #include "conn.h" #include "log.h" +#include "dbg.h" BIO_METHOD *dtls_openssl_bio_method() diff --git a/src/capwap/dtls_openssl_connect.c b/src/capwap/dtls_openssl_connect.c index 63f354ea..d4fb414e 100644 --- a/src/capwap/dtls_openssl_connect.c +++ b/src/capwap/dtls_openssl_connect.c @@ -2,7 +2,9 @@ #include "dtls_openssl.h" #include "log.h" +#include "dbg.h" #include "cw_util.h" +#include "timer.h" /* static BIO_METHOD bio_methods = { diff --git a/src/capwap/format.c b/src/capwap/format.c index 77b60d6e..01820335 100644 --- a/src/capwap/format.c +++ b/src/capwap/format.c @@ -54,3 +54,8 @@ int cw_format_hex_bytes(char *dst, const char *format, const char *delim, } return d - dst; } + + + + + diff --git a/src/capwap/format.h b/src/capwap/format.h index 6881fcfd..d8add300 100644 --- a/src/capwap/format.h +++ b/src/capwap/format.h @@ -55,4 +55,30 @@ extern int cw_format_hex_bytes(char *dst, const char *format, const char *delim, +/*#define cw_format_hdr_flags(s,th) \ + sprintf(s,"(T=%d,F=%d,L=%d,W=%d,M=%d,K=%d)",\ + cw_get_hdr_flag_t(packet),\ + cw_get_hdr_flag_f(packet),\ + cw_get_hdr_flag_l(packet),\ + cw_get_hdr_flag_w(packet),\ + cw_get_hdr_flag_m(packet),\ + cw_get_hdr_flag_k(packet)\ + ); +*/ + +static inline int cw_format_hdr_flags(char *dst,uint8_t *th) +{ + char * s = dst; + s+=sprintf(s,"%s", "("); + s+=sprintf(s,"%s", cw_get_hdr_flag_t(th) ? "T":""); + s+=sprintf(s,"%s", cw_get_hdr_flag_f(th) ? "F":""); + s+=sprintf(s,"%s", cw_get_hdr_flag_l(th) ? "L":""); + s+=sprintf(s,"%s", cw_get_hdr_flag_w(th) ? "W":""); + s+=sprintf(s,"%s", cw_get_hdr_flag_m(th) ? "M":""); + s+=sprintf(s,"%s", cw_get_hdr_flag_k(th) ? "K":""); + s+=sprintf(s,"%s", ")"); + return s-dst; + +} + #endif diff --git a/src/capwap/hdr_print.c b/src/capwap/hdr_print.c index af07144a..d269cf69 100644 --- a/src/capwap/hdr_print.c +++ b/src/capwap/hdr_print.c @@ -58,10 +58,8 @@ int hdr_print(char *str, uint8_t *packet, int len) int hlen = cw_get_hdr_hlen(packet); //CWTH_GET_HLEN(packet); - int rid = cw_get_hdr_rid(packet); int wbid = cw_get_hdr_wbid(packet); - s+=sprintf(s,"\tHLEN: %d, RID: %02X, WBID %02X",hlen,rid,wbid); diff --git a/src/capwap/itemstore.h b/src/capwap/itemstore.h index c2aba3d0..68e13e94 100644 --- a/src/capwap/itemstore.h +++ b/src/capwap/itemstore.h @@ -71,6 +71,7 @@ static inline struct cw_item *cw_itemstore_get(cw_itemstore_t s, uint32_t id) extern cw_itemstore_t cw_itemstore_create(); +extern int cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr); 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); diff --git a/src/capwap/log.h b/src/capwap/log.h index 4adf0c0d..5682738a 100644 --- a/src/capwap/log.h +++ b/src/capwap/log.h @@ -45,61 +45,12 @@ -/** - * @defgroup DebugOptions Dbug Options - * @{ - */ - -#define DBG_MSG 0x00000001 /* Parsed CAPWAP/LWAPP messages */ - -#define DBG_ELEM 0x00000002 /* Parsed CAPWAP/LWAPP message elements */ -#define DBG_ELEM_DMP 0x00000004 /* Dump CAPWAP message elements */ - -#define DBG_CW_INFO 0x00000008 -#define DBG_CW_RFC 0x00000010 /* RCF-realted CAPWAP errors */ -#define DBG_CW_STRICT 0x00000010 -#define DBG_CW_PKT_IN 0x00000020 /* Headers of incoming CAPWAP packets */ -#define DBG_CW_PKT_OUT 0x00000040 /* Headers of outgoing CAPWAP packets */ -#define DBG_CW_PKT_DMP 0x00000080 /* Dump packts */ -#define DBG_CW_PKT_DTL 0x00000100 -#define DBG_CW_PKT_ERR 0x00000200 -#define DBG_MSG_ERR 0x00000400 /* Errors in CAPWAP messages */ -#define DBG_CW_IMG_DTL 0x00000800 /* Detail about image transfer */ -#define DBG_ELEM_ERR 0x00001000 - -/* driver specific debugs */ -#define DBG_DRV 0x00010000 -#define DBG_DRV_ERR 0x00020000 - -/* DTLS debugs */ -#define DBG_DTLS 0x10000000 -#define DBG_DTLS_DETAIL 0x20000000 -#define DBG_DTLS_BIO 0x40000000 -#define DBG_DTLS_BIO_DMP 0x80000000 - -#define DBG_ALL 0xffffffff -#define DBG_CW_PKT_INOUT (DBG_CW_PKT_IN | DBG_CW_PKT_OUT) - - -#define DBG_DETAIL_LINE_NUMBERS 0x00000001 -#define DBG_DETAIL_ASC_DMP 0x00000002 - - -#define DBG_DETAIL_ALL 0xffffffff -#define DBG_ERR (DBG_MSG_ERR | DBG_CW_PKT_ERR) - -/**@}*/ - - -extern void cw_log_dbg_(int type, const char *file, int line, const char *fromat, ...); -extern void cw_log_dbg_dmp_(int type, const char *file, int line, const uint8_t * data, - int len, const char *format, ...); -extern int cw_dbg_opt_detail; -extern int cw_dbg_opt_level; - +//extern void cw_log_dbg_(int type, const char *file, int line, const char *fromat, ...); +//extern void cw_log_dbg_dmp_(int type, const char *file, int line, const uint8_t * data, + //int len, const char *format, ...); #define cw_dbg_is_level(level) (cw_dbg_opt_level & level) @@ -111,28 +62,31 @@ extern int cw_dbg_opt_level; #define cw_log(...) #endif -#ifdef WITH_CW_LOG_DEBUG +//#ifdef WITH_CW_LOG_DEBUG -#define cw_log_dbg(type,...) cw_log_dbg_(type,__FILE__,__LINE__,__VA_ARGS__) -#define cw_dbg(type,...) cw_log_dbg_(type,__FILE__,__LINE__,__VA_ARGS__) -#define cw_log_dbg_dmp(type,str,len,...) cw_log_dbg_dmp_(type,__FILE__,__LINE__,str,len,__VA_ARGS__) -#define cw_dbg_dmp(type,str,len,...) cw_log_dbg_dmp_(type,__FILE__,__LINE__,str,len,__VA_ARGS__) -#define cw_dbg_msgelem(msgtype,msgelemtype,msgbuf,msglen) cw_dbg_msgelem_(msgtype,msgelemtype,msgbuf,msglen) -#define cw_dbg_missing_mand_elems(conn, msgtyoe, mand) cw_dbg_missing_mand_elems_(conn, msgtyoe, mand) +//#define cw_log_dbg(type,...) cw_log_dbg_(type,__FILE__,__LINE__,__VA_ARGS__) -#define lw_dbg_elem(msgtype,msgelemtype,msgbuf,msglen) lw_dbg_elem_(msgtype,msgelemtype,msgbuf,msglen) -#else -#define cw_log_dbg(...) -#define cw_dbg(...) -#define cw_dbg_missing_mand_elems(conn, msgtyoe, mand) +//#define cw_log_dbg_dmp(type,str,len,...) cw_log_dbg_dmp_(type,__FILE__,__LINE__,str,len,__VA_ARGS__) +//#define cw_dbg_dmp(type,str,len,...) cw_log_dbg_dmp_(type,__FILE__,__LINE__,str,len,__VA_ARGS__) -#endif +//#define cw_dbg_msgelem(msgtype,msgelemtype,msgbuf,msglen) cw_dbg_msgelem_(msgtype,msgelemtype,msgbuf,msglen) +//#define cw_dbg_missing_mand_elems(conn, msgtyoe, mand) cw_dbg_missing_mand_elems_(conn, msgtyoe, mand) + +//#define lw_dbg_elem(msgtype,msgelemtype,msgbuf,msglen) lw_dbg_elem_(msgtype,msgelemtype,msgbuf,msglen) + +//#else +//#define cw_log_dbg(...) +//#define cw_dbg(...) + +//#define cw_dbg_missing_mand_elems(conn, msgtyoe, mand) + +//#endif extern void (*cw_log_cb) (int level, const char *fromat, ...); -extern void (*cw_vlog_cb) (int level, const char *fromat, va_list args); +extern void (*cw_log_vcb) (int level, const char *fromat, va_list args); /* Syslog functins */ extern void cw_log_syslog(int level, const char *format, ...); diff --git a/src/capwap/log_file.c b/src/capwap/log_file.c index 56acb2f4..b9abb44f 100644 --- a/src/capwap/log_file.c +++ b/src/capwap/log_file.c @@ -10,21 +10,8 @@ char * cw_log_filename = NULL; void cw_log_vfile(int level,const char * format, va_list args) { -/* switch(level){ - case LOG_DEBUG: - printf("DBG:"); - break; - case LOG_INFO: - printf("INFO:"); - break; - case LOG_ERR: - printf("ERROR:"); - break; - } -*/ vprintf(format,args); printf("\n"); - } void cw_log_file(int level,const char *format, ...) diff --git a/src/capwap/send.c b/src/capwap/send.c index 1ca8bcff..c4287b62 100644 --- a/src/capwap/send.c +++ b/src/capwap/send.c @@ -4,6 +4,7 @@ #include "capwap.h" #include "log.h" #include "sock.h" +#include "timer.h" int cw_send_request(struct conn *conn,int msg_id) { @@ -18,6 +19,9 @@ int cw_send_request(struct conn *conn,int msg_id) int i; int rc=-1; for (i=0; imax_retransmit && rc<0; i++){ + if ( i>0 ){ + cw_log(LOG_WARNING,"Retransmitting request ... %d",i); + } time_t timer = cw_timer_start(conn->retransmit_interval); while (!cw_timer_timeout(timer) && rc<0){ @@ -36,9 +40,13 @@ int cw_send_request(struct conn *conn,int msg_id) } - if ( rc <0 ) { + if ( rc <0 && errno != EAGAIN) { cw_log(LOG_ERR,"Error reading from %s:%s",sock_addr2str(&conn->addr),strerror(errno)); } + if ( rc <0 && errno == EAGAIN) { + errno=ETIMEDOUT; + rc=-1; + } return rc; } diff --git a/src/capwap/strheap.h b/src/capwap/strheap.h index f606e16c..8897c830 100644 --- a/src/capwap/strheap.h +++ b/src/capwap/strheap.h @@ -3,17 +3,12 @@ #include +#include "strlist.h" #include "avltree.h" typedef struct avltree * cw_strheap_t; -struct cw_str { - int id; - const char *str; -}; - -#define CW_STR_STOP -1138 extern cw_strheap_t cw_strheap_create(); extern int cw_strheap_register_strings(cw_strheap_t h, struct cw_str *s); diff --git a/src/wtp/Makefile b/src/wtp/Makefile index 372de683..fdde8712 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -20,7 +20,7 @@ ifndef ARCH endif -CFLAGS += -Os -Wall -g +CFLAGS += -O0 -Wall -g #CFLAGS += -Os -Wall LDFLAGS += -L../../src/capwap/$(ARCH) @@ -79,6 +79,8 @@ CFLAGS += -I../../src -I /usr/local/include OBJS += wtp_main.o +OBJS += image_update.o + #OBJS += wtp_conf.o diff --git a/src/wtp/conf_uci.c b/src/wtp/conf_uci.c index 8f5e814e..4c1f61d6 100644 --- a/src/wtp/conf_uci.c +++ b/src/wtp/conf_uci.c @@ -16,6 +16,7 @@ #include "wtp_conf.h" #include "capwap/log.h" +#include "capwap/dbg.h" #include "capwap/bstr.h" @@ -59,8 +60,9 @@ static void read_dbg_options(struct uci_context *ctx, struct uci_section *sectio { int i; - for (i=0; cw_dbg_cfgstrs[i].name; i++) { - set_dbg_opt(ctx,section,cw_dbg_cfgstrs[i].level,cw_dbg_cfgstrs[i].name); + for (i=0; cw_dbg_strings[i].id!=CW_STR_STOP; i++) { + + set_dbg_opt(ctx,section,cw_dbg_strings[i].id,cw_dbg_strings[i].str); } } @@ -96,13 +98,13 @@ int read_config(const char * filename){ if (filename == NULL){ filename = "wtp_uci.conf"; } - cw_dbg(DBG_ALL,"Reading config file %s",filename); + cw_dbg(DBG_INFO,"Reading config file %s",filename); int rc = uci_load(ctx, filename, &pkg ); if (rc == UCI_ERR_NOTFOUND){ - cw_dbg(DBG_CW_INFO,"Config file '%s' not found, running without config",filename); + cw_log(LOG_INFO,"Config file '%s' not found, running without config",filename); return 1; } @@ -126,7 +128,7 @@ int read_config(const char * filename){ section = get_anon_section(pkg,"wtp"); if (!section) { - cw_dbg(DBG_CW_INFO,"No 'wtp' section found, running without config"); + cw_dbg(DBG_INFO,"No 'wtp' section found, running without config"); return 1; } diff --git a/src/wtp/join.c b/src/wtp/join.c index 8580f908..ad090039 100644 --- a/src/wtp/join.c +++ b/src/wtp/join.c @@ -10,6 +10,7 @@ #include "capwap/dtls.h" #include "capwap/log.h" +#include "capwap/dbg.h" #include "capwap/sock.h" #include "capwap/dtls.h" #include "capwap/aciplist.h" @@ -214,92 +215,3 @@ int join() } -/* -int join(struct sockaddr *sa) -{ - int sockfd; - int rc; - -// sockfd = socket(AF_INET,SOCK_DGRAM,0); - - sockfd = get_sock(); - if (sockfd==-1){ - cw_log(LOG_ERR,"Can't create socket: %s\n",strerror(errno)); - return -1; - } - - sock_set_recvtimeout(sockfd,1); - - rc = connect(sockfd,(struct sockaddr*)sa,sock_addrlen((struct sockaddr*)sa)); - if (rc<0){ - char str[100]; - sock_addrtostr(sa,str,100); - cw_log(LOG_ERR,"Can't connect to %s: %s\n",str,strerror(errno)); - close(sockfd); - return -1; - } - - struct conn * conn = get_conn(); - -conn->capwap_mode = CWMODE_CISCO; -conn->seqnum=-1; - - - conn->sock=sockfd; - sock_copyaddr(&conn->addr,sa); - - -#ifdef WITH_DTLS - cw_dbg (DBG_DTLS,"Establishing DTLS session with %s",sock_addr2str(sa)); - - - - if (conf_dtls_psk){ - conn->dtls_psk=conf_dtls_psk; - conn->dtls_psk_len=strlen(conn->dtls_psk); - conn->dtls_cipher=conf_dtls_cipher; - } - - if (conf_sslkeyfilename && conf_sslcertfilename){ - - conn->dtls_key_file = conf_sslkeyfilename; - conn->dtls_cert_file = conf_sslcertfilename; - conn->dtls_key_pass = conf_sslkeypass; - conn->dtls_cipher=conf_dtls_cipher; - - } - - - - rc = dtls_connect(conn); - if (rc!=1){ - dtls_shutdown(conn); - char str[100]; - sock_addrtostr(sa,str,100); - cw_log(LOG_ERR,"Can't establish DTLS connection to %s",str); - close(sockfd); - return 0; - } - - -#endif - cw_dbg (DBG_DTLS,"DTLS session established with %s, cipher=%s",sock_addr2str(sa),dtls_get_cipher(conn)); - - - #ifdef WITH_CW_LOG_DEBUG - { - char str[100]; - sock_addrtostr(sa,str,100); -// cw_log_debug0("DTLS connection to %s established",str); - } - #endif - - join_state(conn); - -printf("Joined with conn %p\n",conn); - - return 1; -} - - -*/ diff --git a/src/wtp/nlt.c b/src/wtp/nlt.c index fa323e4d..3233bfe0 100644 --- a/src/wtp/nlt.c +++ b/src/wtp/nlt.c @@ -4,6 +4,7 @@ #include #include "capwap/log.h" +#include "capwap/dbg.h" #include "capwap/avltree.h" #include "nlt.h" diff --git a/src/wtp/sulking.c b/src/wtp/sulking.c index f202df4e..ae78b4fb 100644 --- a/src/wtp/sulking.c +++ b/src/wtp/sulking.c @@ -1,14 +1,13 @@ #include -#include "capwap/log.h" +#include "capwap/dbg.h" #include "wtp.h" #include "wtp_conf.h" int sulking_state() { - cw_dbg(DBG_CW_INFO,"Entering Sulking state"); - cw_dbg(DBG_CW_INFO,"Sleeping for %i seconds",conf_silent_interval); + cw_dbg(DBG_INFO,"Sulking state, sleeping for %i seconds",conf_silent_interval); sleep(conf_silent_interval); return 1; } diff --git a/src/wtp/wtp.h b/src/wtp/wtp.h index fb42ad6b..8fc73065 100644 --- a/src/wtp/wtp.h +++ b/src/wtp/wtp.h @@ -8,6 +8,7 @@ extern int sulking_state(); extern int join(); extern int discovery(); +extern int image_update(); struct conn * get_conn(); diff --git a/src/wtp/wtp_conf.c b/src/wtp/wtp_conf.c index 91841a1a..03d345f2 100644 --- a/src/wtp/wtp_conf.c +++ b/src/wtp/wtp_conf.c @@ -13,6 +13,8 @@ #include "capwap/capwap.h" #include "capwap/log.h" +#include "capwap/dbg.h" + #include "capwap/cw_util.h" #include "wtp_conf.h" @@ -111,7 +113,7 @@ int wtpconf_primary_if() return 0; }; - cw_dbg(DBG_CW_INFO, "Primary interface: %s, mac address: %s.", + cw_dbg(DBG_INFO, "Primary interface: %s, mac address: %s.", conf_primary_if, sock_hwaddr2str(conf_macaddress,conf_macaddress_len) ); @@ -133,7 +135,7 @@ int wtpconf_name() if (!conf_wtpname) return 0; - cw_dbg(DBG_CW_INFO,"Using self assigned wtp name: %s",conf_wtpname); + cw_dbg(DBG_INFO,"Using self assigned wtp name: %s",conf_wtpname); return 1; } @@ -190,7 +192,7 @@ int wtpconf_ac_list() conf_ac_list_len=len; #ifdef WITH_CW_LOG_DEBUG for (i=0; ilocal,CW_ITEM_LOCATION_DATA,"Berlin"); cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube"); + cw_itemstore_set_byte(conn->local,CW_ITEM_WTP_MAC_TYPE,0); + cw_itemstore_set_byte(conn->local,CW_ITEM_WTP_FRAME_TUNNEL_MODE,0); + discovery(); join(); + image_update(); } diff --git a/src/wtp/wtpdrv.c b/src/wtp/wtpdrv.c index 2ff10f45..9afcdee8 100644 --- a/src/wtp/wtpdrv.c +++ b/src/wtp/wtpdrv.c @@ -12,6 +12,7 @@ #include "capwap/radioinfo.h" #include "capwap/sock.h" #include "capwap/capwap_80211.h" +#include "capwap/dbg.h" int wpa_printf() {