mwifiex: remove global user_scan_cfg variable
[cascardo/linux.git] / drivers / net / wireless / mwifiex / cfg80211.c
index 6505038..4dcb8fb 100644 (file)
 #include "cfg80211.h"
 #include "main.h"
 
+static const struct ieee80211_regdomain mwifiex_world_regdom_custom = {
+       .n_reg_rules = 7,
+       .alpha2 =  "99",
+       .reg_rules = {
+               /* Channel 1 - 11 */
+               REG_RULE(2412-10, 2462+10, 40, 3, 20, 0),
+               /* Channel 12 - 13 */
+               REG_RULE(2467-10, 2472+10, 20, 3, 20,
+                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
+               /* Channel 14 */
+               REG_RULE(2484-10, 2484+10, 20, 3, 20,
+                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
+                        NL80211_RRF_NO_OFDM),
+               /* Channel 36 - 48 */
+               REG_RULE(5180-10, 5240+10, 40, 3, 20,
+                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
+               /* Channel 149 - 165 */
+               REG_RULE(5745-10, 5825+10, 40, 3, 20,
+                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
+               /* Channel 52 - 64 */
+               REG_RULE(5260-10, 5320+10, 40, 3, 30,
+                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
+                        NL80211_RRF_DFS),
+               /* Channel 100 - 140 */
+               REG_RULE(5500-10, 5700+10, 40, 3, 30,
+                        NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS |
+                        NL80211_RRF_DFS),
+       }
+};
+
 /*
  * This function maps the nl802.11 channel type into driver channel type.
  *
@@ -90,6 +120,115 @@ mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev,
        return 0;
 }
 
+/*
+ * This function forms an skb for management frame.
+ */
+static int
+mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len)
+{
+       u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+       u16 pkt_len;
+       u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT;
+       struct timeval tv;
+
+       pkt_len = len + ETH_ALEN;
+
+       skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN +
+                   MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
+       memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len));
+
+       memcpy(skb_push(skb, sizeof(tx_control)),
+              &tx_control, sizeof(tx_control));
+
+       memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type));
+
+       /* Add packet data and address4 */
+       memcpy(skb_put(skb, sizeof(struct ieee80211_hdr_3addr)), buf,
+              sizeof(struct ieee80211_hdr_3addr));
+       memcpy(skb_put(skb, ETH_ALEN), addr, ETH_ALEN);
+       memcpy(skb_put(skb, len - sizeof(struct ieee80211_hdr_3addr)),
+              buf + sizeof(struct ieee80211_hdr_3addr),
+              len - sizeof(struct ieee80211_hdr_3addr));
+
+       skb->priority = LOW_PRIO_TID;
+       do_gettimeofday(&tv);
+       skb->tstamp = timeval_to_ktime(tv);
+
+       return 0;
+}
+
+/*
+ * CFG802.11 operation handler to transmit a management frame.
+ */
+static int
+mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
+                        struct ieee80211_channel *chan, bool offchan,
+                        enum nl80211_channel_type channel_type,
+                        bool channel_type_valid, unsigned int wait,
+                        const u8 *buf, size_t len, bool no_cck,
+                        bool dont_wait_for_ack, u64 *cookie)
+{
+       struct sk_buff *skb;
+       u16 pkt_len;
+       const struct ieee80211_mgmt *mgmt;
+       struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
+
+       if (!buf || !len) {
+               wiphy_err(wiphy, "invalid buffer and length\n");
+               return -EFAULT;
+       }
+
+       mgmt = (const struct ieee80211_mgmt *)buf;
+       if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA &&
+           ieee80211_is_probe_resp(mgmt->frame_control)) {
+               /* Since we support offload probe resp, we need to skip probe
+                * resp in AP or GO mode */
+               wiphy_dbg(wiphy,
+                         "info: skip to send probe resp in AP or GO mode\n");
+               return 0;
+       }
+
+       pkt_len = len + ETH_ALEN;
+       skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN +
+                           MWIFIEX_MGMT_FRAME_HEADER_SIZE +
+                           pkt_len + sizeof(pkt_len));
+
+       if (!skb) {
+               wiphy_err(wiphy, "allocate skb failed for management frame\n");
+               return -ENOMEM;
+       }
+
+       mwifiex_form_mgmt_frame(skb, buf, len);
+       mwifiex_queue_tx_pkt(priv, skb);
+
+       *cookie = random32() | 1;
+       cfg80211_mgmt_tx_status(dev, *cookie, buf, len, true, GFP_ATOMIC);
+
+       wiphy_dbg(wiphy, "info: management frame transmitted\n");
+       return 0;
+}
+
+/*
+ * CFG802.11 operation handler to register a mgmt frame.
+ */
+static void
+mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
+                                    struct net_device *dev,
+                                    u16 frame_type, bool reg)
+{
+       struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
+
+       if (reg)
+               priv->mgmt_frame_mask |= BIT(frame_type >> 4);
+       else
+               priv->mgmt_frame_mask &= ~BIT(frame_type >> 4);
+
+       mwifiex_send_cmd_async(priv, HostCmd_CMD_MGMT_FRAME_REG,
+                              HostCmd_ACT_GEN_SET, 0, &priv->mgmt_frame_mask);
+
+       wiphy_dbg(wiphy, "info: mgmt frame registered\n");
+}
+
 /*
  * CFG802.11 operation handler to set Tx power.
  */
