cfg80211: allow registering more than one beacon listener
[linux-3.10.git] / net / wireless / nl80211.c
index 206465d..ba44f98 100644 (file)
@@ -22,8 +22,8 @@
 #include "core.h"
 #include "nl80211.h"
 #include "reg.h"
+#include "rdev-ops.h"
 
-static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
                                   struct genl_info *info,
                                   struct cfg80211_crypto_settings *settings,
@@ -46,28 +46,175 @@ static struct genl_family nl80211_fam = {
        .post_doit = nl80211_post_doit,
 };
 
-/* internal helper: get rdev and dev */
-static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
-                                  struct cfg80211_registered_device **rdev,
-                                  struct net_device **dev)
+/* returns ERR_PTR values */
+static struct wireless_dev *
+__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
 {
-       int ifindex;
+       struct cfg80211_registered_device *rdev;
+       struct wireless_dev *result = NULL;
+       bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
+       bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
+       u64 wdev_id;
+       int wiphy_idx = -1;
+       int ifidx = -1;
 
-       if (!attrs[NL80211_ATTR_IFINDEX])
-               return -EINVAL;
+       assert_cfg80211_lock();
 
-       ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
-       *dev = dev_get_by_index(netns, ifindex);
-       if (!*dev)
-               return -ENODEV;
+       if (!have_ifidx && !have_wdev_id)
+               return ERR_PTR(-EINVAL);
 
-       *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
-       if (IS_ERR(*rdev)) {
-               dev_put(*dev);
-               return PTR_ERR(*rdev);
+       if (have_ifidx)
+               ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
+       if (have_wdev_id) {
+               wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
+               wiphy_idx = wdev_id >> 32;
        }
 
-       return 0;
+       list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
+               struct wireless_dev *wdev;
+
+               if (wiphy_net(&rdev->wiphy) != netns)
+                       continue;
+
+               if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
+                       continue;
+
+               mutex_lock(&rdev->devlist_mtx);
+               list_for_each_entry(wdev, &rdev->wdev_list, list) {
+                       if (have_ifidx && wdev->netdev &&
+                           wdev->netdev->ifindex == ifidx) {
+                               result = wdev;
+                               break;
+                       }
+                       if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
+                               result = wdev;
+                               break;
+                       }
+               }
+               mutex_unlock(&rdev->devlist_mtx);
+
+               if (result)
+                       break;
+       }
+
+       if (result)
+               return result;
+       return ERR_PTR(-ENODEV);
+}
+
+static struct cfg80211_registered_device *
+__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
+{
+       struct cfg80211_registered_device *rdev = NULL, *tmp;
+       struct net_device *netdev;
+
+       assert_cfg80211_lock();
+
+       if (!attrs[NL80211_ATTR_WIPHY] &&
+           !attrs[NL80211_ATTR_IFINDEX] &&
+           !attrs[NL80211_ATTR_WDEV])
+               return ERR_PTR(-EINVAL);
+
+       if (attrs[NL80211_ATTR_WIPHY])
+               rdev = cfg80211_rdev_by_wiphy_idx(
+                               nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
+
+       if (attrs[NL80211_ATTR_WDEV]) {
+               u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
+               struct wireless_dev *wdev;
+               bool found = false;
+
+               tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
+               if (tmp) {
+                       /* make sure wdev exists */
+                       mutex_lock(&tmp->devlist_mtx);
+                       list_for_each_entry(wdev, &tmp->wdev_list, list) {
+                               if (wdev->identifier != (u32)wdev_id)
+                                       continue;
+                               found = true;
+                               break;
+                       }
+                       mutex_unlock(&tmp->devlist_mtx);
+
+                       if (!found)
+                               tmp = NULL;
+
+                       if (rdev && tmp != rdev)
+                               return ERR_PTR(-EINVAL);
+                       rdev = tmp;
+               }
+       }
+
+       if (attrs[NL80211_ATTR_IFINDEX]) {
+               int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
+               netdev = dev_get_by_index(netns, ifindex);
+               if (netdev) {
+                       if (netdev->ieee80211_ptr)
+                               tmp = wiphy_to_dev(
+                                               netdev->ieee80211_ptr->wiphy);
+                       else
+                               tmp = NULL;
+
+                       dev_put(netdev);
+
+                       /* not wireless device -- return error */
+                       if (!tmp)
+                               return ERR_PTR(-EINVAL);
+
+                       /* mismatch -- return error */
+                       if (rdev && tmp != rdev)
+                               return ERR_PTR(-EINVAL);
+
+                       rdev = tmp;
+               }
+       }
+
+       if (!rdev)
+               return ERR_PTR(-ENODEV);
+
+       if (netns != wiphy_net(&rdev->wiphy))
+               return ERR_PTR(-ENODEV);
+
+       return rdev;
+}
+
+/*
+ * This function returns a pointer to the driver
+ * that the genl_info item that is passed refers to.
+ * If successful, it returns non-NULL and also locks
+ * the driver's mutex!
+ *
+ * This means that you need to call cfg80211_unlock_rdev()
+ * before being allowed to acquire &cfg80211_mutex!
+ *
+ * This is necessary because we need to lock the global
+ * mutex to get an item off the list safely, and then
+ * we lock the rdev mutex so it doesn't go away under us.
+ *
+ * We don't want to keep cfg80211_mutex locked
+ * for all the time in order to allow requests on
+ * other interfaces to go through at the same time.
+ *
+ * The result of this can be a PTR_ERR and hence must
+ * be checked with IS_ERR() for errors.
+ */
+static struct cfg80211_registered_device *
+cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
+{
+       struct cfg80211_registered_device *rdev;
+
+       mutex_lock(&cfg80211_mutex);
+       rdev = __cfg80211_rdev_from_attrs(netns, info->attrs);
+
+       /* if it is not an error we grab the lock on
+        * it to assure it won't be going away while
+        * we operate on it */
+       if (!IS_ERR(rdev))
+               mutex_lock(&rdev->mtx);
+
+       mutex_unlock(&cfg80211_mutex);
+
+       return rdev;
 }
 
 /* policy for the attributes */
@@ -115,7 +262,7 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
        [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
        [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
        [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
-                               .len = IEEE80211_MAX_MESH_ID_LEN },
+                                  .len = IEEE80211_MAX_MESH_ID_LEN },
        [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
 
        [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
@@ -206,6 +353,11 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
        [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
        [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
        [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
+       [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
+       [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
+       [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
+       [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
+       [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
 };
 
 /* policy for the key attributes */
@@ -250,8 +402,9 @@ nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
 
 static const struct nla_policy
 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
-       [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
+       [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
                                                 .len = IEEE80211_MAX_SSID_LEN },
+       [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
 };
 
 /* ifidx get helper */
@@ -346,11 +499,11 @@ static bool is_valid_ie_attr(const struct nlattr *attr)
 }
 
 /* message building helper */
-static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
+static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
                                   int flags, u8 cmd)
 {
        /* since there is no private header just add the generic one */
-       return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
+       return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
 }
 
 static int nl80211_msg_put_channel(struct sk_buff *msg,
@@ -540,7 +693,7 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
 
 static struct cfg80211_cached_keys *
 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
-                      struct nlattr *keys)
+                      struct nlattr *keys, bool *no_ht)
 {
        struct key_parse parse;
        struct nlattr *key;
@@ -583,6 +736,12 @@ nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
                result->params[parse.idx].key_len = parse.p.key_len;
                result->params[parse.idx].key = result->data[parse.idx];
                memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
+
+               if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
+                   parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
+                       if (no_ht)
+                               *no_ht = true;
+               }
        }
 
        return result;
@@ -701,7 +860,7 @@ nla_put_failure:
        return -ENOBUFS;
 }
 
-static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
+static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags,
                              struct cfg80211_registered_device *dev)
 {
        void *hdr;
@@ -716,7 +875,7 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
        const struct ieee80211_txrx_stypes *mgmt_stypes =
                                dev->wiphy.mgmt_stypes;
 
-       hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
+       hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
        if (!hdr)
                return -1;
 
@@ -793,7 +952,7 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
             dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
                u32 tx_ant = 0, rx_ant = 0;
                int res;
-               res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
+               res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
                if (!res) {
                        if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX,
                                        tx_ant) ||
@@ -832,6 +991,15 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
                                dev->wiphy.bands[band]->ht_cap.ampdu_density)))
                        goto nla_put_failure;
 
+               /* add VHT info */
+               if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
+                   (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
+                            sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
+                            &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
+                    nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
+                                dev->wiphy.bands[band]->vht_cap.cap)))
+                       goto nla_put_failure;
+
                /* add frequencies */
                nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
                if (!nl_freqs)
@@ -921,7 +1089,12 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
                if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
                        goto nla_put_failure;
        }
-       CMD(set_channel, SET_CHANNEL);
+       if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
+           dev->ops->join_mesh) {
+               i++;
+               if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
+                       goto nla_put_failure;
+       }
        CMD(set_wds_peer, SET_WDS_PEER);
        if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
                CMD(tdls_mgmt, TDLS_MGMT);
@@ -936,6 +1109,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
                if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
                        goto nla_put_failure;
        }
+       CMD(start_p2p_device, START_P2P_DEVICE);
+       CMD(set_mcast_rate, SET_MCAST_RATE);
 
 #ifdef CONFIG_NL80211_TESTMODE
        CMD(testmode_cmd, TESTMODE);
@@ -1018,6 +1193,7 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
                nla_nest_end(msg, nl_ifs);
        }
 
+#ifdef CONFIG_PM
        if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
                struct nlattr *nl_wowlan;
 
@@ -1058,6 +1234,7 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
 
                nla_nest_end(msg, nl_wowlan);
        }
+#endif
 
        if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
                                dev->wiphy.software_iftypes))
@@ -1100,7 +1277,7 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
                        continue;
                if (++idx <= start)
                        continue;
