Patchwork [15/18] driver_nl80211: subscribe to spurious class3 frame events

login
register
mail settings
Submitter Johannes Berg
Date Nov. 4, 2011, 10:38 a.m.
Message ID <20111104103812.394367400@sipsolutions.net>
Download mbox | patch
Permalink /patch/123600/
State Superseded
Headers show

Comments

Johannes Berg - Nov. 4, 2011, 10:38 a.m.
From: Johannes Berg <johannes.berg@intel.com>

These events are necessary to send deauth frames to
stations sending spurious data frames. Subscribe to
them on the per-BSS event socket.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
---
 src/drivers/driver_nl80211.c |   56 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index a763bbe..3be461c 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1735,6 +1735,27 @@  static void nl80211_client_probe_event(struct wpa_driver_nl80211_data *drv,
 }
 
 
+static void nl80211_spurious_class3_frame(struct i802_bss *bss,
+					  struct nlattr **tb)
+{
+	struct wpa_driver_nl80211_data *drv = bss->drv;
+	union wpa_event_data event;
+	u8 bssid[ETH_ALEN];
+
+	if (!tb[NL80211_ATTR_MAC])
+		return;
+
+	if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, bssid) < 0)
+		return;
+
+	os_memset(&event, 0, sizeof(event));
+	event.rx_from_unknown.bssid = bssid;
+	event.rx_from_unknown.addr = nla_data(tb[NL80211_ATTR_MAC]);
+
+	wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event);
+}
+
+
 static int process_drv_event(struct nl_msg *msg, void *arg)
 {
 	struct wpa_driver_nl80211_data *drv = arg;
@@ -1886,6 +1907,9 @@  static int process_bss_event(struct nl_msg *msg, void *arg)
 			   tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK],
 			   tb[NL80211_ATTR_COOKIE]);
 		break;
+	case NL80211_CMD_UNEXPECTED_FRAME:
+		nl80211_spurious_class3_frame(bss, tb);
+		break;
 	default:
 		wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event "
 			   "(cmd=%d)", gnlh->cmd);
@@ -2665,6 +2689,35 @@  static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
 }
 
 
+static int nl80211_register_spurious_class3(struct i802_bss *bss)
+{
+	struct wpa_driver_nl80211_data *drv = bss->drv;
+	struct nl_msg *msg;
+	int ret = -1;
+
+	msg = nlmsg_alloc();
+	if (!msg)
+		return -1;
+
+	nl80211_cmd(drv, msg, 0, NL80211_CMD_UNEXPECTED_FRAME);
+
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
+
+	ret = send_and_recv(drv, bss->nl_mgmt.handle, msg, NULL, NULL);
+	msg = NULL;
+	if (ret) {
+		wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
+			   "failed: ret=%d (%s)",
+			   ret, strerror(-ret));
+		goto nla_put_failure;
+	}
+	ret = 0;
+nla_put_failure:
+	nlmsg_free(msg);
+	return ret;
+}
+
+
 static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
 {
 	static const int stypes[] = {
@@ -2696,6 +2749,9 @@  static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
 		}
 	}
 
+	if (nl80211_register_spurious_class3(bss))
+		goto out_err;
+
 	return 0;
 
  out_err: