2013-05-01 14:52:55 +02:00
|
|
|
#include "capwap.h"
|
2016-08-22 16:59:55 +02:00
|
|
|
#include "array.h"
|
|
|
|
#include "element.h"
|
2013-05-01 14:52:55 +02:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
|
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Stations | Limit |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Active WTPs | Max WTPs |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Security | R-MAC Field | Reserved1 | DTLS Policy |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| AC Information Sub-Element...
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2013-05-27 21:33:23 +02:00
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| AC Information Vendor Identifier |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| AC Information Type | AC Information Length |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| AC Information Data...
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
|
|
Type: 1 for AC Descriptor
|
|
|
|
Length: >= 12
|
|
|
|
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
/* */
|
2013-05-27 21:33:23 +02:00
|
|
|
static void capwap_acdescriptor_element_create(void* data, capwap_message_elements_handle handle, struct capwap_write_message_elements_ops* func) {
|
|
|
|
int i;
|
|
|
|
struct capwap_acdescriptor_element* element = (struct capwap_acdescriptor_element*)data;
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
ASSERT(data != NULL);
|
2013-06-09 17:41:52 +02:00
|
|
|
ASSERT(!(element->security & ~CAPWAP_ACDESC_SECURITY_MASK));
|
|
|
|
ASSERT(!(element->dtlspolicy & ~CAPWAP_ACDESC_DTLS_POLICY_MASK));
|
|
|
|
ASSERT((element->rmacfield == CAPWAP_ACDESC_RMACFIELD_SUPPORTED) || (element->rmacfield == CAPWAP_ACDESC_RMACFIELD_NOTSUPPORTED));
|
2013-09-22 22:28:07 +02:00
|
|
|
ASSERT(element->descsubelement != NULL);
|
2013-05-01 14:52:55 +02:00
|
|
|
|
2013-05-27 21:33:23 +02:00
|
|
|
/* */
|
|
|
|
func->write_u16(handle, element->stations);
|
|
|
|
func->write_u16(handle, element->stationlimit);
|
|
|
|
func->write_u16(handle, element->activewtp);
|
|
|
|
func->write_u16(handle, element->maxwtp);
|
|
|
|
func->write_u8(handle, element->security);
|
|
|
|
func->write_u8(handle, element->rmacfield);
|
|
|
|
func->write_u8(handle, 0);
|
|
|
|
func->write_u8(handle, element->dtlspolicy);
|
|
|
|
|
|
|
|
/* */
|
|
|
|
for (i = 0; i < element->descsubelement->count; i++) {
|
|
|
|
struct capwap_acdescriptor_desc_subelement* desc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(element->descsubelement, i);
|
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
ASSERT(desc->length > 0);
|
|
|
|
ASSERT(desc->data != NULL);
|
|
|
|
|
2013-05-27 21:33:23 +02:00
|
|
|
func->write_u32(handle, desc->vendor);
|
|
|
|
func->write_u16(handle, desc->type);
|
|
|
|
func->write_u16(handle, desc->length);
|
|
|
|
func->write_block(handle, desc->data, desc->length);
|
2013-05-01 14:52:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 16:39:27 +02:00
|
|
|
/* */
|
|
|
|
static void* capwap_acdescriptor_element_clone(void* data) {
|
|
|
|
int i;
|
|
|
|
struct capwap_acdescriptor_element* cloneelement;
|
|
|
|
struct capwap_acdescriptor_element* element = (struct capwap_acdescriptor_element*)data;
|
|
|
|
|
|
|
|
ASSERT(data != NULL);
|
|
|
|
|
|
|
|
cloneelement = capwap_clone(data, sizeof(struct capwap_acdescriptor_element));
|
|
|
|
cloneelement->descsubelement = capwap_array_create(sizeof(struct capwap_acdescriptor_desc_subelement), 0, 1);
|
|
|
|
for (i = 0; i < element->descsubelement->count; i++) {
|
|
|
|
struct capwap_acdescriptor_desc_subelement* desc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(element->descsubelement, i);
|
|
|
|
struct capwap_acdescriptor_desc_subelement* clonedesc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(cloneelement->descsubelement, i);
|
|
|
|
|
|
|
|
memcpy(clonedesc, desc, sizeof(struct capwap_acdescriptor_desc_subelement));
|
|
|
|
if (desc->length) {
|
|
|
|
clonedesc->data = capwap_clone(desc->data, desc->length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cloneelement;
|
|
|
|
}
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
/* */
|
2013-05-27 21:33:23 +02:00
|
|
|
static void capwap_acdescriptor_element_free(void* data) {
|
2013-06-09 17:41:52 +02:00
|
|
|
int i;
|
|
|
|
struct capwap_acdescriptor_element* element = (struct capwap_acdescriptor_element*)data;
|
|
|
|
|
|
|
|
ASSERT(element != NULL);
|
|
|
|
ASSERT(element->descsubelement != NULL);
|
2013-05-27 21:33:23 +02:00
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
/* */
|
|
|
|
for (i = 0; i < element->descsubelement->count; i++) {
|
|
|
|
struct capwap_acdescriptor_desc_subelement* desc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(element->descsubelement, i);
|
2013-05-27 21:33:23 +02:00
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
if (desc->data) {
|
|
|
|
capwap_free(desc->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
capwap_array_free(element->descsubelement);
|
|
|
|
capwap_free(data);
|
2013-05-01 14:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2013-05-27 21:33:23 +02:00
|
|
|
static void* capwap_acdescriptor_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
|
2013-05-01 14:52:55 +02:00
|
|
|
struct capwap_acdescriptor_element* data;
|
|
|
|
|
2013-05-27 21:33:23 +02:00
|
|
|
ASSERT(handle != NULL);
|
|
|
|
ASSERT(func != NULL);
|
|
|
|
|
|
|
|
if (func->read_ready(handle) < 12) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor element: underbuffer");
|
2013-05-01 14:52:55 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
data = (struct capwap_acdescriptor_element*)capwap_alloc(sizeof(struct capwap_acdescriptor_element));
|
2013-05-27 21:33:23 +02:00
|
|
|
memset(data, 0, sizeof(struct capwap_acdescriptor_element));
|
2013-06-08 17:26:10 +02:00
|
|
|
data->descsubelement = capwap_array_create(sizeof(struct capwap_acdescriptor_desc_subelement), 0, 1);
|
2013-05-27 21:33:23 +02:00
|
|
|
|
|
|
|
/* Retrieve data */
|
|
|
|
func->read_u16(handle, &data->stations);
|
|
|
|
func->read_u16(handle, &data->stationlimit);
|
|
|
|
func->read_u16(handle, &data->activewtp);
|
|
|
|
func->read_u16(handle, &data->maxwtp);
|
|
|
|
|
|
|
|
/* Check */
|
2013-06-09 17:41:52 +02:00
|
|
|
if (data->stations > data->stationlimit) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor element: stations > stationlimit");
|
2013-06-09 17:41:52 +02:00
|
|
|
capwap_acdescriptor_element_free(data);
|
|
|
|
return NULL;
|
|
|
|
} else if (data->activewtp > data->maxwtp) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor element: activewtp > maxwtp");
|
2013-05-27 21:33:23 +02:00
|
|
|
capwap_acdescriptor_element_free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
/* */
|
2013-05-27 21:33:23 +02:00
|
|
|
func->read_u8(handle, &data->security);
|
|
|
|
func->read_u8(handle, &data->rmacfield);
|
|
|
|
func->read_u8(handle, NULL);
|
|
|
|
func->read_u8(handle, &data->dtlspolicy);
|
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
/* */
|
|
|
|
if (data->security & ~CAPWAP_ACDESC_SECURITY_MASK) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor element: security");
|
2013-06-09 17:41:52 +02:00
|
|
|
capwap_acdescriptor_element_free(data);
|
|
|
|
return NULL;
|
|
|
|
} else if (data->dtlspolicy & ~CAPWAP_ACDESC_DTLS_POLICY_MASK) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor element: dtlspolicy");
|
2013-06-09 17:41:52 +02:00
|
|
|
capwap_acdescriptor_element_free(data);
|
|
|
|
return NULL;
|
|
|
|
} else if ((data->rmacfield != CAPWAP_ACDESC_RMACFIELD_SUPPORTED) && (data->rmacfield != CAPWAP_ACDESC_RMACFIELD_NOTSUPPORTED)) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor element: rmacfield");
|
2013-06-09 17:41:52 +02:00
|
|
|
capwap_acdescriptor_element_free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
/* Description Subelement */
|
2013-05-27 21:33:23 +02:00
|
|
|
while (func->read_ready(handle) > 0) {
|
|
|
|
unsigned short length;
|
|
|
|
struct capwap_acdescriptor_desc_subelement* desc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(data->descsubelement, data->descsubelement->count);
|
|
|
|
|
|
|
|
/* */
|
|
|
|
func->read_u32(handle, &desc->vendor);
|
|
|
|
func->read_u16(handle, &desc->type);
|
|
|
|
func->read_u16(handle, &desc->length);
|
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
if ((desc->type != CAPWAP_ACDESC_SUBELEMENT_HARDWAREVERSION) && (desc->type != CAPWAP_ACDESC_SUBELEMENT_SOFTWAREVERSION)) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor subelement: type");
|
2013-06-09 17:41:52 +02:00
|
|
|
capwap_acdescriptor_element_free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-27 21:33:23 +02:00
|
|
|
/* Check buffer size */
|
|
|
|
length = func->read_ready(handle);
|
|
|
|
if ((length > CAPWAP_ACDESC_SUBELEMENT_MAXDATA) || (length < desc->length)) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid AC Descriptor subelement: length");
|
2013-05-01 14:52:55 +02:00
|
|
|
capwap_acdescriptor_element_free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
desc->data = (uint8_t*)capwap_alloc(desc->length + 1);
|
2013-05-27 21:33:23 +02:00
|
|
|
func->read_block(handle, desc->data, desc->length);
|
2013-06-09 17:41:52 +02:00
|
|
|
desc->data[desc->length] = 0;
|
2013-05-01 14:52:55 +02:00
|
|
|
}
|
2013-05-27 21:33:23 +02:00
|
|
|
|
2013-05-01 14:52:55 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2016-03-07 18:07:46 +01:00
|
|
|
const struct capwap_message_elements_ops capwap_element_acdescriptor_ops = {
|
2016-03-07 18:08:35 +01:00
|
|
|
.category = CAPWAP_MESSAGE_ELEMENT_SINGLE,
|
2016-03-07 17:12:48 +01:00
|
|
|
.create = capwap_acdescriptor_element_create,
|
|
|
|
.parse = capwap_acdescriptor_element_parsing,
|
|
|
|
.clone = capwap_acdescriptor_element_clone,
|
|
|
|
.free = capwap_acdescriptor_element_free
|
2013-05-27 21:33:23 +02:00
|
|
|
};
|