-               if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
+               if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).portid,
                                       cb->nlh->nlmsg_seq, NLM_F_MULTI,
                                       dev) < 0) {
                        idx--;
@@ -1123,7 +1300,7 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
        if (!msg)
                return -ENOMEM;
 
-       if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
+       if (nl80211_send_wiphy(msg, info->snd_portid, info->snd_seq, 0, dev) < 0) {
                nlmsg_free(msg);
                return -ENOBUFS;
        }
@@ -1162,18 +1339,22 @@ static int parse_txq_params(struct nlattr *tb[],
 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
 {
        /*
-        * You can only set the channel explicitly for AP, mesh
-        * and WDS type interfaces; all others have their channel
-        * managed via their respective "establish a connection"
-        * command (connect, join, ...)
+        * You can only set the channel explicitly for WDS interfaces,
+        * all others have their channel managed via their respective
+        * "establish a connection" command (connect, join, ...)
+        *
+        * For AP/GO and mesh mode, the channel can be set with the
+        * channel userspace API, but is only stored and passed to the
+        * low-level driver when the AP starts or the mesh is joined.
+        * This is for backward compatibility, userspace can also give
+        * the channel in the start-ap or join-mesh commands instead.
         *
         * Monitors are special as they are normally slaved to
-        * whatever else is going on, so they behave as though
-        * you tried setting the wiphy channel itself.
+        * whatever else is going on, so they have their own special
+        * operation to set the monitor channel if possible.
         */
        return !wdev ||
                wdev->iftype == NL80211_IFTYPE_AP ||
-               wdev->iftype == NL80211_IFTYPE_WDS ||
                wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
                wdev->iftype == NL80211_IFTYPE_MONITOR ||
                wdev->iftype == NL80211_IFTYPE_P2P_GO;
@@ -1204,9 +1385,14 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
                                 struct wireless_dev *wdev,
                                 struct genl_info *info)
 {
+       struct ieee80211_channel *channel;
        enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
        u32 freq;
        int result;
+       enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
+
+       if (wdev)
+               iftype = wdev->iftype;
 
        if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
                return -EINVAL;
@@ -1221,12 +1407,32 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
        freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
 
        mutex_lock(&rdev->devlist_mtx);
-       if (wdev) {
-               wdev_lock(wdev);
-               result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
-               wdev_unlock(wdev);
-       } else {
-               result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
+       switch (iftype) {
+       case NL80211_IFTYPE_AP:
+       case NL80211_IFTYPE_P2P_GO:
+               if (wdev->beacon_interval) {
+                       result = -EBUSY;
+                       break;
+               }
+               channel = rdev_freq_to_chan(rdev, freq, channel_type);
+               if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
+                                                             channel,
+                                                             channel_type)) {
+                       result = -EINVAL;
+                       break;
+               }
+               wdev->preset_chan = channel;
+               wdev->preset_chantype = channel_type;
+               result = 0;
+               break;
+       case NL80211_IFTYPE_MESH_POINT:
+               result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
+               break;
+       case NL80211_IFTYPE_MONITOR:
+               result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
+               break;
+       default:
+               result = -EINVAL;
        }
        mutex_unlock(&rdev->devlist_mtx);
 
@@ -1261,7 +1467,7 @@ static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
                return -EOPNOTSUPP;
 
        bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
-       return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
+       return rdev_set_wds_peer(rdev, dev, bssid);
 }
 
 
@@ -1300,7 +1506,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
        }
 
        if (!netdev) {
-               rdev = __cfg80211_rdev_from_info(info);
+               rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
+                                                 info->attrs);
                if (IS_ERR(rdev)) {
                        mutex_unlock(&cfg80211_mutex);
                        return PTR_ERR(rdev);
@@ -1310,11 +1517,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                result = 0;
 
                mutex_lock(&rdev->mtx);
-       } else if (netif_running(netdev) &&
-                  nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
+       } else
                wdev = netdev->ieee80211_ptr;
-       else
-               wdev = NULL;
 
        /*
         * end workaround code, by now the rdev is available
@@ -1366,24 +1570,29 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                        if (result)
                                goto bad_res;
 
-                       result = rdev->ops->set_txq_params(&rdev->wiphy,
-                                                          netdev,
-                                                          &txq_params);
+                       result = rdev_set_txq_params(rdev, netdev,
+                                                    &txq_params);
                        if (result)
                                goto bad_res;
                }
        }
 
        if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
-               result = __nl80211_set_channel(rdev, wdev, info);
+               result = __nl80211_set_channel(rdev,
+                               nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
+                               info);
                if (result)
                        goto bad_res;
        }
 
        if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
+               struct wireless_dev *txp_wdev = wdev;
                enum nl80211_tx_power_setting type;
                int idx, mbm = 0;
 
+               if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
+                       txp_wdev = NULL;
+
                if (!rdev->ops->set_tx_power) {
                        result = -EOPNOTSUPP;
                        goto bad_res;
@@ -1403,7 +1612,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                        mbm = nla_get_u32(info->attrs[idx]);
                }
 
-               result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
+               result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
                if (result)
                        goto bad_res;
        }
@@ -1432,7 +1641,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
                rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
 
-               result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
+               result = rdev_set_antenna(rdev, tx_ant, rx_ant);
                if (result)
                        goto bad_res;
        }
@@ -1517,7 +1726,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
                if (changed & WIPHY_PARAM_COVERAGE_CLASS)
                        rdev->wiphy.coverage_class = coverage_class;
 
-               result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
+               result = rdev_set_wiphy_params(rdev, changed);
                if (result) {
                        rdev->wiphy.retry_short = old_retry_short;
                        rdev->wiphy.retry_long = old_retry_long;
@@ -1534,22 +1743,32 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
        return result;
 }
 
+static inline u64 wdev_id(struct wireless_dev *wdev)
+{
+       return (u64)wdev->identifier |
+              ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
+}
 
-static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
+static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
                              struct cfg80211_registered_device *rdev,
-                             struct net_device *dev)
+                             struct wireless_dev *wdev)
 {
+       struct net_device *dev = wdev->netdev;
        void *hdr;
 
-       hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
+       hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
        if (!hdr)
                return -1;
 
-       if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
-           nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
-           nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
-           nla_put_u32(msg, NL80211_ATTR_IFTYPE,
-                       dev->ieee80211_ptr->iftype) ||
+       if (dev &&
+           (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
+            nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
+               goto nla_put_failure;
+
+       if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
+           nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
+           nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
+           nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
            nla_put_u32(msg, NL80211_ATTR_GENERATION,
                        rdev->devlist_generation ^
                        (cfg80211_rdev_list_generation << 2)))
@@ -1559,12 +1778,12 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
                struct ieee80211_channel *chan;
                enum nl80211_channel_type channel_type;
 
-               chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
+               chan = rdev_get_channel(rdev, wdev, &channel_type);
                if (chan &&
                    (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
-                                   chan->center_freq) ||
+                                chan->center_freq) ||
                     nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
-                                   channel_type)))
+                                channel_type)))
                        goto nla_put_failure;
        }
 
@@ -1595,14 +1814,14 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
                if_idx = 0;
 
                mutex_lock(&rdev->devlist_mtx);
-               list_for_each_entry(wdev, &rdev->netdev_list, list) {
+               list_for_each_entry(wdev, &rdev->wdev_list, list) {
                        if (if_idx < if_start) {
                                if_idx++;
                                continue;
                        }
-                       if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
+                       if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
                                               cb->nlh->nlmsg_seq, NLM_F_MULTI,
-                                              rdev, wdev->netdev) < 0) {
+                                              rdev, wdev) < 0) {
                                mutex_unlock(&rdev->devlist_mtx);
                                goto out;
                        }
@@ -1625,14 +1844,14 @@ static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
 {
        struct sk_buff *msg;
        struct cfg80211_registered_device *dev = info->user_ptr[0];
-       struct net_device *netdev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
 
        msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
        if (!msg)
                return -ENOMEM;
 
-       if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
-                              dev, netdev) < 0) {
+       if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
+                              dev, wdev) < 0) {
                nlmsg_free(msg);
                return -ENOBUFS;
        }
@@ -1772,7 +1991,8 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
        struct vif_params params;
-       struct net_device *dev;
+       struct wireless_dev *wdev;
+       struct sk_buff *msg;
        int err;
        enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
        u32 flags;
@@ -1799,19 +2019,25 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
                        return err;
        }
 
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+       if (!msg)
+               return -ENOMEM;
+
        err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
                                  info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
                                  &flags);
-       dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
-               nla_data(info->attrs[NL80211_ATTR_IFNAME]),
-               type, err ? NULL : &flags, &params);
-       if (IS_ERR(dev))
-               return PTR_ERR(dev);
-
-       if (type == NL80211_IFTYPE_MESH_POINT &&
-           info->attrs[NL80211_ATTR_MESH_ID]) {
-               struct wireless_dev *wdev = dev->ieee80211_ptr;
+       wdev = rdev_add_virtual_intf(rdev,
+                               nla_data(info->attrs[NL80211_ATTR_IFNAME]),
+                               type, err ? NULL : &flags, &params);
+       if (IS_ERR(wdev)) {
+               nlmsg_free(msg);
+               return PTR_ERR(wdev);
+       }
 
+       switch (type) {
+       case NL80211_IFTYPE_MESH_POINT:
+               if (!info->attrs[NL80211_ATTR_MESH_ID])
+                       break;
                wdev_lock(wdev);
                BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
                             IEEE80211_MAX_MESH_ID_LEN);
@@ -1820,20 +2046,56 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
                memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
                       wdev->mesh_id_up_len);
                wdev_unlock(wdev);
+               break;
+       case NL80211_IFTYPE_P2P_DEVICE:
+               /*
+                * P2P Device doesn't have a netdev, so doesn't go
+                * through the netdev notifier and must be added here
+                */
+               mutex_init(&wdev->mtx);
+               INIT_LIST_HEAD(&wdev->event_list);
+               spin_lock_init(&wdev->event_lock);
+               INIT_LIST_HEAD(&wdev->mgmt_registrations);
+               spin_lock_init(&wdev->mgmt_registrations_lock);
+
+               mutex_lock(&rdev->devlist_mtx);
+               wdev->identifier = ++rdev->wdev_id;
+               list_add_rcu(&wdev->list, &rdev->wdev_list);
+               rdev->devlist_generation++;
+               mutex_unlock(&rdev->devlist_mtx);
+               break;
+       default:
+               break;
        }
 
-       return 0;
+       if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
+                              rdev, wdev) < 0) {
+               nlmsg_free(msg);
+               return -ENOBUFS;
+       }
+
+       return genlmsg_reply(msg, info);
 }
 
 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
-       struct net_device *dev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
 
        if (!rdev->ops->del_virtual_intf)
                return -EOPNOTSUPP;
 
-       return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
+       /*
+        * If we remove a wireless device without a netdev then clear
+        * user_ptr[1] so that nl80211_post_doit won't dereference it
+        * to check if it needs to do dev_put(). Otherwise it crashes
+        * since the wdev has been freed, unlike with a netdev where
+        * we need the dev_put() for the netdev to really be freed.
+        */
+       if (!wdev->netdev)
+               info->user_ptr[1] = NULL;
+
+       return rdev_del_virtual_intf(rdev, wdev);
 }
 
 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
@@ -1850,7 +2112,7 @@ static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
 
        noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
 
-       return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
+       return rdev_set_noack_map(rdev, dev, noack_map);
 }
 
 struct get_key_cookie {
@@ -1941,7 +2203,7 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
        if (!msg)
                return -ENOMEM;
 
-       hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+       hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                             NL80211_CMD_NEW_KEY);
        if (IS_ERR(hdr))
                return PTR_ERR(hdr);