@@ -345,8 +484,6 @@ mwifiex_set_rf_channel(struct mwifiex_private *priv,
                        mwifiex_cfg80211_channel_type_to_sec_chan_offset
                        (channel_type);
                adapter->channel_type = channel_type;
-
-               mwifiex_send_domain_info_cmd_fw(wiphy);
        }
 
        wiphy_dbg(wiphy, "info: setting band %d, chan offset %d, mode %d\n",
@@ -390,6 +527,41 @@ mwifiex_cfg80211_set_channel(struct wiphy *wiphy, struct net_device *dev,
        return mwifiex_set_rf_channel(priv, chan, channel_type);
 }
 
+static int
+mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
+{
+       struct mwifiex_private *priv = mwifiex_cfg80211_get_priv(wiphy);
+       struct mwifiex_adapter *adapter = priv->adapter;
+       struct mwifiex_ds_ant_cfg ant_cfg;
+
+       if (!tx_ant || !rx_ant)
+               return -EOPNOTSUPP;
+
+       if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) {
+               /* Not a MIMO chip. User should provide specific antenna number
+                * for Tx/Rx path or enable all antennas for diversity
+                */
+               if (tx_ant != rx_ant)
+                       return -EOPNOTSUPP;
+
+               if ((tx_ant & (tx_ant - 1)) &&
+                   (tx_ant != BIT(adapter->number_of_antenna) - 1))
+                       return -EOPNOTSUPP;
+
+               if ((tx_ant == BIT(adapter->number_of_antenna) - 1) &&
+                   (priv->adapter->number_of_antenna > 1)) {
+                       tx_ant = RF_ANTENNA_AUTO;
+                       rx_ant = RF_ANTENNA_AUTO;
+               }
+       }
+
+       ant_cfg.tx_ant = tx_ant;
+       ant_cfg.rx_ant = rx_ant;
+
+       return mwifiex_send_cmd_sync(priv, HostCmd_CMD_RF_ANTENNA,
+                                    HostCmd_ACT_GEN_SET, 0, &ant_cfg);
+}
+
 /*
  * This function sets the fragmentation threshold.
  *
@@ -516,25 +688,23 @@ static int
 mwifiex_dump_station_info(struct mwifiex_private *priv,
                          struct station_info *sinfo)
 {
-       struct mwifiex_ds_get_signal signal;
        struct mwifiex_rate_cfg rate;
-       int ret = 0;
 
        sinfo->filled = STATION_INFO_RX_BYTES | STATION_INFO_TX_BYTES |
-               STATION_INFO_RX_PACKETS |
-               STATION_INFO_TX_PACKETS
-               | STATION_INFO_SIGNAL | STATION_INFO_TX_BITRATE;
+                       STATION_INFO_RX_PACKETS | STATION_INFO_TX_PACKETS |
+                       STATION_INFO_TX_BITRATE |
+                       STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
 
        /* Get signal information from the firmware */
-       memset(&signal, 0, sizeof(struct mwifiex_ds_get_signal));
-       if (mwifiex_get_signal_info(priv, &signal)) {
-               dev_err(priv->adapter->dev, "getting signal information\n");
-               ret = -EFAULT;
+       if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
+                                 HostCmd_ACT_GEN_GET, 0, NULL)) {
+               dev_err(priv->adapter->dev, "failed to get signal information\n");
+               return -EFAULT;
        }
 
        if (mwifiex_drv_get_data_rate(priv, &rate)) {
                dev_err(priv->adapter->dev, "getting data rate\n");
-               ret = -EFAULT;
+               return -EFAULT;
        }
 
        /* Get DTIM period information from firmware */
