cw_process_elem is good now
FossilOrigin-Name: 71fd059171a96310ba664dfe7b34ea5940eaf7f57837751d443d5f4335f38b76
This commit is contained in:
parent
6c38ad4a5d
commit
df6ce963ee
@ -324,6 +324,7 @@
|
||||
<File Name="src/cw/cw_types_del_null.c"/>
|
||||
<File Name="src/cw/cw_type_bstr16.c"/>
|
||||
<File Name="src/cw/cw_process_element.c"/>
|
||||
<File Name="src/cw/cw_result_is_ok.c"/>
|
||||
</VirtualDirectory>
|
||||
</VirtualDirectory>
|
||||
<Description/>
|
||||
|
@ -546,7 +546,7 @@ static void wtpman_run(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
if (!cw_rcok(rc)) {
|
||||
if (!cw_result_is_ok(rc)) {
|
||||
cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc));
|
||||
wtpman_remove(wtpman);
|
||||
return;
|
||||
|
@ -637,7 +637,7 @@ extern struct cw_strlist_elem mbag_item_strings[];
|
||||
|
||||
|
||||
const char * cw_strerror(int rc);
|
||||
int cw_rcok(int rc);
|
||||
int cw_result_is_ok(int rc);
|
||||
const char *cw_strelemp_(cw_strheap_t h, int msg_id);
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ const char * cw_strerror(int rc) {
|
||||
return cw_strresult(rc);
|
||||
}
|
||||
|
||||
|
||||
/*(
|
||||
|
||||
int cw_rcok(int rc)
|
||||
{
|
||||
@ -20,7 +20,7 @@ int cw_rcok(int rc)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
*@defgroup CW CW
|
||||
|
@ -307,7 +307,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
|
||||
if (!message){
|
||||
/* Message is unknown */
|
||||
cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.",
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Message type %d (%s) unrecognized, sending response.",
|
||||
search.type, cw_strmsg(search.type),
|
||||
cw_strstate(conn->capwap_state));
|
||||
result_code = CAPWAP_RESULT_MSG_UNRECOGNIZED;
|
||||
@ -339,8 +340,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
if (!*i){
|
||||
/* Message found, but it was in wrong state */
|
||||
cw_dbg(DBG_MSG_ERR,
|
||||
"Message type %d (%s) not allowed in %s State.", search.type,
|
||||
cw_strmsg(search.type), cw_strstate(conn->capwap_state));
|
||||
"Message type %d (%s) not allowed in %s State, sending response.",
|
||||
search.type,cw_strmsg(search.type), cw_strstate(conn->capwap_state));
|
||||
result_code = CAPWAP_RESULT_MSG_INVALID_IN_CURRENT_STATE;
|
||||
cw_send_error_response(conn, rawmsg, result_code);
|
||||
errno = EAGAIN;
|
||||
@ -367,7 +368,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
/* Create an avltree to catch the found mandatory elements */
|
||||
conn->mand = stravltree_create();
|
||||
|
||||
int unrecognized = 0;
|
||||
|
||||
|
||||
/* iterate through message elements */
|
||||
cw_foreach_elem(elem, elems_ptr, elems_len) {
|
||||
@ -394,9 +395,15 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
params.from=from;
|
||||
params.msgdata=message;
|
||||
|
||||
result_code = cw_process_element(¶ms,0,0,elem_id,elem_data,elem_len); //elems_len-(elem-elems_ptr));
|
||||
result_code = cw_process_element(¶ms,0,0,elem_id,elem_data,elem_len);
|
||||
|
||||
|
||||
if (cw_result_is_ok(result_code))
|
||||
continue;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
elem_id = cw_get_elem_id(elem);
|
||||
@ -435,20 +442,6 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
|
||||
continue;
|
||||
exit(0);
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -462,7 +455,7 @@ exit(0);
|
||||
af = 0;
|
||||
|
||||
if (!af) {
|
||||
unrecognized++;
|
||||
//unrecognized++;
|
||||
|
||||
|
||||
/* cw_dbg(DBG_ELEM_ERR,
|
||||
@ -530,7 +523,7 @@ exit(0);
|
||||
|
||||
|
||||
//int result_code = 0;
|
||||
|
||||
int unrecognized =3;
|
||||
|
||||
|
||||
int rct = cw_in_check_generic(conn, afm, rawmsg, len, from);
|
||||
|
@ -456,6 +456,7 @@ uint8_t *cw_init_data_keep_alive_msg(uint8_t * buffer,uint8_t *rmac);
|
||||
int cw_out_radio_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
|
||||
int cw_put_elem_session_id(uint8_t *dst, uint8_t *session_id, int len);
|
||||
|
||||
int cw_result_is_ok( int rc );
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -17,7 +17,7 @@ int cw_in_check_generic_resp(struct conn *conn, struct cw_action_in *a, uint8_t
|
||||
mbag_item_t * result = mbag_get(conn->incomming,CW_ITEM_RESULT_CODE);
|
||||
|
||||
if (result ) {
|
||||
if (!cw_rcok(result->u2.dword)){
|
||||
if (!cw_result_is_ok(result->u2.dword)){
|
||||
return result->u2.dword;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a, uint8_t * d
|
||||
|
||||
mbag_item_t * jresult = mbag_get(conn->incomming,CW_ITEM_RESULT_CODE);
|
||||
if (jresult ) {
|
||||
if (!cw_rcok(jresult->u2.dword)){
|
||||
if (!cw_result_is_ok(jresult->u2.dword)){
|
||||
return jresult->u2.dword;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
|
||||
|
||||
struct cw_ElemHandler * handler;
|
||||
struct cw_ElemData * elem_data, elem_data_search;
|
||||
|
||||
|
||||
/* try to retrieve a handler for this message element */
|
||||
handler = cw_msgset_get_elemhandler(params->conn->msgset,0, 0, elem_id);
|
||||
if (!handler) {
|
||||
cw_dbg(DBG_ELEM_ERR, "Unrecognized message element: %d, ignoring",
|
||||
@ -25,18 +26,32 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
|
||||
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
||||
}
|
||||
|
||||
/* check if this message element in the current message allowed */
|
||||
elem_data_search.id=elem_id;
|
||||
elem_data_search.proto=0;
|
||||
elem_data_search.vendor=0;
|
||||
|
||||
elem_data = mavl_find_ptr(params->msgdata->elements_tree,&elem_data_search);
|
||||
|
||||
if (!elem_data){
|
||||
cw_dbg(DBG_ELEM_ERR, "Element %d - %s, not allowed here",
|
||||
elem_id, handler->name);
|
||||
return 0;
|
||||
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
||||
}
|
||||
|
||||
/* check the length of the message */
|
||||
if (len < handler->min_len) {
|
||||
cw_dbg(DBG_ELEM_ERR,
|
||||
"%d (%s) message element too short, len=%d, min len=%d",
|
||||
handler->id, handler->name, len,
|
||||
handler->min_len);
|
||||
return -1;
|
||||
}
|
||||
if (len > handler->max_len && handler->max_len) {
|
||||
cw_dbg(DBG_ELEM_ERR,
|
||||
"%d (%s) message element too big, len=%d, max len=%d", handler->id,
|
||||
handler->name, len, handler->max_len);
|
||||
/* TODO XXX truncate the element instead of return */
|
||||
return -1;
|
||||
}
|
||||
|
||||
cw_dbg_elem(DBG_ELEM, params->conn, params->msgdata->type, handler,
|
||||
data,len);
|
||||
|
8
src/cw/cw_result_is_ok.c
Normal file
8
src/cw/cw_result_is_ok.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "capwap.h"
|
||||
#include "cw.h"
|
||||
|
||||
int cw_result_is_ok( int rc ) {
|
||||
if(rc == CAPWAP_RESULT_SUCCESS || rc == CAPWAP_RESULT_SUCCESS_NAT)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
@ -81,7 +81,8 @@ typedef union mavldata mavldata_t;
|
||||
struct mavlnode {
|
||||
/** Pointer to data, that belongs to the node */
|
||||
|
||||
union mavldata data;
|
||||
union mavldata data;
|
||||
|
||||
/** Pointer to left son*/
|
||||
struct mavlnode *left;
|
||||
/** Pointer to right son*/
|
||||
@ -102,6 +103,8 @@ struct mavl {
|
||||
void (*del) (union mavldata *);
|
||||
/** Number of elements currently stored in the tree */
|
||||
int count;
|
||||
|
||||
size_t data_size;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -42,12 +42,16 @@ struct mlist_elem {
|
||||
* The last element is determined by a NULL pointer
|
||||
* */
|
||||
struct mlist_elem *next;
|
||||
struct mlist_elem *prev;
|
||||
};
|
||||
|
||||
struct mlist {
|
||||
void *data;
|
||||
int (*cmp) (const void *d1, const void *d2);
|
||||
struct mlist_elem *first;
|
||||
struct mlist_elem *last;
|
||||
int count;
|
||||
//size_t elem_size;
|
||||
};
|
||||
|
||||
typedef struct mlist * mlist_t;
|
||||
|
@ -21,7 +21,7 @@ int changestate()
|
||||
|
||||
/* Change State ... */
|
||||
int rc = cw_send_request(conn,CAPWAP_MSG_CHANGE_STATE_EVENT_REQUEST);
|
||||
if ( !cw_rcok(rc) ) {
|
||||
if ( !cw_result_is_ok(rc) ) {
|
||||
cw_strresult(rc);
|
||||
return 0;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ int configure()
|
||||
int rc = cw_send_request(conn, CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST);
|
||||
conn->radios_upd=radios_upd;
|
||||
|
||||
if (!cw_rcok(rc)) {
|
||||
if (!cw_result_is_ok(rc)) {
|
||||
if (rc > 0) {
|
||||
cw_log(LOG_ERR,
|
||||
"Error sending Configuration Status Request to AC at %s, AC said: %d - %s.",
|
||||
|
@ -188,7 +188,7 @@ int run_join(struct conn *conn)
|
||||
|
||||
int rc = cw_send_request(conn, CAPWAP_MSG_JOIN_REQUEST);
|
||||
|
||||
if (!cw_rcok(rc)) {
|
||||
if (!cw_result_is_ok(rc)) {
|
||||
if (rc > 0) {
|
||||
cw_log(LOG_ERR, "Can't Join AC at %s, AC said: %d - %s.",
|
||||
sock_addr2str(&conn->addr), rc, cw_strerror(rc));
|
||||
|
@ -95,7 +95,7 @@ static void do_update(struct conn * conn)
|
||||
cfg_to_json();
|
||||
/* Change State ... */
|
||||
int rc = cw_send_request(conn,CAPWAP_MSG_CHANGE_STATE_EVENT_REQUEST);
|
||||
if ( !cw_rcok(rc) ) {
|
||||
if ( !cw_result_is_ok(rc) ) {
|
||||
cw_strresult(rc);
|
||||
return ;
|
||||
}
|
||||
@ -131,7 +131,7 @@ int run()
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !cw_rcok(rc))
|
||||
if ( !cw_result_is_ok(rc))
|
||||
break;
|
||||
|
||||
|
||||
@ -144,14 +144,14 @@ int run()
|
||||
if (rc<0 && errno == EAGAIN){
|
||||
rc = cw_send_request(conn,CAPWAP_MSG_ECHO_REQUEST);
|
||||
|
||||
if (!cw_rcok(rc)) {
|
||||
if (!cw_result_is_ok(rc)) {
|
||||
cw_log(LOG_ERR,"Error in run state: %d %s",rc,cw_strrc(rc));
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!cw_rcok(rc)) {
|
||||
if (!cw_result_is_ok(rc)) {
|
||||
cw_log(LOG_ERR,"Error in run state: %d %s",rc,cw_strrc(rc));
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user