2013-12-07 18:14:32 +01:00
|
|
|
#include "wtp.h"
|
2014-01-18 19:13:10 +01:00
|
|
|
#include "capwap_hash.h"
|
2014-02-08 18:03:38 +01:00
|
|
|
#include "capwap_list.h"
|
2013-12-07 18:14:32 +01:00
|
|
|
#include "wtp_radio.h"
|
2014-02-16 15:28:27 +01:00
|
|
|
#include "wtp_dfa.h"
|
2013-12-07 18:14:32 +01:00
|
|
|
|
2014-01-21 19:54:59 +01:00
|
|
|
/* */
|
|
|
|
#define WTP_UPDATE_FREQUENCY_DSSS 1
|
|
|
|
#define WTP_UPDATE_FREQUENCY_OFDM 2
|
|
|
|
#define WTP_UPDATE_RATES 3
|
|
|
|
#define WTP_UPDATE_CONFIGURATION 4
|
|
|
|
|
|
|
|
struct wtp_update_configuration_item {
|
|
|
|
int type;
|
|
|
|
struct wtp_radio* radio;
|
|
|
|
};
|
|
|
|
|
2013-12-20 23:14:34 +01:00
|
|
|
/* */
|
|
|
|
static int wtp_radio_configure_phy(struct wtp_radio* radio) {
|
|
|
|
/* Default rate set is all supported rate */
|
|
|
|
if (radio->radioid != radio->rateset.radioid) {
|
|
|
|
if (radio->radioid != radio->supportedrates.radioid) {
|
|
|
|
return -1; /* Supported rate not set */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
radio->rateset.radioid = radio->radioid;
|
|
|
|
radio->rateset.ratesetcount = radio->supportedrates.supportedratescount;
|
|
|
|
memcpy(radio->rateset.rateset, radio->supportedrates.supportedrates, CAPWAP_RATESET_MAXLENGTH);
|
2014-01-21 19:54:59 +01:00
|
|
|
|
|
|
|
/* Update rates */
|
2014-02-08 18:03:38 +01:00
|
|
|
if (wifi_device_updaterates(radio->devicehandle, radio->rateset.rateset, radio->rateset.ratesetcount)) {
|
2014-01-21 19:54:59 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check channel radio */
|
|
|
|
if (radio->radioid != radio->radioinformation.radioid) {
|
|
|
|
return -1;
|
|
|
|
} else if (radio->radioid != radio->radioconfig.radioid) {
|
|
|
|
return -1;
|
|
|
|
} else if ((!radio->directsequencecontrol.radioid && !radio->ofdmcontrol.radioid) || ((radio->directsequencecontrol.radioid == radio->radioid) && (radio->ofdmcontrol.radioid == radio->radioid))) {
|
|
|
|
return -1; /* Only one from DSSS and OFDM can select */
|
|
|
|
} else if ((radio->radioid == radio->directsequencecontrol.radioid) && !(radio->radioinformation.radiotype & (CAPWAP_RADIO_TYPE_80211B | CAPWAP_RADIO_TYPE_80211G))) {
|
|
|
|
return -1;
|
|
|
|
} else if ((radio->radioid == radio->ofdmcontrol.radioid) && !(radio->radioinformation.radiotype & CAPWAP_RADIO_TYPE_80211A)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-09 21:55:10 +01:00
|
|
|
/* */
|
2014-03-16 21:34:29 +01:00
|
|
|
static void wtp_radio_send_mgmtframe_to_ac(void* param, const struct ieee80211_header_mgmt* mgmt, int mgmtlength) {
|
2014-02-16 15:28:27 +01:00
|
|
|
struct wtp_radio_wlan* wlan = (struct wtp_radio_wlan*)param;
|
2014-02-09 21:55:10 +01:00
|
|
|
|
|
|
|
ASSERT(param != NULL);
|
|
|
|
ASSERT(mgmt != NULL);
|
2014-02-16 15:28:27 +01:00
|
|
|
ASSERT(mgmtlength >= sizeof(struct ieee80211_header));
|
2014-02-09 21:55:10 +01:00
|
|
|
|
2014-02-16 15:28:27 +01:00
|
|
|
/* Send packet */
|
2014-04-14 22:33:12 +02:00
|
|
|
wtp_send_data_packet(wlan->radio->radioid, wlan->wlanid, (const uint8_t*)mgmt, mgmtlength, 1);
|
2014-02-09 21:55:10 +01:00
|
|
|
}
|
|
|
|
|
2014-01-18 19:13:10 +01:00
|
|
|
/* */
|
2014-03-22 21:31:09 +01:00
|
|
|
static unsigned long wtp_radio_acl_item_gethash(const void* key, unsigned long keysize, unsigned long hashsize) {
|
2014-01-18 19:13:10 +01:00
|
|
|
uint8_t* macaddress = (uint8_t*)key;
|
|
|
|
|
|
|
|
ASSERT(keysize == ETH_ALEN);
|
|
|
|
|
2014-03-22 21:31:09 +01:00
|
|
|
return (((unsigned long)macaddress[3] ^ (unsigned long)macaddress[4] ^ (unsigned long)macaddress[5]) >> 2);
|
2014-01-18 19:13:10 +01:00
|
|
|
}
|
|
|
|
|
2013-12-20 23:14:34 +01:00
|
|
|
/* */
|
|
|
|
void wtp_radio_init(void) {
|
|
|
|
g_wtp.radios = capwap_array_create(sizeof(struct wtp_radio), 0, 1);
|
2014-01-18 19:13:10 +01:00
|
|
|
|
|
|
|
g_wtp.defaultaclstations = WTP_RADIO_ACL_STATION_ALLOW;
|
|
|
|
g_wtp.aclstations = capwap_hash_create(WTP_RADIO_ACL_HASH_SIZE, WTP_RADIO_ACL_KEY_SIZE, wtp_radio_acl_item_gethash, NULL, NULL);
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
void wtp_radio_close(void) {
|
2014-02-08 18:03:38 +01:00
|
|
|
int i;
|
|
|
|
struct capwap_list_item* itemwlan;
|
2013-12-20 23:14:34 +01:00
|
|
|
|
|
|
|
ASSERT(g_wtp.radios != NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < g_wtp.radios->count; i++) {
|
|
|
|
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
|
|
|
|
|
|
|
if (radio->antenna.selections) {
|
|
|
|
capwap_array_free(radio->antenna.selections);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radio->wlan) {
|
2014-02-08 18:03:38 +01:00
|
|
|
for (itemwlan = radio->wlan->first; itemwlan != NULL; itemwlan = itemwlan->next) {
|
|
|
|
struct wtp_radio_wlan* wlan = (struct wtp_radio_wlan*)itemwlan->item;
|
|
|
|
|
|
|
|
/* Destroy BSS interface */
|
|
|
|
if (wlan->wlanhandle) {
|
|
|
|
wifi_wlan_destroy(wlan->wlanhandle);
|
|
|
|
}
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
capwap_list_free(radio->wlan);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radio->wlanpool) {
|
|
|
|
for (itemwlan = radio->wlanpool->first; itemwlan != NULL; itemwlan = itemwlan->next) {
|
|
|
|
struct wtp_radio_wlanpool* wlanpool = (struct wtp_radio_wlanpool*)itemwlan->item;
|
|
|
|
|
|
|
|
/* Destroy BSS interface */
|
|
|
|
if (wlanpool->wlanhandle) {
|
|
|
|
wifi_wlan_destroy(wlanpool->wlanhandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
capwap_list_free(radio->wlanpool);
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
capwap_array_resize(g_wtp.radios, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
void wtp_radio_free(void) {
|
|
|
|
ASSERT(g_wtp.radios != NULL);
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
if (g_wtp.radios->count > 0) {
|
|
|
|
wtp_radio_close();
|
2013-12-21 23:50:15 +01:00
|
|
|
}
|
|
|
|
|
2013-12-20 23:14:34 +01:00
|
|
|
capwap_array_free(g_wtp.radios);
|
2014-01-18 19:13:10 +01:00
|
|
|
capwap_hash_free(g_wtp.aclstations);
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet) {
|
|
|
|
int i;
|
2014-01-21 19:54:59 +01:00
|
|
|
int result = 0;
|
2013-12-20 23:14:34 +01:00
|
|
|
unsigned short binding;
|
|
|
|
struct capwap_array* messageelements;
|
2014-01-21 19:54:59 +01:00
|
|
|
struct capwap_array* updateitems;
|
|
|
|
struct wtp_update_configuration_item* item;
|
2013-12-20 23:14:34 +01:00
|
|
|
|
|
|
|
ASSERT(packet != NULL);
|
|
|
|
|
2014-01-21 19:54:59 +01:00
|
|
|
/* */
|
|
|
|
updateitems = capwap_array_create(sizeof(struct wtp_update_configuration_item), 0, 1);
|
|
|
|
|
2013-12-20 23:14:34 +01:00
|
|
|
/* */
|
|
|
|
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
|
|
|
if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
|
2014-02-08 18:03:38 +01:00
|
|
|
struct wtp_radio* radio;
|
2014-01-10 13:25:28 +01:00
|
|
|
struct capwap_list_item* search;
|
2013-12-20 23:14:34 +01:00
|
|
|
|
2014-01-10 13:25:28 +01:00
|
|
|
/* Set radio configuration and invalidate the old values */
|
|
|
|
search = packet->messages->first;
|
|
|
|
while (search) {
|
|
|
|
struct capwap_message_element_itemlist* messageelement = (struct capwap_message_element_itemlist*)search->item;
|
|
|
|
|
|
|
|
/* Parsing only IEEE 802.11 message element */
|
|
|
|
if (IS_80211_MESSAGE_ELEMENTS(messageelement->type)) {
|
|
|
|
switch (messageelement->type) {
|
|
|
|
case CAPWAP_ELEMENT_80211_DIRECTSEQUENCECONTROL: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_directsequencecontrol_element* directsequencecontrol;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
directsequencecontrol = *(struct capwap_80211_directsequencecontrol_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(directsequencecontrol->radioid);
|
|
|
|
if (radio) {
|
|
|
|
memset(&radio->directsequencecontrol, 0, sizeof(struct capwap_80211_directsequencecontrol_element));
|
|
|
|
memset(&radio->ofdmcontrol, 0, sizeof(struct capwap_80211_ofdmcontrol_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_OFDMCONTROL: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_ofdmcontrol_element* ofdmcontrol;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
ofdmcontrol = *(struct capwap_80211_ofdmcontrol_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(ofdmcontrol->radioid);
|
|
|
|
if (radio) {
|
|
|
|
memset(&radio->directsequencecontrol, 0, sizeof(struct capwap_80211_directsequencecontrol_element));
|
|
|
|
memset(&radio->ofdmcontrol, 0, sizeof(struct capwap_80211_ofdmcontrol_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_wtpradioinformation_element* radioinformation;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
radioinformation = *(struct capwap_80211_wtpradioinformation_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(radioinformation->radioid);
|
|
|
|
if (radio && (radio->radioid == radioinformation->radioid)) {
|
|
|
|
memcpy(&radio->radioinformation, radioinformation, sizeof(struct capwap_80211_wtpradioinformation_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next */
|
|
|
|
search = search->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update new values */
|
|
|
|
search = packet->messages->first;
|
2013-12-20 23:14:34 +01:00
|
|
|
while (search) {
|
|
|
|
struct capwap_message_element_itemlist* messageelement = (struct capwap_message_element_itemlist*)search->item;
|
|
|
|
|
|
|
|
/* Parsing only IEEE 802.11 message element */
|
|
|
|
if (IS_80211_MESSAGE_ELEMENTS(messageelement->type)) {
|
|
|
|
switch (messageelement->type) {
|
|
|
|
case CAPWAP_ELEMENT_80211_ANTENNA: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_antenna_element* antenna;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
antenna = *(struct capwap_80211_antenna_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(antenna->radioid);
|
|
|
|
if (radio && (radio->radioid == antenna->radioid)) {
|
|
|
|
capwap_element_80211_antenna_copy(&radio->antenna, antenna);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_MACOPERATION: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_macoperation_element* macoperation;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
macoperation = *(struct capwap_80211_macoperation_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(macoperation->radioid);
|
|
|
|
if (radio && (radio->radioid == macoperation->radioid)) {
|
|
|
|
memcpy(&radio->macoperation, macoperation, sizeof(struct capwap_80211_macoperation_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_MULTIDOMAINCAPABILITY: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_multidomaincapability_element* multidomaincapability;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
multidomaincapability = *(struct capwap_80211_multidomaincapability_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(multidomaincapability->radioid);
|
|
|
|
if (radio && (radio->radioid == multidomaincapability->radioid)) {
|
|
|
|
memcpy(&radio->multidomaincapability, multidomaincapability, sizeof(struct capwap_80211_multidomaincapability_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_DIRECTSEQUENCECONTROL: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_directsequencecontrol_element* directsequencecontrol;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
directsequencecontrol = *(struct capwap_80211_directsequencecontrol_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(directsequencecontrol->radioid);
|
|
|
|
if (radio && (radio->radioid == directsequencecontrol->radioid)) {
|
2014-01-21 19:54:59 +01:00
|
|
|
if (radio->radioinformation.radiotype & (CAPWAP_RADIO_TYPE_80211B | CAPWAP_RADIO_TYPE_80211G)) {
|
|
|
|
memcpy(&radio->directsequencecontrol, directsequencecontrol, sizeof(struct capwap_80211_directsequencecontrol_element));
|
2014-01-10 13:25:28 +01:00
|
|
|
|
2014-01-21 19:54:59 +01:00
|
|
|
/* Pending change radio channel */
|
|
|
|
item = (struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, updateitems->count);
|
|
|
|
item->type = WTP_UPDATE_FREQUENCY_DSSS;
|
|
|
|
item->radio = radio;
|
2014-01-10 13:25:28 +01:00
|
|
|
}
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_OFDMCONTROL: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_ofdmcontrol_element* ofdmcontrol;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
ofdmcontrol = *(struct capwap_80211_ofdmcontrol_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(ofdmcontrol->radioid);
|
|
|
|
if (radio && (radio->radioid == ofdmcontrol->radioid)) {
|
2014-01-21 19:54:59 +01:00
|
|
|
if (radio->radioinformation.radiotype & CAPWAP_RADIO_TYPE_80211A) {
|
|
|
|
memcpy(&radio->ofdmcontrol, ofdmcontrol, sizeof(struct capwap_80211_ofdmcontrol_element));
|
2014-01-10 13:25:28 +01:00
|
|
|
|
2014-01-21 19:54:59 +01:00
|
|
|
/* Pending change radio channel */
|
|
|
|
item = (struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, updateitems->count);
|
|
|
|
item->type = WTP_UPDATE_FREQUENCY_OFDM;
|
|
|
|
item->radio = radio;
|
2014-01-10 13:25:28 +01:00
|
|
|
}
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_RATESET: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_rateset_element* rateset;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
rateset = *(struct capwap_80211_rateset_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(rateset->radioid);
|
|
|
|
if (radio && (radio->radioid == rateset->radioid)) {
|
|
|
|
memcpy(&radio->rateset, rateset, sizeof(struct capwap_80211_rateset_element));
|
2014-01-21 19:54:59 +01:00
|
|
|
|
|
|
|
/* Pending change radio rates */
|
|
|
|
item = (struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, updateitems->count);
|
|
|
|
item->type = WTP_UPDATE_RATES;
|
|
|
|
item->radio = radio;
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_SUPPORTEDRATES: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_supportedrates_element* supportedrates;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
supportedrates = *(struct capwap_80211_supportedrates_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(supportedrates->radioid);
|
|
|
|
if (radio && (radio->radioid == supportedrates->radioid)) {
|
|
|
|
memcpy(&radio->supportedrates, supportedrates, sizeof(struct capwap_80211_supportedrates_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_TXPOWER: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_txpower_element* txpower;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
txpower = *(struct capwap_80211_txpower_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(txpower->radioid);
|
|
|
|
if (radio && (radio->radioid == txpower->radioid)) {
|
|
|
|
memcpy(&radio->txpower, txpower, sizeof(struct capwap_80211_txpower_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_WTP_QOS: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_wtpqos_element* qos;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
qos = *(struct capwap_80211_wtpqos_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(qos->radioid);
|
|
|
|
if (radio && (radio->radioid == qos->radioid)) {
|
|
|
|
memcpy(&radio->qos, qos, sizeof(struct capwap_80211_wtpqos_element));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAPWAP_ELEMENT_80211_WTP_RADIO_CONF: {
|
|
|
|
messageelements = (struct capwap_array*)messageelement->data;
|
|
|
|
if (messageelements && (messageelements->count > 0)) {
|
|
|
|
struct capwap_80211_wtpradioconf_element* radioconfig;
|
|
|
|
|
|
|
|
for (i = 0; i < messageelements->count; i++) {
|
|
|
|
radioconfig = *(struct capwap_80211_wtpradioconf_element**)capwap_array_get_item_pointer(messageelements, i);
|
|
|
|
radio = wtp_radio_get_phy(radioconfig->radioid);
|
|
|
|
if (radio && (radio->radioid == radioconfig->radioid)) {
|
|
|
|
memcpy(&radio->radioconfig, radioconfig, sizeof(struct capwap_80211_wtpradioconf_element));
|
2014-01-21 19:54:59 +01:00
|
|
|
|
|
|
|
/* Pending change radio configuration */
|
|
|
|
item = (struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, updateitems->count);
|
|
|
|
item->type = WTP_UPDATE_CONFIGURATION;
|
|
|
|
item->radio = radio;
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next */
|
|
|
|
search = search->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-21 19:54:59 +01:00
|
|
|
/* Update radio frequency */
|
|
|
|
for (i = 0; (i < updateitems->count) && !result; i++) {
|
|
|
|
struct wtp_update_configuration_item* item = (struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, i);
|
|
|
|
|
|
|
|
switch (item->type) {
|
|
|
|
case WTP_UPDATE_FREQUENCY_DSSS: {
|
2014-02-08 18:03:38 +01:00
|
|
|
result = wifi_device_setfrequency(item->radio->devicehandle, WIFI_BAND_2GHZ, item->radio->radioinformation.radiotype, item->radio->directsequencecontrol.currentchannel);
|
2014-01-21 19:54:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WTP_UPDATE_FREQUENCY_OFDM: {
|
2014-02-08 18:03:38 +01:00
|
|
|
result = wifi_device_setfrequency(item->radio->devicehandle, WIFI_BAND_5GHZ, item->radio->radioinformation.radiotype, item->radio->ofdmcontrol.currentchannel);
|
2014-01-21 19:54:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update radio configuration */
|
|
|
|
for (i = 0; (i < updateitems->count) && !result; i++) {
|
|
|
|
struct wtp_update_configuration_item* item = (struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, i);
|
|
|
|
|
|
|
|
switch (item->type) {
|
|
|
|
case WTP_UPDATE_RATES: {
|
2014-02-08 18:03:38 +01:00
|
|
|
result = wifi_device_updaterates(item->radio->devicehandle, item->radio->rateset.rateset, item->radio->rateset.ratesetcount);
|
2014-01-21 19:54:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WTP_UPDATE_CONFIGURATION: {
|
|
|
|
struct device_setconfiguration_params params;
|
|
|
|
|
|
|
|
memset(¶ms, 0, sizeof(struct device_setconfiguration_params));
|
|
|
|
params.shortpreamble = ((item->radio->radioconfig.shortpreamble == CAPWAP_WTP_RADIO_CONF_SHORTPREAMBLE_ENABLE) ? 1 : 0);
|
|
|
|
params.maxbssid = item->radio->radioconfig.maxbssid;
|
|
|
|
params.dtimperiod = item->radio->radioconfig.dtimperiod;
|
|
|
|
memcpy(params.bssid, item->radio->radioconfig.bssid, ETH_ALEN);
|
|
|
|
params.beaconperiod = item->radio->radioconfig.beaconperiod;
|
|
|
|
memcpy(params.country, item->radio->radioconfig.country, WIFI_COUNTRY_LENGTH);
|
2014-02-08 18:03:38 +01:00
|
|
|
result = wifi_device_setconfiguration(item->radio->devicehandle, ¶ms);
|
2014-01-21 19:54:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
capwap_array_free(updateitems);
|
|
|
|
return result;
|
2013-12-20 23:14:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
struct wtp_radio* wtp_radio_create_phy(void) {
|
|
|
|
struct wtp_radio* radio;
|
|
|
|
|
|
|
|
/* Create disabled radio */
|
|
|
|
radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, g_wtp.radios->count);
|
|
|
|
radio->radioid = (uint8_t)g_wtp.radios->count;
|
|
|
|
radio->status = WTP_RADIO_DISABLED;
|
|
|
|
|
|
|
|
/* Init configuration radio */
|
2014-02-08 18:03:38 +01:00
|
|
|
radio->wlan = capwap_list_create();
|
|
|
|
radio->wlanpool = capwap_list_create();
|
2013-12-20 23:14:34 +01:00
|
|
|
radio->antenna.selections = capwap_array_create(sizeof(uint8_t), 0, 1);
|
|
|
|
return radio;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
struct wtp_radio* wtp_radio_get_phy(uint8_t radioid) {
|
|
|
|
int i;
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
/* Check */
|
|
|
|
if (!IS_VALID_RADIOID(radioid)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-12-20 23:14:34 +01:00
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
/* Retrieve radio */
|
2013-12-20 23:14:34 +01:00
|
|
|
for (i = 0; i < g_wtp.radios->count; i++) {
|
|
|
|
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
|
|
|
if (radioid == radio->radioid) {
|
|
|
|
return radio;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
struct wtp_radio_wlan* wtp_radio_get_wlan(struct wtp_radio* radio, uint8_t wlanid) {
|
2014-02-08 18:03:38 +01:00
|
|
|
struct capwap_list_item* itemwlan;
|
2013-12-20 23:14:34 +01:00
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
ASSERT(radio != NULL);
|
2013-12-20 23:14:34 +01:00
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
/* Check */
|
|
|
|
if (!IS_VALID_WLANID(wlanid)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve BSS */
|
|
|
|
for (itemwlan = radio->wlan->first; itemwlan != NULL; itemwlan = itemwlan->next) {
|
|
|
|
struct wtp_radio_wlan* wlan = (struct wtp_radio_wlan*)itemwlan->item;
|
|
|
|
if (wlanid == wlan->wlanid) {
|
2013-12-20 23:14:34 +01:00
|
|
|
return wlan;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-12-21 23:50:15 +01:00
|
|
|
/* */
|
2014-02-08 18:03:38 +01:00
|
|
|
void wtp_radio_update_fdevent(struct wtp_fds* fds) {
|
2013-12-21 23:50:15 +01:00
|
|
|
int count;
|
2014-02-08 18:03:38 +01:00
|
|
|
struct pollfd* fdsbuffer;
|
|
|
|
|
|
|
|
ASSERT(fds != NULL);
|
2013-12-21 23:50:15 +01:00
|
|
|
|
|
|
|
/* Retrieve number of File Descriptor Event */
|
|
|
|
count = wifi_event_getfd(NULL, NULL, 0);
|
|
|
|
if (count < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
/* Resize poll */
|
|
|
|
if (fds->eventscount != count) {
|
|
|
|
fdsbuffer = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * (fds->fdsnetworkcount + count));
|
|
|
|
if (fds->fdspoll && (fds->fdsnetworkcount > 0)) {
|
|
|
|
memcpy(fdsbuffer, fds->fdspoll, sizeof(struct pollfd) * fds->fdsnetworkcount);
|
|
|
|
capwap_free(fds->fdspoll);
|
|
|
|
}
|
2013-12-21 23:50:15 +01:00
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
fds->fdspoll = fdsbuffer;
|
2013-12-21 23:50:15 +01:00
|
|
|
|
|
|
|
/* Events Callback */
|
2014-02-08 18:03:38 +01:00
|
|
|
if (fds->events) {
|
|
|
|
capwap_free(fds->events);
|
2013-12-21 23:50:15 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
fds->events = (struct wifi_event*)((count > 0) ? capwap_alloc(sizeof(struct wifi_event) * count) : NULL);
|
2013-12-21 23:50:15 +01:00
|
|
|
|
|
|
|
/* */
|
2014-02-08 18:03:38 +01:00
|
|
|
fds->eventscount = count;
|
|
|
|
fds->fdstotalcount = fds->fdsnetworkcount + count;
|
2013-12-21 23:50:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve File Descriptor Event */
|
|
|
|
if (count > 0) {
|
2014-02-08 18:03:38 +01:00
|
|
|
ASSERT(fds->fdspoll != NULL);
|
|
|
|
wifi_event_getfd(&fds->fdspoll[fds->fdsnetworkcount], fds->events, fds->eventscount);
|
2013-12-21 23:50:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-07 18:14:32 +01:00
|
|
|
/* */
|
|
|
|
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid) {
|
2013-12-20 23:14:34 +01:00
|
|
|
struct wtp_radio* radio;
|
|
|
|
struct wtp_radio_wlan* wlan;
|
2014-02-08 18:03:38 +01:00
|
|
|
struct wtp_radio_wlanpool* wlanpool;
|
|
|
|
struct capwap_list_item* itemwlan;
|
|
|
|
struct capwap_list_item* itemwlanpool;
|
|
|
|
struct wlan_startap_params params;
|
2013-12-20 23:14:34 +01:00
|
|
|
struct capwap_80211_addwlan_element* addwlan;
|
|
|
|
|
2014-04-14 22:33:12 +02:00
|
|
|
ASSERT(packet != NULL);
|
|
|
|
|
2013-12-20 23:14:34 +01:00
|
|
|
/* Get message elements */
|
|
|
|
addwlan = (struct capwap_80211_addwlan_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_80211_ADD_WLAN);
|
|
|
|
if (!addwlan) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get physical radio */
|
|
|
|
radio = wtp_radio_get_phy(addwlan->radioid);
|
|
|
|
if (!radio) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if virtual interface is already exist */
|
|
|
|
wlan = wtp_radio_get_wlan(radio, addwlan->wlanid);
|
|
|
|
if (wlan) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
/* Verify exist interface into pool */
|
|
|
|
if (!radio->wlanpool->first) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-12-20 23:14:34 +01:00
|
|
|
/* Prepare physical interface for create wlan */
|
|
|
|
if (!radio->wlan->count) {
|
|
|
|
if (wtp_radio_configure_phy(radio)) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
/* Get interface from pool */
|
|
|
|
itemwlanpool = capwap_itemlist_remove_head(radio->wlanpool);
|
|
|
|
wlanpool = (struct wtp_radio_wlanpool*)itemwlanpool->item;
|
2013-12-20 23:14:34 +01:00
|
|
|
|
2014-02-09 21:55:10 +01:00
|
|
|
/* Create interface used */
|
|
|
|
itemwlan = capwap_itemlist_create(sizeof(struct wtp_radio_wlan));
|
|
|
|
wlan = (struct wtp_radio_wlan*)itemwlan->item;
|
|
|
|
wlan->wlanid = addwlan->wlanid;
|
|
|
|
wlan->wlanhandle = wlanpool->wlanhandle;
|
|
|
|
wlan->radio = wlanpool->radio;
|
|
|
|
|
2014-01-21 19:54:59 +01:00
|
|
|
/* Wlan configuration */
|
2014-02-08 18:03:38 +01:00
|
|
|
memset(¶ms, 0, sizeof(struct wlan_startap_params));
|
2014-02-09 21:55:10 +01:00
|
|
|
params.send_mgmtframe = wtp_radio_send_mgmtframe_to_ac;
|
|
|
|
params.send_mgmtframe_to_ac_cbparam = (void*)wlan;
|
2014-02-08 18:03:38 +01:00
|
|
|
params.ssid = (const char*)addwlan->ssid;
|
|
|
|
params.ssid_hidden = addwlan->suppressssid;
|
2014-01-21 19:54:59 +01:00
|
|
|
params.capability = addwlan->capability;
|
|
|
|
params.qos = addwlan->qos;
|
|
|
|
params.authmode = addwlan->authmode;
|
|
|
|
params.macmode = addwlan->macmode;
|
|
|
|
params.tunnelmode = addwlan->tunnelmode;
|
2014-01-10 13:25:28 +01:00
|
|
|
/* TODO (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_80211_IE) */
|
|
|
|
|
2013-12-20 23:14:34 +01:00
|
|
|
/* Start AP */
|
2014-02-08 18:03:38 +01:00
|
|
|
if (wifi_wlan_startap(wlanpool->wlanhandle, ¶ms)) {
|
2014-02-09 21:55:10 +01:00
|
|
|
/* Set interface to pool */
|
|
|
|
capwap_itemlist_free(itemwlan);
|
2014-02-08 18:03:38 +01:00
|
|
|
capwap_itemlist_insert_before(radio->wlanpool, NULL, itemwlanpool);
|
2013-12-20 23:14:34 +01:00
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-02-08 18:03:38 +01:00
|
|
|
/* Move interface from pool to used */
|
|
|
|
capwap_itemlist_free(itemwlanpool);
|
|
|
|
capwap_itemlist_insert_after(radio->wlan, NULL, itemwlan);
|
|
|
|
|
2013-12-21 23:50:15 +01:00
|
|
|
/* Update Event File Descriptor */
|
2014-02-08 18:03:38 +01:00
|
|
|
wtp_radio_update_fdevent(&g_wtp.fds);
|
2013-12-21 23:50:15 +01:00
|
|
|
|
|
|
|
/* Retrieve macaddress of new device */
|
2013-12-20 23:14:34 +01:00
|
|
|
bssid->radioid = addwlan->radioid;
|
|
|
|
bssid->wlanid = addwlan->wlanid;
|
2014-02-08 18:03:38 +01:00
|
|
|
wifi_wlan_getbssid(wlan->wlanhandle, bssid->bssid);
|
2013-12-20 23:14:34 +01:00
|
|
|
|
2013-12-07 18:14:32 +01:00
|
|
|
return CAPWAP_RESULTCODE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
uint32_t wtp_radio_update_wlan(struct capwap_parsed_packet* packet) {
|
|
|
|
/* TODO */
|
|
|
|
return CAPWAP_RESULTCODE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
uint32_t wtp_radio_delete_wlan(struct capwap_parsed_packet* packet) {
|
|
|
|
/* TODO */
|
|
|
|
return CAPWAP_RESULTCODE_SUCCESS;
|
|
|
|
}
|
2014-01-18 19:13:10 +01:00
|
|
|
|
2014-04-14 22:33:12 +02:00
|
|
|
/* */
|
|
|
|
uint32_t wtp_radio_add_station(struct capwap_parsed_packet* packet) {
|
|
|
|
struct capwap_addstation_element* addstation;
|
|
|
|
struct capwap_80211_station_element* station80211;
|
|
|
|
struct wtp_radio* radio;
|
|
|
|
struct wtp_radio_wlan* wlan;
|
|
|
|
struct station_add_params stationparams;
|
|
|
|
|
|
|
|
/* Get message elements */
|
|
|
|
addstation = (struct capwap_addstation_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_ADDSTATION);
|
|
|
|
station80211 = (struct capwap_80211_station_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_80211_STATION);
|
|
|
|
if (!station80211 || (addstation->radioid != station80211->radioid)) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get physical radio */
|
|
|
|
radio = wtp_radio_get_phy(addstation->radioid);
|
|
|
|
if (!radio) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get virtual interface */
|
|
|
|
wlan = wtp_radio_get_wlan(radio, station80211->wlanid);
|
|
|
|
if (!wlan) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Authorize station */
|
|
|
|
memset(&stationparams, 0, sizeof(struct station_add_params));
|
|
|
|
stationparams.address = station80211->address;
|
|
|
|
|
|
|
|
if (wifi_station_add(wlan->wlanhandle, &stationparams)) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CAPWAP_RESULTCODE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
uint32_t wtp_radio_delete_station(struct capwap_parsed_packet* packet) {
|
2014-04-15 22:26:31 +02:00
|
|
|
struct wtp_radio* radio;
|
|
|
|
struct station_delete_params stationparams;
|
|
|
|
struct capwap_deletestation_element* deletestation;
|
|
|
|
|
|
|
|
/* Get message elements */
|
|
|
|
deletestation = (struct capwap_deletestation_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_DELETESTATION);
|
|
|
|
|
|
|
|
/* Get physical radio */
|
|
|
|
radio = wtp_radio_get_phy(deletestation->radioid);
|
|
|
|
if (!radio) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Authorize station */
|
|
|
|
memset(&stationparams, 0, sizeof(struct station_delete_params));
|
|
|
|
stationparams.address = deletestation->address;
|
|
|
|
|
|
|
|
if (wifi_station_delete(radio->devicehandle, &stationparams)) {
|
|
|
|
return CAPWAP_RESULTCODE_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-04-14 22:33:12 +02:00
|
|
|
return CAPWAP_RESULTCODE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-01-18 19:13:10 +01:00
|
|
|
/* */
|
|
|
|
int wtp_radio_acl_station(const uint8_t* macaddress) {
|
|
|
|
ASSERT(macaddress != NULL);
|
|
|
|
|
|
|
|
/* Check if exist ACL for station */
|
|
|
|
if (capwap_hash_hasitem(g_wtp.aclstations, macaddress)) {
|
|
|
|
return ((g_wtp.defaultaclstations == WTP_RADIO_ACL_STATION_ALLOW) ? WTP_RADIO_ACL_STATION_DENY : WTP_RADIO_ACL_STATION_ALLOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default ACL station */
|
|
|
|
return g_wtp.defaultaclstations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
|
|
|
void wtp_radio_acl_addstation(const uint8_t* macaddress) {
|
|
|
|
ASSERT(macaddress != NULL);
|
|
|
|
|
|
|
|
capwap_hash_add(g_wtp.aclstations, macaddress, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wtp_radio_acl_deletestation(const uint8_t* macaddress) {
|
|
|
|
ASSERT(macaddress != NULL);
|
|
|
|
|
|
|
|
capwap_hash_delete(g_wtp.aclstations, macaddress);
|
|
|
|
}
|