From 0a0ec8141ad67c1e57336bafef8162d796e1218f Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Fri, 2 Mar 2018 07:49:37 +0000 Subject: [PATCH] Some imprevements to hte new protocol FossilOrigin-Name: 6934f0a8e932314676572b629dbbc776facf11cab1e6f87a4fff822e9b9a8a63 --- actube.workspace | 4 +- src/cw/conn_process_packet.c | 81 ++++++++++++------------------ src/cw/cw.h | 9 ++-- src/cw/message_set.c | 10 ++-- src/cw/message_set.h | 2 +- src/mod/capwap/capwap_actions_ac.c | 16 +++--- src/mod/cisco/cisco_actions_ac.c | 4 +- 7 files changed, 54 insertions(+), 72 deletions(-) diff --git a/actube.workspace b/actube.workspace index b8870938..e0162c79 100644 --- a/actube.workspace +++ b/actube.workspace @@ -3,9 +3,9 @@ - + - + diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c index 48994032..3339ac04 100644 --- a/src/cw/conn_process_packet.c +++ b/src/cw/conn_process_packet.c @@ -249,13 +249,11 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, } } - + /* Detect the connecting AC type */ if (!conn->detected) { - //struct mod_ac *mod; + struct cw_MsgSet *set = load_msg_set(conn, rawmsg, len, elems_len, from); - - if (!set) { //cw_log(LOG_ERR, "Error"); errno = EAGAIN; @@ -263,20 +261,22 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, } conn->msgset= set; -// conn->actions = ad; conn->detected = 1; } + /** debug the received message */ cw_dbg_msg(DBG_MSG_IN, conn, rawmsg, len, from); /* prepare struct for search operation */ struct cw_MsgData search; search.type = cw_get_msg_id(msg_ptr); + + /* Search message */ struct cw_MsgData * message; - /* Search for message combination */ message = mavl_get(conn->msgset->messages,&search); int result_code = 0; + if (!message){ /* Message is unknown */ cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.", @@ -288,9 +288,10 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, return -1; } -printf("Receivers: %d %d\n",message->receiver,conn->receiver); - /* Throw away unexpected messages */ + /* maybe we have to check this too: if (!(message->type & 1)) + * means unexpected response message + * */ if (!(message->receiver & conn->receiver)) { cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unexpected/illegal in %s State, discarding.", @@ -319,54 +320,17 @@ printf("Receivers: %d %d\n",message->receiver,conn->receiver); } - -// afm = cw_actionlist_in_get(conn->actions->in, &as); - - if (!afm) { - // Throw away unexpected response messages - if (!(as.msg_id & 1)) { - cw_dbg(DBG_MSG_ERR, - "Message type %d (%s) unexpected/illegal in %s State, discarding.", - as.msg_id, cw_strmsg(as.msg_id), - cw_strstate(conn->capwap_state)); - errno = EAGAIN; - return -1; - } - - /* Request message not found in current state, check if we know - anything else about this message type */ - // TODO XXXX - //const char *str = cw_strheap_get(conn->actions->strmsg, as.msg_id); - const char *str = 0; - 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 = CAPWAP_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)); - result_code = CW_RESULT_MSG_UNRECOGNIZED; - - } - cw_send_error_response(conn, rawmsg, result_code); - errno = EAGAIN; - return -1; - } - if (conn->msg_start){ conn->msg_start(conn, afm, rawmsg, len, from); } /* Execute start processor for message */ - if (afm->start) { - afm->start(conn, afm, rawmsg, len, from); - } +// if (afm->start) { +// afm->start(conn, afm, rawmsg, len, from); +// } + + uint8_t *elems_ptr = cw_get_msg_elems_ptr(msg_ptr); uint8_t *elem; @@ -382,6 +346,23 @@ printf("Receivers: %d %d\n",message->receiver,conn->receiver); as.elem_id = cw_get_elem_id(elem); int elem_len = cw_get_elem_len(elem); + cw_elem_handler_t search_eh; + memset(&search_eh,0,sizeof(search_eh)); + struct cw_ElemDef search_elem; + search_elem.handler=&search_eh; + + search_eh.id = cw_get_elem_id(elem); + + + + struct cw_ElemDef * elem; + elem = mavl_find(message->elements_tree,&search_elem); + + +printf("ElemCHeck %d\n",search_eh.id); +if (elem){ + printf("Elem %d found! %s\n", elem->handler->id , elem->handler->name); +} // TODO XXX // af = cw_actionlist_in_get(conn->actions->in, &as); af = 0; diff --git a/src/cw/cw.h b/src/cw/cw.h index fe0078e1..47911fc4 100644 --- a/src/cw/cw.h +++ b/src/cw/cw.h @@ -127,11 +127,12 @@ struct cw_MsgSet { typedef struct cw_MsgSet cw_MsgSet_t; -typedef struct{ - cw_elem_handler_t * elem; +typedef struct cw_ElemDef{ + cw_elem_handler_t * handler; int mand; int op; -}cw_msgelemprops_t; +}; +typedef struct cw_ElemDef cw_ElemDef_t; #define CW_RECEIVER_AC 1 #define CW_RECEIVER_WTP 1 @@ -141,7 +142,7 @@ struct cw_MsgDef{ int * states; /**< states in wich the message is allowed */ int receiver; /**< Who can receive this message */ - cw_msgelemprops_t * elements; + cw_ElemDef_t * elements; const char * name; }; typedef struct cw_MsgDef cw_msgdef_t; diff --git a/src/cw/message_set.c b/src/cw/message_set.c index b9ad84b6..20123738 100644 --- a/src/cw/message_set.c +++ b/src/cw/message_set.c @@ -16,8 +16,8 @@ typedef struct { */ static inline int cmp_cw_msgelemprops(const void *elem1, const void *elem2){ - cw_elem_handler_t * e1 = ((cw_msgelemprops_t*)elem1)->elem; - cw_elem_handler_t * e2 = ((cw_msgelemprops_t*)elem2)->elem; + cw_elem_handler_t * e1 = ((cw_ElemDef_t*)elem1)->handler; + cw_elem_handler_t * e2 = ((cw_ElemDef_t*)elem2)->handler; int r; r = e1->id - e2->id; if (r!=0) @@ -81,12 +81,12 @@ cw_MsgSet_t * cw_message_set_create(){ static void update_message(message2_t * msg, cw_msgdef_t * src, cw_MsgSet_t * set){ - cw_msgelemprops_t *md; + cw_ElemDef_t *md; - for (md = src->elements; md->elem!=0; md++){ - cw_dbg(DBG_INFO," add element %d - %s, %d",md->elem->id, md->elem->name, md->mand); + for (md = src->elements; md->handler!=0; md++){ + cw_dbg(DBG_INFO," add element %d - %s, %d",md->handler->id, md->handler->name, md->mand); mavl_add(msg->elements_tree,md); mavl_add(set->all_elems,md); mlist_append(msg->elements_list,md); diff --git a/src/cw/message_set.h b/src/cw/message_set.h index ff72310c..7c1418b9 100644 --- a/src/cw/message_set.h +++ b/src/cw/message_set.h @@ -10,7 +10,7 @@ extern void cw_msgset_add(cw_MsgSet_t * set, mlist_t cw_msgset_get_msg(cw_MsgSet_t * set, int type); -typedef struct cw_MsgData{ +struct cw_MsgData{ int type; const char * name; int * states; diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c index 2cb1ccf1..936e48f8 100644 --- a/src/mod/capwap/capwap_actions_ac.c +++ b/src/mod/capwap/capwap_actions_ac.c @@ -104,7 +104,7 @@ static cw_msgdef_t messages[] = { .type = CAPWAP_MSG_DISCOVERY_REQUEST, .receiver = CW_RECEIVER_AC, .states = (int[]){CAPWAP_STATE_DISCOVERY,0}, - .elements = (cw_msgelemprops_t []){ + .elements = (cw_ElemDef_t []){ {&_DISCOVERY_TYPE,1}, {&_WTP_BOARD_DATA,1}, {&_WTP_DESCRIPTOR,1}, @@ -121,7 +121,7 @@ static cw_msgdef_t messages[] = { .type = CAPWAP_MSG_DISCOVERY_RESPONSE, .receiver = CW_RECEIVER_WTP, .states = (int[]){CAPWAP_STATE_DISCOVERY,0}, - .elements = (cw_msgelemprops_t[]){ + .elements = (cw_ElemDef_t[]){ {&_AC_DESCRIPTOR,1}, {0,0}, } @@ -155,16 +155,16 @@ void test_sets(){ memset(&el,0,sizeof(el)); el.id=CAPWAP_ELEM_DISCOVERY_TYPE; - cw_msgelemprops_t search, *result;; - search.elem = ⪙ + cw_ElemDef_t search, *result;; + search.handler = ⪙ result = mavl_find(set->all_elems,&search); if (result!=NULL){ printf("Found: %d %s %d\n", - result->elem->id, - result->elem->name, + result->handler->id, + result->handler->name, result->mand ); } @@ -178,8 +178,8 @@ void test_sets(){ struct mlist_elem * i; mlist_foreach(i,m){ - cw_msgelemprops_t * le = i->data; - printf("Element: %d %s\n",le->elem->id, le->elem->name, le->mand); + cw_ElemDef_t * le = i->data; + printf("Element: %d %s\n",le->handler->id, le->handler->name, le->mand); } diff --git a/src/mod/cisco/cisco_actions_ac.c b/src/mod/cisco/cisco_actions_ac.c index cccec0a5..d059ae22 100644 --- a/src/mod/cisco/cisco_actions_ac.c +++ b/src/mod/cisco/cisco_actions_ac.c @@ -59,7 +59,7 @@ static cw_msgdef_t messages[] = { .name = "Discovery Request Cisco", .type = CAPWAP_MSG_DISCOVERY_REQUEST, .states = (int[]){CAPWAP_STATE_DISCOVERY,0}, - .elements = (cw_msgelemprops_t []){ + .elements = (cw_ElemDef_t []){ {&_DISCOVERY_TYPE,1}, {0,0}, } @@ -69,7 +69,7 @@ static cw_msgdef_t messages[] = { .name = "Discovery Response", .type = CAPWAP_MSG_DISCOVERY_RESPONSE, .states = (int[]){CAPWAP_STATE_DISCOVERY,0}, - .elements = (cw_msgelemprops_t[]){ + .elements = (cw_ElemDef_t[]){ {0,0}, } },