@@ -544,9 +714,9 @@ mwifiex_dump_station_info(struct mwifiex_private *priv,
 
        /*
         * Bit 0 in tx_htinfo indicates that current Tx rate is 11n rate. Valid
-        * MCS index values for us are 0 to 7.
+        * MCS index values for us are 0 to 15.
         */
-       if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 8)) {
+       if ((priv->tx_htinfo & BIT(0)) && (priv->tx_rate < 16)) {
                sinfo->txrate.mcs = priv->tx_rate;
                sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
                /* 40MHz rate */
@@ -557,11 +727,12 @@ mwifiex_dump_station_info(struct mwifiex_private *priv,
                        sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
        }
 
+       sinfo->signal_avg = priv->bcn_rssi_avg;
        sinfo->rx_bytes = priv->stats.rx_bytes;
        sinfo->tx_bytes = priv->stats.tx_bytes;
        sinfo->rx_packets = priv->stats.rx_packets;
        sinfo->tx_packets = priv->stats.tx_packets;
-       sinfo->signal = priv->qual_level;
+       sinfo->signal = priv->bcn_rssi_avg;
        /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */
        sinfo->txrate.legacy = rate.rate * 5;
 
@@ -581,7 +752,7 @@ mwifiex_dump_station_info(struct mwifiex_private *priv,
                        priv->curr_bss_params.bss_descriptor.beacon_period;
        }
 
-       return ret;
+       return 0;
 }
 
 /*
@@ -604,6 +775,23 @@ mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
        return mwifiex_dump_station_info(priv, sinfo);
 }
 
+/*
+ * CFG802.11 operation handler to dump station information.
+ */
+static int
+mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
+                             int idx, u8 *mac, struct station_info *sinfo)
+{
+       struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
+
+       if (!priv->media_connected || idx)
+               return -ENOENT;
+
+       memcpy(mac, priv->cfg_bssid, ETH_ALEN);
+
+       return mwifiex_dump_station_info(priv, sinfo);
+}
+
 /* Supported rates to be advertised to the cfg80211 */
 
 static struct ieee80211_rate mwifiex_rates[] = {
@@ -698,11 +886,40 @@ static const u32 mwifiex_cipher_suites[] = {
        WLAN_CIPHER_SUITE_CCMP,
 };
 
+/* Supported mgmt frame types to be advertised to cfg80211 */
+static const struct ieee80211_txrx_stypes
+mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = {
+       [NL80211_IFTYPE_STATION] = {
+               .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
+               .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
+       },
+       [NL80211_IFTYPE_AP] = {
+               .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
+               .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
+       },
+       [NL80211_IFTYPE_P2P_CLIENT] = {
+               .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
+               .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
+       },
+       [NL80211_IFTYPE_P2P_GO] = {
+               .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
+               .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
+                     BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
+       },
+};
+
 /*
  * CFG802.11 operation handler for setting bit rates.
  *
- * Function selects legacy bang B/G/BG from corresponding bitrates selection.
- * Currently only 2.4GHz band is supported.
+ * Function configures data rates to firmware using bitrate mask
+ * provided by cfg80211.
  */
 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
                                struct net_device *dev,
@@ -710,41 +927,73 @@ static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy,
                                const struct cfg80211_bitrate_mask *mask)
 {
        struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
-       int index = 0, mode = 0, i;
-       struct mwifiex_adapter *adapter = priv->adapter;
+       u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
+       enum ieee80211_band band;
 
-       /* Currently only 2.4GHz is supported */
-       for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) {
-               /*
-                * Rates below 6 Mbps in the table are CCK rates; 802.11b
-                * and from 6 they are OFDM; 802.11G
-                */
-               if (mwifiex_rates[i].bitrate == 60) {
-                       index = 1 << i;
-                       break;
-               }
+       if (!priv->media_connected) {
+               dev_err(priv->adapter->dev,
+                       "Can not set Tx data rate in disconnected state\n");
+               return -EINVAL;
        }
 
-       if (mask->control[IEEE80211_BAND_2GHZ].legacy < index) {
-               mode = BAND_B;
-       } else {
-               mode = BAND_G;
-               if (mask->control[IEEE80211_BAND_2GHZ].legacy % index)
-                       mode |=  BAND_B;
-       }
+       band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
 
-       if (!((mode | adapter->fw_bands) & ~adapter->fw_bands)) {
-               adapter->config_bands = mode;
-               if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
-                       adapter->adhoc_start_band = mode;
-                       adapter->adhoc_11n_enabled = false;
-               }
-       }
-       adapter->sec_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
-       adapter->channel_type = NL80211_CHAN_NO_HT;
+       memset(bitmap_rates, 0, sizeof(bitmap_rates));
+
+       /* Fill HR/DSSS rates. */
+       if (band == IEEE80211_BAND_2GHZ)
+               bitmap_rates[0] = mask->control[band].legacy & 0x000f;
+
+       /* Fill OFDM rates */
+       if (band == IEEE80211_BAND_2GHZ)
+               bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4;
+       else
+               bitmap_rates[1] = mask->control[band].legacy;
 
