Patchwork [v3,09/15] driver_nl80211: allocate nl CB for BSS RX

login
register
mail settings
Submitter Johannes Berg
Date Nov. 19, 2011, 12:39 p.m.
Message ID <20111119123952.093112599@sipsolutions.net>
Download mbox | patch
Permalink /patch/126576/
State Accepted
Commit cc7a48d1f4e80e1d3d55c9801e574c55da4562f1
Headers show

Comments

Johannes Berg - Nov. 19, 2011, 12:39 p.m.
From: Johannes Berg <johannes.berg@intel.com>

In preparation for things that receive on a
BSS-specific handle, allocate a CB for it and
hook it up to receive functions.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
---
 src/drivers/driver_nl80211.c |   49 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
Jouni Malinen - Dec. 3, 2011, 6:15 p.m.
On Sat, Nov 19, 2011 at 01:39:19PM +0100, Johannes Berg wrote:
> In preparation for things that receive on a
> BSS-specific handle, allocate a CB for it and
> hook it up to receive functions.

Thanks, applied.

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 40de7ac..a26245a 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -192,6 +192,7 @@  struct i802_bss {
 	int freq;
 
 	struct nl80211_handles nl_preq;
+	struct nl_cb *nl_cb;
 };
 
 struct wpa_driver_nl80211_data {
@@ -1846,6 +1847,25 @@  static int process_drv_event(struct nl_msg *msg, void *arg)
 }
 
 
+static int process_bss_event(struct nl_msg *msg, void *arg)
+{
+	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+	struct nlattr *tb[NL80211_ATTR_MAX + 1];
+
+	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+		  genlmsg_attrlen(gnlh, 0), NULL);
+
+	switch (gnlh->cmd) {
+	default:
+		wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event "
+			   "(cmd=%d)", gnlh->cmd);
+		break;
+	}
+
+	return NL_SKIP;
+}
+
+
 static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
 					     void *handle)
 {
@@ -2362,6 +2382,28 @@  static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, void *eloop_ctx,
 }
 
 
+static int nl80211_init_bss(struct i802_bss *bss)
+{
+	bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
+	if (!bss->nl_cb)
+		return -1;
+
+	nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
+		  no_seq_check, NULL);
+	nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
+		  process_bss_event, bss);
+
+	return 0;
+}
+
+
+static void nl80211_destroy_bss(struct i802_bss *bss)
+{
+	nl_cb_put(bss->nl_cb);
+	bss->nl_cb = NULL;
+}
+
+
 /**
  * wpa_driver_nl80211_init - Initialize nl80211 driver interface
  * @ctx: context to be used when calling wpa_supplicant functions,
@@ -2399,6 +2441,9 @@  static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 		return NULL;
 	}
 
+	if (nl80211_init_bss(bss))
+		goto failed;
+
 	nl80211_get_phy_name(drv);
 
 	rcfg = os_zalloc(sizeof(*rcfg));
@@ -2710,6 +2755,8 @@  static void wpa_driver_nl80211_deinit(void *priv)
 	nl_destroy_handles(&drv->nl_event);
 	nl_cb_put(drv->nl_cb);
 
+	nl80211_destroy_bss(&drv->first_bss);
+
 	os_free(drv->filter_ssids);
 
 	if (drv->in_interface_list)
@@ -6907,6 +6954,7 @@  static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
 		drv->first_bss.next = new_bss;
 		if (drv_priv)
 			*drv_priv = new_bss;
+		nl80211_init_bss(new_bss);
 	}
 #endif /* HOSTAPD */
 
@@ -6958,6 +7006,7 @@  static int wpa_driver_nl80211_if_remove(void *priv,
 		for (tbss = &drv->first_bss; tbss; tbss = tbss->next) {
 			if (tbss->next == bss) {
 				tbss->next = bss->next;
+				nl80211_destroy_bss(bss);
 				os_free(bss);
 				bss = NULL;
 				break;