Changed the management of the wireless interfaces, from creation to usage.
The virtual interfaces are created at the startup of the wtp to reduce the time required to configure a wireless interface. Applied some patches to build the WTP on OpenWRT trunk
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
/* Global values */
|
||||
#define IEEE80211_MTU 2304
|
||||
#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
|
||||
|
156
src/binding/ieee80211/netlink_link.c
Normal file
156
src/binding/ieee80211/netlink_link.c
Normal file
@ -0,0 +1,156 @@
|
||||
#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) {
|
||||
capwap_logging_debug("*** netlink_set_link_status error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
capwap_logging_debug("*** netlink_set_link_status complete");
|
||||
return 0;
|
||||
}
|
59
src/binding/ieee80211/netlink_link.h
Normal file
59
src/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__ */
|
@ -1,7 +1,6 @@
|
||||
#include "capwap.h"
|
||||
#include "capwap_array.h"
|
||||
#include "capwap_list.h"
|
||||
#include "capwap_element.h"
|
||||
#include "wtp_radio.h"
|
||||
#include "wifi_drivers.h"
|
||||
|
||||
/* Declare enable wifi driver */
|
||||
@ -17,276 +16,25 @@ static struct wifi_driver_instance wifi_driver[] = {
|
||||
};
|
||||
|
||||
/* Radio instance */
|
||||
static struct capwap_array* g_wifidevice = NULL;
|
||||
static struct capwap_list* g_wifidevice = NULL;
|
||||
|
||||
/* */
|
||||
int wifi_driver_init(void) {
|
||||
int i;
|
||||
|
||||
for (i = 0; wifi_driver[i].ops != NULL; i++) {
|
||||
/* Initialize driver */
|
||||
ASSERT(wifi_driver[i].ops->global_init != NULL);
|
||||
wifi_driver[i].handle = wifi_driver[i].ops->global_init();
|
||||
if (!wifi_driver[i].handle) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Device handler */
|
||||
g_wifidevice = capwap_array_create(sizeof(struct wifi_device), 0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
void wifi_driver_free(void) {
|
||||
unsigned long i;
|
||||
unsigned long j;
|
||||
|
||||
/* Free device */
|
||||
if (g_wifidevice) {
|
||||
for (i = 0; i < g_wifidevice->count; i++) {
|
||||
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, i);
|
||||
|
||||
if (device->wlan) {
|
||||
if (device->instance->ops->wlan_delete != NULL) {
|
||||
for (j = 0; j < device->wlan->count; j++) {
|
||||
struct wifi_wlan* wlan = (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, j);
|
||||
|
||||
if (wlan->handle) {
|
||||
device->instance->ops->wlan_delete(wlan->handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
capwap_array_free(device->wlan);
|
||||
}
|
||||
|
||||
if (device->handle && device->instance->ops->device_deinit) {
|
||||
device->instance->ops->device_deinit(device->handle);
|
||||
}
|
||||
}
|
||||
|
||||
capwap_array_free(g_wifidevice);
|
||||
}
|
||||
|
||||
/* Free driver */
|
||||
for (i = 0; wifi_driver[i].ops != NULL; i++) {
|
||||
if (wifi_driver[i].ops->global_deinit) {
|
||||
wifi_driver[i].ops->global_deinit(wifi_driver[i].handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_event_getfd(struct pollfd* fds, struct wifi_event* events, int count) {
|
||||
int i, j;
|
||||
int result = 0;
|
||||
|
||||
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 (i = 0; i < g_wifidevice->count; i++) {
|
||||
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, i);
|
||||
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->instance->ops->wlan_getfdevent) {
|
||||
for (j = 0; j < device->wlan->count; j++) {
|
||||
struct wifi_wlan* wlan = (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, j);
|
||||
|
||||
if (wlan->handle) {
|
||||
result += device->instance->ops->wlan_getfdevent(wlan->handle, (count ? &fds[result] : NULL), (count ? &events[result] : NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_device_connect(int radioid, const char* ifname, const char* driver) {
|
||||
int i;
|
||||
int length;
|
||||
int result = -1;
|
||||
|
||||
ASSERT(radioid > 0);
|
||||
ASSERT(ifname != NULL);
|
||||
ASSERT(driver != NULL);
|
||||
|
||||
/* Check */
|
||||
length = strlen(ifname);
|
||||
if ((length <= 0) || (length >= IFNAMSIZ)) {
|
||||
capwap_logging_warning("Wifi device name error: %s", ifname);
|
||||
return -1;
|
||||
} else if (g_wifidevice->count >= radioid) {
|
||||
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
|
||||
if (device->handle) {
|
||||
capwap_logging_warning("Wifi device RadioID already used: %d", radioid);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Search driver */
|
||||
for (i = 0; wifi_driver[i].ops != NULL; i++) {
|
||||
if (!strcmp(driver, wifi_driver[i].ops->name)) {
|
||||
wifi_device_handle devicehandle;
|
||||
struct device_init_params params = {
|
||||
.ifname = ifname
|
||||
};
|
||||
|
||||
/* Device init */
|
||||
ASSERT(wifi_driver[i].ops->device_init);
|
||||
devicehandle = wifi_driver[i].ops->device_init(wifi_driver[i].handle, ¶ms);
|
||||
if (devicehandle) {
|
||||
/* Register new device */
|
||||
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
device->handle = devicehandle;
|
||||
device->instance = &wifi_driver[i];
|
||||
device->wlan = capwap_array_create(sizeof(struct wifi_wlan), 0, 1);
|
||||
|
||||
result = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* */
|
||||
static struct wifi_device* wifi_device_getdevice(int radioid) {
|
||||
struct wifi_device* device;
|
||||
|
||||
ASSERT(radioid > 0);
|
||||
|
||||
if (g_wifidevice->count < radioid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get radio connection */
|
||||
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
if (!device->handle) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
/* */
|
||||
static struct wifi_wlan* wifi_wlan_getdevice(int radioid, int wlanid) {
|
||||
struct wifi_device* device;
|
||||
|
||||
ASSERT(radioid > 0);
|
||||
ASSERT(wlanid > 0);
|
||||
|
||||
if (g_wifidevice->count < radioid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get radio connection */
|
||||
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
if (!device->handle || (device->wlan->count < wlanid)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* */
|
||||
if (device->wlan->count < wlanid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return wlan connection */
|
||||
return (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, wlanid);
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_wlan_create(int radioid, int wlanid, const char* ifname, uint8_t* bssid) {
|
||||
int length;
|
||||
struct wifi_device* device;
|
||||
struct wifi_wlan* wlan;
|
||||
wifi_wlan_handle wlanhandle;
|
||||
struct wlan_init_params params;
|
||||
|
||||
ASSERT(radioid > 0);
|
||||
ASSERT(wlanid > 0);
|
||||
ASSERT(ifname != NULL);
|
||||
//ASSERT(bssid != NULL);
|
||||
|
||||
/* Check */
|
||||
length = strlen(ifname);
|
||||
if ((length <= 0) || (length >= IFNAMSIZ)) {
|
||||
capwap_logging_warning("Wifi device name error: %s", ifname);
|
||||
return -1;
|
||||
} else if (g_wifidevice->count < radioid) {
|
||||
capwap_logging_warning("Wifi device RadioID %d is not connected", radioid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get radio connection */
|
||||
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
if (!device->handle) {
|
||||
capwap_logging_warning("Wifi device RadioID %d is not connected", radioid);
|
||||
return -1;
|
||||
} else if (device->wlan->count >= wlanid) {
|
||||
wlan = (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, wlanid);
|
||||
if (wlan->handle) {
|
||||
capwap_logging_warning("WLAN interface already used: %d", wlanid);
|
||||
return -1;
|
||||
}
|
||||
} else if (!device->instance->ops->wlan_create) {
|
||||
capwap_logging_warning("%s library don't support wlan_create", device->instance->ops->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create interface */
|
||||
params.ifname = ifname;
|
||||
params.type = WLAN_INTERFACE_AP;
|
||||
wlanhandle = device->instance->ops->wlan_create(device->handle, ¶ms);
|
||||
if (!wlanhandle) {
|
||||
capwap_logging_warning("Unable to create virtual interface: %s", ifname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* */
|
||||
wlan = (struct wifi_wlan*)capwap_array_get_item_pointer(device->wlan, wlanid);
|
||||
wlan->handle = wlanhandle;
|
||||
wlan->device = device;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
static void wifi_wlan_getrates(struct wifi_device* device, struct wtp_radio* radio, struct device_setrates_params* device_params) {
|
||||
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(radio != NULL);
|
||||
ASSERT(radio->rateset.ratesetcount > 0);
|
||||
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(radio->radioid);
|
||||
capability = wifi_device_getcapability(device);
|
||||
if (!capability) {
|
||||
return;
|
||||
}
|
||||
@ -298,19 +46,19 @@ static void wifi_wlan_getrates(struct wifi_device* device, struct wtp_radio* rad
|
||||
}
|
||||
|
||||
/* Check type of rate mode */
|
||||
for (i = 0; i < radio->rateset.ratesetcount; i++) {
|
||||
for (i = 0; i < ratescount; i++) {
|
||||
if (device->currentfreq.band == WIFI_BAND_2GHZ) {
|
||||
if (IS_IEEE80211_RATE_B(radio->rateset.rateset[i])) {
|
||||
if (IS_IEEE80211_RATE_B(rates[i])) {
|
||||
mode |= CAPWAP_RADIO_TYPE_80211B;
|
||||
} else if (IS_IEEE80211_RATE_G(radio->rateset.rateset[i])) {
|
||||
} else if (IS_IEEE80211_RATE_G(rates[i])) {
|
||||
mode |= CAPWAP_RADIO_TYPE_80211G;
|
||||
} else if (IS_IEEE80211_RATE_N(radio->rateset.rateset[i])) {
|
||||
} 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(radio->rateset.rateset[i])) {
|
||||
if (IS_IEEE80211_RATE_A(rates[i])) {
|
||||
mode |= CAPWAP_RADIO_TYPE_80211A;
|
||||
} else if (IS_IEEE80211_RATE_N(radio->rateset.rateset[i])) {
|
||||
} else if (IS_IEEE80211_RATE_N(rates[i])) {
|
||||
mode |= CAPWAP_RADIO_TYPE_80211N;
|
||||
}
|
||||
}
|
||||
@ -330,12 +78,12 @@ static void wifi_wlan_getrates(struct wifi_device* device, struct wtp_radio* rad
|
||||
|
||||
if (bandcap->band == device->currentfreq.band) {
|
||||
for (j = 0; j < bandcap->rate->count; j++) {
|
||||
struct wifi_rate_capability* rate = (struct wifi_rate_capability*)capwap_array_get_item_pointer(bandcap->rate, j);
|
||||
struct wifi_rate_capability* ratecapability = (struct wifi_rate_capability*)capwap_array_get_item_pointer(bandcap->rate, j);
|
||||
|
||||
/* Validate rate */
|
||||
for (w = 0; w < radio->rateset.ratesetcount; w++) {
|
||||
if (radio->rateset.rateset[w] == rate->bitrate) {
|
||||
device_params->supportedrates[device_params->supportedratescount++] = rate->bitrate;
|
||||
for (w = 0; w < ratescount; w++) {
|
||||
if (rates[w] == ratecapability->bitrate) {
|
||||
device_params->supportedrates[device_params->supportedratescount++] = ratecapability->bitrate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -372,85 +120,162 @@ static void wifi_wlan_getrates(struct wifi_device* device, struct wtp_radio* rad
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_wlan_startap(int radioid, int wlanid, struct wifi_wlan_startap_params* params) {
|
||||
struct wifi_wlan* wlan;
|
||||
struct wlan_startap_params wlan_params;
|
||||
int wifi_driver_init(void) {
|
||||
int i;
|
||||
|
||||
ASSERT(radioid > 0);
|
||||
ASSERT(wlanid > 0);
|
||||
|
||||
/* */
|
||||
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||
if (!wlan || !wlan->device->instance->ops->wlan_startap) {
|
||||
return -1;
|
||||
for (i = 0; wifi_driver[i].ops != NULL; i++) {
|
||||
/* Initialize driver */
|
||||
ASSERT(wifi_driver[i].ops->global_init != NULL);
|
||||
wifi_driver[i].handle = wifi_driver[i].ops->global_init();
|
||||
if (!wifi_driver[i].handle) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start AP */
|
||||
memset(&wlan_params, 0, sizeof(struct wlan_startap_params));
|
||||
wlan_params.ssid = params->ssid;
|
||||
wlan_params.ssid_hidden = params->ssid_hidden;
|
||||
wlan_params.capability = params->capability;
|
||||
wlan_params.authenticationtype = params->authmode;
|
||||
/* Device handler */
|
||||
g_wifidevice = capwap_list_create();
|
||||
|
||||
return wlan->device->instance->ops->wlan_startap(wlan->handle, &wlan_params);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_wlan_stopap(int radioid, int wlanid) {
|
||||
struct wifi_wlan* wlan;
|
||||
void wifi_driver_free(void) {
|
||||
unsigned long i;
|
||||
struct capwap_list_item* itemdevice;
|
||||
struct capwap_list_item* itemwlan;
|
||||
|
||||
/* */
|
||||
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||
if (!wlan->device->instance->ops->wlan_stopap) {
|
||||
return -1;
|
||||
}
|
||||
/* Free device */
|
||||
if (g_wifidevice) {
|
||||
for (itemdevice = g_wifidevice->first; itemdevice != NULL; itemdevice = itemdevice->next) {
|
||||
struct wifi_device* device = (struct wifi_device*)itemdevice->item;
|
||||
|
||||
return wlan->device->instance->ops->wlan_stopap(wlan->handle);
|
||||
}
|
||||
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;
|
||||
|
||||
/* */
|
||||
int wifi_wlan_getbssid(int radioid, int wlanid, uint8_t* bssid) {
|
||||
struct wifi_wlan* wlan;
|
||||
if (wlan->handle) {
|
||||
device->instance->ops->wlan_delete(wlan->handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||
if (!wlan->device->instance->ops->wlan_getmacaddress) {
|
||||
return -1;
|
||||
}
|
||||
capwap_list_free(device->wlan);
|
||||
}
|
||||
|
||||
return wlan->device->instance->ops->wlan_getmacaddress(wlan->handle, bssid);
|
||||
}
|
||||
|
||||
/* */
|
||||
void wifi_wlan_destroy(int radioid, int wlanid) {
|
||||
struct wifi_wlan* wlan;
|
||||
|
||||
ASSERT(radioid > 0);
|
||||
ASSERT(wlanid > 0);
|
||||
|
||||
wlan = wifi_wlan_getdevice(radioid, wlanid);
|
||||
if (wlan && wlan->handle) {
|
||||
if (wlan->device->instance->ops->wlan_delete) {
|
||||
wlan->device->instance->ops->wlan_delete(wlan->handle);
|
||||
if (device->handle && device->instance->ops->device_deinit) {
|
||||
device->instance->ops->device_deinit(device->handle);
|
||||
}
|
||||
}
|
||||
|
||||
memset(wlan, 0, sizeof(struct wifi_wlan));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
const struct wifi_capability* wifi_device_getcapability(int radioid) {
|
||||
struct wifi_device* device;
|
||||
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;
|
||||
|
||||
ASSERT(radioid > 0);
|
||||
if ((count > 0) && (!fds || !events)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (g_wifidevice->count <= radioid) {
|
||||
/* 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 */
|
||||
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
if (!device->handle || !device->instance->ops->device_getcapability) {
|
||||
if (!device->instance->ops->device_getcapability) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -458,12 +283,13 @@ const struct wifi_capability* wifi_device_getcapability(int radioid) {
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_device_setconfiguration(int radioid, struct device_setconfiguration_params* params) {
|
||||
struct wifi_device* device;
|
||||
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 */
|
||||
device = wifi_device_getdevice(radioid);
|
||||
if (!device || !device->handle || !device->instance->ops->device_setconfiguration) {
|
||||
if (!device->instance->ops->device_setconfiguration) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -472,20 +298,22 @@ int wifi_device_setconfiguration(int radioid, struct device_setconfiguration_par
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_device_setfrequency(int radioid, uint32_t band, uint32_t mode, uint8_t channel) {
|
||||
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(radioid > 0);
|
||||
ASSERT(device != NULL);
|
||||
ASSERT(device->handle != NULL);
|
||||
|
||||
if (g_wifidevice->count <= radioid) {
|
||||
/* Check device */
|
||||
if (!device->instance->ops->device_setfrequency) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Capability device */
|
||||
capability = wifi_device_getcapability(radioid);
|
||||
capability = wifi_device_getcapability(device);
|
||||
if (!capability || !(capability->flags & WIFI_CAPABILITY_RADIOTYPE) || !(capability->flags & WIFI_CAPABILITY_BANDS)) {
|
||||
return -1;
|
||||
}
|
||||
@ -507,9 +335,6 @@ int wifi_device_setfrequency(int radioid, uint32_t band, uint32_t mode, uint8_t
|
||||
|
||||
/* Configure frequency */
|
||||
if (frequency) {
|
||||
struct wifi_device* device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
|
||||
memset(&device->currentfreq, 0, sizeof(struct wifi_frequency));
|
||||
device->currentfreq.band = band;
|
||||
device->currentfreq.mode = mode;
|
||||
device->currentfreq.channel = channel;
|
||||
@ -523,10 +348,7 @@ int wifi_device_setfrequency(int radioid, uint32_t band, uint32_t mode, uint8_t
|
||||
}
|
||||
|
||||
/* Set frequency */
|
||||
device = (struct wifi_device*)capwap_array_get_item_pointer(g_wifidevice, radioid);
|
||||
if (device->handle && device->instance->ops->device_setfrequency) {
|
||||
result = device->instance->ops->device_setfrequency(device->handle, &device->currentfreq);
|
||||
}
|
||||
result = device->instance->ops->device_setfrequency(device->handle, &device->currentfreq);
|
||||
}
|
||||
|
||||
/* */
|
||||
@ -534,23 +356,124 @@ int wifi_device_setfrequency(int radioid, uint32_t band, uint32_t mode, uint8_t
|
||||
}
|
||||
|
||||
/* */
|
||||
int wifi_device_updaterates(int radioid) {
|
||||
struct wtp_radio* radio;
|
||||
struct wifi_device* device;
|
||||
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 */
|
||||
device = wifi_device_getdevice(radioid);
|
||||
radio = wtp_radio_get_phy(radioid);
|
||||
if (!device || !radio || !device->handle || !device->instance->ops->device_setrates) {
|
||||
if (!device->instance->ops->device_setrates) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set rates */
|
||||
wifi_wlan_getrates(device, radio, ¶ms);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
uint32_t wifi_iface_index(const char* ifname) {
|
||||
if (!ifname || !*ifname) {
|
||||
@ -560,6 +483,24 @@ uint32_t wifi_iface_index(const char* ifname) {
|
||||
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;
|
||||
@ -572,9 +513,18 @@ int wifi_iface_updown(int sock, const char* ifname, int up) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -94,22 +94,18 @@ struct device_setconfiguration_params {
|
||||
uint8_t country[WIFI_COUNTRY_LENGTH];
|
||||
};
|
||||
|
||||
/* */
|
||||
struct wlan_init_params {
|
||||
const char* ifname;
|
||||
int type;
|
||||
};
|
||||
|
||||
/* */
|
||||
struct wlan_startap_params {
|
||||
const char* ssid;
|
||||
uint8_t ssid_hidden;
|
||||
|
||||
uint16_t capability;
|
||||
|
||||
uint8_t authenticationtype;
|
||||
uint8_t qos;
|
||||
uint8_t authmode;
|
||||
uint8_t macmode;
|
||||
uint8_t tunnelmode;
|
||||
};
|
||||
|
||||
|
||||
/* */
|
||||
struct wlan_send_frame_params {
|
||||
char* packet;
|
||||
@ -204,10 +200,11 @@ struct wifi_frequency {
|
||||
};
|
||||
|
||||
/* */
|
||||
#define WIFI_EVENT_MAX_ITEMS 2
|
||||
struct wifi_event {
|
||||
void (*event_handler)(int fd, void* param1, void* param2);
|
||||
void* param1;
|
||||
void* param2;
|
||||
void (*event_handler)(int fd, void** params, int paramscount);
|
||||
int paramscount;
|
||||
void* params[WIFI_EVENT_MAX_ITEMS];
|
||||
};
|
||||
|
||||
/* */
|
||||
@ -230,10 +227,10 @@ struct wifi_driver_ops {
|
||||
void (*device_deinit)(wifi_device_handle handle);
|
||||
|
||||
/* WLAN functions */
|
||||
wifi_wlan_handle (*wlan_create)(wifi_device_handle handle, struct wlan_init_params* params);
|
||||
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);
|
||||
int (*wlan_stopap)(wifi_wlan_handle handle);
|
||||
void (*wlan_stopap)(wifi_wlan_handle handle);
|
||||
int (*wlan_getmacaddress)(wifi_wlan_handle handle, uint8_t* address);
|
||||
void (*wlan_delete)(wifi_wlan_handle handle);
|
||||
};
|
||||
@ -249,7 +246,7 @@ struct wifi_device {
|
||||
wifi_device_handle handle; /* Device handle */
|
||||
struct wifi_driver_instance* instance; /* Driver instance */
|
||||
|
||||
struct capwap_array* wlan; /* Virtual AP */
|
||||
struct capwap_list* wlan; /* BSS */
|
||||
|
||||
/* Current frequency */
|
||||
struct wifi_frequency currentfreq;
|
||||
@ -261,17 +258,6 @@ struct wifi_wlan {
|
||||
struct wifi_device* device;
|
||||
};
|
||||
|
||||
/* */
|
||||
struct wifi_wlan_startap_params {
|
||||
uint16_t capability;
|
||||
uint8_t qos;
|
||||
uint8_t authmode;
|
||||
uint8_t macmode;
|
||||
uint8_t tunnelmode;
|
||||
uint8_t ssid_hidden;
|
||||
char ssid[IEEE80211_IE_SSID_MAX_LENGTH + 1];
|
||||
};
|
||||
|
||||
/* Initialize wifi driver engine */
|
||||
int wifi_driver_init(void);
|
||||
void wifi_driver_free(void);
|
||||
@ -280,18 +266,18 @@ void wifi_driver_free(void);
|
||||
int wifi_event_getfd(struct pollfd* fds, struct wifi_event* events, int count);
|
||||
|
||||
/* */
|
||||
int wifi_device_connect(int radioid, const char* ifname, const char* driver);
|
||||
const struct wifi_capability* wifi_device_getcapability(int radioid);
|
||||
int wifi_device_setconfiguration(int radioid, struct device_setconfiguration_params* params);
|
||||
int wifi_device_setfrequency(int radioid, uint32_t band, uint32_t mode, uint8_t channel);
|
||||
int wifi_device_updaterates(int radioid);
|
||||
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);
|
||||
|
||||
/* */
|
||||
int wifi_wlan_create(int radioid, int wlanid, const char* ifname, uint8_t* bssid);
|
||||
int wifi_wlan_startap(int radioid, int wlanid, struct wifi_wlan_startap_params* params);
|
||||
int wifi_wlan_stopap(int radioid, int wlanid);
|
||||
int wifi_wlan_getbssid(int radioid, int wlanid, uint8_t* bssid);
|
||||
void wifi_wlan_destroy(int radioid, int wlanid);
|
||||
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);
|
||||
|
||||
/* Util functions */
|
||||
uint32_t wifi_iface_index(const char* ifname);
|
||||
@ -314,6 +300,7 @@ void wifi_aid_free(uint32_t* aidbitfield, uint16_t aid);
|
||||
/* */
|
||||
int wifi_retrieve_information_elements_position(struct ieee80211_ie_items* items, const uint8_t* data, int length);
|
||||
|
||||
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)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,9 +2,10 @@
|
||||
#define __WIFI_NL80211_HEADER__
|
||||
|
||||
#include "capwap_hash.h"
|
||||
#include "netlink_link.h"
|
||||
|
||||
/* Compatibility functions */
|
||||
#if !defined(HAVE_LIBNL20) && !defined(HAVE_LIBNL30)
|
||||
#ifdef HAVE_LIBNL_10
|
||||
#define nl_sock nl_handle
|
||||
#endif
|
||||
|
||||
@ -24,19 +25,31 @@ struct nl80211_global_handle {
|
||||
struct nl_sock* nl_event;
|
||||
int nl_event_fd;
|
||||
|
||||
struct netlink* netlinkhandle;
|
||||
|
||||
int sock_util;
|
||||
|
||||
struct capwap_list* devicelist;
|
||||
};
|
||||
|
||||
/* 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;
|
||||
@ -63,7 +76,9 @@ struct nl80211_device_handle {
|
||||
};
|
||||
|
||||
/* WLAN handle */
|
||||
#define NL80211_WLAN_SET_BEACON 0x00000001
|
||||
#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;
|
||||
@ -91,9 +106,13 @@ struct nl80211_wlan_handle {
|
||||
|
||||
/* Station information */
|
||||
unsigned long stationscount;
|
||||
unsigned long maxstationscount;
|
||||
struct capwap_hash* stations;
|
||||
|
||||
uint32_t aidbitfield[WIFI_AID_BITFIELD_SIZE];
|
||||
|
||||
/* Scan */
|
||||
unsigned long scancomplete;
|
||||
};
|
||||
|
||||
/* Physical device info */
|
||||
|
Reference in New Issue
Block a user