-       wiphy_debug(wiphy, "info: device configured in 802.11%s%s mode\n",
-                   (mode & BAND_B) ? "b" : "", (mode & BAND_G) ? "g" : "");
+       /* Fill MCS rates */
+       bitmap_rates[2] = mask->control[band].mcs[0];
+       if (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2)
+               bitmap_rates[2] |= mask->control[band].mcs[1] << 8;
+
+       return mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
+                                    HostCmd_ACT_GEN_SET, 0, bitmap_rates);
+}
+
+/*
+ * CFG802.11 operation handler for connection quality monitoring.
+ *
+ * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI
+ * events to FW.
+ */
+static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy,
+                                               struct net_device *dev,
+                                               s32 rssi_thold, u32 rssi_hyst)
+{
+       struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
+       struct mwifiex_ds_misc_subsc_evt subsc_evt;
+
+       priv->cqm_rssi_thold = rssi_thold;
+       priv->cqm_rssi_hyst = rssi_hyst;
+
+       memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt));
+       subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH;
+
+       /* Subscribe/unsubscribe low and high rssi events */
+       if (rssi_thold && rssi_hyst) {
+               subsc_evt.action = HostCmd_ACT_BITWISE_SET;
+               subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold);
+               subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold);
+               subsc_evt.bcn_l_rssi_cfg.evt_freq = 1;
+               subsc_evt.bcn_h_rssi_cfg.evt_freq = 1;
+               return mwifiex_send_cmd_sync(priv,
+                                            HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
+                                            0, 0, &subsc_evt);
+       } else {
+               subsc_evt.action = HostCmd_ACT_BITWISE_CLR;
+               return mwifiex_send_cmd_sync(priv,
+                                            HostCmd_CMD_802_11_SUBSCRIBE_EVENT,
+                                            0, 0, &subsc_evt);
+       }
 
        return 0;
 }
@@ -962,8 +1211,9 @@ done:
                }
        }
 
-       if (mwifiex_bss_start(priv, bss, &req_ssid))
-               return -EFAULT;
+       ret = mwifiex_bss_start(priv, bss, &req_ssid);
+       if (ret)
+               return ret;
 
        if (mode == NL80211_IFTYPE_ADHOC) {
                /* Inform the BSS information to kernel, otherwise
@@ -1013,9 +1263,19 @@ done:
                        "info: association to bssid %pM failed\n",
                        priv->cfg_bssid);
                memset(priv->cfg_bssid, 0, ETH_ALEN);
+
+               if (ret > 0)
+                       cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
+                                               NULL, 0, NULL, 0, ret,
+                                               GFP_KERNEL);
+               else
+                       cfg80211_connect_result(priv->netdev, priv->cfg_bssid,
+                                               NULL, 0, NULL, 0,
+                                               WLAN_STATUS_UNSPECIFIED_FAILURE,
+                                               GFP_KERNEL);
        }
 
-       return ret;
+       return 0;
 }
 
 /*
@@ -1090,40 +1350,82 @@ mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
                      struct cfg80211_scan_request *request)
 {
        struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
-       int i;
+       int i, ret;
        struct ieee80211_channel *chan;
+       struct mwifiex_user_scan_cfg *user_scan_cfg;
 
        wiphy_dbg(wiphy, "info: received scan request on %s\n", dev->name);
 
-       priv->scan_request = request;
+       if ((request->flags & CFG80211_SCAN_FLAG_TX_ABORT) &&
+           atomic_read(&priv->wmm.tx_pkts_queued) >=
+           MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN) {
+               dev_dbg(priv->adapter->dev, "scan rejected due to traffic\n");
+               return -EBUSY;
+       }
 
-       priv->user_scan_cfg = kzalloc(sizeof(struct mwifiex_user_scan_cfg),
-                                     GFP_KERNEL);
-       if (!priv->user_scan_cfg) {
+       /* Block scan request if scan operation or scan cleanup when interface
+        * is disabled is in process
+        */
+       if (priv->scan_request || priv->scan_aborting) {
+               dev_err(priv->adapter->dev, "cmd: Scan already in process..\n");
+               return -EBUSY;
+       }
+
+       user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL);
+       if (!user_scan_cfg) {
                dev_err(priv->adapter->dev, "failed to alloc scan_req\n");
                return -ENOMEM;
        }
 
