2015-04-05 02:10:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "capwap.h"
|
|
|
|
#include "capwap_items.h"
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
#include "cw_log.h"
|
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
int cw_put_item(uint8_t * dst, struct cw_item *item)
|
2015-04-05 02:10:37 +02:00
|
|
|
{
|
2015-04-10 17:14:55 +02:00
|
|
|
switch (item->type) {
|
2015-04-05 02:10:37 +02:00
|
|
|
case CW_ITEMTYPE_STR:
|
2015-04-10 17:14:55 +02:00
|
|
|
return cw_put_data(dst, item->data, strlen((char *) item->data));
|
2015-04-05 02:10:37 +02:00
|
|
|
case CW_ITEMTYPE_BYTE:
|
2015-04-10 17:14:55 +02:00
|
|
|
return cw_put_byte(dst, item->byte);
|
2015-04-05 02:10:37 +02:00
|
|
|
case CW_ITEMTYPE_WORD:
|
2015-04-10 17:14:55 +02:00
|
|
|
return cw_put_word(dst, item->word);
|
2015-04-05 02:10:37 +02:00
|
|
|
case CW_ITEMTYPE_DWORD:
|
2015-04-10 17:14:55 +02:00
|
|
|
return cw_put_dword(dst, item->dword);
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // ,struct cw_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-10 17:14:55 +02:00
|
|
|
struct cw_item *item = NULL;
|
|
|
|
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) {
|
|
|
|
if (a->mand) {
|
|
|
|
cw_log(LOG_ERR, "Error: Cannot send mandatory message element %d - (%s)",
|
|
|
|
a->elem_id, cw_strelemp(conn->actions, a->elem_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
|
|
|
}
|