Skip to contentSkip to conversation

nl80211: implement NL80211_CMD_GET_BEACON command

RFC PATCH In review Sergey Matyukevich 2 participants 9 messages Nov 9, 2017 – Dec 19, 2017 802.11 (including cfg80211/NL80211)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 nl80211: implement NL80211_CMD_GET_BEACON command

From: Vasily Ulyanov <[email protected]>

Implement nl80211_get_beacon callback which returns current beacon configuration. The actual data is saved on .start_ap and .set_beacon calls.

---
 include/net/cfg80211.h       |   3 +
 include/uapi/linux/nl80211.h |   5 +-
 net/wireless/nl80211.c       | 220 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 227 insertions(+), 1 deletion(-)
include/net/cfg80211.h +3 -0
index 8b8118a7fadb..31d39e066274 100644
@@ -4002,6 +4002,8 @@ struct cfg80211_cqm_config;
  *	the user-set channel definition.
  * @preset_chandef: (private) Used by the internal configuration code to
  *	track the channel to be used for AP later
+ * @beacon: (private) Used by the internal configuration code to track
+ *	the user-set effective beacon data.
  * @bssid: (private) Used by the internal configuration code
  * @ssid: (private) Used by the internal configuration code
  * @ssid_len: (private) Used by the internal configuration code
@@ -4078,6 +4080,7 @@ struct wireless_dev {
 	struct cfg80211_internal_bss *current_bss; /* associated / joined */
 	struct cfg80211_chan_def preset_chandef;
 	struct cfg80211_chan_def chandef;
+	struct cfg80211_beacon_data beacon;
 
 	bool ibss_fixed;
 	bool ibss_dfs_possible;
include/uapi/linux/nl80211.h +4 -1
index f882fe1f9709..e9e163bbe11a 100644
@@ -279,7 +279,10 @@
  * @NL80211_CMD_DEL_KEY: delete a key identified by %NL80211_ATTR_KEY_IDX
  *	or %NL80211_ATTR_MAC.
  *
- * @NL80211_CMD_GET_BEACON: (not used)
+ * @NL80211_CMD_GET_BEACON: Get beacon attributes on an access point interface.
+ *	%NL80211_ATTR_BEACON_HEAD, %NL80211_ATTR_BEACON_TAIL, %NL80211_ATTR_IE,
+ *	%NL80211_ATTR_IE_PROBE_RESP, NL80211_ATTR_IE_ASSOC_RESP,
+ *	%NL80211_ATTR_PROBE_RESP will be returned if present.
  * @NL80211_CMD_SET_BEACON: change the beacon on an access point interface
  *	using the %NL80211_ATTR_BEACON_HEAD and %NL80211_ATTR_BEACON_TAIL
  *	attributes. For drivers that generate the beacon and probe responses
net/wireless/nl80211.c +220 -0

274 lines not on this page · raw message

Signature · 1 line
2.11.0
#1 lore raw

RFC PATCH 2/2 nl80211: implement beacon change notifier

From: Vasily Ulyanov <[email protected]>

Notify user-space listeners about beacon data change.

---
 net/wireless/nl80211.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
net/wireless/nl80211.c +26 -1
index f03f9989efbc..98e52e5ffc13 100644
@@ -3950,6 +3950,26 @@ static int nl80211_send_beacon(struct sk_buff *msg, u32 portid,
 	return -EMSGSIZE;
 }
 
+static void nl80211_notify_beacon_change(struct net_device *dev,
+					 enum nl80211_commands cmd,
+					 struct cfg80211_beacon_data *bcn)
+{
+	struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
+	struct sk_buff *msg;
+
+	msg = nlmsg_new(nl80211_beacon_size(bcn), GFP_KERNEL);
+	if (!msg)
+		return;
+
+	if (nl80211_send_beacon(msg, cmd, 0, 0, 0, bcn) < 0) {
+		nlmsg_free(msg);
+		return;
+	}
+
+	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
+				NL80211_MCGRP_MLME, GFP_KERNEL);
+}
+
 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
 					    const u8 *rates)
 {
@@ -4250,6 +4270,8 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
 		wdev->ssid_len = params.ssid_len;
 		memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
 		nl80211_assign_beacon(&wdev->beacon, &new_bcn);
+		nl80211_notify_beacon_change(dev, NL80211_CMD_START_AP,
+					     &wdev->beacon);
 	}
 	wdev_unlock(wdev);
 
@@ -4317,8 +4339,11 @@ static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
 
 	wdev_lock(wdev);
 	err = rdev_change_beacon(rdev, dev, &params);
-	if (!err)
+	if (!err) {
 		nl80211_assign_beacon(&wdev->beacon, &merged_bcn);
+		nl80211_notify_beacon_change(dev, NL80211_CMD_SET_BEACON,
+					     &wdev->beacon);
+	}
 	wdev_unlock(wdev);
 
 	if (err)
Signature · 1 line
2.11.0
maintainer
#2 lore raw

Re: [RFC PATCH 2/2] nl80211: implement beacon change notifier

Quoted 3 lines · Sergey Matyukevich

From: Vasily Ulyanov <[email protected]>

Notify user-space listeners about beacon data change.

What would this be needed for, and why couldn't you just directly talk to hostapd/wpa_s?

johannes

#3 lore raw

Re: [RFC PATCH 2/2] nl80211: implement beacon change notifier

Hello Johannes and all,

Quoted 6 lines
Quoted 3 lines

From: Vasily Ulyanov <[email protected]>

Notify user-space listeners about beacon data change.

