2015-04-05 02:10:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "capwap.h"
|
|
|
|
#include "capwap_items.h"
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "dbg.h"
|
2015-04-10 17:52:01 +02:00
|
|
|
#include "log.h"
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
int cw_put_item(uint8_t * dst, struct mbag_item *item)
|
2015-04-05 02:10:37 +02:00
|
|
|
{
|
2015-04-19 23:27:44 +02:00
|
|
|
if (MBAG_STR == item->type ){
|
|
|
|
return cw_put_data(dst, item->data, strlen((char *) item->data));
|
|
|
|
}
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
if (MBAG_BYTE == item->type){
|
|
|
|
return cw_put_byte(dst, item->byte);
|
|
|
|
}
|
|
|
|
if (MBAG_WORD == item->type){
|
|
|
|
return cw_put_word(dst, item->word);
|
|
|
|
}
|
|
|
|
if (MBAG_DWORD == item->type){
|
|
|
|
return cw_put_dword(dst, item->dword);
|
|
|
|
}
|
|
|
|
if (MBAG_BSTR == item->type) {
|
|
|
|
return cw_put_bstr(dst, item->data);
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
if ( MBAG_BSTR16 == item->type)
|
|
|
|
return cw_put_bstr16(dst,item->data);
|
|
|
|
|
|
|
|
if (MBAG_VENDORSTR == item->type)
|
|
|
|
{
|
|
|
|
int l=0;
|
2016-03-04 20:20:28 +01:00
|
|
|
l+=cw_put_dword(dst, bstrv_get_vendor_id(item->data));
|
|
|
|
l+=cw_put_data(dst+4, bstrv_data(item->data),bstrv_len(item->data));
|
2015-04-19 23:27:44 +02:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
cw_log(LOG_ERR,"No method to put items of type %d",item->type);
|
|
|
|
|
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // ,struct mbag_item * item)
|
2015-04-05 02:10:37 +02:00
|
|
|
{
|
2015-04-05 20:27:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Get the item to put */
|
2015-04-19 23:27:44 +02:00
|
|
|
struct mbag_item *item = NULL;
|
2015-04-10 17:14:55 +02:00
|
|
|
if (a->get) {
|
|
|
|
item = a->get(conn, a);
|
2015-04-05 20:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Size for msg elem header depends on
|
|
|
|
vendor specific payload */
|
2015-04-10 17:14:55 +02:00
|
|
|
int start = a->vendor_id ? 10 : 4;
|
|
|
|
|
2015-04-05 20:27:17 +02:00
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
int len;
|
2015-04-10 17:14:55 +02:00
|
|
|
if (!item) {
|
2015-04-19 16:44:20 +02:00
|
|
|
const char *vendor="";
|
|
|
|
if ( a->vendor_id ) {
|
|
|
|
vendor=cw_strvendor(a->vendor_id);
|
|
|
|
}
|
2015-04-10 17:14:55 +02:00
|
|
|
if (a->mand) {
|
2015-04-11 19:00:51 +02:00
|
|
|
cw_log(LOG_ERR,
|
2015-04-19 16:44:20 +02:00
|
|
|
"Can't put mandatory element %s%d - (%s) into %s. No value found.",
|
|
|
|
vendor,
|
2015-04-11 19:00:51 +02:00
|
|
|
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
|
|
|
|
, cw_strmsg(a->msg_id)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else{
|
2015-05-02 02:02:06 +02:00
|
|
|
cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %s not found.",
|
2015-04-19 16:44:20 +02:00
|
|
|
vendor,
|
2015-04-11 19:00:51 +02:00
|
|
|
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
|
|
|
|
, cw_strmsg(a->msg_id),a->item_id);
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2015-04-10 17:14:55 +02:00
|
|
|
} else {
|
|
|
|
len = cw_put_item(dst + start, item);
|
2015-04-05 20:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
if (a->vendor_id)
|
|
|
|
return len + cw_put_elem_vendor_hdr(dst, a->vendor_id, a->elem_id, len);
|
2015-04-05 20:27:17 +02:00
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
return len + cw_put_elem_hdr(dst, a->elem_id, len);
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
2015-04-28 10:23:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|