/* 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 |
 
 
        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;
 
  *
  * @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
 
        NL80211_ATTR_KEY_TYPE,
 
+       NL80211_ATTR_MAX_SCAN_IE_LEN,
+
        /* add attributes here, update the policy in nl80211.c */
 
        __NL80211_ATTR_AFTER_LAST,
 
 
        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
 
                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);
 
                *pos = rate->bitrate / 5;
        }
 
+       /* if adding more here, adjust max_scan_ie_len */
+
        if (ie)
                memcpy(skb_put(skb, ie_len), ie, ie_len);
 
 
        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)
        else
                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