2013-05-31 22:24:58 +02:00
|
|
|
#include "capwap.h"
|
2016-08-22 16:59:55 +02:00
|
|
|
#include "element.h"
|
2013-05-31 22:24:58 +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
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Radio ID | WLAN ID | Capability |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Key Index | Key Status | Key Length |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Key... |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Group TSC |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Group TSC | QoS | Auth Type |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| MAC Mode | Tunnel Mode | Suppress SSID | SSID ...
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
|
|
Type: 1024 for IEEE 802.11 Add WLAN
|
|
|
|
|
|
|
|
Length: >= 20
|
|
|
|
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
/* */
|
|
|
|
static void capwap_80211_addwlan_element_create(void* data, capwap_message_elements_handle handle, struct capwap_write_message_elements_ops* func) {
|
2013-06-09 17:41:52 +02:00
|
|
|
int length;
|
2013-05-31 22:24:58 +02:00
|
|
|
struct capwap_80211_addwlan_element* element = (struct capwap_80211_addwlan_element*)data;
|
|
|
|
|
|
|
|
ASSERT(data != NULL);
|
2013-06-09 17:41:52 +02:00
|
|
|
ASSERT(IS_VALID_RADIOID(element->radioid));
|
|
|
|
ASSERT(IS_VALID_WLANID(element->wlanid));
|
2013-05-31 22:24:58 +02:00
|
|
|
|
|
|
|
func->write_u8(handle, element->radioid);
|
|
|
|
func->write_u8(handle, element->wlanid);
|
|
|
|
func->write_u16(handle, element->capability);
|
|
|
|
func->write_u8(handle, element->keyindex);
|
|
|
|
func->write_u8(handle, element->keystatus);
|
|
|
|
func->write_u16(handle, element->keylength);
|
|
|
|
if ((element->keylength > 0) && element->key) {
|
|
|
|
func->write_block(handle, element->key, element->keylength);
|
|
|
|
}
|
|
|
|
func->write_block(handle, element->grouptsc, CAPWAP_ADD_WLAN_GROUPTSC_LENGTH);
|
|
|
|
func->write_u8(handle, element->qos);
|
|
|
|
func->write_u8(handle, element->authmode);
|
|
|
|
func->write_u8(handle, element->macmode);
|
|
|
|
func->write_u8(handle, element->tunnelmode);
|
|
|
|
func->write_u8(handle, element->suppressssid);
|
2013-06-09 17:41:52 +02:00
|
|
|
|
|
|
|
length = strlen((char*)element->ssid);
|
|
|
|
ASSERT((length > 0) && (length <= CAPWAP_ADD_WLAN_SSID_LENGTH));
|
|
|
|
|
|
|
|
func->write_block(handle, element->ssid, length);
|
2013-05-31 22:24:58 +02:00
|
|
|
}
|
|
|
|
|
2013-10-01 16:39:27 +02:00
|
|
|
/* */
|
|
|
|
static void* capwap_80211_addwlan_element_clone(void* data) {
|
|
|
|
struct capwap_80211_addwlan_element* cloneelement;
|
|
|
|
struct capwap_80211_addwlan_element* element = (struct capwap_80211_addwlan_element*)data;
|
|
|
|
|
|
|
|
ASSERT(data != NULL);
|
|
|
|
|
|
|
|
cloneelement = capwap_clone(data, sizeof(struct capwap_80211_addwlan_element));
|
|
|
|
if (cloneelement->keylength > 0) {
|
|
|
|
cloneelement->key = capwap_clone(element->key, cloneelement->keylength);
|
|
|
|
}
|
|
|
|
cloneelement->ssid = (uint8_t*)capwap_duplicate_string((char*)element->ssid);
|
|
|
|
|
|
|
|
return cloneelement;
|
|
|
|
}
|
|
|
|
|
2013-05-31 22:24:58 +02:00
|
|
|
/* */
|
|
|
|
static void capwap_80211_addwlan_element_free(void* data) {
|
|
|
|
struct capwap_80211_addwlan_element* element = (struct capwap_80211_addwlan_element*)data;
|
|
|
|
|
|
|
|
ASSERT(data != NULL);
|
|
|
|
|
|
|
|
if (element->ssid) {
|
|
|
|
capwap_free(element->ssid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element->key) {
|
|
|
|
capwap_free(element->key);
|
|
|
|
}
|
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
capwap_free(data);
|
2013-05-31 22:24:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
static void* capwap_80211_addwlan_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
|
|
|
|
unsigned short length;
|
|
|
|
struct capwap_80211_addwlan_element* data;
|
|
|
|
|
|
|
|
ASSERT(handle != NULL);
|
|
|
|
ASSERT(func != NULL);
|
|
|
|
|
|
|
|
length = func->read_ready(handle);
|
|
|
|
if (length < 20) {
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid IEEE 802.11 Add WLAN element: underbuffer");
|
2013-05-31 22:24:58 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
data = (struct capwap_80211_addwlan_element*)capwap_alloc(sizeof(struct capwap_80211_addwlan_element));
|
2013-08-18 19:07:19 +02:00
|
|
|
memset(data, 0, sizeof(struct capwap_80211_addwlan_element));
|
2013-05-31 22:24:58 +02:00
|
|
|
|
|
|
|
/* Retrieve data */
|
|
|
|
func->read_u8(handle, &data->radioid);
|
|
|
|
func->read_u8(handle, &data->wlanid);
|
2013-06-09 17:41:52 +02:00
|
|
|
|
|
|
|
if (!IS_VALID_RADIOID(data->radioid)) {
|
|
|
|
capwap_80211_addwlan_element_free((void*)data);
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid IEEE 802.11 Add WLAN element: invalid radioid");
|
2013-06-09 17:41:52 +02:00
|
|
|
return NULL;
|
|
|
|
} else if (!IS_VALID_WLANID(data->wlanid)) {
|
|
|
|
capwap_80211_addwlan_element_free((void*)data);
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid IEEE 802.11 Add WLAN element: invalid wlanid");
|
2013-06-09 17:41:52 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-31 22:24:58 +02:00
|
|
|
func->read_u16(handle, &data->capability);
|
|
|
|
func->read_u8(handle, &data->keyindex);
|
|
|
|
func->read_u8(handle, &data->keystatus);
|
|
|
|
func->read_u16(handle, &data->keylength);
|
|
|
|
|
|
|
|
if (data->keylength > 0) {
|
|
|
|
data->key = (uint8_t*)capwap_alloc(data->keylength);
|
|
|
|
func->read_block(handle, data->key, data->keylength);
|
|
|
|
}
|
|
|
|
|
|
|
|
func->read_block(handle, data->grouptsc, CAPWAP_ADD_WLAN_GROUPTSC_LENGTH);
|
|
|
|
func->read_u8(handle, &data->qos);
|
|
|
|
func->read_u8(handle, &data->authmode);
|
|
|
|
func->read_u8(handle, &data->macmode);
|
|
|
|
func->read_u8(handle, &data->tunnelmode);
|
|
|
|
func->read_u8(handle, &data->suppressssid);
|
|
|
|
|
2013-12-04 22:25:16 +01:00
|
|
|
length = func->read_ready(handle);
|
2013-06-09 17:41:52 +02:00
|
|
|
if (!length || (length > CAPWAP_ADD_WLAN_SSID_LENGTH)) {
|
2013-05-31 22:24:58 +02:00
|
|
|
capwap_80211_addwlan_element_free((void*)data);
|
2016-03-30 14:47:57 +02:00
|
|
|
log_printf(LOG_DEBUG, "Invalid IEEE 802.11 Add WLAN element: invalid ssid");
|
2013-05-31 22:24:58 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-09 17:41:52 +02:00
|
|
|
data->ssid = (uint8_t*)capwap_alloc(length + 1);
|
|
|
|
func->read_block(handle, data->ssid, length);
|
|
|
|
data->ssid[length] = 0;
|
2013-05-31 22:24:58 +02:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2016-03-07 18:07:46 +01:00
|
|
|
const struct capwap_message_elements_ops capwap_element_80211_addwlan_ops = {
|
2016-03-07 18:08:35 +01:00
|
|
|
.category = CAPWAP_MESSAGE_ELEMENT_SINGLE,
|
2016-03-07 17:12:48 +01:00
|
|
|
.create = capwap_80211_addwlan_element_create,
|
|
|
|
.parse = capwap_80211_addwlan_element_parsing,
|
|
|
|
.clone = capwap_80211_addwlan_element_clone,
|
|
|
|
.free = capwap_80211_addwlan_element_free
|
2013-05-31 22:24:58 +02:00
|
|
|
};
|