@@ -1960,8 +2222,8 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
            !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
                return -ENOENT;
 
-       err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
-                                mac_addr, &cookie, get_key_callback);
+       err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
+                          get_key_callback);
 
        if (err)
                goto free_msg;
@@ -2009,7 +2271,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
                if (err)
                        goto out;
 
-               err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
+               err = rdev_set_default_key(rdev, dev, key.idx,
                                                 key.def_uni, key.def_multi);
 
                if (err)
@@ -2033,8 +2295,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
                if (err)
                        goto out;
 
-               err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
-                                                     dev, key.idx);
+               err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
                if (err)
                        goto out;
 
@@ -2090,9 +2351,9 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
        wdev_lock(dev->ieee80211_ptr);
        err = nl80211_key_allowed(dev->ieee80211_ptr);
        if (!err)
-               err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
-                                        key.type == NL80211_KEYTYPE_PAIRWISE,
-                                        mac_addr, &key.p);
+               err = rdev_add_key(rdev, dev, key.idx,
+                                  key.type == NL80211_KEYTYPE_PAIRWISE,
+                                   mac_addr, &key.p);
        wdev_unlock(dev->ieee80211_ptr);
 
        return err;
@@ -2136,9 +2397,9 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
                err = -ENOENT;
 
        if (!err)
-               err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
-                                        key.type == NL80211_KEYTYPE_PAIRWISE,
-                                        mac_addr);
+               err = rdev_del_key(rdev, dev, key.idx,
+                                  key.type == NL80211_KEYTYPE_PAIRWISE,
+                                  mac_addr);
 
 #ifdef CONFIG_CFG80211_WEXT
        if (!err) {
@@ -2213,6 +2474,57 @@ static int nl80211_parse_beacon(struct genl_info *info,
        return 0;
 }
 
+static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
+                                  struct cfg80211_ap_settings *params)
+{
+       struct wireless_dev *wdev;
+       bool ret = false;
+
+       mutex_lock(&rdev->devlist_mtx);
+
+       list_for_each_entry(wdev, &rdev->wdev_list, list) {
+               if (wdev->iftype != NL80211_IFTYPE_AP &&
+                   wdev->iftype != NL80211_IFTYPE_P2P_GO)
+                       continue;
+
+               if (!wdev->preset_chan)
+                       continue;
+
+               params->channel = wdev->preset_chan;
+               params->channel_type = wdev->preset_chantype;
+               ret = true;
+               break;
+       }
+
+       mutex_unlock(&rdev->devlist_mtx);
+
+       return ret;
+}
+
+static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
+                                   enum nl80211_auth_type auth_type,
+                                   enum nl80211_commands cmd)
+{
+       if (auth_type > NL80211_AUTHTYPE_MAX)
+               return false;
+
+       switch (cmd) {
+       case NL80211_CMD_AUTHENTICATE:
+               if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
+                   auth_type == NL80211_AUTHTYPE_SAE)
+                       return false;
+               return true;
+       case NL80211_CMD_CONNECT:
+       case NL80211_CMD_START_AP:
+               /* SAE not supported yet */
+               if (auth_type == NL80211_AUTHTYPE_SAE)
+                       return false;
+               return true;
+       default:
+               return false;
+       }
+}
+
 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
@@ -2282,7 +2594,8 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
        if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
                params.auth_type = nla_get_u32(
                        info->attrs[NL80211_ATTR_AUTH_TYPE]);
-               if (!nl80211_valid_auth_type(params.auth_type))
+               if (!nl80211_valid_auth_type(rdev, params.auth_type,
+                                            NL80211_CMD_START_AP))
                        return -EINVAL;
        } else
                params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
@@ -2299,9 +2612,44 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
                        info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
        }
 
-       err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
-       if (!err)
+       if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
+               enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
+
+               if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
+                   !nl80211_valid_channel_type(info, &channel_type))
+                       return -EINVAL;
+
+               params.channel = rdev_freq_to_chan(rdev,
+                       nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
+                       channel_type);
+               if (!params.channel)
+                       return -EINVAL;
+               params.channel_type = channel_type;
+       } else if (wdev->preset_chan) {
+               params.channel = wdev->preset_chan;
+               params.channel_type = wdev->preset_chantype;
+       } else if (!nl80211_get_ap_channel(rdev, &params))
+               return -EINVAL;
+
+       if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
+                                         params.channel_type))
+               return -EINVAL;
+
+       mutex_lock(&rdev->devlist_mtx);
+       err = cfg80211_can_use_chan(rdev, wdev, params.channel,
+                                   CHAN_MODE_SHARED);
+       mutex_unlock(&rdev->devlist_mtx);
+
+       if (err)
+               return err;
+
+       err = rdev_start_ap(rdev, dev, &params);
+       if (!err) {
+               wdev->preset_chan = params.channel;
+               wdev->preset_chantype = params.channel_type;
                wdev->beacon_interval = params.beacon_interval;
+               wdev->channel = params.channel;
+       }
        return err;
 }
 
@@ -2327,30 +2675,15 @@ static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
        if (err)
                return err;
 
-       return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
+       return rdev_change_beacon(rdev, dev, &params);
 }
 
 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
        struct net_device *dev = info->user_ptr[1];
-       struct wireless_dev *wdev = dev->ieee80211_ptr;
-       int err;
-
-       if (!rdev->ops->stop_ap)
-               return -EOPNOTSUPP;
 
-       if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
-               return -EOPNOTSUPP;
-
-       if (!wdev->beacon_interval)
-               return -ENOENT;
-
-       err = rdev->ops->stop_ap(&rdev->wiphy, dev);
-       if (!err)
-               wdev->beacon_interval = 0;
-       return err;
+       return cfg80211_stop_ap(rdev, dev);
 }
 
 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
@@ -2442,7 +2775,8 @@ static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
                                 int attr)
 {
        struct nlattr *rate;
-       u16 bitrate;
+       u32 bitrate;
+       u16 bitrate_compat;
 
        rate = nla_nest_start(msg, attr);
        if (!rate)
@@ -2450,8 +2784,12 @@ static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
 
        /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
        bitrate = cfg80211_calculate_bitrate(info);
+       /* report 16-bit bitrate only if we can */
+       bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
        if ((bitrate > 0 &&
-            nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) ||
+            nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) ||
+           (bitrate_compat > 0 &&
+            nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) ||
            ((info->flags & RATE_INFO_FLAGS_MCS) &&
             nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) ||
            ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) &&
@@ -2467,7 +2805,7 @@ nla_put_failure:
        return false;
 }
 
-static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
+static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
                                int flags,
                                struct cfg80211_registered_device *rdev,
                                struct net_device *dev,
@@ -2476,7 +2814,7 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
        void *hdr;
        struct nlattr *sinfoattr, *bss_param;
 
-       hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
+       hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
        if (!hdr)
                return -1;
 
@@ -2621,15 +2959,15 @@ static int nl80211_dump_station(struct sk_buff *skb,
 
        while (1) {
                memset(&sinfo, 0, sizeof(sinfo));
-               err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
-                                            mac_addr, &sinfo);
+               err = rdev_dump_station(dev, netdev, sta_idx,
+                                       mac_addr, &sinfo);
                if (err == -ENOENT)
                        break;
                if (err)
                        goto out_err;
 
                if (nl80211_send_station(skb,
-                               NETLINK_CB(cb->skb).pid,
+                               NETLINK_CB(cb->skb).portid,
                                cb->nlh->nlmsg_seq, NLM_F_MULTI,
                                dev, netdev, mac_addr,
                                &sinfo) < 0)
@@ -2667,7 +3005,7 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
        if (!rdev->ops->get_station)
                return -EOPNOTSUPP;
 
-       err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
+       err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
        if (err)
                return err;
 
@@ -2675,7 +3013,7 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
        if (!msg)
                return -ENOMEM;
 
-       if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
+       if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
                                 rdev, dev, mac_addr, &sinfo) < 0) {
                nlmsg_free(msg);
                return -ENOBUFS;
@@ -2844,7 +3182,7 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
 
        /* be aware of params.vlan when changing code here */
 
-       err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
+       err = rdev_change_station(rdev, dev, mac_addr, &params);
 
        if (params.vlan)
                dev_put(params.vlan);
@@ -2896,6 +3234,10 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
                params.ht_capa =
                        nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
 
+       if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
+               params.vht_capa =
+                       nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
+
        if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
                params.plink_action =
                    nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
@@ -2973,7 +3315,7 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
 
        /* be aware of params.vlan when changing code here */
 
-       err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
+       err = rdev_add_station(rdev, dev, mac_addr, &params);
 
        if (params.vlan)
                dev_put(params.vlan);
@@ -2998,10 +3340,10 @@ static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
        if (!rdev->ops->del_station)
                return -EOPNOTSUPP;
 
-       return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
+       return rdev_del_station(rdev, dev, mac_addr);
 }
 
-static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
+static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
                                int flags, struct net_device *dev,
                                u8 *dst, u8 *next_hop,
                                struct mpath_info *pinfo)
@@ -3009,7 +3351,7 @@ static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
        void *hdr;
        struct nlattr *pinfoattr;
 
-       hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
+       hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
        if (!hdr)
                return -1;
 
@@ -3080,14 +3422,14 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
        }
 
        while (1) {
-               err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
-                                          dst, next_hop, &pinfo);
+               err = rdev_dump_mpath(dev, netdev, path_idx, dst, next_hop,
+                                     &pinfo);
                if (err == -ENOENT)
                        break;
                if (err)
                        goto out_err;
 
-               if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
+               if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
                                       cb->nlh->nlmsg_seq, NLM_F_MULTI,
                                       netdev, dst, next_hop,
                                       &pinfo) < 0)
@@ -3128,7 +3470,7 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
        if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
                return -EOPNOTSUPP;
 
-       err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
+       err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
        if (err)
                return err;
 
@@ -3136,7 +3478,7 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
        if (!msg)
                return -ENOMEM;
 
-       if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
+       if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
                                 dev, dst, next_hop, &pinfo) < 0) {
                nlmsg_free(msg);
                return -ENOBUFS;
@@ -3167,7 +3509,7 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
        if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
                return -EOPNOTSUPP;
 
-       return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
+       return rdev_change_mpath(rdev, dev, dst, next_hop);
 }
 
 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
@@ -3192,7 +3534,7 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
        if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
                return -EOPNOTSUPP;
 
-       return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
+       return rdev_add_mpath(rdev, dev, dst, next_hop);
 }
 
 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
@@ -3207,7 +3549,7 @@ static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
        if (!rdev->ops->del_mpath)
                return -EOPNOTSUPP;
 
-       return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
+       return rdev_del_mpath(rdev, dev, dst);
 }
 
 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
@@ -3252,7 +3594,7 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
            dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
                return -EOPNOTSUPP;
 
