Add nl80211 handler message events
This commit is contained in:
@ -113,6 +113,46 @@ void wifi_driver_free(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
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;
|
||||
|
@ -152,6 +152,13 @@ struct wifi_frequency {
|
||||
uint32_t frequency;
|
||||
};
|
||||
|
||||
/* */
|
||||
struct wifi_event {
|
||||
void (*event_handler)(int fd, void* param1, void* param2);
|
||||
void* param1;
|
||||
void* param2;
|
||||
};
|
||||
|
||||
/* */
|
||||
struct wifi_driver_ops {
|
||||
const char* name; /* Name of wifi driver */
|
||||
@ -159,16 +166,19 @@ struct wifi_driver_ops {
|
||||
|
||||
/* 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 */
|
||||
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);
|
||||
int (*device_getcapability)(wifi_device_handle handle, struct wifi_capability* capability);
|
||||
int (*device_setfrequency)(wifi_device_handle handle, struct wifi_frequency* freq);
|
||||
void (*device_deinit)(wifi_device_handle handle);
|
||||
|
||||
/* WLAN functions */
|
||||
wifi_wlan_handle (*wlan_create)(wifi_device_handle handle, struct wlan_init_params* params);
|
||||
int (*wlan_getfdevent)(wifi_wlan_handle handle, struct pollfd* fds, struct wifi_event* events);
|
||||
int (*wlan_setupap)(wifi_wlan_handle handle, struct wlan_setupap_params* params);
|
||||
int (*wlan_startap)(wifi_wlan_handle handle);
|
||||
int (*wlan_stopap)(wifi_wlan_handle handle);
|
||||
@ -210,6 +220,9 @@ struct wifi_wlan {
|
||||
int wifi_driver_init(void);
|
||||
void wifi_driver_free(void);
|
||||
|
||||
/* Get File Descriptor Event */
|
||||
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);
|
||||
struct wifi_capability* wifi_device_getcapability(int radioid);
|
||||
|
@ -93,6 +93,19 @@ static int nl80211_process_bss_event(struct nl_msg* msg, void* arg) {
|
||||
return NL_SKIP;
|
||||
}
|
||||
|
||||
/* */
|
||||
static void nl80211_event_receive(int fd, void* param1, void* param2) {
|
||||
int res;
|
||||
struct nl_sock* nl = (struct nl_sock*)param1;
|
||||
struct nl_cb* nl_cb = (struct nl_cb*)param2;
|
||||
|
||||
/* */
|
||||
res = nl_recvmsgs(nl, nl_cb);
|
||||
if (res) {
|
||||
capwap_logging_warning("Receive nl80211 message failed: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
static int nl80211_global_valid_handler(struct nl_msg* msg, void* arg) {
|
||||
/* TODO */
|
||||
@ -622,6 +635,11 @@ static wifi_device_handle nl80211_device_init(wifi_global_handle handle, struct
|
||||
return devicehandle;
|
||||
}
|
||||
|
||||
/* */
|
||||
int nl80211_device_getfdevent(wifi_device_handle handle, struct pollfd* fds, struct wifi_event* events) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
int nl80211_device_getcapability(wifi_device_handle handle, struct wifi_capability* capability) {
|
||||
int result;
|
||||
@ -805,7 +823,9 @@ static wifi_wlan_handle nl80211_wlan_create(wifi_device_handle handle, struct wl
|
||||
nl_cb_set(wlanhandle->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, nl80211_process_bss_event, NULL);
|
||||
|
||||
wlanhandle->nl = nl_create_handle(wlanhandle->nl_cb);
|
||||
if (!wlanhandle->nl) {
|
||||
if (wlanhandle->nl) {
|
||||
wlanhandle->nl_fd = nl_socket_get_fd(wlanhandle->nl);
|
||||
} else {
|
||||
nl80211_wlan_delete((wifi_wlan_handle)wlanhandle);
|
||||
return NULL;
|
||||
}
|
||||
@ -813,6 +833,26 @@ static wifi_wlan_handle nl80211_wlan_create(wifi_device_handle handle, struct wl
|
||||
return wlanhandle;
|
||||
}
|
||||
|
||||
/* */
|
||||
static int nl80211_wlan_getfdevent(wifi_wlan_handle handle, struct pollfd* fds, struct wifi_event* events) {
|
||||
struct nl80211_wlan_handle* wlanhandle = (struct nl80211_wlan_handle*)handle;
|
||||
|
||||
ASSERT(handle != NULL);
|
||||
|
||||
if (fds) {
|
||||
fds[0].fd = wlanhandle->nl_fd;
|
||||
fds[0].events = POLLIN | POLLERR | POLLHUP;
|
||||
}
|
||||
|
||||
if (events) {
|
||||
events[0].event_handler = nl80211_event_receive;
|
||||
events[0].param1 = (void*)wlanhandle->nl;
|
||||
events[0].param2 = (void*)wlanhandle->nl_cb;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* */
|
||||
static int nl80211_wlan_setupap(wifi_wlan_handle handle, struct wlan_setupap_params* params) {
|
||||
int i;
|
||||
@ -1005,17 +1045,25 @@ static wifi_global_handle nl80211_global_init(void) {
|
||||
return (wifi_global_handle)globalhandle;
|
||||
}
|
||||
|
||||
/* */
|
||||
static int nl80211_global_getfdevent(wifi_global_handle handle, struct pollfd* fds, struct wifi_event* events) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Driver function */
|
||||
const struct wifi_driver_ops wifi_driver_nl80211_ops = {
|
||||
.name = "nl80211",
|
||||
.description = "Linux nl80211/cfg80211",
|
||||
.global_init = nl80211_global_init,
|
||||
.global_getfdevent = nl80211_global_getfdevent,
|
||||
.global_deinit = nl80211_global_deinit,
|
||||
.device_init = nl80211_device_init,
|
||||
.device_getfdevent = nl80211_device_getfdevent,
|
||||
.device_getcapability = nl80211_device_getcapability,
|
||||
.device_setfrequency = nl80211_device_setfrequency,
|
||||
.device_deinit = nl80211_device_deinit,
|
||||
.wlan_create = nl80211_wlan_create,
|
||||
.wlan_getfdevent = nl80211_wlan_getfdevent,
|
||||
.wlan_setupap = nl80211_wlan_setupap,
|
||||
.wlan_startap = nl80211_wlan_startap,
|
||||
.wlan_stopap = nl80211_wlan_stopap,
|
||||
|
@ -33,6 +33,7 @@ struct nl80211_wlan_handle {
|
||||
struct nl80211_device_handle* devicehandle;
|
||||
|
||||
struct nl_sock* nl;
|
||||
int nl_fd;
|
||||
struct nl_cb* nl_cb;
|
||||
|
||||
uint32_t virtindex;
|
||||
|
Reference in New Issue
Block a user