Change the location of binding file.

This commit is contained in:
vemax78
2014-04-15 16:45:39 +02:00
parent 3569267283
commit 3e06393469
11 changed files with 8 additions and 7 deletions

View File

@ -1,634 +0,0 @@
#include "capwap.h"
#include "ieee80211.h"
/* */
static int ieee80211_ie_set_ssid(uint8_t* 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 = 0;
} else {
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 ieee80211_ie_set_supportedrates(uint8_t* buffer, uint8_t* supportedrates, int supportedratescount) {
int i;
int count;
struct ieee80211_ie_supported_rates* iesupportedrates = (struct ieee80211_ie_supported_rates*)buffer;
ASSERT(buffer != NULL);
ASSERT(supportedrates != NULL);
ASSERT(supportedratescount > 0);
/* IE accept max only 8 rate */
count = supportedratescount;
if (count > 8) {
count = 8;
}
/* */
iesupportedrates->id = IEEE80211_IE_SUPPORTED_RATES;
iesupportedrates->len = count;
for (i = 0; i < count; i++) {
iesupportedrates->rates[i] = supportedrates[i];
}
return sizeof(struct ieee80211_ie_supported_rates) + iesupportedrates->len;
}
/* */
static int ieee80211_ie_set_extendedsupportedrates(uint8_t* buffer, uint8_t* supportedrates, int supportedratescount) {
int i, j;
struct ieee80211_ie_extended_supported_rates* ieextendedsupportedrates = (struct ieee80211_ie_extended_supported_rates*)buffer;
ASSERT(buffer != NULL);
ASSERT(supportedrates != NULL);
/* IE accept only > 8 rate */
if (supportedratescount <= IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH) {
return 0;
}
/* */
ieextendedsupportedrates->id = IEEE80211_IE_EXTENDED_SUPPORTED_RATES;
ieextendedsupportedrates->len = supportedratescount - IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH;
for (i = IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH, j = 0; i < supportedratescount; i++, j++) {
ieextendedsupportedrates->rates[j] = supportedrates[i];
}
return sizeof(struct ieee80211_ie_extended_supported_rates) + ieextendedsupportedrates->len;
}
/* */
static int ieee80211_ie_set_dsss(uint8_t* buffer, uint8_t channel) {
struct ieee80211_ie_dsss* iedsss = (struct ieee80211_ie_dsss*)buffer;
ASSERT(buffer != NULL);
iedsss->id = IEEE80211_IE_DSSS;
iedsss->len = IEEE80211_IE_DSSS_LENGTH;
iedsss->channel = channel;
return sizeof(struct ieee80211_ie_dsss);
}
/* */
static int ieee80211_ie_set_erp(uint8_t* buffer, uint32_t mode, uint8_t erpinfo) {
struct ieee80211_ie_erp* ieerp = (struct ieee80211_ie_erp*)buffer;
ASSERT(buffer != NULL);
if (!(mode & IEEE80211_RADIO_TYPE_80211G)) {
return 0;
}
ieerp->id = IEEE80211_IE_ERP;
ieerp->len = IEEE80211_IE_ERP_LENGTH;
ieerp->params = erpinfo;
return sizeof(struct ieee80211_ie_erp);
}
/* */
int ieee80211_retrieve_information_elements_position(struct ieee80211_ie_items* items, const uint8_t* data, int length) {
ASSERT(items != NULL);
ASSERT(data != NULL);
/* */
memset(items, 0, sizeof(struct ieee80211_ie_items));
/* Parsing */
while (length >= 2) {
uint8_t ie_id = data[0];
uint8_t ie_len = data[1];
/* Parsing Information Element */
switch (ie_id) {
case IEEE80211_IE_SSID: {
if (ie_len > IEEE80211_IE_SSID_MAX_LENGTH) {
return -1;
}
items->ssid = (struct ieee80211_ie_ssid*)data;
break;
}
case IEEE80211_IE_SUPPORTED_RATES: {
if ((ie_len < IEEE80211_IE_SUPPORTED_RATES_MIN_LENGTH) || (ie_len > IEEE80211_IE_SUPPORTED_RATES_MAX_LENGTH)) {
return -1;
}
items->supported_rates = (struct ieee80211_ie_supported_rates*)data;
break;
}
case IEEE80211_IE_DSSS: {
if (ie_len != IEEE80211_IE_DSSS_LENGTH) {
return -1;
}
items->dsss = (struct ieee80211_ie_dsss*)data;
break;
}
case IEEE80211_IE_COUNTRY: {
if (ie_len < IEEE80211_IE_COUNTRY_MIN_LENGTH) {
return -1;
}
items->country = (struct ieee80211_ie_country*)data;
break;
}
case IEEE80211_IE_CHALLENGE_TEXT: {
if (ie_len < IEEE80211_IE_CHALLENGE_TEXT_MIN_LENGTH) {
return -1;
}
items->challenge_text = (struct ieee80211_ie_challenge_text*)data;
break;
}
case IEEE80211_IE_ERP: {
if (ie_len != IEEE80211_IE_ERP_LENGTH) {
return -1;
}
items->erp = (struct ieee80211_ie_erp*)data;
break;
}
case IEEE80211_IE_EXTENDED_SUPPORTED_RATES: {
if (ie_len < IEEE80211_IE_EXTENDED_SUPPORTED_MIN_LENGTH) {
return -1;
}
items->extended_supported_rates = (struct ieee80211_ie_extended_supported_rates*)data;
break;
}
case IEEE80211_IE_EDCA_PARAMETER_SET: {
if (ie_len != IEEE80211_IE_EDCA_PARAMETER_SET_LENGTH) {
return -1;
}
items->edca_parameter_set = (struct ieee80211_ie_edca_parameter_set*)data;
break;
}
case IEEE80211_IE_QOS_CAPABILITY: {
if (ie_len != IEEE80211_IE_QOS_CAPABILITY_LENGTH) {
return -1;
}
items->qos_capability = (struct ieee80211_ie_qos_capability*)data;
break;
}
case IEEE80211_IE_POWER_CONSTRAINT: {
if (ie_len != IEEE80211_IE_POWER_CONSTRAINT_LENGTH) {
return -1;
}
items->power_constraint = (struct ieee80211_ie_power_constraint*)data;
break;
}
case IEEE80211_IE_SSID_LIST: {
items->ssid_list = (struct ieee80211_ie_ssid_list*)data;
break;
}
}
/* Next Information Element */
data += sizeof(struct ieee80211_ie) + ie_len;
length -= sizeof(struct ieee80211_ie) + ie_len;
}
return (!length ? 0 : -1);
}
/* */
int ieee80211_aid_create(uint32_t* aidbitfield, uint16_t* aid) {
int i, j;
ASSERT(aidbitfield != NULL);
ASSERT(aid != NULL);
/* Search free aid bitfield */
for (i = 0; i < IEEE80211_AID_BITFIELD_SIZE; i++) {
if (aidbitfield[i] != 0xffffffff) {
uint32_t bitfield = aidbitfield[i];
/* Search free bit */
for (j = 0; j < 32; j++) {
if (!(bitfield & (1 << j))) {
*aid = i * 32 + j + 1;
if (*aid <= IEEE80211_AID_MAX_VALUE) {
aidbitfield[i] |= (1 << j);
return 0;
}
break;
}
}
break;
}
}
*aid = 0;
return -1;
}
/* */
void ieee80211_aid_free(uint32_t* aidbitfield, uint16_t aid) {
ASSERT(aidbitfield != NULL);
ASSERT((aid > 0) && (aid <= IEEE80211_AID_MAX_VALUE));
aidbitfield[(aid - 1) / 32] &= ~(1 << ((aid - 1) % 32));
}
/* */
unsigned long ieee80211_frequency_to_channel(uint32_t freq) {
if ((freq >= 2412) && (freq <= 2472)) {
return (freq - 2407) / 5;
} else if (freq == 2484) {
return 14;
} else if ((freq >= 4915) && (freq <= 4980)) {
return (freq - 4000) / 5;
} else if ((freq >= 5035) && (freq <= 5825)) {
return (freq - 5000) / 5;
}
return 0;
}
/* */
int ieee80211_is_broadcast_addr(const uint8_t* addr) {
return (((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) && (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff)) ? 1 : 0);
}
/* */
int ieee80211_is_valid_ssid(const char* ssid, struct ieee80211_ie_ssid* iessid, struct ieee80211_ie_ssid_list* isssidlist) {
int ssidlength;
ASSERT(ssid != NULL);
if (!iessid) {
return IEEE80211_WRONG_SSID;
}
/* Check SSID */
ssidlength = strlen((char*)ssid);
if ((ssidlength == iessid->len) && !memcmp(ssid, iessid->ssid, ssidlength)) {
return IEEE80211_VALID_SSID;
}
/* Check SSID list */
if (isssidlist) {
int length = isssidlist->len;
uint8_t* pos = isssidlist->lists;
while (length >= sizeof(struct ieee80211_ie)) {
struct ieee80211_ie_ssid* ssiditem = (struct ieee80211_ie_ssid*)pos;
/* Check buffer */
length -= sizeof(struct ieee80211_ie);
if ((ssiditem->id != IEEE80211_IE_SSID) || !ssiditem->len || (length < ssiditem->len)) {
break;
} else if ((ssidlength == ssiditem->len) && !memcmp(ssid, ssiditem->ssid, ssidlength)) {
return IEEE80211_VALID_SSID;
}
/* Next */
length -= ssiditem->len;
pos += sizeof(struct ieee80211_ie) + ssiditem->len;
}
}
return (!iessid->len ? IEEE80211_WILDCARD_SSID : IEEE80211_WRONG_SSID);
}
/* */
uint8_t ieee80211_get_erpinfo(uint32_t mode, int olbc, unsigned long stationnonerpcount, unsigned long stationnoshortpreamblecount, int shortpreamble) {
uint8_t result = 0;
/* Erp mode is valid only in IEEE 802.11 g*/
if (mode & IEEE80211_RADIO_TYPE_80211G) {
if (olbc) {
result |= IEEE80211_ERP_INFO_USE_PROTECTION;
}
if (stationnonerpcount > 0) {
result |= (IEEE80211_ERP_INFO_NON_ERP_PRESENT | IEEE80211_ERP_INFO_USE_PROTECTION);
}
if (!shortpreamble || (stationnoshortpreamblecount > 0)) {
result |= IEEE80211_ERP_INFO_BARKER_PREAMBLE_MODE;
}
}
return result;
}
/* */
int ieee80211_create_beacon(uint8_t* buffer, int length, struct ieee80211_beacon_params* params) {
int result;
uint8_t* pos;
struct ieee80211_header_mgmt* header;
ASSERT(buffer != NULL);
/* */
header = (struct ieee80211_header_mgmt*)buffer;
params->headbeacon = buffer;
/* Management header frame */
header->framecontrol = IEEE80211_FRAME_CONTROL(IEEE80211_FRAMECONTROL_TYPE_MGMT, IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_BEACON);
header->durationid = __cpu_to_le16(0);
memset(header->da, 0xff, ETH_ALEN);
memcpy(header->sa, params->bssid, ETH_ALEN);
memcpy(header->bssid, params->bssid, ETH_ALEN);
header->sequencecontrol = __cpu_to_le16(0);
memset(header->beacon.timestamp, 0, sizeof(header->beacon.timestamp));
header->beacon.beaconinterval = __cpu_to_le16(params->beaconperiod);
header->beacon.capability = __cpu_to_le16(params->capability);
/* Header frame size */
params->headbeaconlength = (int)((uint8_t*)&header->beacon.ie[0] - (uint8_t*)header);
pos = buffer + params->headbeaconlength;
/* Information Element: SSID */
result = ieee80211_ie_set_ssid(pos, params->ssid, (params->ssid_hidden ? 1 : 0));
if (result < 0) {
return -1;
}
pos += result;
params->headbeaconlength += result;
/* Information Element: Supported Rates */
result = ieee80211_ie_set_supportedrates(pos, params->supportedrates, params->supportedratescount);
if (result < 0) {
return -1;
}
pos += result;
params->headbeaconlength += result;
/* Information Element: DSSS */
result = ieee80211_ie_set_dsss(pos, params->channel);
if (result < 0) {
return -1;
}
pos += result;
params->headbeaconlength += result;
/* Separate Information Elements into two block between IE TIM */
params->tailbeacon = pos;
params->tailbeaconlength = 0;
/* Information Element: Country */
/* TODO */
/* Information Element: ERP */
result = ieee80211_ie_set_erp(pos, params->mode, params->erpinfo);
if (result < 0) {
return -1;
}
pos += result;
params->tailbeaconlength += result;
/* Information Element: Extended Supported Rates */
result = ieee80211_ie_set_extendedsupportedrates(pos, params->supportedrates, params->supportedratescount);
if (result < 0) {
return -1;
}
pos += result;
params->tailbeaconlength += result;
/* Probe Response offload */
if (params->flags & IEEE80221_CREATE_BEACON_FLAGS_PROBE_RESPONSE_OFFLOAD) {
struct ieee80211_probe_response_params proberesponseparams;
/* */
memset(&proberesponseparams, 0, sizeof(struct ieee80211_probe_response_params));
memcpy(proberesponseparams.bssid, params->bssid, ETH_ALEN);
proberesponseparams.beaconperiod = params->beaconperiod;
proberesponseparams.capability = params->capability;
proberesponseparams.ssid = params->ssid;
memcpy(proberesponseparams.supportedrates, params->supportedrates, params->supportedratescount);
proberesponseparams.supportedratescount = params->supportedratescount;
proberesponseparams.mode = params->mode;
proberesponseparams.erpinfo = params->erpinfo;
proberesponseparams.channel = params->channel;
/* */
params->proberesponseoffload = pos;
params->proberesponseoffloadlength = ieee80211_create_probe_response(pos, (int)(pos - buffer), &proberesponseparams);
if (params->proberesponseoffloadlength < 0) {
return -1;
}
/* */
pos += params->proberesponseoffloadlength;
}
return (int)(pos - buffer);
}
/* */
int ieee80211_create_probe_response(uint8_t* buffer, int length, struct ieee80211_probe_response_params* params) {
int result;
uint8_t* pos;
int responselength;
struct ieee80211_header_mgmt* header;
ASSERT(buffer != NULL);
/* */
header = (struct ieee80211_header_mgmt*)buffer;
/* Management header frame */
header->framecontrol = IEEE80211_FRAME_CONTROL(IEEE80211_FRAMECONTROL_TYPE_MGMT, IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_PROBE_RESPONSE);
header->durationid = __cpu_to_le16(0);
memcpy(header->da, params->station, ETH_ALEN);
memcpy(header->sa, params->bssid, ETH_ALEN);
memcpy(header->bssid, params->bssid, ETH_ALEN);
header->sequencecontrol = __cpu_to_le16(0);
memset(header->proberesponse.timestamp, 0, sizeof(header->proberesponse.timestamp));
header->proberesponse.beaconinterval = __cpu_to_le16(params->beaconperiod);
header->proberesponse.capability = __cpu_to_le16(params->capability);
/* Header frame size */
responselength = (int)((uint8_t*)&header->proberesponse.ie[0] - (uint8_t*)header);
pos = buffer + responselength;
/* Information Element: SSID */
result = ieee80211_ie_set_ssid(pos, params->ssid, 0);
if (result < 0) {
return -1;
}
pos += result;
responselength += result;
/* Information Element: Supported Rates */
result = ieee80211_ie_set_supportedrates(pos, params->supportedrates, params->supportedratescount);
if (result < 0) {
return -1;
}
pos += result;
responselength += result;
/* Information Element: DSSS */
result = ieee80211_ie_set_dsss(pos, params->channel);
if (result < 0) {
return -1;
}
pos += result;
responselength += result;
/* Information Element: Country */
/* TODO */
/* Information Element: ERP */
result = ieee80211_ie_set_erp(pos, params->mode, params->erpinfo);
if (result < 0) {
return -1;
}
pos += result;
responselength += result;
/* Information Element: Extended Supported Rates */
result = ieee80211_ie_set_extendedsupportedrates(pos, params->supportedrates, params->supportedratescount);
if (result < 0) {
return -1;
}
pos += result;
responselength += result;
return responselength;
}
/* */
int ieee80211_create_authentication_response(uint8_t* buffer, int length, struct ieee80211_authentication_params* params) {
int responselength;
struct ieee80211_header_mgmt* header;
ASSERT(buffer != NULL);
/* */
header = (struct ieee80211_header_mgmt*)buffer;
/* Management header frame */
header->framecontrol = IEEE80211_FRAME_CONTROL(IEEE80211_FRAMECONTROL_TYPE_MGMT, IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_AUTHENTICATION);
header->durationid = __cpu_to_le16(0);
memcpy(header->da, params->station, ETH_ALEN);
memcpy(header->sa, params->bssid, ETH_ALEN);
memcpy(header->bssid, params->bssid, ETH_ALEN);
header->sequencecontrol = __cpu_to_le16(0);
header->authetication.algorithm = __cpu_to_le16(params->algorithm);
header->authetication.transactionseqnumber = __cpu_to_le16(params->transactionseqnumber);
header->authetication.statuscode = __cpu_to_le16(params->statuscode);
/* Header frame size */
responselength = (int)((uint8_t*)&header->authetication.ie[0] - (uint8_t*)header);
/* TODO: add custon IE */
return responselength;
}
/* */
int ieee80211_create_associationresponse_response(uint8_t* buffer, int length, struct ieee80211_associationresponse_params* params) {
uint8_t* pos;
int result;
int responselength;
struct ieee80211_header_mgmt* header;
ASSERT(buffer != NULL);
/* */
header = (struct ieee80211_header_mgmt*)buffer;
/* Management header frame */
header->framecontrol = IEEE80211_FRAME_CONTROL(IEEE80211_FRAMECONTROL_TYPE_MGMT, IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ASSOCIATION_RESPONSE);
header->durationid = __cpu_to_le16(0);
memcpy(header->da, params->station, ETH_ALEN);
memcpy(header->sa, params->bssid, ETH_ALEN);
memcpy(header->bssid, params->bssid, ETH_ALEN);
header->sequencecontrol = __cpu_to_le16(0);
header->associationresponse.capability = __cpu_to_le16(params->capability);
header->associationresponse.statuscode = __cpu_to_le16(params->statuscode);
header->associationresponse.aid = __cpu_to_le16(params->aid);
/* Header frame size */
responselength = (int)((uint8_t*)&header->associationresponse.ie[0] - (uint8_t*)header);
pos = buffer + responselength;
/* Information Element: Supported Rates */
result = ieee80211_ie_set_supportedrates(pos, params->supportedrates, params->supportedratescount);
if (result < 0) {
return -1;
}
pos += result;
responselength += result;
/* Information Element: Extended Supported Rates */
result = ieee80211_ie_set_extendedsupportedrates(pos, params->supportedrates, params->supportedratescount);
if (result < 0) {
return -1;
}
pos += result;
responselength += result;
return responselength;
}
/* */
int ieee80211_create_deauthentication(uint8_t* buffer, int length, struct ieee80211_deauthentication_params* params) {
struct ieee80211_header_mgmt* header;
ASSERT(buffer != NULL);
/* */
header = (struct ieee80211_header_mgmt*)buffer;
/* Management header frame */
header->framecontrol = IEEE80211_FRAME_CONTROL(IEEE80211_FRAMECONTROL_TYPE_MGMT, IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_DEAUTHENTICATION);
header->durationid = __cpu_to_le16(0);
memcpy(header->da, params->station, ETH_ALEN);
memcpy(header->sa, params->bssid, ETH_ALEN);
memcpy(header->bssid, params->bssid, ETH_ALEN);
header->sequencecontrol = __cpu_to_le16(0);
header->deauthetication.reasoncode = __cpu_to_le16(params->reasoncode);
return (int)((uint8_t*)&header->deauthetication.ie[0] - (uint8_t*)header);
}

View File

@ -1,587 +0,0 @@
#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 7981
#define IEEE80211_SUPPORTEDRATE_MAX_COUNT 16
#define IEEE80211_MAX_STATIONS 2007
/* Radio type with value same of IEEE802.11 Radio Information Message Element */
#define IEEE80211_RADIO_TYPE_80211B 0x00000001
#define IEEE80211_RADIO_TYPE_80211A 0x00000002
#define IEEE80211_RADIO_TYPE_80211G 0x00000004
#define IEEE80211_RADIO_TYPE_80211N 0x00000008
/* */
#define IS_IEEE80211_FREQ_BG(x) (((x >= 2412) && (x <= 2484)) ? 1 : 0)
#define IS_IEEE80211_FREQ_A(x) ((((x >= 4915) && (x <= 4980)) || ((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)
#define IEEE80211_BASICRATE 128
#define IS_IEEE80211_BASICRATE_B(x) ((x == IEEE80211_RATE_1M) || (x == IEEE80211_RATE_2M))
#define IS_IEEE80211_BASICRATE_G(x) ((x == IEEE80211_RATE_1M) || (x == IEEE80211_RATE_2M) || (x == IEEE80211_RATE_5_5M) || (x == IEEE80211_RATE_11M))
#define IS_IEEE80211_BASICRATE_A(x) ((x == IEEE80211_RATE_6M) || (x == IEEE80211_RATE_12M) || (x == IEEE80211_RATE_24M))
/* 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_ASSOCIATION_REQUEST 0
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ASSOCIATION_RESPONSE 1
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_REASSOCIATION_REQUEST 2
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_REASSOCIATION_RESPONSE 3
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_PROBE_REQUEST 4
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_PROBE_RESPONSE 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_DISASSOCIATION 10
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_AUTHENTICATION 11
#define IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_DEAUTHENTICATION 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))
#define IEEE80211_FRAME_CONTROL_GET_TYPE(framecontrol) (((framecontrol) & 0x000c) >> 2)
#define IEEE80211_FRAME_CONTROL_GET_SUBTYPE(framecontrol) (((framecontrol) & 0x00f0) >> 4)
/* IEEE802.11 Status Code */
#define IEEE80211_STATUS_SUCCESS 0
#define IEEE80211_STATUS_UNSPECIFIED_FAILURE 1
#define IEEE80211_STATUS_TDLS_WAKEUP_ALTERNATE 2
#define IEEE80211_STATUS_TDLS_WAKEUP_REJECT 3
#define IEEE80211_STATUS_SECURITY_DISABLED 5
#define IEEE80211_STATUS_UNACCEPTABLE_LIFETIME 6
#define IEEE80211_STATUS_NOT_IN_SAME_BSS 7
#define IEEE80211_STATUS_CAPS_UNSUPPORTED 10
#define IEEE80211_STATUS_REASSOCIATION_NO_ASSOCIATE 11
#define IEEE80211_STATUS_ASSOCIATION_DENIED_UNSPEC 12
#define IEEE80211_STATUS_NOT_SUPPORTED_AUTHENTICATION_ALGORITHM 13
#define IEEE80211_STATUS_UNKNOWN_AUTHENTICATION_TRANSACTION 14
#define IEEE80211_STATUS_CHALLENGE_FAIL 15
#define IEEE80211_STATUS_AUTHENTICATION_TIMEOUT 16
#define IEEE80211_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
#define IEEE80211_STATUS_ASSOCIATION_DENIED_RATES 18
#define IEEE80211_STATUS_ASSOCIATION_DENIED_NOSHORT 19
#define IEEE80211_STATUS_ASSOCIATION_DENIED_NOPBCC 20
#define IEEE80211_STATUS_ASSOCIATION_DENIED_NOAGILITY 21
#define IEEE80211_STATUS_SPEC_MGMT_REQUIRED 22
#define IEEE80211_STATUS_PWR_CAPABILITY_NOT_VALID 23
#define IEEE80211_STATUS_SUPPORTED_CHANNEL_NOT_VALID 24
#define IEEE80211_STATUS_ASSOCIATION_DENIED_NO_SHORT_SLOT_TIME 25
#define IEEE80211_STATUS_ASSOCIATION_DENIED_NO_DSSS_OFDM 26
#define IEEE80211_STATUS_ASSOCIATION_DENIED_NO_HT 27
#define IEEE80211_STATUS_R0KH_UNREACHABLE 28
#define IEEE80211_STATUS_ASSOCIATION_DENIED_NO_PCO 29
#define IEEE80211_STATUS_ASSOCIATION_REJECTED_TEMPORARILY 30
#define IEEE80211_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION 31
#define IEEE80211_STATUS_UNSPECIFIED_QOS_FAILURE 32
#define IEEE80211_STATUS_QOS_INSUFFICIENT_BANDWIDTH 33
#define IEEE80211_STATUS_EXCESSIVE_FRAME_LOST 34
#define IEEE80211_STATUS_STA_NOT_SUPPORT_QOS_FACILITY 35
#define IEEE80211_STATUS_REQUEST_DECLINED 37
#define IEEE80211_STATUS_INVALID_PARAMETERS 38
#define IEEE80211_STATUS_REJECTED_WITH_SUGGESTED_CHANGES 39
#define IEEE80211_STATUS_INVALID_IE 40
#define IEEE80211_STATUS_GROUP_CIPHER_NOT_VALID 41
#define IEEE80211_STATUS_PAIRWISE_CIPHER_NOT_VALID 42
#define IEEE80211_STATUS_AKMP_NOT_VALID 43
#define IEEE80211_STATUS_UNSUPPORTED_RSN_IE_VERSION 44
#define IEEE80211_STATUS_INVALID_RSN_IE_CAPAB 45
#define IEEE80211_STATUS_CIPHER_REJECTED_PER_POLICY 46
#define IEEE80211_STATUS_TS_NOT_CREATED 47
#define IEEE80211_STATUS_DIRECT_LINK_NOT_ALLOWED 48
#define IEEE80211_STATUS_DEST_STA_NOT_PRESENT 49
#define IEEE80211_STATUS_DEST_STA_NOT_QOS_STA 50
#define IEEE80211_STATUS_ASSOCIATION_DENIED_LISTEN_INT_TOO_LARGE 51
#define IEEE80211_STATUS_INVALID_FT_ACTION_FRAME_COUNT 52
#define IEEE80211_STATUS_INVALID_PMKID 53
#define IEEE80211_STATUS_INVALID_MDIE 54
#define IEEE80211_STATUS_INVALID_FTIE 55
#define IEEE80211_STATUS_REQUEST_TCLAS_NOT_SUPPORTED 56
#define IEEE80211_STATUS_INSUFFICIENT_TCLAS 57
#define IEEE80211_STATUS_TS_NOT_BEEN_CREATED 58
#define IEEE80211_STATUS_GAS_ADV_PROTO_NOT_SUPPORTED 59
#define IEEE80211_STATUS_NO_OUTSTANDING_GAS_REQ 60
#define IEEE80211_STATUS_GAS_RESP_NOT_RECEIVED 61
#define IEEE80211_STATUS_STA_TIMED_OUT_WAITING_FOR_GAS_RESP 62
#define IEEE80211_STATUS_GAS_RESP_LARGER_THAN_LIMIT 63
#define IEEE80211_STATUS_REQ_REFUSED_HOME 64
#define IEEE80211_STATUS_ADV_SRV_UNREACHABLE 65
#define IEEE80211_STATUS_REQ_REFUSED_SSPN 67
#define IEEE80211_STATUS_REQ_REFUSED_UNAUTH_ACCESS 68
#define IEEE80211_STATUS_INVALID_RSNIE 72
#define IEEE80211_STATUS_UAPSD_COEXISTENCE_NOT_SUPPORTED 73
#define IEEE80211_STATUS_REQUEST_UAPSD_COEXISTENCE_NOT_SUPPORTED 74
#define IEEE80211_STATUS_REQUEST_INTERVAL_NOT SUPPORTED 75
#define IEEE80211_STATUS_ANTI_CLOGGING_TOKEN_REQ 76
#define IEEE80211_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED 77
#define IEEE80211_STATUS_CANNOT_FIND_ALTERNATIVE_TBTT 78
#define IEEE80211_STATUS_TRANSMISSION_FAILURE 79
#define IEEE80211_STATUS_REQUYESTED_TCLAS_NOT_SUPPORTED 80
#define IEEE80211_STATUS_TCLAS_RESOURCES_EXHAUSTED 81
#define IEEE80211_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION 82
#define IEEE80211_STATUS_REFUSED_EXTERNAL_REASON 92
#define IEEE80211_STATUS_REFUSED_AP_OUT_OF_MEMORY 93
#define IEEE80211_STATUS_REJECTED_EMERGENCY_SERVICES_NOT_SUPPORTED 94
#define IEEE80211_STATUS_QUERY_RESPONSE_OUTSTANDING 95
#define IEEE80211_STATUS_MCCAOP_RESERVATION_CONFLICT 100
#define IEEE80211_STATUS_MAF_LIMIT_EXCEEDED 101
#define IEEE80211_STATUS_MCCA_TRACK_LIMIT_EXCEEDED 102
/* IEEE802.11 Reason code */
#define IEEE80211_REASON_UNSPECIFIED 1
#define IEEE80211_REASON_PREV_AUTH_NOT_VALID 2
#define IEEE80211_REASON_DEAUTH_LEAVING 3
#define IEEE80211_REASON_DISASSOC_DUE_TO_INACTIVITY 4
#define IEEE80211_REASON_DISASSOC_AP_BUSY 5
#define IEEE80211_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
#define IEEE80211_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
#define IEEE80211_REASON_DISASSOC_STA_HAS_LEFT 8
#define IEEE80211_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
#define IEEE80211_REASON_PWR_CAPABILITY_NOT_VALID 10
#define IEEE80211_REASON_SUPPORTED_CHANNEL_NOT_VALID 11
#define IEEE80211_REASON_INVALID_IE 13
#define IEEE80211_REASON_MICHAEL_MIC_FAILURE 14
#define IEEE80211_REASON_4WAY_HANDSHAKE_TIMEOUT 15
#define IEEE80211_REASON_GROUP_KEY_UPDATE_TIMEOUT 16
#define IEEE80211_REASON_IE_IN_4WAY_DIFFERS 17
#define IEEE80211_REASON_GROUP_CIPHER_NOT_VALID 18
#define IEEE80211_REASON_PAIRWISE_CIPHER_NOT_VALID 19
#define IEEE80211_REASON_AKMP_NOT_VALID 20
#define IEEE80211_REASON_UNSUPPORTED_RSN_IE_VERSION 21
#define IEEE80211_REASON_INVALID_RSN_IE_CAPAB 22
#define IEEE80211_REASON_IEEE_802_1X_AUTH_FAILED 23
#define IEEE80211_REASON_CIPHER_SUITE_REJECTED 24
#define IEEE80211_REASON_TDLS_TEARDOWN_UNREACHABLE 25
#define IEEE80211_REASON_TDLS_TEARDOWN_UNSPECIFIED 26
#define IEEE80211_REASON_DISASSOC_LOW_ACK 34
/* IEEE802.11 Authentication Algorithm */
#define IEEE80211_AUTHENTICATION_ALGORITHM_OPEN 0
#define IEEE80211_AUTHENTICATION_ALGORITHM_SHARED_KEY 1
#define IEEE80211_AUTHENTICATION_ALGORITHM_FAST_BSS 2
#define IEEE80211_AUTHENTICATION_ALGORITHM_SAE 3
/* */
#define IEEE80211_AID_FIELD 0xC000
#define IEEE80211_AID_MAX_VALUE 2007
/* */
#define IEEE80211_ERP_INFO_NON_ERP_PRESENT 0x01
#define IEEE80211_ERP_INFO_USE_PROTECTION 0x02
#define IEEE80211_ERP_INFO_BARKER_PREAMBLE_MODE 0x04
/* */
#define IEEE80211_CAPABILITY_ESS 0x0001
#define IEEE80211_CAPABILITY_IBSS 0x0002
#define IEEE80211_CAPABILITY_CFPOLLABLE 0x0004
#define IEEE80211_CAPABILITY_CFPOLLREQUEST 0x0008
#define IEEE80211_CAPABILITY_PRIVACY 0x0010
#define IEEE80211_CAPABILITY_SHORTPREAMBLE 0x0020
#define IEEE80211_CAPABILITY_PBCC 0x0040
#define IEEE80211_CAPABILITY_CHANNELAGILITY 0x0080
#define IEEE80211_CAPABILITY_SPECTRUMMAN 0x0100
#define IEEE80211_CAPABILITY_QOS 0x0200
#define IEEE80211_CAPABILITY_SHORTSLOTTIME 0x0400
#define IEEE80211_CAPABILITY_APSD 0x0800
#define IEEE80211_CAPABILITY_DSSS_OFDM 0x2000
#define IEEE80211_CAPABILITY_DELAYEDACK 0x4000
#define IEEE80211_CAPABILITY_IMMEDIATEACK 0x8000
/* 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;
union {
struct {
uint8_t timestamp[8];
__le16 beaconinterval;
__le16 capability;
uint8_t ie[0];
} STRUCT_PACKED beacon;
struct {
uint8_t ie[0];
} STRUCT_PACKED proberequest;
struct {
uint8_t timestamp[8];
__le16 beaconinterval;
__le16 capability;
uint8_t ie[0];
} STRUCT_PACKED proberesponse;
struct {
__le16 algorithm;
__le16 transactionseqnumber;
__le16 statuscode;
uint8_t ie[0];
} STRUCT_PACKED authetication;
struct {
__le16 capability;
__le16 listeninterval;
uint8_t ie[0];
} STRUCT_PACKED associationrequest;
struct {
__le16 capability;
__le16 statuscode;
__le16 aid;
uint8_t ie[0];
} STRUCT_PACKED associationresponse;
struct {
__le16 capability;
__le16 listeninterval;
uint8_t currentap[6];
uint8_t ie[0];
} STRUCT_PACKED reassociationrequest;
struct {
__le16 capability;
__le16 statuscode;
__le16 aid;
uint8_t ie[0];
} STRUCT_PACKED reassociationresponse;
struct {
__le16 reasoncode;
uint8_t ie[0];
} STRUCT_PACKED deauthetication;
struct {
__le16 reasoncode;
uint8_t ie[0];
} STRUCT_PACKED disassociation;
};
} 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_MIN_LENGTH 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
#define IEEE80211_IE_DSSS_LENGTH 1
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
#define IEEE80211_IE_COUNTRY_MIN_LENGTH 6
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 Challenge text information element */
#define IEEE80211_IE_CHALLENGE_TEXT 16
#define IEEE80211_IE_CHALLENGE_TEXT_MIN_LENGTH 3
struct ieee80211_ie_challenge_text {
uint8_t id;
uint8_t len;
uint8_t challengetext[0];
} STRUCT_PACKED;
/* 802.11 ERP information element */
#define IEEE80211_IE_ERP 42
#define IEEE80211_IE_ERP_LENGTH 1
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
#define IEEE80211_IE_EXTENDED_SUPPORTED_MIN_LENGTH 1
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 {
uint8_t id;
uint8_t len;
/* 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 {
uint8_t id;
uint8_t len;
/* TODO */
} STRUCT_PACKED;
/* 802.11 Power Constraint information element */
#define IEEE80211_IE_POWER_CONSTRAINT 32
#define IEEE80211_IE_POWER_CONSTRAINT_LENGTH 1
struct ieee80211_ie_power_constraint {
uint8_t id;
uint8_t len;
/* TODO */
} STRUCT_PACKED;
/* 802.11 SSID List */
#define IEEE80211_IE_SSID_LIST 84
struct ieee80211_ie_ssid_list {
uint8_t id;
uint8_t len;
uint8_t lists[0];
} STRUCT_PACKED;
/* 802.11 All information elements */
struct ieee80211_ie_items {
struct ieee80211_ie_ssid* ssid;
struct ieee80211_ie_supported_rates* supported_rates;
struct ieee80211_ie_dsss* dsss;
struct ieee80211_ie_country* country;
struct ieee80211_ie_challenge_text* challenge_text;
struct ieee80211_ie_erp* erp;
struct ieee80211_ie_extended_supported_rates* extended_supported_rates;
struct ieee80211_ie_edca_parameter_set* edca_parameter_set;
struct ieee80211_ie_qos_capability* qos_capability;
struct ieee80211_ie_power_constraint* power_constraint;
struct ieee80211_ie_ssid_list* ssid_list;
};
/* IEEE 802.11 functions */
uint8_t ieee80211_get_erpinfo(uint32_t mode, int olbc, unsigned long stationnonerpcount, unsigned long stationnoshortpreamblecount, int shortpreamble);
/* Management Beacon */
#define IEEE80221_CREATE_BEACON_FLAGS_PROBE_RESPONSE_OFFLOAD 0x00000001
struct ieee80211_beacon_params {
unsigned long flags;
uint8_t* headbeacon;
int headbeaconlength;
uint8_t* tailbeacon;
int tailbeaconlength;
uint8_t bssid[ETH_ALEN];
uint16_t beaconperiod;
uint16_t capability;
const char* ssid;
int ssid_hidden;
int supportedratescount;
uint8_t supportedrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
uint8_t channel;
uint32_t mode;
uint8_t erpinfo;
uint8_t* proberesponseoffload;
int proberesponseoffloadlength;
};
int ieee80211_create_beacon(uint8_t* buffer, int length, struct ieee80211_beacon_params* params);
/* Management Probe Response */
struct ieee80211_probe_response_params {
uint8_t bssid[ETH_ALEN];
uint8_t station[ETH_ALEN];
uint16_t beaconperiod;
uint16_t capability;
const char* ssid;
int supportedratescount;
uint8_t supportedrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
uint8_t channel;
uint32_t mode;
uint8_t erpinfo;
};
int ieee80211_create_probe_response(uint8_t* buffer, int length, struct ieee80211_probe_response_params* params);
/* Management Authentication */
struct ieee80211_authentication_params {
uint8_t bssid[ETH_ALEN];
uint8_t station[ETH_ALEN];
uint16_t algorithm;
uint16_t transactionseqnumber;
uint16_t statuscode;
};
int ieee80211_create_authentication_response(uint8_t* buffer, int length, struct ieee80211_authentication_params* params);
/* Management Association Response */
struct ieee80211_associationresponse_params {
uint8_t bssid[ETH_ALEN];
uint8_t station[ETH_ALEN];
uint16_t capability;
uint16_t statuscode;
uint16_t aid;
int supportedratescount;
uint8_t supportedrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
};
int ieee80211_create_associationresponse_response(uint8_t* buffer, int length, struct ieee80211_associationresponse_params* params);
/* Management Deauthentication */
struct ieee80211_deauthentication_params {
uint8_t bssid[ETH_ALEN];
uint8_t station[ETH_ALEN];
uint16_t reasoncode;
};
int ieee80211_create_deauthentication(uint8_t* buffer, int length, struct ieee80211_deauthentication_params* params);
/* Utils */
int ieee80211_retrieve_information_elements_position(struct ieee80211_ie_items* items, const uint8_t* data, int length);
unsigned long ieee80211_frequency_to_channel(uint32_t freq);
int ieee80211_is_broadcast_addr(const uint8_t* addr);
/* */
#define IEEE80211_VALID_SSID 1
#define IEEE80211_WILDCARD_SSID 0
#define IEEE80211_WRONG_SSID -1
int ieee80211_is_valid_ssid(const char* ssid, struct ieee80211_ie_ssid* iessid, struct ieee80211_ie_ssid_list* isssidlist);
/* IEEE802.11 Aid management */
#define IEEE80211_AID_BITFIELD_SIZE 63
int ieee80211_aid_create(uint32_t* aidbitfield, uint16_t* aid);
void ieee80211_aid_free(uint32_t* aidbitfield, uint16_t aid);
#endif /* __CAPWAP_IEEE802_11_HEADER__ */

View File

@ -1,154 +0,0 @@
#include "capwap.h"
#include <linux/socket.h>
#include "wifi_drivers.h"
#include "netlink_link.h"
/* */
struct netlink_request {
struct nlmsghdr hdr;
struct ifinfomsg ifinfo;
char opts[16];
};
/* */
struct netlink* netlink_init(void) {
int sock;
struct sockaddr_nl local;
struct netlink* netlinkhandle;
/* Create netlink socket */
sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock < 0) {
return NULL;
}
/* Bind to kernel */
memset(&local, 0, sizeof(struct sockaddr_nl));
local.nl_family = AF_NETLINK;
local.nl_groups = RTMGRP_LINK;
if (bind(sock, (struct sockaddr*)&local, sizeof(struct sockaddr_nl)) < 0) {
close(sock);
return NULL;
}
/* Netlink reference */
netlinkhandle = (struct netlink*)capwap_alloc(sizeof(struct netlink));
netlinkhandle->sock = sock;
netlinkhandle->nl_sequence = 1;
return netlinkhandle;
}
/* */
void netlink_free(struct netlink* netlinkhandle) {
ASSERT(netlinkhandle != NULL);
ASSERT(netlinkhandle->sock >= 0);
/* */
close(netlinkhandle->sock);
capwap_free(netlinkhandle);
}
/* */
void netlink_event_receive(int fd, void** params, int paramscount) {
int result;
struct netlink* netlinkhandle;
struct sockaddr_nl from;
socklen_t fromlen;
char buffer[8192];
struct nlmsghdr* message;
ASSERT(fd >= 0);
ASSERT(params != NULL);
ASSERT(paramscount == 2);
/* */
netlinkhandle = (struct netlink*)params[0];
/* Retrieve all netlink message */
for (;;) {
/* Get message */
fromlen = sizeof(struct sockaddr_nl);
result = recvfrom(netlinkhandle->sock, buffer, sizeof(buffer), MSG_DONTWAIT, (struct sockaddr*)&from, &fromlen);
if (result <= 0) {
if (errno == EINTR) {
continue;
}
/* */
break;
}
/* Parsing message */
message = (struct nlmsghdr*)buffer;
while (NLMSG_OK(message, result)) {
switch (message->nlmsg_type) {
case RTM_NEWLINK: {
if (netlinkhandle->newlink_event && NLMSG_PAYLOAD(message, 0) >= sizeof(struct ifinfomsg)) {
netlinkhandle->newlink_event((wifi_global_handle)params[1], NLMSG_DATA(message), (uint8_t*)(NLMSG_DATA(message) + NLMSG_ALIGN(sizeof(struct ifinfomsg))), NLMSG_PAYLOAD(message, sizeof(struct ifinfomsg)));
}
break;
}
case RTM_DELLINK: {
if (netlinkhandle->dellink_event && NLMSG_PAYLOAD(message, 0) >= sizeof(struct ifinfomsg)) {
netlinkhandle->dellink_event((wifi_global_handle)params[1], NLMSG_DATA(message), (uint8_t*)(NLMSG_DATA(message) + NLMSG_ALIGN(sizeof(struct ifinfomsg))), NLMSG_PAYLOAD(message, sizeof(struct ifinfomsg)));
}
break;
}
}
/* */
message = NLMSG_NEXT(message, result);
}
}
}
int netlink_set_link_status(struct netlink* netlinkhandle, int ifindex, int linkmode, int operstate) {
char* data;
struct rtattr* rta;
struct netlink_request request;
ASSERT(netlinkhandle != NULL);
ASSERT(ifindex >= 0);
/* */
memset(&request, 0, sizeof(struct netlink_request));
request.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
request.hdr.nlmsg_type = RTM_SETLINK;
request.hdr.nlmsg_flags = NLM_F_REQUEST;
request.hdr.nlmsg_seq = netlinkhandle->nl_sequence++;
request.hdr.nlmsg_pid = 0;
request.ifinfo.ifi_family = AF_UNSPEC;
request.ifinfo.ifi_type = 0;
request.ifinfo.ifi_index = ifindex;
request.ifinfo.ifi_flags = 0;
request.ifinfo.ifi_change = 0;
if (linkmode != -1) {
rta = (struct rtattr*)((char*)&request + NLMSG_ALIGN(request.hdr.nlmsg_len));
rta->rta_type = IFLA_LINKMODE;
rta->rta_len = RTA_LENGTH(sizeof(char));
data = (char*)RTA_DATA(rta);
*data = (char)linkmode;
request.hdr.nlmsg_len = NLMSG_ALIGN(request.hdr.nlmsg_len) + RTA_LENGTH(sizeof(char));
}
if (operstate != -1) {
rta = (struct rtattr*)((char*)&request + NLMSG_ALIGN(request.hdr.nlmsg_len));
rta->rta_type = IFLA_OPERSTATE;
rta->rta_len = RTA_LENGTH(sizeof(char));
data = (char*)RTA_DATA(rta);
*data = (char)operstate;
request.hdr.nlmsg_len = NLMSG_ALIGN(request.hdr.nlmsg_len) + RTA_LENGTH(sizeof(char));
}
/* Send new interface operation state */
if (send(netlinkhandle->sock, &request, request.hdr.nlmsg_len, 0) < 0) {
return -1;
}
return 0;
}