-       return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
+       return rdev_change_bss(rdev, dev, &params);
 }
 
 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
@@ -3304,6 +3646,7 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
 {
        int r;
        char *data = NULL;
+       enum nl80211_user_reg_hint_type user_reg_hint_type;
 
        /*
         * You should only get this when cfg80211 hasn't yet initialized
@@ -3323,7 +3666,21 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
 
        data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
 
-       r = regulatory_hint_user(data);
+       if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
+               user_reg_hint_type =
+                 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
+       else
+               user_reg_hint_type = NL80211_USER_REG_HINT_USER;
+
+       switch (user_reg_hint_type) {
+       case NL80211_USER_REG_HINT_USER:
+       case NL80211_USER_REG_HINT_CELL_BASE:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       r = regulatory_hint_user(data, user_reg_hint_type);
 
        return r;
 }
@@ -3351,8 +3708,7 @@ static int nl80211_get_mesh_config(struct sk_buff *skb,
        if (!wdev->mesh_id_len)
                memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
        else
-               err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
-                                                &cur_params);
+               err = rdev_get_mesh_config(rdev, dev, &cur_params);
        wdev_unlock(wdev);
 
        if (err)
@@ -3362,7 +3718,7 @@ static int nl80211_get_mesh_config(struct sk_buff *skb,
        msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
        if (!msg)
                return -ENOMEM;
-       hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+       hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                             NL80211_CMD_GET_MESH_CONFIG);
        if (!hdr)
                goto out;
@@ -3413,7 +3769,13 @@ static int nl80211_get_mesh_config(struct sk_buff *skb,
            nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
                        cur_params.rssi_threshold) ||
            nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
-                       cur_params.ht_opmode))
+                       cur_params.ht_opmode) ||
+           nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
+                       cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
+           nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
+                       cur_params.dot11MeshHWMProotInterval) ||
+           nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
+                       cur_params.dot11MeshHWMPconfirmationInterval))
                goto nla_put_failure;
        nla_nest_end(msg, pinfoattr);
        genlmsg_end(msg, hdr);
@@ -3436,7 +3798,6 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
        [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
        [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
        [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
-
        [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
        [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
        [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
@@ -3448,8 +3809,11 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
        [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
        [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
        [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
-       [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32},
-       [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16},
+       [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
+       [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
+       [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
+       [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
+       [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
 };
 
 static const struct nla_policy
@@ -3459,7 +3823,7 @@ static const struct nla_policy
        [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
        [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
        [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
-               .len = IEEE80211_MAX_DATA_LEN },
+                                   .len = IEEE80211_MAX_DATA_LEN },
        [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
 };
 
@@ -3492,63 +3856,82 @@ do {\
 
        /* Fill in the params struct */
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
-                       mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
+                                 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
+                                 nla_get_u16);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
-                       mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
+                                 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
+                                 nla_get_u16);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
-                       mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
+                                 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
+                                 nla_get_u16);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
-                       mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
+                                 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
+                                 nla_get_u16);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
-                       mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
+                                 mask, NL80211_MESHCONF_MAX_RETRIES,
+                                 nla_get_u8);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
-                       mask, NL80211_MESHCONF_TTL, nla_get_u8);
+                                 mask, NL80211_MESHCONF_TTL, nla_get_u8);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
-                       mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
+                                 mask, NL80211_MESHCONF_ELEMENT_TTL,
+                                 nla_get_u8);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
-                       mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
-       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
-                       mask, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
-                       nla_get_u32);
+                                 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
+                                 nla_get_u8);
+       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask,
+                                 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
+                                 nla_get_u32);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
-                       mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
-                       nla_get_u8);
+                                 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
+                                 nla_get_u8);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
-                       mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
+                                 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
+                                 nla_get_u32);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
-                       mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
-                       nla_get_u16);
-       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
-                       mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
-                       nla_get_u32);
+                                 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
+                                 nla_get_u16);
+       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask,
+                                 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
+                                 nla_get_u32);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
-                       mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
-                       nla_get_u16);
+                                 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
+                                 nla_get_u16);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
-                       mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
-                       nla_get_u16);
-       FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
-                       dot11MeshHWMPnetDiameterTraversalTime,
-                       mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
-                       nla_get_u16);
+                                 mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
+                                 nla_get_u16);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
-                       dot11MeshHWMPRootMode, mask,
-                       NL80211_MESHCONF_HWMP_ROOTMODE,
-                       nla_get_u8);
+                                 dot11MeshHWMPnetDiameterTraversalTime, mask,
+                                 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
+                                 nla_get_u16);
+       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
+                                 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
+       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
+                                 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
+                                 nla_get_u16);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
-                       dot11MeshHWMPRannInterval, mask,
-                       NL80211_MESHCONF_HWMP_RANN_INTERVAL,
-                       nla_get_u16);
-       FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
-                       dot11MeshGateAnnouncementProtocol, mask,
-                       NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
-                       nla_get_u8);
+                                 dot11MeshGateAnnouncementProtocol, mask,
+                                 NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
+                                 nla_get_u8);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
-                       mask, NL80211_MESHCONF_FORWARDING, nla_get_u8);
+                                 mask, NL80211_MESHCONF_FORWARDING,
+                                 nla_get_u8);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
-                       mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32);
+                                 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
+                                 nla_get_u32);
        FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode,
-                       mask, NL80211_MESHCONF_HT_OPMODE, nla_get_u16);
+                                 mask, NL80211_MESHCONF_HT_OPMODE,
+                                 nla_get_u16);
+       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
+                                 mask,
+                                 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
+                                 nla_get_u32);
+       FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval,
+                                 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
+                                 nla_get_u16);
+       FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
+                                 dot11MeshHWMPconfirmationInterval, mask,
+                                 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
+                                 nla_get_u16);
        if (mask_out)
                *mask_out = mask;
 
@@ -3627,8 +4010,7 @@ static int nl80211_update_mesh_config(struct sk_buff *skb,
                err = -ENOLINK;
 
        if (!err)
-               err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
-                                                   mask, &cfg);
+               err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
 
        wdev_unlock(wdev);
 
@@ -3654,7 +4036,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
                goto out;
        }
 
-       hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+       hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                             NL80211_CMD_GET_REG);
        if (!hdr)
                goto put_failure;
@@ -3666,6 +4048,11 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
                        cfg80211_regdomain->dfs_region)))
                goto nla_put_failure;
 
+       if (reg_last_request_cell_base() &&
+           nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
+                       NL80211_USER_REG_HINT_CELL_BASE))
+               goto nla_put_failure;
+
        nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
        if (!nl_reg_rules)
                goto nla_put_failure;
@@ -3831,7 +4218,7 @@ static int validate_scan_freqs(struct nlattr *freqs)
 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
-       struct net_device *dev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
        struct cfg80211_scan_request *request;
        struct nlattr *attr;
        struct wiphy *wiphy;
@@ -3988,18 +4375,32 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
                }
        }
 
+       if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
+               request->flags = nla_get_u32(
+                       info->attrs[NL80211_ATTR_SCAN_FLAGS]);
+               if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
+                    !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
+                   ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
+                    !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
+                       err = -EOPNOTSUPP;
+                       goto out_free;
+               }
+       }
+
        request->no_cck =
                nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
 
-       request->dev = dev;
+       request->wdev = wdev;
        request->wiphy = &rdev->wiphy;
+       request->scan_start = jiffies;
 
        rdev->scan_req = request;
-       err = rdev->ops->scan(&rdev->wiphy, dev, request);
+       err = rdev_scan(rdev, request);
 
        if (!err) {
-               nl80211_send_scan_start(rdev, dev);
-               dev_hold(dev);
+               nl80211_send_scan_start(rdev, wdev);
+               if (wdev->netdev)
+                       dev_hold(wdev->netdev);
        } else {
  out_free:
                rdev->scan_req = NULL;
@@ -4185,12 +4586,12 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
                nla_for_each_nested(attr,
                                    info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
                                    tmp) {
-                       struct nlattr *ssid;
+                       struct nlattr *ssid, *rssi;
 
                        nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
                                  nla_data(attr), nla_len(attr),
                                  nl80211_match_policy);
-                       ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
+                       ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
                        if (ssid) {
                                if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
                                        err = -EINVAL;
@@ -4201,6 +4602,12 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
                                request->match_sets[i].ssid.ssid_len =
                                        nla_len(ssid);
                        }
+                       rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
+                       if (rssi)
+                               request->rssi_thold = nla_get_u32(rssi);
+                       else
+                               request->rssi_thold =
+                                                  NL80211_SCAN_RSSI_THOLD_OFF;
                        i++;
                }
        }
@@ -4212,11 +4619,24 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
                       request->ie_len);
        }
 
+       if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
+               request->flags = nla_get_u32(
+                       info->attrs[NL80211_ATTR_SCAN_FLAGS]);
+               if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
+                    !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
+                   ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
+                    !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
+                       err = -EOPNOTSUPP;
+                       goto out_free;
+               }
+       }
+
        request->dev = dev;
        request->wiphy = &rdev->wiphy;
        request->interval = interval;
+       request->scan_start = jiffies;
 
