mac80211/cfg80211 scan improvements
Johannes Berg
maintainerv3 cover mac80211/cfg80211 scan improvements
We currently don't tell userspace what the max IE length is, fix that. We also have hw_scan build the probe request, which is not necessary, mac80211 can do that.
I have, but will submit over a different channel, a patch to fix up iwlwifi to support proper scanning after this series.
johannes
Johannes Berg
maintainerPATCH v3 1/3 cfg80211: introduce scan IE limit attribute
This patch introduces a new attribute for a wiphy that tells userspace how long the information elements added to a probe request frame can be at most. It also updates the at76 to advertise that it cannot support that, and, for now until I can fix that, iwlwifi too.
--- drivers/net/wireless/at76c50x-usb.c | 1 + drivers/net/wireless/iwlwifi/iwl-core.c | 1 + include/linux/nl80211.h | 4 ++++ include/net/wireless.h | 1 + net/mac80211/main.c | 13 ++++++++++++- net/mac80211/util.c | 2 ++ net/wireless/nl80211.c | 7 +++++++ 7 files changed, 28 insertions(+), 1 deletion(-)
include/net/wireless.h +1 -0
@@ -222,6 +222,7 @@ struct wiphy {int bss_priv_size;u8 max_scan_ssids; +u16 max_scan_ie_len;/* If multiple wiphys are registered and you're handed e.g. * a regular netdev with assigned ieee80211_ptr, you won't
net/wireless/nl80211.c +7 -0
@@ -151,6 +151,8 @@ static int nl80211_send_wiphy(struct sk_NLA_PUT_STRING (msg,NL80211_ATTR_WIPHY_NAME ,wiphy_name (&dev->wiphy));NLA_PUT_U8 (msg,NL80211_ATTR_MAX_NUM_SCAN_SSIDS , dev->wiphy.max_scan_ssids); +NLA_PUT_U16 (msg,NL80211_ATTR_MAX_SCAN_IE_LEN , + dev->wiphy.max_scan_ie_len); nl_modes =nla_nest_start (msg,NL80211_ATTR_SUPPORTED_IFTYPES );if (!nl_modes)
@@ -2492,6 +2494,11 @@ static int nl80211_trigger_scan(struct selse ie_len =0 ; +if (ie_len > wiphy->max_scan_ie_len) { + err = -EINVAL ; + goto out; + } + request =kzalloc (sizeof (*request) +sizeof (*ssid) * n_ssids + sizeof(channel) * n_channels
include/linux/nl80211.h +4 -0
@@ -380,6 +380,8 @@ enum nl80211_commands {* * @NL80211_ATTR_MAX_NUM_SCAN_SSIDS: number of SSIDs you can scan with * a single scan request, a wiphy attribute. +* @NL80211_ATTR_MAX_SCAN_IE_LEN: maximum length of information elements +* that can be added to a scan request * * @NL80211_ATTR_SCAN_FREQUENCIES: nested attribute with frequencies (in MHz) * @NL80211_ATTR_SCAN_SSIDS: nested attribute with SSIDs, leave out for passive
@@ -492,6 +494,8 @@ enum nl80211_attrs {NL80211_ATTR_AUTH_TYPE ,NL80211_ATTR_REASON_CODE , +NL80211_ATTR_MAX_SCAN_IE_LEN , +/* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST,
net/mac80211/main.c +12 -1
@@ -724,7 +724,18 @@ struct ieee80211_hw *ieee80211_alloc_hw(return NULL ; wiphy->privid = mac80211_wiphy_privid; - wiphy->max_scan_ssids =4 ; + +if (!ops->hw_scan) { +/* For hw_scan, driver needs to set these up. */ + wiphy->max_scan_ssids =4 ; + +/* we support a maximum of 32 rates in cfg80211 */ + wiphy->max_scan_ie_len =IEEE80211_MAX_DATA_LEN + -2 -32 /* SSID */ + -4 -32 /* (ext) supp rates */ ; + + } +/* Yes, putting cfg80211_bss into ieee80211_bss is a hack */ wiphy->bss_priv_size =sizeof (struct ieee80211_bss ) -sizeof (struct cfg80211_bss );
net/mac80211/util.c +2 -0
@@ -891,6 +891,8 @@ void ieee80211_send_probe_req(struct iee *pos = rate->bitrate /5 ; } +/* if adding more here, adjust max_scan_ie_len */ +if (ie)memcpy (skb_put (skb, ie_len), ie, ie_len);
drivers/net/wireless/at76c50x-usb.c +1 -0
@@ -2248,6 +2248,7 @@ static int at76_init_new_device(struct a/* mac80211 initialisation */ priv->hw->wiphy->max_scan_ssids =1 ; + priv->hw->wiphy->max_scan_ie_len =0 ; priv->hw->wiphy->interface_modes =BIT (NL80211_IFTYPE_STATION ); priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ ] = &at76_supported_band; priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
drivers/net/wireless/iwlwifi/iwl-core.c +1 -0
@@ -1306,6 +1306,7 @@ int iwl_setup_mac(struct iwl_priv *priv) hw->wiphy->custom_regulatory = true; hw->wiphy->max_scan_ssids =1 ; + hw->wiphy->max_scan_ie_len =0 ;/* XXX for now */ /* Default value; 4 EDCA QOS priorities */ hw->queues =4 ;
Johannes Berg
maintainerPATCH v3 2/3 mac80211: pass all probe request IEs to driver
In reply to Johannes BergInstead of just passing the cfg80211-requested IEs, pass the locally generated ones as well.
---
v2: * assume wiphy->max_scan_ie_len contains the limit *including*
the IEs mac80211 passes (since the driver cannot know how long those will be) and adjust the driver's limit accordingly
* keep track of original IEs and hand back the pristine cfg80211 request structure
* mark the IE pointer const in the request struct
v3: * move code to correct place (register_hw)
* calculate upper limit for userspace scan IEs more accurately
include/net/cfg80211.h | 2 - include/net/mac80211.h | 13 ++++--- net/mac80211/ieee80211_i.h | 9 +++-- net/mac80211/main.c | 49 +++++++++++++++++++-------- net/mac80211/scan.c | 24 +++++++++++++ net/mac80211/util.c | 79 +++++++++++++++++++++++++++------------------ net/wireless/nl80211.c | 3 + 7 files changed, 123 insertions(+), 56 deletions(-)
include/net/mac80211.h +8 -5
@@ -1330,11 +1330,14 @@ enum ieee80211_ampdu_mlme_action {* the scan state machine in stack. The scan must honour the channel * configuration done by the regulatory agent in the wiphy's * registered bands. The hardware (or the driver) needs to make sure -* that power save is disabled. When the scan finishes, -* ieee80211_scan_completed() must be called; note that it also must -* be called when the scan cannot finish because the hardware is -* turned off! Anything else is a bug! Returns a negative error code -* which will be seen in userspace. +* that power save is disabled. +* The @req ie/ie_len members are rewritten by mac80211 to contain the +* entire IEs after the SSID, so that drivers need not look at these +* at all but just send them after the SSID -- mac80211 includes the +* (extended) supported rates and HT information (where applicable). +* When the scan finishes, ieee80211_scan_completed() must be called; +* note that it also must be called when the scan cannot finish due to +* any error unless this callback returned a negative error code. * * @sw_scan_start: Notifier function that is called just before a software scan * is started. Can be NULL, if the driver doesn't need this notification.
net/mac80211/ieee80211_i.h +7 -2
@@ -671,7 +671,10 @@ struct ieee80211_local {struct cfg80211_scan_request int_scan_req;struct cfg80211_scan_request *scan_req;struct ieee80211_channel *scan_channel; +const u8 *orig_ies; +int orig_ies_len;int scan_channel_idx; +int scan_ies_len;enum {SCAN_SET_CHANNEL ,SCAN_SEND_PROBE } scan_state;unsigned long last_scan_completed;
@@ -1093,9 +1096,11 @@ void ieee80211_send_auth(struct ieee8021 u16 transaction, u16 auth_alg, u8 *extra, size_t extra_len, const u8 *bssid, int encrypt); +int ieee80211_build_preq_ies (struct ieee80211_local *local,u8 *buffer, +const u8 *ie,size_t ie_len);void ieee80211_send_probe_req (struct ieee80211_sub_if_data *sdata,u8 *dst, -u8 *ssid,size_t ssid_len, -u8 *ie,size_t ie_len); +const u8 *ssid,size_t ssid_len, +const u8 *ie,size_t ie_len); void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, const size_t supp_rates_len,
net/mac80211/util.c +48 -31
97 lines not on this page · raw message
net/mac80211/main.c +34 -15
87 lines not on this page · raw message
net/mac80211/scan.c +23 -1
@@ -286,6 +286,12 @@ void ieee80211_scan_completed(struct ieeif (WARN_ON (!local->scan_req))return ; +if (local->hw_scanning) { +kfree (local->scan_req->ie); + local->scan_req->ie = local->orig_ies; + local->scan_req->ie_len = local->orig_ies_len; + } +if (local->scan_req != &local->int_scan_req)cfg80211_scan_done (local->scan_req, aborted); local->scan_req =NULL ;
@@ -456,12 +462,28 @@ int ieee80211_start_scan(struct ieee8021 }if (local->ops->hw_scan) { -int rc; +u8 *ies; +int rc, ielen; + + ies =kmalloc (2 +IEEE80211_MAX_SSID_LEN + + local->scan_ies_len + req->ie_len,GFP_KERNEL ); +if (!ies) +return -ENOMEM ; + + ielen =ieee80211_build_preq_ies (local, ies, + req->ie, req->ie_len); + local->orig_ies = req->ie; + local->orig_ies_len = req->ie_len; + req->ie = ies; + req->ie_len = ielen; local->hw_scanning = true; rc =drv_hw_scan (local, req);if (rc) { local->hw_scanning = false; +kfree (ies); + req->ie_len = local->orig_ies_len; + req->ie = local->orig_ies;return rc; } local->scan_sdata = scan_sdata;
include/net/cfg80211.h +1 -1
@@ -504,7 +504,7 @@ struct cfg80211_scan_request {int n_ssids;struct ieee80211_channel **channels;u32 n_channels; -u8 *ie; +const u8 *ie;size_t ie_len;/* internal */
net/wireless/nl80211.c +2 -1
@@ -2561,7 +2561,8 @@ static int nl80211_trigger_scan(struct sif (info->attrs[NL80211_ATTR_IE ]) { request->ie_len =nla_len (info->attrs[NL80211_ATTR_IE ]); -memcpy (request->ie,nla_data (info->attrs[NL80211_ATTR_IE ]), +memcpy ((void *)request->ie, +nla_data (info->attrs[NL80211_ATTR_IE ]), request->ie_len); }
Johannes Berg
maintainerPATCH v4 2/3 mac80211: pass all probe request IEs to driver
Instead of just passing the cfg80211-requested IEs, pass the locally generated ones as well.
---
v2: * assume wiphy->max_scan_ie_len contains the limit *including*
the IEs mac80211 passes (since the driver cannot know how long those will be) and adjust the driver's limit accordingly
* keep track of original IEs and hand back the pristine cfg80211 request structure
* mark the IE pointer const in the request struct
v3: * move code to correct place (register_hw)
* calculate upper limit for userspace scan IEs more accurately
v4: * apply w/o op dbg patch
include/net/cfg80211.h | 2 - include/net/mac80211.h | 13 ++++--- net/mac80211/ieee80211_i.h | 9 +++-- net/mac80211/main.c | 49 +++++++++++++++++++-------- net/mac80211/scan.c | 24 +++++++++++++ net/mac80211/util.c | 79 +++++++++++++++++++++++++++------------------ net/wireless/nl80211.c | 3 + 7 files changed, 123 insertions(+), 56 deletions(-)
include/net/mac80211.h +8 -5
@@ -1330,11 +1330,14 @@ enum ieee80211_ampdu_mlme_action {* the scan state machine in stack. The scan must honour the channel * configuration done by the regulatory agent in the wiphy's * registered bands. The hardware (or the driver) needs to make sure -* that power save is disabled. When the scan finishes, -* ieee80211_scan_completed() must be called; note that it also must -* be called when the scan cannot finish because the hardware is -* turned off! Anything else is a bug! Returns a negative error code -* which will be seen in userspace. +* that power save is disabled. +* The @req ie/ie_len members are rewritten by mac80211 to contain the +* entire IEs after the SSID, so that drivers need not look at these +* at all but just send them after the SSID -- mac80211 includes the +* (extended) supported rates and HT information (where applicable). +* When the scan finishes, ieee80211_scan_completed() must be called; +* note that it also must be called when the scan cannot finish due to +* any error unless this callback returned a negative error code. * * @sw_scan_start: Notifier function that is called just before a software scan * is started. Can be NULL, if the driver doesn't need this notification.
net/mac80211/ieee80211_i.h +7 -2
@@ -671,7 +671,10 @@ struct ieee80211_local {struct cfg80211_scan_request int_scan_req;struct cfg80211_scan_request *scan_req;struct ieee80211_channel *scan_channel; +const u8 *orig_ies; +int orig_ies_len;int scan_channel_idx; +int scan_ies_len;enum {SCAN_SET_CHANNEL ,SCAN_SEND_PROBE } scan_state;unsigned long last_scan_completed;
@@ -1093,9 +1096,11 @@ void ieee80211_send_auth(struct ieee8021 u16 transaction, u16 auth_alg, u8 *extra, size_t extra_len, const u8 *bssid, int encrypt); +int ieee80211_build_preq_ies (struct ieee80211_local *local,u8 *buffer, +const u8 *ie,size_t ie_len);void ieee80211_send_probe_req (struct ieee80211_sub_if_data *sdata,u8 *dst, -u8 *ssid,size_t ssid_len, -u8 *ie,size_t ie_len); +const u8 *ssid,size_t ssid_len, +const u8 *ie,size_t ie_len); void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, const size_t supp_rates_len,
net/mac80211/util.c +48 -31
97 lines not on this page · raw message
net/mac80211/main.c +34 -15
87 lines not on this page · raw message
net/mac80211/scan.c +23 -1
@@ -285,6 +285,12 @@ void ieee80211_scan_completed(struct ieeif (WARN_ON (!local->scan_req))return ; +if (local->hw_scanning) { +kfree (local->scan_req->ie); + local->scan_req->ie = local->orig_ies; + local->scan_req->ie_len = local->orig_ies_len; + } +if (local->scan_req != &local->int_scan_req)cfg80211_scan_done (local->scan_req, aborted); local->scan_req =NULL ;
@@ -457,12 +463,28 @@ int ieee80211_start_scan(struct ieee8021 }if (local->ops->hw_scan) { -int rc; +u8 *ies; +int rc, ielen; + + ies =kmalloc (2 +IEEE80211_MAX_SSID_LEN + + local->scan_ies_len + req->ie_len,GFP_KERNEL ); +if (!ies) +return -ENOMEM ; + + ielen =ieee80211_build_preq_ies (local, ies, + req->ie, req->ie_len); + local->orig_ies = req->ie; + local->orig_ies_len = req->ie_len; + req->ie = ies; + req->ie_len = ielen; local->hw_scanning = true; rc = local->ops->hw_scan (local_to_hw (local), req);if (rc) { local->hw_scanning = false; +kfree (ies); + req->ie_len = local->orig_ies_len; + req->ie = local->orig_ies;return rc; } local->scan_sdata = scan_sdata;
include/net/cfg80211.h +1 -1
@@ -504,7 +504,7 @@ struct cfg80211_scan_request {int n_ssids;struct ieee80211_channel **channels;u32 n_channels; -u8 *ie; +const u8 *ie;size_t ie_len;/* internal */
net/wireless/nl80211.c +2 -1
@@ -2561,7 +2561,8 @@ static int nl80211_trigger_scan(struct sif (info->attrs[NL80211_ATTR_IE ]) { request->ie_len =nla_len (info->attrs[NL80211_ATTR_IE ]); -memcpy (request->ie,nla_data (info->attrs[NL80211_ATTR_IE ]), +memcpy ((void *)request->ie, +nla_data (info->attrs[NL80211_ATTR_IE ]), request->ie_len); }
Johannes Berg
maintainerPATCH v3 3/3 mac80211: include HT capabilities in probe request
In reply to Johannes BergInclude the HT capabilities in the probe request frame.
---
v2: fix the HT IE
net/mac80211/main.c | 5 +++++ net/mac80211/util.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+)
net/mac80211/util.c +16 -0
@@ -862,6 +862,22 @@ int ieee80211_build_preq_ies(struct ieee *pos++ = rate->bitrate /5 ; } +if (sband->ht_cap.ht_supported) { +__le16 tmp =cpu_to_le16 (sband->ht_cap.cap); + + *pos++ =WLAN_EID_HT_CAPABILITY ; + *pos++ =sizeof (struct ieee80211_ht_cap ); +memset (pos,0 ,sizeof (struct ieee80211_ht_cap )); +memcpy (pos, &tmp,sizeof (u16)); + pos +=sizeof (u16); +/* TODO: needs a define here for << 2 */ + *pos++ = sband->ht_cap.ampdu_factor | + (sband->ht_cap.ampdu_density <<2 ); +memcpy (pos, &sband->ht_cap.mcs,sizeof (sband->ht_cap.mcs)); + pos +=sizeof (sband->ht_cap.mcs); + pos +=2 +4 +1 ;/* ext info, BF cap, antsel */ + } +/* * If adding more here, adjust code in main.c * that calculates local->scan_ies_len.
net/mac80211/main.c +5 -0
@@ -818,6 +818,7 @@ int ieee80211_register_hw(struct ieee802struct net_device *mdev;struct ieee80211_master_priv *mpriv;int channels, i, j, max_bitrates; +bool supp_ht;/* * generic code guarantees at least one band,
@@ -826,6 +827,7 @@ int ieee80211_register_hw(struct ieee802*/ channels =0 ; max_bitrates =0 ; + supp_ht = false;for (band =0 ; band <IEEE80211_NUM_BANDS ; band++) {struct ieee80211_supported_band *sband;
@@ -842,6 +844,7 @@ int ieee80211_register_hw(struct ieee802if (max_bitrates < sband->n_bitrates) max_bitrates = sband->n_bitrates; + supp_ht = supp_ht || sband->ht_cap.ht_supported; } local->int_scan_req.n_channels = channels;
@@ -868,6 +871,8 @@ int ieee80211_register_hw(struct ieee802* information -- SSID is the driver's responsibility. */ local->scan_ies_len =4 + max_bitrates;/* (ext) supp rates */ +if (supp_ht) + local->scan_ies_len +=2 +sizeof (struct ieee80211_ht_cap );if (!local->ops->hw_scan) {/* For hw_scan, driver needs to set these up. */