freewtp/lib/element_80211_stationkey.c

109 lines
3.8 KiB
C
Raw Normal View History

2013-05-30 22:32:08 +02:00
#include "capwap.h"
2016-08-22 16:59:55 +02:00
#include "element.h"
2013-05-30 22:32:08 +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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MAC Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MAC Address |A|C| Flags |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Pairwise TSC |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Pairwise TSC | Pairwise RSC |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Pairwise RSC |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Key...
+-+-+-+-+-+-+-+-
Type: 1038 for IEEE 802.11 Station Session Key
Length: >= 25
********************************************************************/
/* */
static void capwap_80211_stationkey_element_create(void* data, capwap_message_elements_handle handle, struct capwap_write_message_elements_ops* func) {
struct capwap_80211_stationkey_element* element = (struct capwap_80211_stationkey_element*)data;
ASSERT(data != NULL);
func->write_block(handle, element->address, MACADDRESS_EUI48_LENGTH);
2013-05-30 22:32:08 +02:00
func->write_u16(handle, element->flags);
func->write_block(handle, element->pairwisetsc, CAPWAP_STATION_SESSION_KEY_PAIRWISE_TSC_LENGTH);
func->write_block(handle, element->pairwisersc, CAPWAP_STATION_SESSION_KEY_PAIRWISE_RSC_LENGTH);
func->write_block(handle, element->key, element->keylength);
}
/* */
static void* capwap_80211_stationkey_element_parsing(capwap_message_elements_handle handle,
struct capwap_read_message_elements_ops* func)
{
2013-05-30 22:32:08 +02:00
unsigned short length;
struct capwap_80211_stationkey_element* data;
ASSERT(handle != NULL);
ASSERT(func != NULL);
length = func->read_ready(handle);
if (length < 25) {
log_printf(LOG_DEBUG, "Invalid IEEE 802.11 Station Session Key element");
2013-05-30 22:32:08 +02:00
return NULL;
}
/* */
data = (struct capwap_80211_stationkey_element *)
capwap_alloc(sizeof(struct capwap_80211_stationkey_element));
memset(data, 0, sizeof(struct capwap_80211_stationkey_element));
2013-05-31 22:24:58 +02:00
data->keylength = length - 20;
data->key = (uint8_t*)capwap_alloc(data->keylength);
2013-05-30 22:32:08 +02:00
/* Retrieve data */
func->read_block(handle, data->address, MACADDRESS_EUI48_LENGTH);
2013-05-30 22:32:08 +02:00
func->read_u16(handle, &data->flags);
func->read_block(handle, data->pairwisetsc, CAPWAP_STATION_SESSION_KEY_PAIRWISE_TSC_LENGTH);
func->read_block(handle, data->pairwisersc, CAPWAP_STATION_SESSION_KEY_PAIRWISE_RSC_LENGTH);
func->read_block(handle, data->key, data->keylength);
return data;
}
2013-10-01 16:39:27 +02:00
/* */
static void* capwap_80211_stationkey_element_clone(void* data) {
struct capwap_80211_stationkey_element* cloneelement;
ASSERT(data != NULL);
cloneelement = capwap_clone(data, sizeof(struct capwap_80211_stationkey_element));
if (cloneelement->keylength > 0) {
cloneelement->key = capwap_clone(((struct capwap_80211_stationkey_element*)data)->key, cloneelement->keylength);
}
return cloneelement;
}
2013-05-30 22:32:08 +02:00
/* */
static void capwap_80211_stationkey_element_free(void* data) {
2013-05-31 22:24:58 +02:00
struct capwap_80211_stationkey_element* element = (struct capwap_80211_stationkey_element*)data;
2013-05-30 22:32:08 +02:00
ASSERT(data != NULL);
2013-05-31 22:24:58 +02:00
if (element->key) {
capwap_free(element->key);
}
capwap_free(data);
2013-05-30 22:32:08 +02:00
}
/* */
2016-03-07 18:07:46 +01:00
const struct capwap_message_elements_ops capwap_element_80211_stationkey_ops = {
.category = CAPWAP_MESSAGE_ELEMENT_SINGLE,
.create = capwap_80211_stationkey_element_create,
.parse = capwap_80211_stationkey_element_parsing,
.clone = capwap_80211_stationkey_element_clone,
.free = capwap_80211_stationkey_element_free
2013-05-30 22:32:08 +02:00
};