-       err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
+       err = rdev_sched_scan_start(rdev, dev, request);
        if (!err) {
                rdev->sched_scan_req = request;
                nl80211_send_sched_scan(rdev, dev,
@@ -4260,7 +4680,7 @@ static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
 
        ASSERT_WDEV_LOCK(wdev);
 
-       hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
+       hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
                             NL80211_CMD_NEW_SCAN_RESULTS);
        if (!hdr)
                return -1;
@@ -4379,14 +4799,14 @@ static int nl80211_dump_scan(struct sk_buff *skb,
        return skb->len;
 }
 
-static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
+static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
                                int flags, struct net_device *dev,
                                struct survey_info *survey)
 {
        void *hdr;
        struct nlattr *infoattr;
 
-       hdr = nl80211hdr_put(msg, pid, seq, flags,
+       hdr = nl80211hdr_put(msg, portid, seq, flags,
                             NL80211_CMD_NEW_SURVEY_RESULTS);
        if (!hdr)
                return -ENOMEM;
@@ -4459,8 +4879,7 @@ static int nl80211_dump_survey(struct sk_buff *skb,
        while (1) {
                struct ieee80211_channel *chan;
 
-               res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
-                                           &survey);
+               res = rdev_dump_survey(dev, netdev, survey_idx, &survey);
                if (res == -ENOENT)
                        break;
                if (res)
@@ -4480,7 +4899,7 @@ static int nl80211_dump_survey(struct sk_buff *skb,
                }
 
                if (nl80211_send_survey(skb,
-                               NETLINK_CB(cb->skb).pid,
+                               NETLINK_CB(cb->skb).portid,
                                cb->nlh->nlmsg_seq, NLM_F_MULTI,
                                netdev,
                                &survey) < 0)
@@ -4496,11 +4915,6 @@ static int nl80211_dump_survey(struct sk_buff *skb,
        return res;
 }
 
-static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
-{
-       return auth_type <= NL80211_AUTHTYPE_MAX;
-}
-
 static bool nl80211_valid_wpa_versions(u32 wpa_versions)
 {
        return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
@@ -4512,8 +4926,8 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
        struct net_device *dev = info->user_ptr[1];
        struct ieee80211_channel *chan;
-       const u8 *bssid, *ssid, *ie = NULL;
-       int err, ssid_len, ie_len = 0;
+       const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
+       int err, ssid_len, ie_len = 0, sae_data_len = 0;
        enum nl80211_auth_type auth_type;
        struct key_parse key;
        bool local_state_change;
@@ -4589,9 +5003,23 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
        }
 
        auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
-       if (!nl80211_valid_auth_type(auth_type))
+       if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
                return -EINVAL;
 
+       if (auth_type == NL80211_AUTHTYPE_SAE &&
+           !info->attrs[NL80211_ATTR_SAE_DATA])
+               return -EINVAL;
+
+       if (info->attrs[NL80211_ATTR_SAE_DATA]) {
+               if (auth_type != NL80211_AUTHTYPE_SAE)
+                       return -EINVAL;
+               sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
+               sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
+               /* need to include at least Auth Transaction and Status Code */
+               if (sae_data_len < 4)
+                       return -EINVAL;
+       }
+
        local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
 
        /*
@@ -4603,7 +5031,8 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
 
        return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
                                  ssid, ssid_len, ie, ie_len,
-                                 key.p.key, key.p.key_len, key.idx);
+                                 key.p.key, key.p.key_len, key.idx,
+                                 sae_data, sae_data_len);
 }
 
 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
@@ -4983,10 +5412,18 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
                return -EINVAL;
 
        if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
+               bool no_ht = false;
+
                connkeys = nl80211_parse_connkeys(rdev,
-                                       info->attrs[NL80211_ATTR_KEYS]);
+                                         info->attrs[NL80211_ATTR_KEYS],
+                                         &no_ht);
                if (IS_ERR(connkeys))
                        return PTR_ERR(connkeys);
+
+               if ((ibss.channel_type != NL80211_CHAN_NO_HT) && no_ht) {
+                       kfree(connkeys);
+                       return -EINVAL;
+               }
        }
 
        ibss.control_port =
@@ -5012,6 +5449,36 @@ static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
        return cfg80211_leave_ibss(rdev, dev, false);
 }
 
+static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *rdev = info->user_ptr[0];
+       struct net_device *dev = info->user_ptr[1];
+       int mcast_rate[IEEE80211_NUM_BANDS];
+       u32 nla_rate;
+       int err;
+
+       if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
+           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
+               return -EOPNOTSUPP;
+
+       if (!rdev->ops->set_mcast_rate)
+               return -EOPNOTSUPP;
+
+       memset(mcast_rate, 0, sizeof(mcast_rate));
+
+       if (!info->attrs[NL80211_ATTR_MCAST_RATE])
+               return -EINVAL;
+
+       nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
+       if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
+               return -EINVAL;
+
+       err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
+
+       return err;
+}
+
+
 #ifdef CONFIG_NL80211_TESTMODE
 static struct genl_multicast_group nl80211_testmode_mcgrp = {
        .name = "testmode",
@@ -5028,7 +5495,7 @@ static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
        err = -EOPNOTSUPP;
        if (rdev->ops->testmode_cmd) {
                rdev->testmode_info = info;
-               err = rdev->ops->testmode_cmd(&rdev->wiphy,
+               err = rdev_testmode_cmd(rdev,
                                nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
                                nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
                rdev->testmode_info = NULL;
@@ -5058,21 +5525,18 @@ static int nl80211_testmode_dump(struct sk_buff *skb,
                                  nl80211_policy);
                if (err)
                        return err;
-               if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
-                       phy_idx = nla_get_u32(
-                               nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
-               } else {
-                       struct net_device *netdev;
 
-                       err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
-                                                     nl80211_fam.attrbuf,
-                                                     &rdev, &netdev);
-                       if (err)
-                               return err;
-                       dev_put(netdev);
-                       phy_idx = rdev->wiphy_idx;
-                       cfg80211_unlock_rdev(rdev);
+               mutex_lock(&cfg80211_mutex);
+               rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
+                                                 nl80211_fam.attrbuf);
+               if (IS_ERR(rdev)) {
+                       mutex_unlock(&cfg80211_mutex);
+                       return PTR_ERR(rdev);
                }
+               phy_idx = rdev->wiphy_idx;
+               rdev = NULL;
+               mutex_unlock(&cfg80211_mutex);
+
                if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
                        cb->args[1] =
                                (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
@@ -5098,7 +5562,7 @@ static int nl80211_testmode_dump(struct sk_buff *skb,
        }
 
        while (1) {
-               void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
+               void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
                                           cb->nlh->nlmsg_seq, NLM_F_MULTI,
                                           NL80211_CMD_TESTMODE);
                struct nlattr *tmdata;
@@ -5113,8 +5577,7 @@ static int nl80211_testmode_dump(struct sk_buff *skb,
                        genlmsg_cancel(skb, hdr);
                        break;
                }
-               err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
-                                              data, data_len);
+               err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
                nla_nest_end(skb, tmdata);
 
                if (err == -ENOBUFS || err == -ENOENT) {
@@ -5138,7 +5601,7 @@ static int nl80211_testmode_dump(struct sk_buff *skb,
 
 static struct sk_buff *
 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
-                             int approxlen, u32 pid, u32 seq, gfp_t gfp)
+                             int approxlen, u32 portid, u32 seq, gfp_t gfp)
 {
        struct sk_buff *skb;
        void *hdr;
@@ -5148,7 +5611,7 @@ __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
        if (!skb)
                return NULL;
 
-       hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE);
+       hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
        if (!hdr) {
                kfree_skb(skb);
                return NULL;
@@ -5178,7 +5641,7 @@ struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
                return NULL;
 
        return __cfg80211_testmode_alloc_skb(rdev, approxlen,
-                               rdev->testmode_info->snd_pid,
+                               rdev->testmode_info->snd_portid,
                                rdev->testmode_info->snd_seq,
                                GFP_KERNEL);
 }
@@ -5243,7 +5706,8 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
        if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
                connect.auth_type =
                        nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
-               if (!nl80211_valid_auth_type(connect.auth_type))
+               if (!nl80211_valid_auth_type(rdev, connect.auth_type,
+                                            NL80211_CMD_CONNECT))
                        return -EINVAL;
        } else
                connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
@@ -5289,7 +5753,7 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
 
        if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
                connkeys = nl80211_parse_connkeys(rdev,
-                                       info->attrs[NL80211_ATTR_KEYS]);
+                                         info->attrs[NL80211_ATTR_KEYS], NULL);
                if (IS_ERR(connkeys))
                        return PTR_ERR(connkeys);
        }
@@ -5303,8 +5767,10 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
                       sizeof(connect.ht_capa_mask));
 
        if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
-               if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
+               if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
+                       kfree(connkeys);
                        return -EINVAL;
+               }
                memcpy(&connect.ht_capa,
                       nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
                       sizeof(connect.ht_capa));
@@ -5416,7 +5882,7 @@ static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
        if (!rdev->ops->flush_pmksa)
                return -EOPNOTSUPP;
 
-       return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
+       return rdev_flush_pmksa(rdev, dev);
 }
 
 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
@@ -5443,10 +5909,10 @@ static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
        status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
        dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
 
-       return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
-                                   dialog_token, status_code,
-                                   nla_data(info->attrs[NL80211_ATTR_IE]),
-                                   nla_len(info->attrs[NL80211_ATTR_IE]));
+       return rdev_tdls_mgmt(rdev, dev, peer, action_code,
+                             dialog_token, status_code,
+                             nla_data(info->attrs[NL80211_ATTR_IE]),
+                             nla_len(info->attrs[NL80211_ATTR_IE]));
 }
 
 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
@@ -5467,14 +5933,14 @@ static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
        operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
        peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
 
-       return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
+       return rdev_tdls_oper(rdev, dev, peer, operation);
 }
 
 static int nl80211_remain_on_channel(struct sk_buff *skb,
                                     struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
-       struct net_device *dev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
        struct ieee80211_channel *chan;
        struct sk_buff *msg;
        void *hdr;
@@ -5489,18 +5955,18 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,
 
        duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
 
+       if (!rdev->ops->remain_on_channel ||
+           !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
+               return -EOPNOTSUPP;
+
        /*
-        * We should be on that channel for at least one jiffie,
-        * and more than 5 seconds seems excessive.
+        * We should be on that channel for at least a minimum amount of
+        * time (10ms) but no longer than the driver supports.
         */
-       if (!duration || !msecs_to_jiffies(duration) ||
+       if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
            duration > rdev->wiphy.max_remain_on_channel_duration)
                return -EINVAL;
 
-       if (!rdev->ops->remain_on_channel ||
-           !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
-               return -EOPNOTSUPP;
-
        if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
            !nl80211_valid_channel_type(info, &channel_type))
                return -EINVAL;
@@ -5514,7 +5980,7 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,
        if (!msg)
                return -ENOMEM;
 
-       hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+       hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                             NL80211_CMD_REMAIN_ON_CHANNEL);
 
        if (IS_ERR(hdr)) {
@@ -5522,8 +5988,8 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,
                goto free_msg;
        }
 
-       err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
-                                          channel_type, duration, &cookie);
+       err = rdev_remain_on_channel(rdev, wdev, chan, channel_type, duration,
+                                    &cookie);
 
        if (err)
                goto free_msg;
@@ -5546,7 +6012,7 @@ static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
                                            struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
-       struct net_device *dev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
        u64 cookie;
 
        if (!info->attrs[NL80211_ATTR_COOKIE])
@@ -5557,7 +6023,7 @@ static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
 
        cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
 
-       return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
+       return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
 }
 
 static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
@@ -5700,13 +6166,13 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
                }
        }
 
-       return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
+       return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
 }
 
 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
-       struct net_device *dev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
        u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
 
        if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
@@ -5715,21 +6181,25 @@ static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
        if (info->attrs[NL80211_ATTR_FRAME_TYPE])
                frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
 
-       if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
+       switch (wdev->iftype) {
+       case NL80211_IFTYPE_STATION:
+       case NL80211_IFTYPE_ADHOC:
+       case NL80211_IFTYPE_P2P_CLIENT:
+       case NL80211_IFTYPE_AP:
+       case NL80211_IFTYPE_AP_VLAN:
+       case NL80211_IFTYPE_MESH_POINT:
+       case NL80211_IFTYPE_P2P_GO:
+       case NL80211_IFTYPE_P2P_DEVICE:
+               break;
+       default:
                return -EOPNOTSUPP;
+       }
 
        /* not much point in registering if we can't reply */
        if (!rdev->ops->mgmt_tx)
                return -EOPNOTSUPP;
 
