Skip to contentSkip to conversation

wireless: Allow registering more than one beacon listener.

PATCH Superseded [email protected] 2 participants 2 messages Oct 26, 2012 802.11 (including cfg80211/NL80211)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wireless: Allow registering more than one beacon listener.

From: Ben Greear <[email protected]>

The commit:

commit 5e760230e42cf759bd923457ca2753aacf2e656e

Author: Johannes Berg <[email protected]>
Date:   Fri Nov 4 11:18:17 2011 +0100

cfg80211: allow registering to beacons

allowed only a single process to register for beacon events per wiphy. This breaks cases where a user may want two or more VIFs on a wiphy and run a seperate hostapd process on each vif.

This patch allows multiple beacon listeners, fixing the regression.

---
 net/wireless/core.c    |    7 ++++
 net/wireless/core.h    |    7 +++-
 net/wireless/nl80211.c |   86 +++++++++++++++++++++++++++++++++--------------
 3 files changed, 73 insertions(+), 27 deletions(-)
net/wireless/core.c +7 -0
index f280f48..19f789f 100644
@@ -326,6 +326,8 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
 	mutex_init(&rdev->devlist_mtx);
 	mutex_init(&rdev->sched_scan_mtx);
 	INIT_LIST_HEAD(&rdev->wdev_list);
+	INIT_LIST_HEAD(&rdev->beacon_registrations);
+	spin_lock_init(&rdev->beacon_registrations_lock);
 	spin_lock_init(&rdev->bss_lock);
 	INIT_LIST_HEAD(&rdev->bss_list);
 	INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
@@ -699,10 +701,15 @@ EXPORT_SYMBOL(wiphy_unregister);
 void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
 {
 	struct cfg80211_internal_bss *scan, *tmp;
+	struct cfg80211_beacon_registration *reg, *treg;
 	rfkill_destroy(rdev->rfkill);
 	mutex_destroy(&rdev->mtx);
 	mutex_destroy(&rdev->devlist_mtx);
 	mutex_destroy(&rdev->sched_scan_mtx);
+	list_for_each_entry_safe(reg, treg, &rdev->beacon_registrations, list) {
+		list_del(&reg->list);
+		kfree(reg);
+	}
 	list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list)
 		cfg80211_put_bss(&scan->pub);
 	kfree(rdev);
net/wireless/core.h +6 -1
index b8eb743..e53831c 100644
@@ -55,7 +55,8 @@ struct cfg80211_registered_device {
 	int opencount; /* also protected by devlist_mtx */
 	wait_queue_head_t dev_wait;
 
-	u32 ap_beacons_nlportid;
+	struct list_head beacon_registrations;
+	spinlock_t beacon_registrations_lock;
 
 	/* protected by RTNL only */
 	int num_running_ifaces;
@@ -260,6 +261,10 @@ enum cfg80211_chan_mode {
 	CHAN_MODE_EXCLUSIVE,
 };
 
+struct cfg80211_beacon_registration {
+	struct list_head list;
+	u32 nlportid;
+};
 
 /* free object */
 extern void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
net/wireless/nl80211.c +60 -26

127 lines not on this page · raw message

Signature · 1 line
1.7.3.4
maintainer
#1 lore raw

Thanks Ben,

A few small comments:

net/wireless/nl80211.c static int nl80211_probe_client(struct sk_buff *skb,

Quoted 3 lines
net/wireless/nl80211.c +2 -0
+	nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
 
+	memset(nreg, 0, sizeof(*nreg));

that memset isn't needed after kzalloc :)

net/wireless/nl80211.c void cfg80211_report_obss_beacon(struct wiphy *wiphy, · line 8963

Quoted 3 lines
net/wireless/nl80211.c +3 -0
+	spin_lock_bh(&rdev->beacon_registrations_lock);
+	list_for_each_entry(reg, &rdev->beacon_registrations, list) {
+		msg = nlmsg_new(len + 100, gfp);

since you're in the locked section, you can't use "gfp" any more and have to use GFP_ATOMIC, so we could even consider removing the gfp argument to the function.

net/wireless/nl80211.c void cfg80211_report_obss_beacon(struct wiphy *wiphy, · line 8973

Quoted 5 lines
net/wireless/nl80211.c +5 -0
+		hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
+		if (!hdr) {
+			spin_unlock_bh(&rdev->beacon_registrations_lock);
+			nlmsg_free(msg);
+			return;

it seems this should be some goto since nla_put_failure is also a label?

net/wireless/nl80211.c static int nl80211_netlink_notify(struct notifier_block * nb, · line 9021

Quoted 6 lines
net/wireless/nl80211.c +6 -0
+		spin_lock_bh(&rdev->beacon_registrations_lock);
+		list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
+					 list) {
+			if (reg->nlportid == notify->portid) {
+				list_del(&reg->list);
+				kfree(reg);

You could break here, but it doesn't matter much.

johannes