Moved message encoding/decoding to message.c
This commit is contained in:
parent
a051ba41de
commit
be210692c6
@ -181,7 +181,6 @@ MISCSRC=\
|
||||
conn_create_noq.c\
|
||||
connlist.c\
|
||||
conn_prepare_image_data_request.c\
|
||||
cw_decode_msg.c \
|
||||
conn_q_add_packet.c\
|
||||
conn_q_get_packet.c\
|
||||
conn_q_recv_packet.c\
|
||||
@ -204,6 +203,8 @@ MISCSRC=\
|
||||
conn.c \
|
||||
val.c \
|
||||
discovery.c\
|
||||
message.c\
|
||||
|
||||
|
||||
|
||||
# conn_q_wait_packet.c\
|
||||
|
@ -378,7 +378,7 @@ int cw_send_response(struct cw_Conn *conn, uint8_t * rawmsg, int len)
|
||||
{
|
||||
int rc;
|
||||
cw_init_response(conn, rawmsg);
|
||||
rc = cw_assemble_message(conn, conn->resp_buffer);
|
||||
rc = cw_compose_message(conn, conn->resp_buffer);
|
||||
if (!cw_result_is_ok(rc))
|
||||
return 0;
|
||||
conn_send_msg(conn, conn->resp_buffer);
|
||||
|
17
src/cw/cw.c
17
src/cw/cw.c
@ -134,3 +134,20 @@ int cw_out_radio_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerP
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int cw_write_header(struct cw_ElemHandler * handler, uint8_t * dst, int len)
|
||||
{
|
||||
if (handler->vendor)
|
||||
return len + cw_put_elem_vendor_hdr(dst, handler->vendor, handler->id, len);
|
||||
|
||||
return len + cw_put_elem_hdr(dst, handler->id, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int cw_header_len(struct cw_ElemHandler * handler)
|
||||
{
|
||||
return handler->vendor ? 10 : 4;
|
||||
}
|
||||
|
||||
|
||||
|
@ -550,6 +550,9 @@ int cw_stricmp(char const *a, char const *b);
|
||||
int cw_write_header(struct cw_ElemHandler * handler, uint8_t * dst, int len);
|
||||
int cw_header_len(struct cw_ElemHandler * handler);
|
||||
|
||||
int cw_compose_message(struct cw_Conn *conn, uint8_t * rawout);
|
||||
|
||||
|
||||
/**
|
||||
*@}
|
||||
*/
|
||||
|
@ -1,127 +0,0 @@
|
||||
#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)
|
||||
{
|
||||
|
||||
struct cw_ElemHandler *handler;
|
||||
struct cw_ElemData *elem_data, elem_data_search;
|
||||
int rc;
|
||||
|
||||
//params->elem = NULL;
|
||||
|
||||
/* try to retrieve a handler for this message element */
|
||||
handler =
|
||||
cw_msgset_get_elemhandler(params->msgset, proto, vendor,
|
||||
elem_id);
|
||||
if (!handler) {
|
||||
|
||||
cw_dbg(DBG_ELEM_ERR,
|
||||
"Unrecognized message element: %d, ignoring", elem_id);
|
||||
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 = proto;
|
||||
elem_data_search.vendor = vendor;
|
||||
elem_data = mavl_get(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 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 (elem_data->mand) {
|
||||
mavl_add_str(params->mand_found, handler->key);
|
||||
}
|
||||
|
||||
|
||||
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_IN, NULL, params->msgdata->type, handler,
|
||||
data, len);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
rc = handler->get(handler, params, data, len);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
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*));
|
||||
|
||||
cw_foreach_elem(elem, elems_ptr, elems_len) {
|
||||
int rc;
|
||||
|
||||
int elem_len, elem_id, max_len;
|
||||
uint8_t * elem_data;
|
||||
|
||||
|
||||
elem_len = cw_get_elem_len(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){
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mavl_destroy(mand_found);
|
||||
mlist_destroy(unrecognized);
|
||||
return 0;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#include "conn.h"
|
||||
#include "msgset.h"
|
||||
#include "cw.h"
|
||||
|
||||
int cw_write_header(struct cw_ElemHandler * handler, uint8_t * dst, int len)
|
||||
{
|
||||
if (handler->vendor)
|
||||
return len + cw_put_elem_vendor_hdr(dst, handler->vendor, handler->id, len);
|
||||
|
||||
return len + cw_put_elem_hdr(dst, handler->id, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int cw_header_len(struct cw_ElemHandler * handler)
|
||||
{
|
||||
return handler->vendor ? 10 : 4;
|
||||
}
|
||||
|
||||
|
@ -186,16 +186,13 @@ int main (int argc, char **argv)
|
||||
join(conn,results);
|
||||
|
||||
cw_discovery_results_destroy(results);
|
||||
|
||||
|
||||
printf("JOIN CONF\n");
|
||||
rc = 0;
|
||||
printf("Goto errx 0");
|
||||
goto errX;
|
||||
|
||||
|
||||
// clean_cfg(conn->remote_cfg);
|
||||
// mavl_merge(conn->local_cfg,conn->remote_cfg);
|
||||
|
||||
mavl_del_all(conn->remote_cfg);
|
||||
printf("JOIN CONF\n");
|
||||
configure(conn);
|
||||
clean_cfg(conn->remote_cfg);
|
||||
mavl_merge(conn->local_cfg,conn->remote_cfg);
|
||||
|
Loading…
Reference in New Issue
Block a user