remove dos style newlines

This commit is contained in:
Andreas Schultz
2016-02-05 17:38:49 +01:00
parent 6e3ce9ed74
commit 8c20d78941
104 changed files with 21740 additions and 21740 deletions

View File

@ -1,155 +1,155 @@
#include "capwap.h"
#include "capwap_network.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;
}
#include "capwap.h"
#include "capwap_network.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 +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__ */
#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,436 +1,436 @@
#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_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
/* */
DECLARE_OPAQUE_TYPE(wifi_global_handle);
DECLARE_OPAQUE_TYPE(wifi_device_handle);
DECLARE_OPAQUE_TYPE(wifi_wlan_handle);
/* */
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[MACADDRESS_EUI48_LENGTH];
uint16_t beaconperiod;
uint8_t country[WIFI_COUNTRY_LENGTH];
};
/* */
typedef int (*send_frame_to_ac)(void* param, const uint8_t* frame, int length, uint8_t rssi, uint8_t snr, uint16_t rate);
struct wlan_startap_params {
uint8_t radioid;
uint8_t wlanid;
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;
};
/* 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 {
struct wifi_device* 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_instance {
struct wifi_driver_ops* ops; /* Driver functions */
wifi_global_handle handle; /* Global instance handle */
};
/* */
struct wifi_global {
int sock_util;
struct capwap_list* devices;
/* Timeout */
struct capwap_timeout* timeout;
/* Stations */
struct capwap_hash* stations;
};
/* Device handle */
#define WIFI_DEVICE_SET_FREQUENCY 0x00000001
#define WIFI_DEVICE_SET_RATES 0x00000002
#define WIFI_DEVICE_SET_CONFIGURATION 0x00000004
#define WIFI_DEVICE_REQUIRED_FOR_BSS (WIFI_DEVICE_SET_FREQUENCY | WIFI_DEVICE_SET_RATES | WIFI_DEVICE_SET_CONFIGURATION)
struct wifi_device {
struct wifi_global* global;
wifi_device_handle handle; /* Device handle */
struct wifi_driver_instance* instance; /* Driver instance */
uint32_t phyindex;
char phyname[IFNAMSIZ];
unsigned long flags;
/* */
struct capwap_list* wlans;
unsigned long wlanactive;
/* Current frequency */
struct wifi_frequency currentfrequency;
/* */
uint16_t beaconperiod;
uint8_t dtimperiod;
int shortpreamble;
/* 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 WIFI_WLAN_RUNNING 0x00000001
#define WIFI_WLAN_SET_BEACON 0x00000002
#define WIFI_WLAN_OPERSTATE_RUNNING 0x00000004
struct wifi_wlan {
wifi_wlan_handle handle;
struct wifi_device* device;
unsigned long flags;
uint32_t virtindex;
char virtname[IFNAMSIZ];
uint8_t address[MACADDRESS_EUI48_LENGTH];
/* */
uint8_t radioid;
uint8_t wlanid;
/* WLAN information */
char ssid[IEEE80211_SSID_MAX_LENGTH + 1];
uint8_t ssid_hidden;
uint16_t capability;
/* Tunnel */
uint8_t macmode;
uint8_t tunnelmode;
/* Authentication */
uint8_t authmode;
/* Station information */
unsigned long stationscount;
unsigned long maxstationscount;
uint32_t aidbitfield[IEEE80211_AID_BITFIELD_SIZE];
};
/* Station handle */
#define WIFI_STATION_FLAGS_AUTHENTICATED 0x00000001
#define WIFI_STATION_FLAGS_ASSOCIATE 0x00000002
#define WIFI_STATION_FLAGS_NON_ERP 0x00000004
#define WIFI_STATION_FLAGS_NO_SHORT_SLOT_TIME 0x00000008
#define WIFI_STATION_FLAGS_NO_SHORT_PREAMBLE 0x00000010
#define WIFI_STATION_FLAGS_WMM 0x00000020
#define WIFI_STATION_FLAGS_AUTHORIZED 0x00000040
/* */
#define WIFI_STATION_TIMEOUT_ASSOCIATION_COMPLETE 30000
#define WIFI_STATION_TIMEOUT_AFTER_DEAUTHENTICATED 5000
/* */
#define WIFI_STATION_TIMEOUT_ACTION_DELETE 0x00000001
#define WIFI_STATION_TIMEOUT_ACTION_DEAUTHENTICATE 0x00000002
struct wifi_station {
uint8_t address[MACADDRESS_EUI48_LENGTH];
char addrtext[CAPWAP_MACADDRESS_EUI48_BUFFER];
/* */
struct wifi_wlan* wlan;
/* */
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;
};
/* */
struct wifi_driver_ops {
const char* name; /* Name of wifi driver */
const char* description; /* Description of wifi driver */
/* Global initialize driver */
wifi_global_handle (*global_init)(void);
int (*global_getfdevent)(wifi_global_handle handle, struct pollfd* fds, struct wifi_event* events);
void (*global_deinit)(wifi_global_handle handle);
/* Device functions */
int (*device_init)(wifi_global_handle handle, struct wifi_device* device);
int (*device_getfdevent)(struct wifi_device* device, struct pollfd* fds, struct wifi_event* events);
int (*device_getcapability)(struct wifi_device* device, struct wifi_capability* capability);
void (*device_updatebeacons)(struct wifi_device* device);
int (*device_setfrequency)(struct wifi_device* device);
void (*device_deinit)(struct wifi_device* device);
/* WLAN functions */
wifi_wlan_handle (*wlan_create)(struct wifi_device* device, struct wifi_wlan* wlan);
int (*wlan_getfdevent)(struct wifi_wlan* wlan, struct pollfd* fds, struct wifi_event* events);
int (*wlan_startap)(struct wifi_wlan* wlan);
void (*wlan_stopap)(struct wifi_wlan* wlan);
int (*wlan_sendframe)(struct wifi_wlan* wlan, uint8_t* frame, int length, uint32_t frequency, uint32_t duration, int offchannel_tx_ok, int no_cck_rate, int no_wait_ack);
void (*wlan_delete)(struct wifi_wlan* wlan);
/* Stations functions */
int (*station_authorize)(struct wifi_wlan* wlan, struct wifi_station* station);
int (*station_deauthorize)(struct wifi_wlan* wlan, const uint8_t* address);
};
/* 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_wlan* wifi_get_wlan(uint32_t ifindex);
/* Device management */
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);
/* WLAN management */
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);
uint16_t wifi_wlan_check_capability(struct wifi_wlan* wlan, uint16_t capability);
int wifi_wlan_send_frame(struct wifi_wlan* wlan, const uint8_t* data, int length, uint8_t rssi, uint8_t snr, uint16_t rate);
void wifi_wlan_destroy(struct wifi_wlan* wlan);
/* WLAN packet management */
void wifi_wlan_receive_station_frame(struct wifi_wlan* wlan, const struct ieee80211_header* frame, int length, uint32_t frequency, uint8_t rssi, uint8_t snr, uint16_t rate);
void wifi_wlan_receive_station_ackframe(struct wifi_wlan* wlan, const struct ieee80211_header* frame, int length, int ack);
void wifi_wlan_receive_ac_frame(struct wifi_wlan* wlan, struct ieee80211_header* frame, int length);
/* Station management */
int wifi_station_authorize(struct wifi_wlan* wlan, struct station_add_params* params);
void wifi_station_deauthorize(struct wifi_device* device, const uint8_t* address);
/* 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__ */
#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_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
/* */
DECLARE_OPAQUE_TYPE(wifi_global_handle);
DECLARE_OPAQUE_TYPE(wifi_device_handle);
DECLARE_OPAQUE_TYPE(wifi_wlan_handle);
/* */
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[MACADDRESS_EUI48_LENGTH];
uint16_t beaconperiod;
uint8_t country[WIFI_COUNTRY_LENGTH];
};
/* */
typedef int (*send_frame_to_ac)(void* param, const uint8_t* frame, int length, uint8_t rssi, uint8_t snr, uint16_t rate);
struct wlan_startap_params {
uint8_t radioid;
uint8_t wlanid;
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;
};
/* 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 {
struct wifi_device* 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_instance {
struct wifi_driver_ops* ops; /* Driver functions */
wifi_global_handle handle; /* Global instance handle */
};
/* */
struct wifi_global {
int sock_util;
struct capwap_list* devices;
/* Timeout */
struct capwap_timeout* timeout;
/* Stations */
struct capwap_hash* stations;
};
/* Device handle */
#define WIFI_DEVICE_SET_FREQUENCY 0x00000001
#define WIFI_DEVICE_SET_RATES 0x00000002
#define WIFI_DEVICE_SET_CONFIGURATION 0x00000004
#define WIFI_DEVICE_REQUIRED_FOR_BSS (WIFI_DEVICE_SET_FREQUENCY | WIFI_DEVICE_SET_RATES | WIFI_DEVICE_SET_CONFIGURATION)
struct wifi_device {
struct wifi_global* global;
wifi_device_handle handle; /* Device handle */
struct wifi_driver_instance* instance; /* Driver instance */
uint32_t phyindex;
char phyname[IFNAMSIZ];
unsigned long flags;
/* */
struct capwap_list* wlans;
unsigned long wlanactive;
/* Current frequency */
struct wifi_frequency currentfrequency;
/* */
uint16_t beaconperiod;
uint8_t dtimperiod;
int shortpreamble;
/* 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 WIFI_WLAN_RUNNING 0x00000001
#define WIFI_WLAN_SET_BEACON 0x00000002
#define WIFI_WLAN_OPERSTATE_RUNNING 0x00000004
struct wifi_wlan {
wifi_wlan_handle handle;
struct wifi_device* device;
unsigned long flags;
uint32_t virtindex;
char virtname[IFNAMSIZ];
uint8_t address[MACADDRESS_EUI48_LENGTH];
/* */
uint8_t radioid;
uint8_t wlanid;
/* WLAN information */
char ssid[IEEE80211_SSID_MAX_LENGTH + 1];
uint8_t ssid_hidden;
uint16_t capability;
/* Tunnel */
uint8_t macmode;
uint8_t tunnelmode;
/* Authentication */
uint8_t authmode;
/* Station information */
unsigned long stationscount;
unsigned long maxstationscount;
uint32_t aidbitfield[IEEE80211_AID_BITFIELD_SIZE];
};
/* Station handle */
#define WIFI_STATION_FLAGS_AUTHENTICATED 0x00000001
#define WIFI_STATION_FLAGS_ASSOCIATE 0x00000002
#define WIFI_STATION_FLAGS_NON_ERP 0x00000004
#define WIFI_STATION_FLAGS_NO_SHORT_SLOT_TIME 0x00000008
#define WIFI_STATION_FLAGS_NO_SHORT_PREAMBLE 0x00000010
#define WIFI_STATION_FLAGS_WMM 0x00000020
#define WIFI_STATION_FLAGS_AUTHORIZED 0x00000040
/* */
#define WIFI_STATION_TIMEOUT_ASSOCIATION_COMPLETE 30000
#define WIFI_STATION_TIMEOUT_AFTER_DEAUTHENTICATED 5000
/* */
#define WIFI_STATION_TIMEOUT_ACTION_DELETE 0x00000001
#define WIFI_STATION_TIMEOUT_ACTION_DEAUTHENTICATE 0x00000002
struct wifi_station {
uint8_t address[MACADDRESS_EUI48_LENGTH];
char addrtext[CAPWAP_MACADDRESS_EUI48_BUFFER];
/* */
struct wifi_wlan* wlan;
/* */
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;
};
/* */
struct wifi_driver_ops {
const char* name; /* Name of wifi driver */
const char* description; /* Description of wifi driver */
/* Global initialize driver */
wifi_global_handle (*global_init)(void);
int (*global_getfdevent)(wifi_global_handle handle, struct pollfd* fds, struct wifi_event* events);
void (*global_deinit)(wifi_global_handle handle);
/* Device functions */
int (*device_init)(wifi_global_handle handle, struct wifi_device* device);
int (*device_getfdevent)(struct wifi_device* device, struct pollfd* fds, struct wifi_event* events);
int (*device_getcapability)(struct wifi_device* device, struct wifi_capability* capability);
void (*device_updatebeacons)(struct wifi_device* device);
int (*device_setfrequency)(struct wifi_device* device);
void (*device_deinit)(struct wifi_device* device);
/* WLAN functions */
wifi_wlan_handle (*wlan_create)(struct wifi_device* device, struct wifi_wlan* wlan);
int (*wlan_getfdevent)(struct wifi_wlan* wlan, struct pollfd* fds, struct wifi_event* events);
int (*wlan_startap)(struct wifi_wlan* wlan);
void (*wlan_stopap)(struct wifi_wlan* wlan);
int (*wlan_sendframe)(struct wifi_wlan* wlan, uint8_t* frame, int length, uint32_t frequency, uint32_t duration, int offchannel_tx_ok, int no_cck_rate, int no_wait_ack);
void (*wlan_delete)(struct wifi_wlan* wlan);
/* Stations functions */
int (*station_authorize)(struct wifi_wlan* wlan, struct wifi_station* station);
int (*station_deauthorize)(struct wifi_wlan* wlan, const uint8_t* address);
};
/* 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_wlan* wifi_get_wlan(uint32_t ifindex);
/* Device management */
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);
/* WLAN management */
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);
uint16_t wifi_wlan_check_capability(struct wifi_wlan* wlan, uint16_t capability);
int wifi_wlan_send_frame(struct wifi_wlan* wlan, const uint8_t* data, int length, uint8_t rssi, uint8_t snr, uint16_t rate);
void wifi_wlan_destroy(struct wifi_wlan* wlan);
/* WLAN packet management */
void wifi_wlan_receive_station_frame(struct wifi_wlan* wlan, const struct ieee80211_header* frame, int length, uint32_t frequency, uint8_t rssi, uint8_t snr, uint16_t rate);
void wifi_wlan_receive_station_ackframe(struct wifi_wlan* wlan, const struct ieee80211_header* frame, int length, int ack);
void wifi_wlan_receive_ac_frame(struct wifi_wlan* wlan, struct ieee80211_header* frame, int length);
/* Station management */
int wifi_station_authorize(struct wifi_wlan* wlan, struct station_add_params* params);
void wifi_station_deauthorize(struct wifi_device* device, const uint8_t* address);
/* 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,45 +1,45 @@
#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
/* */
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;
};
/* Device handle */
struct nl80211_device_handle {
struct nl80211_global_handle* globalhandle;
};
/* WLAN handle */
struct nl80211_wlan_handle {
struct nl80211_device_handle* devicehandle;
struct nl_sock* nl;
int nl_fd;
struct nl_cb* nl_cb;
uint64_t last_cookie;
};
#endif /* __WIFI_NL80211_HEADER__ */
#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
/* */
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;
};
/* Device handle */
struct nl80211_device_handle {
struct nl80211_global_handle* globalhandle;
};
/* WLAN handle */
struct nl80211_wlan_handle {
struct nl80211_device_handle* devicehandle;
struct nl_sock* nl;
int nl_fd;
struct nl_cb* nl_cb;
uint64_t last_cookie;
};
#endif /* __WIFI_NL80211_HEADER__ */