cfg80211: Retrieve missing BSS info after connect
cover cfg80211: Retrieve missing BSS info after connect
This patchset attempts to address the issue where a driver that uses the cfg80211 connect operation connects to an AP before the scan result for the AP is available. This triggers a WARN_ON in sme.c, and the connection fails.
This is only an issue for drivers that do not pass beacons/probes to cfg80211, except in response to an explicit scan. With typical userspace the issue will only manifest if using iwconfig to connect, or if using wpa_supplicant with ap_scan=2 (which you might do with a hidden SSID).
The patches were originally written for the orinoco cfg80211 conversion (currently stalled due to lack of time). It sounds like the libertas cfg80211 drivers have the same problem, so I'm posting them in case they're useful. There's a bit of cleanup to do, and there may be issues with the setting of the channels to scan (orinoco can't scan by channel) so if someone wants to pick these up, please do.
Testing
- a version of this has been running with my orinoco changes for the last 3 or 4 months (in more or less daily use).
- Untested against drivers that don't use ->connect
---
David Kilroy (2):
cfg80211: generic trigger scan and callback on completion
cfg80211: scan for missing BSS on connect completion
include/net/cfg80211.h | 3 + net/wireless/core.h | 6 ++ net/wireless/scan.c | 41 ++++++++++++- net/wireless/sme.c | 163 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 178 insertions(+), 35 deletions(-)
RFC 1/2 cfg80211: generic trigger scan and callback on completion
cfg80211 SME already has a hook for it's own callback, so we hook this into the new mechanism.
We could maintain a list of functions to call, but this isn't necessary for the moment. Just maintain the single function pointer to be called on scan completion.
Note that we allow the caller to set the callback even when a scan is already in progress. This allows cfg80211 SME to scan again when the existing scan completes.
--- net/wireless/core.h | 6 ++++++ net/wireless/scan.c | 36 +++++++++++++++++++++++++++++++++++- net/wireless/sme.c | 20 +++++--------------- 3 files changed, 46 insertions(+), 16 deletions(-)
net/wireless/core.h +6 -0
@@ -63,6 +63,8 @@ struct cfg80211_registered_device {unsigned long suspend_at;struct work_struct scan_done_wk; +void (*async_scan_cb)(struct net_device *); +#ifdef CONFIG_NL80211_TESTMODE struct genl_info *testmode_info;#endif
@@ -372,6 +374,10 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev, struct net_device *dev, enum nl80211_iftype ntype, u32 *flags, struct vif_params *params);void cfg80211_process_rdev_events (struct cfg80211_registered_device *rdev); +int cfg80211_async_scan (struct wireless_dev *wdev, +struct cfg80211_scan_request *request, +bool set_cb_on_busy, +void (*cb)(struct net_device *));struct ieee80211_channel * rdev_fixed_channel(struct cfg80211_registered_device *rdev,
net/wireless/scan.c +35 -1
@@ -40,7 +40,10 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak)* Otherwise, wpa_supplicant gets completely confused with * wext events. */ -cfg80211_sme_scan_done (dev); +if (rdev->async_scan_cb) { + rdev->async_scan_cb (dev); + rdev->async_scan_cb =NULL ; + }if (request->aborted)nl80211_send_scan_aborted (rdev, dev);
@@ -655,6 +658,37 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) }EXPORT_SYMBOL (cfg80211_unlink_bss); +/* Do a scan, and schedule a callback to be run on completion. */ +int cfg80211_async_scan (struct wireless_dev *wdev, +struct cfg80211_scan_request *request, +bool set_cb_on_busy, +void (*cb)(struct net_device *)) +{ +struct cfg80211_registered_device *rdev =wiphy_to_dev (wdev->wiphy); +int err; + +ASSERT_RDEV_LOCK (rdev); + +if (rdev->scan_req) { +if (set_cb_on_busy) + rdev->async_scan_cb = cb; +return -EBUSY ; + } + + rdev->scan_req = request; + rdev->async_scan_cb = cb; + + err = rdev->ops->scan (wdev->wiphy, wdev->netdev, request); +if (!err) { +nl80211_send_scan_start (rdev, wdev->netdev); +dev_hold (wdev->netdev); + }else { + rdev->scan_req =NULL ; + } + +return err; +} +#ifdef CONFIG_CFG80211_WEXT int cfg80211_wext_siwscan(struct net_device *dev, struct iw_request_info *info,
net/wireless/sme.c +5 -15
@@ -75,17 +75,12 @@ static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);static int cfg80211_conn_scan (struct wireless_dev *wdev) { -struct cfg80211_registered_device *rdev =wiphy_to_dev (wdev->wiphy);struct cfg80211_scan_request *request;int n_channels, err;ASSERT_RTNL (); -ASSERT_RDEV_LOCK (rdev);ASSERT_WDEV_LOCK (wdev); -if (rdev->scan_req) -return -EBUSY ; -if (wdev->conn->params.channel) { n_channels =1 ; }else {
@@ -128,19 +123,14 @@ static int cfg80211_conn_scan(struct wireless_dev *wdev) request->ssids[0 ].ssid_len = wdev->conn->params.ssid_len; request->dev = wdev->netdev; - request->wiphy = &rdev->wiphy; - - rdev->scan_req = request; + request->wiphy = wdev->wiphy; - err = rdev->ops->scan (wdev->wiphy, wdev->netdev, request); -if (!err) { + err =cfg80211_async_scan (wdev, request, true, cfg80211_sme_scan_done); +if (!err) wdev->conn->state =CFG80211_CONN_SCANNING ; -nl80211_send_scan_start (rdev, wdev->netdev); -dev_hold (wdev->netdev); - }else { - rdev->scan_req =NULL ; +else kfree (request); - } +return err; }
Signature · 1 line
1.6.4.4
Johannes Berg
maintainerRe: [RFC 1/2] cfg80211: generic trigger scan and callback on completion
Quoted 7 lines · David Kilroy
We could maintain a list of functions to call, but this isn't necessary for the moment. Just maintain the single function pointer to be called on scan completion.
Note that we allow the caller to set the callback even when a scan is already in progress. This allows cfg80211 SME to scan again when the existing scan completes.
I think the "callback even when busy" thing is somewhat confusing. I'd prefer if you used a standard notifier struct (probably raw since we have rdev locking; see include/linux/notifier.h) and the callees sorted out their state there. As it is, it's really complicated to make sure that one request doesn't clobber another -- the current use guarantees that but I'm not sure I want to rely on it going forward.
johannes
RFC 2/2 cfg80211: scan for missing BSS on connect completion
In reply to David KilroySome drivers don't notify cfg80211 of every beacon or probe response they get. In this case, cfg80211 won't have the BSS structure for the AP that we just connected with.
We address that issue by doing a scan after the driver indicates it has connected. Scan for the SSID that we are in. If we have the channel, specify that as well to reduce scanning time.
--- include/net/cfg80211.h | 3 + net/wireless/scan.c | 5 ++ net/wireless/sme.c | 143 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 132 insertions(+), 19 deletions(-)
include/net/cfg80211.h +3 -0
@@ -1420,6 +1420,7 @@ extern void wiphy_free(struct wiphy *wiphy);struct cfg80211_conn ;struct cfg80211_internal_bss ;struct cfg80211_cached_keys ; +struct cfg80211_conn2 ;#define MAX_AUTH_BSSES 4
@@ -1471,6 +1472,8 @@ struct wireless_dev {struct cfg80211_conn *conn;struct cfg80211_cached_keys *connect_keys; +struct cfg80211_conn2 *conn2;/* TODO: Rename */ +struct list_head event_list;spinlock_t event_lock;
net/wireless/scan.c +5 -0
@@ -39,6 +39,11 @@ void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak)* This must be before sending the other events! * Otherwise, wpa_supplicant gets completely confused with * wext events. +* +* At the moment this will either call cfg80211_sme_scan_done +* or cfg80211_complete_connect. The former should only get +* called if the device supports ops->auth & ops->assoc, the +* latter if the device supports ops->connect. */ if (rdev->async_scan_cb) { rdev->async_scan_cb (dev);
net/wireless/sme.c +124 -19
182 lines not on this page · raw message
Signature · 1 line
1.6.4.4
Johannes Berg
maintainerRe: [RFC 2/2] cfg80211: scan for missing BSS on connect completion
net/wireless/sme.c void cfg80211_sme_failed_assoc(struct wireless_dev *wdev) · line 441
Quoted 10 lines · David Kilroy
net/wireless/sme.c +10
-0+if (wdev->conn2) { +struct cfg80211_bss *bss; + + bss =cfg80211_get_bss (wdev->wiphy,NULL , wdev->conn2->bssid, + wdev->ssid, wdev->ssid_len, +WLAN_CAPABILITY_ESS , +WLAN_CAPABILITY_ESS ); + +if (WARN_ON (!bss)) + wdev->sme_state =CFG80211_SME_IDLE ;
Can that case happen "legitimately", say the AP crashes right after you connect, possibly due to the connection?
Even if not, this will leave the driver in a different state than the state machine here, which we should clean up regardless I think.
johannes
Johannes Berg
maintainerQuoted 4 lines · David Kilroy
This patchset attempts to address the issue where a driver that uses the cfg80211 connect operation connects to an AP before the scan result for the AP is available. This triggers a
WARN_ONinsme.c, and the connection fails.
With technical comments out of the way (see other emails) I guess I want to know whether this really makes sense.
Yes, we definitely need the right BSS struct when the driver signals that it connected, but we also need the same information when it roamed for example. Does it really make sense to scan after the fact, instead of asking the driver to provide the information? This is a genuine question -- I can see value in this if more than one driver needs it, but if the devices can just provide BSS information right before the connected call that would be a lot simpler here.
johannes
Quoted 9 lines · Johannes Berg
Quoted 4 lines · David Kilroy
This patchset attempts to address the issue where a driver that uses the cfg80211 connect operation connects to an AP before the scan result for the AP is available. This triggers a
WARN_ONinsme.c, and the connection fails.With technical comments out of the way (see other emails) I guess I want to know whether this really makes sense.
Quoted 7 lines
Yes, we definitely need the right BSS struct when the driver signals that it connected, but we also need the same information when it roamed for example. Does it really make sense to scan after the fact, instead of asking the driver to provide the information? This is a genuine question -- I can see value in this if more than one driver needs it, but if the devices can just provide BSS information right before the connected call that would be a lot simpler here.
Thanks for the feedback. Like I said, the main point of posting was to see if this logic helped libertas in any way. Sounds like it doesn't, so I won't push this for now. When I get round to looking at orinoco again I'll see if I can handle this within the driver. If not I'll address the issues you've raised.
I don't think orinoco can provide the BSS info without explicitly doing the scan (whether internally or via cfg80211). Even if I could get it to work for the firmware version I have, there's no guarantee that it'll work for the other supported firmware types (that I don't have).
Dave.
Johannes Berg
maintainerQuoted 2 lines · Dave
Thanks for the feedback. Like I said, the main point of posting was to see if this logic helped libertas in any way.
Right.
Quoted 9 lines
Sounds like it doesn't, so
I won't push this for now. When I get round to looking at orinoco again I'll see if I can handle this within the driver. If not I'll address the issues you've raised.I don't think orinoco can provide the BSS info without explicitly doing the scan (whether internally or via cfg80211). Even if I could get it to work for the firmware version I have, there's no guarantee that it'll work for the other supported firmware types (that I don't have).
Ok. Don't get me wrong -- I don't really mind doing it in cfg80211, just wanted to see why, but if it really _requires_ a scan then that's fine. Maybe in cfg80211 makes more sense, might simplify other drivers too, or allow us to convert some of the other drivers that might not have such functionality.
Since your patch creates a directed scan, it should be pretty quick just scanning one channel, and maybe the driver knows the channel?
johannes
Quoted 2 lines
It sounds like the libertas cfg80211 drivers have the same problem, so I'm posting them in case they're useful.
I'm not sure about that.
One thing that I'm sure of is that for the Libertas case I need to scan *before* the connection takes place. The Libertas firmware doesn't roam by itself, so I don't tell her an SSID like you'll tell the orinoco firmware.
Instead the libertas firmware needs a BSSID where it should connect to. If you let do wpa_supplicant do the job (even for WEP), that's no problem, because wpa_supplicant always scans and then connects to a specific BSSID, which suits Libertas very well.
As for sending back then cfg80211_connect_result() to cfg80211, I'm using the IEs from the firmware CMD_802_11_ASSOCIATE command, which seems to work quite nicely.
The only thing where Libertas would need a scan during connect if someone tries to connect to an AP without a previous scan using the "iw wlan0 connect" command. Not sure what Simon did here, but my previous v4 patch simply failed.
Signature · 1 line
http://www.holgerschurig.de
Quoted 5 lines · Holger Schurig
Quoted 2 lines
It sounds like the libertas cfg80211 drivers have the same problem, so I'm posting them in case they're useful.
I'm not sure about that.
Quoted 8 lines
One thing that I'm sure of is that for the Libertas case I need to scan *before* the connection takes place. The Libertas firmware doesn't roam by itself, so I don't tell her an SSID like you'll tell the orinoco firmware.
Instead the libertas firmware needs a BSSID where it should connect to. If you let do
wpa_supplicantdo the job (even for WEP), that's no problem, becausewpa_supplicantalways scans and then connects to a specific BSSID, which suits Libertas very well.
Fair enough. If I find the time to finish orinoco cfg80211, then I'll try to keep this within the driver.
Dave.