-       priv->user_scan_cfg->num_ssids = request->n_ssids;
-       priv->user_scan_cfg->ssid_list = request->ssids;
+       priv->scan_request = request;
+
+       user_scan_cfg->num_ssids = request->n_ssids;
+       user_scan_cfg->ssid_list = request->ssids;
+
+       if (request->ie && request->ie_len) {
+               for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
+                       if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
+                               continue;
+                       priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
+                       memcpy(&priv->vs_ie[i].ie, request->ie,
+                              request->ie_len);
+                       break;
+               }
+       }
 
        for (i = 0; i < request->n_channels; i++) {
                chan = request->channels[i];
-               priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
-               priv->user_scan_cfg->chan_list[i].radio_type = chan->band;
+               user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
+               user_scan_cfg->chan_list[i].radio_type = chan->band;
 
                if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
-                       priv->user_scan_cfg->chan_list[i].scan_type =
+                       user_scan_cfg->chan_list[i].scan_type =
                                                MWIFIEX_SCAN_TYPE_PASSIVE;
                else
-                       priv->user_scan_cfg->chan_list[i].scan_type =
+                       user_scan_cfg->chan_list[i].scan_type =
                                                MWIFIEX_SCAN_TYPE_ACTIVE;
 
-               priv->user_scan_cfg->chan_list[i].scan_time = 0;
+               user_scan_cfg->chan_list[i].scan_time = 0;
        }
-       if (mwifiex_set_user_scan_ioctl(priv, priv->user_scan_cfg))
-               return -EFAULT;
 
+       ret = mwifiex_scan_networks(priv, user_scan_cfg);
+       kfree(user_scan_cfg);
+       if (ret) {
+               dev_err(priv->adapter->dev, "scan failed: %d\n", ret);
+               priv->scan_aborting = false;
+               priv->scan_request = NULL;
+               return ret;
+       }
+
+       if (request->ie && request->ie_len) {
+               for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
+                       if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
+                               priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
+                               memset(&priv->vs_ie[i].ie, 0,
+                                      MWIFIEX_MAX_VSIE_LEN);
+                       }
+               }
+       }
        return 0;
 }
 
@@ -1214,11 +1516,11 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
        void *mdev_priv;
 
        if (!priv)
-               return NULL;
+               return ERR_PTR(-EFAULT);
 
        adapter = priv->adapter;
        if (!adapter)
-               return NULL;
+               return ERR_PTR(-EFAULT);
 
        switch (type) {
        case NL80211_IFTYPE_UNSPECIFIED:
@@ -1227,7 +1529,7 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
                if (priv->bss_mode) {
                        wiphy_err(wiphy, "cannot create multiple"
                                        " station/adhoc interfaces\n");
-                       return NULL;
+                       return ERR_PTR(-EINVAL);
                }
 
                if (type == NL80211_IFTYPE_UNSPECIFIED)
@@ -1244,14 +1546,15 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
                break;
        default:
                wiphy_err(wiphy, "type not supported\n");
-               return NULL;
+               return ERR_PTR(-EINVAL);
        }
 
-       dev = alloc_netdev_mq(sizeof(struct mwifiex_private *), name,
-                             ether_setup, 1);
+       dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name,
+                              ether_setup, IEEE80211_NUM_ACS, 1);
        if (!dev) {
                wiphy_err(wiphy, "no memory available for netdevice\n");
-               goto error;
+               priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
+               return ERR_PTR(-ENOMEM);
        }
 
        dev_net_set(dev, wiphy_net(wiphy));
