Created a patch for mac80211 that allows to capture the raw IEEE80211 packets

(management, control, data) of one or more wireless interfaces.
Not necessary the monitor interface. The patch allows to discriminate which
IEEE802.11 types and IEEE802.11 subtypes capture.
This commit is contained in:
vemax78
2014-06-04 22:58:34 +02:00
parent 0ebf1a434f
commit 92c86462dc
7 changed files with 586 additions and 44 deletions

View File

@ -6,6 +6,7 @@
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include "wtp_kmod.h"
/* Local version of nl80211 with all feature to remove the problem of frag version of nl80211 */
#include "nl80211_v3_10.h"
@ -353,7 +354,7 @@ static int nl80211_device_changefrequency(struct wifi_device* device, struct wif
/* Set wifi frequency */
result = nl80211_send_and_recv_msg(devicehandle->globalhandle, msg, NULL, NULL);
if (!result) {
capwap_logging_error("Change %s frequency %d", wlan->virtname, (int)freq->frequency);
capwap_logging_info("Change %s frequency %d", wlan->virtname, (int)freq->frequency);
} else {
capwap_logging_error("Unable set frequency %d, error code: %d", (int)freq->frequency, result);
}
@ -802,6 +803,11 @@ static int nl80211_wlan_startap(struct wifi_wlan* wlan) {
wlan->flags |= WIFI_WLAN_OPERSTATE_RUNNING;
netlink_set_link_status(wlanhandle->devicehandle->globalhandle->netlinkhandle, wlan->virtindex, -1, IF_OPER_UP);
/* */
if (!wtp_kmod_join_mac80211_device(wlan->virtindex)) {
capwap_logging_info("Joined in kernel mode the interface %d", wlan->virtindex);
}
return 0;
}

View File

@ -145,7 +145,7 @@ static int wtp_kmod_send_and_recv_msg(struct nl_msg* msg, wtp_kmod_valid_cb vali
}
/* */
static int wtp_kmod_connect(void) {
static int wtp_kmod_link(void) {
int result;
struct nl_msg* msg;
@ -156,7 +156,7 @@ static int wtp_kmod_connect(void) {
}
/* */
genlmsg_put(msg, 0, 0, g_kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_CONNECT, 0);
genlmsg_put(msg, 0, 0, g_kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_LINK, 0);
/* */
result = wtp_kmod_send_and_recv_msg(msg, NULL, NULL);
@ -173,6 +173,38 @@ static int wtp_kmod_connect(void) {
return result;
}
/* */
int wtp_kmod_join_mac80211_device(uint32_t ifindex) {
int result;
struct nl_msg* msg;
/* */
if (!g_kmodhandle.nlsmartcapwap_id) {
return -1;
}
/* */
msg = nlmsg_alloc();
if (!msg) {
return -1;
}
/* */
genlmsg_put(msg, 0, 0, g_kmodhandle.nlsmartcapwap_id, 0, 0, NLSMARTCAPWAP_CMD_JOIN_MAC80211_DEVICE, 0);
nla_put_u32(msg, NLSMARTCAPWAP_ATTR_IFINDEX, ifindex);
nla_put_u16(msg, NLSMARTCAPWAP_ATTR_DATA_SUBTYPE_MASK, 0xffff);
/* */
result = wtp_kmod_send_and_recv_msg(msg, NULL, NULL);
if (result) {
capwap_logging_warning("Unable to join with interface: %d", ifindex);
}
/* */
nlmsg_free(msg);
return result;
}
/* */
int wtp_kmod_init(void) {
int result;
@ -197,6 +229,7 @@ int wtp_kmod_init(void) {
/* Get nlsmartcapwap netlink family */
g_kmodhandle.nlsmartcapwap_id = genl_ctrl_resolve(g_kmodhandle.nl, SMARTCAPWAP_GENL_NAME);
if (g_kmodhandle.nlsmartcapwap_id < 0) {
capwap_logging_warning("Unable to found kernel module");
wtp_kmod_free();
return -1;
}
@ -205,8 +238,8 @@ int wtp_kmod_init(void) {
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);
/* Connect to kernel module */
result = wtp_kmod_connect();
/* Link to kernel module */
result = wtp_kmod_link();
if (result) {
wtp_kmod_free();
return result;
@ -224,4 +257,7 @@ void wtp_kmod_free(void) {
if (g_kmodhandle.nl_cb) {
nl_cb_put(g_kmodhandle.nl_cb);
}
/* */
memset(&g_kmodhandle, 0, sizeof(struct wtp_kmod_handle));
}

View File

@ -5,4 +5,7 @@
int wtp_kmod_init(void);
void wtp_kmod_free(void);
/* */
int wtp_kmod_join_mac80211_device(uint32_t ifindex);
#endif /* __WTP_KMOD_HEADER__ */