View File

@ -1,59 +0,0 @@
#ifndef __NETLINK_LINK_HEADER__
#define __NETLINK_LINK_HEADER__
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
/* */
#ifndef IFLA_IFNAME
#define IFLA_IFNAME 3
#endif
#ifndef IFLA_WIRELESS
#define IFLA_WIRELESS 11
#endif
#ifndef IFLA_OPERSTATE
#define IFLA_OPERSTATE 16
#endif
#ifndef IFLA_LINKMODE
#define IFLA_LINKMODE 17
#endif
#ifndef IF_OPER_DORMANT
#define IF_OPER_DORMANT 5
#endif
#ifndef IF_OPER_UP
#define IF_OPER_UP 6
#endif
#ifndef IFF_LOWER_UP
#define IFF_LOWER_UP 0x10000
#endif
#ifndef IFF_DORMANT
#define IFF_DORMANT 0x20000
#endif
/* */
struct netlink {
int sock;
void (*newlink_event)(wifi_global_handle handle, struct ifinfomsg* infomsg, uint8_t* data, int length);
void (*dellink_event)(wifi_global_handle handle, struct ifinfomsg* infomsg, uint8_t* data, int length);
int nl_sequence;
};
/* */
struct netlink* netlink_init(void);
void netlink_free(struct netlink* netlinkhandle);
/* */
int netlink_set_link_status(struct netlink* netlinkhandle, int ifindex, int linkmode, int operstate);
/* */
void netlink_event_receive(int fd, void** params, int paramscount);
#endif /* __NETLINK_LINK_HEADER__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,608 +0,0 @@
#include "capwap.h"
#include "capwap_list.h"
#include "capwap_element.h"
#include "wifi_drivers.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_list* g_wifidevice = NULL;
/* */
static void wifi_wlan_getrates(struct wifi_device* device, uint8_t* rates, int ratescount, struct device_setrates_params* device_params) {
int i, j, w;
int radiotype;
uint32_t mode = 0;
const struct wifi_capability* capability;
ASSERT(device != NULL);
ASSERT(rates != NULL);
ASSERT(ratescount > 0);
ASSERT(device_params != NULL);
/* */
memset(device_params, 0, sizeof(struct device_setrates_params));
/* Retrieve capability */
capability = wifi_device_getcapability(device);
if (!capability) {
return;
}
/* Get radio type for basic rate */
radiotype = wifi_frequency_to_radiotype(device->currentfreq.frequency);
if (radiotype < 0) {
return;
}
/* Check type of rate mode */
for (i = 0; i < ratescount; i++) {
if (device->currentfreq.band == WIFI_BAND_2GHZ) {
if (IS_IEEE80211_RATE_B(rates[i])) {
mode |= CAPWAP_RADIO_TYPE_80211B;
} else if (IS_IEEE80211_RATE_G(rates[i])) {
mode |= CAPWAP_RADIO_TYPE_80211G;
} else if (IS_IEEE80211_RATE_N(rates[i])) {
mode |= CAPWAP_RADIO_TYPE_80211N;
}
} else if (device->currentfreq.band == WIFI_BAND_5GHZ) {
if (IS_IEEE80211_RATE_A(rates[i])) {
mode |= CAPWAP_RADIO_TYPE_80211A;
} else if (IS_IEEE80211_RATE_N(rates[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_params->supportedrates[device_params->supportedratescount++] = IEEE80211_RATE_1M;
device_params->supportedrates[device_params->supportedratescount++] = IEEE80211_RATE_2M;
device_params->supportedrates[device_params->supportedratescount++] = IEEE80211_RATE_5_5M;
device_params->supportedrates[device_params->supportedratescount++] = IEEE80211_RATE_11M;
}
/* Filter band */
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->band == device->currentfreq.band) {
for (j = 0; j < bandcap->rate->count; j++) {
struct wifi_rate_capability* ratecapability = (struct wifi_rate_capability*)capwap_array_get_item_pointer(bandcap->rate, j);
/* Validate rate */
for (w = 0; w < ratescount; w++) {
if (rates[w] == ratecapability->bitrate) {
device_params->supportedrates[device_params->supportedratescount++] = ratecapability->bitrate;
break;
}
}
}
break;
}
}
/* Apply basic rate */
for (i = 0; i < device_params->supportedratescount; i++) {
if (radiotype == CAPWAP_RADIO_TYPE_80211A) {
if (IS_IEEE80211_BASICRATE_A(device_params->supportedrates[i])) {
device_params->basicrates[device_params->basicratescount++] = device_params->supportedrates[i];
device_params->supportedrates[i] |= IEEE80211_BASICRATE;
}
} else if (radiotype == CAPWAP_RADIO_TYPE_80211B) {
if (IS_IEEE80211_BASICRATE_B(device_params->supportedrates[i])) {
device_params->basicrates[device_params->basicratescount++] = device_params->supportedrates[i];
device_params->supportedrates[i] |= IEEE80211_BASICRATE;
}
} else if (radiotype == CAPWAP_RADIO_TYPE_80211G) {
if (IS_IEEE80211_BASICRATE_G(device_params->supportedrates[i])) {
device_params->basicrates[device_params->basicratescount++] = device_params->supportedrates[i];
device_params->supportedrates[i] |= IEEE80211_BASICRATE;
}
}
}
/* 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_params->supportedrates[device_params->supportedratescount++] = IEEE80211_RATE_80211N;
}
}
/* */
int wifi_driver_init(struct capwap_timeout* timeout) {
int i;
struct global_init_params params;
ASSERT(timeout != NULL);
/* */
params.timeout = timeout;
/* */
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(&params);
if (!wifi_driver[i].handle) {
return -1;
}
}
/* Device handler */
g_wifidevice = capwap_list_create();
return 0;
}
/* */
void wifi_driver_free(void) {
unsigned long i;
struct capwap_list_item* itemdevice;
struct capwap_list_item* itemwlan;
/* Free device */
if (g_wifidevice) {
for (itemdevice = g_wifidevice->first; itemdevice != NULL; itemdevice = itemdevice->next) {
struct wifi_device* device = (struct wifi_device*)itemdevice->item;
if (device->wlan) {
if (device->instance->ops->wlan_delete != NULL) {
for (itemwlan = device->wlan->first; itemwlan != NULL; itemwlan = itemwlan->next) {
struct wifi_wlan* wlan = (struct wifi_wlan*)itemwlan->item;
if (wlan->handle) {
device->instance->ops->wlan_delete(wlan->handle);
}
}
}
capwap_list_free(device->wlan);
}
if (device->handle && device->instance->ops->device_deinit) {
device->instance->ops->device_deinit(device->handle);
}
}
capwap_list_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_event_getfd(struct pollfd* fds, struct wifi_event* events, int count) {
int i;
int result = 0;
struct capwap_list_item* itemdevice;
struct capwap_list_item* itemwlan;
if ((count > 0) && (!fds || !events)) {
return -1;
}
/* Get from driver */
for (i = 0; wifi_driver[i].ops != NULL; i++) {
if (wifi_driver[i].ops->global_getfdevent) {
result += wifi_driver[i].ops->global_getfdevent(wifi_driver[i].handle, (count ? &fds[result] : NULL), (count ? &events[result] : NULL));
}
}
/* Get from device */
for (itemdevice = g_wifidevice->first; itemdevice != NULL; itemdevice = itemdevice->next) {
struct wifi_device* device = (struct wifi_device*)itemdevice->item;
if (device->handle) {
if (device->instance->ops->device_getfdevent) {
result += device->instance->ops->device_getfdevent(device->handle, (count ? &fds[result] : NULL), (count ? &events[result] : NULL));
}
/* Get from wlan */
if (device->wlan && device->instance->ops->wlan_getfdevent) {
for (itemwlan = device->wlan->first; itemwlan != NULL; itemwlan = itemwlan->next) {
struct wifi_wlan* wlan = (struct wifi_wlan*)itemwlan->item;
if (wlan->handle) {
result += device->instance->ops->wlan_getfdevent(wlan->handle, (count ? &fds[result] : NULL), (count ? &events[result] : NULL));
}
}
}
}
}
return result;
}
/* */
struct wifi_device* wifi_device_connect(const char* ifname, const char* driver) {
int i;
int length;
struct wifi_device* device = NULL;
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 NULL;
}
/* 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, &params);
if (devicehandle) {
struct capwap_list_item* itemdevice;
/* Register new device */
itemdevice = capwap_itemlist_create(sizeof(struct wifi_device));
device = (struct wifi_device*)itemdevice->item;
device->handle = devicehandle;
device->instance = &wifi_driver[i];
device->wlan = capwap_list_create();
/* Appent to device list */
capwap_itemlist_insert_after(g_wifidevice, NULL, itemdevice);
}
break;
}
}
return device;
}
/* */
const struct wifi_capability* wifi_device_getcapability(struct wifi_device* device) {
ASSERT(device != NULL);
ASSERT(device->handle != NULL);
/* Retrieve cached capability */
if (!device->instance->ops->device_getcapability) {
return NULL;
}
return device->instance->ops->device_getcapability(device->handle);
}
/* */
int wifi_device_setconfiguration(struct wifi_device* device, struct device_setconfiguration_params* params) {
ASSERT(device != NULL);
ASSERT(device->handle != NULL);
ASSERT(params != NULL);
/* Get radio device */
if (!device->instance->ops->device_setconfiguration) {
return -1;
}
/* Set rates */
return device->instance->ops->device_setconfiguration(device->handle, params);
}
/* */
int wifi_device_setfrequency(struct wifi_device* device, uint32_t band, uint32_t mode, uint8_t channel) {
int i, j;
int result = -1;
const struct wifi_capability* capability;
uint32_t frequency = 0;
ASSERT(device != NULL);
ASSERT(device->handle != NULL);
/* Check device */
if (!device->instance->ops->device_setfrequency) {
return -1;
}
/* Capability device */
capability = wifi_device_getcapability(device);
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) {
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 */
result = device->instance->ops->device_setfrequency(device->handle, &device->currentfreq);
}
/* */
return result;
}
/* */
int wifi_device_updaterates(struct wifi_device* device, uint8_t* rates, int ratescount) {
struct device_setrates_params params;
ASSERT(device != NULL);
ASSERT(device->handle != NULL);
ASSERT(rates != NULL);
ASSERT(ratescount > 0);
/* Get radio device */
if (!device->instance->ops->device_setrates) {
return -1;
}
/* Set rates */
wifi_wlan_getrates(device, rates, ratescount, &params);
return device->instance->ops->device_setrates(device->handle, &params);
}
/* */
struct wifi_wlan* wifi_wlan_create(struct wifi_device* device, const char* ifname) {
int length;
struct wifi_wlan* wlan;
wifi_wlan_handle wlanhandle;
struct capwap_list_item* itemwlan;
ASSERT(device != NULL);
ASSERT(device->handle != NULL);
ASSERT(ifname != NULL);
/* Check */
length = strlen(ifname);
if ((length <= 0) || (length >= IFNAMSIZ)) {
capwap_logging_warning("Wifi device name error: %s", ifname);
return NULL;
} else if (!device->instance->ops->wlan_create) {
capwap_logging_warning("%s library don't support wlan_create", device->instance->ops->name);
return NULL;
}
/* Create interface */
wlanhandle = device->instance->ops->wlan_create(device->handle, ifname);
if (!wlanhandle) {
capwap_logging_warning("Unable to create BSS: %s", ifname);
return NULL;
}
/* Create new BSS */
itemwlan = capwap_itemlist_create(sizeof(struct wifi_wlan));
wlan = (struct wifi_wlan*)itemwlan->item;
wlan->handle = wlanhandle;
wlan->device = device;
/* Appent to wlan list */
capwap_itemlist_insert_after(device->wlan, NULL, itemwlan);
return wlan;
}
/* */
int wifi_wlan_startap(struct wifi_wlan* wlan, struct wlan_startap_params* params) {
ASSERT(wlan != NULL);
ASSERT(wlan->device != NULL);
ASSERT(params != NULL);
/* Check */
if (!wlan->device->instance->ops->wlan_startap) {
return -1;
}
/* Start AP */
return wlan->device->instance->ops->wlan_startap(wlan->handle, params);
}
/* */
void wifi_wlan_stopap(struct wifi_wlan* wlan) {
ASSERT(wlan != NULL);
ASSERT(wlan->device != NULL);
/* Stop AP */
if (wlan->device->instance->ops->wlan_stopap) {
wlan->device->instance->ops->wlan_stopap(wlan->handle);
}
}
/* */
int wifi_wlan_getbssid(struct wifi_wlan* wlan, uint8_t* bssid) {
ASSERT(wlan != NULL);
ASSERT(wlan->handle != NULL);
ASSERT(bssid != NULL);
/* */
if (!wlan->device->instance->ops->wlan_getmacaddress) {
return -1;
}
return wlan->device->instance->ops->wlan_getmacaddress(wlan->handle, bssid);
}
/* */
void wifi_wlan_destroy(struct wifi_wlan* wlan) {
struct capwap_list_item* itemwlan;
ASSERT(wlan != NULL);
ASSERT(wlan->handle != NULL);
/* */
if (wlan->device->instance->ops->wlan_delete) {
wlan->device->instance->ops->wlan_delete(wlan->handle);
}
/* Remove from wlan list of device */
for (itemwlan = wlan->device->wlan->first; itemwlan != NULL; itemwlan = itemwlan->next) {
if (wlan == (struct wifi_wlan*)itemwlan->item) {
capwap_itemlist_free(capwap_itemlist_remove(wlan->device->wlan, itemwlan));
break;
}
}
}
/* */
int wifi_station_add(struct wifi_wlan* wlan, struct station_add_params* params) {
ASSERT(wlan != NULL);
ASSERT(wlan->device != NULL);
ASSERT(params != NULL);
/* Check */
if (!wlan->device->instance->ops->station_add) {
return -1;
}
return wlan->device->instance->ops->station_add(wlan->handle, params);
}
/* */
int wifi_station_delete(struct wifi_device* device, struct station_delete_params* params) {
ASSERT(device != NULL);
ASSERT(params != NULL);
/* Check */
if (!device->instance->ops->station_delete) {
return -1;
}
return device->instance->ops->station_delete(device->handle, params);
}
/* */
uint32_t wifi_iface_index(const char* ifname) {
if (!ifname || !*ifname) {
return 0;
}
return if_nametoindex(ifname);
}
/* */
int wifi_iface_getstatus(int sock, const char* ifname) {
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)) {
return ((ifreq.ifr_flags & IFF_UP) ? 1: 0);
}
return -1;
}
/* */
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)) {
/* Set flag */
if (up) {
if (ifreq.ifr_flags & IFF_UP) {
return 0; /* Flag is already set */
}
ifreq.ifr_flags |= IFF_UP;
} else {
if (!(ifreq.ifr_flags & IFF_UP)) {
return 0; /* Flag is already unset */
}
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;
}
/* */
int wifi_frequency_to_radiotype(uint32_t freq) {
if ((freq >= 2412) && (freq <= 2472)) {
return CAPWAP_RADIO_TYPE_80211G;
} else if (freq == 2484) {
return CAPWAP_RADIO_TYPE_80211B;
} else if ((freq >= 4915) && (freq <= 4980)) {
return CAPWAP_RADIO_TYPE_80211A;
} else if ((freq >= 5035) && (freq <= 5825)) {
return CAPWAP_RADIO_TYPE_80211A;
}
return -1;
}

View File

@ -1,320 +0,0 @@
#ifndef __WIFI_DRIVERS_HEADER__
#define __WIFI_DRIVERS_HEADER__
#include <net/if_arp.h>
#include <linux/if_ether.h>
#include "ieee80211.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_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_MAX_SCAN_SSIDS 0x00000020
#define WIFI_CAPABILITY_MAX_SCHED_SCAN_SSIDS 0x00000040
#define WIFI_CAPABILITY_MAX_MATCH_SETS 0x00000080
#define WIFI_CAPABILITY_MAX_ACL_MACADDRESS 0x00000100
/* */
#define WIFI_CAPABILITY_FLAGS_OFFCHANNEL_TX_OK 0x00000001
#define WIFI_CAPABILITY_FLAGS_ROAM_SUPPORT 0x00000002
#define WIFI_CAPABILITY_FLAGS_SUPPORT_AP_UAPSD 0x00000004
#define WIFI_CAPABILITY_FLAGS_DEVICE_AP_SME 0x00000008
#define WIFI_CAPABILITY_FLAGS_PROBE_RESPONSE_OFFLOAD 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 global_init_params {
struct capwap_timeout* timeout;
};
/* */
struct device_init_params {
const char* ifname;
};
/* */
struct device_setrates_params {
int supportedratescount;
uint8_t supportedrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
int basicratescount;
uint8_t basicrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
};
/* */
#define WIFI_COUNTRY_LENGTH 4
struct device_setconfiguration_params {
int shortpreamble;
uint8_t maxbssid;
uint8_t dtimperiod;
uint8_t bssid[ETH_ALEN];
uint16_t beaconperiod;
uint8_t country[WIFI_COUNTRY_LENGTH];
};
/* */
typedef void (*send_mgmtframe_to_ac)(void* param, const struct ieee80211_header_mgmt* mgmt, int mgmtlength);
struct wlan_startap_params {
send_mgmtframe_to_ac send_mgmtframe;
void* send_mgmtframe_to_ac_cbparam;
const char* ssid;
uint8_t ssid_hidden;
uint16_t capability;
uint8_t qos;
uint8_t authmode;
uint8_t macmode;
uint8_t tunnelmode;
};
/* */
struct wlan_send_frame_params {
uint8_t* packet;
int length;
uint32_t frequency;
uint32_t duration;
int offchannel_tx_ok;
int no_cck_rate;
int no_wait_ack;
uint64_t cookie;
};
/* */
struct station_add_params {
uint8_t* address;
};
/* */
struct station_delete_params {
uint8_t* address;
};
/* 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;
unsigned long capability;
/* 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;
/* WIFI_CAPABILITY_MAX_SCAN_SSIDS */
uint8_t maxscanssids;
/* WIFI_CAPABILITY_MAX_SCHED_SCAN_SSIDS */
uint8_t maxschedscanssids;
/* WIFI_CAPABILITY_MAX_MATCH_SETS */
uint8_t maxmatchsets;
/* WIFI_CAPABILITY_MAX_ACL_MACADDRESS */
uint8_t maxaclmacaddress;
};
/* Frequency configuration */
struct wifi_frequency {
uint32_t band;
uint32_t mode;
uint8_t channel;
uint32_t frequency;
};
/* */
#define WIFI_EVENT_MAX_ITEMS 2
struct wifi_event {
void (*event_handler)(int fd, void** params, int paramscount);
int paramscount;
void* params[WIFI_EVENT_MAX_ITEMS];
};
/* */
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)(struct global_init_params* params);
int (*global_getfdevent)(wifi_global_handle handle, struct pollfd* fds, struct wifi_event* events);
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_getfdevent)(wifi_device_handle handle, struct pollfd* fds, struct wifi_event* events);
const struct wifi_capability* (*device_getcapability)(wifi_device_handle handle);
int (*device_setconfiguration)(wifi_device_handle handle, struct device_setconfiguration_params* params);
int (*device_setfrequency)(wifi_device_handle handle, struct wifi_frequency* freq);
int (*device_setrates)(wifi_device_handle handle, struct device_setrates_params* params);
void (*device_deinit)(wifi_device_handle handle);
/* WLAN functions */
wifi_wlan_handle (*wlan_create)(wifi_device_handle handle, const char* ifname);
int (*wlan_getfdevent)(wifi_wlan_handle handle, struct pollfd* fds, struct wifi_event* events);
int (*wlan_startap)(wifi_wlan_handle handle, struct wlan_startap_params* params);
void (*wlan_stopap)(wifi_wlan_handle handle);
int (*wlan_getmacaddress)(wifi_wlan_handle handle, uint8_t* address);
void (*wlan_delete)(wifi_wlan_handle handle);
/* Stations functions */
int (*station_add)(wifi_wlan_handle handle, struct station_add_params* params);
int (*station_delete)(wifi_device_handle handle, struct station_delete_params* params);
};
/* */
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_list* wlan; /* BSS */
/* Current frequency */
struct wifi_frequency currentfreq;
};
/* */
struct wifi_wlan {
wifi_wlan_handle handle;
struct wifi_device* device;
};
/* Initialize wifi driver engine */
int wifi_driver_init(struct capwap_timeout* timeout);
void wifi_driver_free(void);
/* Get File Descriptor Event */
int wifi_event_getfd(struct pollfd* fds, struct wifi_event* events, int count);
/* */
struct wifi_device* wifi_device_connect(const char* ifname, const char* driver);
const struct wifi_capability* wifi_device_getcapability(struct wifi_device* device);
int wifi_device_setconfiguration(struct wifi_device* device, struct device_setconfiguration_params* params);
int wifi_device_setfrequency(struct wifi_device* device, uint32_t band, uint32_t mode, uint8_t channel);
int wifi_device_updaterates(struct wifi_device* device, uint8_t* rates, int ratescount);
/* */
struct wifi_wlan* wifi_wlan_create(struct wifi_device* device, const char* ifname);
int wifi_wlan_startap(struct wifi_wlan* wlan, struct wlan_startap_params* params);
void wifi_wlan_stopap(struct wifi_wlan* wlan);
int wifi_wlan_getbssid(struct wifi_wlan* wlan, uint8_t* bssid);
void wifi_wlan_destroy(struct wifi_wlan* wlan);
/* */
int wifi_station_add(struct wifi_wlan* wlan, struct station_add_params* params);
int wifi_station_delete(struct wifi_device* device, struct station_delete_params* params);
/* Util functions */
uint32_t wifi_iface_index(const char* ifname);
int wifi_iface_hwaddr(int sock, const char* ifname, uint8_t* hwaddr);
int wifi_frequency_to_radiotype(uint32_t freq);
/* */
int wifi_iface_getstatus(int sock, const char* ifname);
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__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,184 +0,0 @@
#ifndef __WIFI_NL80211_HEADER__
#define __WIFI_NL80211_HEADER__
#include "capwap_hash.h"
#include "netlink_link.h"
/* Compatibility functions */
#ifdef HAVE_LIBNL_10
#define nl_sock nl_handle
#endif
/* */
#define WIFI_NL80211_STATIONS_HASH_SIZE 256
#define WIFI_NL80211_STATIONS_KEY_SIZE ETH_ALEN
/* */
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;
struct nl_sock* nl_event;
int nl_event_fd;
struct netlink* netlinkhandle;
int sock_util;
struct capwap_list* devicelist;
struct capwap_timeout* timeout;
/* Stations */
struct capwap_hash* stations;
};
/* Device handle */
#define NL80211_DEVICE_SET_FREQUENCY 0x00000001
#define NL80211_DEVICE_SET_RATES 0x00000002
#define NL80211_DEVICE_SET_CONFIGURATION 0x00000004
#define NL80211_DEVICE_REQUIRED_FOR_BSS (NL80211_DEVICE_SET_FREQUENCY | NL80211_DEVICE_SET_RATES | NL80211_DEVICE_SET_CONFIGURATION)
struct nl80211_device_handle {
struct nl80211_global_handle* globalhandle;
uint32_t phyindex;
char phyname[IFNAMSIZ];
unsigned long flags;
/* */
struct capwap_list* wlanlist;
unsigned long wlanactive;
/* */
uint16_t beaconperiod;
uint8_t dtimperiod;
int shortpreamble;
/* */
struct wifi_frequency currentfrequency;
/* Cached capability */
struct wifi_capability* capability;
/* Rates */
unsigned long supportedratescount;
uint8_t supportedrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
unsigned long basicratescount;
uint8_t basicrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
/* ERP Information */
int olbc;
unsigned long stationsnonerpcount;
unsigned long stationsnoshortslottimecount;
unsigned long stationsnoshortpreamblecount;
};
/* WLAN handle */
#define NL80211_WLAN_RUNNING 0x00000001
#define NL80211_WLAN_SET_BEACON 0x00000002
#define NL80211_WLAN_OPERSTATE_RUNNING 0x00000004
struct nl80211_wlan_handle {
struct nl80211_device_handle* devicehandle;
struct nl_sock* nl;
int nl_fd;
struct nl_cb* nl_cb;
unsigned long flags;
uint32_t virtindex;
char virtname[IFNAMSIZ];
uint8_t address[ETH_ALEN];
uint64_t last_cookie;
/* */
send_mgmtframe_to_ac send_mgmtframe;
void* send_mgmtframe_to_ac_cbparam;
/* WLAN information */
char ssid[WIFI_SSID_MAX_LENGTH + 1];
uint8_t ssid_hidden;
uint16_t capability;
/* Tunnel */
uint8_t macmode;
uint8_t tunnelmode;
/* Authentication */
uint8_t authenticationtype;
/* Station information */
unsigned long stationscount;
unsigned long maxstationscount;
uint32_t aidbitfield[IEEE80211_AID_BITFIELD_SIZE];
};
/* 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];
};
/* Station */
#define NL80211_STATION_FLAGS_AUTHENTICATED 0x00000001
#define NL80211_STATION_FLAGS_ASSOCIATE 0x00000002
#define NL80211_STATION_FLAGS_NON_ERP 0x00000004
#define NL80211_STATION_FLAGS_NO_SHORT_SLOT_TIME 0x00000008
#define NL80211_STATION_FLAGS_NO_SHORT_PREAMBLE 0x00000010
#define NL80211_STATION_FLAGS_WMM 0x00000020
#define NL80211_STATION_FLAGS_AUTHORIZED 0x00000040
/* */
#define NL80211_STATION_TIMEOUT_ASSOCIATION_COMPLETE 30000
#define NL80211_STATION_TIMEOUT_AFTER_DEAUTHENTICATED 5000
/* */
#define NL80211_STATION_TIMEOUT_ACTION_DELETE 0x00000001
#define NL80211_STATION_TIMEOUT_ACTION_DEAUTHENTICATE 0x00000002
/* */
struct nl80211_station {
struct nl80211_global_handle* globalhandle;
uint8_t address[ETH_ALEN];
/* */
struct nl80211_wlan_handle* wlanhandle;
/* */
unsigned long flags;
/* Timers */
int timeoutaction;
unsigned long idtimeout;
/* */
uint16_t capability;
uint16_t listeninterval;
uint16_t aid;
/* */
int supportedratescount;
uint8_t supportedrates[IEEE80211_SUPPORTEDRATE_MAX_COUNT];
/* Authentication */
uint16_t authalgorithm;
};
#endif /* __WIFI_NL80211_HEADER__ */