The first beacon of SmartCAPWAP
This commit is contained in:
parent
29ba25e434
commit
bef31786ce
@ -34,9 +34,7 @@ INCLUDES = \
|
|||||||
-I$(top_srcdir)/build \
|
-I$(top_srcdir)/build \
|
||||||
-I$(top_srcdir)/src/common \
|
-I$(top_srcdir)/src/common \
|
||||||
-I$(top_srcdir)/src/wtp \
|
-I$(top_srcdir)/src/wtp \
|
||||||
-I$(top_srcdir)/src/binding/wifi/drivers \
|
-I$(top_srcdir)/src/binding/ieee80211
|
||||||
-I$(top_srcdir)/src/binding/wifi/ap/ \
|
|
||||||
-I$(top_srcdir)/src/binding/wifi/ap/common
|
|
||||||
|
|
||||||
include $(top_srcdir)/build/Makefile_common.am
|
include $(top_srcdir)/build/Makefile_common.am
|
||||||
|
|
||||||
@ -56,7 +54,7 @@ wtp_SOURCES = \
|
|||||||
$(top_srcdir)/src/wtp/wtp_dfa_reset.c \
|
$(top_srcdir)/src/wtp/wtp_dfa_reset.c \
|
||||||
$(top_srcdir)/src/wtp/wtp_dfa_imagedata.c \
|
$(top_srcdir)/src/wtp/wtp_dfa_imagedata.c \
|
||||||
$(top_srcdir)/src/wtp/wtp_radio.c \
|
$(top_srcdir)/src/wtp/wtp_radio.c \
|
||||||
$(top_srcdir)/src/binding/wifi/drivers/wifi_drivers.c
|
$(top_srcdir)/src/binding/ieee80211/wifi_drivers.c
|
||||||
|
|
||||||
wtp_LDADD = \
|
wtp_LDADD = \
|
||||||
$(CONFIG_LIBS)
|
$(CONFIG_LIBS)
|
||||||
@ -66,7 +64,7 @@ wtp_LDADD += $(SSL_LIBS)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if BUILD_WTP_WIFI_DRIVERS_NL80211
|
if BUILD_WTP_WIFI_DRIVERS_NL80211
|
||||||
wtp_SOURCES += $(top_srcdir)/src/binding/wifi/drivers/wifi_nl80211.c
|
wtp_SOURCES += $(top_srcdir)/src/binding/ieee80211/wifi_nl80211.c
|
||||||
wtp_LDADD += $(LIBNL_LIBS)
|
wtp_LDADD += $(LIBNL_LIBS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -71,7 +71,11 @@ application: {
|
|||||||
certificate = "/etc/capwap/wtp.crt";
|
certificate = "/etc/capwap/wtp.crt";
|
||||||
privatekey = "/etc/capwap/wtp.key";
|
privatekey = "/etc/capwap/wtp.key";
|
||||||
privatekeypassword = "";
|
privatekeypassword = "";
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
wlan: {
|
||||||
|
prefix = "ap";
|
||||||
};
|
};
|
||||||
|
|
||||||
radio = (
|
radio = (
|
||||||
@ -97,14 +101,6 @@ application: {
|
|||||||
combiner = "omni";
|
combiner = "omni";
|
||||||
selection = [ "internal" ];
|
selection = [ "internal" ];
|
||||||
};
|
};
|
||||||
dsss = {
|
|
||||||
clearchannelassessment = 0;
|
|
||||||
energydetectthreshold = 0;
|
|
||||||
};
|
|
||||||
ofdm = {
|
|
||||||
bandsupported = 0;
|
|
||||||
tithreshold = 100;
|
|
||||||
};
|
|
||||||
multidomaincapability = {
|
multidomaincapability = {
|
||||||
firstchannel = 1;
|
firstchannel = 1;
|
||||||
numberchannels = 11;
|
numberchannels = 11;
|
||||||
|
212
src/binding/ieee80211/ieee80211.h
Normal file
212
src/binding/ieee80211/ieee80211.h
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
#ifndef __CAPWAP_IEEE802_11_HEADER__
|
||||||
|
#define __CAPWAP_IEEE802_11_HEADER__
|
||||||
|
|
||||||
|
#include <linux/types.h>
|
||||||
|
#include <asm/byteorder.h>
|
||||||
|
#include <linux/if_ether.h>
|
||||||
|
|
||||||
|
#ifndef STRUCT_PACKED
|
||||||
|
#define STRUCT_PACKED __attribute__((__packed__))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Global values */
|
||||||
|
#define IEEE80211_MTU 2304
|
||||||
|
|
||||||
|
#define IS_IEEE80211_FREQ_BG(x) (((x >= 2412) && (x <= 2484)) ? 1 : 0)
|
||||||
|
#define IS_IEEE80211_FREQ_A(x) (((x >= 5035) && (x <= 5825)) ? 1 : 0)
|
||||||
|
|
||||||
|
/* Rate into multiple of 500Kbps */
|
||||||
|
#define IEEE80211_RATE_1M 2
|
||||||
|
#define IEEE80211_RATE_2M 4
|
||||||
|
#define IEEE80211_RATE_5_5M 11
|
||||||
|
#define IEEE80211_RATE_11M 22
|
||||||
|
#define IEEE80211_RATE_6M 12
|
||||||
|
#define IEEE80211_RATE_9M 18
|
||||||
|
#define IEEE80211_RATE_12M 24
|
||||||
|
#define IEEE80211_RATE_18M 36
|
||||||
|
#define IEEE80211_RATE_24M 48
|
||||||
|
#define IEEE80211_RATE_36M 72
|
||||||
|
#define IEEE80211_RATE_48M 96
|
||||||
|
#define IEEE80211_RATE_54M 108
|
||||||
|
#define IEEE80211_RATE_80211N 127
|
||||||
|
|
||||||
|
#define IS_IEEE80211_RATE_B(x) (((x == IEEE80211_RATE_1M) || (x == IEEE80211_RATE_2M) || (x == IEEE80211_RATE_5_5M) || (x == IEEE80211_RATE_11M)) ? 1 : 0)
|
||||||
|
#define IS_IEEE80211_RATE_G(x) (((x == IEEE80211_RATE_6M) || (x == IEEE80211_RATE_9M) || (x == IEEE80211_RATE_12M) || (x == IEEE80211_RATE_18M) || (x == IEEE80211_RATE_24M) || (x == IEEE80211_RATE_36M) || (x == IEEE80211_RATE_48M) || (x == IEEE80211_RATE_54M)) ? 1 : 0)
|
||||||
|
#define IS_IEEE80211_RATE_A(x) (((x == IEEE80211_RATE_6M) || (x == IEEE80211_RATE_9M) || (x == IEEE80211_RATE_12M) || (x == IEEE80211_RATE_18M) || (x == IEEE80211_RATE_24M) || (x == IEEE80211_RATE_36M) || (x == IEEE80211_RATE_48M) || (x == IEEE80211_RATE_54M)) ? 1 : 0)
|
||||||
|
#define IS_IEEE80211_RATE_N(x) ((x == IEEE80211_RATE_80211N) ? 1 : 0)
|
||||||
|
|
||||||
|
/* Frame control type */
|
||||||
|
#define IEEE80211_FRAMECONTROL_TYPE_MGMT 0
|
||||||
|
#define IEEE80211_FRAMECONTROL_TYPE_CTRL 1
|
||||||
|
#define IEEE80211_FRAMECONTROL_TYPE_DATA 2
|
||||||
|
|
||||||
|
/* Frame control Management subtype */
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ASSOC_REQ 0
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ASSOC_RESP 1
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_REASSOC_REQ 2
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_REASSOC_RESP 3
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_PROBE_REQ 4
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_PROBE_RESP 5
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_TIMING_ADV 6
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_BEACON 8
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ATIM 9
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_DISASSOC 10
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_AUTH 11
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_DEAUTH 12
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ACTION 13
|
||||||
|
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ACTION_NOACK 14
|
||||||
|
|
||||||
|
/* Frame control Control subtype */
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_CTRLWRAPPER 7
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_BLOCKACK_REQ 8
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_BLOCKACK 9
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_PSPOLL 10
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_RTS 11
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_CTS 12
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_ACK 13
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_CFEND 14
|
||||||
|
#define IEEE80211_FRAMECONTROL_CTRL_SUBTYPE_CFEND_CFACK 15
|
||||||
|
|
||||||
|
/* Frame control Data subtype */
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_DATA 0
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_DATA_CFACK 1
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_DATA_CFPOLL 2
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_DATA_CFACK_CFPOLL 3
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_NULL 4
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_CFACK 5
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_CFPOLL 6
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_CFACK_CFPOLL 7
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_QOSDATA 8
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_QOSDATA_CFACK 9
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_QOSDATA_CFPOLL 10
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_QOSDATA_CFACK_CFPOLL 11
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_QOSNULL 12
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_QOSCFPOLL 14
|
||||||
|
#define IEEE80211_FRAMECONTROL_DATA_SUBTYPE_QOSCFACK_CFPOLL 15
|
||||||
|
|
||||||
|
/* */
|
||||||
|
#define IEEE80211_FRAME_CONTROL(type, stype) __cpu_to_le16((type << 2) | (stype << 4))
|
||||||
|
|
||||||
|
/* 802.11 Packet - IEEE802.11 is a little-endian protocol */
|
||||||
|
struct ieee80211_header {
|
||||||
|
__le16 framecontrol;
|
||||||
|
__le16 durationid;
|
||||||
|
uint8_t address1[ETH_ALEN];
|
||||||
|
uint8_t address2[ETH_ALEN];
|
||||||
|
uint8_t address3[ETH_ALEN];
|
||||||
|
__le16 sequencecontrol;
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct ieee80211_header_mgmt {
|
||||||
|
__le16 framecontrol;
|
||||||
|
__le16 durationid;
|
||||||
|
uint8_t da[ETH_ALEN];
|
||||||
|
uint8_t sa[ETH_ALEN];
|
||||||
|
uint8_t bssid[ETH_ALEN];
|
||||||
|
__le16 sequencecontrol;
|
||||||
|
|
||||||
|
uint8_t timestamp[8];
|
||||||
|
__le16 beaconinterval;
|
||||||
|
__le16 capability;
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 Generic information element */
|
||||||
|
struct ieee80211_ie {
|
||||||
|
uint8_t id;
|
||||||
|
uint8_t len;
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 SSID information element */
|
||||||
|
#define IEEE80211_IE_SSID 0
|
||||||
|
#define IEEE80211_IE_SSID_MAX_LENGTH 32
|
||||||
|
|
||||||
|
struct ieee80211_ie_ssid {
|
||||||
|
uint8_t id;
|
||||||
|
uint8_t len;
|
||||||
|
uint8_t ssid[0];
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 Supported Rates information element */
|
||||||
|
#define IEEE80211_IE_SUPPORTED_RATES 1
|
||||||
|
#define IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH 8
|
||||||
|
|
||||||
|
struct ieee80211_ie_supported_rates {
|
||||||
|
uint8_t id;
|
||||||
|
uint8_t len;
|
||||||
|
uint8_t rates[0];
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 DSSS information element */
|
||||||
|
#define IEEE80211_IE_DSSS 3
|
||||||
|
|
||||||
|
struct ieee80211_ie_dsss {
|
||||||
|
uint8_t id;
|
||||||
|
uint8_t len;
|
||||||
|
uint8_t channel;
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 Country information element */
|
||||||
|
#define IEEE80211_IE_COUNTRY 7
|
||||||
|
|
||||||
|
struct ieee80211_ie_country_channelgroup {
|
||||||
|
uint8_t firstchannel;
|
||||||
|
uint8_t numberchannels;
|
||||||
|
uint8_t maxtxpower;
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
struct ieee80211_ie_country {
|
||||||
|
uint8_t id;
|
||||||
|
uint8_t len;
|
||||||
|
uint8_t country[3];
|
||||||
|
uint8_t channelgroup[0];
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 ERP information element */
|
||||||
|
#define IEEE80211_IE_ERP 42
|
||||||
|
|
||||||
|
struct ieee80211_ie_erp {
|
||||||
|
uint8_t id;
|
||||||
|
uint8_t len;
|
||||||
|
uint8_t params;
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 Extended Supported Rates information element */
|
||||||
|
#define IEEE80211_IE_EXTENDED_SUPPORTED_RATES 50
|
||||||
|
|
||||||
|
struct ieee80211_ie_extended_supported_rates {
|
||||||
|
uint8_t id;
|
||||||
|
uint8_t len;
|
||||||
|
uint8_t rates[0];
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 EDCA Parameter Set information element */
|
||||||
|
#define IEEE80211_IE_EDCA_PARAMETER_SET 12
|
||||||
|
#define IEEE80211_IE_EDCA_PARAMETER_SET_LENGTH 18
|
||||||
|
|
||||||
|
#define EDCA_PARAMETER_RECORD_AC_BE_FIELD 0
|
||||||
|
#define EDCA_PARAMETER_RECORD_AC_BK_FIELD 1
|
||||||
|
#define EDCA_PARAMETER_RECORD_AC_VI_FIELD 2
|
||||||
|
#define EDCA_PARAMETER_RECORD_AC_VO_FIELD 3
|
||||||
|
|
||||||
|
struct ieee80211_ie_edca_parameter_set {
|
||||||
|
/* TODO */
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
/* 802.11 QoS Capability information element */
|
||||||
|
#define IEEE80211_IE_QOS_CAPABILITY 46
|
||||||
|
#define IEEE80211_IE_QOS_CAPABILITY_LENGTH 1
|
||||||
|
|
||||||
|
struct ieee80211_ie_qos_capability {
|
||||||
|
/* TODO */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 802.11 Power Constraint information element */
|
||||||
|
#define IEEE80211_IE_POWER_CONSTRAINT 52
|
||||||
|
#define IEEE80211_IE_POWER_CONSTRAINT_LENGTH 1
|
||||||
|
|
||||||
|
struct ieee80211_ie_power_constraint {
|
||||||
|
/* TODO */
|
||||||
|
} STRUCT_PACKED;
|
||||||
|
|
||||||
|
#endif /* __CAPWAP_IEEE802_11_HEADER__ */
|
3724
src/binding/ieee80211/nl80211_v3_10.h
Normal file
3724
src/binding/ieee80211/nl80211_v3_10.h
Normal file
File diff suppressed because it is too large
Load Diff
741
src/binding/ieee80211/wifi_drivers.c
Normal file
741
src/binding/ieee80211/wifi_drivers.c
Normal file
@ -0,0 +1,741 @@
|
|||||||
|
#include "capwap.h"
|
||||||
|
#include "capwap_array.h"
|
||||||
|
#include "capwap_element.h"
|
||||||
|
#include "wtp_radio.h"
|
||||||
|
#include "wifi_drivers.h"
|
||||||
|
#include "ieee80211.h"
|
||||||
|
|
||||||
|
/* Declare enable wifi driver */
|
||||||
|
#ifdef ENABLE_WIFI_DRIVERS_NL80211
|
||||||
|
extern struct wifi_driver_ops wifi_driver_nl80211_ops;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static struct wifi_driver_instance wifi_driver[] = {
|
||||||
|
#ifdef ENABLE_WIFI_DRIVERS_NL80211
|
||||||
|
{ &wifi_driver_nl80211_ops },
|
||||||
|
#endif
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Radio instance */
|
||||||
|
static struct capwap_array* g_wifidevice = NULL;
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static void wifi_device_freecapability(struct wifi_capability* capability) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ASSERT(capability != NULL);
|
||||||
|
|
||||||
|
/* Free memory */
|
||||||
|
if (capability->bands) {
|
||||||
|
for (i = 0; i < capability->bands->count; i++) {
|
||||||
|
struct wifi_band_capability* bandcap = (struct wifi_band_capability*)capwap_array_get_item_pointer(capability->bands, i);
|
||||||
|
|
||||||
|
if (bandcap->freq) {
|
||||||
|
capwap_array_free(bandcap->freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bandcap->rate) {
|
||||||
|
capwap_array_free(bandcap->rate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
capwap_array_free(capability->bands);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (capability->ciphers) {
|
||||||
|
capwap_array_free(capability->ciphers);
|
||||||
|
}
|
||||||
|
|
||||||
|
capwap_free(capability);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_driver_init(void) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; wifi_driver[i].ops != NULL; i++) {
|
||||||
|
/* Initialize driver */
|
||||||
|
ASSERT(wifi_driver[i].ops->global_init != NULL);
|
||||||
|
wifi_driver[i].handle = wifi_driver[i].ops->global_init();
|
||||||
|
if (!wifi_driver[i].handle) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Device handler */
|
||||||
|
g_wifidevice = capwap_array_create(sizeof(struct wifi_device), 0, 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void wifi_driver_free(void) {
|
||||||
|
unsigned long i;
|
||||||
|
unsigned long j;
|
||||||
|
|
||||||
|
/* Free device */
|
||||||
|
if (g_wifidevice) {
|
||||||
|
for (i = 0; i < g_wifidevice->count; i++) {
|
||||||
|
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, i);
|
||||||
|
|
||||||
|
if (device->wlan) {
|
||||||
|
if (device->instance->ops->wlan_delete != NULL) {
|
||||||
|
for (j = 0; j < device->wlan->count; j++) {
|
||||||
|
struct wifi_wlan* wlan = (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, j);
|
||||||
|
|
||||||
|
if (wlan->handle) {
|
||||||
|
device->instance->ops->wlan_delete(wlan->handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
capwap_array_free(device->wlan);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device->capability) {
|
||||||
|
wifi_device_freecapability(device->capability);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device->handle && device->instance->ops->device_deinit) {
|
||||||
|
device->instance->ops->device_deinit(device->handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
capwap_array_free(g_wifidevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free driver */
|
||||||
|
for (i = 0; wifi_driver[i].ops != NULL; i++) {
|
||||||
|
if (wifi_driver[i].ops->global_deinit) {
|
||||||
|
wifi_driver[i].ops->global_deinit(wifi_driver[i].handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_device_connect(int radioid, const char* ifname, const char* driver) {
|
||||||
|
int i;
|
||||||
|
int length;
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
ASSERT(radioid > 0);
|
||||||
|
ASSERT(ifname != NULL);
|
||||||
|
ASSERT(driver != NULL);
|
||||||
|
|
||||||
|
/* Check */
|
||||||
|
length = strlen(ifname);
|
||||||
|
if ((length <= 0) || (length >= IFNAMSIZ)) {
|
||||||
|
capwap_logging_warning("Wifi device name error: %s", ifname);
|
||||||
|
return -1;
|
||||||
|
} else if (g_wifidevice->count >= radioid) {
|
||||||
|
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||||
|
|
||||||
|
if (device->handle) {
|
||||||
|
capwap_logging_warning("Wifi device RadioID already used: %d", radioid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search driver */
|
||||||
|
for (i = 0; wifi_driver[i].ops != NULL; i++) {
|
||||||
|
if (!strcmp(driver, wifi_driver[i].ops->name)) {
|
||||||
|
wifi_device_handle devicehandle;
|
||||||
|
struct device_init_params params = {
|
||||||
|
.ifname = ifname
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Device init */
|
||||||
|
ASSERT(wifi_driver[i].ops->device_init);
|
||||||
|
devicehandle = wifi_driver[i].ops->device_init(wifi_driver[i].handle, ¶ms);
|
||||||
|
if (devicehandle) {
|
||||||
|
/* Register new device */
|
||||||
|
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||||
|
device->handle = devicehandle;
|
||||||
|
device->instance = &wifi_driver[i];
|
||||||
|
device->wlan = capwap_array_create(sizeof(struct wifi_wlan), 0, 1);
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static struct wifi_wlan* wifi_wlan_getdevice(int radioid, int wlanid) {
|
||||||
|
struct wifi_device* device;
|
||||||
|
|
||||||
|
ASSERT(radioid > 0);
|
||||||
|
ASSERT(wlanid > 0);
|
||||||
|
|
||||||
|
if (g_wifidevice->count < radioid) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get radio connection */
|
||||||
|
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||||
|
if (device->wlan->count < wlanid) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
if (device->wlan->count < wlanid) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return wlan connection */
|
||||||
|
return (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, wlanid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_wlan_create(int radioid, int wlanid, const char* ifname, uint8_t* bssid) {
|
||||||
|
int length;
|
||||||
|
struct wifi_device* device;
|
||||||
|
struct wifi_wlan* wlan;
|
||||||
|
wifi_wlan_handle wlanhandle;
|
||||||
|
struct wlan_init_params params = {
|
||||||
|
.ifname = ifname,
|
||||||
|
.type = WLAN_INTERFACE_AP
|
||||||
|
};
|
||||||
|
|
||||||
|
ASSERT(radioid > 0);
|
||||||
|
ASSERT(wlanid > 0);
|
||||||
|
ASSERT(ifname != NULL);
|
||||||
|
//ASSERT(bssid != NULL);
|
||||||
|
|
||||||
|
/* Check */
|
||||||
|
length = strlen(ifname);
|
||||||
|
if ((length <= 0) || (length >= IFNAMSIZ)) {
|
||||||
|
capwap_logging_warning("Wifi device name error: %s", ifname);
|
||||||
|
return -1;
|
||||||
|
} else if (g_wifidevice->count < radioid) {
|
||||||
|
capwap_logging_warning("Wifi device RadioID %d is not connected", radioid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get radio connection */
|
||||||
|
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||||
|
if (!device->handle) {
|
||||||
|
capwap_logging_warning("Wifi device RadioID %d is not connected", radioid);
|
||||||
|
return -1;
|
||||||
|
} else if (device->wlan->count >= wlanid) {
|
||||||
|
wlan = (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, wlanid);
|
||||||
|
if (wlan->handle) {
|
||||||
|
capwap_logging_warning("WLAN interface already used: %d", wlanid);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (!device->instance->ops->wlan_create) {
|
||||||
|
capwap_logging_warning("%s library don't support wlan_create", device->instance->ops->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create interface */
|
||||||
|
wlanhandle = device->instance->ops->wlan_create(device->handle, ¶ms);
|
||||||
|
if (!wlanhandle) {
|
||||||
|
capwap_logging_warning("Unable to create virtual interface: %s", ifname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
wlan = (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, wlanid);
|
||||||
|
wlan->handle = wlanhandle;
|
||||||
|
wlan->device = device;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static void wifi_wlan_getrates(struct wifi_device* device, struct wtp_radio* radio) {
|
||||||
|
int i, j, w;
|
||||||
|
uint32_t mode = 0;
|
||||||
|
|
||||||
|
ASSERT(device != NULL);
|
||||||
|
ASSERT(radio != NULL);
|
||||||
|
|
||||||
|
/* Free old supported rates */
|
||||||
|
device->supportedratescount = 0;
|
||||||
|
|
||||||
|
/* Retrieve cached capability */
|
||||||
|
if (!device->capability) {
|
||||||
|
if (!wifi_device_getcapability(radio->radioid)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check type of rate mode */
|
||||||
|
for (i = 0; i < radio->rateset.ratesetcount; i++) {
|
||||||
|
if (device->currentfreq.band == WIFI_BAND_2GHZ) {
|
||||||
|
if (IS_IEEE80211_RATE_B(radio->rateset.rateset[i])) {
|
||||||
|
mode |= CAPWAP_RADIO_TYPE_80211B;
|
||||||
|
} else if (IS_IEEE80211_RATE_G(radio->rateset.rateset[i])) {
|
||||||
|
mode |= CAPWAP_RADIO_TYPE_80211G;
|
||||||
|
} else if (IS_IEEE80211_RATE_N(radio->rateset.rateset[i])) {
|
||||||
|
mode |= CAPWAP_RADIO_TYPE_80211N;
|
||||||
|
}
|
||||||
|
} else if (device->currentfreq.band == WIFI_BAND_5GHZ) {
|
||||||
|
if (IS_IEEE80211_RATE_A(radio->rateset.rateset[i])) {
|
||||||
|
mode |= CAPWAP_RADIO_TYPE_80211A;
|
||||||
|
} else if (IS_IEEE80211_RATE_N(radio->rateset.rateset[i])) {
|
||||||
|
mode |= CAPWAP_RADIO_TYPE_80211N;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add implicit 802.11b rate with only 802.11g rate */
|
||||||
|
if ((device->currentfreq.band == WIFI_BAND_2GHZ) && !(mode & CAPWAP_RADIO_TYPE_80211B) && (device->currentfreq.mode & CAPWAP_RADIO_TYPE_80211B)) {
|
||||||
|
device->supportedrates[device->supportedratescount++] = IEEE80211_RATE_1M;
|
||||||
|
device->supportedrates[device->supportedratescount++] = IEEE80211_RATE_2M;
|
||||||
|
device->supportedrates[device->supportedratescount++] = IEEE80211_RATE_5_5M;
|
||||||
|
device->supportedrates[device->supportedratescount++] = IEEE80211_RATE_11M;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Filter band */
|
||||||
|
for (i = 0; i < device->capability->bands->count; i++) {
|
||||||
|
struct wifi_band_capability* bandcap = (struct wifi_band_capability*)capwap_array_get_item_pointer(device->capability->bands, i);
|
||||||
|
|
||||||
|
if (bandcap->band == device->currentfreq.band) {
|
||||||
|
if (bandcap->rate->count) {
|
||||||
|
for (j = 0; j < bandcap->rate->count; j++) {
|
||||||
|
struct wifi_rate_capability* rate = (struct wifi_rate_capability*)capwap_array_get_item_pointer(bandcap->rate, j);
|
||||||
|
|
||||||
|
/* Validate rate */
|
||||||
|
for (w = 0; w < radio->rateset.ratesetcount; w++) {
|
||||||
|
if (radio->rateset.rateset[w] == rate->bitrate) {
|
||||||
|
device->supportedrates[device->supportedratescount++] = rate->bitrate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add implicit 802.11n rate with only 802.11a/g rate */
|
||||||
|
if (!(mode & CAPWAP_RADIO_TYPE_80211N) && (device->currentfreq.mode & CAPWAP_RADIO_TYPE_80211N)) {
|
||||||
|
device->supportedrates[device->supportedratescount++] = IEEE80211_RATE_80211N;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static int wifi_ie_ssid(char* buffer, const char* ssid, int hidessid) {
|
||||||
|
struct ieee80211_ie_ssid* iessid = (struct ieee80211_ie_ssid*)buffer;
|
||||||
|
|
||||||
|
ASSERT(buffer != NULL);
|
||||||
|
ASSERT(ssid != NULL);
|
||||||
|
|
||||||
|
iessid->id = IEEE80211_IE_SSID;
|
||||||
|
if (!hidessid) {
|
||||||
|
iessid->len = strlen(ssid);
|
||||||
|
if (iessid->len > IEEE80211_IE_SSID_MAX_LENGTH) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy((char*)iessid->ssid, ssid, iessid->len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sizeof(struct ieee80211_ie_ssid) + iessid->len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static int wifi_ie_supportedrates(char* buffer, struct wifi_device* device) {
|
||||||
|
int i;
|
||||||
|
int count;
|
||||||
|
struct ieee80211_ie_supported_rates* iesupportedrates = (struct ieee80211_ie_supported_rates*)buffer;
|
||||||
|
|
||||||
|
ASSERT(buffer != NULL);
|
||||||
|
|
||||||
|
/* IE accept max only 8 rate */
|
||||||
|
count = device->supportedratescount;
|
||||||
|
if (count > 8) {
|
||||||
|
count = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
iesupportedrates->id = IEEE80211_IE_SUPPORTED_RATES;
|
||||||
|
iesupportedrates->len = count;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
iesupportedrates->rates[i] = device->supportedrates[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return sizeof(struct ieee80211_ie_supported_rates) + iesupportedrates->len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static int wifi_ie_extendedsupportedrates(char* buffer, struct wifi_device* device) {
|
||||||
|
int i, j;
|
||||||
|
struct ieee80211_ie_extended_supported_rates* ieextendedsupportedrates = (struct ieee80211_ie_extended_supported_rates*)buffer;
|
||||||
|
|
||||||
|
ASSERT(buffer != NULL);
|
||||||
|
|
||||||
|
/* IE accept only > 8 rate */
|
||||||
|
if (device->supportedratescount <= IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
ieextendedsupportedrates->id = IEEE80211_IE_EXTENDED_SUPPORTED_RATES;
|
||||||
|
ieextendedsupportedrates->len = device->supportedratescount - IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH;
|
||||||
|
|
||||||
|
for (i = IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH, j = 0; i < device->supportedratescount; i++, j++) {
|
||||||
|
ieextendedsupportedrates->rates[j] = device->supportedrates[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return sizeof(struct ieee80211_ie_extended_supported_rates) + ieextendedsupportedrates->len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static int wifi_ie_dsss(char* buffer, struct wifi_device* device) {
|
||||||
|
struct ieee80211_ie_dsss* iedsss;
|
||||||
|
|
||||||
|
ASSERT(buffer != NULL);
|
||||||
|
ASSERT(device != NULL);
|
||||||
|
|
||||||
|
iedsss = (struct ieee80211_ie_dsss*)buffer;
|
||||||
|
iedsss->id = IEEE80211_IE_SSID;
|
||||||
|
iedsss->len = 1;
|
||||||
|
iedsss->channel = device->currentfreq.channel;
|
||||||
|
|
||||||
|
return sizeof(struct ieee80211_ie_dsss);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static int wifi_ie_erp(char* buffer, struct wifi_device* device) {
|
||||||
|
ASSERT(buffer != NULL);
|
||||||
|
ASSERT(device != NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* TODO implements params ERP
|
||||||
|
struct ieee80211_ie_erp* ieerp = (struct ieee80211_ie_erp*)buffer;
|
||||||
|
|
||||||
|
if (device->currentfreq.mode != CAPWAP_RADIO_TYPE_80211G) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ieerp->id = IEEE80211_IE_ERP;
|
||||||
|
ieerp->len = 1;
|
||||||
|
iedsss->params = 0;
|
||||||
|
|
||||||
|
return sizeof(struct ieee80211_ie_erp);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_wlan_setupap(struct capwap_80211_addwlan_element* addwlan, struct capwap_array* ies) {
|
||||||
|
int result;
|
||||||
|
struct wifi_wlan* wlan;
|
||||||
|
struct wtp_radio* radio;
|
||||||
|
char buffer[IEEE80211_MTU];
|
||||||
|
struct ieee80211_header_mgmt* header;
|
||||||
|
struct wlan_setupap_params params;
|
||||||
|
|
||||||
|
ASSERT(addwlan != NULL);
|
||||||
|
|
||||||
|
/* Get WLAN and Radio information */
|
||||||
|
wlan = wifi_wlan_getdevice(addwlan->radioid, addwlan->wlanid);
|
||||||
|
radio = wtp_radio_get_phy(addwlan->radioid);
|
||||||
|
if (!wlan || !radio || !wlan->handle || !wlan->device) {
|
||||||
|
return -1;
|
||||||
|
} else if (!wlan->device->instance->ops->wlan_setupap) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
header = (struct ieee80211_header_mgmt*)buffer;
|
||||||
|
|
||||||
|
/* */
|
||||||
|
memset(¶ms, 0, sizeof(struct wlan_setupap_params));
|
||||||
|
params.headbeacon = buffer;
|
||||||
|
|
||||||
|
/* Management header frame */
|
||||||
|
header->framecontrol = IEEE80211_FRAME_CONTROL(IEEE80211_FRAMECONTROL_TYPE_MGMT, IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_BEACON);
|
||||||
|
memset(header->da, 0xff, ETH_ALEN);
|
||||||
|
wlan->device->instance->ops->wlan_getmacaddress(wlan->handle, header->sa);
|
||||||
|
memcpy(header->bssid, header->sa, ETH_ALEN);
|
||||||
|
header->beaconinterval = __cpu_to_le16(radio->radioconfig.beaconperiod);
|
||||||
|
header->capability = __cpu_to_le16(addwlan->capability);
|
||||||
|
params.headbeaconlength += sizeof(struct ieee80211_header_mgmt);
|
||||||
|
|
||||||
|
/* Information Element: SSID */
|
||||||
|
result = wifi_ie_ssid(¶ms.headbeacon[params.headbeaconlength], (const char*)addwlan->ssid, (addwlan->suppressssid ? 1 : 0));
|
||||||
|
if (result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.headbeaconlength += result;
|
||||||
|
|
||||||
|
/* Information Element: Supported Rates */
|
||||||
|
wifi_wlan_getrates(wlan->device, radio);
|
||||||
|
result = wifi_ie_supportedrates(¶ms.headbeacon[params.headbeaconlength], wlan->device);
|
||||||
|
if (result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.headbeaconlength += result;
|
||||||
|
|
||||||
|
/* Information Element: DSSS */
|
||||||
|
result = wifi_ie_dsss(¶ms.headbeacon[params.headbeaconlength], wlan->device);
|
||||||
|
if (result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.headbeaconlength += result;
|
||||||
|
|
||||||
|
/* Separate Information Elements into two block between IE TIM */
|
||||||
|
params.tailbeacon = ¶ms.headbeacon[params.headbeaconlength];
|
||||||
|
|
||||||
|
/* Information Element: Country */
|
||||||
|
/* TODO */
|
||||||
|
|
||||||
|
/* Information Element: ERP */
|
||||||
|
result = wifi_ie_erp(¶ms.tailbeacon[params.tailbeaconlength], wlan->device);
|
||||||
|
if (result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.tailbeaconlength += result;
|
||||||
|
|
||||||
|
/* Information Element: Extended Supported Rates */
|
||||||
|
result = wifi_ie_extendedsupportedrates(¶ms.tailbeacon[params.tailbeaconlength], wlan->device);
|
||||||
|
if (result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.tailbeaconlength += result;
|
||||||
|
|
||||||
|
/* Set configuration params */
|
||||||
|
strcpy(params.ssid, (const char*)addwlan->ssid);
|
||||||
|
params.suppressssid = addwlan->suppressssid;
|
||||||
|
params.beaconinterval = radio->radioconfig.beaconperiod;
|
||||||
|
params.dtimperiod = radio->radioconfig.dtimperiod;
|
||||||
|
params.authenticationtype = addwlan->authmode;
|
||||||
|
|
||||||
|
/* Configuration complete */
|
||||||
|
return wlan->device->instance->ops->wlan_setupap(wlan->handle, ¶ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_wlan_startap(int radioid, int wlanid) {
|
||||||
|
struct wifi_wlan* wlan;
|
||||||
|
|
||||||
|
/* */
|
||||||
|
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||||
|
if (!wlan->device->instance->ops->wlan_startap) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wlan->device->instance->ops->wlan_startap(wlan->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_wlan_stopap(int radioid, int wlanid) {
|
||||||
|
struct wifi_wlan* wlan;
|
||||||
|
|
||||||
|
/* */
|
||||||
|
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||||
|
if (!wlan->device->instance->ops->wlan_stopap) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wlan->device->instance->ops->wlan_stopap(wlan->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_wlan_getbssid(int radioid, int wlanid, uint8_t* bssid) {
|
||||||
|
struct wifi_wlan* wlan;
|
||||||
|
|
||||||
|
/* */
|
||||||
|
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||||
|
if (!wlan->device->instance->ops->wlan_getmacaddress) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wlan->device->instance->ops->wlan_getmacaddress(wlan->handle, bssid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void wifi_wlan_destroy(int radioid, int wlanid) {
|
||||||
|
struct wifi_wlan* wlan;
|
||||||
|
|
||||||
|
ASSERT(radioid > 0);
|
||||||
|
ASSERT(wlanid > 0);
|
||||||
|
|
||||||
|
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||||
|
if (wlan && wlan->handle) {
|
||||||
|
if (wlan->device->instance->ops->wlan_delete) {
|
||||||
|
wlan->device->instance->ops->wlan_delete(wlan->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(wlan, 0, sizeof(struct wifi_wlan));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_capability* wifi_device_getcapability(int radioid) {
|
||||||
|
struct wifi_device* device;
|
||||||
|
|
||||||
|
ASSERT(radioid > 0);
|
||||||
|
|
||||||
|
if (g_wifidevice->count <= radioid) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieve cached capability */
|
||||||
|
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||||
|
if (!device->capability && device->handle && device->instance->ops->device_getcapability) {
|
||||||
|
/* Get capability from device */
|
||||||
|
device->capability = (struct wifi_capability*)capwap_alloc(sizeof(struct wifi_capability));
|
||||||
|
memset(device->capability, 0, sizeof(struct wifi_capability));
|
||||||
|
|
||||||
|
device->capability->bands = capwap_array_create(sizeof(struct wifi_band_capability), 0, 1);
|
||||||
|
device->capability->ciphers = capwap_array_create(sizeof(struct wifi_cipher_capability), 0, 1);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
if (device->instance->ops->device_getcapability(device->handle, device->capability)) {
|
||||||
|
wifi_device_freecapability(device->capability);
|
||||||
|
device->capability = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return device->capability;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_device_setfrequency(int radioid, uint32_t band, uint32_t mode, uint8_t channel) {
|
||||||
|
int i, j;
|
||||||
|
int result = -1;
|
||||||
|
struct wifi_capability* capability;
|
||||||
|
uint32_t frequency = 0;
|
||||||
|
|
||||||
|
ASSERT(radioid > 0);
|
||||||
|
|
||||||
|
if (g_wifidevice->count <= radioid) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Capability device */
|
||||||
|
capability = wifi_device_getcapability(radioid);
|
||||||
|
if (!capability || !(capability->flags & WIFI_CAPABILITY_RADIOTYPE) || !(capability->flags & WIFI_CAPABILITY_BANDS)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search frequency */
|
||||||
|
for (i = 0; (i < capability->bands->count) && !frequency; i++) {
|
||||||
|
struct wifi_band_capability* bandcap = (struct wifi_band_capability*)capwap_array_get_item_pointer(capability->bands, i);
|
||||||
|
|
||||||
|
if (bandcap->band == band) {
|
||||||
|
for (j = 0; j < bandcap->freq->count; j++) {
|
||||||
|
struct wifi_freq_capability* freqcap = (struct wifi_freq_capability*)capwap_array_get_item_pointer(bandcap->freq, j);
|
||||||
|
if (freqcap->channel == channel) {
|
||||||
|
frequency = freqcap->frequency;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Configure frequency */
|
||||||
|
if (frequency) {
|
||||||
|
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||||
|
|
||||||
|
memset(&device->currentfreq, 0, sizeof(struct wifi_frequency));
|
||||||
|
device->currentfreq.band = band;
|
||||||
|
device->currentfreq.mode = mode;
|
||||||
|
device->currentfreq.channel = channel;
|
||||||
|
device->currentfreq.frequency = frequency;
|
||||||
|
|
||||||
|
/* According to the selected band remove the invalid mode */
|
||||||
|
if (device->currentfreq.band == WIFI_BAND_2GHZ) {
|
||||||
|
device->currentfreq.mode &= ~CAPWAP_RADIO_TYPE_80211A;
|
||||||
|
} else if (device->currentfreq.band == WIFI_BAND_5GHZ) {
|
||||||
|
device->currentfreq.mode &= ~(CAPWAP_RADIO_TYPE_80211B | CAPWAP_RADIO_TYPE_80211G);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set frequency */
|
||||||
|
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||||
|
if (device->handle && device->instance->ops->device_setfrequency) {
|
||||||
|
result = device->instance->ops->device_setfrequency(device->handle, &device->currentfreq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
uint32_t wifi_iface_index(const char* ifname) {
|
||||||
|
if (!ifname || !*ifname) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return if_nametoindex(ifname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_iface_updown(int sock, const char* ifname, int up) {
|
||||||
|
struct ifreq ifreq;
|
||||||
|
|
||||||
|
ASSERT(sock > 0);
|
||||||
|
ASSERT(ifname != NULL);
|
||||||
|
ASSERT(*ifname != 0);
|
||||||
|
|
||||||
|
/* Change link state of interface */
|
||||||
|
memset(&ifreq, 0, sizeof(ifreq));
|
||||||
|
strcpy(ifreq.ifr_name, ifname);
|
||||||
|
if (!ioctl(sock, SIOCGIFFLAGS, &ifreq)) {
|
||||||
|
if (up) {
|
||||||
|
ifreq.ifr_flags |= IFF_UP;
|
||||||
|
} else {
|
||||||
|
ifreq.ifr_flags &= ~IFF_UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ioctl(sock, SIOCSIFFLAGS, &ifreq)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_iface_hwaddr(int sock, const char* ifname, uint8_t* hwaddr) {
|
||||||
|
struct ifreq ifreq;
|
||||||
|
|
||||||
|
ASSERT(sock > 0);
|
||||||
|
ASSERT(ifname != NULL);
|
||||||
|
ASSERT(*ifname != 0);
|
||||||
|
ASSERT(hwaddr != NULL);
|
||||||
|
|
||||||
|
/* Get mac address of interface */
|
||||||
|
memset(&ifreq, 0, sizeof(ifreq));
|
||||||
|
strcpy(ifreq.ifr_name, ifname);
|
||||||
|
if (!ioctl(sock, SIOCGIFHWADDR, &ifreq)) {
|
||||||
|
if (ifreq.ifr_hwaddr.sa_family == ARPHRD_ETHER) {
|
||||||
|
memcpy(hwaddr, ifreq.ifr_hwaddr.sa_data, ETH_ALEN);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
unsigned long wifi_frequency_to_channel(unsigned long freq) {
|
||||||
|
if ((freq >= 2412) && (freq <= 2472)) {
|
||||||
|
return (freq - 2407) / 5;
|
||||||
|
} else if (freq == 2484) {
|
||||||
|
return 14;
|
||||||
|
} else if ((freq >= 5035) && (freq <= 5825)) {
|
||||||
|
return freq / 5 - 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
235
src/binding/ieee80211/wifi_drivers.h
Normal file
235
src/binding/ieee80211/wifi_drivers.h
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
#ifndef __WIFI_DRIVERS_HEADER__
|
||||||
|
#define __WIFI_DRIVERS_HEADER__
|
||||||
|
|
||||||
|
#include <net/if_arp.h>
|
||||||
|
#include <linux/if_ether.h>
|
||||||
|
|
||||||
|
/* */
|
||||||
|
#define WIFI_DRIVER_NAME_SIZE 16
|
||||||
|
#define WIFI_SSID_MAX_LENGTH 32
|
||||||
|
|
||||||
|
/* */
|
||||||
|
#define WIFI_BAND_UNKNOWN 0
|
||||||
|
#define WIFI_BAND_2GHZ 1
|
||||||
|
#define WIFI_BAND_5GHZ 2
|
||||||
|
|
||||||
|
/* */
|
||||||
|
#define WIFI_SUPPORTEDRATE_MAX_COUNT 16
|
||||||
|
|
||||||
|
/* */
|
||||||
|
#define WIFI_CAPABILITY_RADIOSUPPORTED 0x00000001
|
||||||
|
#define WIFI_CAPABILITY_RADIOTYPE 0x00000002
|
||||||
|
#define WIFI_CAPABILITY_BANDS 0x00000004
|
||||||
|
#define WIFI_CAPABILITY_CIPHERS 0x00000008
|
||||||
|
#define WIFI_CAPABILITY_ANTENNA_MASK 0x00000010
|
||||||
|
|
||||||
|
/* */
|
||||||
|
#define WIFI_CAPABILITY_AP_SUPPORTED 0x00000001
|
||||||
|
#define WIFI_CAPABILITY_AP_VLAN_SUPPORTED 0x00000002
|
||||||
|
#define WIFI_CAPABILITY_ADHOC_SUPPORTED 0x00000004
|
||||||
|
#define WIFI_CAPABILITY_MONITOR_SUPPORTED 0x00000008
|
||||||
|
#define WIFI_CAPABILITY_WDS_SUPPORTED 0x00000010
|
||||||
|
|
||||||
|
#define FREQ_CAPABILITY_DISABLED 0x00000001
|
||||||
|
#define FREQ_CAPABILITY_PASSIVE_SCAN 0x00000002
|
||||||
|
#define FREQ_CAPABILITY_NO_IBBS 0x00000004
|
||||||
|
#define FREQ_CAPABILITY_RADAR 0x00000008
|
||||||
|
#define FREQ_CAPABILITY_DFS_STATE 0x00000010
|
||||||
|
#define FREQ_CAPABILITY_DFS_TIME 0x00000020
|
||||||
|
|
||||||
|
#define RATE_CAPABILITY_SHORTPREAMBLE 0x00000001
|
||||||
|
|
||||||
|
#define CIPHER_CAPABILITY_UNKNOWN 0
|
||||||
|
#define CIPHER_CAPABILITY_WEP40 1
|
||||||
|
#define CIPHER_CAPABILITY_WEP104 2
|
||||||
|
#define CIPHER_CAPABILITY_TKIP 3
|
||||||
|
#define CIPHER_CAPABILITY_CCMP 4
|
||||||
|
#define CIPHER_CAPABILITY_CMAC 5
|
||||||
|
#define CIPHER_CAPABILITY_GCMP 6
|
||||||
|
#define CIPHER_CAPABILITY_WPI_SMS4 7
|
||||||
|
|
||||||
|
#define IEEE80211_DFS_USABLE 0
|
||||||
|
#define IEEE80211_DFS_UNAVAILABLE 1
|
||||||
|
#define IEEE80211_DFS_AVAILABLE 2
|
||||||
|
|
||||||
|
#define WLAN_INTERFACE_AP 1
|
||||||
|
|
||||||
|
/* */
|
||||||
|
typedef void* wifi_global_handle;
|
||||||
|
typedef void* wifi_device_handle;
|
||||||
|
typedef void* wifi_wlan_handle;
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct device_init_params {
|
||||||
|
const char* ifname;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wlan_init_params {
|
||||||
|
const char* ifname;
|
||||||
|
int type;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wlan_setupap_params {
|
||||||
|
char* headbeacon;
|
||||||
|
int headbeaconlength;
|
||||||
|
char* tailbeacon;
|
||||||
|
int tailbeaconlength;
|
||||||
|
|
||||||
|
char ssid[WIFI_SSID_MAX_LENGTH + 1];
|
||||||
|
uint8_t suppressssid;
|
||||||
|
|
||||||
|
uint16_t beaconinterval;
|
||||||
|
uint8_t dtimperiod;
|
||||||
|
|
||||||
|
uint8_t authenticationtype;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Interface capability */
|
||||||
|
struct wifi_freq_capability {
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
unsigned long frequency; /* MHz */
|
||||||
|
unsigned long channel;
|
||||||
|
|
||||||
|
unsigned long maxtxpower; /* mBm = 100 * dBm */
|
||||||
|
|
||||||
|
unsigned long dfsstate;
|
||||||
|
unsigned long dfstime; /* ms */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_rate_capability {
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
uint8_t bitrate;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_band_capability {
|
||||||
|
unsigned long band;
|
||||||
|
|
||||||
|
unsigned long htcapability;
|
||||||
|
|
||||||
|
struct capwap_array* freq;
|
||||||
|
struct capwap_array* rate;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_cipher_capability {
|
||||||
|
unsigned long cipher;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_capability {
|
||||||
|
wifi_device_handle device;
|
||||||
|
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
/* WIFI_CAPABILITY_RADIOSUPPORTED */
|
||||||
|
unsigned long radiosupported;
|
||||||
|
|
||||||
|
/* WIFI_CAPABILITY_RADIOTYPE */
|
||||||
|
unsigned long radiotype;
|
||||||
|
|
||||||
|
/* WIFI_CAPABILITY_ANTENNA_MASK */
|
||||||
|
unsigned long txantennamask;
|
||||||
|
unsigned long rxantennamask;
|
||||||
|
|
||||||
|
/* WIFI_CAPABILITY_BANDS */
|
||||||
|
struct capwap_array* bands;
|
||||||
|
|
||||||
|
/* WIFI_CAPABILITY_CIPHERS */
|
||||||
|
struct capwap_array* ciphers;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Frequency configuration */
|
||||||
|
struct wifi_frequency {
|
||||||
|
uint32_t band;
|
||||||
|
uint32_t mode;
|
||||||
|
uint8_t channel;
|
||||||
|
uint32_t frequency;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_driver_ops {
|
||||||
|
const char* name; /* Name of wifi driver */
|
||||||
|
const char* description; /* Description of wifi driver */
|
||||||
|
|
||||||
|
/* Global initialize driver */
|
||||||
|
wifi_global_handle (*global_init)(void);
|
||||||
|
void (*global_deinit)(wifi_global_handle handle);
|
||||||
|
|
||||||
|
/* Device functions */
|
||||||
|
wifi_device_handle (*device_init)(wifi_global_handle handle, struct device_init_params* params);
|
||||||
|
int (*device_getcapability)(wifi_device_handle handle, struct wifi_capability* capability);
|
||||||
|
int (*device_setfrequency)(wifi_device_handle handle, struct wifi_frequency* freq);
|
||||||
|
void (*device_deinit)(wifi_device_handle handle);
|
||||||
|
|
||||||
|
/* WLAN functions */
|
||||||
|
wifi_wlan_handle (*wlan_create)(wifi_device_handle handle, struct wlan_init_params* params);
|
||||||
|
int (*wlan_setupap)(wifi_wlan_handle handle, struct wlan_setupap_params* params);
|
||||||
|
int (*wlan_startap)(wifi_wlan_handle handle);
|
||||||
|
int (*wlan_stopap)(wifi_wlan_handle handle);
|
||||||
|
int (*wlan_getmacaddress)(wifi_wlan_handle handle, uint8_t* address);
|
||||||
|
void (*wlan_delete)(wifi_wlan_handle handle);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_driver_instance {
|
||||||
|
struct wifi_driver_ops* ops; /* Driver functions */
|
||||||
|
wifi_global_handle handle; /* Global instance handle */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_device {
|
||||||
|
wifi_device_handle handle; /* Device handle */
|
||||||
|
struct wifi_driver_instance* instance; /* Driver instance */
|
||||||
|
|
||||||
|
struct capwap_array* wlan; /* Virtual AP */
|
||||||
|
|
||||||
|
/* Cache capability */
|
||||||
|
struct wifi_capability* capability;
|
||||||
|
|
||||||
|
/* Current frequency */
|
||||||
|
struct wifi_frequency currentfreq;
|
||||||
|
|
||||||
|
/* Supported Rates */
|
||||||
|
int supportedratescount;
|
||||||
|
uint8_t supportedrates[WIFI_SUPPORTEDRATE_MAX_COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wifi_wlan {
|
||||||
|
wifi_wlan_handle handle;
|
||||||
|
struct wifi_device* device;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Initialize wifi driver engine */
|
||||||
|
int wifi_driver_init(void);
|
||||||
|
void wifi_driver_free(void);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_device_connect(int radioid, const char* ifname, const char* driver);
|
||||||
|
struct wifi_capability* wifi_device_getcapability(int radioid);
|
||||||
|
int wifi_device_setfrequency(int radioid, uint32_t band, uint32_t mode, uint8_t channel);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wifi_wlan_create(int radioid, int wlanid, const char* ifname, uint8_t* bssid);
|
||||||
|
int wifi_wlan_setupap(struct capwap_80211_addwlan_element* addwlan, struct capwap_array* ies);
|
||||||
|
int wifi_wlan_startap(int radioid, int wlanid);
|
||||||
|
int wifi_wlan_stopap(int radioid, int wlanid);
|
||||||
|
int wifi_wlan_getbssid(int radioid, int wlanid, uint8_t* bssid);
|
||||||
|
void wifi_wlan_destroy(int radioid, int wlanid);
|
||||||
|
|
||||||
|
/* Util functions */
|
||||||
|
uint32_t wifi_iface_index(const char* ifname);
|
||||||
|
int wifi_iface_hwaddr(int sock, const char* ifname, uint8_t* hwaddr);
|
||||||
|
unsigned long wifi_frequency_to_channel(unsigned long freq);
|
||||||
|
|
||||||
|
int wifi_iface_updown(int sock, const char* ifname, int up);
|
||||||
|
#define wifi_iface_up(sock, ifname) wifi_iface_updown(sock, ifname, 1)
|
||||||
|
#define wifi_iface_down(sock, ifname) wifi_iface_updown(sock, ifname, 0)
|
||||||
|
|
||||||
|
#endif /* __WIFI_DRIVERS_HEADER__ */
|
1024
src/binding/ieee80211/wifi_nl80211.c
Normal file
1024
src/binding/ieee80211/wifi_nl80211.c
Normal file
File diff suppressed because it is too large
Load Diff
71
src/binding/ieee80211/wifi_nl80211.h
Normal file
71
src/binding/ieee80211/wifi_nl80211.h
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#ifndef __WIFI_NL80211_HEADER__
|
||||||
|
#define __WIFI_NL80211_HEADER__
|
||||||
|
|
||||||
|
/* Compatibility functions */
|
||||||
|
#if !defined(HAVE_LIBNL20) && !defined(HAVE_LIBNL30)
|
||||||
|
#define nl_sock nl_handle
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* */
|
||||||
|
typedef int (*nl_valid_cb)(struct nl_msg* msg, void* data);
|
||||||
|
|
||||||
|
/* Global handle */
|
||||||
|
struct nl80211_global_handle {
|
||||||
|
struct nl_sock* nl;
|
||||||
|
struct nl_cb* nl_cb;
|
||||||
|
int nl80211_id;
|
||||||
|
|
||||||
|
int sock_util;
|
||||||
|
|
||||||
|
struct capwap_list* devicelist;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Device handle */
|
||||||
|
struct nl80211_device_handle {
|
||||||
|
struct nl80211_global_handle* globalhandle;
|
||||||
|
|
||||||
|
uint32_t phyindex;
|
||||||
|
char phyname[IFNAMSIZ];
|
||||||
|
};
|
||||||
|
|
||||||
|
/* WLAN handle */
|
||||||
|
struct nl80211_wlan_handle {
|
||||||
|
struct nl80211_device_handle* devicehandle;
|
||||||
|
|
||||||
|
struct nl_sock* nl;
|
||||||
|
struct nl_cb* nl_cb;
|
||||||
|
|
||||||
|
uint32_t virtindex;
|
||||||
|
char virtname[IFNAMSIZ];
|
||||||
|
|
||||||
|
uint8_t address[ETH_ALEN];
|
||||||
|
|
||||||
|
/* Beacon / Probe response */
|
||||||
|
void* headbeacon;
|
||||||
|
int headbeaconlength;
|
||||||
|
void* tailbeacon;
|
||||||
|
int tailbeaconlength;
|
||||||
|
|
||||||
|
char ssid[WIFI_SSID_MAX_LENGTH + 1];
|
||||||
|
uint32_t suppressssid;
|
||||||
|
|
||||||
|
uint32_t beaconinterval;
|
||||||
|
uint32_t dtimperiod;
|
||||||
|
|
||||||
|
uint32_t authenticationtype;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Physical device info */
|
||||||
|
struct nl80211_phydevice_item {
|
||||||
|
uint32_t index;
|
||||||
|
char name[IFNAMSIZ];
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Virtual device info */
|
||||||
|
struct nl80211_virtdevice_item {
|
||||||
|
uint32_t phyindex;
|
||||||
|
uint32_t virtindex;
|
||||||
|
char virtname[IFNAMSIZ];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __WIFI_NL80211_HEADER__ */
|
@ -137,7 +137,7 @@ char* capwap_duplicate_string(const char* source) {
|
|||||||
|
|
||||||
ASSERT(source != NULL);
|
ASSERT(source != NULL);
|
||||||
|
|
||||||
clone = capwap_alloc(sizeof(char) * (strlen(source) + 1));
|
clone = capwap_alloc(strlen(source) + 1);
|
||||||
strcpy(clone, source);
|
strcpy(clone, source);
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
|
@ -124,7 +124,7 @@ void capwap_element_80211_antenna_copy(struct capwap_80211_antenna_element* dst,
|
|||||||
ASSERT(src != NULL);
|
ASSERT(src != NULL);
|
||||||
|
|
||||||
if (dst->selections) {
|
if (dst->selections) {
|
||||||
capwap_array_free(dst->selections);
|
capwap_array_resize(dst->selections, 0);
|
||||||
} else {
|
} else {
|
||||||
dst->selections = capwap_array_create(sizeof(uint8_t), 0, 1);
|
dst->selections = capwap_array_create(sizeof(uint8_t), 0, 1);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ void capwap_get_packet_digest(struct capwap_packet_rxmng* rxmngpacket, struct ca
|
|||||||
|
|
||||||
MD5Final(&mdContext);
|
MD5Final(&mdContext);
|
||||||
|
|
||||||
memcpy(&packetdigest[0], &mdContext.digest[0], sizeof(unsigned char) * 16);
|
memcpy(&packetdigest[0], &mdContext.digest[0], 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify duplicate packet */
|
/* Verify duplicate packet */
|
||||||
@ -140,7 +140,7 @@ int capwap_recv_retrasmitted_request(struct capwap_dtls* dtls, struct capwap_pac
|
|||||||
|
|
||||||
/* Check packet digest */
|
/* Check packet digest */
|
||||||
capwap_get_packet_digest(rxmngpacket, connection, recvpacketdigest);
|
capwap_get_packet_digest(rxmngpacket, connection, recvpacketdigest);
|
||||||
if (!memcmp(&recvpacketdigest[0], &packetdigest[0], sizeof(unsigned char) * 16)) {
|
if (!memcmp(&recvpacketdigest[0], &packetdigest[0], 16)) {
|
||||||
/* Retransmit response */
|
/* Retransmit response */
|
||||||
if (!capwap_crypt_sendto_fragmentpacket(dtls, connection->socket.socket[connection->socket.type], txfragmentpacket, &connection->localaddr, &connection->remoteaddr)) {
|
if (!capwap_crypt_sendto_fragmentpacket(dtls, connection->socket.socket[connection->socket.type], txfragmentpacket, &connection->localaddr, &connection->remoteaddr)) {
|
||||||
capwap_logging_debug("Warning: error to resend response packet");
|
capwap_logging_debug("Warning: error to resend response packet");
|
||||||
|
119
src/wtp/wtp.c
119
src/wtp/wtp.c
@ -19,35 +19,6 @@ struct wtp_t g_wtp;
|
|||||||
|
|
||||||
static char g_configurationfile[260] = WTP_STANDARD_CONFIGURATION_FILE;
|
static char g_configurationfile[260] = WTP_STANDARD_CONFIGURATION_FILE;
|
||||||
|
|
||||||
/* */
|
|
||||||
static struct wtp_radio* wtp_create_radio(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 = g_wtp.radios->count;
|
|
||||||
radio->status = WTP_RADIO_DISABLED;
|
|
||||||
|
|
||||||
/* Init configuration radio */
|
|
||||||
radio->antenna.selections = capwap_array_create(sizeof(uint8_t), 0, 1);
|
|
||||||
|
|
||||||
return radio;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* */
|
|
||||||
static void wtp_free_radios(void) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
capwap_array_free(radio->antenna.selections);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* */
|
|
||||||
capwap_array_free(g_wtp.radios);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Alloc WTP */
|
/* Alloc WTP */
|
||||||
static int wtp_init(void) {
|
static int wtp_init(void) {
|
||||||
/* Init WTP with default value */
|
/* Init WTP with default value */
|
||||||
@ -55,6 +26,7 @@ static int wtp_init(void) {
|
|||||||
|
|
||||||
/* Standard running mode is standalone */
|
/* Standard running mode is standalone */
|
||||||
g_wtp.standalone = 1;
|
g_wtp.standalone = 1;
|
||||||
|
strcpy(g_wtp.wlanprefix, WTP_PREFIX_DEFAULT_NAME);
|
||||||
|
|
||||||
/* Standard name */
|
/* Standard name */
|
||||||
g_wtp.name.name = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_NAME);
|
g_wtp.name.name = (uint8_t*)capwap_duplicate_string(WTP_STANDARD_NAME);
|
||||||
@ -108,8 +80,8 @@ static int wtp_init(void) {
|
|||||||
g_wtp.acdiscoveryresponse = capwap_array_create(sizeof(struct wtp_discovery_response), 0, 1);
|
g_wtp.acdiscoveryresponse = capwap_array_create(sizeof(struct wtp_discovery_response), 0, 1);
|
||||||
|
|
||||||
/* Radios */
|
/* Radios */
|
||||||
g_wtp.radios = capwap_array_create(sizeof(struct wtp_radio), 0, 1);
|
wtp_radio_init();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +130,7 @@ static void wtp_destroy(void) {
|
|||||||
capwap_free(g_wtp.location.value);
|
capwap_free(g_wtp.location.value);
|
||||||
|
|
||||||
/* Free radios */
|
/* Free radios */
|
||||||
wtp_free_radios();
|
wtp_radio_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save AC address */
|
/* Save AC address */
|
||||||
@ -311,52 +283,6 @@ static int wtp_parsing_radio_configuration(config_setting_t* configElement, stru
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DSSS */
|
|
||||||
configSection = config_setting_get_member(configElement, "dsss");
|
|
||||||
if (configSection) {
|
|
||||||
radio->directsequencecontrol.radioid = radio->radioid;
|
|
||||||
radio->directsequencecontrol.currentchannel = 0;
|
|
||||||
|
|
||||||
if (config_setting_lookup_int(configSection, "clearchannelassessment", &configInt) == CONFIG_TRUE) {
|
|
||||||
if ((configInt & CAPWAP_DSCONTROL_CCA_MASK) == configInt) {
|
|
||||||
radio->directsequencecontrol.currentcca = (uint8_t)configInt;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config_setting_lookup_int(configSection, "energydetectthreshold", &configInt) == CONFIG_TRUE) {
|
|
||||||
radio->directsequencecontrol.enerydetectthreshold = (uint32_t)configInt;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* OFDM */
|
|
||||||
configSection = config_setting_get_member(configElement, "ofdm");
|
|
||||||
if (configSection) {
|
|
||||||
radio->ofdmcontrol.radioid = radio->radioid;
|
|
||||||
radio->ofdmcontrol.currentchannel = 0;
|
|
||||||
|
|
||||||
if (config_setting_lookup_int(configSection, "bandsupported", &configInt) == CONFIG_TRUE) {
|
|
||||||
if ((configInt & CAPWAP_OFDMCONTROL_BAND_MASK) == configInt) {
|
|
||||||
radio->ofdmcontrol.bandsupport = (uint8_t)configInt;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config_setting_lookup_int(configSection, "tithreshold", &configInt) == CONFIG_TRUE) {
|
|
||||||
radio->ofdmcontrol.tithreshold = (uint32_t)configInt;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Multi-Domain Capability */
|
/* Multi-Domain Capability */
|
||||||
configSection = config_setting_get_member(configElement, "multidomaincapability");
|
configSection = config_setting_get_member(configElement, "multidomaincapability");
|
||||||
if (configSection) {
|
if (configSection) {
|
||||||
@ -680,7 +606,7 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
|||||||
case CAPWAP_WIRELESS_BINDING_IEEE80211: {
|
case CAPWAP_WIRELESS_BINDING_IEEE80211: {
|
||||||
/* Initialize wifi binding driver */
|
/* Initialize wifi binding driver */
|
||||||
capwap_logging_info("Initializing wifi binding engine");
|
capwap_logging_info("Initializing wifi binding engine");
|
||||||
if (wifi_init_driver()) {
|
if (wifi_driver_init()) {
|
||||||
capwap_logging_fatal("Unable initialize wifi binding engine");
|
capwap_logging_fatal("Unable initialize wifi binding engine");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -808,16 +734,27 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set WLAN WTP */
|
||||||
|
if (config_lookup_string(config, "wlan.prefix", &configString) == CONFIG_TRUE) {
|
||||||
|
int length = strlen(configString);
|
||||||
|
|
||||||
|
if ((length > 0) && (length < WTP_PREFIX_NAME_MAX_LENGTH)) {
|
||||||
|
strcpy(g_wtp.wlanprefix, configString);
|
||||||
|
} else {
|
||||||
|
capwap_logging_error("Invalid configuration file, wlan.prefix string length exceeded");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Set Radio WTP */
|
/* Set Radio WTP */
|
||||||
configSetting = config_lookup(config, "application.radio");
|
configSetting = config_lookup(config, "application.radio");
|
||||||
if (configSetting != NULL) {
|
if (configSetting != NULL) {
|
||||||
|
struct wtp_radio* radio;
|
||||||
struct wifi_capability* capability;
|
struct wifi_capability* capability;
|
||||||
int count = config_setting_length(configSetting);
|
int count = config_setting_length(configSetting);
|
||||||
|
|
||||||
if (g_wtp.binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
|
if (g_wtp.binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
struct wtp_radio* radio;
|
|
||||||
|
|
||||||
if (!IS_VALID_RADIOID(g_wtp.radios->count + 1)) {
|
if (!IS_VALID_RADIOID(g_wtp.radios->count + 1)) {
|
||||||
capwap_logging_error("Exceeded max number of radio device");
|
capwap_logging_error("Exceeded max number of radio device");
|
||||||
return 0;
|
return 0;
|
||||||
@ -829,7 +766,7 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
|||||||
if (config_setting_lookup_string(configElement, "device", &configString) == CONFIG_TRUE) {
|
if (config_setting_lookup_string(configElement, "device", &configString) == CONFIG_TRUE) {
|
||||||
if (*configString && (strlen(configString) < IFNAMSIZ)) {
|
if (*configString && (strlen(configString) < IFNAMSIZ)) {
|
||||||
/* Create new radio device */
|
/* Create new radio device */
|
||||||
radio = wtp_create_radio();
|
radio = wtp_radio_create_phy();
|
||||||
strcpy(radio->device, configString);
|
strcpy(radio->device, configString);
|
||||||
|
|
||||||
if (config_setting_lookup_bool(configElement, "enabled", &configInt) == CONFIG_TRUE) {
|
if (config_setting_lookup_bool(configElement, "enabled", &configInt) == CONFIG_TRUE) {
|
||||||
@ -839,14 +776,15 @@ static int wtp_parsing_configuration_1_0(config_t* config) {
|
|||||||
/* Initialize radio device */
|
/* Initialize radio device */
|
||||||
if (config_setting_lookup_string(configElement, "driver", &configString) == CONFIG_TRUE) {
|
if (config_setting_lookup_string(configElement, "driver", &configString) == CONFIG_TRUE) {
|
||||||
if (*configString && (strlen(configString) < WIFI_DRIVER_NAME_SIZE)) {
|
if (*configString && (strlen(configString) < WIFI_DRIVER_NAME_SIZE)) {
|
||||||
result = wifi_create_device(radio->radioid, radio->device, configString);
|
result = wifi_device_connect(radio->radioid, radio->device, configString);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
radio->status = WTP_RADIO_ENABLED;
|
radio->status = WTP_RADIO_ENABLED;
|
||||||
capwap_logging_info("Register radioid %d with radio device: %s - %s", radio->radioid, radio->device, configString);
|
capwap_logging_info("Register radioid %d with radio device: %s - %s", radio->radioid, radio->device, configString);
|
||||||
|
|
||||||
/* Update radio capability with device query */
|
/* Update radio capability with device query */
|
||||||
capability = wifi_get_capability_device(radio->radioid);
|
capability = wifi_device_getcapability(radio->radioid);
|
||||||
if (capability) {
|
if (capability) {
|
||||||
|
/* TODO */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
radio->status = WTP_RADIO_HWFAILURE;
|
radio->status = WTP_RADIO_HWFAILURE;
|
||||||
@ -1395,14 +1333,13 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
capwap_logging_info("Terminate WTP");
|
capwap_logging_info("Terminate WTP");
|
||||||
|
|
||||||
|
/* Close radio */
|
||||||
|
wtp_radio_close();
|
||||||
|
|
||||||
/* Free binding */
|
/* Free binding */
|
||||||
switch (g_wtp.binding) {
|
if (g_wtp.binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
|
||||||
case CAPWAP_WIRELESS_BINDING_IEEE80211: {
|
capwap_logging_info("Free wifi binding engine");
|
||||||
/* Free wifi binding driver */
|
wifi_driver_free();
|
||||||
wifi_free_driver();
|
|
||||||
capwap_logging_info("Free wifi binding engine");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,8 @@ struct wtp_t {
|
|||||||
int standalone;
|
int standalone;
|
||||||
int running;
|
int running;
|
||||||
|
|
||||||
|
char wlanprefix[IFNAMSIZ];
|
||||||
|
|
||||||
struct wtp_state dfa;
|
struct wtp_state dfa;
|
||||||
struct capwap_network net;
|
struct capwap_network net;
|
||||||
|
|
||||||
|
@ -31,42 +31,42 @@ void wtp_send_configure(struct timeout_control* timeout) {
|
|||||||
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
||||||
|
|
||||||
/* Set message element */
|
/* Set message element */
|
||||||
if ((radio->status == WTP_RADIO_ENABLED) && radio->radioinformation.radioid) {
|
if ((radio->status == WTP_RADIO_ENABLED) && (radio->radioid == radio->radioinformation.radioid)) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION, &radio->radioinformation);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION, &radio->radioinformation);
|
||||||
|
|
||||||
if (radio->radioinformation.radioid) {
|
if (radio->radioid == radio->radioinformation.radioid) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_ANTENNA, &radio->antenna);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_ANTENNA, &radio->antenna);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->directsequencecontrol.radioid && (radio->radioinformation.radiotype & (CAPWAP_RADIO_TYPE_80211B | CAPWAP_RADIO_TYPE_80211G))) {
|
if ((radio->radioid == radio->directsequencecontrol.radioid) && (radio->radioinformation.radiotype & (CAPWAP_RADIO_TYPE_80211B | CAPWAP_RADIO_TYPE_80211G))) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_DIRECTSEQUENCECONTROL, &radio->directsequencecontrol);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_DIRECTSEQUENCECONTROL, &radio->directsequencecontrol);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->macoperation.radioid) {
|
if (radio->radioid == radio->macoperation.radioid) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_MACOPERATION, &radio->macoperation);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_MACOPERATION, &radio->macoperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->multidomaincapability.radioid) {
|
if (radio->radioid == radio->multidomaincapability.radioid) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_MULTIDOMAINCAPABILITY, &radio->multidomaincapability);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_MULTIDOMAINCAPABILITY, &radio->multidomaincapability);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->ofdmcontrol.radioid && (radio->radioinformation.radiotype & CAPWAP_RADIO_TYPE_80211A)) {
|
if ((radio->radioid == radio->ofdmcontrol.radioid) && (radio->radioinformation.radiotype & CAPWAP_RADIO_TYPE_80211A)) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_OFDMCONTROL, &radio->ofdmcontrol);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_OFDMCONTROL, &radio->ofdmcontrol);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->supportedrates.radioid) {
|
if (radio->radioid == radio->supportedrates.radioid) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_SUPPORTEDRATES, &radio->supportedrates);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_SUPPORTEDRATES, &radio->supportedrates);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->txpower.radioid) {
|
if (radio->radioid == radio->txpower.radioid) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_TXPOWER, &radio->txpower);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_TXPOWER, &radio->txpower);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->txpowerlevel.radioid) {
|
if (radio->radioid == radio->txpowerlevel.radioid) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_TXPOWERLEVEL, &radio->txpowerlevel);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_TXPOWERLEVEL, &radio->txpowerlevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio->radioconfig.radioid) {
|
if (radio->radioid == radio->radioconfig.radioid) {
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_WTP_RADIO_CONF, &radio->radioconfig);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_WTP_RADIO_CONF, &radio->radioconfig);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -123,15 +123,18 @@ void wtp_dfa_state_configure(struct capwap_parsed_packet* packet, struct timeout
|
|||||||
capwap_logging_warning("Receive Configure Status Response with error: %d", (int)resultcode->code);
|
capwap_logging_warning("Receive Configure Status Response with error: %d", (int)resultcode->code);
|
||||||
wtp_teardown_connection(timeout);
|
wtp_teardown_connection(timeout);
|
||||||
} else {
|
} else {
|
||||||
/* TODO: gestione richiesta */
|
/* Timers */
|
||||||
|
|
||||||
/* */
|
|
||||||
timers = (struct capwap_timers_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_TIMERS);
|
timers = (struct capwap_timers_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_TIMERS);
|
||||||
g_wtp.dfa.rfcMaxDiscoveryInterval = timers->discovery;
|
g_wtp.dfa.rfcMaxDiscoveryInterval = timers->discovery;
|
||||||
g_wtp.dfa.rfcEchoInterval = timers->echorequest;
|
g_wtp.dfa.rfcEchoInterval = timers->echorequest;
|
||||||
|
|
||||||
/* Send change state event packet */
|
/* Binding values */
|
||||||
wtp_send_datacheck(timeout);
|
if (!wtp_radio_setconfiguration(packet)) {
|
||||||
|
wtp_send_datacheck(timeout); /* Send change state event packet */
|
||||||
|
} else {
|
||||||
|
capwap_logging_warning("Receive Configure Status Response with invalid elements");
|
||||||
|
wtp_teardown_connection(timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -122,8 +122,13 @@ void wtp_dfa_state_join(struct capwap_parsed_packet* packet, struct timeout_cont
|
|||||||
/* DTLS data policy */
|
/* DTLS data policy */
|
||||||
g_wtp.dtlsdatapolicy = acdescriptor->dtlspolicy & g_wtp.validdtlsdatapolicy;
|
g_wtp.dtlsdatapolicy = acdescriptor->dtlspolicy & g_wtp.validdtlsdatapolicy;
|
||||||
|
|
||||||
/* Send configuration packet */
|
/* Binding values */
|
||||||
wtp_send_configure(timeout);
|
if (!wtp_radio_setconfiguration(packet)) {
|
||||||
|
wtp_send_configure(timeout); /* Send configuration packet */
|
||||||
|
} else {
|
||||||
|
capwap_logging_warning("Receive Join Response with invalid elements");
|
||||||
|
wtp_teardown_connection(timeout);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
capwap_logging_warning("Receive Join Response with invalid DTLS data policy");
|
capwap_logging_warning("Receive Join Response with invalid DTLS data policy");
|
||||||
wtp_teardown_connection(timeout);
|
wtp_teardown_connection(timeout);
|
||||||
|
@ -8,7 +8,7 @@ void wtp_create_radioopsstate_element(struct capwap_packet_txmng* txmngpacket) {
|
|||||||
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
||||||
struct capwap_radiooprstate_element radiooprstate;
|
struct capwap_radiooprstate_element radiooprstate;
|
||||||
|
|
||||||
radiooprstate.radioid = (unsigned char)(i + 1);
|
radiooprstate.radioid = radio->radioid;
|
||||||
radiooprstate.state = ((radio->status == WTP_RADIO_ENABLED) ? CAPWAP_RADIO_OPERATIONAL_STATE_ENABLED : CAPWAP_RADIO_OPERATIONAL_STATE_DISABLED);
|
radiooprstate.state = ((radio->status == WTP_RADIO_ENABLED) ? CAPWAP_RADIO_OPERATIONAL_STATE_ENABLED : CAPWAP_RADIO_OPERATIONAL_STATE_DISABLED);
|
||||||
|
|
||||||
if (radio->status == WTP_RADIO_ENABLED) {
|
if (radio->status == WTP_RADIO_ENABLED) {
|
||||||
@ -36,7 +36,7 @@ void wtp_create_radioadmstate_element(struct capwap_packet_txmng* txmngpacket) {
|
|||||||
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
struct wtp_radio* radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, i);
|
||||||
struct capwap_radioadmstate_element radioadmstate;
|
struct capwap_radioadmstate_element radioadmstate;
|
||||||
|
|
||||||
radioadmstate.radioid = (unsigned char)(i + 1);
|
radioadmstate.radioid = radio->radioid;
|
||||||
radioadmstate.state = ((radio->status == WTP_RADIO_DISABLED) ? CAPWAP_RADIO_ADMIN_STATE_DISABLED : CAPWAP_RADIO_ADMIN_STATE_ENABLED);
|
radioadmstate.state = ((radio->status == WTP_RADIO_DISABLED) ? CAPWAP_RADIO_ADMIN_STATE_DISABLED : CAPWAP_RADIO_ADMIN_STATE_ENABLED);
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RADIOADMSTATE, &radioadmstate);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RADIOADMSTATE, &radioadmstate);
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ void wtp_create_80211_wtpradioinformation_element(struct capwap_packet_txmng* tx
|
|||||||
memcpy(&element, &radio->radioinformation, sizeof(struct capwap_80211_wtpradioinformation_element));
|
memcpy(&element, &radio->radioinformation, sizeof(struct capwap_80211_wtpradioinformation_element));
|
||||||
} else {
|
} else {
|
||||||
memset(&element, 0, sizeof(struct capwap_80211_wtpradioinformation_element));
|
memset(&element, 0, sizeof(struct capwap_80211_wtpradioinformation_element));
|
||||||
element.radioid = (uint8_t)radio->radioid;
|
element.radioid = radio->radioid;
|
||||||
}
|
}
|
||||||
|
|
||||||
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION, &element);
|
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION, &element);
|
||||||
|
@ -1,8 +1,436 @@
|
|||||||
#include "wtp.h"
|
#include "wtp.h"
|
||||||
#include "wtp_radio.h"
|
#include "wtp_radio.h"
|
||||||
|
|
||||||
|
/* */
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void wtp_radio_init(void) {
|
||||||
|
g_wtp.radios = capwap_array_create(sizeof(struct wtp_radio), 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void wtp_radio_close(void) {
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
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) {
|
||||||
|
for (j = 0; j < radio->wlan->count; j++) {
|
||||||
|
wtp_radio_destroy_wlan((struct wtp_radio_wlan*)capwap_array_get_item_pointer(radio->wlan, j));
|
||||||
|
}
|
||||||
|
|
||||||
|
capwap_array_free(radio->wlan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
capwap_array_resize(g_wtp.radios, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void wtp_radio_free(void) {
|
||||||
|
ASSERT(g_wtp.radios != NULL);
|
||||||
|
ASSERT(g_wtp.radios->count == 0);
|
||||||
|
|
||||||
|
capwap_array_free(g_wtp.radios);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet) {
|
||||||
|
int i;
|
||||||
|
unsigned short binding;
|
||||||
|
struct wtp_radio* radio;
|
||||||
|
struct capwap_array* messageelements;
|
||||||
|
|
||||||
|
ASSERT(packet != NULL);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
|
||||||
|
if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
|
||||||
|
struct capwap_list_item* 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_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)) {
|
||||||
|
memcpy(&radio->directsequencecontrol, directsequencecontrol, sizeof(struct capwap_80211_directsequencecontrol_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 && (radio->radioid == ofdmcontrol->radioid)) {
|
||||||
|
memcpy(&radio->ofdmcontrol, ofdmcontrol, sizeof(struct capwap_80211_ofdmcontrol_element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Next */
|
||||||
|
search = search->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
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 */
|
||||||
|
radio->wlan = capwap_array_create(sizeof(struct wtp_radio_wlan), 0, 1);
|
||||||
|
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;
|
||||||
|
|
||||||
|
ASSERT(IS_VALID_RADIOID(radioid));
|
||||||
|
|
||||||
|
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) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ASSERT(IS_VALID_WLANID(wlanid));
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
return wlan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid) {
|
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid) {
|
||||||
|
uint32_t band;
|
||||||
|
uint8_t channel;
|
||||||
|
struct wtp_radio* radio;
|
||||||
|
struct wtp_radio_wlan* wlan;
|
||||||
|
struct capwap_80211_addwlan_element* addwlan;
|
||||||
|
struct capwap_array* ies;
|
||||||
|
|
||||||
|
/* Get message elements */
|
||||||
|
addwlan = (struct capwap_80211_addwlan_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_80211_ADD_WLAN);
|
||||||
|
ies = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_80211_IE);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepare physical interface for create wlan */
|
||||||
|
if (!radio->wlan->count) {
|
||||||
|
if (wtp_radio_configure_phy(radio)) {
|
||||||
|
return CAPWAP_RESULTCODE_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set radio channel */
|
||||||
|
band = ((radio->radioid == radio->directsequencecontrol.radioid) ? WIFI_BAND_2GHZ : WIFI_BAND_5GHZ);
|
||||||
|
channel = ((radio->radioid == radio->directsequencecontrol.radioid) ? radio->directsequencecontrol.currentchannel : radio->ofdmcontrol.currentchannel);
|
||||||
|
if (wifi_device_setfrequency(addwlan->radioid, band, radio->radioinformation.radiotype, channel)) {
|
||||||
|
return CAPWAP_RESULTCODE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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(wlan->wlanname, "%s%02d.%02d", g_wtp.wlanprefix, (int)addwlan->radioid, (int)addwlan->wlanid);
|
||||||
|
if (wifi_iface_index(wlan->wlanname)) {
|
||||||
|
memset(wlan, 0, sizeof(struct wtp_radio_wlan));
|
||||||
|
return CAPWAP_RESULTCODE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create virtual interface */
|
||||||
|
if (!wifi_wlan_create(addwlan->radioid, addwlan->wlanid, wlan->wlanname, NULL)) {
|
||||||
|
wlan->state = WTP_RADIO_WLAN_STATE_CREATED;
|
||||||
|
} else {
|
||||||
|
wtp_radio_destroy_wlan(wlan);
|
||||||
|
return CAPWAP_RESULTCODE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Configure virtual interface */
|
||||||
|
if (!wifi_wlan_setupap(addwlan, ies)) {
|
||||||
|
wlan->state = WTP_RADIO_WLAN_STATE_READY;
|
||||||
|
} else {
|
||||||
|
wtp_radio_destroy_wlan(wlan);
|
||||||
|
return CAPWAP_RESULTCODE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start AP */
|
||||||
|
if (!wifi_wlan_startap(addwlan->radioid, addwlan->wlanid)) {
|
||||||
|
wlan->state = WTP_RADIO_WLAN_STATE_AP;
|
||||||
|
} else {
|
||||||
|
wtp_radio_destroy_wlan(wlan);
|
||||||
|
return CAPWAP_RESULTCODE_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* */
|
||||||
|
bssid->radioid = addwlan->radioid;
|
||||||
|
bssid->wlanid = addwlan->wlanid;
|
||||||
|
wifi_wlan_getbssid(addwlan->radioid, addwlan->wlanid, bssid->bssid);
|
||||||
|
|
||||||
return CAPWAP_RESULTCODE_SUCCESS;
|
return CAPWAP_RESULTCODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,28 +1,65 @@
|
|||||||
#ifndef __WTP_RADIO_HEADER__
|
#ifndef __WTP_RADIO_HEADER__
|
||||||
#define __WTP_RADIO_HEADER__
|
#define __WTP_RADIO_HEADER__
|
||||||
|
|
||||||
|
/* */
|
||||||
#define WTP_RADIO_ENABLED 0
|
#define WTP_RADIO_ENABLED 0
|
||||||
#define WTP_RADIO_DISABLED 1
|
#define WTP_RADIO_DISABLED 1
|
||||||
#define WTP_RADIO_HWFAILURE 2
|
#define WTP_RADIO_HWFAILURE 2
|
||||||
#define WTP_RADIO_SWFAILURE 3
|
#define WTP_RADIO_SWFAILURE 3
|
||||||
|
|
||||||
|
/* */
|
||||||
|
#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_READY 2
|
||||||
|
#define WTP_RADIO_WLAN_STATE_AP 3
|
||||||
|
|
||||||
|
struct wtp_radio_wlan {
|
||||||
|
struct wtp_radio* radio;
|
||||||
|
|
||||||
|
uint8_t wlanid;
|
||||||
|
char wlanname[IFNAMSIZ];
|
||||||
|
|
||||||
|
int state;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
struct wtp_radio {
|
struct wtp_radio {
|
||||||
int radioid;
|
uint8_t radioid;
|
||||||
char device[IFNAMSIZ];
|
char device[IFNAMSIZ];
|
||||||
|
|
||||||
|
struct capwap_array* wlan;
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
struct capwap_80211_antenna_element antenna;
|
struct capwap_80211_antenna_element antenna;
|
||||||
struct capwap_80211_directsequencecontrol_element directsequencecontrol;
|
struct capwap_80211_directsequencecontrol_element directsequencecontrol;
|
||||||
struct capwap_80211_macoperation_element macoperation;
|
struct capwap_80211_macoperation_element macoperation;
|
||||||
struct capwap_80211_multidomaincapability_element multidomaincapability;
|
struct capwap_80211_multidomaincapability_element multidomaincapability;
|
||||||
struct capwap_80211_ofdmcontrol_element ofdmcontrol;
|
struct capwap_80211_ofdmcontrol_element ofdmcontrol;
|
||||||
|
struct capwap_80211_rateset_element rateset;
|
||||||
struct capwap_80211_supportedrates_element supportedrates;
|
struct capwap_80211_supportedrates_element supportedrates;
|
||||||
struct capwap_80211_txpower_element txpower;
|
struct capwap_80211_txpower_element txpower;
|
||||||
struct capwap_80211_txpowerlevel_element txpowerlevel;
|
struct capwap_80211_txpowerlevel_element txpowerlevel;
|
||||||
struct capwap_80211_wtpradioconf_element radioconfig;
|
struct capwap_80211_wtpradioconf_element radioconfig;
|
||||||
struct capwap_80211_wtpradioinformation_element radioinformation;
|
struct capwap_80211_wtpradioinformation_element radioinformation;
|
||||||
|
struct capwap_80211_wtpqos_element qos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* */
|
||||||
|
void wtp_radio_init(void);
|
||||||
|
void wtp_radio_close(void);
|
||||||
|
void wtp_radio_free(void);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
struct wtp_radio* wtp_radio_create_phy(void);
|
||||||
|
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 wtp_radio_setconfiguration(struct capwap_parsed_packet* packet);
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid);
|
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid);
|
||||||
uint32_t wtp_radio_update_wlan(struct capwap_parsed_packet* packet);
|
uint32_t wtp_radio_update_wlan(struct capwap_parsed_packet* packet);
|
||||||
|
Loading…
Reference in New Issue
Block a user