diff --git a/Makefile b/Makefile index 4573f1d0..1f4a98ef 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ .OBJDIR: ./ all: - $(MAKE) -C src/cw - $(MAKE) -C src/mod - $(MAKE) -C src/ac - $(MAKE) -C src/wtp + $(MAKE) -C src/cw -j16 + $(MAKE) -C src/mod -j16 + $(MAKE) -C src/ac -j16 + $(MAKE) -C src/wtp -j16 clean: $(MAKE) -C src/cw clean $(MAKE) -C src/mod clean $(MAKE) -C src/ac clean - $(MAKE) -C src/wtp + $(MAKE) -C src/wtp clean diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index 2c61eac9..1ebc290b 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -500,7 +500,8 @@ void process_cw_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, wtpman_start (wtpman, preamble & 0xf); } - + printf("Got Packet with len: %d\n",len); + wtpman_addpacket (wtpman, buffer, len); wtplist_unlock(); } diff --git a/src/cw/Makefile b/src/cw/Makefile index b24e6784..c00cda15 100644 --- a/src/cw/Makefile +++ b/src/cw/Makefile @@ -45,7 +45,6 @@ CWSRC=\ cw_put_elem_radio_operational_state.c\ cw_put_image_data.c\ cw_put_local_ip_address.c\ - cw_put_msg.c\ cw_radio_set_admin_state.c\ cw_rand.c\ cw_randint.c\ @@ -207,6 +206,7 @@ MISCSRC=\ # conn_init.c\ # conn_create.c\ # conn_send_request.c\ +# cw_put_msg.c\ DTLSSRC+=\ dtls_bio.c\ diff --git a/src/cw/conn.c b/src/cw/conn.c index 71275f02..430a0a5e 100644 --- a/src/cw/conn.c +++ b/src/cw/conn.c @@ -1,4 +1,5 @@ #include +#include #include "conn.h" @@ -17,6 +18,12 @@ #include "cw.h" +#include "dbg.h" +#include "msgset.h" +#include "mavltypes.h" + + + static int write_header(struct cw_ElemHandler * handler, uint8_t * dst, int len) @@ -32,6 +39,140 @@ static int header_len(struct cw_ElemHandler * handler) return handler->vendor ? 10 : 4; } +/** + * Put a message to a buffer + * This functions assumes, that a message header is + * alread initilaized in buffer + * Message alements are taken fom actiondef in #conn->action + */ +int cw_assemble_message(struct cw_Conn *conn, uint8_t * rawout) +{ + char details[1024]; + uint8_t *msgptr,*dst; + int type; + struct cw_MsgData * msg; + struct mlistelem * elem; + int len,l; + + cw_dbg(DBG_INFO, "Number of elements in ktv: %d",conn->local_cfg->count); +/* cw_dbg_ktv_dump(conn->local_cfg,DBG_CFG_DMP,"Local CFG","LOCAL:","End Local CFG");*/ + + /* rawout is already initialized, so we can get + * msg type from buffer */ + msgptr = rawout + cw_get_hdr_msg_offset(rawout); + type = cw_get_msg_type(msgptr); + + /* look for message data */ + msg = cw_msgset_get_msgdata(conn->msgset,type); + if (msg == NULL){ + cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.", + type, cw_strmsg(type)); + return CAPWAP_RESULT_MSG_UNRECOGNIZED; + } + + if (msg->preprocess){ + msg->preprocess(conn); + } + + cw_dbg(DBG_MSG_ASSEMBLY,"*** Assembling message of type %d (%s) ***", + msg->type, msg->name); + + dst = msgptr+8; + len =0; + mlist_foreach(elem,msg->elements_list){ + struct cw_ElemData * data; + struct cw_ElemHandler * handler; + struct cw_ElemHandlerParams params; + + data = mlistelem_dataptr(elem); + handler = cw_msgset_get_elemhandler(conn->msgset,data->proto,data->vendor,data->id); +printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name); + if (handler==NULL){ + cw_log(LOG_ERR,"Can't put message element %d %d %d, no handler defined.", + data->proto,data->vendor,data->id); + continue; + } + + + if (handler->put == NULL){ + if (data->mand){ + cw_log(LOG_ERR,"Error: Can't add mandatory message element %d - %s, no put method defined", + handler->id, handler->name); + + } + continue; + } + + /* params.conn=conn;*/ + params.local_cfg=conn->local_cfg; + params.remote_cfg=conn->remote_cfg; + params.default_cfg=conn->default_cfg; + params.global_cfg=conn->global_cfg; + params.msgset=conn->msgset; + + + + params.elemdata = data; + params.msgdata=msg; + params.debug_details=details; + *details=0; + +/* if (strcmp(handler->key,"cisco/ap-led-flash-config")==0){ + printf("flash config\n"); + cisco/ap-led-flash-config/flash-enable + }*/ + + + l = handler->put(handler,¶ms,dst+len); + + /* if(l>0) + cw_dbg_elem(DBG_ELEM_OUT,conn,type,handler,dst+len,l); + * if (strlen(details)){ + cw_dbg(DBG_ELEM_DETAIL," %s",params.debug_details); + } + */ len += l; + } + + cw_set_msg_elems_len(msgptr, len); + cw_dbg(DBG_MSG_ASSEMBLY,"*** Done assenmbling message of type %d (%s) ***", + msg->type, msg->name); + if (type & 1) { + /* It's a request, so we have to set seqnum */ + int s = conn_get_next_seqnum(conn); + cw_set_msg_seqnum(msgptr,s); + } + + + { + printf ("----------------------------------- redecode -----------------------------\n"); + uint8_t *elems_ptr; + + int offset = cw_get_hdr_msg_offset(rawout); + + uint8_t *msg_ptr = rawout + offset; + int elems_len = cw_get_msg_elems_len(msg_ptr); + elems_ptr = cw_get_msg_elems_ptr(msg_ptr); + mavl_t * cfg = cw_ktv_create(); + + struct cw_ElemHandlerParams params; + + params.remote_cfg=cfg; + params.msgset=conn->msgset; + params.msgdata=msg; + + + cw_decode_elements( ¶ms, elems_ptr,elems_len); + + printf ("----------------------------------- end redecode -----------------------------\n"); + + } + + return CAPWAP_RESULT_SUCCESS; + + +} + + /** * Basic initialization of a conn object diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c index e3affebc..bbf46916 100644 --- a/src/cw/conn_process_packet.c +++ b/src/cw/conn_process_packet.c @@ -118,7 +118,7 @@ int cw_send_response(struct cw_Conn *conn, uint8_t * rawmsg, int len) { int rc; cw_init_response(conn, rawmsg); - rc = cw_put_msg(conn, conn->resp_buffer); + rc = cw_assemble_message(conn, conn->resp_buffer); if (!cw_result_is_ok(rc)) return 0; conn_send_msg(conn, conn->resp_buffer); @@ -390,16 +390,15 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len, params.cfg = cw_cfg_create(); cw_decode_elements(¶ms,elems_ptr, elems_len); - exit(0); - /* all message elements are processed, do now after processing by calling the "end" function for the message */ cw_check_missing_mand(message, mand_found); - cw_dbg(DBG_MSG_PARSING, " *** Done parsing message of type %d (%s) ***", + cw_dbg(DBG_MSG_PARSING, " *** End parsing message of type %d (%s) ***", message->type, message->name); + mavl_destroy(mand_found); /* cw_dbg_ktv_dump(conn->remote_cfg,DBG_CFG_DMP, @@ -441,7 +440,6 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len, */ } - /*stravltree_destroy(conn->mand); */ return result_code; diff --git a/src/cw/cw.h b/src/cw/cw.h index f12eb42d..530283a3 100644 --- a/src/cw/cw.h +++ b/src/cw/cw.h @@ -536,7 +536,7 @@ uint8_t *cw_init_data_keep_alive_msg(uint8_t * buffer,uint8_t *rmac); int cw_put_elem_session_id(uint8_t *dst, uint8_t *session_id, int len); int cw_result_is_ok( int rc ); -int cw_put_msg(struct cw_Conn *conn, uint8_t * rawout); +int cw_assemble_message(struct cw_Conn *conn, uint8_t * rawout); /** * @} diff --git a/src/cw/cw_put_msg.c b/src/cw/cw_put_msg.c index 2bec95a0..3200e727 100644 --- a/src/cw/cw_put_msg.c +++ b/src/cw/cw_put_msg.c @@ -21,150 +21,6 @@ * @brief implementation of cw_put_msg. */ -#include "cw.h" - -#include "conn.h" - -#include "log.h" -#include "dbg.h" -#include "msgset.h" -#include "mavltypes.h" - -/** - * Put a message to a buffer - * This functions assumes, that a message header is - * alread initilaized in buffer - * Message alements are taken fom actiondef in #conn->action - */ -int cw_put_msg(struct cw_Conn *conn, uint8_t * rawout) -{ - char details[1024]; - uint8_t *msgptr,*dst; - int type; - struct cw_MsgData * msg; - struct mlistelem * elem; - int len,l; - -printf("Hello msg\n"); - cw_dbg(DBG_INFO, "Number of elements in ktv: %d",conn->local_cfg->count); -/* cw_dbg_ktv_dump(conn->local_cfg,DBG_CFG_DMP,"Local CFG","LOCAL:","End Local CFG");*/ - - /* rawout is already initialized, so we can get - * msg type from buffer */ - msgptr = rawout + cw_get_hdr_msg_offset(rawout); - type = cw_get_msg_type(msgptr); - - /* look for message data */ - msg = cw_msgset_get_msgdata(conn->msgset,type); - if (msg == NULL){ - cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.", - type, cw_strmsg(type)); - return CAPWAP_RESULT_MSG_UNRECOGNIZED; - } - - if (msg->preprocess){ - msg->preprocess(conn); - } - - cw_dbg(DBG_MSG_ASSEMBLY,"*** Assembling message of type %d (%s) ***", - msg->type, msg->name); - - dst = msgptr+8; - len =0; - mlist_foreach(elem,msg->elements_list){ - struct cw_ElemData * data; - struct cw_ElemHandler * handler; - struct cw_ElemHandlerParams params; - - data = mlistelem_dataptr(elem); - handler = cw_msgset_get_elemhandler(conn->msgset,data->proto,data->vendor,data->id); -printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name); - if (handler==NULL){ - cw_log(LOG_ERR,"Can't put message element %d %d %d, no handler defined.", - data->proto,data->vendor,data->id); - continue; - } - - - if (handler->put == NULL){ - if (data->mand){ - cw_log(LOG_ERR,"Error: Can't add mandatory message element %d - %s, no put method defined", - handler->id, handler->name); - - } - continue; - } - - /* params.conn=conn;*/ - params.local_cfg=conn->local_cfg; - params.remote_cfg=conn->remote_cfg; - params.default_cfg=conn->default_cfg; - params.global_cfg=conn->global_cfg; - params.msgset=conn->msgset; - - - - params.elemdata = data; -// params.elem=NULL; - params.msgdata=msg; - params.debug_details=details; - *details=0; - - if (strcmp(handler->key,"cisco/ap-led-flash-config")==0){ - printf("flash config\n"); - /* cisco/ap-led-flash-config/flash-enable */ - } - - l = handler->put(handler,¶ms,dst+len); - - /* if(l>0) - cw_dbg_elem(DBG_ELEM_OUT,conn,type,handler,dst+len,l); - * if (strlen(details)){ - cw_dbg(DBG_ELEM_DETAIL," %s",params.debug_details); - } - */ len += l; - } - - cw_set_msg_elems_len(msgptr, len); - cw_dbg(DBG_MSG_ASSEMBLY,"*** Done assenmbling message of type %d (%s) ***", - msg->type, msg->name); - if (type & 1) { - /* It's a request, so we have to set seqnum */ - int s = conn_get_next_seqnum(conn); - cw_set_msg_seqnum(msgptr,s); - } - - - { - printf ("----------------------------------- redecode -----------------------------\n"); - uint8_t *elems_ptr; - - int offset = cw_get_hdr_msg_offset(rawout); - - uint8_t *msg_ptr = rawout + offset; - int elems_len = cw_get_msg_elems_len(msg_ptr); - elems_ptr = cw_get_msg_elems_ptr(msg_ptr); - mavl_t * cfg = cw_ktv_create(); - - struct cw_ElemHandlerParams params; - - params.remote_cfg=cfg; - params.msgset=conn->msgset; - params.msgdata=msg; - - - cw_decode_elements( ¶ms, elems_ptr,elems_len); - - printf ("----------------------------------- end redecode -----------------------------\n"); - - } - - return CAPWAP_RESULT_SUCCESS; - - -} - - /** * Put a message to a buffer diff --git a/src/cw/send.c b/src/cw/send.c index 17529613..2a793c52 100644 --- a/src/cw/send.c +++ b/src/cw/send.c @@ -173,7 +173,7 @@ int cw_send_request(struct cw_Conn *conn,int msg_id) int rc; char sock_buf[SOCK_ADDR_BUFSIZE]; cw_init_request(conn, msg_id); - if ( cw_put_msg(conn, conn->req_buffer) == -1 ){ + if ( cw_assemble_message(conn, conn->req_buffer) == -1 ){ errno=ENOMSG; return -1; } diff --git a/src/wtp/configure.c b/src/wtp/configure.c index 6bab8409..f9ea86f4 100644 --- a/src/wtp/configure.c +++ b/src/wtp/configure.c @@ -10,7 +10,7 @@ #include "cfg.h" -int configure(struct conn * conn) +int configure(struct cw_Conn * conn) { char sockbuff[SOCK_ADDR_BUFSIZE]; diff --git a/src/wtp/discovery.c b/src/wtp/discovery.c index 65d8e16c..30137376 100644 --- a/src/wtp/discovery.c +++ b/src/wtp/discovery.c @@ -153,7 +153,7 @@ static int run_discovery(struct cw_Conn *conn, struct cw_DiscoveryResult * dis) /* create and send a discovery request message */ cw_init_request(conn, CAPWAP_MSG_DISCOVERY_REQUEST); - cw_put_msg(conn, conn->req_buffer); + cw_assemble_message(conn, conn->req_buffer); conn_send_msg(conn, conn->req_buffer);