-       return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
-                       frame_type,
+       return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
                        nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
                        nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
 }
@@ -5737,7 +6207,7 @@ static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
-       struct net_device *dev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
        struct ieee80211_channel *chan;
        enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
        bool channel_type_valid = false;
@@ -5758,19 +6228,33 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
        if (!rdev->ops->mgmt_tx)
                return -EOPNOTSUPP;
 
-       if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
+       switch (wdev->iftype) {
+       case NL80211_IFTYPE_STATION:
+       case NL80211_IFTYPE_ADHOC:
+       case NL80211_IFTYPE_P2P_CLIENT:
+       case NL80211_IFTYPE_AP:
+       case NL80211_IFTYPE_AP_VLAN:
+       case NL80211_IFTYPE_MESH_POINT:
+       case NL80211_IFTYPE_P2P_GO:
+       case NL80211_IFTYPE_P2P_DEVICE:
+               break;
+       default:
                return -EOPNOTSUPP;
+       }
 
        if (info->attrs[NL80211_ATTR_DURATION]) {
                if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
                        return -EINVAL;
                wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
+
+               /*
+                * We should wait on the channel for at least a minimum amount
+                * of time (10ms) but no longer than the driver supports.
+                */
+               if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
+                   wait > rdev->wiphy.max_remain_on_channel_duration)
+                       return -EINVAL;
+
        }
 
        if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
@@ -5796,7 +6280,7 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
                if (!msg)
                        return -ENOMEM;
 
-               hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+               hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                                     NL80211_CMD_FRAME);
 
                if (IS_ERR(hdr)) {
@@ -5805,7 +6289,7 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
                }
        }
 
-       err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
+       err = cfg80211_mlme_mgmt_tx(rdev, wdev, chan, offchan, channel_type,
                                    channel_type_valid, wait,
                                    nla_data(info->attrs[NL80211_ATTR_FRAME]),
                                    nla_len(info->attrs[NL80211_ATTR_FRAME]),
@@ -5833,7 +6317,7 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
-       struct net_device *dev = info->user_ptr[1];
+       struct wireless_dev *wdev = info->user_ptr[1];
        u64 cookie;
 
        if (!info->attrs[NL80211_ATTR_COOKIE])
@@ -5842,17 +6326,22 @@ static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *in
        if (!rdev->ops->mgmt_tx_cancel_wait)
                return -EOPNOTSUPP;
 
-       if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
-           dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
+       switch (wdev->iftype) {
+       case NL80211_IFTYPE_STATION:
+       case NL80211_IFTYPE_ADHOC:
+       case NL80211_IFTYPE_P2P_CLIENT:
+       case NL80211_IFTYPE_AP:
+       case NL80211_IFTYPE_AP_VLAN:
+       case NL80211_IFTYPE_P2P_GO:
+       case NL80211_IFTYPE_P2P_DEVICE:
+               break;
+       default:
                return -EOPNOTSUPP;
+       }
 
        cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
 
-       return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
+       return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
 }
 
 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
@@ -5882,8 +6371,7 @@ static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
        if (state == wdev->ps)
                return 0;
 
-       err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
-                                       wdev->ps_timeout);
+       err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
        if (!err)
                wdev->ps = state;
        return err;
@@ -5908,7 +6396,7 @@ static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
        if (!msg)
                return -ENOMEM;
 
-       hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+       hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                             NL80211_CMD_GET_POWER_SAVE);
        if (!hdr) {
                err = -ENOBUFS;
@@ -5938,8 +6426,34 @@ nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
        [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
        [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
        [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
+       [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
+       [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
+       [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
 };
 
+static int nl80211_set_cqm_txe(struct genl_info *info,
+                               u32 rate, u32 pkts, u32 intvl)
+{
+       struct cfg80211_registered_device *rdev = info->user_ptr[0];
+       struct wireless_dev *wdev;
+       struct net_device *dev = info->user_ptr[1];
+
+       if ((rate < 0 || rate > 100) ||
+           (intvl < 0 || intvl > NL80211_CQM_TXE_MAX_INTVL))
+               return -EINVAL;
+
+       wdev = dev->ieee80211_ptr;
+
+       if (!rdev->ops->set_cqm_txe_config)
+               return -EOPNOTSUPP;
+
+       if (wdev->iftype != NL80211_IFTYPE_STATION &&
+           wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
+               return -EOPNOTSUPP;
+
+       return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
+}
+
 static int nl80211_set_cqm_rssi(struct genl_info *info,
                                s32 threshold, u32 hysteresis)
 {
@@ -5959,8 +6473,7 @@ static int nl80211_set_cqm_rssi(struct genl_info *info,
            wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
                return -EOPNOTSUPP;
 
-       return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
-                                             threshold, hysteresis);
+       return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
 }
 
 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
@@ -5987,6 +6500,14 @@ static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
                threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
                hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
                err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
+       } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
+                  attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
+                  attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
+               u32 rate, pkts, intvl;
+               rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
+               pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
+               intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
+               err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
        } else
                err = -EINVAL;
 
@@ -6032,6 +6553,24 @@ static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
                        return err;
        }
 
+       if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
+               enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
+
+               if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
+                   !nl80211_valid_channel_type(info, &channel_type))
+                       return -EINVAL;
+
+               setup.channel = rdev_freq_to_chan(rdev,
+                       nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
+                       channel_type);
+               if (!setup.channel)
+                       return -EINVAL;
+               setup.channel_type = channel_type;
+       } else {
+               /* cfg80211_join_mesh() will sort it out */
+               setup.channel = NULL;
+       }
+
        return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
 }
 
@@ -6043,6 +6582,7 @@ static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
        return cfg80211_leave_mesh(rdev, dev);
 }
 
+#ifdef CONFIG_PM
 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
@@ -6056,7 +6596,7 @@ static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
        if (!msg)
                return -ENOMEM;
 
-       hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+       hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                             NL80211_CMD_GET_WOWLAN);
        if (!hdr)
                goto nla_put_failure;
@@ -6124,8 +6664,8 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
        struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
-       struct cfg80211_wowlan no_triggers = {};
        struct cfg80211_wowlan new_triggers = {};
+       struct cfg80211_wowlan *ntrig;
        struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
        int err, i;
        bool prev_enabled = rdev->wowlan;
@@ -6133,8 +6673,11 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
        if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
                return -EOPNOTSUPP;
 
-       if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
-               goto no_triggers;
+       if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
+               cfg80211_rdev_free_wowlan(rdev);
+               rdev->wowlan = NULL;
+               goto set_wakeup;
+       }
 
        err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
                        nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
@@ -6245,24 +6788,17 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
                }
        }
 
-       if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
-               struct cfg80211_wowlan *ntrig;
-               ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
-                               GFP_KERNEL);
-               if (!ntrig) {
-                       err = -ENOMEM;
-                       goto error;
-               }
-               cfg80211_rdev_free_wowlan(rdev);
-               rdev->wowlan = ntrig;
-       } else {
- no_triggers:
-               cfg80211_rdev_free_wowlan(rdev);
-               rdev->wowlan = NULL;
+       ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
+       if (!ntrig) {
+               err = -ENOMEM;
+               goto error;
        }
+       cfg80211_rdev_free_wowlan(rdev);
+       rdev->wowlan = ntrig;
 
+ set_wakeup:
        if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan)
-               rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan);
+               rdev_set_wakeup(rdev, rdev->wowlan);
 
        return 0;
  error:
@@ -6271,6 +6807,7 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
        kfree(new_triggers.patterns);
        return err;
 }
+#endif
 
 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
 {
@@ -6317,7 +6854,7 @@ static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
                goto out;
        }
 
-       err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
+       err = rdev_set_rekey_data(rdev, dev, &rekey_data);
  out:
        wdev_unlock(wdev);
        return err;
@@ -6333,10 +6870,10 @@ static int nl80211_register_unexpected_frame(struct sk_buff *skb,
            wdev->iftype != NL80211_IFTYPE_P2P_GO)
                return -EINVAL;
 
-       if (wdev->ap_unexpected_nlpid)
+       if (wdev->ap_unexpected_nlportid)
                return -EBUSY;
 
-       wdev->ap_unexpected_nlpid = info->snd_pid;
+       wdev->ap_unexpected_nlportid = info->snd_portid;
        return 0;
 }
 
@@ -6366,7 +6903,7 @@ static int nl80211_probe_client(struct sk_buff *skb,
        if (!msg)
                return -ENOMEM;
 
-       hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
+       hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
                             NL80211_CMD_PROBE_CLIENT);
 
        if (IS_ERR(hdr)) {
@@ -6376,7 +6913,7 @@ static int nl80211_probe_client(struct sk_buff *skb,
 
        addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
 
-       err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
+       err = rdev_probe_client(rdev, dev, addr, &cookie);
        if (err)
                goto free_msg;
 
@@ -6397,14 +6934,95 @@ static int nl80211_probe_client(struct sk_buff *skb,
 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
+       struct cfg80211_beacon_registration *reg, *nreg;
+       int rv;
 
        if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
                return -EOPNOTSUPP;
 
-       if (rdev->ap_beacons_nlpid)
-               return -EBUSY;
+       nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
+       if (!nreg)
+               return -ENOMEM;
 
-       rdev->ap_beacons_nlpid = info->snd_pid;
+       /* First, check if already registered. */
+       spin_lock_bh(&rdev->beacon_registrations_lock);
+       list_for_each_entry(reg, &rdev->beacon_registrations, list) {
+               if (reg->nlportid == info->snd_portid) {
+                       rv = -EALREADY;
+                       goto out_err;
+               }
+       }
+       /* Add it to the list */
+       nreg->nlportid = info->snd_portid;
+       list_add(&nreg->list, &rdev->beacon_registrations);
+
+       spin_unlock_bh(&rdev->beacon_registrations_lock);
+
+       return 0;
+out_err:
+       spin_unlock_bh(&rdev->beacon_registrations_lock);
+       kfree(nreg);
+       return rv;
+}
+
+static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *rdev = info->user_ptr[0];
+       struct wireless_dev *wdev = info->user_ptr[1];
+       int err;
+
+       if (!rdev->ops->start_p2p_device)
+               return -EOPNOTSUPP;
+
+       if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
+               return -EOPNOTSUPP;
+
+       if (wdev->p2p_started)
+               return 0;
+
+       mutex_lock(&rdev->devlist_mtx);
+       err = cfg80211_can_add_interface(rdev, wdev->iftype);
+       mutex_unlock(&rdev->devlist_mtx);
+       if (err)
+               return err;
+
+       err = rdev_start_p2p_device(rdev, wdev);
+       if (err)
+               return err;
+
+       wdev->p2p_started = true;
+       mutex_lock(&rdev->devlist_mtx);
+       rdev->opencount++;
+       mutex_unlock(&rdev->devlist_mtx);
+
+       return 0;
+}
+
+static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
+{
+       struct cfg80211_registered_device *rdev = info->user_ptr[0];
+       struct wireless_dev *wdev = info->user_ptr[1];
+
+       if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
+               return -EOPNOTSUPP;
+
+       if (!rdev->ops->stop_p2p_device)
+               return -EOPNOTSUPP;
+
+       if (!wdev->p2p_started)
+               return 0;
+
+       rdev_stop_p2p_device(rdev, wdev);
+       wdev->p2p_started = false;
+
+       mutex_lock(&rdev->devlist_mtx);
+       rdev->opencount--;
+       mutex_unlock(&rdev->devlist_mtx);
+
+       if (WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev)) {
+               rdev->scan_req->aborted = true;
+               ___cfg80211_scan_done(rdev, true);
+       }
 
        return 0;
 }
