Changed the management of the wireless interfaces, from creation to usage.

The virtual interfaces are created at the startup of the wtp to reduce the time
required to configure a wireless interface.
Applied some patches to build the WTP on OpenWRT trunk
This commit is contained in:
vemax78
2014-02-08 18:03:38 +01:00
parent 64a8bdfa1e
commit 025880583c
21 changed files with 1468 additions and 744 deletions

View File

@ -7,6 +7,7 @@
#include "capwap_element.h"
#include "capwap_dtls.h"
#include "wtp_dfa.h"
#include "wtp_radio.h"
#include <arpa/inet.h>
#include <libconfig.h>
@ -14,8 +15,9 @@
struct wtp_t g_wtp;
/* Local param */
#define WTP_STANDARD_NAME "Unknown WTP"
#define WTP_STANDARD_LOCATION "Unknown Location"
#define WTP_STANDARD_NAME "Unknown WTP"
#define WTP_STANDARD_LOCATION "Unknown Location"
#define WTP_WAIT_RADIO_INITIALIZATION 1
static char g_configurationfile[260] = WTP_STANDARD_CONFIGURATION_FILE;
@ -186,7 +188,7 @@ static void wtp_print_usage(void) {
static int wtp_parsing_radio_configuration(config_setting_t* configElement, struct wtp_radio* radio) {
int i;
int configBool;
long int configInt;
LIBCONFIG_LOOKUP_INT_ARG configInt;
const char* configString;
config_setting_t* configItems;
config_setting_t* configSection;
@ -458,6 +460,16 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
return 0;
}
if (config_setting_lookup_string(configElement, "bssprefixname", &configString) == CONFIG_TRUE) {
if (strlen(configString) < IFNAMSIZ) {
strcpy(radio->wlanprefix, configString);
} else {
return 0;
}
} else {
return 0;
}
if (config_setting_lookup_int(configElement, "dtimperiod", &configInt) == CONFIG_TRUE) {
if ((configInt > 0) && (configInt < 256)) {
radio->radioconfig.dtimperiod = (uint8_t)configInt;
@ -501,17 +513,16 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
/* Parsing configuration */
static int wtp_parsing_configuration_1_0(config_t* config) {
int i;
int result;
int configInt;
int configBool;
int configIPv4;
int configIPv6;
long int configLongInt;
LIBCONFIG_LOOKUP_INT_ARG configInt;
const char* configString;
config_setting_t* configSetting;
/* Logging configuration */
if (config_lookup_bool(config, "logging.enable", &configInt) == CONFIG_TRUE) {
if (!configInt) {
if (config_lookup_bool(config, "logging.enable", &configBool) == CONFIG_TRUE) {
if (!configBool) {
capwap_logging_verboselevel(CAPWAP_LOGGING_NONE);
capwap_logging_disable_allinterface();
} else {
@ -559,8 +570,8 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set running mode */
if (config_lookup_bool(config, "application.standalone", &configInt) == CONFIG_TRUE) {
g_wtp.standalone = ((configInt != 0) ? 1 : 0);
if (config_lookup_bool(config, "application.standalone", &configBool) == CONFIG_TRUE) {
g_wtp.standalone = ((configBool != 0) ? 1 : 0);
}
/* Set name of WTP */
@ -623,20 +634,20 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
/* Set tunnelmode of WTP */
if (config_lookup(config, "application.tunnelmode") != NULL) {
g_wtp.mactunnel.mode = 0;
if (config_lookup_bool(config, "application.tunnelmode.nativeframe", &configInt) == CONFIG_TRUE) {
if (configInt != 0) {
if (config_lookup_bool(config, "application.tunnelmode.nativeframe", &configBool) == CONFIG_TRUE) {
if (configBool != 0) {
g_wtp.mactunnel.mode |= CAPWAP_WTP_NATIVE_FRAME_TUNNEL;
}
}
if (config_lookup_bool(config, "application.tunnelmode.ethframe", &configInt) == CONFIG_TRUE) {
if (configInt != 0) {
if (config_lookup_bool(config, "application.tunnelmode.ethframe", &configBool) == CONFIG_TRUE) {
if (configBool != 0) {
g_wtp.mactunnel.mode |= CAPWAP_WTP_8023_FRAME_TUNNEL;
}
}
if (config_lookup_bool(config, "application.tunnelmode.localbridging", &configInt) == CONFIG_TRUE) {
if (configInt != 0) {
if (config_lookup_bool(config, "application.tunnelmode.localbridging", &configBool) == CONFIG_TRUE) {
if (configBool != 0) {
g_wtp.mactunnel.mode |= CAPWAP_WTP_LOCAL_BRIDGING;
}
}
@ -655,8 +666,8 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set VendorID Boardinfo of WTP */
if (config_lookup_int(config, "application.boardinfo.idvendor", &configLongInt) == CONFIG_TRUE) {
g_wtp.boarddata.vendor = (unsigned long)configLongInt;
if (config_lookup_int(config, "application.boardinfo.idvendor", &configInt) == CONFIG_TRUE) {
g_wtp.boarddata.vendor = (unsigned long)configInt;
}
/* Set Element Boardinfo of WTP */
@ -769,22 +780,48 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
radio = wtp_radio_create_phy();
strcpy(radio->device, configString);
if (config_setting_lookup_bool(configElement, "enabled", &configInt) == CONFIG_TRUE) {
if (configInt) {
if (config_setting_lookup_bool(configElement, "enabled", &configBool) == CONFIG_TRUE) {
if (configBool) {
/* Retrieve radio capability */
if (wtp_parsing_radio_configuration(configElement, radio)) {
/* Initialize radio device */
if (config_setting_lookup_string(configElement, "driver", &configString) == CONFIG_TRUE) {
if (*configString && (strlen(configString) < WIFI_DRIVER_NAME_SIZE)) {
result = wifi_device_connect(radio->radioid, radio->device, configString);
if (!result) {
radio->devicehandle = wifi_device_connect(radio->device, configString);
if (radio->devicehandle) {
radio->status = WTP_RADIO_ENABLED;
capwap_logging_info("Register radioid %d with radio device: %s - %s", radio->radioid, radio->device, configString);
/* Update radio capability with device query */
capability = wifi_device_getcapability(radio->radioid);
capability = wifi_device_getcapability(radio->devicehandle);
if (capability) {
/* TODO */
uint8_t bssid;
char wlanname[IFNAMSIZ];
struct capwap_list_item* itemwlan;
struct wtp_radio_wlanpool* wlanpool;
/* Create interface */
for (bssid = 0; bssid < radio->radioconfig.maxbssid; bssid++) {
sprintf(wlanname, "%s%02d.%02d", radio->wlanprefix, (int)radio->radioid, (int)bssid + 1);
if (wifi_iface_index(wlanname)) {
capwap_logging_error("interface %s already exists", wlanname);
return 0;
}
/* */
itemwlan = capwap_itemlist_create(sizeof(struct wtp_radio_wlanpool));
wlanpool = (struct wtp_radio_wlanpool*)itemwlan->item;
wlanpool->radio = radio;
wlanpool->wlanhandle = wifi_wlan_create(radio->devicehandle, wlanname);
if (!wlanpool->wlanhandle) {
capwap_logging_error("Unable to create interface: %s", wlanname);
return 0;
}
/* Appent to wlan pool */
capwap_logging_debug("Created wlan interface: %s", wlanname);
capwap_itemlist_insert_after(radio->wlanpool, NULL, itemwlan);
}
}
} else {
radio->status = WTP_RADIO_HWFAILURE;
@ -855,7 +892,7 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
for (i = 0; i < count; i++) {
config_setting_t* configElement = config_setting_get_elem(configSetting, i);
if (configElement != NULL) {
long int configVendor;
LIBCONFIG_LOOKUP_INT_ARG configVendor;
if (config_setting_lookup_int(configElement, "idvendor", &configVendor) == CONFIG_TRUE) {
const char* configType;
if (config_setting_lookup_string(configElement, "type", &configType) == CONFIG_TRUE) {
@ -916,9 +953,9 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set Timer of WTP */
if (config_lookup_int(config, "application.timer.statistics", &configLongInt) == CONFIG_TRUE) {
if ((configLongInt > 0) && (configLongInt < 65536)) {
g_wtp.statisticstimer.timer = (unsigned short)configLongInt;
if (config_lookup_int(config, "application.timer.statistics", &configInt) == CONFIG_TRUE) {
if ((configInt > 0) && (configInt < 65536)) {
g_wtp.statisticstimer.timer = (unsigned short)configInt;
} else {
capwap_logging_error("Invalid configuration file, invalid application.timer.statistics value");
return 0;
@ -926,8 +963,8 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set DTLS of WTP */
if (config_lookup_bool(config, "application.dtls.enable", &configInt) == CONFIG_TRUE) {
if (configInt != 0) {
if (config_lookup_bool(config, "application.dtls.enable", &configBool) == CONFIG_TRUE) {
if (configBool != 0) {
struct capwap_dtls_param dtlsparam;
/* Init dtls param */
@ -937,14 +974,14 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
/* Set DTLS Policy of WTP */
if (config_lookup(config, "application.dtls.dtlspolicy") != NULL) {
g_wtp.validdtlsdatapolicy = 0;
if (config_lookup_bool(config, "application.dtls.dtlspolicy.cleardatachannel", &configInt) == CONFIG_TRUE) {
if (configInt != 0) {
if (config_lookup_bool(config, "application.dtls.dtlspolicy.cleardatachannel", &configBool) == CONFIG_TRUE) {
if (configBool != 0) {
g_wtp.validdtlsdatapolicy |= CAPWAP_ACDESC_CLEAR_DATA_CHANNEL_ENABLED;
}
}
if (config_lookup_bool(config, "application.dtls.dtlspolicy.dtlsdatachannel", &configInt) == CONFIG_TRUE) {
if (configInt != 0) {
if (config_lookup_bool(config, "application.dtls.dtlspolicy.dtlsdatachannel", &configBool) == CONFIG_TRUE) {
if (configBool != 0) {
g_wtp.validdtlsdatapolicy |= CAPWAP_ACDESC_DTLS_DATA_CHANNEL_ENABLED;
}
}
@ -1058,9 +1095,9 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set mtu of WTP */
if (config_lookup_int(config, "application.network.mtu", &configLongInt) == CONFIG_TRUE) {
if ((configLongInt > 0) && (configLongInt < 65536)) {
g_wtp.mtu = (unsigned short)configLongInt;
if (config_lookup_int(config, "application.network.mtu", &configInt) == CONFIG_TRUE) {
if ((configInt > 0) && (configInt < 65536)) {
g_wtp.mtu = (unsigned short)configInt;
} else {
capwap_logging_error("Invalid configuration file, invalid application.network.mtu value");
return 0;
@ -1068,9 +1105,9 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set network port of WTP */
if (config_lookup_int(config, "application.network.port", &configLongInt) == CONFIG_TRUE) {
if ((configLongInt > 0) && (configLongInt < 65535)) {
g_wtp.net.bind_sock_ctrl_port = (unsigned short)configLongInt;
if (config_lookup_int(config, "application.network.port", &configInt) == CONFIG_TRUE) {
if ((configInt > 0) && (configInt < 65535)) {
g_wtp.net.bind_sock_ctrl_port = (unsigned short)configInt;
} else {
capwap_logging_error("Invalid configuration file, invalid application.network.port value");
return 0;
@ -1108,8 +1145,8 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set ip dual stack of WTP */
if (config_lookup_bool(config, "application.network.ipdualstack", &configInt) == CONFIG_TRUE) {
if (!configInt) {
if (config_lookup_bool(config, "application.network.ipdualstack", &configBool) == CONFIG_TRUE) {
if (!configBool) {
g_wtp.net.bind_ctrl_flags |= CAPWAP_IPV6ONLY_FLAG;
g_wtp.net.bind_data_flags |= CAPWAP_IPV6ONLY_FLAG;
} else {
@ -1119,8 +1156,8 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
}
/* Set search discovery of WTP */
if (config_lookup_bool(config, "application.acdiscovery.search", &configInt) == CONFIG_TRUE) {
g_wtp.acdiscoveryrequest = (configInt ? 1 : 0);
if (config_lookup_bool(config, "application.acdiscovery.search", &configBool) == CONFIG_TRUE) {
g_wtp.acdiscoveryrequest = (configBool ? 1 : 0);
}
/* Set discovery host of WTP */
@ -1271,12 +1308,54 @@ static int wtp_configure(void) {
return CAPWAP_SUCCESSFUL;
}
/* */
static void wtp_wait_radio_ready(void) {
int index;
struct wtp_fds fds;
struct timeout_control timeout;
/* Get only radio file descriptor */
memset(&fds, 0, sizeof(struct wtp_fds));
wtp_radio_update_fdevent(&fds);
capwap_init_timeout(&timeout);
for (;;) {
capwap_set_timeout(WTP_WAIT_RADIO_INITIALIZATION, &timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
/* Wait packet */
index = capwap_wait_recvready(fds.fdspoll, fds.fdstotalcount, &timeout);
if (index < 0) {
break;
} else if (!fds.events[index].event_handler) {
break;
}
fds.events[index].event_handler(fds.fdspoll[index].fd, fds.events[index].params, fds.events[index].paramscount);
}
/* */
wtp_free_fds(&fds);
}
/* */
int wtp_update_radio_in_use() {
/* TODO */
return g_wtp.radios->count;
}
/* */
void wtp_free_fds(struct wtp_fds* fds) {
ASSERT(fds != NULL);
if (fds->fdspoll) {
capwap_free(fds->fdspoll);
}
if (fds->events) {
capwap_free(fds->events);
}
}
/* Main*/
int main(int argc, char** argv) {
int value;
@ -1319,6 +1398,11 @@ int main(int argc, char** argv) {
capwap_logging_info("Running WTP in daemon mode");
}
/* Wait the initialization of radio interfaces */
capwap_logging_info("Wait the initialization of radio interfaces");
wtp_wait_radio_ready();
/* */
capwap_logging_info("Startup WTP");
/* Complete configuration WTP */

View File

@ -7,7 +7,6 @@
#include "capwap_network.h"
#include "capwap_protocol.h"
#include "wifi_drivers.h"
#include "wtp_radio.h"
/* WTP Configuration */
#define WTP_STANDARD_CONFIGURATION_FILE "/etc/capwap/wtp.conf"
@ -74,6 +73,16 @@ struct wtp_state {
int rfcDTLSSessionDelete;
};
/* */
struct wtp_fds {
struct pollfd* fdspoll;
int fdstotalcount;
int fdsnetworkcount;
struct wifi_event* events;
int eventscount;
};
/* WTP */
struct wtp_t {
int standalone;
@ -83,9 +92,7 @@ struct wtp_t {
/* */
struct capwap_network net;
struct pollfd* fds;
int fdstotalcount;
int fdsnetworkcount;
struct wtp_fds fds;
/* */
struct wtp_state dfa;
@ -137,8 +144,6 @@ struct wtp_t {
/* */
struct capwap_array* radios;
struct wifi_event* events;
int eventscount;
/* Radio ACL */
int defaultaclstations;
@ -158,6 +163,7 @@ extern struct wtp_t g_wtp;
/* */
int wtp_update_radio_in_use();
void wtp_free_fds(struct wtp_fds* fds);
/* Build capwap element helper */
void wtp_create_radioadmstate_element(struct capwap_packet_txmng* txmngpacket);

View File

@ -150,11 +150,12 @@ static void wtp_dfa_execute(struct capwap_parsed_packet* packet, struct timeout_
}
/* */
static int wtp_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct timeout_control* timeout) {
static int wtp_recvfrom(struct wtp_fds* fds, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct timeout_control* timeout) {
int index;
ASSERT(fds);
ASSERT(fdscount > 0);
ASSERT(fds != NULL);
ASSERT(fds->fdspoll != NULL);
ASSERT(fds->fdstotalcount > 0);
ASSERT(buffer != NULL);
ASSERT(size != NULL);
ASSERT(*size > 0);
@ -162,31 +163,49 @@ static int wtp_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* siz
ASSERT(recvtoaddr != NULL);
/* Wait packet */
index = capwap_wait_recvready(fds, fdscount, timeout);
index = capwap_wait_recvready(fds->fdspoll, fds->fdstotalcount, timeout);
if (index < 0) {
return index;
} else if (index >= g_wtp.fdsnetworkcount) {
int pos = index - g_wtp.fdsnetworkcount;
} else if (index >= fds->fdsnetworkcount) {
int pos = index - fds->fdsnetworkcount;
if (pos < g_wtp.eventscount) {
if (!g_wtp.events[pos].event_handler) {
if (pos < fds->eventscount) {
if (!fds->events[pos].event_handler) {
return CAPWAP_RECV_ERROR_SOCKET;
}
g_wtp.events[pos].event_handler(fds[index].fd, g_wtp.events[pos].param1, g_wtp.events[pos].param2);
fds->events[pos].event_handler(fds->fdspoll[index].fd, fds->events[pos].params, fds->events[pos].paramscount);
}
return WTP_RECV_NOERROR_RADIO;
}
/* Receive packet */
if (!capwap_recvfrom_fd(fds[index].fd, buffer, size, recvfromaddr, recvtoaddr)) {
if (!capwap_recvfrom_fd(fds->fdspoll[index].fd, buffer, size, recvfromaddr, recvtoaddr)) {
return CAPWAP_RECV_ERROR_SOCKET;
}
return index;
}
/* */
static void wtp_dfa_init_fdspool(struct wtp_fds* fds, struct capwap_network* net) {
ASSERT(fds != NULL);
ASSERT(net != NULL);
/* */
memset(fds, 0, sizeof(struct wtp_fds));
fds->fdstotalcount = CAPWAP_MAX_SOCKETS * 2;
fds->fdspoll = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * fds->fdstotalcount);
/* Retrive all socket for polling */
fds->fdsnetworkcount = capwap_network_set_pollfd(net, fds->fdspoll, fds->fdstotalcount);
fds->fdstotalcount = fds->fdsnetworkcount;
/* Update Event File Descriptor */
wtp_radio_update_fdevent(fds);
}
/* WTP state machine */
int wtp_dfa_running(void) {
int res;
@ -209,21 +228,13 @@ int wtp_dfa_running(void) {
/* Init */
capwap_init_timeout(&timeout);
capwap_set_timeout(0, &timeout, CAPWAP_TIMER_CONTROL_CONNECTION); /* Start DFA with timeout */
memset(&packet, 0, sizeof(struct capwap_parsed_packet));
/* Start DFA with timeout */
capwap_set_timeout(0, &timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
/* Configure poll struct */
g_wtp.fdstotalcount = CAPWAP_MAX_SOCKETS * 2;
g_wtp.fds = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * g_wtp.fdstotalcount);
/* Retrive all socket for polling */
g_wtp.fdsnetworkcount = capwap_network_set_pollfd(&g_wtp.net, g_wtp.fds, g_wtp.fdstotalcount);
g_wtp.fdstotalcount = g_wtp.fdsnetworkcount;
ASSERT(g_wtp.fdstotalcount > 0);
/* Update Event File Descriptor */
wtp_radio_update_fdevent();
wtp_dfa_init_fdspool(&g_wtp.fds, &g_wtp.net);
/* Handler signal */
g_wtp.running = 1;
@ -241,7 +252,7 @@ int wtp_dfa_running(void) {
isrecvpacket = 0;
buffer = bufferencrypt;
buffersize = CAPWAP_MAX_PACKET_SIZE;
index = wtp_recvfrom(g_wtp.fds, g_wtp.fdstotalcount, buffer, &buffersize, &recvfromaddr, &recvtoaddr, &timeout);
index = wtp_recvfrom(&g_wtp.fds, buffer, &buffersize, &recvfromaddr, &recvtoaddr, &timeout);
if (!g_wtp.running) {
capwap_logging_debug("Closing WTP, Teardown connection");
@ -261,7 +272,7 @@ int wtp_dfa_running(void) {
int check;
/* Retrieve network information */
capwap_get_network_socket(&g_wtp.net, &socket, g_wtp.fds[index].fd);
capwap_get_network_socket(&g_wtp.net, &socket, g_wtp.fds.fdspoll[index].fd);
/* Check source */
if (socket.isctrlsocket && (g_wtp.acctrladdress.ss_family != AF_UNSPEC)) {
@ -339,7 +350,7 @@ int wtp_dfa_running(void) {
socklen_t sockinfolen = sizeof(struct sockaddr_storage);
memset(&sockinfo, 0, sizeof(struct sockaddr_storage));
if (getsockname(g_wtp.fds[index].fd, (struct sockaddr*)&sockinfo, &sockinfolen) < 0) {
if (getsockname(g_wtp.fds.fdspoll[index].fd, (struct sockaddr*)&sockinfo, &sockinfolen) < 0) {
break;
}
@ -447,7 +458,7 @@ int wtp_dfa_running(void) {
}
/* Free memory */
capwap_free(g_wtp.fds);
wtp_free_fds(&g_wtp.fds);
return result;
}

View File

@ -4,6 +4,7 @@
#include "capwap_array.h"
#include "capwap_list.h"
#include "wtp_dfa.h"
#include "wtp_radio.h"
/* */
void wtp_send_configure(struct timeout_control* timeout) {

View File

@ -4,6 +4,7 @@
#include "capwap_array.h"
#include "capwap_list.h"
#include "wtp_dfa.h"
#include "wtp_radio.h"
/* */
void wtp_send_join(struct timeout_control* timeout) {

View File

@ -2,6 +2,7 @@
#include "capwap_dfa.h"
#include "capwap_element.h"
#include "wtp_dfa.h"
#include "wtp_radio.h"
/* */
static int send_echo_request() {

View File

@ -1,4 +1,5 @@
#include "wtp.h"
#include "wtp_radio.h"
/* */
void wtp_create_radioopsstate_element(struct capwap_packet_txmng* txmngpacket) {

View File

@ -1,5 +1,6 @@
#include "wtp.h"
#include "capwap_hash.h"
#include "capwap_list.h"
#include "wtp_radio.h"
/* */
@ -27,7 +28,7 @@ static int wtp_radio_configure_phy(struct wtp_radio* radio) {
memcpy(radio->rateset.rateset, radio->supportedrates.supportedrates, CAPWAP_RATESET_MAXLENGTH);
/* Update rates */
if (wifi_device_updaterates(radio->radioid)) {
if (wifi_device_updaterates(radio->devicehandle, radio->rateset.rateset, radio->rateset.ratesetcount)) {
return -1;
}
}
@ -48,23 +49,6 @@ static int wtp_radio_configure_phy(struct wtp_radio* radio) {
return 0;
}
/* */
static void wtp_radio_destroy_wlan(struct wtp_radio_wlan* wlan) {
if (wlan->wlanid && wlan->radio) {
if (wlan->state != WTP_RADIO_WLAN_STATE_IDLE) {
if (wlan->state == WTP_RADIO_WLAN_STATE_AP) {
wifi_wlan_stopap(wlan->radio->radioid, wlan->wlanid);
}
/* Destroy interface */
wifi_wlan_destroy(wlan->radio->radioid, wlan->wlanid);
}
}
/* Release item */
memset(wlan, 0, sizeof(struct wtp_radio_wlan));
}
/* */
unsigned long wtp_radio_acl_item_gethash(const void* key, unsigned long keysize, unsigned long hashsize) {
uint8_t* macaddress = (uint8_t*)key;
@ -84,7 +68,8 @@ void wtp_radio_init(void) {
/* */
void wtp_radio_close(void) {
int i, j;
int i;
struct capwap_list_item* itemwlan;
ASSERT(g_wtp.radios != NULL);
@ -96,11 +81,29 @@ void wtp_radio_close(void) {
}
if (radio->wlan) {
for (j = 0; j < radio->wlan->count; j++) {
wtp_radio_destroy_wlan((struct wtp_radio_wlan*)capwap_array_get_item_pointer(radio->wlan, j));
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);
}
}
capwap_array_free(radio->wlan);
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);
}
}
@ -110,10 +113,9 @@ void wtp_radio_close(void) {
/* */
void wtp_radio_free(void) {
ASSERT(g_wtp.radios != NULL);
ASSERT(g_wtp.radios->count == 0);
if (g_wtp.events) {
capwap_free(g_wtp.events);
if (g_wtp.radios->count > 0) {
wtp_radio_close();
}
capwap_array_free(g_wtp.radios);
@ -125,7 +127,6 @@ int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet) {
int i;
int result = 0;
unsigned short binding;
struct wtp_radio* radio;
struct capwap_array* messageelements;
struct capwap_array* updateitems;
struct wtp_update_configuration_item* item;
@ -138,6 +139,7 @@ int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet) {
/* */
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
struct wtp_radio* radio;
struct capwap_list_item* search;
/* Set radio configuration and invalidate the old values */
@ -422,12 +424,12 @@ int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet) {
switch (item->type) {
case WTP_UPDATE_FREQUENCY_DSSS: {
result = wifi_device_setfrequency(item->radio->radioid, WIFI_BAND_2GHZ, item->radio->radioinformation.radiotype, item->radio->directsequencecontrol.currentchannel);
result = wifi_device_setfrequency(item->radio->devicehandle, WIFI_BAND_2GHZ, item->radio->radioinformation.radiotype, item->radio->directsequencecontrol.currentchannel);
break;
}
case WTP_UPDATE_FREQUENCY_OFDM: {
result = wifi_device_setfrequency(item->radio->radioid, WIFI_BAND_5GHZ, item->radio->radioinformation.radiotype, item->radio->ofdmcontrol.currentchannel);
result = wifi_device_setfrequency(item->radio->devicehandle, WIFI_BAND_5GHZ, item->radio->radioinformation.radiotype, item->radio->ofdmcontrol.currentchannel);
break;
}
}
@ -439,7 +441,7 @@ int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet) {
switch (item->type) {
case WTP_UPDATE_RATES: {
result = wifi_device_updaterates(radio->radioid);
result = wifi_device_updaterates(item->radio->devicehandle, item->radio->rateset.rateset, item->radio->rateset.ratesetcount);
break;
}
@ -453,7 +455,7 @@ int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet) {
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);
result = wifi_device_setconfiguration(item->radio->radioid, &params);
result = wifi_device_setconfiguration(item->radio->devicehandle, &params);
break;
}
}
@ -474,7 +476,8 @@ struct wtp_radio* wtp_radio_create_phy(void) {
radio->status = WTP_RADIO_DISABLED;
/* Init configuration radio */
radio->wlan = capwap_array_create(sizeof(struct wtp_radio_wlan), 0, 1);
radio->wlan = capwap_list_create();
radio->wlanpool = capwap_list_create();
radio->antenna.selections = capwap_array_create(sizeof(uint8_t), 0, 1);
return radio;
}
@ -483,8 +486,12 @@ struct wtp_radio* wtp_radio_create_phy(void) {
struct wtp_radio* wtp_radio_get_phy(uint8_t radioid) {
int i;
ASSERT(IS_VALID_RADIOID(radioid));
/* Check */
if (!IS_VALID_RADIOID(radioid)) {
return NULL;
}
/* Retrieve radio */
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) {
@ -497,13 +504,19 @@ struct wtp_radio* wtp_radio_get_phy(uint8_t radioid) {
/* */
struct wtp_radio_wlan* wtp_radio_get_wlan(struct wtp_radio* radio, uint8_t wlanid) {
int i;
struct capwap_list_item* itemwlan;
ASSERT(IS_VALID_WLANID(wlanid));
ASSERT(radio != NULL);
for (i = 0; i < radio->wlan->count; i++) {
struct wtp_radio_wlan* wlan = (struct wtp_radio_wlan*)capwap_array_get_item_pointer(radio->wlan, i);
if ((wlanid == wlan->wlanid) && (radio == wlan->radio)) {
/* 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) {
return wlan;
}
}
@ -512,8 +525,11 @@ struct wtp_radio_wlan* wtp_radio_get_wlan(struct wtp_radio* radio, uint8_t wlani
}
/* */
void wtp_radio_update_fdevent(void) {
void wtp_radio_update_fdevent(struct wtp_fds* fds) {
int count;
struct pollfd* fdsbuffer;
ASSERT(fds != NULL);
/* Retrieve number of File Descriptor Event */
count = wifi_event_getfd(NULL, NULL, 0);
@ -521,41 +537,43 @@ void wtp_radio_update_fdevent(void) {
return;
}
/* */
if (g_wtp.eventscount != count) {
struct pollfd* fds;
/* Resize poll */
fds = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * (g_wtp.fdsnetworkcount + count));
memcpy(fds, g_wtp.fds, sizeof(struct pollfd) * g_wtp.fdsnetworkcount);
capwap_free(g_wtp.fds);
g_wtp.fds = fds;
/* Events Callback */
if (g_wtp.events) {
capwap_free(g_wtp.events);
/* 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);
}
g_wtp.events = (struct wifi_event*)((count > 0) ? capwap_alloc(sizeof(struct wifi_event) * count) : NULL);
fds->fdspoll = fdsbuffer;
/* Events Callback */
if (fds->events) {
capwap_free(fds->events);
}
fds->events = (struct wifi_event*)((count > 0) ? capwap_alloc(sizeof(struct wifi_event) * count) : NULL);
/* */
g_wtp.eventscount = count;
g_wtp.fdstotalcount = g_wtp.fdsnetworkcount + g_wtp.eventscount;
fds->eventscount = count;
fds->fdstotalcount = fds->fdsnetworkcount + count;
}
/* Retrieve File Descriptor Event */
if (count > 0) {
count = wifi_event_getfd(&g_wtp.fds[g_wtp.fdsnetworkcount], g_wtp.events, g_wtp.eventscount);
ASSERT(g_wtp.eventscount == count);
ASSERT(fds->fdspoll != NULL);
wifi_event_getfd(&fds->fdspoll[fds->fdsnetworkcount], fds->events, fds->eventscount);
}
}
/* */
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid) {
char wlanname[IFNAMSIZ];
struct wtp_radio* radio;
struct wtp_radio_wlan* wlan;
struct wifi_wlan_startap_params params;
struct wtp_radio_wlanpool* wlanpool;
struct capwap_list_item* itemwlan;
struct capwap_list_item* itemwlanpool;
struct wlan_startap_params params;
struct capwap_80211_addwlan_element* addwlan;
/* Get message elements */
@ -576,6 +594,11 @@ uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwa
return CAPWAP_RESULTCODE_FAILURE;
}
/* Verify exist interface into pool */
if (!radio->wlanpool->first) {
return CAPWAP_RESULTCODE_FAILURE;
}
/* Prepare physical interface for create wlan */
if (!radio->wlan->count) {
if (wtp_radio_configure_phy(radio)) {
@ -583,51 +606,45 @@ uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwa
}
}
/* Set virtual interface information */
wlan = (struct wtp_radio_wlan*)capwap_array_get_item_pointer(radio->wlan, radio->wlan->count);
wlan->radio = radio;
wlan->wlanid = addwlan->wlanid;
sprintf(wlanname, "%s%02d.%02d", g_wtp.wlanprefix, (int)addwlan->radioid, (int)addwlan->wlanid);
if (wifi_iface_index(wlanname)) {
memset(wlan, 0, sizeof(struct wtp_radio_wlan));
return CAPWAP_RESULTCODE_FAILURE;
}
/* Create virtual interface */
if (!wifi_wlan_create(addwlan->radioid, addwlan->wlanid, wlanname, NULL)) {
wlan->state = WTP_RADIO_WLAN_STATE_CREATED;
} else {
wtp_radio_destroy_wlan(wlan);
return CAPWAP_RESULTCODE_FAILURE;
}
/* Get interface from pool */
itemwlanpool = capwap_itemlist_remove_head(radio->wlanpool);
wlanpool = (struct wtp_radio_wlanpool*)itemwlanpool->item;
/* Wlan configuration */
memset(&params, 0, sizeof(struct wifi_wlan_startap_params));
memset(&params, 0, sizeof(struct wlan_startap_params));
params.ssid = (const char*)addwlan->ssid;
params.ssid_hidden = addwlan->suppressssid;
params.capability = addwlan->capability;
params.qos = addwlan->qos;
params.authmode = addwlan->authmode;
params.macmode = addwlan->macmode;
params.tunnelmode = addwlan->tunnelmode;
params.ssid_hidden = addwlan->suppressssid;
strcpy(params.ssid, (const char*)addwlan->ssid);
/* TODO (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_80211_IE) */
/* Start AP */
if (!wifi_wlan_startap(addwlan->radioid, addwlan->wlanid, &params)) {
wlan->state = WTP_RADIO_WLAN_STATE_AP;
} else {
wtp_radio_destroy_wlan(wlan);
if (wifi_wlan_startap(wlanpool->wlanhandle, &params)) {
capwap_itemlist_insert_before(radio->wlanpool, NULL, itemwlanpool);
return CAPWAP_RESULTCODE_FAILURE;
}
/* Move interface from pool to 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;
/* */
capwap_itemlist_free(itemwlanpool);
capwap_itemlist_insert_after(radio->wlan, NULL, itemwlan);
/* Update Event File Descriptor */
wtp_radio_update_fdevent();
wtp_radio_update_fdevent(&g_wtp.fds);
/* Retrieve macaddress of new device */
bssid->radioid = addwlan->radioid;
bssid->wlanid = addwlan->wlanid;
wifi_wlan_getbssid(addwlan->radioid, addwlan->wlanid, bssid->bssid);
wifi_wlan_getbssid(wlan->wlanhandle, bssid->bssid);
return CAPWAP_RESULTCODE_SUCCESS;
}

View File

@ -20,22 +20,27 @@
#define WTP_PREFIX_NAME_MAX_LENGTH (IFNAMSIZ - 6)
#define WTP_PREFIX_DEFAULT_NAME "ap"
#define WTP_RADIO_WLAN_STATE_IDLE 0
#define WTP_RADIO_WLAN_STATE_CREATED 1
#define WTP_RADIO_WLAN_STATE_AP 2
struct wtp_radio_wlan {
struct wtp_radio* radio;
int state;
uint8_t wlanid;
struct wifi_wlan* wlanhandle;
struct wtp_radio* radio;
};
/* */
struct wtp_radio_wlanpool {
struct wifi_wlan* wlanhandle;
struct wtp_radio* radio;
};
/* */
struct wtp_radio {
uint8_t radioid;
char device[IFNAMSIZ];
struct wifi_device* devicehandle;
struct capwap_array* wlan;
char wlanprefix[IFNAMSIZ];
struct capwap_list* wlan;
struct capwap_list* wlanpool;
int status;
struct capwap_80211_antenna_element antenna;
@ -64,7 +69,7 @@ struct wtp_radio_wlan* wtp_radio_get_wlan(struct wtp_radio* radio, uint8_t wlani
/* */
int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet);
void wtp_radio_update_fdevent(void);
void wtp_radio_update_fdevent(struct wtp_fds* fds);
/* */
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid);