From 4c0d06e21d3c2896b8e96a04b4480e9121563f31 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Tue, 7 Apr 2015 05:42:36 +0000 Subject: [PATCH] VM FossilOrigin-Name: 4bbb8402b5110003c6d19908b6fa9b4a7a6b5903ba1fa691eb93a49aa0f089f4 --- src/Config.mak | 2 +- src/ac/Makefile | 2 +- src/ac/ac_global.c | 15 +- src/ac/ac_interface.c | 10 +- src/ac/ac_main.c | 26 +- src/ac/conf.c | 16 +- src/ac/conf.h | 6 +- src/ac/db.c | 2 +- src/ac/socklist.c | 4 +- src/ac/wtplist.c | 6 +- src/ac/wtpman.c | 992 +++++++++--------- src/ac/wtpman.h | 4 +- src/capwap/Makefile | 19 +- src/capwap/action.c | 111 +- src/capwap/action.h | 14 +- src/capwap/avltree.h | 1 + src/capwap/bstr.h | 50 +- src/capwap/bstr_create.c | 2 +- src/capwap/capwap.h | 98 +- src/capwap/capwap_actions.h | 51 +- src/capwap/capwap_actions_ac.c | 151 +-- src/capwap/capwap_cisco.h | 1 + src/capwap/capwap_items.h | 12 +- src/capwap/capwap_strings_elem.c | 2 +- src/capwap/cipwap_actions_ac.c | 27 +- src/capwap/conn.h | 8 + src/capwap/conn_process_packet.c | 24 +- src/capwap/cw_dbg_elem.c | 2 + src/capwap/cw_in_generic.c | 27 +- src/capwap/cw_in_wtp_board_data.c | 10 +- src/capwap/cw_log_debug.c | 2 + src/capwap/cw_msg_init.c | 2 - src/capwap/cw_out_ac_descriptor.c | 4 +- src/capwap/cw_out_cisco_ac_descriptor.c | 2 +- src/capwap/cw_out_generic.c | 14 +- src/capwap/cw_process_msg.c | 119 ++- src/capwap/cw_put_msg.c | 12 +- .../cw_readelem_wtp_reboot_statistics.c | 2 +- src/capwap/cw_util.c | 3 +- src/capwap/cw_util.h | 2 +- .../cwread_configuration_status_request.c | 2 +- src/capwap/dbg.h | 1 + src/capwap/dtls.h | 6 +- src/capwap/itemstore.c | 84 +- src/capwap/itemstore.h | 62 +- src/capwap/strheap.h | 11 +- src/wtp/Makefile | 7 +- src/wtp/configure.c | 3 +- src/wtp/discovery.c | 292 +----- src/wtp/join.c | 5 +- src/wtp/run.c | 11 +- src/wtp/wtp.h | 8 + src/wtp/wtp_conf.h | 2 + src/wtp/wtp_interface.c | 7 +- src/wtp/wtp_main.c | 180 +--- 55 files changed, 1312 insertions(+), 1226 deletions(-) diff --git a/src/Config.mak b/src/Config.mak index d2b03275..5423810e 100644 --- a/src/Config.mak +++ b/src/Config.mak @@ -14,7 +14,7 @@ USE_CONTRIB_GNUTLS=1 # Compiler to use CC=clang -#CC=gcca +#CC=gcc #CC=mips-openwrt-linux-uclibc-gcc #LD=mips-openwrt-linux-uclibc-ld #AR=mips-openwrt-linux-uclibc-ar diff --git a/src/ac/Makefile b/src/ac/Makefile index 50f01eb8..030b303f 100644 --- a/src/ac/Makefile +++ b/src/ac/Makefile @@ -11,7 +11,7 @@ ifndef ARCH endif LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib -L../capwap/$(ARCH) -CFLAGS += -Wall -g -O0 -D_REENTRANT -DIPV6 -I/usr/local/include -I../capwap +CFLAGS += -Wall -g -O0 -D_REENTRANT -DIPV6 -I/usr/local/include -I../ LIBS+=-lcapwap diff --git a/src/ac/ac_global.c b/src/ac/ac_global.c index 3a9b58e6..17b97f1b 100644 --- a/src/ac/ac_global.c +++ b/src/ac/ac_global.c @@ -3,11 +3,11 @@ #include "ac.h" #include "conf.h" -#include "capwap.h" -#include "capwap_items.h" -#include "aciplist.h" +#include "capwap/capwap.h" +#include "capwap/capwap_items.h" +#include "capwap/aciplist.h" #include "socklist.h" -#include "sock.h" +#include "capwap/sock.h" struct cw_ac_status ac_status; @@ -93,11 +93,14 @@ int ac_global_init() ac_status.dtls_policy = CW_FLAG_DTLS_POLICY_C | CW_FLAG_DTLS_POLICY_D; - cw_itemstore_set_version(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0, + cw_itemstore_set_vendorstr(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0, bstr_data(conf_hardware_version), bstr_len(conf_hardware_version)); - cw_itemstore_set_version(ac_config, CW_ITEM_AC_SOFTWARE_VERSION, 0, + cw_itemstore_set_vendorstr(ac_config, CW_ITEM_AC_SOFTWARE_VERSION, 0, bstr_data(conf_software_version), bstr_len(conf_software_version)); + + cw_itemstore_set_str(ac_config,CW_ITEM_AC_IMAGE_DIR,conf_image_dir); + // cw_itemstore_set_avltree(ac_config, CW_ITEM_AC_IP_LIST, aciplist); diff --git a/src/ac/ac_interface.c b/src/ac/ac_interface.c index ad6a0dc0..48911635 100644 --- a/src/ac/ac_interface.c +++ b/src/ac/ac_interface.c @@ -4,15 +4,15 @@ #include #include -#include "sock.h" +#include "capwap/sock.h" #include "socklist.h" -#include "acinfo.h" +#include "capwap/acinfo.h" #include "conf.h" -#include "capwap.h" -#include "capwap_80211.h" -#include "aciplist.h" +#include "capwap/capwap.h" +#include "capwap/capwap_80211.h" +#include "capwap/aciplist.h" diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index b5935890..3f76e626 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -27,18 +27,19 @@ #include "actube.h" #include "wtplist.h" -#include "dtls.h" -#include "cw_log.h" +#include "capwap/dtls.h" +#include "capwap/cw_log.h" #include "conf.h" -#include "sock.h" +#include "capwap/sock.h" #include "socklist.h" #include "db.h" -#include "capwap_items.h" -#include "capwap_cisco.h" +#include "capwap/capwap_items.h" +#include "capwap/capwap_cisco.h" #include "ac.h" +#include "capwap/format.h" int ac_run(); @@ -50,7 +51,7 @@ void alive_thread(void *data) } } -#include "action.h" +#include "capwap/action.h" /* @@ -98,20 +99,13 @@ int readelem_cisco_rad_name(struct conn *conn,struct cw_action * a,uint8_t *data */ -/* -int avlprint(void *priv, void *data) -{ - struct cw_str * d = (struct cw_str*) data; - printf("String: %d - %s\n",d->id,d->str); -} -*/ +#include "capwap/capwap_crypto.h" + + int main (int argc, const char * argv[]) { - - - cw_log_name="AC-Tube"; read_config("ac.conf"); diff --git a/src/ac/conf.c b/src/ac/conf.c index 36aa1e35..775f03a1 100644 --- a/src/ac/conf.c +++ b/src/ac/conf.c @@ -21,13 +21,13 @@ #include -#include "capwap.h" -#include "sock.h" +#include "capwap/capwap.h" +#include "capwap/sock.h" #include "conf.h" -#include "cw_log.h" -#include "cw_util.h" +#include "capwap/cw_log.h" +#include "capwap/cw_util.h" uint8_t conf_macaddress[12]; uint8_t conf_macaddress_len=0; @@ -391,7 +391,7 @@ static char * conf_default_mcast_groups_ipv6[] = { #endif //#include "avltree" -#include "stravltree.h" +#include "capwap/stravltree.h" @@ -568,6 +568,12 @@ int read_config(const char * filename){ if (!init_control_port()) return 0; + + + + + + cfg_opt_t opts[] = { CFG_STR_LIST("dbg", "{}", CFGF_NONE), CFG_STR_LIST("listen", "{}", CFGF_NONE), diff --git a/src/ac/conf.h b/src/ac/conf.h index 8fb05be4..0c515ed0 100644 --- a/src/ac/conf.h +++ b/src/ac/conf.h @@ -26,9 +26,9 @@ #include -#include "capwap.h" -#include "lwapp.h" -#include "bstr.h" +#include "capwap/capwap.h" +#include "capwap/lwapp.h" +#include "capwap/bstr.h" #ifndef CONF_DEFAULT_ACNAME #define CONF_DEFAULT_ACNAME "AC" diff --git a/src/ac/db.c b/src/ac/db.c index afd9149e..254cd6c9 100644 --- a/src/ac/db.c +++ b/src/ac/db.c @@ -1,7 +1,7 @@ #include -#include "cw_log.h" +#include "capwap/cw_log.h" #include "conf.h" diff --git a/src/ac/socklist.c b/src/ac/socklist.c index 95d81ad0..bec41895 100644 --- a/src/ac/socklist.c +++ b/src/ac/socklist.c @@ -25,8 +25,8 @@ #include -#include "cw_log.h" -#include "sock.h" +#include "capwap/cw_log.h" +#include "capwap/sock.h" #include "socklist.h" diff --git a/src/ac/wtplist.c b/src/ac/wtplist.c index 4132a479..ea38db79 100644 --- a/src/ac/wtplist.c +++ b/src/ac/wtplist.c @@ -30,12 +30,12 @@ #include #include "wtplist.h" -#include "conn.h" -#include "sock.h" +#include "capwap/conn.h" +#include "capwap/sock.h" #include "conf.h" -#include "cw_log.h" +#include "capwap/cw_log.h" /* static struct wtpman ** wtplist = 0; diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index c610f712..faea72e4 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -7,36 +7,34 @@ #include "wtplist.h" -#include "capwap.h" -#include "sock.h" +#include "capwap/capwap.h" +#include "capwap/sock.h" #include "socklist.h" -#include "conn.h" +#include "capwap/conn.h" #include "wtpman.h" #include "conf.h" -#include "cw_log.h" - -#include "dtls.h" - +#include "capwap/cw_log.h" #include "conf.h" -#include "lwmsg.h" -#include "lwapp.h" +#include "capwap/lwmsg.h" +#include "capwap/lwapp.h" #include -#include "capwap.h" -#include "capwap_80211.h" -#include "capwap_cisco.h" +#include "capwap/capwap_80211.h" +#include "capwap/capwap_cisco.h" -#include "cw_util.h" +#include "capwap/cw_util.h" -#include "capwap_items.h" +#include "capwap/capwap_items.h" #include "ac.h" +#include "capwap/dtls.h" + extern struct cw_actiondef capwap_actions; @@ -58,33 +56,33 @@ int conn_handle_echo_request(void * d) */ -void conn_handle_change_state_event_request(struct conn * conn) +void conn_handle_change_state_event_request(struct conn *conn) { } - -static struct cwrmsg * xconn_wait_for_message(struct conn * conn, time_t timer) +/* +static struct cwrmsg *xconn_wait_for_message(struct conn *conn, time_t timer) { - struct cwrmsg * cwrmsg; + struct cwrmsg *cwrmsg; - while (!cw_timer_timeout(timer)){ + while (!cw_timer_timeout(timer)) { cwrmsg = conn_get_message(conn); - if (!cwrmsg){ + if (!cwrmsg) { if (!conn_is_error(conn)) continue; return 0; } - if (cwrmsg->type & 1){ - if (conn->request_handler){ + if (cwrmsg->type & 1) { + if (conn->request_handler) { if (conn->request_handler(conn->request_handler_param)) continue; } - + } return cwrmsg; @@ -93,157 +91,167 @@ static struct cwrmsg * xconn_wait_for_message(struct conn * conn, time_t timer) return 0; } +*/ - -struct rh_param{ - struct conn * conn; +struct rh_param { + struct conn *conn; int *msglist; }; static int conn_rh(void *param) { - struct rh_param * p = (struct rh_param*)param; + struct rh_param *p = (struct rh_param *) param; int i; - int *msglist=p->msglist; + int *msglist = p->msglist; -printf("Param %p\n",param); + printf("Param %p\n", param); - for (i=0; msglist[i]!=-1; i++){ - if (msglist[i] == p->conn->cwrmsg.type ) + for (i = 0; msglist[i] != -1; i++) { + if (msglist[i] == p->conn->cwrmsg.type) return 0; } /* unexpected response here */ - cw_log(LOG_ERR,"Unexpected message from %s",sock_addr2str(&p->conn->addr)); - cwsend_unknown_response(p->conn,p->conn->cwrmsg.seqnum,p->conn->cwrmsg.type); - return 1; + cw_log(LOG_ERR, "Unexpected message from %s", sock_addr2str(&p->conn->addr)); + cwsend_unknown_response(p->conn, p->conn->cwrmsg.seqnum, p->conn->cwrmsg.type); + return 1; } -static struct cwrmsg * zconn_wait_for_request(struct conn * conn, int *msglist, time_t timer) + +/* +static struct cwrmsg *zconn_wait_for_request(struct conn *conn, int *msglist, + time_t timer) { - int (*request_handler_save) (void*); - void * request_handler_param_save; + int (*request_handler_save) (void *); + void *request_handler_param_save; struct rh_param rh_param; - - if (msglist){ - request_handler_save=conn->request_handler; - request_handler_param_save=conn->request_handler_param; - rh_param.conn=conn; - rh_param.msglist=msglist; - conn->request_handler=conn_rh; - conn->request_handler_param=&rh_param; + + if (msglist) { + request_handler_save = conn->request_handler; + request_handler_param_save = conn->request_handler_param; + rh_param.conn = conn; + rh_param.msglist = msglist; + conn->request_handler = conn_rh; + conn->request_handler_param = &rh_param; } - struct cwrmsg * cwrmsg; - while (!cw_timer_timeout(timer)){ - cwrmsg = conn_wait_for_message(conn,timer); - if (!cwrmsg){ + struct cwrmsg *cwrmsg; + while (!cw_timer_timeout(timer)) { + cwrmsg = conn_wait_for_message(conn, timer); + if (!cwrmsg) { if (!conn_is_error(conn)) continue; break; } - /* response message? no action*/ - if (! (cwrmsg->type & 1) ) - continue; + if (!(cwrmsg->type & 1)) + continue; - /* it's a request message */ break; } - if (msglist){ - conn->request_handler=request_handler_save; - conn->request_handler_param=request_handler_param_save; + if (msglist) { + conn->request_handler = request_handler_save; + conn->request_handler_param = request_handler_param_save; } return cwrmsg; } +*/ - - -struct cwrmsg * xconn_send_request(struct conn * conn) +/* +struct cwrmsg *xconn_send_request(struct conn *conn) { int i; - struct cwrmsg * cwrmsg; - struct cwmsg * cwmsg = &conn->req_msg; - -printf("Retrans interval = %d\n",conn->retransmit_interval); -printf("Current Seqnum = %d\n",conn->seqnum); + 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++) { + for (i = 0; i < conn->max_retransmit; i++) { - time_t r_timer = cw_timer_start(conn->retransmit_interval); - if (i!=0) - cw_dbg(DBG_MSG_ERR,"Retransmitting message, type=%d,seq=%d",cwmsg->type,cwmsg->seqnum); + time_t r_timer = cw_timer_start(conn->retransmit_interval); + if (i != 0) + cw_dbg(DBG_MSG_ERR, "Retransmitting message, type=%d,seq=%d", + cwmsg->type, cwmsg->seqnum); - conn_send_cwmsg(conn,&conn->req_msg); - cwrmsg = conn_wait_for_message(conn,r_timer); - if (cwrmsg){ - if (cwrmsg->type == conn->req_msg.type+1){ + conn_send_cwmsg(conn, &conn->req_msg); + cwrmsg = conn_wait_for_message(conn, r_timer); + if (cwrmsg) { + if (cwrmsg->type == conn->req_msg.type + 1) { printf("YeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaA!!!!!\n"); - return cwrmsg; + return cwrmsg; } +// cw_dbg(DBG_CW_MSG_ERR,"Wrong message blablub, type=%d,seq=%d",cwmsg->type,cwmsg->seqnum); + -// cw_dbg(DBG_CW_MSG_ERR,"Wrong message blablub, type=%d,seq=%d",cwmsg->type,cwmsg->seqnum); - - } - } - cw_dbg(DBG_MSG_ERR,"Max retransmit's reached, message type=%d,seq=%d",cwmsg->type,cwmsg->seqnum); - return 0; + } + cw_dbg(DBG_MSG_ERR, "Max retransmit's reached, message type=%d,seq=%d", + cwmsg->type, cwmsg->seqnum); + return 0; } +*/ int wtpman_handle_request(void *p) { - struct wtpman * wtpman = (struct wtpman *)p; - struct conn * conn = wtpman->conn; - struct cwrmsg * cwrmsg = &conn->cwrmsg; - switch(conn->cwrmsg.type){ + +/* + struct wtpman *wtpman = (struct wtpman *) p; + struct conn *conn = wtpman->conn; + struct cwrmsg *cwrmsg = &conn->cwrmsg; + switch (conn->cwrmsg.type) { case CW_MSG_ECHO_REQUEST: cw_handle_echo_request(conn); break; case CW_MSG_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); + cwread_change_state_event_request(&wtpman->wtpinfo, + cwrmsg->msgelems, + cwrmsg->msgelems_len); + cwsend_change_state_event_response(wtpman->conn, cwrmsg->seqnum, + wtpman->wtpinfo.radioinfo); break; default: - printf("Unhandeleed message %d!!!!!!!!!!!!\n",cwrmsg->type); - cwsend_unknown_response(conn,cwrmsg->seqnum,cwrmsg->type); + printf("Unhandeleed message %d!!!!!!!!!!!!\n", cwrmsg->type); + cwsend_unknown_response(conn, cwrmsg->seqnum, cwrmsg->type); } return 1; +*/ } -void usend_image_file(struct conn * conn,const char * filename) +void usend_image_file(struct conn *conn, const char *filename) { - FILE * infile; - infile = fopen(filename,"rb"); - if (!infile){ - cw_log(LOG_ERR,"Can't open image file %s:%s",filename,strerror(errno)); + FILE *infile; + infile = fopen(filename, "rb"); + if (!infile) { + cw_log(LOG_ERR, "Can't open image file %s:%s", filename, strerror(errno)); return; } - - cw_log(LOG_INFO,"Sending image file %s to %s",filename,sock_addr2str(&conn->addr)); - struct cwrmsg * cwrmsg; - uint8_t buffer[1024]; + cw_log(LOG_INFO, "Sending image file %s to %s", filename, + sock_addr2str(&conn->addr)); + + struct cwrmsg *cwrmsg; + uint8_t buffer[1024]; struct cwimage_data data; data.data = buffer; @@ -251,12 +259,12 @@ void usend_image_file(struct conn * conn,const char * filename) conn->request_handler = cw_handle_echo_request; conn->request_handler_param = conn; -int bl=0; + int bl = 0; //fseek(infile,2703*1024,SEEK_SET); - do{ + do { - data.len = fread(buffer,1,sizeof(buffer),infile); + data.len = fread(buffer, 1, sizeof(buffer), infile); //data.len=0; /* @@ -272,43 +280,44 @@ buffer[279]=199; buffer[319]=219; */ -int ai; -for (ai=0; ai<1024; ai++){ - printf("%02X ",buffer[ai]); + int ai; + for (ai = 0; ai < 1024; ai++) { + printf("%02X ", buffer[ai]); -} + } if (feof(infile)) - data.type=2; - else - data.type=1; + data.type = 2; + else + data.type = 1; - if (data.len==0){ - printf("*******************************************len0************************************\n"); + 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)); + 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); + conn_prepare_image_data_request(conn, &data, 0); +// cwrmsg = conn_send_request(conn); - if (cwrmsg){ + if (cwrmsg) { printf("Got img data response\n"); - } - else{ + } else { printf("Respnse Timeout\n"); exit(0); } - }while(!feof(infile)); + } while (!feof(infile)); exit(0); @@ -318,9 +327,9 @@ for (ai=0; ai<1024; ai++){ //ACIPLIST * get_aciplist(); -struct ac_info * get_acinfo(); +struct ac_info *get_acinfo(); -static void wtpman_remove(struct wtpman * wtpman) +static void wtpman_remove(struct wtpman *wtpman) { wtplist_lock(); wtplist_remove(wtpman); @@ -335,58 +344,79 @@ static void wtpman_remove(struct wtpman * wtpman) * Returns pointer to cwrms if message is received * Returns EOF in case of any other error */ -static struct cwrmsg * wtpman_wait_for_message(struct wtpman * wtpman, time_t timer) + +/* +static struct cwrmsg *wtpman_wait_for_message(struct wtpman *wtpman, time_t timer) { - struct cwrmsg * cwrmsg; + struct cwrmsg *cwrmsg; do { cwrmsg = conn_get_message(wtpman->conn); if (!cwrmsg && wtpman->conn->dtls_error) - return (struct cwrmsg*)EOF; - if (!cwrmsg && cw_timer_timeout(timer)) + return (struct cwrmsg *) EOF; + if (!cwrmsg && cw_timer_timeout(timer)) return NULL; - }while(!cwrmsg); + } while (!cwrmsg); - cw_dbg(DBG_MSG,"Received message from %s, type=%d - %s" - ,CLIENT_IP,cwrmsg->type,cw_msgtostr(cwrmsg->type)); + cw_dbg(DBG_MSG, "Received message from %s, type=%d - %s", CLIENT_IP, cwrmsg->type, + cw_msgtostr(cwrmsg->type)); return cwrmsg; } +*/ - int conn_msg_processor(struct conn *conn); +//int conn_msg_processor(struct conn *conn); + + + +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; + return 0; + +} + static void wtpman_run_discovery(void *arg) { - struct wtpman * wtpman = (struct wtpman *)arg; - struct cwrmsg * cwrmsg; - + struct wtpman *wtpman = (struct wtpman *) arg; + struct cwrmsg *cwrmsg; + time_t timer = cw_timer_start(10); -extern cw_actionlist_in_t the_tree; + extern cw_actionlist_in_t the_tree; - wtpman->conn->capwap_state=CW_STATE_DISCOVERY; + wtpman->conn->capwap_state = CW_STATE_DISCOVERY; wtpman->conn->actions = &capwap_actions; +/* + cw_actionlist_in_set_msg_end_callback(capwap_actions.in, CW_STATE_DISCOVERY, + CW_MSG_DISCOVERY_REQUEST, check_discovery); + +*/ + wtpman->conn->local = ac_config; wtpman->conn->remote = cw_itemstore_create(); - while ( !cw_timer_timeout(timer) && wtpman->conn->capwap_state==CW_STATE_DISCOVERY){ - conn_msg_processor(wtpman->conn); + while (!cw_timer_timeout(timer) + && wtpman->conn->capwap_state == CW_STATE_DISCOVERY) { + cw_read_messages(wtpman->conn); } - struct cw_item * wn = cw_itemstore_get(wtpman->conn->remote,CW_ITEM_WTP_NAME); + struct cw_item *wn = cw_itemstore_get(wtpman->conn->remote, CW_ITEM_WTP_NAME); - if (wn ) { - printf("WTP Name: %s\n",wn->data); + if (wn) { + printf("WTP Name: %s\n", wn->data); } wtpman_remove(wtpman); return; - + @@ -395,45 +425,49 @@ extern cw_actionlist_in_t the_tree; timer = cw_timer_start(10); cwrmsg = wtpman_wait_for_message(wtpman, timer); - if ( !cwrmsg ) - { - cw_dbg(DBG_MSG_ERR,"No complete message from %s received after %d seconds",CLIENT_IP,10); + if (!cwrmsg) { + cw_dbg(DBG_MSG_ERR, + "No complete message from %s received after %d seconds", CLIENT_IP, + 10); wtpman_remove(wtpman); return; } - - if (cwrmsg->type!=CW_MSG_DISCOVERY_REQUEST){ - cw_dbg(DBG_MSG_ERR,"Invalid message in discovery state from %s, type=%s - %s ", - CLIENT_IP,cwrmsg->type,cw_msgtostr(cwrmsg->type)); + + if (cwrmsg->type != CW_MSG_DISCOVERY_REQUEST) { + cw_dbg(DBG_MSG_ERR, + "Invalid message in discovery state from %s, type=%s - %s ", + CLIENT_IP, cwrmsg->type, cw_msgtostr(cwrmsg->type)); wtpman_remove(wtpman); return; } - cwread_discovery_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len); + cwread_discovery_request(&wtpman->wtpinfo, cwrmsg->msgelems, + cwrmsg->msgelems_len); -// printf("RMAC-LEN:%d\n",cwrmsg->rmac[0]); +// printf("RMAC-LEN:%d\n",cwrmsg->rmac[0]); //printf("HW: %s\n",sock_hwaddr2str(bstr_data(cwrmsg->rmac),bstr_len(cwrmsg->rmac))); - conn_detect_capwap(wtpman->conn,&wtpman->wtpinfo); + conn_detect_capwap(wtpman->conn, &wtpman->wtpinfo); char wtpinfostr[8192]; - wtpinfo_print(wtpinfostr,&wtpman->wtpinfo); - cw_dbg(DBG_CW_INFO,"Discovery request gave us the follwing WTP Info:\n%s",wtpinfostr); + wtpinfo_print(wtpinfostr, &wtpman->wtpinfo); + cw_dbg(DBG_CW_INFO, "Discovery request gave us the follwing WTP Info:\n%s", + wtpinfostr); struct radioinfo radioinfo; radioinfo.rid = cwrmsg->rid; - radioinfo.rmac = 0; //&cwrmsg->rmac; - -// memcpy(radioinfo.rmac, cwrmsg->rmac,8); -// radioinfo.rmac[0]=0; + radioinfo.rmac = 0; //&cwrmsg->rmac; - struct ac_info * acinfo = get_acinfo(); +// memcpy(radioinfo.rmac, cwrmsg->rmac,8); +// radioinfo.rmac[0]=0; + + struct ac_info *acinfo = get_acinfo(); @@ -442,7 +476,8 @@ extern cw_actionlist_in_t the_tree; cw_dbg(DBG_CW_INFO,"Discovery request gave us the follwing WTP Info:\n%s",wtpinfostr); */ - cwsend_discovery_response(wtpman->conn,cwrmsg->seqnum,&radioinfo,acinfo,&wtpman->wtpinfo); + cwsend_discovery_response(wtpman->conn, cwrmsg->seqnum, &radioinfo, acinfo, + &wtpman->wtpinfo); wtpman_remove(wtpman); } @@ -450,26 +485,26 @@ extern cw_actionlist_in_t the_tree; static void wtpman_run_run(void *arg) { - - struct wtpman * wtpman = (struct wtpman *)arg; - struct conn * conn = wtpman->conn; +/* + struct wtpman *wtpman = (struct wtpman *) arg; + struct conn *conn = wtpman->conn; - struct cwrmsg * cwrmsg; + struct cwrmsg *cwrmsg; - conn->request_handler=wtpman_handle_request; - conn->request_handler_param=wtpman; + conn->request_handler = wtpman_handle_request; + conn->request_handler_param = wtpman; + - int i; - for (i=0; i<1; i++){ + for (i = 0; i < 1; i++) { time_t t = cw_timer_start(1); printf("Wait...\n"); - conn_wait_for_message(conn,t); + conn_wait_for_message(conn, t); } printf("Update now?\n"); - +*/ /* conn_prepare_request(conn,CW_MSG_CONFIGURATION_UPDATE_REQUEST); @@ -488,22 +523,22 @@ static void wtpman_run_run(void *arg) } */ - -printf("Adding WLAN\n"); +/* + printf("Adding WLAN\n"); struct cwwlan wlan; - memset(&wlan,0,sizeof(wlan)); + memset(&wlan, 0, sizeof(wlan)); - const char * wl = "wl7u83"; - wlan.ssid = bstr_create(wl,strlen(wl)); + const char *wl = "wl7u83"; + wlan.ssid = bstr_create(wl, strlen(wl)); - conn_prepare_request(conn,CWMSG_80211_WLAN_CONFIGURATION_REQUEST); - struct cwmsg * cwmsg = &conn->req_msg; - cwmsg_addelem_80211_add_wlan(cwmsg,&wlan); + conn_prepare_request(conn, CWMSG_80211_WLAN_CONFIGURATION_REQUEST); + struct cwmsg *cwmsg = &conn->req_msg; + cwmsg_addelem_80211_add_wlan(cwmsg, &wlan); cwrmsg = conn_send_request(conn); -printf("WLAN CONF sent\n"); - + printf("WLAN CONF sent\n"); +*/ @@ -511,17 +546,18 @@ printf("WLAN CONF sent\n"); /* conn_prepare_request(conn,CWMSG_RESET_REQUEST); cwmsg_addelem_image_identifier(&conn->req_msg,CW_VENDOR_ID_CISCO,"image00",strlen("image00")); cwrmsg = conn_send_request(conn); -*/ +*/ - for (i=0; i<100; i++){ +/* + for (i = 0; i < 100; i++) { time_t t = cw_timer_start(1); printf("Wait...\n"); - conn_wait_for_message(conn,t); + conn_wait_for_message(conn, t); } printf("Set name?\n"); - exit(0); - + exit(0); +*/ } @@ -529,90 +565,193 @@ printf("WLAN CONF sent\n"); static int wtpman_establish_dtls(void *arg) { - struct wtpman * wtpman = (struct wtpman *)arg; - + struct wtpman *wtpman = (struct wtpman *) arg; + /* setup cipher */ - wtpman->conn->dtls_cipher=conf_sslcipher; + wtpman->conn->dtls_cipher = conf_sslcipher; /* setup DTSL certificates */ - int dtls_ok=0; - if (conf_sslkeyfilename && conf_sslcertfilename){ + int dtls_ok = 0; + if (conf_sslkeyfilename && conf_sslcertfilename) { wtpman->conn->dtls_key_file = conf_sslkeyfilename; 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",wtpman->conn->dtls_cert_file); - dtls_ok=1; + cw_dbg(DBG_DTLS, "DTLS - Using key file %s", wtpman->conn->dtls_key_file); + cw_dbg(DBG_DTLS, "DTLS - Using cert file %s", + wtpman->conn->dtls_cert_file); + dtls_ok = 1; } /* setup DTLS psk */ - if (conf_dtls_psk){ - wtpman->conn->dtls_psk=conf_dtls_psk; - wtpman->conn->dtls_psk_len=strlen(conf_dtls_psk); - dtls_ok=1; + if (conf_dtls_psk) { + wtpman->conn->dtls_psk = conf_dtls_psk; + wtpman->conn->dtls_psk_len = strlen(conf_dtls_psk); + dtls_ok = 1; } - if (!dtls_ok){ - cw_log(LOG_ERR,"Can't establish DTLS session, neither psk nor certs set in config file."); + if (!dtls_ok) { + cw_log(LOG_ERR, + "Can't establish DTLS session, neither psk nor certs set in config file."); return 0; } /* try to accept the connection */ - if ( !dtls_accept(wtpman->conn) ){ - cw_dbg(DBG_DTLS,"Error establishing DTLS session with %s",CLIENT_IP); + if (!dtls_accept(wtpman->conn)) { + cw_dbg(DBG_DTLS, "Error establishing DTLS session with %s", CLIENT_IP); return 0; } - - cw_dbg(DBG_DTLS,"DTLS session established with %s, cipher=%s", CLIENT_IP,dtls_get_cipher(wtpman->conn)); - /* DTLS handshake done */ + cw_dbg(DBG_DTLS, "DTLS session established with %s, cipher=%s", CLIENT_IP, + dtls_get_cipher(wtpman->conn)); + /* DTLS handshake done */ int cert_len; struct dtls_ssl_cert cert; FILE *f; - f = fopen ("pcert.der","wb"); + f = fopen("pcert.der", "wb"); printf("Calling peers cert\n"); - cert = dtls_get_peers_cert(wtpman->conn,0); + 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); return 1; } -static int wtpman_join(void *arg,time_t timer) +static int wtpman_join(void *arg, time_t timer) { - struct wtpman * wtpman = (struct wtpman *)arg; + struct wtpman *wtpman = (struct wtpman *) arg; -extern cw_actionlist_in_t the_tree; -wtpman->conn->actions=&capwap_actions; -wtpman->conn->capwap_state=CW_STATE_JOIN; + extern cw_actionlist_in_t the_tree; + wtpman->conn->actions = &capwap_actions; + wtpman->conn->capwap_state = CW_STATE_JOIN; - wtpman->conn->capwap_state=CW_STATE_JOIN; + wtpman->conn->capwap_state = CW_STATE_JOIN; wtpman->conn->actions = &capwap_actions; -// wtpman->conn->itemstore = cw_itemstore_create(); +// wtpman->conn->itemstore = cw_itemstore_create(); wtpman->conn->local = ac_config; wtpman->conn->remote = cw_itemstore_create(); - while ( !cw_timer_timeout(timer) && wtpman->conn->capwap_state==CW_STATE_JOIN){ - int rc = conn_msg_processor(wtpman->conn); - if (rc <0 ) { + while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CW_STATE_JOIN) { + int rc = cw_read_messages(wtpman->conn); + if (rc < 0) { + break; + } + } + + 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; + + +} + + +static int wtpman_send_image_file(struct wtpman *wtpman, struct cwrmsg *cwrmsg) +{ + struct cwimage_data data; + memset(&data, 0, sizeof(struct cwimage_data)); + uint8_t id[1025]; + data.identifier = id; + char filename[2048]; + id[0] = 0; + + + cw_read_image_data_request(&data, cwrmsg->msgelems, cwrmsg->msgelems_len); + if (!strlen(id)) { + cw_dbg(DBG_MSG_ERR, "No image identifier in image data request"); + cw_send_image_data_response(wtpman->conn, cwrmsg->seqnum, + CW_RESULT_FAILURE); + return 0; + } + + sprintf(filename, "%s/%s", conf_image_dir, id); + + FILE *infile; + infile = fopen(filename, "rb"); + if (infile) { + cw_send_image_data_response(wtpman->conn, cwrmsg->seqnum, + CW_RESULT_SUCCESS); + cw_log(LOG_INFO, "Sending image file %s to %s", filename, + sock_addr2str(&wtpman->conn->addr)); + cw_send_image_file(wtpman->conn, infile); + return 1; + } + + cw_log(LOG_ERR, "Can't open image file %s:%s", filename, strerror(errno)); + cw_send_image_data_response(wtpman->conn, cwrmsg->seqnum, CW_RESULT_FAILURE); + + return 0; + +} + +static void wtpman_run(void *arg) +{ + struct wtpman *wtpman = (struct wtpman *) arg; + 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) { + cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.", + CLIENT_IP); + wtpman_remove(wtpman); + return; + } + + + time_t timer = cw_timer_start(wtpman->conn->wait_dtls); + + /* establish dtls session */ + if (!wtpman_establish_dtls(wtpman)) { + wtpman_remove(wtpman); + return; + } + + + /* dtls is established, goto join state */ + if (!wtpman_join(wtpman, timer)) { + wtpman_remove(wtpman); + return; + } + + + + + /* here the WTP has joined, now we assume an image data request + or an configuration status request. Nothing else. + State is Image update + */ + + + while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CW_STATE_CONFIGURE) { + int rc = cw_read_messages(wtpman->conn); + if (rc < 0) { break; } } - printf("Breaked\n"); + + + + exit(0); @@ -622,190 +761,72 @@ wtpman->conn->capwap_state=CW_STATE_JOIN; +/* - - - - /* timer = cw_timer_start(wtpman->conn->wait_join); */ - - int join_msgs[] = { CW_MSG_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_MSG_ERR,"DTLS connection closed while waiting for join request from %s.",CLIENT_IP); - return 0; - } - - 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; - - } - - - process_join_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len); - conn_detect_capwap(wtpman->conn,&wtpman->wtpinfo); - - { - char wtpinfostr[8192]; - wtpinfo_print(wtpinfostr,&wtpman->wtpinfo); - cw_dbg(DBG_CW_INFO,"Join request gave us the follwing WTP Info:\n%s",wtpinfostr); - } - - - struct radioinfo radioinfo; - radioinfo.rid = cwrmsg->rid; -// memcpy (radioinfo.rmac, cwrmsg->rmac,8); - struct ac_info * acinfo = get_acinfo(); - - - int result_code = 0; - cw_dbg(DBG_MSG,"Sending join response to %s",CLIENT_IP); -printf("SLeep befor join resp\n"); -printf("Slept befor join resp\n"); - - cwsend_join_response(wtpman->conn,cwrmsg->seqnum,result_code,&radioinfo,acinfo,&wtpman->wtpinfo); - cw_log(LOG_INFO,"WTP joined, Name = %s, Location = %s, IP = %s", - wtpman->wtpinfo.name,wtpman->wtpinfo.location, - sock_addr2str(&wtpman->conn->addr)); - -//exit(0); - return 1; - -} - - -static int wtpman_send_image_file(struct wtpman * wtpman,struct cwrmsg * cwrmsg) -{ - struct cwimage_data data; - memset(&data,0,sizeof(struct cwimage_data)); - uint8_t id [1025]; - data.identifier=id; - char filename[2048]; - id[0]=0; - - - cw_read_image_data_request(&data,cwrmsg->msgelems,cwrmsg->msgelems_len); - if (!strlen(id)){ - cw_dbg(DBG_MSG_ERR, "No image identifier in image data request"); - cw_send_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_FAILURE); - return 0; - } - - sprintf(filename,"%s/%s",conf_image_dir,id); - - FILE *infile; - infile = fopen(filename, "rb"); - if (infile) { - cw_send_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_SUCCESS); - cw_log(LOG_INFO, "Sending image file %s to %s", filename, sock_addr2str(&wtpman->conn->addr)); - cw_send_image_file(wtpman->conn, infile); - return 1; - } - - cw_log(LOG_ERR, "Can't open image file %s:%s", filename, strerror(errno)); - cw_send_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_FAILURE); - - return 0; - -} - -static void wtpman_run(void *arg) -{ - struct wtpman * wtpman = (struct wtpman *)arg; - 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){ - cw_dbg(DBG_DTLS,"Dropping connection from %s to non-unicast socket.", CLIENT_IP); - wtpman_remove(wtpman); - return; - } - - - time_t timer = cw_timer_start(wtpman->conn->wait_dtls); - - /* establish dtls session*/ - if (!wtpman_establish_dtls(wtpman)){ - wtpman_remove(wtpman); - return; - } - - - /* dtls is established, goto join state */ - if (!wtpman_join(wtpman,timer)){ - wtpman_remove(wtpman); - return; - } - - - - - /* here the WTP has joined, now we assume an image data request - or an configuration status request. Nothing else. i - State is Image update - */ - 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); + 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 (!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); 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 ){ + // 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; } } - } while (cwrmsg->type != CW_MSG_CONFIGURATION_STATUS_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; + 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"); + 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); + 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){ + 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); + 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: @@ -816,17 +837,18 @@ printf("Done\n"); //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"); - + + // 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; @@ -846,16 +868,18 @@ printf("Done\n"); */ -// 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); +// 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); + 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; @@ -871,17 +895,19 @@ for (ii=0; ii<3; ii++){ } */ +/* wtpman_run_run(wtpman); -exit(0); + 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); + 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); } - +*/ @@ -891,36 +917,37 @@ exit(0); 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); - } - - - 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); +*/ + + + + +// 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); + while (1) { + struct cwrmsg *cwrmsg = conn_get_message(wtpman->conn); @@ -929,15 +956,15 @@ exit(0); if (!cwrmsg) { msg_counter++; - if (msg_counter < CAPWAP_ECHO_INTERVAL *2 ) + if (msg_counter < CAPWAP_ECHO_INTERVAL * 2) continue; - - // cw_log_debug0("WTP died"); + + // cw_log_debug0("WTP died"); wtpman_remove(wtpman); return; } - +*/ /* if (cwrmsg->type == CWMSG_CONFIGURATION_STATUS_REQUEST){ process_conf_status_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len); @@ -952,79 +979,61 @@ if (cwrmsg->type == CWMSG_CONFIGURATION_STATUS_REQUEST){ } */ - msg_counter=0; + +/* + msg_counter = 0; - if (cwrmsg->type == CW_MSG_ECHO_REQUEST){ - cwsend_echo_response(wtpman->conn,cwrmsg->seqnum,wtpman->wtpinfo.radioinfo); + if (cwrmsg->type == CW_MSG_ECHO_REQUEST) { + cwsend_echo_response(wtpman->conn, cwrmsg->seqnum, + wtpman->wtpinfo.radioinfo); } -// printf("Got msg: %i\n",cwrmsg->type); - - } - - - - -// process_discovery(wtpman,cwrmsg); - exit(0); - - - printf("Messag gote ssl\n"); - - printf("Precdeis sssl\n"); - - printf ("SEQNUM REC: %i\n",cwrmsg->seqnum); - - printf("procdis ende\n"); - - - exit(0); - - - - - while (1) - { - /* - sem_wait(&wtpman->q_sem); - int qrpos = wtpman->qrpos+1; - if (qrpos==WTPMAN_QSIZE) - qrpos=0; - wtpman->qrpos=qrpos; - - uint8_t * packet = wtpman->q[qrpos]+4; - int len = *( (uint32_t*)(wtpman->q[qrpos])); */ - uint8_t * packet = conn_q_get_packet(wtpman->conn); -// int len = *( (uint32_t*)(packet)); + +// printf("Got msg: %i\n",cwrmsg->type); + +} -// conn_process_packet(wtpman->conn,packet+4,len); + + +// 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); } -} +*/ -void wtpman_destroy(struct wtpman * wtpman) + + +void wtpman_destroy(struct wtpman *wtpman) { - if ( wtpman->conn) + if (wtpman->conn) conn_destroy(wtpman->conn); - free (wtpman); + free(wtpman); } -struct wtpman * wtpman_create(int socklistindex,struct sockaddr * srcaddr) +struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr) { - struct wtpman * wtpman; + struct wtpman *wtpman; wtpman = malloc(sizeof(struct wtpman)); if (!wtpman) return 0; - memset (wtpman,0,sizeof(struct wtpman)); + memset(wtpman, 0, sizeof(struct wtpman)); int sockfd = socklist[socklistindex].reply_sockfd; - wtpman->conn=conn_create(sockfd,srcaddr,100); - if (!wtpman->conn){ + wtpman->conn = conn_create(sockfd, srcaddr, 100); + if (!wtpman->conn) { wtpman_destroy(wtpman); return NULL; } @@ -1033,25 +1042,25 @@ struct wtpman * wtpman_create(int socklistindex,struct sockaddr * srcaddr) } -void wtpman_addpacket(struct wtpman * wtpman,uint8_t *packet,int len) +void wtpman_addpacket(struct wtpman *wtpman, uint8_t * packet, int len) { - conn_q_add_packet(wtpman->conn,packet,len); + conn_q_add_packet(wtpman->conn, packet, len); } -void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t *packet, int len) +void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t * packet, int len) { -// uint8_t * m = packet+12; -// int l = LWTH_GET_LENGTH(packet+6); +// uint8_t * m = packet+12; +// int l = LWTH_GET_LENGTH(packet+6); - uint8_t * msg = packet+12; + uint8_t *msg = packet + 12; - int msgtype = LWMSG_GET_TYPE(msg); - int msglen = LWMSG_GET_LEN(msg); - printf ("Type is %d, Len is %d\n",msgtype,msglen); - - uint8_t * msgdata = LWMSG_GET_DATA(msg); + int msgtype = LWMSG_GET_TYPE(msg); + int msglen = LWMSG_GET_LEN(msg); + printf("Type is %d, Len is %d\n", msgtype, msglen); + + uint8_t *msgdata = LWMSG_GET_DATA(msg); /* int c=0; @@ -1065,7 +1074,7 @@ void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t *packet, int len) */ - uint8_t * data; + uint8_t *data; /* lw_foreach_msgelem(data,msgdata,msglen){ int eltype = LWMSGELEM_GET_TYPE(data); @@ -1080,16 +1089,16 @@ void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t *packet, int len) */ char wi[4096]; - wtpinfo_print(wi,&wtpman->wtpinfo); - printf ("WTPINFO: \n%s\n",wi); + wtpinfo_print(wi, &wtpman->wtpinfo); + printf("WTPINFO: \n%s\n", wi); - -// char buffer[2048]; -// struct lwmsg lwmsg; -// lwmsg_init(&lwmsg, buffer,conf_macaddress,LWMSG_DISCOVERY_RESPONSE,conn_get_next_seqnum(wtpman->conn)); - -// conn_send_packet(wtpman->conn,buffer,60); + +// char buffer[2048]; +// struct lwmsg lwmsg; +// lwmsg_init(&lwmsg, buffer,conf_macaddress,LWMSG_DISCOVERY_RESPONSE,conn_get_next_seqnum(wtpman->conn)); + +// conn_send_packet(wtpman->conn,buffer,60); @@ -1097,22 +1106,21 @@ void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t *packet, int len) } -void wtpman_start(struct wtpman * wtpman,int dtlsmode) +void wtpman_start(struct wtpman *wtpman, int dtlsmode) { - if ( dtlsmode ){ - cw_dbg(DBG_CW_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"); - pthread_create (&wtpman->thread, NULL, (void *) &wtpman_run_discovery, (void *) wtpman); + if (dtlsmode) { + cw_dbg(DBG_CW_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"); + pthread_create(&wtpman->thread, NULL, (void *) &wtpman_run_discovery, + (void *) wtpman); } } -void wtpman_lw_start(struct wtpman * wtpman) +void wtpman_lw_start(struct wtpman *wtpman) { } - - diff --git a/src/ac/wtpman.h b/src/ac/wtpman.h index 8a0d4e25..966838de 100644 --- a/src/ac/wtpman.h +++ b/src/ac/wtpman.h @@ -5,8 +5,8 @@ #include #include -#include "capwap.h" -#include "fragman.h" +#include "capwap/capwap.h" +#include "capwap/fragman.h" #define WTPMAN_QSIZE 1024 diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 89a1c1a0..a4545ea0 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -98,7 +98,6 @@ CAPWAPOBJS= \ cwmsg_addelem_ac_descriptor.o \ cwmsg_addelem_wtp_descriptor.o \ cwmsg_addelem_wtp_radio_infos.o \ - cwmsg_addelem_wtp_board_data.o \ cwmsg_addelem_cw_local_ip_addr.o \ cwmsg_addelem_mtu_discovery_padding.o \ cwmsg_addelem_ac_timestamp.o \ @@ -121,11 +120,9 @@ CAPWAPOBJS= \ cw_handle_echo_request.o \ cwsend_conf_status_response.o\ cwread_configuration_status_request.o\ - cwread_discovery_request.o\ cwread_change_state_event_request.o\ cwread_wtp_event_request.o \ process_conf_status_request.o \ - wtpinfo_readelem_wtp_board_data.o \ wtpinfo_readelem_wtp_mac_type.o \ wtpinfo_readelem_wtp_radio_info.o \ cw_readelem_80211_wtp_radio_info.o \ @@ -172,20 +169,27 @@ CAPWAPOBJS= \ cw_in_wtp_board_data.o \ cw_in_check_disc_req.o \ cw_in_check_join_req.o \ + cw_in_check_img_data_req.o \ cw_out_generic.o \ cw_out_ac_descriptor.o \ cw_out_cisco_ac_descriptor.o \ cw_out_cisco_ap_timesync.o \ + cw_in_cisco_image_identifier.o\ cw_out_capwap_control_ip_addrs.o \ strheap.o \ cw_check_missing_mand.o \ - dbg.o + dbg.o \ + md5sum.o \ + format.o + #cw_in_wtp_name.o \ #cw_msgtostr.o \ #cw_msgelemtostr.o \ #cwmsg_addelem_ctrl_ip_addrs.o \ #process_join_request.o \ + #cwmsg_addelem_wtp_board_data.o \ + #wtpinfo_readelem_wtp_board_data.o \ #cw_ianavendoridtostr.o \ #cwmsg_addelem_result_code.o \ @@ -202,6 +206,7 @@ CAPWAPOBJS= \ # cwmsg_set_control_header.o # process_msgelems.o \ # cwsend_join_response.o \ +# cwread_discovery_request.o\ # # SSL objects @@ -243,7 +248,6 @@ CONNOBJS= conn_create.o \ connlist.o \ conn_create_noq.o \ conn_send_response.o \ - conn_get_message.o \ conn_get_response.o \ conn_prepare_configuration_update_request.o \ cw_prepare_configuration_status_request.o \ @@ -255,6 +259,7 @@ CONNOBJS= conn_create.o \ conn_wait_for_request.o \ conn_init.o \ conn_send_msg.o +#conn_get_message.o \ @@ -269,8 +274,10 @@ FRAGOBJS=fragman.o CWACTION=action.o \ cw_process_msg.o \ capwap_actions_ac.o \ + capwap_actions_wtp.o \ cw_in_generic.o \ cw_in_wtp_descriptor.o \ + cw_out_wtp_board_data.o \ cipwap_actions_ac.o \ cipwap_strings_elem.o \ cw_put_msg.o \ @@ -291,7 +298,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 -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 += $(GNUTLS_CFLAGS) \ -DWITH_CW_LOG \ diff --git a/src/capwap/action.c b/src/capwap/action.c index 673898a3..1e3e9e66 100644 --- a/src/capwap/action.c +++ b/src/capwap/action.c @@ -19,7 +19,7 @@ /** * @file * @brief Implementation of methods for actionlists. - */ + */ #include @@ -27,30 +27,30 @@ #include "action.h" -static inline int cw_action_in_cmp(const void *elem1,const void *elem2) +static inline int cw_action_in_cmp(const void *elem1, const void *elem2) { - struct cw_action_in * e1 = (struct cw_action_in*)elem1; - struct cw_action_in * e2 = (struct cw_action_in*)elem2; - int r; + struct cw_action_in *e1 = (struct cw_action_in *) elem1; + struct cw_action_in *e2 = (struct cw_action_in *) elem2; + int r; r = e1->msg_id - e2->msg_id; - if (r!=0) - return r; - - r = e1->capwap_state - e2->capwap_state; - if (r!=0) + if (r != 0) return r; r = e1->elem_id - e2->elem_id; - if (r!=0) + if (r != 0) + return r; + + r = e1->capwap_state - e2->capwap_state; + if (r != 0) return r; r = e1->vendor_id - e2->vendor_id; - if (r!=0) + if (r != 0) return r; r = e1->proto - e2->proto; - if (r!=0) + if (r != 0) return r; @@ -59,41 +59,41 @@ static inline int cw_action_in_cmp(const void *elem1,const void *elem2) } -cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in * a) +cw_action_in_t *cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in * a) { - return cw_actionlist_add(t,a,sizeof(struct cw_action_in)); + return cw_actionlist_add(t, a, sizeof(struct cw_action_in)); } -struct cw_action_in * cw_actionlist_in_get(cw_actionlist_in_t t,struct cw_action_in *a) +struct cw_action_in *cw_actionlist_in_get(cw_actionlist_in_t t, struct cw_action_in *a) { - return avltree_get(t,a); + return avltree_get(t, a); } cw_actionlist_in_t cw_actionlist_in_create() { - return avltree_create(cw_action_in_cmp,free); + return avltree_create(cw_action_in_cmp, free); } -int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions) +int cw_actionlist_in_register_actions(cw_actionlist_in_t t, cw_action_in_t * actions) { - while(actions->capwap_state){ - cw_action_in_t * rc = cw_actionlist_in_add(t,actions); - if (rc==0) - return 0; + while (actions->capwap_state) { + cw_action_in_t *rc = cw_actionlist_in_add(t, actions); + if (rc == 0) + return 0; actions++; } return 1; } -int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * actions) +int cw_actionlist_out_register_actions(cw_actionlist_out_t t, cw_action_out_t * actions) { - while(actions->msg_id!=0){ - cw_action_out_t * rc = cw_actionlist_out_add(t,actions); - if (rc==0) - return 0; + while (actions->msg_id != 0) { + cw_action_out_t *rc = cw_actionlist_out_add(t, actions); + if (rc == 0) + return 0; actions++; } return 1; @@ -104,23 +104,23 @@ int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * a /* * Compare function for actionlist_out_t lists - */ -static int cw_action_out_cmp(const void *elem1,const void *elem2) + */ +static int cw_action_out_cmp(const void *elem1, const void *elem2) { - struct cw_action_out * e1 = (struct cw_action_out*)elem1; - struct cw_action_out * e2 = (struct cw_action_out*)elem2; - int r; + struct cw_action_out *e1 = (struct cw_action_out *) elem1; + struct cw_action_out *e2 = (struct cw_action_out *) elem2; + int r; r = e1->msg_id - e2->msg_id; - if (r!=0) + if (r != 0) return r; r = e1->item_id - e2->item_id; - if (r!=0) + if (r != 0) return r; r = e1->vendor_id - e2->vendor_id; - if (r!=0) + if (r != 0) return r; return 0; @@ -134,19 +134,19 @@ static int cw_action_out_cmp(const void *elem1,const void *elem2) * @param a action to add * @param s size of element to add * @return pointer to added element or NULL if an error has opccured - */ -void * cw_actionlist_add(struct avltree *t, void *a, size_t s) + */ +void *cw_actionlist_add(struct avltree *t, void *a, size_t s) { - void * r = avltree_replace_data(t,a,sizeof(struct cw_action_in)); + void *r = avltree_replace_data(t, a, sizeof(struct cw_action_in)); if (r) return r; - + void *an = malloc(sizeof(struct cw_action_in)); if (!an) return NULL; - memcpy(an,a,s); - return avltree_add(t,an); + memcpy(an, a, s); + return avltree_add(t, an); } @@ -154,19 +154,38 @@ void * cw_actionlist_add(struct avltree *t, void *a, size_t s) /** * Create an action list for outgoing message lements * @return the created action list or NULL if an erro has occured. - */ + */ cw_actionlist_out_t cw_actionlist_out_create() { - return avltree_create(cw_action_out_cmp,free); + return avltree_create(cw_action_out_cmp, free); } -cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a) +cw_action_out_t *cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a) { - return cw_actionlist_add(t,a,sizeof (struct cw_action_out)); + return cw_actionlist_add(t, a, sizeof(struct cw_action_out)); } +cw_action_in_t *cw_actionlist_in_set_msg_end_callback(cw_actionlist_in_t a, + uint8_t capwap_state, + uint32_t msg_id, + int (*fun) (struct conn * conn, + struct cw_action_in * a, uint8_t * data, + int len)) +{ + cw_action_in_t as,*ar; + as.vendor_id=0; + as.proto=0; + as.elem_id=-1; + as.msg_id=msg_id; + as.capwap_state=capwap_state; + ar = cw_actionlist_in_get(a,&as); + if (!ar) + return NULL; + ar->end=fun; + return ar; +} diff --git a/src/capwap/action.h b/src/capwap/action.h index 51f9170d..f6060641 100644 --- a/src/capwap/action.h +++ b/src/capwap/action.h @@ -46,6 +46,7 @@ struct cw_action_in{ uint16_t item_id; uint16_t min_len; uint16_t max_len; + uint8_t mand; }; @@ -58,6 +59,12 @@ extern cw_actionlist_in_t cw_actionlist_in_create(); extern cw_action_in_t * cw_actionlist_in_get(cw_actionlist_in_t t,cw_action_in_t *a); extern cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t,cw_action_in_t *a); extern int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions); +extern cw_action_in_t *cw_actionlist_in_set_msg_end_callback(cw_actionlist_in_t a, + uint8_t capwap_state, + uint32_t msg_id, + int (*fun) (struct conn * conn, + struct cw_action_in * a, uint8_t * data, + int len)); /* Definitions for outgoing messages */ @@ -69,9 +76,12 @@ struct cw_action_out{ int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst); struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a); - - + uint8_t mand; + uint8_t itemtype; + void *defval; + }; + typedef struct cw_action_out cw_action_out_t; typedef struct avltree *cw_actionlist_out_t; diff --git a/src/capwap/avltree.h b/src/capwap/avltree.h index a8fddc81..62733a1c 100644 --- a/src/capwap/avltree.h +++ b/src/capwap/avltree.h @@ -91,6 +91,7 @@ static inline void avltree_destroy(struct avltree *t) } + #define avltree_find(t,d) avltree_get(t,d) #define avltree_insert(t,d) avltree_add(t,d) //#define avltree_walk(t,dir) avltree_foreach(t,dir) diff --git a/src/capwap/bstr.h b/src/capwap/bstr.h index 8198bb82..650f3104 100644 --- a/src/capwap/bstr.h +++ b/src/capwap/bstr.h @@ -24,6 +24,7 @@ #ifndef __BSTR_H #define __BSTR_H +#include #include #include @@ -46,7 +47,7 @@ extern int bstr_to_str(char *dst, bstr_t str,char * def); /** * Return the length of a bstr_t string. */ -#define bstr_len(s) (*(s)) +#define bstr_len(s) (*((uint8_t*)(s))) /** * Return the data of a bstr_t string. @@ -77,6 +78,53 @@ static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len) return len+2; } +static inline uint8_t * bstr16_create(uint8_t *data, uint16_t len) +{ + uint8_t * str = malloc(2+len*sizeof(uint8_t)); + if (!str) + return 0; + *((uint16_t*)str)=len; + memcpy(str+2,data,len); + return str; +} + + + + +#define vendorstr_get_vendor_id(str)\ + ( *((uint32_t*)((str)+2))) + +#define vendorstr_set_vendor_id(str,id)\ + ( *((uint32_t*)((str)+2)) = id) + +#define vendorstr_len(str)\ + (*((uint16_t*)((str)+0))) + +#define vendorstr_set_len(str,len)\ + (*((uint16_t*)((str)+0))=len) + +#define vendorstr_data(str)\ + (((uint8_t*)(str))+6) + +#define vendorstr_size(n)\ + (1+6+(len)*sizeof(uint8_t)) + + +static inline uint8_t * vendorstr_create(uint32_t vendor_id, uint8_t *data, uint8_t len) +{ + uint8_t * str = malloc(vendorstr_size(len)); + if (!str) + return 0; + + vendorstr_set_vendor_id(str,vendor_id); + vendorstr_set_len(str,len); + memcpy(vendorstr_data(str),data,len); + *(vendorstr_data(str)+vendorstr_len(str))=0; + return str; + +} + + #endif diff --git a/src/capwap/bstr_create.c b/src/capwap/bstr_create.c index fc10149f..03c8c5ad 100644 --- a/src/capwap/bstr_create.c +++ b/src/capwap/bstr_create.c @@ -36,7 +36,7 @@ */ uint8_t * bstr_create(uint8_t *data, uint8_t len) { - uint8_t * str = malloc(len*sizeof(uint8_t)); + uint8_t * str = malloc(1+len*sizeof(uint8_t)); if (!str) return 0; *str=len; diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index 015980ad..863df83d 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -65,7 +65,7 @@ enum capwap_states { CW_STATE_DISCOVERY, CW_STATE_JOIN, CW_STATE_CONFIGURE, - CW_STATE_IMAGE, + CW_STATE_IMAGE_DATA, CW_STATE_UPDATE, CW_STATE_RUN }; @@ -227,7 +227,7 @@ struct capwap_ctrlhdr #define CW_ELEM_WTP_NAME 45 #define CW_ELEM_RESERVED_46 46 #define CW_ELEM_WTP_RADIO_STATISTICS 47 -#define CWMSGELEM_WTP_REBOOT_STATISTICS 48 +#define CW_ELEM_WTP_REBOOT_STATISTICS 48 #define CW_ELEM_WTP_STATIC_IP_ADDRESS_INFORMATION 49 #define CW_ELEM_WTP_STATIC_IP_ADDR_INFO 49 @@ -247,11 +247,11 @@ struct capwap_ctrlhdr /* wtp board data subelements */ -#define CWBOARDDATA_MODELNO 0 -#define CWBOARDDATA_SERIALNO 1 -#define CWBOARDDATA_BOARDID 2 -#define CWBOARDDATA_REVISION 3 -#define CWBOARDDATA_MACADDRESS 4 +#define CW_BOARDDATA_MODELNO 0 +#define CW_BOARDDATA_SERIALNO 1 +#define CW_BOARDDATA_BOARDID 2 +#define CW_BOARDDATA_REVISION 3 +#define CW_BOARDDATA_MACADDRESS 4 /* AC Security flags for authentication */ @@ -397,7 +397,7 @@ extern void cwsend_join_response(struct conn *conn, int seqnum, int rc, struct wtpinfo *wtpinfo); -extern void cwread_discovery_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len); +//extern void cwread_discovery_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len); extern void process_join_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len); extern void process_conf_status_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len); @@ -477,18 +477,18 @@ extern int cw_readelem_vendor_specific_payload(void *data, int msgtype, int elem 14 Image Data Error (Invalid Checksum) - 15 Image Data Error (Invalid Data Length) - - 16 Image Data Error (Other Error) - - 17 Image Data Error (Image Already Present) - - 18 Message Unexpected (Invalid in Current State) - - 19 Message Unexpected (Unrecognized Request) */ +#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) +/* + 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_MISSING_MAND_ELEM 20 + /* 21 Failure - Unrecognized Message Element @@ -579,6 +579,33 @@ static inline void cw_set_hdr_hlen(uint8_t *th,int hlen){ 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){ + uint32_t d = cw_get_dword(th); + d &= (0x1f << 9) ^ 0xffffffff; + 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){ + uint32_t d = cw_get_dword(th); + d &= (0x1f << 9) ^ 0xffffffff; + d |= ((rid) & 0x1f) <<14; + cw_set_dword(th,d); +} + + + + /** * Set CAPWAP header flags * @param th pointer to header @@ -718,7 +745,7 @@ static inline int cw_addelem_bstr(uint8_t * dst, uint16_t type, const bstr_t bst } -static inline int cw_addelem_result_code(uint8_t * dst, uint32_t code) +static inline int cw_put_elem_result_code(uint8_t * dst, uint32_t code) { cw_put_dword(dst + 4, code); return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4); @@ -778,6 +805,12 @@ extern int cw_send_configuration_update_response(struct conn *conn, int seqnum, /* cwmsg methods */ +static inline int cw_addelem_result_code(uint8_t * dst, uint32_t code) +{ + cw_put_dword(dst + 4, code); + return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4); +} + #define cwmsg_addelem_vendor_specific_payload(cwmsg,vendor_id, type, data,len) \ (cwmsg)->pos+=cw_addelem_vendor_specific_payload((cwmsg)->msgelems+(cwmsg)->pos,vendor_id,type,data,len) @@ -811,7 +844,14 @@ extern struct cw_str capwap_strings_elem[]; #define cw_strvendor(id) cw_strlist_get_str(capwap_strings_vendor,id) -#define cw_strelemp(p,id) cw_strheap_get((p)->strelem,id) +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,0); +} + +#define cw_strelemp(p,id) cw_strelemp_((p)->strelem,id) extern const char *cw_strlist_get_str(struct cw_str *s, int id); @@ -875,13 +915,12 @@ static inline int cw_put_ac_status(uint8_t *dst, struct cw_ac_status *s){ } -static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint32_t vendor_id,bstr16_t data) +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,vendor_id); - d += cw_put_dword(d, (subelem_id<<16) | bstr16_len(data)); - d += cw_put_data(d,bstr16_data(data),bstr16_len(data)); + 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; } @@ -889,9 +928,20 @@ static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint32_t vend int cw_register_actions_capwap_ac(struct cw_actiondef *def); 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); struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a); +extern int cw_in_check_disc_req(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) ; + +void cw_init_request(struct conn *conn,int msg_id); diff --git a/src/capwap/capwap_actions.h b/src/capwap/capwap_actions.h index 613ce8ed..180397e1 100644 --- a/src/capwap/capwap_actions.h +++ b/src/capwap/capwap_actions.h @@ -46,6 +46,35 @@ CW_ITEM_SESSION_ID, /* ID to use store */ \ 16, 16 /* min/max length */ +#define CW_ACTION_IN_IMAGE_IDENTIFIER \ + CW_ELEM_IMAGE_IDENTIFIER, /* Element ID*/ \ + cw_in_generic, 0, /* start/end callback */ \ + CW_ITEMTYPE_VENDORSTR, /* Type of element */ \ + CW_ITEM_IMAGE_IDENTIFIER, /* ID to use store */ \ + 5, 4096 /* min/max length */ + +#define CW_ACTION_IN_AC_NAME \ + CW_ELEM_AC_NAME, /* Element ID*/ \ + cw_in_generic, 0, /* start/end callback */ \ + CW_ITEMTYPE_STR, /* Type of element */ \ + CW_ITEM_AC_NAME, /* ID to use store */ \ + 1, 1024 /* min/max length */ + +#define CW_ACTION_IN_STATISTICS_TIMER \ + CW_ELEM_STATISTICS_TIMER, /* Element ID*/ \ + cw_in_generic, 0, /* start/end callback */ \ + CW_ITEMTYPE_DWORD, /* Type of element */ \ + CW_ITEM_STATISTICS_TIMER, /* ID to use store */ \ + 1, 1024 /* min/max length */ + +#define CW_ACTION_IN_WTP_REBOOT_STATISTICS \ + CW_ELEM_WTP_REBOOT_STATISTICS, /* Element ID*/ \ + cw_in_generic, 0, /* start/end callback */ \ + CW_ITEMTYPE_DATA, /* Type of element */ \ + CW_ITEM_WTP_REBOOT_STATISTICS, /* ID to use store */ \ + 15, 15 /* min/max length */ + + #define CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE \ CW_ELEM_WTP_FRAME_TUNNEL_MODE, /* Element ID*/ \ cw_in_generic, 0, /* start/end callback */ \ @@ -63,16 +92,24 @@ #define CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD \ CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, /* Element ID */ \ - cw_in_vendor_specific_payload, 0 /* start/end callback*/ \ - - + cw_in_vendor_specific_payload,0, /* start/end callback*/ \ + 0, \ + 0, \ + 0,0 + #define CW_ACTION_IN_WTP_BOARD_DATA \ - CW_ELEM_WTP_BOARD_DATA, /* Element ID */ \ - cw_in_wtp_board_data, 0 /* start/end callback */ \ + CW_ELEM_WTP_BOARD_DATA, /* Element ID */ \ + cw_in_wtp_board_data, 0, /* start/end callback */ \ + 0, \ + CW_ITEM_WTP_BOARD_DATA, \ + 0,0 #define CW_ACTION_IN_WTP_DESCRIPTOR \ - CW_ELEM_WTP_DESCRIPTOR, /* Element ID */ \ - cw_in_wtp_descriptor, 0 /* start/end callback */ \ + CW_ELEM_WTP_DESCRIPTOR, /* Element ID */ \ + cw_in_wtp_descriptor, 0, /* start/end callback */ \ + 0, \ + CW_ITEM_WTP_DESCRIPTOR, \ + 0,0 #endif diff --git a/src/capwap/capwap_actions_ac.c b/src/capwap/capwap_actions_ac.c index 738ce8a1..d7ebfa78 100644 --- a/src/capwap/capwap_actions_ac.c +++ b/src/capwap/capwap_actions_ac.c @@ -28,127 +28,137 @@ cw_action_in_t capwap_actions_ac_in[] = { - /* -------------------------------------------------------------------------------*/ + /* ------------------------------------------------------------------------------- */ /* Message Discovery Request */ - {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, -1, - 0, cw_in_set_state_none} + {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, 0, + 0, cw_in_check_disc_req} , /* Element Discovery Type */ {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ELEM_DISCOVERY_TYPE, - cw_in_generic, 0, CW_ITEMTYPE_BYTE, CW_ITEM_DISCOVERY_TYPE, 1, 1} + cw_in_generic, 0, CW_ITEMTYPE_BYTE, CW_ITEM_DISCOVERY_TYPE, 1, 1, 1} , /* Element WTP Board Data */ - {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA } + {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA, + 1} , /* Element WTP Descriptor */ - {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR } + {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR, + 1} , /* Element Frame Tunnel Mode */ - {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE} + {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, + CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE, 1} , /* Element WTP Mac Tpe */ - {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE} + {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE, 1} , /* Vendor Specific Payload */ - {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD} + {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, + CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD} , - /* -------------------------------------------------------------------------------*/ + /* ------------------------------------------------------------------------------- */ /* Message: Join Request */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, -1, - 0, 0} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, 0, + 0, cw_in_check_join_req} , /* Element Location Data */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_LOCATION_DATA} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_LOCATION_DATA, 1} , /* Element WTP Board Data */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA, 1} , /* Element WTP Board Data */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR, 1} , /* Element WTP Board Data */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_NAME} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_NAME, 1} , /* Element WTP Board Data */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_SESSION_ID} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_SESSION_ID, 1} , /* Element WTP Board Data */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE, 1} , /* Element WTP MAC Type */ - {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE} + {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE, 1} , /* Element Vendor Specific Payload */ {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD} , + /* ------------------------------------------------------------------------------- */ + /* Message: Configuration Status Request */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST, 0, + 0, cw_in_check_join_req} + , + /* Element: AC Name */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST, + CW_ACTION_IN_AC_NAME, 1} + , + /* Element: Statistics Timer */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST, + CW_ACTION_IN_STATISTICS_TIMER, 1} + , -/* - {0, 1, 1, CW_MSG_DISCOVERY_RESPONSE, 0, - 0, 0} + /* Element: Statistics Timer */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST, + CW_ACTION_IN_WTP_REBOOT_STATISTICS, 1} , - {0, 1, 1, CW_MSG_DISCOVERY_RESPONSE, CW_ELEM_AC_NAME, - cw_out_generic, 0, CW_ITEMTYPE_DATA,CW_ITEM_AC_NAME} + /* Element Vendor Specific Payload */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST, + CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD} , - {0, 1, 2, CW_MSG_DISCOVERY_RESPONSE, 0, - 0, 0} + /* Element WTP Board Data */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA, + 1} , -*/ + /* ------------------------------------------------------------------------------- */ - -/* - {CW_VENDOR_ID_CISCO, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_CISCO_RAD_NAME, - cw_in_wtp_name, 0} + /* 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, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST, + CW_ACTION_IN_IMAGE_IDENTIFIER, + 0} + , + + + {0, 0, 0} }; -/* -int cw_out_ac_name(uint8_t * dst, struct cw_item *item) -{ - - printf("Putting out the AC name %s\n", item->data); - - uint8_t *data = item->data; - int len = cw_put_data(dst + 4, data, strlen((char *) data)); - return len + cw_put_elem_hdr(dst, CW_ELEM_AC_NAME, len); -} -*/ - - - cw_action_out_t capwap_actions_ac_out[] = { {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_NONE} , - + /* AC Descriptor */ - {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 - ,CW_ELEM_AC_DESCRIPTOR, cw_out_ac_descriptor, 0} + {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR, + cw_out_ac_descriptor, 0} , /* AC Name */ {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_NAME, 0, - CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_local} + CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_local} , /* List of CAPWAP Control IPv4 and IPv6 addresses */ - {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_CAPWAP_CONTROL_IP_LIST, 0, - 0, cw_out_capwap_control_ip_addrs, cw_out_get_local} + {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_CAPWAP_CONTROL_IP_LIST, 0, + 0, cw_out_capwap_control_ip_addrs, cw_out_get_local} , @@ -158,19 +168,38 @@ cw_action_out_t capwap_actions_ac_out[] = { {CW_MSG_JOIN_RESPONSE, CW_ITEM_NONE} , - /* Result Code */ + /* Result Code */ {CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE, 0, - CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_local} + CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_local, 1} , - + /* AC Descriptor */ - {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 - ,CW_ELEM_AC_DESCRIPTOR, cw_out_ac_descriptor, 0} + {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR, + cw_out_ac_descriptor, 0, 1} + , + + /* AC Name */ + {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_NAME, 0, + CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_local} , + /* ------------------------------------------------------------------------------- + * 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, cw_out_generic, cw_out_get_local, 1} + , + + + + /* End of list */ {0, 0} }; @@ -190,12 +219,12 @@ int cw_register_actions_capwap_ac(struct cw_actiondef *def) cw_actionlist_in_register_actions(def->in, capwap_actions_ac_in); cw_actionlist_out_register_actions(def->out, capwap_actions_ac_out); - int rc ; - rc = cw_strheap_register_strings(def->strmsg,capwap_strings_msg); - rc += cw_strheap_register_strings(def->strelem,capwap_strings_elem); + int rc; + rc = cw_strheap_register_strings(def->strmsg, capwap_strings_msg); + rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem); - printf("Registered %d strings\n",rc); + printf("Registered %d strings\n", rc); return 1; } diff --git a/src/capwap/capwap_cisco.h b/src/capwap/capwap_cisco.h index 1e0d2aa5..ff48978b 100644 --- a/src/capwap/capwap_cisco.h +++ b/src/capwap/capwap_cisco.h @@ -191,6 +191,7 @@ int cw_readelem_cisco_wtp_radio_cfg(int elem_id,uint8_t *elem, int len,struct ra int cw_addelem_cisco_wtp_radio_cfg(uint8_t*dst,struct radioinfo * ri); extern int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst) ; +int cw_in_cisco_image_identifier(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len); diff --git a/src/capwap/capwap_items.h b/src/capwap/capwap_items.h index 9e941f90..43743c0e 100644 --- a/src/capwap/capwap_items.h +++ b/src/capwap/capwap_items.h @@ -23,6 +23,8 @@ enum capwap_items { CW_ITEM_WTP_BOOTLOADER_VERSION, CW_ITEM_WTP_OTHERSOFTWARE_VENDOR, CW_ITEM_WTP_OTHERSOFTWARE_VERSION, + CW_ITEM_WTP_BOARD_DATA, + CW_ITEM_WTP_DESCRIPTOR, CW_ITEM_AC_NAME, CW_ITEM_AC_DESCRIPTOR, @@ -39,12 +41,20 @@ enum capwap_items { CW_ITEM_SESSION_ID, CW_ITEM_AC_TIMESTAMP, + CW_ITEM_STATISTICS_TIMER, + CW_ITEM_WTP_REBOOT_STATISTICS, + CW_ITEM_IMAGE_IDENTIFIER, + /* CIPWAP and Cisco */ - CW_ITEM_WTP_GROUP_NAME + CW_ITEM_WTP_GROUP_NAME, + /* Other Items */ + CW_ITEM_AC_IMAGE_DIR, /* Path where image WTP images are stored */ + CW_ITEM_WTP_IMAGE_FILENAME /* Full path of image filename */ + }; diff --git a/src/capwap/capwap_strings_elem.c b/src/capwap/capwap_strings_elem.c index e02bad9c..434e2e49 100644 --- a/src/capwap/capwap_strings_elem.c +++ b/src/capwap/capwap_strings_elem.c @@ -54,7 +54,7 @@ struct cw_str capwap_strings_elem[] = { {CW_ELEM_WTP_NAME, "WTP Name"}, {CW_ELEM_RESERVED_46, "Reserved 46"}, {CW_ELEM_WTP_RADIO_STATISTICS, "WTP Radio Statistics"}, - {CWMSGELEM_WTP_REBOOT_STATISTICS, "WTP Reboot Statistics"}, + {CW_ELEM_WTP_REBOOT_STATISTICS, "WTP Reboot Statistics"}, {CW_ELEM_WTP_STATIC_IP_ADDRESS_INFORMATION, "WTP Static IP Address Information"}, diff --git a/src/capwap/cipwap_actions_ac.c b/src/capwap/cipwap_actions_ac.c index aba47269..14083d31 100644 --- a/src/capwap/cipwap_actions_ac.c +++ b/src/capwap/cipwap_actions_ac.c @@ -9,6 +9,12 @@ *brief CIPWAP Actions */ +#define CW_ACTION_IN_CISCO_IMAGE_IDENTIFIER \ + CW_ELEM_IMAGE_IDENTIFIER, /* Element ID*/ \ + cw_in_cisco_image_identifier, 0, /* start/end callback */ \ + CW_ITEMTYPE_VENDORSTR, /* Type of element */ \ + CW_ITEM_IMAGE_IDENTIFIER, /* ID to use store */ \ + 1, 4096 /* min/max length */ cw_action_in_t cipwap_actions_ac_in[] = { @@ -26,6 +32,15 @@ cw_action_in_t cipwap_actions_ac_in[] = { cw_in_generic, 0, CW_ITEMTYPE_STR,CW_ITEM_WTP_GROUP_NAME,1,512} , + /* ------------------------------------------------------------------------------- + * Image Data Request - Conig State + */ + + {0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST, + CW_ACTION_IN_CISCO_IMAGE_IDENTIFIER, + 0} + , + {0,0,0} @@ -39,7 +54,6 @@ cw_action_out_t cipwap_actions_ac_out[] = { * Discovery Response OUT */ - /* AC Descriptor (Cisco) */ {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 , CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0} @@ -51,6 +65,17 @@ cw_action_out_t cipwap_actions_ac_out[] = { CW_CISCO_AP_TIMESYNC, cw_out_cisco_ap_timesync, 0} , + /* ------------------------------------------------------------------------------- + * Join Response OUT + */ + + /* AC Descriptor (Cisco) */ + {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 , + CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0} + , + + + {0,0,0} diff --git a/src/capwap/conn.h b/src/capwap/conn.h index 630bb819..a15c5044 100644 --- a/src/capwap/conn.h +++ b/src/capwap/conn.h @@ -38,6 +38,7 @@ #include "action.h" #include "itemstore.h" +#include "intavltree.h" /** * Connection Object @@ -53,6 +54,9 @@ struct conn { A WTP holds here data about it's AC */ cw_itemstore_t remote; + /** Counter for mandatory message elements */ + struct avltree *mand; + struct cw_actiondef *actions; @@ -227,5 +231,9 @@ struct cwrmsg *conn_wait_for_request(struct conn *conn, int *msglist, time_t tim void conn_init(struct conn *conn); +extern int cw_read_messages(struct conn *conn); + + + #endif /* __CONLIST_H */ diff --git a/src/capwap/conn_process_packet.c b/src/capwap/conn_process_packet.c index bfe9f2af..84fa4f19 100644 --- a/src/capwap/conn_process_packet.c +++ b/src/capwap/conn_process_packet.c @@ -232,8 +232,8 @@ void conn_process_packet(struct conn * conn, uint8_t *packet, int len,int (*cb)( // extern int cw_process_msg(struct conn * conn,uint8_t*msg,int len); // cw_process_msg(conn,f+4,*(uint32_t*)f); -printf("Received a fragmented packetm should process it"); -exit(0); +//printf("Received a fragmented packetm should process it"); +//exit(0); /* if (!cwrmsg_init_ctrlhdr(conn,&cwrmsg,f+4,*(uint32_t*)f)){ @@ -261,3 +261,23 @@ exit(0); return; } + +/** + * Used as main message loop + */ +int cw_read_messages(struct conn *conn) +{ + uint8_t buf[2024]; + int len = 2024; + + int n = conn->read(conn, buf, len); + if (n<0 ) + return n; + + if (n > 0) + conn_process_packet(conn, buf, n, cw_process_msg, conn); + +} + + + diff --git a/src/capwap/cw_dbg_elem.c b/src/capwap/cw_dbg_elem.c index b8ae1d2c..27b38885 100644 --- a/src/capwap/cw_dbg_elem.c +++ b/src/capwap/cw_dbg_elem.c @@ -1,3 +1,5 @@ + + #include "cw_log.h" #include "capwap.h" #include "capwap_cisco.h" diff --git a/src/capwap/cw_in_generic.c b/src/capwap/cw_in_generic.c index 3787a808..ea2fcdab 100644 --- a/src/capwap/cw_in_generic.c +++ b/src/capwap/cw_in_generic.c @@ -2,36 +2,23 @@ #include "action.h" #include "cw_log.h" #include "itemstore.h" +#include "capwap.h" -int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len) -{ - switch (item_type) { - case CW_ITEMTYPE_BYTE: - cw_itemstore_set_byte(itemstore,item_id,*data); - break; - - case CW_ITEMTYPE_STR: - cw_itemstore_set_strn(itemstore,item_id,(char*)data,len); - break; - case CW_ITEMTYPE_BSTR: - cw_itemstore_set_bstrn(itemstore,item_id,data,len); - break; - - - } - return 0; -} - int cw_in_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len) { if (lenmin_len) { cw_dbg(DBG_ELEM_ERR,"Message element too short, %d < %d", len,a->min_len); return 0; } + if (len>a->max_len) { + cw_dbg(DBG_ELEM_ERR,"Message element too big, %d > %d", len,a->max_len); + return 0; + } + cw_itemstore_set(conn->remote,a->item_id,a->itemtype,data,len); - + return 0; } diff --git a/src/capwap/cw_in_wtp_board_data.c b/src/capwap/cw_in_wtp_board_data.c index 43ba4135..ece5fdd6 100644 --- a/src/capwap/cw_in_wtp_board_data.c +++ b/src/capwap/cw_in_wtp_board_data.c @@ -54,25 +54,25 @@ static void readsubelems_wtp_board_data(cw_itemstore_t itemstore, uint8_t * msge sublen); switch (subtype) { - case CWBOARDDATA_MODELNO: + case CW_BOARDDATA_MODELNO: cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MODELNO, msgelem + i, sublen); break; - case CWBOARDDATA_SERIALNO: + case CW_BOARDDATA_SERIALNO: cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_SERIALNO, msgelem + i, sublen); break; - case CWBOARDDATA_MACADDRESS: + case CW_BOARDDATA_MACADDRESS: cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MACADDRESS, msgelem + i, sublen); break; - case CWBOARDDATA_BOARDID: + case CW_BOARDDATA_BOARDID: cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID, msgelem + i, sublen); break; - case CWBOARDDATA_REVISION: + case CW_BOARDDATA_REVISION: cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_REVISION, msgelem + i, sublen); default: diff --git a/src/capwap/cw_log_debug.c b/src/capwap/cw_log_debug.c index 091a2c1f..59d778cc 100644 --- a/src/capwap/cw_log_debug.c +++ b/src/capwap/cw_log_debug.c @@ -361,6 +361,7 @@ void lw_dbg_elem_(int msg_id, int elem_id, const uint8_t * elem_data, int elem_l } +/* void cw_dbg_missing_mand_elems_(struct conn *conn, int msgtype, int *mand) { if (!cw_dbg_is_level(DBG_CW_RFC)) @@ -372,3 +373,4 @@ void cw_dbg_missing_mand_elems_(struct conn *conn, int msgtype, int *mand) cw_dbg(DBG_CW_RFC, "Missing msgelems in %s: %s", cw_strmsg(msgtype), str); } } +*/ diff --git a/src/capwap/cw_msg_init.c b/src/capwap/cw_msg_init.c index 92b8164e..794e1637 100644 --- a/src/capwap/cw_msg_init.c +++ b/src/capwap/cw_msg_init.c @@ -32,6 +32,4 @@ void cw_init_response(struct conn * conn, uint8_t *req) cw_set_msg_type(dmsgptr,cw_get_msg_type(msgptr)+1); cw_set_msg_seqnum(dmsgptr,cw_get_msg_seqnum(msgptr)); cw_set_msg_flags(dmsgptr,0); - - } diff --git a/src/capwap/cw_out_ac_descriptor.c b/src/capwap/cw_out_ac_descriptor.c index e5e723d6..875a989a 100644 --- a/src/capwap/cw_out_ac_descriptor.c +++ b/src/capwap/cw_out_ac_descriptor.c @@ -38,7 +38,7 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst i = cw_itemstore_get(conn->local,CW_ITEM_AC_HARDWARE_VERSION); if ( i ) { - d += cw_put_version(d,CW_SUBELEM_AC_HARDWARE_VERSION,*((uint32_t*)(i->data)),i->data+4); + 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."); @@ -48,7 +48,7 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION); if ( i ) { - d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,*((uint32_t*)(i->data)),i->data+4); + 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."); diff --git a/src/capwap/cw_out_cisco_ac_descriptor.c b/src/capwap/cw_out_cisco_ac_descriptor.c index 5dceefc1..a823150a 100644 --- a/src/capwap/cw_out_cisco_ac_descriptor.c +++ b/src/capwap/cw_out_cisco_ac_descriptor.c @@ -24,7 +24,7 @@ int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_ i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION); if ( i ) { - d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,*((uint32_t*)(i->data)),i->data+4); + d += cw_put_version(d,1,i->data); } else { cw_dbg(DBG_ELEM_ERR, "Can't send software version in AC descriptor, not set."); diff --git a/src/capwap/cw_out_generic.c b/src/capwap/cw_out_generic.c index 6c0278df..3ead2172 100644 --- a/src/capwap/cw_out_generic.c +++ b/src/capwap/cw_out_generic.c @@ -4,6 +4,8 @@ #include "capwap.h" #include "capwap_items.h" +#include "cw_log.h" + int cw_put_item(uint8_t *dst,struct cw_item*item) { @@ -31,7 +33,6 @@ int cw_out_generic(struct conn *conn,struct cw_action_out *a,uint8_t *dst) // ,s item = a->get (conn,a); } - printf("Out generic item %p\n",item); /* Size for msg elem header depends on vendor specific payload */ @@ -39,13 +40,14 @@ int cw_out_generic(struct conn *conn,struct cw_action_out *a,uint8_t *dst) // ,s int len; - if ( !item ) - len=0; + if ( !item ){ + if (a->mand){ + cw_log(LOG_ERR,"Cannot send mandatory message element %d",a->elem_id); + } + return 0; + } else{ - printf("Putting it\n"); - printf("To put: %d %s\n",len,item->data); len = cw_put_item(dst+start,item); - printf("Putted: %d %s\n",len,item->data); } diff --git a/src/capwap/cw_process_msg.c b/src/capwap/cw_process_msg.c index 1b4f7c43..553d3170 100644 --- a/src/capwap/cw_process_msg.c +++ b/src/capwap/cw_process_msg.c @@ -19,7 +19,7 @@ /** * @file * @brief Processing of incomming messaages. - */ + */ #include #include @@ -42,32 +42,51 @@ int conn_send_msg(struct conn *conn, uint8_t * rawmsg); /** * Init response message header - */ -void cw_init_response(struct conn * conn, uint8_t *req) + */ +void cw_init_response(struct conn *conn, uint8_t * req) { - uint8_t *buffer=conn->resp_buffer; + uint8_t *buffer = conn->resp_buffer; int shbytes = cw_get_hdr_msg_offset(req); int dhbytes; - memcpy(buffer,req,shbytes); - cw_set_hdr_hlen(buffer,2); - cw_set_hdr_flags(buffer,CW_FLAG_HDR_M,1); + memcpy(buffer, req, shbytes); + cw_set_hdr_hlen(buffer, 2); + cw_set_hdr_flags(buffer, CW_FLAG_HDR_M, 1); dhbytes = cw_get_hdr_msg_offset(buffer); - uint8_t * msgptr = req+shbytes; - uint8_t * dmsgptr = buffer+dhbytes; + uint8_t *msgptr = req + shbytes; + uint8_t *dmsgptr = buffer + dhbytes; + + cw_set_msg_type(dmsgptr, cw_get_msg_type(msgptr) + 1); + cw_set_msg_seqnum(dmsgptr, cw_get_msg_seqnum(msgptr)); + cw_set_msg_flags(dmsgptr, 0); +} + +void cw_init_request(struct conn *conn, int msg_id) +{ + uint8_t *buffer = conn->req_buffer; + + cw_put_dword(buffer + 0, 0); + cw_put_dword(buffer + 4, 0); + cw_set_hdr_preamble(buffer, 0); + cw_set_hdr_hlen(buffer, 2); + cw_set_hdr_wbid(buffer, 1); + cw_set_hdr_rid(buffer, 0); + uint8_t *msgptr = cw_get_hdr_msg_offset(buffer) + buffer; + cw_set_msg_type(msgptr, msg_id); + cw_set_msg_flags(msgptr, 0); + cw_set_msg_elems_len(msgptr, 0); + - cw_set_msg_type(dmsgptr,cw_get_msg_type(msgptr)+1); - cw_set_msg_seqnum(dmsgptr,cw_get_msg_seqnum(msgptr)); - cw_set_msg_flags(dmsgptr,0); } /** * send a response - */ + */ int cw_send_response(struct conn *conn, uint8_t * rawmsg, int len) { cw_init_response(conn, rawmsg); - cw_put_msg(conn,conn->resp_buffer); + if (cw_put_msg(conn, conn->resp_buffer) == -1) + return 0; conn_send_msg(conn, conn->resp_buffer); return 1; } @@ -82,17 +101,17 @@ int cw_send_response(struct conn *conn, uint8_t * rawmsg, int len) * @param rawmsg the received request message, which the response belongs to * @pqram result_code result code to send * @return 1 - */ -int cw_send_error_response(struct conn *conn,uint8_t *rawmsg, uint32_t result_code) + */ +int cw_send_error_response(struct conn *conn, uint8_t * rawmsg, uint32_t result_code) { - cw_init_response(conn,rawmsg); - + cw_init_response(conn, rawmsg); + uint8_t *out = conn->resp_buffer; uint8_t *dst = cw_get_hdr_msg_elems_ptr(out); - int l = cw_put_elem_result_code(dst,result_code); - - cw_set_msg_elems_len(out+cw_get_hdr_msg_offset(out), l); + int l = cw_put_elem_result_code(dst, result_code); + + cw_set_msg_elems_len(out + cw_get_hdr_msg_offset(out), l); conn_send_msg(conn, conn->resp_buffer); @@ -102,7 +121,7 @@ int cw_send_error_response(struct conn *conn,uint8_t *rawmsg, uint32_t result_co int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) { - struct cw_action_in as, *af,*afm; + struct cw_action_in as, *af, *afm; uint8_t *msg_ptr = rawmsg + cw_get_hdr_msg_offset(rawmsg); @@ -138,7 +157,7 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) as.msg_id = cw_get_msg_id(msg_ptr); as.vendor_id = 0; as.elem_id = 0; - as.proto=0; + as.proto = 0; /* Search for state/message combination */ @@ -146,30 +165,33 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) if (!afm) { /* Throw away unexpected response messages */ - if (!(as.msg_id &1)) { - cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unexpected, discarding.", - as.msg_id, cw_strmsg(as.msg_id)); + if (!(as.msg_id & 1)) { + cw_dbg(DBG_MSG_ERR, + "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; } /* Request message not found in current state, check if we know - anything else about this message type */ - const char *str = cw_strheap_get(conn->actions->strmsg,as.msg_id); - int result_code=0; + anything else about this message type */ + const char *str = cw_strheap_get(conn->actions->strmsg, as.msg_id); + int result_code = 0; if (str) { /* Message found, but it was in wrong state */ - cw_dbg(DBG_MSG_ERR, "Message type %d (%s) not allowed in %s State.", - as.msg_id, cw_strmsg(as.msg_id), cw_strstate(as.capwap_state)); - result_code = CW_RESULT_MSG_INVALID_IN_CURRENT_STATE; - } - else { + cw_dbg(DBG_MSG_ERR, + "Message type %d (%s) not allowed in %s State.", as.msg_id, + cw_strmsg(as.msg_id), cw_strstate(as.capwap_state)); + result_code = CW_RESULT_MSG_INVALID_IN_CURRENT_STATE; + } else { /* Message is unknown */ cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.", - as.msg_id, cw_strmsg(as.msg_id), cw_strstate(as.capwap_state)); + as.msg_id, cw_strmsg(as.msg_id), + cw_strstate(as.capwap_state)); result_code = CW_RESULT_MSG_UNRECOGNIZED; - + } - cw_send_error_response(conn,rawmsg,result_code); + cw_send_error_response(conn, rawmsg, result_code); return 0; } @@ -182,6 +204,7 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) uint8_t *elems_ptr = cw_get_msg_elems_ptr(msg_ptr); uint8_t *elem; + /* avltree to bag the found mandatory elements */ conn->mand = intavltree_create(); /* iterate through message elements */ @@ -190,7 +213,8 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) as.elem_id = cw_get_elem_id(elem); int elem_len = cw_get_elem_len(elem); - cw_dbg_elem(conn,as.msg_id, as.elem_id, cw_get_elem_data(elem), elem_len); + cw_dbg_elem(conn, as.msg_id, as.elem_id, cw_get_elem_data(elem), + elem_len); af = cw_actionlist_in_get(conn->actions->in, &as); @@ -200,11 +224,11 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) as.elem_id, as.msg_id, cw_strmsg(as.msg_id)); continue; } - - if (af->mand){ + + if (af->mand) { /* add found mandatory message element - to mand list */ - intavltree_add(conn->mand,af->item_id); + to mand list */ + intavltree_add(conn->mand, af->item_id); } if (af->start) { @@ -213,19 +237,18 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) } - int result_code=0; + int result_code = 0; if (afm->end) { - result_code=afm->end(conn, afm, rawmsg, len); + result_code = afm->end(conn, afm, rawmsg, len); } /* if we've got a request message, we have to send a response message */ if (as.msg_id & 1) { - if ( result_code>0 ) { + if (result_code > 0) { /* the end method gave us an result code, so send an error message */ - cw_send_error_response(conn,rawmsg,result_code); - } - else{ + cw_send_error_response(conn, rawmsg, result_code); + } else { /* regular response message */ cw_send_response(conn, rawmsg, len); } diff --git a/src/capwap/cw_put_msg.c b/src/capwap/cw_put_msg.c index ee119cd1..5acbc6d8 100644 --- a/src/capwap/cw_put_msg.c +++ b/src/capwap/cw_put_msg.c @@ -25,6 +25,8 @@ #include "capwap_items.h" #include "conn.h" +#include "cw_log.h" + struct args{ struct conn * conn; uint32_t msg_id; @@ -48,6 +50,7 @@ static int action_cb(void *args_param, void *a_param) if (a->item_id == CW_ITEM_NONE) { /* Start of message */ + args->len=0; return 1; } @@ -94,7 +97,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout) args.conn = conn; args.msg_id = as.msg_id; args.dst = msgptr+8; - args.len=0; + args.len=-1; avltree_foreach_from_asc(conn->actions->out, &as, action_cb, &args); @@ -104,6 +107,13 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout) printf ("Total elems len = %d\n",args.len); printf("Total msg len = %d\n",cw_get_hdr_msg_total_len(rawout)); */ + + if (args.len==-1) { + cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.", + args.msg_id,cw_strmsg(args.msg_id)); + + } + return args.len; } diff --git a/src/capwap/cw_readelem_wtp_reboot_statistics.c b/src/capwap/cw_readelem_wtp_reboot_statistics.c index 564ddd70..7a6e02b9 100644 --- a/src/capwap/cw_readelem_wtp_reboot_statistics.c +++ b/src/capwap/cw_readelem_wtp_reboot_statistics.c @@ -23,7 +23,7 @@ int cw_readelem_wtp_reboot_statistics(struct wtp_reboot_statistics *s, int type,uint8_t *msgelem, int len) { - if (type != CWMSGELEM_WTP_REBOOT_STATISTICS) + if (type != CW_ELEM_WTP_REBOOT_STATISTICS) return 0; s->reboot_count=ntohs(*((uint16_t*)(msgelem+0))); diff --git a/src/capwap/cw_util.c b/src/capwap/cw_util.c index 321714e9..6da75acc 100644 --- a/src/capwap/cw_util.c +++ b/src/capwap/cw_util.c @@ -55,6 +55,7 @@ void cw_get_missing_mand_elems(char *dst, int *l) } } +/* int cw_is_missing_mand_elems(int *l) { int i; @@ -66,4 +67,4 @@ int cw_is_missing_mand_elems(int *l) return 0; } - +*/ diff --git a/src/capwap/cw_util.h b/src/capwap/cw_util.h index 3c6d5c2b..b280bbfe 100644 --- a/src/capwap/cw_util.h +++ b/src/capwap/cw_util.h @@ -56,7 +56,7 @@ extern int cw_rand(uint8_t*dst, int len); /* functions used to "rfc-verify" message elements */ void cw_mand_elem_found(int *l,int type); -int cw_is_missing_mand_elems(int *l); +//int cw_is_missing_mand_elems(int *l); void cw_get_missing_mand_elems(char *dst, int *l); diff --git a/src/capwap/cwread_configuration_status_request.c b/src/capwap/cwread_configuration_status_request.c index e5273471..b00c1a16 100644 --- a/src/capwap/cwread_configuration_status_request.c +++ b/src/capwap/cwread_configuration_status_request.c @@ -74,7 +74,7 @@ void cwread_configuration_status_request(struct wtpinfo * wtpinfo, uint8_t * msg { int mand[] = { CW_ELEM_AC_NAME, - CWMSGELEM_WTP_REBOOT_STATISTICS, + CW_ELEM_WTP_REBOOT_STATISTICS, CWMSGELEM_RADIO_ADMINISTRATIVE_STATE, CW_ELEM_STATISTICS_TIMER, -1}; diff --git a/src/capwap/dbg.h b/src/capwap/dbg.h index f2b076d3..e1ad3ea7 100644 --- a/src/capwap/dbg.h +++ b/src/capwap/dbg.h @@ -4,6 +4,7 @@ #include "conn.h" void cw_dbg_elem_(struct conn * conn, int msg, int msgelem, const uint8_t * msgbuf, int len); +void cw_dbg_missing_mand(int level,struct conn *conn,cw_action_in_t ** ml,int n,cw_action_in_t *a); #ifdef WITH_CW_LOG_DEBUG diff --git a/src/capwap/dtls.h b/src/capwap/dtls.h index fa57854a..baaf5c8f 100644 --- a/src/capwap/dtls.h +++ b/src/capwap/dtls.h @@ -15,11 +15,13 @@ along with Foobar. If not, see . */ +#ifndef __CW_DTLS_H +#define __CW_DTLS_H + + #include #include "conn.h" -#ifndef __DTLS_H -#define __DTLS_H struct dtls_ssl_cert { diff --git a/src/capwap/itemstore.c b/src/capwap/itemstore.c index 70aed18f..adc65c8a 100644 --- a/src/capwap/itemstore.c +++ b/src/capwap/itemstore.c @@ -3,6 +3,7 @@ #include #include "itemstore.h" +#include "capwap.h" @@ -13,7 +14,8 @@ static inline void cw_itemstore_del_data(void *e) case CW_ITEMTYPE_DATA: case CW_ITEMTYPE_STR: case CW_ITEMTYPE_BSTR: - case CW_ITEMTYPE_VERSION: + case CW_ITEMTYPE_BSTR16: + case CW_ITEMTYPE_VENDORSTR: case CW_ITEMTYPE_FUN: free(item->data); break; @@ -104,12 +106,28 @@ int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str) return 1; } -int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n) +int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t *data, int len) { struct cw_item *i = cw_item_create(s, id); if (!i) return 0; i->type = CW_ITEMTYPE_DATA; + i->data = malloc(len); + if(!i->data) + return 1; + memcpy(i->data,data,len); + return 1; +} + + + + +int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n) +{ + struct cw_item *i = cw_item_create(s, id); + if (!i) + return 0; + i->type = CW_ITEMTYPE_STR; i->data = strndup(str, n); return 1; } @@ -134,6 +152,20 @@ int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int le return 1; } +int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len) +{ + struct cw_item *i = cw_item_create(s, id); + if (!i) + return 0; + i->type = CW_ITEMTYPE_BSTR16; + i->data = bstr16_create(data, len); + return 1; +} + + + + + int cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr) { @@ -145,23 +177,15 @@ int cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr) return 1; } -int cw_itemstore_set_version(cw_itemstore_t s, uint32_t id, uint32_t vendor_id, - uint8_t * versionstr, int len) +int cw_itemstore_set_vendorstr(cw_itemstore_t s, uint32_t id, uint32_t vendor_id, + uint8_t * vendorstr, int len) { struct cw_item *i = cw_item_create(s, id); if (!i) return 0; - i->type = CW_ITEMTYPE_VERSION; - - uint8_t *ptr = malloc(bstr16_size(len) + 4); - i->data = ptr; - - if (!ptr) - return 1; - - *((uint32_t *) ptr) = vendor_id; - bstr16_ncpy(ptr + 4, versionstr, len); - + + i->type = CW_ITEMTYPE_VENDORSTR; + i->data = vendorstr_create(vendor_id,vendorstr,len); return 1; } @@ -239,3 +263,33 @@ void cw_item_release_data_ptr(struct cw_item *item, void *data) } } + + + +int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len) +{ + switch (item_type) { + case CW_ITEMTYPE_BYTE: + cw_itemstore_set_byte(itemstore,item_id,*data); + break; + + case CW_ITEMTYPE_STR: + cw_itemstore_set_strn(itemstore,item_id,(char*)data,len); + break; + case CW_ITEMTYPE_BSTR: + cw_itemstore_set_bstrn(itemstore,item_id,data,len); + break; + case CW_ITEMTYPE_DATA: + cw_itemstore_set_data(itemstore,item_id,data,len); + break; + case CW_ITEMTYPE_VENDORSTR: + cw_itemstore_set_vendorstr(itemstore,item_id, + cw_get_dword(data),data+4,len-4); + + + } + return 0; +} + + + diff --git a/src/capwap/itemstore.h b/src/capwap/itemstore.h index 007c7065..545efd36 100644 --- a/src/capwap/itemstore.h +++ b/src/capwap/itemstore.h @@ -26,8 +26,11 @@ #include "avltree.h" #include "bstr.h" -enum cw_cfgtem_types{ - CW_ITEMTYPE_NONE=0, +/** + * Item types supported in item store + */ +enum cw_cfgtem_types { + CW_ITEMTYPE_NONE = 0, CW_ITEMTYPE_BYTE, CW_ITEMTYPE_WORD, CW_ITEMTYPE_DWORD, @@ -35,7 +38,10 @@ enum cw_cfgtem_types{ CW_ITEMTYPE_CONST_DATA, CW_ITEMTYPE_STR, CW_ITEMTYPE_BSTR, - CW_ITEMTYPE_VERSION, + CW_ITEMTYPE_BSTR16, + /** Vendor string contains a Vendor ID, followed by bstr16 data, containing + the string. */ + CW_ITEMTYPE_VENDORSTR, CW_ITEMTYPE_AVLTREE, CW_ITEMTYPE_FUN, @@ -52,25 +58,52 @@ struct cw_item { }; }; -typedef struct avltree * cw_itemstore_t; +typedef struct avltree *cw_itemstore_t; -static inline struct cw_item * cw_itemstore_get(cw_itemstore_t s, uint32_t id) +static inline struct cw_item *cw_itemstore_get(cw_itemstore_t s, uint32_t id) { struct cw_item i; - i.id=id; - return avltree_get(s,&i); + i.id = id; + return avltree_get(s, &i); } extern cw_itemstore_t cw_itemstore_create(); -extern int cw_itemstore_set_strn(cw_itemstore_t s,uint32_t id,const char *str,int n); -extern int cw_itemstore_set_str(cw_itemstore_t s,uint32_t id,const char *str); -extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void*ptr); -extern int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t *data,int len); -extern int cw_itemstore_set_dword(cw_itemstore_t s,uint32_t id,uint32_t dword); -extern int cw_itemstore_set_byte(cw_itemstore_t s,uint32_t id,uint8_t byte); -extern int cw_itemstore_set_version(cw_itemstore_t s, uint32_t id, uint32_t vendor_id, uint8_t * versionstr, int len); +extern int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n); +extern int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str); +extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr); +extern int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len); +extern int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword); +extern int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word); +extern int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte); +extern int cw_itemstore_set_vendorstr(cw_itemstore_t s, uint32_t id, + uint32_t vendor_id, uint8_t * vendorstr, + int len); +int cw_itemstore_set_avltree(cw_itemstore_t s, uint32_t id, struct avltree *t); +int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len); + + +extern int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t * data, + int len); + +static inline char * cw_itemstore_get_str(cw_itemstore_t s,uint32_t id) { + struct cw_item *i = cw_itemstore_get(s,id); + if (!i) + return NULL; + return i->data; + +}; + +static inline struct avltree * cw_itemstore_get_avltree(cw_itemstore_t s,uint32_t id){ + struct cw_item *i = cw_itemstore_get(s,id); + if (!i) + return NULL; + if (i->type!=CW_ITEMTYPE_AVLTREE) + return NULL; + return i->data; +} + extern void *cw_item_get_data_ptr(struct cw_item *item); extern void cw_item_release_data_ptr(struct cw_item *item, void *data); @@ -80,5 +113,6 @@ int cw_itemstore_set_fun(cw_itemstore_t s, uint32_t id, void *(*funget) (void *arg), void (*funfree) (void *arg, void *data), void *arg); +int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len); #endif diff --git a/src/capwap/strheap.h b/src/capwap/strheap.h index cc0397b0..6de3d07d 100644 --- a/src/capwap/strheap.h +++ b/src/capwap/strheap.h @@ -17,14 +17,13 @@ extern cw_strheap_t cw_strheap_create(); extern int cw_strheap_register_strings(cw_strheap_t h, struct cw_str *s); static inline const char * cw_strheap_get(cw_strheap_t h, int id) { - struct cw_str s, *rc; + struct cw_str s; s.id=id; - rc = avltree_get(h,&s); - if (rc) - return rc->str; - return cw_strheap_get(h,0); + struct cw_str *r = avltree_get(h,&s); + if (r) + return r->str; + return NULL; } - #endif diff --git a/src/wtp/Makefile b/src/wtp/Makefile index 0ff6f610..dd9763d2 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -6,7 +6,7 @@ ifndef CC endif - +V=0 CFLAGS+=-DWITH_RMAC_SUPPORT CFLAGS+=-DWITH_IPV6 @@ -21,6 +21,7 @@ endif CFLAGS += -Os -Wall -g +CFLAGS += -Os -Wall LDFLAGS += -L../../src/capwap/$(ARCH) @@ -103,7 +104,7 @@ ALL=wtp all: $(ALL) -Q= +Q=@ E=echo ifeq ($(V), 1) Q= @@ -111,8 +112,8 @@ E=true endif %.o: %.c - $(Q)$(CC) -c -o $@ $(CFLAGS) $< @$(E) " CC " $< + $(Q)$(CC) -c -o $@ $(CFLAGS) $< wtp: $(BCHECK) $(OBJS) diff --git a/src/wtp/configure.c b/src/wtp/configure.c index a3033e89..27423e43 100644 --- a/src/wtp/configure.c +++ b/src/wtp/configure.c @@ -6,6 +6,7 @@ int configure() { +/* struct conn * conn = get_conn(); struct wtpinfo * wtpinfo = get_wtpinfo(); @@ -22,7 +23,7 @@ int configure() printf("Got change resp %p\n",cwrmsg); - +*/ } diff --git a/src/wtp/discovery.c b/src/wtp/discovery.c index 139a0d72..ec0a22d1 100644 --- a/src/wtp/discovery.c +++ b/src/wtp/discovery.c @@ -25,253 +25,55 @@ #include "capwap/capwap.h" +#include "capwap/capwap_items.h" #include "capwap/cw_log.h" #include "capwap/wtpinfo.h" #include "capwap/acinfo.h" #include "capwap/sock.h" #include "capwap/cw_util.h" + #include "wtp.h" #include "wtp_conf.h" #include "wtp_interface.h" #include -struct discovery_info{ - ACIPLIST * aciplist; - struct conn * conn; - int response_count; -}; -static int acprint(void *p,void*d) //,int ctr) + +static int run_discovery(struct conn *conn) { + conn->capwap_state=CW_STATE_DISCOVERY; + cw_itemstore_set_byte(conn->local,CW_ITEM_DISCOVERY_TYPE,CW_DISCOVERY_TYPE_UNKNOWN); - ACIP * ip = (ACIP*)d; - char str[100]; - sock_addrtostr((struct sockaddr*)&ip->ip,str,100); - printf("ACIP: %s\n",str); - printf("CTR: %i\n",ip->wtp_count); - return 1; + cw_init_request(conn,CW_MSG_DISCOVERY_REQUEST); + cw_put_msg(conn,conn->req_buffer); + conn_send_msg(conn,conn->req_buffer); + + + time_t timer = cw_timer_start(10); + + while (!cw_timer_timeout(timer) + && conn->capwap_state == CW_STATE_DISCOVERY) { + cw_read_messages(conn); + + } + + + return 0; } -struct ac_info wtp_acinfo; -static int msg_cb(void *priv,struct cwrmsg * cwrmsg) -{ - if (cwrmsg->type != CW_MSG_DISCOVERY_RESPONSE){ - cw_dbg(DBG_ERR,"Expected discovery response, but received %i",cwrmsg->type); - return 1; - } - - struct discovery_info * di = (struct discovery_info*)priv; - -/* - if (di->conn->seqnum != cwrmsg->seqnum){ - cw_log_debug0("Ignoring discovery respone, seqnum=%i, expected seqnum %i",cwrmsg->seqnum,di->conn->seqnum); - return 1; - } -*/ - - - struct ac_info * acinfo = &wtp_acinfo; - memset(acinfo,0,sizeof(struct ac_info)); - - acinfo->aciplist = di->aciplist; - - - - - cwread_discovery_response(acinfo,cwrmsg->msgelems,cwrmsg->msgelems_len); - - - - - - char ai [4096]; - acinfo_print(ai,acinfo); - printf("AC INFO\n%s",ai); - - -//printf("CWRHW: %s\n",sock_hwaddr2str(bstr_data(cwrmsg->rmac),bstr_len(cwrmsg->rmac))); -///exit(0); - - -/* - printf("AC NAME %s\n",acinfo.ac_name); - printf("AC Software version %s\n",acinfo.software_version); - printf("AC Hardwareversion %s\n",acinfo.hardware_version); - - printf("Active wtps: %i\n",acinfo.active_wtps); - printf("Active max wtps: %i\n",acinfo.max_wtps); - - - printf("Got Discovery response\n"); - - printf("ACL COUNT: %i\n",acinfo.aciplist->count); -*/ - aciplist_foreach(acinfo->aciplist,acprint,0); - -// responses++; -// - di->response_count++; - return 1; -} - - -static void rand_sleep(int seconds) -{ - int usecs = seconds * 1000; - uint16_t rnd; - cw_rand((uint8_t*)&rnd,sizeof(rnd)); - uint16_t max = 0-1; - int r = (rnd * usecs) / max; - cw_dbg(DBG_CW_INFO,"Sleeping for %u milliseconds\n",r); - usleep(r*1000); -} - - -static int do_discover_conn(struct conn * conn,struct discovery_info * di) -{ - rand_sleep(conf_max_discovery_interval); - - - struct wtpinfo * wtpinfo; - wtpinfo = get_wtpinfo(); -// wtpinfo_print(wtpinfo); - - -// struct timespec tstart,tcur; - struct radioinfo ri; - memset(&ri,0,sizeof(ri)); - - struct radioinfo * rip = &wtpinfo->radioinfo[0]; - -/* - ri.rmac[0]=6; - ri.rmac[2]=14; - ri.rmac[3]=14; - ri.rmac[4]=14; - ri.rmac[5]=14; - ri.rmac[6]=14; - ri.rmac[7]=14; -*/ - -#ifdef WITH_CW_LOG_DEBUG - char str[100]; - sock_addrtostr((struct sockaddr*)&conn->addr,str,100); -// cw_log_debug0("Sending discovery request to %s",str); -#endif - - int rc; - - do { - conn->capwap_mode=CWMODE_CISCO; - rc = cwsend_discovery_request(conn,rip,wtpinfo); - if (rc<0){ - if (errno == EINTR) - continue; - if (errno == EMSGSIZE){ - conn->mtu-=4; -// cw_log_debug2("Setting mtu to %i",conn->mtu); - continue; - } - } - break; - - }while (rc<0); - - - if (rc < 0 ) - { - char str[100]; - sock_addrtostr((struct sockaddr*)&conn->addr,str,100); - cw_log(LOG_ERR,"Error sending discovery request to %s: %s",str,strerror(errno)); - return 0; - } - - struct connlist * connlist; - connlist = connlist_create(30); - -// clock_gettime(CLOCK_REALTIME,&tstart); -// - int tstart = time(0); - int treset = 0; - do { - char buf[2048]; - int buflen=2048; - struct sockaddr_storage sa; - socklen_t fromlen=sizeof(struct sockaddr_storage); - rc = recvfrom(conn->sock,buf,buflen,0,(struct sockaddr*)&sa,&fromlen); - if (rc<0){ - if (errno==EINTR) - rc=0; - if (errno==EAGAIN) - rc=0; - if (errno==EWOULDBLOCK) - rc=0; - } - if (rc>0) { -#ifdef WITH_CW_LOG_DEBUG - char str[100]; - sock_addrtostr((struct sockaddr*)&sa,str,100); -// cw_log_debug0("Received packet from %s",str); -#endif - - struct conn * rconn; - rconn = connlist_get(connlist,(struct sockaddr*)&sa); - - if (!rconn){ - rconn = conn_create_noq(conn->sock,(struct sockaddr*)&sa); //msg_cb,NULL,0); - // rconn->pmsgarg=conn->pmsgarg; - rconn->mtu = conn->mtu; - rconn->seqnum=conn->seqnum; - connlist_add(connlist,rconn); - } - - conn_process_packet(rconn,(uint8_t*)buf,rc,msg_cb,di); - } - - /* reset discovery timer after we have received the first response */ - if ( di->response_count == 1 && !treset ){ - tstart=time(0); - treset=1; - } - - //clock_gettime(CLOCK_REALTIME,&tcur); -// printf("TTSub: %i %i\n",time(0)-tstart, conf_discovery_interval); - }while(time(0)-tstart < conf_discovery_interval && rc>=0 ); - - - if (rc <0){ - char str[100]; - sock_addrtostr((struct sockaddr*)&conn->addr,str,100); - cw_log(LOG_ERR,"Error sendings discovery request to %s: %s",str,strerror(errno)); - } - - connlist_destroy(connlist); - return 1; -} - - -static int discovery_count; - -ACIPLIST * do_discovery(const char *acaddr) +/** + * Run discovery for on address (eg broadcast 255.255.255.255) + */ +static int cw_run_discovery(struct conn *conn, const char *acaddr) { - /* get an partially intialized connection object - * (seqnum should be set) - * */ - struct conn * conn = get_conn(); - if (!conn){ - cw_log(LOG_ERR,"Can't create conn for %s: %s",acaddr,strerror(errno)); - return 0; - } - - - /* get addr of destination */ + /* get addr of destination */ struct addrinfo hints; struct addrinfo * res,*res0; memset(&hints,0,sizeof(hints)); @@ -285,21 +87,8 @@ ACIPLIST * do_discovery(const char *acaddr) return 0; } - struct discovery_info di; - memset (&di,0,sizeof(struct discovery_info)); - di.aciplist = aciplist_create(); - di.response_count=0; - - for(res=res0; res; res=res->ai_next) { - if ( discovery_count >= conf_max_discoveries){ - sulking_state(); - discovery_count=0; - // cw_log_debug0("Entering discovery state"); - } - discovery_count++; - int sockfd; int opt; @@ -311,39 +100,30 @@ ACIPLIST * do_discovery(const char *acaddr) opt = 1; if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt))<0){ - cw_log(LOG_ERR,"Cant set broadcast sockopt"); + cw_log(LOG_ERR,"Can't set broadcast sockopt"); } sock_set_recvtimeout(sockfd,1); - sock_set_dontfrag(sockfd,0); - di.conn=conn; - sock_copyaddr(&conn->addr,res->ai_addr); conn->sock=sockfd; - do_discover_conn(conn,&di); - - - if ( di.aciplist->count != 0){ - set_sock(sockfd); - break; - } + run_discovery(conn); close(sockfd); - + + } freeaddrinfo(res0); - if (di.aciplist->count){ - cw_dbg(DBG_CW_INFO,"Discovery responses received: %i\n",di.response_count); - return di.aciplist; - - } - - aciplist_destroy(di.aciplist); return 0; } +int discovery() +{ + struct conn * conn = get_conn(); + cw_run_discovery(conn,"255.255.255.255"); + return 0; +} diff --git a/src/wtp/join.c b/src/wtp/join.c index 5524bbdf..7c392348 100644 --- a/src/wtp/join.c +++ b/src/wtp/join.c @@ -13,7 +13,7 @@ #include "capwap/sock.h" #include "capwap/dtls.h" - +/* #define acinfo_log acinfo_log_ void acinfo_log_(int level,const struct ac_info *acinfo,const char * xstr) @@ -175,3 +175,6 @@ printf("Joined with conn %p\n",conn); return 1; } + + +*/ diff --git a/src/wtp/run.c b/src/wtp/run.c index a055a3e6..b55519d3 100644 --- a/src/wtp/run.c +++ b/src/wtp/run.c @@ -14,6 +14,7 @@ #include "wtp_conf.h" +/* static int echo_interval_timer; struct cwrmsg * get_response(struct conn * conn, int type,int seqnum) @@ -34,9 +35,10 @@ struct cwrmsg * get_response(struct conn * conn, int type,int seqnum) return 0; } +*/ - +/* struct cwrmsg * send_request(struct conn * conn,struct cwmsg *cwmsg) { int i; @@ -61,10 +63,11 @@ struct cwrmsg * send_request(struct conn * conn,struct cwmsg *cwmsg) return 0; } +*/ +//extern struct conn * get_conn(); -extern struct conn * get_conn(); - +/* int run(struct conn * conn) { @@ -135,4 +138,4 @@ printf("Error !\n"); } - +*/ diff --git a/src/wtp/wtp.h b/src/wtp/wtp.h index 24167754..fb42ad6b 100644 --- a/src/wtp/wtp.h +++ b/src/wtp/wtp.h @@ -1,7 +1,15 @@ #ifndef __WTP_H #define __WTP_H +#include "capwap/conn.h" + + + extern int sulking_state(); extern int join(); +extern int discovery(); + + +struct conn * get_conn(); #endif diff --git a/src/wtp/wtp_conf.h b/src/wtp/wtp_conf.h index 32c5e121..3b276eb7 100644 --- a/src/wtp/wtp_conf.h +++ b/src/wtp/wtp_conf.h @@ -142,6 +142,8 @@ typedef struct { extern LONGSTRS conf_timer_cfgstrs[]; +int wtpconf_preinit(); +int wtpconf_init(); #endif diff --git a/src/wtp/wtp_interface.c b/src/wtp/wtp_interface.c index 6f1439d5..3bef2ed7 100644 --- a/src/wtp/wtp_interface.c +++ b/src/wtp/wtp_interface.c @@ -11,7 +11,7 @@ #include "wtp_conf.h" #include "wtp_interface.h" - +/* struct wtpinfo * get_wtpinfo() { struct wtpinfo * wtpinfo; @@ -125,3 +125,8 @@ struct conn * get_conn() printf("Get conn returns %p\n",conn); return conn; } + +*/ + + + diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index 5323d4fc..2da775de 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -3,179 +3,71 @@ #include #include -//#include - -#include "capwap/sock.h" -#include "capwap/conn.h" -#include "capwap/dtls.h" -#include "capwap/avltree.h" -#include "capwap/cw_log.h" #include "capwap/capwap.h" -#include "capwap/cw_util.h" -#include "capwap/wtpinfo.h" +#include "capwap/capwap_items.h" +#include "capwap/conn.h" +#include "capwap/cw_log.h" +#include "capwap/dtls.h" #include "wtp.h" #include "wtp_conf.h" -struct wtpinfo wtpinfo; - -//int conf_rids[2]; -//int conf_rids_len[2]; - -//int responses = 0; - -struct avltree * aclist =0; +/** The one and only connection object */ +struct conn *the_conn; +struct cw_actiondef capwap_actions; -extern struct wpa_driver_ops *wpa_drivers[]; - - -#include -#include -#include -#include - -//struct sockaddr conf_preferred_ac; - - - -static void * drv_priv[2]; -static void * drv_glob[2]; - -const char * interfaces[]={ - "wlan0", - "wlan1-1" -}; - -/*static int drv_init() -{ - return 1; -} -*/ int main() { - - - wtp_main(); -} - - -#include - -int pmu; - -//#include - -int do_connect(void *priv,void *data) -{ - ACIP * ip = (ACIP*)data; -// char str[100]; -// sock_addrtostr((struct sockaddr*)&ip->ip,str,100); - - sock_setport(&ip->ip,atoi(conf_control_port)); -// printf("Would connect to %s\n",str); - - -printf("Sleep 5000\n"); -printf("slept\n"); - - int rc; - rc = join(&ip->ip); - if (!rc) - return 1; - -printf("Sleep after oin\n"); -printf("Go conf\n"); -// extern struct conn * get_conn(); -// extern join_state(struct conn * conn); -// struct conn * conn = get_conn(); -//printf("Join conn = %p\n",conn); - -// join_state(conn); - - -// rc = join(&ip->ip); -// if (!rc) -// return 1; - - rc = configure(); - - run (get_conn()); - return 0; -} - - -#include "capwap/bstr.h" - -int wtp_main(const char *ad) -{ wtpconf_preinit(); - if (!read_config("./wtp_uci.conf")){ + if (!read_config("./wtp_uci.conf")) { return 1; } cw_dbg_opt_level = conf_dbg_level; wtpconf_init(); - - cw_dbg_opt_detail=DBG_DETAIL_ASC_DMP; - + + cw_dbg_opt_detail = DBG_DETAIL_ASC_DMP; - - -// cw_log_debug_level=6; //conf_debug_level; - -// conf_dtls_psk="Tube"; -// conf_sslkeyfilename="../../ssl/wtp.key"; -// conf_sslcertfilename="../../ssl/wtp.crt"; -// conf_dtls_psk=0; - -// conf_sslkeyfilename="../../ssl/ac_cisco.key"; -// conf_sslcertfilename="../../ssl/ac_cisco.pem"; - conf_sslkeypass="Tube"; - - - -#ifdef WITH_DTLS dtls_init(); -#endif - - //drv_init(); + + the_conn = conn_create_noq(-1, NULL); + struct conn *conn = the_conn; - while (1){ - ACIPLIST * aciplist=0; - int i; + cw_register_actions_capwap_wtp(&capwap_actions); + conn->actions = &capwap_actions; + conn->remote = cw_itemstore_create(); + conn->local = cw_itemstore_create(); - cw_dbg(DBG_CW_INFO,"Entering discovery state"); - - do { - for (i=0; ilocal, CW_ITEM_WTP_BOARD_DATA, board_data); + + discovery(); - return 0; +} + + +struct conn *get_conn() +{ + return the_conn; }