@@ -6415,44 +7033,82 @@ static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
 #define NL80211_FLAG_CHECK_NETDEV_UP   0x08
 #define NL80211_FLAG_NEED_NETDEV_UP    (NL80211_FLAG_NEED_NETDEV |\
                                         NL80211_FLAG_CHECK_NETDEV_UP)
+#define NL80211_FLAG_NEED_WDEV         0x10
+/* If a netdev is associated, it must be UP, P2P must be started */
+#define NL80211_FLAG_NEED_WDEV_UP      (NL80211_FLAG_NEED_WDEV |\
+                                        NL80211_FLAG_CHECK_NETDEV_UP)
 
 static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
                            struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev;
+       struct wireless_dev *wdev;
        struct net_device *dev;
-       int err;
        bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
 
        if (rtnl)
                rtnl_lock();
 
        if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
-               rdev = cfg80211_get_dev_from_info(info);
+               rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
                if (IS_ERR(rdev)) {
                        if (rtnl)
                                rtnl_unlock();
                        return PTR_ERR(rdev);
                }
                info->user_ptr[0] = rdev;
-       } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
-               err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
-                                             &rdev, &dev);
-               if (err) {
+       } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
+                  ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
+               mutex_lock(&cfg80211_mutex);
+               wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
+                                                 info->attrs);
+               if (IS_ERR(wdev)) {
+                       mutex_unlock(&cfg80211_mutex);
                        if (rtnl)
                                rtnl_unlock();
-                       return err;
+                       return PTR_ERR(wdev);
                }
-               if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
-                   !netif_running(dev)) {
-                       cfg80211_unlock_rdev(rdev);
-                       dev_put(dev);
-                       if (rtnl)
-                               rtnl_unlock();
-                       return -ENETDOWN;
+
+               dev = wdev->netdev;
+               rdev = wiphy_to_dev(wdev->wiphy);
+
+               if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
+                       if (!dev) {
+                               mutex_unlock(&cfg80211_mutex);
+                               if (rtnl)
+                                       rtnl_unlock();
+                               return -EINVAL;
+                       }
+
+                       info->user_ptr[1] = dev;
+               } else {
+                       info->user_ptr[1] = wdev;
                }
+
+               if (dev) {
+                       if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
+                           !netif_running(dev)) {
+                               mutex_unlock(&cfg80211_mutex);
+                               if (rtnl)
+                                       rtnl_unlock();
+                               return -ENETDOWN;
+                       }
+
+                       dev_hold(dev);
+               } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
+                       if (!wdev->p2p_started) {
+                               mutex_unlock(&cfg80211_mutex);
+                               if (rtnl)
+                                       rtnl_unlock();
+                               return -ENETDOWN;
+                       }
+               }
+
+               cfg80211_lock_rdev(rdev);
+
+               mutex_unlock(&cfg80211_mutex);
+
                info->user_ptr[0] = rdev;
-               info->user_ptr[1] = dev;
        }
 
        return 0;
@@ -6463,8 +7119,16 @@ static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
 {
        if (info->user_ptr[0])
                cfg80211_unlock_rdev(info->user_ptr[0]);
-       if (info->user_ptr[1])
-               dev_put(info->user_ptr[1]);
+       if (info->user_ptr[1]) {
+               if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
+                       struct wireless_dev *wdev = info->user_ptr[1];
+
+                       if (wdev->netdev)
+                               dev_put(wdev->netdev);
+               } else {
+                       dev_put(info->user_ptr[1]);
+               }
+       }
        if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
                rtnl_unlock();
 }
@@ -6491,7 +7155,7 @@ static struct genl_ops nl80211_ops[] = {
                .dumpit = nl80211_dump_interface,
                .policy = nl80211_policy,
                /* can be retrieved by unprivileged users */
-               .internal_flags = NL80211_FLAG_NEED_NETDEV,
+               .internal_flags = NL80211_FLAG_NEED_WDEV,
        },
        {
                .cmd = NL80211_CMD_SET_INTERFACE,
@@ -6514,7 +7178,7 @@ static struct genl_ops nl80211_ops[] = {
                .doit = nl80211_del_interface,
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = NL80211_FLAG_NEED_NETDEV |
+               .internal_flags = NL80211_FLAG_NEED_WDEV |
                                  NL80211_FLAG_NEED_RTNL,
        },
        {
@@ -6685,7 +7349,7 @@ static struct genl_ops nl80211_ops[] = {
                .doit = nl80211_trigger_scan,
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
+               .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
                                  NL80211_FLAG_NEED_RTNL,
        },
        {
@@ -6826,7 +7490,7 @@ static struct genl_ops nl80211_ops[] = {
                .doit = nl80211_remain_on_channel,
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
+               .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
                                  NL80211_FLAG_NEED_RTNL,
        },
        {
@@ -6834,7 +7498,7 @@ static struct genl_ops nl80211_ops[] = {
                .doit = nl80211_cancel_remain_on_channel,
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
+               .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
                                  NL80211_FLAG_NEED_RTNL,
        },
        {
@@ -6850,7 +7514,7 @@ static struct genl_ops nl80211_ops[] = {
                .doit = nl80211_register_mgmt,
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = NL80211_FLAG_NEED_NETDEV |
+               .internal_flags = NL80211_FLAG_NEED_WDEV |
                                  NL80211_FLAG_NEED_RTNL,
        },
        {
@@ -6858,7 +7522,7 @@ static struct genl_ops nl80211_ops[] = {
                .doit = nl80211_tx_mgmt,
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
+               .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
                                  NL80211_FLAG_NEED_RTNL,
        },
        {
@@ -6866,7 +7530,7 @@ static struct genl_ops nl80211_ops[] = {
                .doit = nl80211_tx_mgmt_cancel_wait,
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
-               .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
+               .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
                                  NL80211_FLAG_NEED_RTNL,
        },
        {
@@ -6925,6 +7589,7 @@ static struct genl_ops nl80211_ops[] = {
                .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
                                  NL80211_FLAG_NEED_RTNL,
        },
+#ifdef CONFIG_PM
        {
                .cmd = NL80211_CMD_GET_WOWLAN,
                .doit = nl80211_get_wowlan,
@@ -6941,6 +7606,7 @@ static struct genl_ops nl80211_ops[] = {
                .internal_flags = NL80211_FLAG_NEED_WIPHY |
                                  NL80211_FLAG_NEED_RTNL,
        },
+#endif
        {
                .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
                .doit = nl80211_set_rekey_data,
@@ -6997,7 +7663,30 @@ static struct genl_ops nl80211_ops[] = {
                .internal_flags = NL80211_FLAG_NEED_NETDEV |
                                  NL80211_FLAG_NEED_RTNL,
        },
-
+       {
+               .cmd = NL80211_CMD_START_P2P_DEVICE,
+               .doit = nl80211_start_p2p_device,
+               .policy = nl80211_policy,
+               .flags = GENL_ADMIN_PERM,
+               .internal_flags = NL80211_FLAG_NEED_WDEV |
+                                 NL80211_FLAG_NEED_RTNL,
+       },
+       {
+               .cmd = NL80211_CMD_STOP_P2P_DEVICE,
+               .doit = nl80211_stop_p2p_device,
+               .policy = nl80211_policy,
+               .flags = GENL_ADMIN_PERM,
+               .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
+                                 NL80211_FLAG_NEED_RTNL,
+       },
+       {
+               .cmd = NL80211_CMD_SET_MCAST_RATE,
+               .doit = nl80211_set_mcast_rate,
+               .policy = nl80211_policy,
+               .flags = GENL_ADMIN_PERM,
+               .internal_flags = NL80211_FLAG_NEED_NETDEV |
+                                 NL80211_FLAG_NEED_RTNL,
+       },
 };
 
 static struct genl_multicast_group nl80211_mlme_mcgrp = {
@@ -7068,6 +7757,9 @@ static int nl80211_add_scan_req(struct sk_buff *msg,
            nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
                goto nla_put_failure;
 
+       if (req->flags)
+               nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
+
        return 0;
  nla_put_failure:
        return -ENOBUFS;
@@ -7075,18 +7767,20 @@ static int nl80211_add_scan_req(struct sk_buff *msg,
 
 static int nl80211_send_scan_msg(struct sk_buff *msg,
                                 struct cfg80211_registered_device *rdev,
-                                struct net_device *netdev,
-                                u32 pid, u32 seq, int flags,
+                                struct wireless_dev *wdev,
+                                u32 portid, u32 seq, int flags,
                                 u32 cmd)
 {
        void *hdr;
 
-       hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
+       hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
        if (!hdr)
                return -1;
 
        if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
-           nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
+           (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
+                                        wdev->netdev->ifindex)) ||
+           nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
                goto nla_put_failure;
 
        /* ignore errors and send incomplete event anyway */
@@ -7103,11 +7797,11 @@ static int
 nl80211_send_sched_scan_msg(struct sk_buff *msg,
                            struct cfg80211_registered_device *rdev,
                            struct net_device *netdev,
-                           u32 pid, u32 seq, int flags, u32 cmd)
+                           u32 portid, u32 seq, int flags, u32 cmd)
 {
        void *hdr;
 
-       hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
+       hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
        if (!hdr)
                return -1;
 
@@ -7123,15 +7817,15 @@ nl80211_send_sched_scan_msg(struct sk_buff *msg,
 }
 
 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
-                            struct net_device *netdev)
+                            struct wireless_dev *wdev)
 {
        struct sk_buff *msg;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
        if (!msg)
                return;
 
-       if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
+       if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
                                  NL80211_CMD_TRIGGER_SCAN) < 0) {
                nlmsg_free(msg);
                return;
@@ -7142,7 +7836,7 @@ void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
 }
 
 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
-                           struct net_device *netdev)
+                           struct wireless_dev *wdev)
 {
        struct sk_buff *msg;
 
@@ -7150,7 +7844,7 @@ void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
        if (!msg)
                return;
 
-       if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
+       if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
                                  NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
                nlmsg_free(msg);
                return;
@@ -7161,7 +7855,7 @@ void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
 }
 
 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
-                              struct net_device *netdev)
+                              struct wireless_dev *wdev)
 {
        struct sk_buff *msg;
 
@@ -7169,7 +7863,7 @@ void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
        if (!msg)
                return;
 
-       if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
+       if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
                                  NL80211_CMD_SCAN_ABORTED) < 0) {
                nlmsg_free(msg);
                return;
@@ -7203,7 +7897,7 @@ void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
 {
        struct sk_buff *msg;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
        if (!msg)
                return;
 
@@ -7419,7 +8113,7 @@ void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
        struct sk_buff *msg;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -7459,7 +8153,7 @@ void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
        struct sk_buff *msg;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -7497,7 +8191,7 @@ void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
        struct sk_buff *msg;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
        if (!msg)
                return;
 
@@ -7692,7 +8386,7 @@ nla_put_failure:
 
 static void nl80211_send_remain_on_chan_event(
        int cmd, struct cfg80211_registered_device *rdev,
-       struct net_device *netdev, u64 cookie,
+       struct wireless_dev *wdev, u64 cookie,
        struct ieee80211_channel *chan,
        enum nl80211_channel_type channel_type,
        unsigned int duration, gfp_t gfp)
@@ -7711,7 +8405,9 @@ static void nl80211_send_remain_on_chan_event(
        }
 
        if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
-           nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
+           (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
+                                        wdev->netdev->ifindex)) ||
+           nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
            nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
            nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) ||
            nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
@@ -7733,23 +8429,24 @@ static void nl80211_send_remain_on_chan_event(
 }
 
 void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
-                                   struct net_device *netdev, u64 cookie,
+                                   struct wireless_dev *wdev, u64 cookie,
                                    struct ieee80211_channel *chan,
                                    enum nl80211_channel_type channel_type,
                                    unsigned int duration, gfp_t gfp)
 {
        nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
-                                         rdev, netdev, cookie, chan,
+                                         rdev, wdev, cookie, chan,
                                          channel_type, duration, gfp);
 }
 
 void nl80211_send_remain_on_channel_cancel(
-       struct cfg80211_registered_device *rdev, struct net_device *netdev,
+       struct cfg80211_registered_device *rdev,
+       struct wireless_dev *wdev,
        u64 cookie, struct ieee80211_channel *chan,
        enum nl80211_channel_type channel_type, gfp_t gfp)
 {
        nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
-                                         rdev, netdev, cookie, chan,
+                                         rdev, wdev, cookie, chan,
                                          channel_type, 0, gfp);
 }
 
@@ -7759,7 +8456,7 @@ void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
 {
        struct sk_buff *msg;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -7780,7 +8477,7 @@ void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
        struct sk_buff *msg;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -7805,6 +8502,40 @@ void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
        nlmsg_free(msg);
 }
 
+void nl80211_send_conn_failed_event(struct cfg80211_registered_device *rdev,
+                                   struct net_device *dev, const u8 *mac_addr,
+                                   enum nl80211_connect_failed_reason reason,
+                                   gfp_t gfp)
+{
+       struct sk_buff *msg;
+       void *hdr;
+
+       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       if (!msg)
+               return;
+
+       hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
+       if (!hdr) {
+               nlmsg_free(msg);
+               return;
+       }
+
+       if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
+           nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
+           nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
+               goto nla_put_failure;
+
+       genlmsg_end(msg, hdr);
+
+       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
+                               nl80211_mlme_mcgrp.id, gfp);
+       return;
+
+ nla_put_failure:
+       genlmsg_cancel(msg, hdr);
+       nlmsg_free(msg);
+}
+
 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
                                       const u8 *addr, gfp_t gfp)
 {
@@ -7813,9 +8544,9 @@ static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
        struct sk_buff *msg;
        void *hdr;
        int err;
-       u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
+       u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
 
-       if (!nlpid)
+       if (!nlportid)
                return false;
 
        msg = nlmsg_new(100, gfp);
@@ -7839,7 +8570,7 @@ static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
                return true;
        }
 