@@ -1276,11 +1579,12 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
        /* Register network device */
        if (register_netdevice(dev)) {
                wiphy_err(wiphy, "cannot register virtual network device\n");
-               goto error;
+               free_netdev(dev);
+               priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
+               return ERR_PTR(-EFAULT);
        }
 
        sema_init(&priv->async_sem, 1);
-       priv->scan_pending_on_block = false;
 
        dev_dbg(adapter->dev, "info: %s: Marvell 802.11 Adapter\n", dev->name);
 
@@ -1288,12 +1592,6 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
        mwifiex_dev_debugfs_init(priv);
 #endif
        return dev;
-error:
-       if (dev && (dev->reg_state == NETREG_UNREGISTERED))
-               free_netdev(dev);
-       priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
-
-       return NULL;
 }
 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf);
 
@@ -1308,8 +1606,7 @@ int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev)
        mwifiex_dev_debugfs_remove(priv);
 #endif
 
-       if (!netif_queue_stopped(priv->netdev))
-               netif_stop_queue(priv->netdev);
+       mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter);
 
        if (netif_carrier_ok(priv->netdev))
                netif_carrier_off(priv->netdev);
@@ -1317,9 +1614,6 @@ int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev)
        if (dev->reg_state == NETREG_REGISTERED)
                unregister_netdevice(dev);
 
-       if (dev->reg_state == NETREG_UNREGISTERED)
-               free_netdev(dev);
-
        /* Clear the priv in adapter */
        priv->netdev = NULL;
 
@@ -1340,16 +1634,21 @@ static struct cfg80211_ops mwifiex_cfg80211_ops = {
        .connect = mwifiex_cfg80211_connect,
        .disconnect = mwifiex_cfg80211_disconnect,
        .get_station = mwifiex_cfg80211_get_station,
+       .dump_station = mwifiex_cfg80211_dump_station,
        .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params,
        .set_channel = mwifiex_cfg80211_set_channel,
        .join_ibss = mwifiex_cfg80211_join_ibss,
        .leave_ibss = mwifiex_cfg80211_leave_ibss,
        .add_key = mwifiex_cfg80211_add_key,
        .del_key = mwifiex_cfg80211_del_key,
+       .mgmt_tx = mwifiex_cfg80211_mgmt_tx,
+       .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register,
        .set_default_key = mwifiex_cfg80211_set_default_key,
        .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt,
        .set_tx_power = mwifiex_cfg80211_set_tx_power,
        .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask,
+       .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config,
+       .set_antenna = mwifiex_cfg80211_set_antenna,
 };
 
 /*
@@ -1365,6 +1664,7 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
        void *wdev_priv;
        struct wireless_dev *wdev;
        struct ieee80211_sta_ht_cap *ht_info;
+       u8 *country_code;
 
        wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
        if (!wdev) {
@@ -1381,6 +1681,8 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
        }
        wdev->iftype = NL80211_IFTYPE_STATION;
        wdev->wiphy->max_scan_ssids = 10;
+       wdev->wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
+       wdev->wiphy->mgmt_stypes = mwifiex_mgmt_stypes;
        wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
                                       BIT(NL80211_IFTYPE_ADHOC);
 
@@ -1403,8 +1705,23 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
        memcpy(wdev->wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
        wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
 
-       /* Reserve space for bss band information */
-       wdev->wiphy->bss_priv_size = sizeof(u8);
+       wdev->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
+
+       wdev->wiphy->probe_resp_offload =
+                                   NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
+                                   NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
+                                   NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
+
+       wiphy_apply_custom_regulatory(wdev->wiphy,
+                                     &mwifiex_world_regdom_custom);
+
+       wdev->wiphy->available_antennas_tx =
+               BIT(priv->adapter->number_of_antenna) - 1;
+       wdev->wiphy->available_antennas_rx =
+               BIT(priv->adapter->number_of_antenna) - 1;
+
+       /* Reserve space for mwifiex specific private data for BSS */
+       wdev->wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
 
        wdev->wiphy->reg_notifier = mwifiex_reg_notifier;
 
@@ -1427,6 +1744,11 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
                        "info: successfully registered wiphy device\n");
        }
 
+       country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
+       if (country_code)
+               dev_info(priv->adapter->dev,
+                        "ignoring F/W country code %2.2s\n", country_code);
+
        priv->wdev = wdev;
 
        return ret;