What would this be needed for, and why couldn't you just directly talk to hostapd/wpa_s?

I apologize for email duplication, but it looks like reply from Vasily has been rejected due to Outlook issues. While we choose between mutt and gnus, here I briefly repeat the rationale behind these RFC patches.

The nl80211 get_beacon callback appears to be useful in the case when userspace software needs to retrieve current operational parameters of AP including HT/VHT IEs. In fact we considered two implementation options:
to implement this functionality either in hostapd (extending its hostapd_cli interface) or in kernel (adding nl80211 call).

We decided to try nl80211 since there was a stub for NL80211_CMD_GET_BEACON operation. Beacon change notifier was introduced due to the following reason:
if anyone is interested in AP operational params, then he might be also interested to know when those params are changed.

Regards,
Sergey

maintainer
#4 lore raw

Re: [RFC PATCH 2/2] nl80211: implement beacon change notifier

Hi,

Quoted 3 lines

I apologize for email duplication, but it looks like reply from Vasily has been rejected due to Outlook issues. While we choose between mutt and gnus, here I briefly repeat the rationale behind these RFC patches.

:)

Quoted 3 lines

The nl80211 get_beacon callback appears to be useful in the case when userspace software needs to retrieve current operational parameters of AP including HT/VHT IEs.

Do you have any usage in mind though? I can't really see where this would really make sense, rather than getting direct hooks for the bits you needed in hostapd.

For example, if you care about the channel bandwidth changing, wouldn't it be more efficient to just add a signal to hostapd rather than listening to beacon updates and parsing, etc.?

johannes

#5 lore raw

Re: [RFC PATCH 2/2] nl80211: implement beacon change notifier

Hello Johannes,

Quoted 11 lines
Quoted 3 lines

The nl80211 get_beacon callback appears to be useful in the case when userspace software needs to retrieve current operational parameters of AP including HT/VHT IEs.

Do you have any usage in mind though? I can't really see where this would really make sense, rather than getting direct hooks for the bits you needed in hostapd.

For example, if you care about the channel bandwidth changing, wouldn't it be more efficient to just add a signal to hostapd rather than listening to beacon updates and parsing, etc.?

In our case, we are experimenting with applications running along with hostapd and enabling band steering and client roaming functionality. As I mentioned, various approaches are being examined, including both pure nl80211-based approach as well as adding direct hooks to hostapd.

Regards,
Sergey

maintainer
#6 lore raw

Re: [RFC PATCH 2/2] nl80211: implement beacon change notifier

Quoted 5 lines · Sergey Matyukevich

In our case, we are experimenting with applications running along with hostapd and enabling band steering and client roaming functionality. As I mentioned, various approaches are being examined, including both pure nl80211-based approach as well as adding direct hooks to hostapd.

To be honest, I'm torn on this.

On the one hand, I think it's fairly reasonable functionality, but on the other hand I'm not sure we should encourage such separate approaches - it seems to me that will lead to a lot of fragmentation and much harder debuggability for upstream where these things get used.

It's also a bunch of code we have to maintain, for nothing that seems of use to the community - since it's the sort of flexibility explicitly designed for non-public code (otherwise it could just be part of hostapd; actually it could even if it were non-public, at least in theory, unless you're planning it as a value-add thing to go with an open source hostapd ...).

So while I don't want to stop you entirely in your tracks with this, I'd really prefer you explore other options regarding where to put your client steering functionality, perhaps even working on hostapd.

johannes

#7 lore raw

Re: [RFC PATCH 2/2] nl80211: implement beacon change notifier

Hello Johannes,

Quoted 20 lines
Quoted 5 lines

In our case, we are experimenting with applications running along with hostapd and enabling band steering and client roaming functionality. As I mentioned, various approaches are being examined, including both pure nl80211-based approach as well as adding direct hooks to hostapd.

To be honest, I'm torn on this.

On the one hand, I think it's fairly reasonable functionality, but on the other hand I'm not sure we should encourage such separate approaches - it seems to me that will lead to a lot of fragmentation and much harder debuggability for upstream where these things get used.

It's also a bunch of code we have to maintain, for nothing that seems of use to the community - since it's the sort of flexibility explicitly designed for non-public code (otherwise it could just be part of hostapd; actually it could even if it were non-public, at least in theory, unless you're planning it as a value-add thing to go with an open source hostapd ...).

Quoted 3 lines

So while I don't want to stop you entirely in your tracks with this, I'd really prefer you explore other options regarding where to put your client steering functionality, perhaps even working on hostapd.

Well, our preferred approach for these experiments is going to be communication with hostapd instead of kernel. One of the reasons is that GET_CMD_BEACON is not enough. We have to enable multiple listeners of mgmt frames as well. However that feature was rejected earlier this year: https://patchwork.kernel.org/patch/9615697

By the way, speaking about GET_CMD_BEACON and its possible users in the community. There is already a stub for it in nl80211 uapi headers. What was the original idea for that ? Or was it just a placeholder added together with SET_BEACON ?

Regards,
Sergey

maintainer
#8 lore raw

Re: [RFC PATCH 2/2] nl80211: implement beacon change notifier

Hi Sergey,

Sorry for the long delay.

Quoted 5 lines · Sergey Matyukevich

By the way, speaking about GET_CMD_BEACON and its possible users in the community. There is already a stub for it in nl80211 uapi headers. What was the original idea for that ? Or was it just a placeholder added together with SET_BEACON ?

I think it was a placeholder, you can probably find it in git history. I vaguely remember thinking - many years ago - that all the operations should consistently support add, del, set and get, but that isn't really all that practical.

johannes