-       genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
+       genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
        return true;
 
  nla_put_failure:
@@ -7863,10 +8594,11 @@ bool nl80211_unexpected_4addr_frame(struct net_device *dev,
 }
 
 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
-                     struct net_device *netdev, u32 nlpid,
+                     struct wireless_dev *wdev, u32 nlportid,
                      int freq, int sig_dbm,
                      const u8 *buf, size_t len, gfp_t gfp)
 {
+       struct net_device *netdev = wdev->netdev;
        struct sk_buff *msg;
        void *hdr;
 
@@ -7881,7 +8613,8 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
        }
 
        if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
-           nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
+           (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
+                                       netdev->ifindex)) ||
            nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
            (sig_dbm &&
             nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
@@ -7890,7 +8623,7 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
+       return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
 
  nla_put_failure:
        genlmsg_cancel(msg, hdr);
@@ -7899,10 +8632,11 @@ int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
 }
 
 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
-                                struct net_device *netdev, u64 cookie,
+                                struct wireless_dev *wdev, u64 cookie,
                                 const u8 *buf, size_t len, bool ack,
                                 gfp_t gfp)
 {
+       struct net_device *netdev = wdev->netdev;
        struct sk_buff *msg;
        void *hdr;
 
@@ -7917,7 +8651,8 @@ void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
        }
 
        if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
-           nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
+           (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
+                                  netdev->ifindex)) ||
            nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
            nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
            (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
@@ -7943,7 +8678,7 @@ nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
        struct nlattr *pinfoattr;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -7986,7 +8721,7 @@ void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
        struct nlattr *rekey_attr;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -8030,7 +8765,7 @@ void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
        struct nlattr *attr;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -8074,7 +8809,7 @@ void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
        struct sk_buff *msg;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -8101,6 +8836,56 @@ void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
 }
 
 void
+nl80211_send_cqm_txe_notify(struct cfg80211_registered_device *rdev,
+                           struct net_device *netdev, const u8 *peer,
+                           u32 num_packets, u32 rate, u32 intvl, gfp_t gfp)
+{
+       struct sk_buff *msg;
+       struct nlattr *pinfoattr;
+       void *hdr;
+
+       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       if (!msg)
+               return;
+
+       hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
+       if (!hdr) {
+               nlmsg_free(msg);
+               return;
+       }
+
+       if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
+           nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
+           nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
+               goto nla_put_failure;
+
+       pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
+       if (!pinfoattr)
+               goto nla_put_failure;
+
+       if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
+               goto nla_put_failure;
+
+       if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
+               goto nla_put_failure;
+
+       if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
+               goto nla_put_failure;
+
+       nla_nest_end(msg, pinfoattr);
+
+       genlmsg_end(msg, hdr);
+
+       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
+                               nl80211_mlme_mcgrp.id, gfp);
+       return;
+
+ nla_put_failure:
+       genlmsg_cancel(msg, hdr);
+       nlmsg_free(msg);
+}
+
+void
 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
                                struct net_device *netdev, const u8 *peer,
                                u32 num_packets, gfp_t gfp)
@@ -8109,7 +8894,7 @@ nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
        struct nlattr *pinfoattr;
        void *hdr;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
        if (!msg)
                return;
 
@@ -8153,7 +8938,10 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
        void *hdr;
        int err;
 
-       msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
+       trace_cfg80211_probe_status(dev, addr, cookie, acked);
+
+       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
+
        if (!msg)
                return;
 
@@ -8188,41 +8976,46 @@ EXPORT_SYMBOL(cfg80211_probe_status);
 
 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
                                 const u8 *frame, size_t len,
-                                int freq, int sig_dbm, gfp_t gfp)
+                                int freq, int sig_dbm)
 {
        struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
        struct sk_buff *msg;
        void *hdr;
-       u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
+       struct cfg80211_beacon_registration *reg;
 
-       if (!nlpid)
-               return;
+       trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
 
-       msg = nlmsg_new(len + 100, gfp);
-       if (!msg)
-               return;
+       spin_lock_bh(&rdev->beacon_registrations_lock);
+       list_for_each_entry(reg, &rdev->beacon_registrations, list) {
+               msg = nlmsg_new(len + 100, GFP_ATOMIC);
+               if (!msg) {
+                       spin_unlock_bh(&rdev->beacon_registrations_lock);
+                       return;
+               }
 
-       hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
-       if (!hdr) {
-               nlmsg_free(msg);
-               return;
-       }
+               hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
+               if (!hdr)
+                       goto nla_put_failure;
 
-       if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
-           (freq &&
-            nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
-           (sig_dbm &&
-            nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
-           nla_put(msg, NL80211_ATTR_FRAME, len, frame))
-               goto nla_put_failure;
+               if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
+                   (freq &&
+                    nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
+                   (sig_dbm &&
+                    nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
+                   nla_put(msg, NL80211_ATTR_FRAME, len, frame))
+                       goto nla_put_failure;
 
-       genlmsg_end(msg, hdr);
+               genlmsg_end(msg, hdr);
 
-       genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
+               genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
+       }
+       spin_unlock_bh(&rdev->beacon_registrations_lock);
        return;
 
  nla_put_failure:
-       genlmsg_cancel(msg, hdr);
+       spin_unlock_bh(&rdev->beacon_registrations_lock);
+       if (hdr)
+               genlmsg_cancel(msg, hdr);
        nlmsg_free(msg);
 }
 EXPORT_SYMBOL(cfg80211_report_obss_beacon);
@@ -8234,6 +9027,7 @@ static int nl80211_netlink_notify(struct notifier_block * nb,
        struct netlink_notify *notify = _notify;
        struct cfg80211_registered_device *rdev;
        struct wireless_dev *wdev;
+       struct cfg80211_beacon_registration *reg, *tmp;
 
        if (state != NETLINK_URELEASE)
                return NOTIFY_DONE;
@@ -8241,10 +9035,19 @@ static int nl80211_netlink_notify(struct notifier_block * nb,
        rcu_read_lock();
 
        list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
-               list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
-                       cfg80211_mlme_unregister_socket(wdev, notify->pid);
-               if (rdev->ap_beacons_nlpid == notify->pid)
-                       rdev->ap_beacons_nlpid = 0;
+               list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
+                       cfg80211_mlme_unregister_socket(wdev, notify->portid);
+
+               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);
+                               break;
+                       }
+               }
+               spin_unlock_bh(&rdev->beacon_registrations_lock);
        }
 
        rcu_read_unlock();