From 4506690fe1358b20589364719416f3861deadc1e Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Thu, 28 Jul 2022 18:25:05 +0200 Subject: [PATCH] Debuggin with cw_decode_msg is possible --- src/ac/Makefile | 3 ++- src/cw/conn_process_packet.c | 1 - src/cw/cw_decode_msg.c | 49 +++++++++++++++++++++++++----------- src/cw/cw_in_generic.c | 4 +-- src/cw/cw_process_element.c | 2 ++ src/cw/cw_put_msg.c | 26 ++++++++++++++++++- src/cw/msgset.h | 2 +- src/wtp/cisco.ktv | 8 +++--- 8 files changed, 70 insertions(+), 25 deletions(-) diff --git a/src/ac/Makefile b/src/ac/Makefile index ad8d3ab7..d915ed65 100644 --- a/src/ac/Makefile +++ b/src/ac/Makefile @@ -1,5 +1,6 @@ -include ../Config.default.mak +#include ../Config.default.mak -include ../Config.mak +include ../Defs.mak OBJS = \ wtplist.o wtpman.o conf.o ac_main.o \ diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c index a4ed251e..9c24a8b1 100644 --- a/src/cw/conn_process_packet.c +++ b/src/cw/conn_process_packet.c @@ -406,7 +406,6 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, params.global_cfg=conn->global_cfg; params.msgset=conn->msgset; - params.from=from; params.msgdata=message; params.mand_found=mand_found; diff --git a/src/cw/cw_decode_msg.c b/src/cw/cw_decode_msg.c index 3a711be3..d787222d 100644 --- a/src/cw/cw_decode_msg.c +++ b/src/cw/cw_decode_msg.c @@ -1,7 +1,7 @@ #include "cw.h" #include "dbg.h" #include "log.h" - +#include "msgset.h" int cw_decode_element(struct cw_ElemHandlerParams *params, int proto, int vendor, int elem_id, uint8_t * data, int len) @@ -72,32 +72,53 @@ int cw_decode_element(struct cw_ElemHandlerParams *params, int proto, } -int cw_decode_elements(uint8_t * elems_ptr, int elems_len) +int cw_decode_elements(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len) { uint8_t *elem; + mavl_t mand_found; + mlist_t unrecognized; + + mand_found = mavl_create_conststr(); + unrecognized = mlist_create(NULL,NULL,sizeof(uint8_t*)); - /* iterate through message elements */ cw_foreach_elem(elem, elems_ptr, elems_len) { int rc; - - struct cw_ElemHandlerParams params; int elem_len, elem_id, max_len; - uint8_t *elem_data; + uint8_t * elem_data; elem_len = cw_get_elem_len(elem); - elem_data = cw_get_elem_data(elem); + elem_data=cw_get_elem_data(elem); elem_id = cw_get_elem_id(elem); - - max_len = elems_len - (elem_data - elems_ptr); - if (elem_len > max_len) { + + max_len=elems_len-(elem_data-elems_ptr); + if (elem_len > max_len){ cw_dbg(DBG_RFC, - "Messag element claims size of %d bytes, but only %d bytes are left in the payload, truncating.", - elem_len, max_len - 4); + "Messag element claims size of %d bytes, but only %d bytes are left in the payload, truncating.", + elem_len,max_len-4); + } + + + + params->from=NULL; /*from;*/ + params->mand_found=mand_found; + + rc = cw_decode_element(params,0,0,elem_id,elem_data,elem_len); + + + if (cw_result_is_ok(rc)) + continue; + + if (rc == CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT){ + mlist_append(unrecognized,&elem); + continue; + } + + if (rc < 0 ){ + continue; } - - } + } diff --git a/src/cw/cw_in_generic.c b/src/cw/cw_in_generic.c index 2942c500..46d7612a 100644 --- a/src/cw/cw_in_generic.c +++ b/src/cw/cw_in_generic.c @@ -13,11 +13,9 @@ int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name); return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT; } - + result = cw_ktv_add(params->remote_cfg, handler->key, handler->type,NULL, elem_data,elem_len); - params->elem=result; - return CAPWAP_RESULT_SUCCESS; } diff --git a/src/cw/cw_process_element.c b/src/cw/cw_process_element.c index 044ce109..074fb3aa 100644 --- a/src/cw/cw_process_element.c +++ b/src/cw/cw_process_element.c @@ -74,6 +74,8 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo cw_log(LOG_ERR,"No get method defined for %d %s",handler->id,handler->name); return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT; } + + rc = handler->get(handler, params, data, len); diff --git a/src/cw/cw_put_msg.c b/src/cw/cw_put_msg.c index 32146e59..123959d8 100644 --- a/src/cw/cw_put_msg.c +++ b/src/cw/cw_put_msg.c @@ -28,7 +28,7 @@ #include "log.h" #include "dbg.h" #include "msgset.h" - +#include "mavltypes.h" /** * Put a message to a buffer @@ -133,6 +133,30 @@ printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name 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); + + + } + return CAPWAP_RESULT_SUCCESS; diff --git a/src/cw/msgset.h b/src/cw/msgset.h index a74a7cc3..4577df30 100644 --- a/src/cw/msgset.h +++ b/src/cw/msgset.h @@ -32,7 +32,7 @@ struct cw_ElemData{ struct cw_ElemHandlerParams { /* struct conn * conn;*/ - struct cw_MsgData * msgdata; + struct cw_MsgData * msgdata; struct cw_ElemData * elemdata; struct sockaddr *from; mavl_t mand_found; diff --git a/src/wtp/cisco.ktv b/src/wtp/cisco.ktv index 856e8e71..8cf10115 100644 --- a/src/wtp/cisco.ktv +++ b/src/wtp/cisco.ktv @@ -1,4 +1,4 @@ -ac-descriptor/active-wtps :Word: 1 +ac-descriptor/active-wtps :Word: 2 ac-descriptor/dtls-policy :Byte: 0 ac-descriptor/hardware/vendor :Dword: 4232704 ac-descriptor/hardware/version :Bstr16: .x01000001 @@ -61,7 +61,7 @@ cisco/ap-regulatory-domain.1/slot :Byte: 0 cisco/ap-sub-mode :Byte: 0 cisco/ap-telnet-ssh/ssh :Bool: false cisco/ap-telnet-ssh/telnet :Bool: false -cisco/ap-timesync/timestamp :Dword: 1469663405 +cisco/ap-timesync/timestamp :Dword: 1469722147 cisco/ap-timesync/type :Byte: 0 cisco/ap-username-and-password/802.1x-credentials/option :Word: 2 cisco/ap-username-and-password/802.1x-credentials/password :Str: @@ -196,7 +196,7 @@ radio.0/wlan.0/add-wlan/scan-defer-time :Word: 100 radio.0/wlan.0/add-wlan/session-timout :Word: 1800 radio.0/wlan.0/add-wlan/ssid :Str: radio.0/wlan.0/add-wlan/wep-encryption :Bool: false -radio.0/wlan.0/add-wlan/wep-key :Bstr16: .x0c1dfebf4fe85062a9104d37b4 +radio.0/wlan.0/add-wlan/wep-key :Bstr16: .x61d4be12e22feb1135d1be6d3f radio.0/wlan.0/add-wlan/wep-key-index :Byte: 1 radio.0/wlan.0/add-wlan/wlan-capability :Word: 1073 radio.0/wlan.0/add-wlan/wlan-id :Byte: 1 @@ -248,7 +248,7 @@ radio.1/cisco/multi-domain-capability/max-tx-power-level :Word: 20 radio.1/cisco/multi-domain-capability/number-of-channels :Word: 4 radio.1/cisco/multi-domain-capability/reserved :Byte: 1 radio.1/cisco/tx-power-levels :Bstr16: .x070011000e000b000800050002ffff0000 -radio.1/cisco/tx-power/current-tx-power :Word: 1 +radio.1/cisco/tx-power/current-tx-power :Word: 6 radio.1/cisco/tx-power/reserved :Byte: 1 radio.1/cisco/wtp-radio-config/beacon-period :Word: 100 radio.1/cisco/wtp-radio-config/bss-id :Bstr16: .x04fe7f499b90