Fix functions and logic.

Add new functions
Add logic into AC for create/destroy station
This commit is contained in:
vemax78
2014-04-06 17:02:31 +02:00
parent ae97e96f57
commit 539fa51e69
17 changed files with 482 additions and 166 deletions

View File

@ -700,7 +700,11 @@ int capwap_validate_parsed_packet(struct capwap_parsed_packet* packet, struct ca
return 0;
}
} else {
return 0;
/* Validate Radio ID */
uint8_t radioid = GET_RID_HEADER(packet->rxmngpacket->header);
if (IS_VALID_RADIOID(radioid)) {
return 0;
}
}
}

View File

@ -248,20 +248,21 @@ static int capwap_hash_item_memcmp(const void* key1, const void* key2, unsigned
}
/* */
struct capwap_hash* capwap_hash_create(unsigned long count, unsigned long keysize, capwap_hash_item_gethash item_hash, capwap_hash_item_cmp item_cmp, capwap_hash_item_free item_free) {
struct capwap_hash* capwap_hash_create(unsigned long hashsize, unsigned long keysize, capwap_hash_item_gethash item_hash, capwap_hash_item_cmp item_cmp, capwap_hash_item_free item_free) {
unsigned long size;
struct capwap_hash* hash;
ASSERT(count > 0);
ASSERT(hashsize > 0);
ASSERT(keysize > 0);
ASSERT(item_hash != NULL);
size = sizeof(struct capwap_hash_item*) * count;
size = sizeof(struct capwap_hash_item*) * hashsize;
/* */
hash = (struct capwap_hash*)capwap_alloc(sizeof(struct capwap_hash));
hash->count = count;
hash->hashsize = hashsize;
hash->keysize = keysize;
hash->count = 0;
hash->items = (struct capwap_hash_item**)capwap_alloc(size);
memset(hash->items, 0, size);
hash->item_hash = item_hash;
@ -293,12 +294,14 @@ void capwap_hash_add(struct capwap_hash* hash, const void* key, void* data) {
ASSERT(hash != NULL);
ASSERT(key != NULL);
hashvalue = hash->item_hash(key, hash->keysize, hash->count);
ASSERT(hashvalue < hash->count);
/* */
hashvalue = hash->item_hash(key, hash->keysize, hash->hashsize);
ASSERT(hashvalue < hash->hashsize);
/* Search position where insert item */
search = hash->items[hashvalue];
if (!search) {
hash->count++;
hash->items[hashvalue] = capwap_hash_create_item(hash, key, data);
} else {
while (search) {
@ -315,6 +318,7 @@ void capwap_hash_add(struct capwap_hash* hash, const void* key, void* data) {
if (search->left) {
search = search->left;
} else {
hash->count++;
item = capwap_hash_create_item(hash, key, data);
capwap_hash_set_left_item(search, item);
break;
@ -323,6 +327,7 @@ void capwap_hash_add(struct capwap_hash* hash, const void* key, void* data) {
if (search->right) {
search = search->right;
} else {
hash->count++;
item = capwap_hash_create_item(hash, key, data);
capwap_hash_set_right_item(search, item);
break;
@ -351,7 +356,7 @@ void capwap_hash_delete(struct capwap_hash* hash, const void* key) {
ASSERT(key != NULL);
/* */
hashvalue = hash->item_hash(key, hash->keysize, hash->count);
hashvalue = hash->item_hash(key, hash->keysize, hash->hashsize);
if (!hash->items[hashvalue]) {
return;
}
@ -362,6 +367,9 @@ void capwap_hash_delete(struct capwap_hash* hash, const void* key) {
return;
}
/* */
ASSERT(hash->count > 0);
/* Rebalancing tree */
parent = search->parent;
if (!search->left && !search->right) {
@ -453,6 +461,7 @@ void capwap_hash_delete(struct capwap_hash* hash, const void* key) {
}
/* Free node */
hash->count--;
capwap_hash_free_item(hash, search);
}
@ -462,13 +471,15 @@ void capwap_hash_deleteall(struct capwap_hash* hash) {
ASSERT(hash != NULL);
for (i = 0; i < hash->count; i++) {
for (i = 0; i < hash->hashsize; i++) {
if (hash->items[i]) {
capwap_hash_free_items(hash, hash->items[i]);
hash->items[i] = NULL;
}
}
/* */
hash->count = 0;
}
/* */
@ -481,7 +492,7 @@ int capwap_hash_hasitem(struct capwap_hash* hash, const void* key) {
ASSERT(key != NULL);
/* Search item */
hashvalue = hash->item_hash(key, hash->keysize, hash->count);
hashvalue = hash->item_hash(key, hash->keysize, hash->hashsize);
items = hash->items[hashvalue];
if (!items) {
return 0;
@ -502,7 +513,7 @@ void* capwap_hash_search(struct capwap_hash* hash, const void* key) {
ASSERT(key != NULL);
/* Search item */
hashvalue = hash->item_hash(key, hash->keysize, hash->count);
hashvalue = hash->item_hash(key, hash->keysize, hash->hashsize);
items = hash->items[hashvalue];
if (!items) {
return NULL;
@ -524,7 +535,7 @@ void capwap_hash_foreach(struct capwap_hash* hash, capwap_hash_item_foreach item
ASSERT(hash != NULL);
ASSERT(item_foreach != NULL);
for (i = 0; i < hash->count; i++) {
for (i = 0; i < hash->hashsize; i++) {
if (hash->items[i]) {
capwap_hash_foreach_items(hash, hash->items[i], item_foreach, param);
}

View File

@ -20,16 +20,19 @@ struct capwap_hash_item {
struct capwap_hash {
struct capwap_hash_item** items;
unsigned long count;
unsigned long hashsize;
unsigned long keysize;
/* */
unsigned long count;
/* Callback functions */
capwap_hash_item_gethash item_hash;
capwap_hash_item_cmp item_cmp;
capwap_hash_item_free item_free;
};
struct capwap_hash* capwap_hash_create(unsigned long count, unsigned long keysize, capwap_hash_item_gethash item_hash, capwap_hash_item_cmp item_cmp, capwap_hash_item_free item_free);
struct capwap_hash* capwap_hash_create(unsigned long hashsize, unsigned long keysize, capwap_hash_item_gethash item_hash, capwap_hash_item_cmp item_cmp, capwap_hash_item_free item_free);
void capwap_hash_free(struct capwap_hash* hash);
void capwap_hash_add(struct capwap_hash* hash, const void* key, void* data);

View File

@ -8,6 +8,10 @@
#define CAPWAP_CONTROL_PORT 5246
#define CAPWAP_MAX_PACKET_SIZE 65535
/* */
#define CAPWAP_MACADDRESS_EUI48_BUFFER 18
#define CAPWAP_MACADDRESS_EUI64_BUFFER 24
/* Helper */
#define CAPWAP_GET_NETWORK_PORT(address) ntohs((((address)->ss_family == AF_INET) ? ((struct sockaddr_in*)(address))->sin_port : ((struct sockaddr_in6*)(address))->sin6_port))
#define CAPWAP_SET_NETWORK_PORT(address, port) if ((address)->ss_family == AF_INET) { \

View File

@ -155,10 +155,10 @@ struct capwap_data_message {
#define GET_HLEN_HEADER(x) ((x)->hlen)
#define SET_HLEN_HEADER(x, y) ((x)->hlen = (uint16_t)(y))
#ifdef CAPWAP_BIG_ENDIAN
#define GET_RID_HEADER(x) ((x)->rid)
#define GET_RID_HEADER(x) ((uint8_t)((x)->rid))
#define SET_RID_HEADER(x, y) ((x)->rid = (uint16_t)(y))
#else
#define GET_RID_HEADER(x) ((uint16_t)((x)->_rid_hi << 2 | (x)->_rid_lo))
#define GET_RID_HEADER(x) ((uint8_t)((uint16_t)((x)->_rid_hi << 2 | (x)->_rid_lo)))
#define SET_RID_HEADER(x, y) ({ (x)->_rid_hi = (uint16_t)((y) >> 2); (x)->_rid_lo = (uint16_t)((y) & 0x0003); })
#endif
#define GET_WBID_HEADER(x) ((x)->wbid)

View File

@ -3,6 +3,9 @@
/* */
#define CAPWAP_TIMEOUT_HASH_COUNT 128
/* */
/* #define CAPWAP_TIMEOUT_LOGGING_DEBUG 1 */
/* */
static unsigned long capwap_timeout_hash_item_gethash(const void* key, unsigned long keysize, unsigned long hashsize) {
return (*(unsigned long*)key % hashsize);
@ -121,7 +124,10 @@ unsigned long capwap_timeout_createtimer(struct capwap_timeout* timeout) {
/* Create new timeout index */
index = capwap_timeout_set_bitfield(timeout);
#ifdef CAPWAP_TIMEOUT_LOGGING_DEBUG
capwap_logging_debug("Create new timer: %lu", index);
#endif
return index;
}
@ -131,7 +137,9 @@ void capwap_timeout_deletetimer(struct capwap_timeout* timeout, unsigned long in
ASSERT(timeout != NULL);
if (index != CAPWAP_TIMEOUT_INDEX_NO_SET) {
#ifdef CAPWAP_TIMEOUT_LOGGING_DEBUG
capwap_logging_debug("Delete timer: %lu", index);
#endif
/* Unset timeout timer */
capwap_timeout_unset(timeout, index);
@ -169,7 +177,9 @@ unsigned long capwap_timeout_set(struct capwap_timeout* timeout, unsigned long i
item->context = context;
item->param = param;
#ifdef CAPWAP_TIMEOUT_LOGGING_DEBUG
capwap_logging_debug("Update timeout: %lu %ld", item->index, item->durate);
#endif
/* Add itemlist into order list */
capwap_timeout_additem(timeout->itemstimeout, itemlist);
@ -189,7 +199,9 @@ unsigned long capwap_timeout_set(struct capwap_timeout* timeout, unsigned long i
item->context = context;
item->param = param;
#ifdef CAPWAP_TIMEOUT_LOGGING_DEBUG
capwap_logging_debug("Set timeout: %lu %ld", item->index, item->durate);
#endif
/* Add itemlist into hash for rapid searching */
capwap_hash_add(timeout->itemsreference, (const void*)&item->index, (void*)itemlist);
@ -209,7 +221,11 @@ void capwap_timeout_unset(struct capwap_timeout* timeout, unsigned long index) {
if (index != CAPWAP_TIMEOUT_INDEX_NO_SET) {
itemlist = (struct capwap_list_item*)capwap_hash_search(timeout->itemsreference, &index);
if (itemlist) {
#ifdef CAPWAP_TIMEOUT_LOGGING_DEBUG
capwap_logging_debug("Unset timeout: %lu", index);
#endif
/* */
capwap_hash_delete(timeout->itemsreference, &index);
capwap_itemlist_free(capwap_itemlist_remove(timeout->itemstimeout, itemlist));
}
@ -281,7 +297,9 @@ unsigned long capwap_timeout_hasexpired(struct capwap_timeout* timeout) {
itemlist = capwap_itemlist_remove_head(timeout->itemstimeout);
item = (struct capwap_timeout_item*)itemlist->item;
#ifdef CAPWAP_TIMEOUT_LOGGING_DEBUG
capwap_logging_debug("Expired timeout: %lu", item->index);
#endif
/* Cache callback before release timeout timer */
index = item->index;