Permit to forward IEEE802.11 Data Packet from kernel space to user space bypass
kernel network stack.
This commit is contained in:
@ -8,7 +8,6 @@
|
||||
#include "capwap_dtls.h"
|
||||
#include "wtp_dfa.h"
|
||||
#include "wtp_radio.h"
|
||||
#include "wtp_kmod.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <libconfig.h>
|
||||
@ -1305,24 +1304,28 @@ static void wtp_wait_radio_ready(void) {
|
||||
|
||||
/* Get only radio file descriptor */
|
||||
memset(&fds, 0, sizeof(struct wtp_fds));
|
||||
wtp_radio_update_fdevent(&fds);
|
||||
wtp_dfa_update_fdspool(&fds);
|
||||
if (fds.wifieventscount > 0) {
|
||||
ASSERT(fds.fdsnetworkcount == 0);
|
||||
ASSERT(fds.kmodeventscount == 0);
|
||||
|
||||
for (;;) {
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RADIO_INITIALIZATION_INTERVAL, NULL, NULL, NULL);
|
||||
for (;;) {
|
||||
capwap_timeout_set(g_wtp.timeout, g_wtp.idtimercontrol, WTP_RADIO_INITIALIZATION_INTERVAL, NULL, NULL, NULL);
|
||||
|
||||
/* Wait packet */
|
||||
index = capwap_wait_recvready(fds.fdspoll, fds.fdstotalcount, g_wtp.timeout);
|
||||
if (index < 0) {
|
||||
break;
|
||||
} else if (!fds.events[index].event_handler) {
|
||||
break;
|
||||
/* Wait packet */
|
||||
index = capwap_wait_recvready(fds.fdspoll, fds.fdstotalcount, g_wtp.timeout);
|
||||
if (index < 0) {
|
||||
break;
|
||||
} else if (!fds.wifievents[index].event_handler) {
|
||||
break;
|
||||
}
|
||||
|
||||
fds.wifievents[index].event_handler(fds.fdspoll[index].fd, fds.wifievents[index].params, fds.wifievents[index].paramscount);
|
||||
}
|
||||
|
||||
fds.events[index].event_handler(fds.fdspoll[index].fd, fds.events[index].params, fds.events[index].paramscount);
|
||||
}
|
||||
|
||||
/* */
|
||||
wtp_free_fds(&fds);
|
||||
wtp_dfa_free_fdspool(&fds);
|
||||
capwap_timeout_unset(g_wtp.timeout, g_wtp.idtimercontrol);
|
||||
}
|
||||
|
||||
@ -1332,19 +1335,6 @@ int wtp_update_radio_in_use() {
|
||||
return g_wtp.radios->count;
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_free_fds(struct wtp_fds* fds) {
|
||||
ASSERT(fds != NULL);
|
||||
|
||||
if (fds->fdspoll) {
|
||||
capwap_free(fds->fdspoll);
|
||||
}
|
||||
|
||||
if (fds->events) {
|
||||
capwap_free(fds->events);
|
||||
}
|
||||
}
|
||||
|
||||
/* Main*/
|
||||
int main(int argc, char** argv) {
|
||||
int value;
|
||||
@ -1394,8 +1384,7 @@ int main(int argc, char** argv) {
|
||||
/* Connect WTP with kernel module */
|
||||
value = wtp_kmod_init();
|
||||
if (!value || !g_wtp.kmodrequest) {
|
||||
if (!value) {
|
||||
g_wtp.kmodconnect = 1;
|
||||
if (wtp_kmod_isconnected()) {
|
||||
capwap_logging_info("SmartCAPWAP kernel module connected");
|
||||
}
|
||||
|
||||
@ -1413,9 +1402,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
/* Disconnect kernel module */
|
||||
if (g_wtp.kmodconnect) {
|
||||
wtp_kmod_free();
|
||||
}
|
||||
wtp_kmod_free();
|
||||
|
||||
/* */
|
||||
capwap_logging_info("Terminate WTP");
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "capwap_dtls.h"
|
||||
#include "capwap_network.h"
|
||||
#include "capwap_protocol.h"
|
||||
#include "wtp_kmod.h"
|
||||
#include "wifi_drivers.h"
|
||||
|
||||
/* WTP Configuration */
|
||||
@ -43,12 +44,18 @@
|
||||
|
||||
/* */
|
||||
struct wtp_fds {
|
||||
struct pollfd* fdspoll;
|
||||
int fdstotalcount;
|
||||
struct pollfd* fdspoll;
|
||||
|
||||
int fdsnetworkcount;
|
||||
|
||||
struct wifi_event* events;
|
||||
int eventscount;
|
||||
struct wtp_kmod_event* kmodevents;
|
||||
int kmodeventscount;
|
||||
int kmodeventsstartpos;
|
||||
|
||||
struct wifi_event* wifievents;
|
||||
int wifieventscount;
|
||||
int wifieventsstartpos;
|
||||
};
|
||||
|
||||
/* WTP */
|
||||
@ -58,7 +65,7 @@ struct wtp_t {
|
||||
|
||||
/* */
|
||||
int kmodrequest;
|
||||
int kmodconnect;
|
||||
struct wtp_kmod_handle kmodhandle;
|
||||
|
||||
/* */
|
||||
char wlanprefix[IFNAMSIZ];
|
||||
@ -151,7 +158,6 @@ extern struct wtp_t g_wtp;
|
||||
|
||||
/* */
|
||||
int wtp_update_radio_in_use();
|
||||
void wtp_free_fds(struct wtp_fds* fds);
|
||||
|
||||
/* Build capwap element helper */
|
||||
void wtp_create_radioadmstate_element(struct capwap_packet_txmng* txmngpacket);
|
||||
|
@ -158,15 +158,27 @@ static int wtp_recvfrom(struct wtp_fds* fds, void* buffer, int* size, struct soc
|
||||
index = capwap_wait_recvready(fds->fdspoll, fds->fdstotalcount, g_wtp.timeout);
|
||||
if (index < 0) {
|
||||
return index;
|
||||
} else if (index >= fds->fdsnetworkcount) {
|
||||
int pos = index - fds->fdsnetworkcount;
|
||||
} else if ((fds->wifieventsstartpos >= 0) && (index >= fds->wifieventsstartpos)) {
|
||||
int pos = index - fds->wifieventsstartpos;
|
||||
|
||||
if (pos < fds->eventscount) {
|
||||
if (!fds->events[pos].event_handler) {
|
||||
if (pos < fds->wifieventscount) {
|
||||
if (!fds->wifievents[pos].event_handler) {
|
||||
return CAPWAP_RECV_ERROR_SOCKET;
|
||||
}
|
||||
|
||||
fds->events[pos].event_handler(fds->fdspoll[index].fd, fds->events[pos].params, fds->events[pos].paramscount);
|
||||
fds->wifievents[pos].event_handler(fds->fdspoll[index].fd, fds->wifievents[pos].params, fds->wifievents[pos].paramscount);
|
||||
}
|
||||
|
||||
return WTP_RECV_NOERROR_RADIO;
|
||||
} else if ((fds->kmodeventsstartpos >= 0) && (index >= fds->kmodeventsstartpos)) {
|
||||
int pos = index - fds->kmodeventsstartpos;
|
||||
|
||||
if (pos < fds->kmodeventscount) {
|
||||
if (!fds->kmodevents[pos].event_handler) {
|
||||
return CAPWAP_RECV_ERROR_SOCKET;
|
||||
}
|
||||
|
||||
fds->kmodevents[pos].event_handler(fds->fdspoll[index].fd, fds->kmodevents[pos].params, fds->kmodevents[pos].paramscount);
|
||||
}
|
||||
|
||||
return WTP_RECV_NOERROR_RADIO;
|
||||
@ -181,21 +193,115 @@ static int wtp_recvfrom(struct wtp_fds* fds, void* buffer, int* size, struct soc
|
||||
}
|
||||
|
||||
/* */
|
||||
static void wtp_dfa_init_fdspool(struct wtp_fds* fds, struct capwap_network* net) {
|
||||
static int wtp_dfa_init_fdspool(struct wtp_fds* fds, struct capwap_network* net) {
|
||||
ASSERT(fds != NULL);
|
||||
ASSERT(net != NULL);
|
||||
|
||||
/* */
|
||||
memset(fds, 0, sizeof(struct wtp_fds));
|
||||
fds->fdstotalcount = CAPWAP_MAX_SOCKETS * 2;
|
||||
fds->fdspoll = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * fds->fdstotalcount);
|
||||
fds->fdsnetworkcount = capwap_network_set_pollfd(net, NULL, 0);
|
||||
fds->fdspoll = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * fds->fdsnetworkcount);
|
||||
|
||||
/* Retrive all socket for polling */
|
||||
fds->fdsnetworkcount = capwap_network_set_pollfd(net, fds->fdspoll, fds->fdstotalcount);
|
||||
fds->fdstotalcount = fds->fdsnetworkcount;
|
||||
fds->fdstotalcount = capwap_network_set_pollfd(net, fds->fdspoll, fds->fdsnetworkcount);
|
||||
if (fds->fdsnetworkcount != fds->fdstotalcount) {
|
||||
capwap_free(fds->fdspoll);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Update Event File Descriptor */
|
||||
wtp_radio_update_fdevent(fds);
|
||||
wtp_dfa_update_fdspool(fds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* */
|
||||
int wtp_dfa_update_fdspool(struct wtp_fds* fds) {
|
||||
int totalcount;
|
||||
int kmodcount;
|
||||
int wificount;
|
||||
struct pollfd* fdsbuffer;
|
||||
|
||||
ASSERT(fds != NULL);
|
||||
|
||||
/* Retrieve number of Dynamic File Descriptor Event */
|
||||
kmodcount = wtp_kmod_getfd(NULL, NULL, 0);
|
||||
wificount = wifi_event_getfd(NULL, NULL, 0);
|
||||
if ((kmodcount < 0) || (wificount < 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Kernel Module Events Callback */
|
||||
fds->kmodeventsstartpos = -1;
|
||||
if (kmodcount != fds->kmodeventscount) {
|
||||
if (fds->kmodevents) {
|
||||
capwap_free(fds->kmodevents);
|
||||
}
|
||||
|
||||
/* */
|
||||
fds->kmodeventscount = kmodcount;
|
||||
fds->kmodevents = (struct wtp_kmod_event*)((wificount > 0) ? capwap_alloc(sizeof(struct wtp_kmod_event) * kmodcount) : NULL);
|
||||
}
|
||||
|
||||
/* Wifi Events Callback */
|
||||
fds->wifieventsstartpos = -1;
|
||||
if (wificount != fds->wifieventscount) {
|
||||
if (fds->wifievents) {
|
||||
capwap_free(fds->wifievents);
|
||||
}
|
||||
|
||||
/* */
|
||||
fds->wifieventscount = wificount;
|
||||
fds->wifievents = (struct wifi_event*)((wificount > 0) ? capwap_alloc(sizeof(struct wifi_event) * wificount) : NULL);
|
||||
}
|
||||
|
||||
/* Resize poll */
|
||||
totalcount = fds->fdsnetworkcount + fds->kmodeventscount + fds->wifieventscount;
|
||||
if (fds->fdstotalcount != totalcount) {
|
||||
fdsbuffer = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * totalcount);
|
||||
if (fds->fdspoll) {
|
||||
if (fds->fdsnetworkcount > 0) {
|
||||
memcpy(fdsbuffer, fds->fdspoll, sizeof(struct pollfd) * fds->fdsnetworkcount);
|
||||
}
|
||||
|
||||
capwap_free(fds->fdspoll);
|
||||
}
|
||||
|
||||
/* */
|
||||
fds->fdspoll = fdsbuffer;
|
||||
fds->fdstotalcount = totalcount;
|
||||
}
|
||||
|
||||
|
||||
/* Retrieve File Descriptor Kernel Module Event */
|
||||
if (fds->kmodeventscount > 0) {
|
||||
fds->kmodeventsstartpos = fds->fdsnetworkcount;
|
||||
wtp_kmod_getfd(&fds->fdspoll[fds->kmodeventsstartpos], fds->kmodevents, fds->kmodeventscount);
|
||||
}
|
||||
|
||||
/* Retrieve File Descriptor Wifi Event */
|
||||
if (fds->wifieventscount > 0) {
|
||||
fds->wifieventsstartpos = fds->fdsnetworkcount + fds->kmodeventscount;
|
||||
wifi_event_getfd(&fds->fdspoll[fds->wifieventsstartpos], fds->wifievents, fds->wifieventscount);
|
||||
}
|
||||
|
||||
return fds->fdstotalcount;
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_dfa_free_fdspool(struct wtp_fds* fds) {
|
||||
ASSERT(fds != NULL);
|
||||
|
||||
if (fds->fdspoll) {
|
||||
capwap_free(fds->fdspoll);
|
||||
}
|
||||
|
||||
if (fds->kmodevents) {
|
||||
capwap_free(fds->kmodevents);
|
||||
}
|
||||
|
||||
if (fds->wifievents) {
|
||||
capwap_free(fds->wifievents);
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
@ -242,7 +348,9 @@ int wtp_dfa_running(void) {
|
||||
memset(&packet, 0, sizeof(struct capwap_parsed_packet));
|
||||
|
||||
/* Configure poll struct */
|
||||
wtp_dfa_init_fdspool(&g_wtp.fds, &g_wtp.net);
|
||||
if (wtp_dfa_init_fdspool(&g_wtp.fds, &g_wtp.net)) {
|
||||
return CAPWAP_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
/* Handler signal */
|
||||
g_wtp.running = 1;
|
||||
@ -453,8 +561,7 @@ int wtp_dfa_running(void) {
|
||||
}
|
||||
|
||||
/* Free memory */
|
||||
wtp_free_fds(&g_wtp.fds);
|
||||
|
||||
wtp_dfa_free_fdspool(&g_wtp.fds);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,9 @@ void wtp_send_datacheck(void);
|
||||
/* */
|
||||
void wtp_dfa_retransmition_timeout(struct capwap_timeout* timeout, unsigned long index, void* context, void* param);
|
||||
|
||||
int wtp_dfa_update_fdspool(struct wtp_fds* fds);
|
||||
void wtp_dfa_free_fdspool(struct wtp_fds* fds);
|
||||
|
||||
/* */
|
||||
void wtp_dfa_state_idle(void);
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "wtp.h"
|
||||
#include "wtp_kmod.h"
|
||||
#include <netlink/genl/genl.h>
|
||||
#include <netlink/genl/family.h>
|
||||
#include <netlink/genl/ctrl.h>
|
||||
@ -7,7 +6,6 @@
|
||||
|
||||
/* Compatibility functions */
|
||||
#ifdef HAVE_LIBNL_10
|
||||
#define nl_sock nl_handle
|
||||
static uint32_t g_portbitmap[32] = { 0 };
|
||||
|
||||
static struct nl_sock* nl_socket_alloc_cb(void* cb) {
|
||||
@ -40,19 +38,9 @@ static void nl_socket_free(struct nl_sock* handle) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/* */
|
||||
struct wtp_kmod_handle {
|
||||
struct nl_sock* nl;
|
||||
struct nl_cb* nl_cb;
|
||||
int nlsmartcapwap_id;
|
||||
};
|
||||
|
||||
/* */
|
||||
typedef int (*wtp_kmod_valid_cb)(struct nl_msg* msg, void* data);
|
||||
|
||||
/* */
|
||||
static struct wtp_kmod_handle g_kmodhandle;
|
||||
|
||||
/* */
|
||||
static struct nl_sock* nl_create_handle(struct nl_cb* cb) {
|
||||
struct nl_sock* handle;
|
||||
@ -141,7 +129,7 @@ static int wtp_kmod_send_and_recv(struct nl_sock* nl, struct nl_cb* nl_cb, struc
|
||||
|
||||
/* */
|
||||
static int wtp_kmod_send_and_recv_msg(struct nl_msg* msg, wtp_kmod_valid_cb valid_cb, void* data) {
|
||||
return wtp_kmod_send_and_recv(g_kmodhandle.nl, g_kmodhandle.nl_cb, msg, valid_cb, data);
|
||||
return wtp_kmod_send_and_recv(g_wtp.kmodhandle.nl, g_wtp.kmodhandle.nl_cb, msg, valid_cb, data);
|
||||
}
|
||||
|
||||
/* */
|
||||
@ -156,7 +144,7 @@ static int wtp_kmod_link(void) {
|
||||
}
|
||||
|
||||
/* */
|
||||
genlmsg_put(msg, 0, 0, g_kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_LINK, 0);
|
||||
genlmsg_put(msg, 0, 0, g_wtp.kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_LINK, 0);
|
||||
|
||||
/* */
|
||||
result = wtp_kmod_send_and_recv_msg(msg, NULL, NULL);
|
||||
@ -173,13 +161,28 @@ static int wtp_kmod_link(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* */
|
||||
static void wtp_kmod_event_receive(int fd, void** params, int paramscount) {
|
||||
int res;
|
||||
|
||||
ASSERT(fd >= 0);
|
||||
ASSERT(params != NULL);
|
||||
ASSERT(paramscount == 2);
|
||||
|
||||
/* */
|
||||
res = nl_recvmsgs((struct nl_sock*)params[0], (struct nl_cb*)params[1]);
|
||||
if (res) {
|
||||
capwap_logging_warning("Receive kernel module message failed: %d", res);
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
int wtp_kmod_join_mac80211_device(uint32_t ifindex) {
|
||||
int result;
|
||||
struct nl_msg* msg;
|
||||
|
||||
/* */
|
||||
if (!g_kmodhandle.nlsmartcapwap_id) {
|
||||
if (!g_wtp.kmodhandle.nlsmartcapwap_id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -190,8 +193,9 @@ int wtp_kmod_join_mac80211_device(uint32_t ifindex) {
|
||||
}
|
||||
|
||||
/* */
|
||||
genlmsg_put(msg, 0, 0, g_kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_JOIN_MAC80211_DEVICE, 0);
|
||||
genlmsg_put(msg, 0, 0, g_wtp.kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_JOIN_MAC80211_DEVICE, 0);
|
||||
nla_put_u32(msg, NLSMARTCAPWAP_ATTR_IFINDEX, ifindex);
|
||||
nla_put_u32(msg, NLSMARTCAPWAP_ATTR_FLAGS, SMARTCAPWAP_FLAGS_SEND_USERSPACE | SMARTCAPWAP_FLAGS_BLOCK_DATA_FRAME);
|
||||
nla_put_u16(msg, NLSMARTCAPWAP_ATTR_DATA_SUBTYPE_MASK, 0xffff);
|
||||
|
||||
/* */
|
||||
@ -205,38 +209,68 @@ int wtp_kmod_join_mac80211_device(uint32_t ifindex) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* */
|
||||
int wtp_kmod_isconnected(void) {
|
||||
return (g_wtp.kmodhandle.nlsmartcapwap_id ? 1 : 0);
|
||||
}
|
||||
|
||||
/* */
|
||||
int wtp_kmod_getfd(struct pollfd* fds, struct wtp_kmod_event* events, int count) {
|
||||
int kmodcount = (wtp_kmod_isconnected() ? 1 : 0);
|
||||
|
||||
/* */
|
||||
if (!fds && !events && !count) {
|
||||
return kmodcount;
|
||||
} else if ((count > 0) && (!fds || !events)) {
|
||||
return -1;
|
||||
} else if (count < kmodcount) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* */
|
||||
fds[0].fd = g_wtp.kmodhandle.nl_fd;
|
||||
fds[0].events = POLLIN | POLLERR | POLLHUP;
|
||||
|
||||
/* */
|
||||
events[0].event_handler = wtp_kmod_event_receive;
|
||||
events[0].params[0] = (void*)g_wtp.kmodhandle.nl;
|
||||
events[0].params[1] = (void*)g_wtp.kmodhandle.nl_cb;
|
||||
events[0].paramscount = 2;
|
||||
|
||||
return kmodcount;
|
||||
}
|
||||
|
||||
/* */
|
||||
int wtp_kmod_init(void) {
|
||||
int result;
|
||||
|
||||
/* */
|
||||
memset(&g_kmodhandle, 0, sizeof(struct wtp_kmod_handle));
|
||||
|
||||
/* Configure netlink callback */
|
||||
g_kmodhandle.nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
|
||||
if (!g_kmodhandle.nl_cb) {
|
||||
g_wtp.kmodhandle.nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
|
||||
if (!g_wtp.kmodhandle.nl_cb) {
|
||||
wtp_kmod_free();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create netlink socket */
|
||||
g_kmodhandle.nl = nl_create_handle(g_kmodhandle.nl_cb);
|
||||
if (!g_kmodhandle.nl) {
|
||||
g_wtp.kmodhandle.nl = nl_create_handle(g_wtp.kmodhandle.nl_cb);
|
||||
if (!g_wtp.kmodhandle.nl) {
|
||||
wtp_kmod_free();
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_wtp.kmodhandle.nl_fd = nl_socket_get_fd(g_wtp.kmodhandle.nl);
|
||||
|
||||
/* Get nlsmartcapwap netlink family */
|
||||
g_kmodhandle.nlsmartcapwap_id = genl_ctrl_resolve(g_kmodhandle.nl, SMARTCAPWAP_GENL_NAME);
|
||||
if (g_kmodhandle.nlsmartcapwap_id < 0) {
|
||||
g_wtp.kmodhandle.nlsmartcapwap_id = genl_ctrl_resolve(g_wtp.kmodhandle.nl, SMARTCAPWAP_GENL_NAME);
|
||||
if (g_wtp.kmodhandle.nlsmartcapwap_id < 0) {
|
||||
capwap_logging_warning("Unable to found kernel module");
|
||||
wtp_kmod_free();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Configure callback function */
|
||||
nl_cb_set(g_kmodhandle.nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, wtp_kmod_no_seq_check, NULL);
|
||||
nl_cb_set(g_kmodhandle.nl_cb, NL_CB_VALID, NL_CB_CUSTOM, wtp_kmod_valid_handler, NULL);
|
||||
nl_cb_set(g_wtp.kmodhandle.nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, wtp_kmod_no_seq_check, NULL);
|
||||
nl_cb_set(g_wtp.kmodhandle.nl_cb, NL_CB_VALID, NL_CB_CUSTOM, wtp_kmod_valid_handler, NULL);
|
||||
|
||||
/* Link to kernel module */
|
||||
result = wtp_kmod_link();
|
||||
@ -250,14 +284,14 @@ int wtp_kmod_init(void) {
|
||||
|
||||
/* */
|
||||
void wtp_kmod_free(void) {
|
||||
if (g_kmodhandle.nl) {
|
||||
nl_socket_free(g_kmodhandle.nl);
|
||||
if (g_wtp.kmodhandle.nl) {
|
||||
nl_socket_free(g_wtp.kmodhandle.nl);
|
||||
}
|
||||
|
||||
if (g_kmodhandle.nl_cb) {
|
||||
nl_cb_put(g_kmodhandle.nl_cb);
|
||||
if (g_wtp.kmodhandle.nl_cb) {
|
||||
nl_cb_put(g_wtp.kmodhandle.nl_cb);
|
||||
}
|
||||
|
||||
/* */
|
||||
memset(&g_kmodhandle, 0, sizeof(struct wtp_kmod_handle));
|
||||
memset(&g_wtp.kmodhandle, 0, sizeof(struct wtp_kmod_handle));
|
||||
}
|
||||
|
@ -1,10 +1,35 @@
|
||||
#ifndef __WTP_KMOD_HEADER__
|
||||
#define __WTP_KMOD_HEADER__
|
||||
|
||||
/* */
|
||||
#ifdef HAVE_LIBNL_10
|
||||
#define nl_sock nl_handle
|
||||
#endif
|
||||
|
||||
/* */
|
||||
struct wtp_kmod_handle {
|
||||
struct nl_sock* nl;
|
||||
int nl_fd;
|
||||
struct nl_cb* nl_cb;
|
||||
int nlsmartcapwap_id;
|
||||
};
|
||||
|
||||
/* */
|
||||
#define WTP_KMOD_EVENT_MAX_ITEMS 2
|
||||
struct wtp_kmod_event {
|
||||
void (*event_handler)(int fd, void** params, int paramscount);
|
||||
int paramscount;
|
||||
void* params[WTP_KMOD_EVENT_MAX_ITEMS];
|
||||
};
|
||||
|
||||
/* */
|
||||
int wtp_kmod_init(void);
|
||||
void wtp_kmod_free(void);
|
||||
|
||||
/* */
|
||||
int wtp_kmod_isconnected(void);
|
||||
int wtp_kmod_getfd(struct pollfd* fds, struct wtp_kmod_event* events, int count);
|
||||
|
||||
/* */
|
||||
int wtp_kmod_join_mac80211_device(uint32_t ifindex);
|
||||
|
||||
|
@ -555,48 +555,6 @@ struct wtp_radio_wlan* wtp_radio_search_wlan(struct wtp_radio* radio, const uint
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_radio_update_fdevent(struct wtp_fds* fds) {
|
||||
int count;
|
||||
struct pollfd* fdsbuffer;
|
||||
|
||||
ASSERT(fds != NULL);
|
||||
|
||||
/* Retrieve number of File Descriptor Event */
|
||||
count = wifi_event_getfd(NULL, NULL, 0);
|
||||
if (count < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Resize poll */
|
||||
if (fds->eventscount != count) {
|
||||
fdsbuffer = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * (fds->fdsnetworkcount + count));
|
||||
if (fds->fdspoll && (fds->fdsnetworkcount > 0)) {
|
||||
memcpy(fdsbuffer, fds->fdspoll, sizeof(struct pollfd) * fds->fdsnetworkcount);
|
||||
capwap_free(fds->fdspoll);
|
||||
}
|
||||
|
||||
fds->fdspoll = fdsbuffer;
|
||||
|
||||
/* Events Callback */
|
||||
if (fds->events) {
|
||||
capwap_free(fds->events);
|
||||
}
|
||||
|
||||
fds->events = (struct wifi_event*)((count > 0) ? capwap_alloc(sizeof(struct wifi_event) * count) : NULL);
|
||||
|
||||
/* */
|
||||
fds->eventscount = count;
|
||||
fds->fdstotalcount = fds->fdsnetworkcount + count;
|
||||
}
|
||||
|
||||
/* Retrieve File Descriptor Event */
|
||||
if (count > 0) {
|
||||
ASSERT(fds->fdspoll != NULL);
|
||||
wifi_event_getfd(&fds->fdspoll[fds->fdsnetworkcount], fds->events, fds->eventscount);
|
||||
}
|
||||
}
|
||||
|
||||
/* */
|
||||
void wtp_radio_receive_data_packet(uint8_t radioid, unsigned short binding, const uint8_t* frame, int length) {
|
||||
struct wtp_radio* radio;
|
||||
@ -704,7 +662,7 @@ uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwa
|
||||
capwap_itemlist_insert_after(radio->wlan, NULL, itemwlan);
|
||||
|
||||
/* Update Event File Descriptor */
|
||||
wtp_radio_update_fdevent(&g_wtp.fds);
|
||||
wtp_dfa_update_fdspool(&g_wtp.fds);
|
||||
|
||||
/* Retrieve macaddress of new device */
|
||||
bssid->radioid = addwlan->radioid;
|
||||
|
@ -73,7 +73,6 @@ void wtp_radio_receive_data_packet(uint8_t radioid, unsigned short binding, cons
|
||||
|
||||
/* */
|
||||
int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet);
|
||||
void wtp_radio_update_fdevent(struct wtp_fds* fds);
|
||||
|
||||
/* */
|
||||
uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid);
|
||||
|
Reference in New Issue
Block a user