2018-03-09 07:45:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "cw.h"
|
|
|
|
#include "dbg.h"
|
2018-03-24 07:56:05 +01:00
|
|
|
#include "log.h"
|
2018-03-09 07:45:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Process a CAPWAP message element
|
|
|
|
* @param conn
|
|
|
|
* @param msgdata
|
|
|
|
* @param handler
|
|
|
|
* @param elems_ptr
|
|
|
|
* @param elems_len
|
2018-03-09 10:57:16 +01:00
|
|
|
* @return Result Code as defined in RFC5415
|
2018-03-09 07:45:07 +01:00
|
|
|
*/
|
|
|
|
int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendor,int elem_id,
|
|
|
|
uint8_t * data, int len){
|
|
|
|
|
|
|
|
struct cw_ElemHandler * handler;
|
|
|
|
struct cw_ElemData * elem_data, elem_data_search;
|
2018-03-19 17:26:01 +01:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
params->elem=NULL;
|
2018-03-09 15:38:21 +01:00
|
|
|
|
|
|
|
/* try to retrieve a handler for this message element */
|
2018-03-12 11:22:06 +01:00
|
|
|
handler = cw_msgset_get_elemhandler(params->conn->msgset,proto, vendor, elem_id);
|
2018-03-09 07:45:07 +01:00
|
|
|
if (!handler) {
|
2018-03-09 10:57:16 +01:00
|
|
|
cw_dbg(DBG_ELEM_ERR, "Unrecognized message element: %d, ignoring",
|
2018-03-09 07:45:07 +01:00
|
|
|
elem_id);
|
2018-03-09 10:57:16 +01:00
|
|
|
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
2018-03-09 07:45:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-09 15:38:21 +01:00
|
|
|
/* check if this message element in the current message allowed */
|
2018-03-09 07:45:07 +01:00
|
|
|
elem_data_search.id=elem_id;
|
2018-03-12 11:22:06 +01:00
|
|
|
elem_data_search.proto=proto;
|
|
|
|
elem_data_search.vendor=vendor;
|
2018-03-11 00:56:41 +01:00
|
|
|
elem_data = mavl_find(params->msgdata->elements_tree,&elem_data_search);
|
2018-03-09 07:45:07 +01:00
|
|
|
if (!elem_data){
|
|
|
|
cw_dbg(DBG_ELEM_ERR, "Element %d - %s, not allowed here",
|
|
|
|
elem_id, handler->name);
|
2018-03-09 15:38:21 +01:00
|
|
|
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
2018-03-09 07:45:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-09 15:38:21 +01:00
|
|
|
/* 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;
|
|
|
|
}
|
2018-03-19 17:26:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (elem_data->mand){
|
|
|
|
mavl_add_str(params->mand_found,handler->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-09 15:38:21 +01:00
|
|
|
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;
|
|
|
|
}
|
2018-03-09 10:57:16 +01:00
|
|
|
|
2018-03-19 17:26:01 +01:00
|
|
|
cw_dbg_elem(DBG_ELEM_IN, params->conn, params->msgdata->type, handler,
|
2018-03-09 07:45:07 +01:00
|
|
|
data,len);
|
2018-03-09 10:57:16 +01:00
|
|
|
|
2018-03-24 07:56:05 +01:00
|
|
|
if (handler->get == NULL){
|
|
|
|
cw_log(LOG_ERR,"No get method defined for %d %s",handler->id,handler->name);
|
|
|
|
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
|
|
|
}
|
2018-03-19 17:26:01 +01:00
|
|
|
rc = handler->get(handler, params, data, len);
|
|
|
|
|
|
|
|
|
|
|
|
return rc;
|
2018-03-09 07:45:07 +01:00
|
|
|
}
|