Change the location of binding file.
This commit is contained in:
154
src/wtp/binding/ieee80211/netlink_link.c
Normal file
154
src/wtp/binding/ieee80211/netlink_link.c
Normal file
@ -0,0 +1,154 @@
|
||||
#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;
|
||||
}
|
59
src/wtp/binding/ieee80211/netlink_link.h
Normal file
59
src/wtp/binding/ieee80211/netlink_link.h
Normal file
@ -0,0 +1,59 @@
|
||||
#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__ */
|
3724
src/wtp/binding/ieee80211/nl80211_v3_10.h
Normal file
3724
src/wtp/binding/ieee80211/nl80211_v3_10.h
Normal file
File diff suppressed because it is too large
Load Diff
608
src/wtp/binding/ieee80211/wifi_drivers.c
Normal file
608
src/wtp/binding/ieee80211/wifi_drivers.c
Normal file
@ -0,0 +1,608 @@
|
||||
#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(¶ms);
|
||||
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, ¶ms);
|
||||
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, ¶ms);
|
||||
return device->instance->ops->device_setrates(device->handle, ¶ms);
|
||||
}
|
||||
|
||||
/* */
|
||||
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;
|
||||
}
|
320
src/wtp/binding/ieee80211/wifi_drivers.h
Normal file
320
src/wtp/binding/ieee80211/wifi_drivers.h
Normal file
@ -0,0 +1,320 @@
|
||||
#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__ */
|
2933
src/wtp/binding/ieee80211/wifi_nl80211.c
Normal file
2933
src/wtp/binding/ieee80211/wifi_nl80211.c
Normal file
File diff suppressed because it is too large
Load Diff
184
src/wtp/binding/ieee80211/wifi_nl80211.h
Normal file
184
src/wtp/binding/ieee80211/wifi_nl80211.h
Normal file
@ -0,0 +1,184 @@
|
||||
#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__ */
|
Reference in New Issue
Block a user