ath6kl: Fix key configuration to copy at most seq_len from seq
[deliverable/linux.git] / drivers / net / wireless / ath / ath6kl / wmi.c
index 2d80bdb2d912b2f7c054221884cbe445aefde37d..612326d960709fb7eaadb31db57d84c2a1392d5c 100644 (file)
 #include <linux/ip.h>
 #include "core.h"
 #include "debug.h"
+#include "testmode.h"
+#include "../regd.h"
+#include "../regd_common.h"
 
-static int ath6kl_wmi_sync_point(struct wmi *wmi);
+static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
 
 static const s32 wmi_rate_tbl[][2] = {
        /* {W/O SGI, with SGI} */
@@ -78,6 +81,26 @@ enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
        return wmi->ep_id;
 }
 
+struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
+{
+       struct ath6kl_vif *vif, *found = NULL;
+
+       if (WARN_ON(if_idx > (MAX_NUM_VIF - 1)))
+               return NULL;
+
+       /* FIXME: Locking */
+       spin_lock_bh(&ar->list_lock);
+       list_for_each_entry(vif, &ar->vif_list, list) {
+               if (vif->fw_vif_idx == if_idx) {
+                       found = vif;
+                       break;
+               }
+       }
+       spin_unlock_bh(&ar->list_lock);
+
+       return found;
+}
+
 /*  Performs DIX to 802.3 encapsulation for transmit packets.
  *  Assumes the entire DIX header is contigous and that there is
  *  enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
@@ -159,12 +182,12 @@ static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
 int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
                            u8 msg_type, bool more_data,
                            enum wmi_data_hdr_data_type data_type,
-                           u8 meta_ver, void *tx_meta_info)
+                           u8 meta_ver, void *tx_meta_info, u8 if_idx)
 {
        struct wmi_data_hdr *data_hdr;
        int ret;
 
-       if (WARN_ON(skb == NULL))
+       if (WARN_ON(skb == NULL || (if_idx > MAX_NUM_VIF - 1)))
                return -EINVAL;
 
        if (tx_meta_info) {
@@ -186,7 +209,7 @@ int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
                    WMI_DATA_HDR_MORE_MASK << WMI_DATA_HDR_MORE_SHIFT;
 
        data_hdr->info2 = cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
-       data_hdr->info3 = 0;
+       data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
 
        return 0;
 }
@@ -213,7 +236,8 @@ static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
                return ip_pri;
 }
 
-int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
+int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
+                                      struct sk_buff *skb,
                                       u32 layer2_priority, bool wmm_enabled,
                                       u8 *ac)
 {
@@ -259,7 +283,12 @@ int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
                        usr_pri = layer2_priority & 0x7;
        }
 
-       /* workaround for WMM S5 */
+       /*
+        * workaround for WMM S5
+        *
+        * FIXME: wmi->traffic_class is always 100 so this test doesn't
+        * make sense
+        */
        if ((wmi->traffic_class == WMM_AC_VI) &&
            ((usr_pri == 5) || (usr_pri == 4)))
                usr_pri = 1;
@@ -281,7 +310,7 @@ int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
                        cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
                /* Implicit streams are created with TSID 0xFF */
                cmd.tsid = WMI_IMPLICIT_PSTREAM;
-               ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
+               ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
        }
 
        *ac = traffic_class;
@@ -378,25 +407,6 @@ int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
        return 0;
 }
 
-static void ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(struct sk_buff *skb,
-                                                  u8 *datap)
-{
-       struct wmi_bss_info_hdr2 bih2;
-       struct wmi_bss_info_hdr *bih;
-
-       memcpy(&bih2, datap, sizeof(struct wmi_bss_info_hdr2));
-
-       skb_push(skb, 4);
-       bih = (struct wmi_bss_info_hdr *) skb->data;
-
-       bih->ch = bih2.ch;
-       bih->frame_type = bih2.frame_type;
-       bih->snr = bih2.snr;
-       bih->rssi = a_cpu_to_sle16(bih2.snr - 95);
-       bih->ie_mask = cpu_to_le32(le16_to_cpu(bih2.ie_mask));
-       memcpy(bih->bssid, bih2.bssid, ETH_ALEN);
-}
-
 static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
 {
        struct tx_complete_msg_v1 *msg_v1;
@@ -426,13 +436,14 @@ static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
 }
 
 static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
-                                             int len)
+                                             int len, struct ath6kl_vif *vif)
 {
        struct wmi_remain_on_chnl_event *ev;
        u32 freq;
        u32 dur;
        struct ieee80211_channel *chan;
        struct ath6kl *ar = wmi->parent_dev;
+       u32 id;
 
        if (len < sizeof(*ev))
                return -EINVAL;
@@ -442,26 +453,29 @@ static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
        dur = le32_to_cpu(ev->duration);
        ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
                   freq, dur);
-       chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
+       chan = ieee80211_get_channel(ar->wiphy, freq);
        if (!chan) {
                ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
                           "(freq=%u)\n", freq);
                return -EINVAL;
        }
-       cfg80211_ready_on_channel(ar->net_dev, 1, chan, NL80211_CHAN_NO_HT,
+       id = vif->last_roc_id;
+       cfg80211_ready_on_channel(vif->ndev, id, chan, NL80211_CHAN_NO_HT,
                                  dur, GFP_ATOMIC);
 
        return 0;
 }
 
 static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
-                                                    u8 *datap, int len)
+                                                    u8 *datap, int len,
+                                                    struct ath6kl_vif *vif)
 {
        struct wmi_cancel_remain_on_chnl_event *ev;
        u32 freq;
        u32 dur;
        struct ieee80211_channel *chan;
        struct ath6kl *ar = wmi->parent_dev;
+       u32 id;
 
        if (len < sizeof(*ev))
                return -EINVAL;
@@ -471,19 +485,26 @@ static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
        dur = le32_to_cpu(ev->duration);
        ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
                   "status=%u\n", freq, dur, ev->status);
-       chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
+       chan = ieee80211_get_channel(ar->wiphy, freq);
        if (!chan) {
                ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
                           "channel (freq=%u)\n", freq);
                return -EINVAL;
        }
-       cfg80211_remain_on_channel_expired(ar->net_dev, 1, chan,
+       if (vif->last_cancel_roc_id &&
+           vif->last_cancel_roc_id + 1 == vif->last_roc_id)
+               id = vif->last_cancel_roc_id; /* event for cancel command */
+       else
+               id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
+       vif->last_cancel_roc_id = 0;
+       cfg80211_remain_on_channel_expired(vif->ndev, id, chan,
                                           NL80211_CHAN_NO_HT, GFP_ATOMIC);
 
        return 0;
 }
 
-static int ath6kl_wmi_tx_status_event_rx(u8 *datap, int len)
+static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                        struct ath6kl_vif *vif)
 {
        struct wmi_tx_status_event *ev;
        u32 id;
@@ -495,22 +516,43 @@ static int ath6kl_wmi_tx_status_event_rx(u8 *datap, int len)
        id = le32_to_cpu(ev->id);
        ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
                   id, ev->ack_status);
+       if (wmi->last_mgmt_tx_frame) {
+               cfg80211_mgmt_tx_status(vif->ndev, id,
+                                       wmi->last_mgmt_tx_frame,
+                                       wmi->last_mgmt_tx_frame_len,
+                                       !!ev->ack_status, GFP_ATOMIC);
+               kfree(wmi->last_mgmt_tx_frame);
+               wmi->last_mgmt_tx_frame = NULL;
+               wmi->last_mgmt_tx_frame_len = 0;
+       }
 
        return 0;
 }
 
-static int ath6kl_wmi_rx_probe_req_event_rx(u8 *datap, int len)
+static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                           struct ath6kl_vif *vif)
 {
        struct wmi_p2p_rx_probe_req_event *ev;
+       u32 freq;
        u16 dlen;
 
        if (len < sizeof(*ev))
                return -EINVAL;
 
        ev = (struct wmi_p2p_rx_probe_req_event *) datap;
+       freq = le32_to_cpu(ev->freq);
        dlen = le16_to_cpu(ev->len);
-       ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u\n",
-                  dlen);
+       if (datap + len < ev->data + dlen) {
+               ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
+                          "len=%d dlen=%u\n", len, dlen);
+               return -EINVAL;
+       }
+       ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
+                  "probe_req_report=%d\n",
+                  dlen, freq, vif->probe_req_report);
+
+       if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
+               cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
 
        return 0;
 }
@@ -530,17 +572,26 @@ static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
        return 0;
 }
 
-static int ath6kl_wmi_rx_action_event_rx(u8 *datap, int len)
+static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                        struct ath6kl_vif *vif)
 {
        struct wmi_rx_action_event *ev;
+       u32 freq;
        u16 dlen;
 
        if (len < sizeof(*ev))
                return -EINVAL;
 
        ev = (struct wmi_rx_action_event *) datap;
+       freq = le32_to_cpu(ev->freq);
        dlen = le16_to_cpu(ev->len);
-       ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u\n", dlen);
+       if (datap + len < ev->data + dlen) {
+               ath6kl_err("invalid wmi_rx_action_event: "
+                          "len=%d dlen=%u\n", len, dlen);
+               return -EINVAL;
+       }
+       ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
+       cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
 
        return 0;
 }
@@ -605,7 +656,8 @@ static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
 }
 
 /* Send a "simple" wmi command -- one with no arguments */
-static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
+static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
+                                enum wmi_cmd_id cmd_id)
 {
        struct sk_buff *skb;
        int ret;
@@ -614,7 +666,7 @@ static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
        if (!skb)
                return -ENOMEM;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, cmd_id, NO_SYNC_WMIFLAG);
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
 
        return ret;
 }
@@ -626,7 +678,6 @@ static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
        if (len < sizeof(struct wmi_ready_event_2))
                return -EINVAL;
 
-       wmi->ready = true;
        ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
                           le32_to_cpu(ev->sw_version),
                           le32_to_cpu(ev->abi_version));
@@ -634,7 +685,78 @@ static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
        return 0;
 }
 
-static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
+/*
+ * Mechanism to modify the roaming behavior in the firmware. The lower rssi
+ * at which the station has to roam can be passed with
+ * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
+ * in dBm.
+ */
+int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
+{
+       struct sk_buff *skb;
+       struct roam_ctrl_cmd *cmd;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct roam_ctrl_cmd *) skb->data;
+
+       cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
+       cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
+                                                      DEF_SCAN_FOR_ROAM_INTVL);
+       cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
+       cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
+       cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
+
+       ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
+                           NO_SYNC_WMIFLAG);
+
+       return 0;
+}
+
+int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
+{
+       struct sk_buff *skb;
+       struct roam_ctrl_cmd *cmd;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct roam_ctrl_cmd *) skb->data;
+       memset(cmd, 0, sizeof(*cmd));
+
+       memcpy(cmd->info.bssid, bssid, ETH_ALEN);
+       cmd->roam_ctrl = WMI_FORCE_ROAM;
+
+       ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
+       return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
+                                  NO_SYNC_WMIFLAG);
+}
+
+int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
+{
+       struct sk_buff *skb;
+       struct roam_ctrl_cmd *cmd;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct roam_ctrl_cmd *) skb->data;
+       memset(cmd, 0, sizeof(*cmd));
+
+       cmd->info.roam_mode = mode;
+       cmd->roam_ctrl = WMI_SET_ROAM_MODE;
+
+       ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
+       return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
+                                  NO_SYNC_WMIFLAG);
+}
+
+static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                      struct ath6kl_vif *vif)
 {
        struct wmi_connect_event *ev;
        u8 *pie, *peie;
@@ -644,8 +766,44 @@ static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
 
        ev = (struct wmi_connect_event *) datap;
 
-       ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM\n",
-                  __func__, ev->ch, ev->bssid);
+       if (vif->nw_type == AP_NETWORK) {
+               /* AP mode start/STA connected event */
+               struct net_device *dev = vif->ndev;
+               if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
+                       ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
+                                  "(AP started)\n",
+                                  __func__, le16_to_cpu(ev->u.ap_bss.ch),
+                                  ev->u.ap_bss.bssid);
+                       ath6kl_connect_ap_mode_bss(
+                               vif, le16_to_cpu(ev->u.ap_bss.ch));
+               } else {
+                       ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
+                                  "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
+                                  "(STA connected)\n",
+                                  __func__, ev->u.ap_sta.aid,
+                                  ev->u.ap_sta.mac_addr,
+                                  ev->u.ap_sta.auth,
+                                  ev->u.ap_sta.keymgmt,
+                                  le16_to_cpu(ev->u.ap_sta.cipher),
+                                  ev->u.ap_sta.apsd_info);
+                       ath6kl_connect_ap_mode_sta(
+                               vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
+                               ev->u.ap_sta.keymgmt,
+                               le16_to_cpu(ev->u.ap_sta.cipher),
+                               ev->u.ap_sta.auth, ev->assoc_req_len,
+                               ev->assoc_info + ev->beacon_ie_len);
+               }
+               return 0;
+       }
+
+       /* STA/IBSS mode connection event */
+
+       ath6kl_dbg(ATH6KL_DBG_WMI,
+                  "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
+                  le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
+                  le16_to_cpu(ev->u.sta.listen_intvl),
+                  le16_to_cpu(ev->u.sta.beacon_intvl),
+                  le32_to_cpu(ev->u.sta.nw_type));
 
        /* Start of assoc rsp IEs */
        pie = ev->assoc_info + ev->beacon_ie_len +
@@ -674,17 +832,94 @@ static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
                pie += pie[1] + 2;
        }
 
-       ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->ch), ev->bssid,
-                            le16_to_cpu(ev->listen_intvl),
-                            le16_to_cpu(ev->beacon_intvl),
-                            le32_to_cpu(ev->nw_type),
+       ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
+                            ev->u.sta.bssid,
+                            le16_to_cpu(ev->u.sta.listen_intvl),
+                            le16_to_cpu(ev->u.sta.beacon_intvl),
+                            le32_to_cpu(ev->u.sta.nw_type),
                             ev->beacon_ie_len, ev->assoc_req_len,
                             ev->assoc_resp_len, ev->assoc_info);
 
        return 0;
 }
 
-static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
+static struct country_code_to_enum_rd *
+ath6kl_regd_find_country(u16 countryCode)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
+               if (allCountries[i].countryCode == countryCode)
+                       return &allCountries[i];
+       }
+
+       return NULL;
+}
+
+static struct reg_dmn_pair_mapping *
+ath6kl_get_regpair(u16 regdmn)
+{
+       int i;
+
+       if (regdmn == NO_ENUMRD)
+               return NULL;
+
+       for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
+               if (regDomainPairs[i].regDmnEnum == regdmn)
+                       return &regDomainPairs[i];
+       }
+
+       return NULL;
+}
+
+static struct country_code_to_enum_rd *
+ath6kl_regd_find_country_by_rd(u16 regdmn)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
+               if (allCountries[i].regDmnEnum == regdmn)
+                       return &allCountries[i];
+       }
+
+       return NULL;
+}
+
+static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
+{
+
+       struct ath6kl_wmi_regdomain *ev;
+       struct country_code_to_enum_rd *country = NULL;
+       struct reg_dmn_pair_mapping *regpair = NULL;
+       char alpha2[2];
+       u32 reg_code;
+
+       ev = (struct ath6kl_wmi_regdomain *) datap;
+       reg_code = le32_to_cpu(ev->reg_code);
+
+       if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
+               country = ath6kl_regd_find_country((u16) reg_code);
+       else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
+
+               regpair = ath6kl_get_regpair((u16) reg_code);
+               country = ath6kl_regd_find_country_by_rd((u16) reg_code);
+               ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
+                               regpair->regDmnEnum);
+       }
+
+       if (country) {
+               alpha2[0] = country->isoName[0];
+               alpha2[1] = country->isoName[1];
+
+               regulatory_hint(wmi->parent_dev->wiphy, alpha2);
+
+               ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
+                               alpha2[0], alpha2[1]);
+       }
+}
+
+static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                         struct ath6kl_vif *vif)
 {
        struct wmi_disconnect_event *ev;
        wmi->traffic_class = 100;
@@ -694,11 +929,14 @@ static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
 
        ev = (struct wmi_disconnect_event *) datap;
 
+       ath6kl_dbg(ATH6KL_DBG_WMI,
+                  "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
+                  le16_to_cpu(ev->proto_reason_status), ev->bssid,
+                  ev->disconn_reason, ev->assoc_resp_len);
+
        wmi->is_wmm_enabled = false;
-       wmi->pair_crypto_type = NONE_CRYPT;
-       wmi->grp_crypto_type = NONE_CRYPT;
 
-       ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
+       ath6kl_disconnect_event(vif, ev->disconn_reason,
                                ev->bssid, ev->assoc_resp_len, ev->assoc_info,
                                le16_to_cpu(ev->proto_reason_status));
 
@@ -724,7 +962,8 @@ static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
        return 0;
 }
 
-static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                          struct ath6kl_vif *vif)
 {
        struct wmi_tkip_micerr_event *ev;
 
@@ -733,320 +972,99 @@ static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
 
        ev = (struct wmi_tkip_micerr_event *) datap;
 
-       ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
+       ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
 
        return 0;
 }
 
-static int ath6kl_wlan_parse_beacon(u8 *buf, int frame_len,
-                                   struct ath6kl_common_ie *cie)
+static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                      struct ath6kl_vif *vif)
 {
-       u8 *frm, *efrm;
-       u8 elemid_ssid = false;
-
-       frm = buf;
-       efrm = (u8 *) (frm + frame_len);
+       struct wmi_bss_info_hdr2 *bih;
+       u8 *buf;
+       struct ieee80211_channel *channel;
+       struct ath6kl *ar = wmi->parent_dev;
+       struct ieee80211_mgmt *mgmt;
+       struct cfg80211_bss *bss;
 
-       /*
-        * beacon/probe response frame format
-        *  [8] time stamp
-        *  [2] beacon interval
-        *  [2] capability information
-        *  [tlv] ssid
-        *  [tlv] supported rates
-        *  [tlv] country information
-        *  [tlv] parameter set (FH/DS)
-        *  [tlv] erp information
-        *  [tlv] extended supported rates
-        *  [tlv] WMM
-        *  [tlv] WPA or RSN
-        *  [tlv] Atheros Advanced Capabilities
-        */
-       if ((efrm - frm) < 12)
+       if (len <= sizeof(struct wmi_bss_info_hdr2))
                return -EINVAL;
 
-       memset(cie, 0, sizeof(*cie));
+       bih = (struct wmi_bss_info_hdr2 *) datap;
+       buf = datap + sizeof(struct wmi_bss_info_hdr2);
+       len -= sizeof(struct wmi_bss_info_hdr2);
 
-       cie->ie_tstamp = frm;
-       frm += 8;
-       cie->ie_beaconInt = *(u16 *) frm;
-       frm += 2;
-       cie->ie_capInfo = *(u16 *) frm;
-       frm += 2;
-       cie->ie_chan = 0;
-
-       while (frm < efrm) {
-               switch (*frm) {
-               case WLAN_EID_SSID:
-                       if (!elemid_ssid) {
-                               cie->ie_ssid = frm;
-                               elemid_ssid = true;
-                       }
-                       break;
-               case WLAN_EID_SUPP_RATES:
-                       cie->ie_rates = frm;
-                       break;
-               case WLAN_EID_COUNTRY:
-                       cie->ie_country = frm;
-                       break;
-               case WLAN_EID_FH_PARAMS:
-                       break;
-               case WLAN_EID_DS_PARAMS:
-                       cie->ie_chan = frm[2];
-                       break;
-               case WLAN_EID_TIM:
-                       cie->ie_tim = frm;
-                       break;
-               case WLAN_EID_IBSS_PARAMS:
-                       break;
-               case WLAN_EID_EXT_SUPP_RATES:
-                       cie->ie_xrates = frm;
-                       break;
-               case WLAN_EID_ERP_INFO:
-                       if (frm[1] != 1)
-                               return -EINVAL;
-
-                       cie->ie_erp = frm[2];
-                       break;
-               case WLAN_EID_RSN:
-                       cie->ie_rsn = frm;
-                       break;
-               case WLAN_EID_HT_CAPABILITY:
-                       cie->ie_htcap = frm;
-                       break;
-               case WLAN_EID_HT_INFORMATION:
-                       cie->ie_htop = frm;
-                       break;
-               case WLAN_EID_VENDOR_SPECIFIC:
-                       if (frm[1] > 3 && frm[2] == 0x00 && frm[3] == 0x50 &&
-                           frm[4] == 0xf2) {
-                               /* OUT Type (00:50:F2) */
-
-                               if (frm[5] == WPA_OUI_TYPE) {
-                                       /* WPA OUT */
-                                       cie->ie_wpa = frm;
-                               } else if (frm[5] == WMM_OUI_TYPE) {
-                                       /* WMM OUT */
-                                       cie->ie_wmm = frm;
-                               } else if (frm[5] == WSC_OUT_TYPE) {
-                                       /* WSC OUT */
-                                       cie->ie_wsc = frm;
-                               }
-
-                       } else if (frm[1] > 3 && frm[2] == 0x00
-                                  && frm[3] == 0x03 && frm[4] == 0x7f
-                                  && frm[5] == ATH_OUI_TYPE) {
-                               /* Atheros OUI (00:03:7f) */
-                               cie->ie_ath = frm;
-                       }
-                       break;
-               default:
-                       break;
-               }
-               frm += frm[1] + 2;
+       ath6kl_dbg(ATH6KL_DBG_WMI,
+                  "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
+                  "frame_type=%d\n",
+                  bih->ch, bih->snr, bih->snr - 95, bih->bssid,
+                  bih->frame_type);
+
+       if (bih->frame_type != BEACON_FTYPE &&
+           bih->frame_type != PROBERESP_FTYPE)
+               return 0; /* Only update BSS table for now */
+
+       if (bih->frame_type == BEACON_FTYPE &&
+           test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
+               clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
+               ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
+                                        NONE_BSS_FILTER, 0);
        }
 
-       if ((cie->ie_rates == NULL)
-           || (cie->ie_rates[1] > ATH6KL_RATE_MAXSIZE))
-               return -EINVAL;
-
-       if ((cie->ie_ssid == NULL)
-           || (cie->ie_ssid[1] > IEEE80211_MAX_SSID_LEN))
+       channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
+       if (channel == NULL)
                return -EINVAL;
 
-       return 0;
-}
-
-static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
-{
-       struct bss *bss = NULL;
-       struct wmi_bss_info_hdr *bih;
-       u8 cached_ssid_len = 0;
-       u8 cached_ssid[IEEE80211_MAX_SSID_LEN] = { 0 };
-       u8 beacon_ssid_len = 0;
-       u8 *buf, *ie_ssid;
-       u8 *ni_buf;
-       int buf_len;
-
-       int ret;
-
-       if (len <= sizeof(struct wmi_bss_info_hdr))
+       if (len < 8 + 2 + 2)
                return -EINVAL;
 
-       bih = (struct wmi_bss_info_hdr *) datap;
-       bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
-
-       if (a_sle16_to_cpu(bih->rssi) > 0) {
-               if (bss == NULL)
-                       return 0;
-               else
-                       bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
-       }
-
-       buf = datap + sizeof(struct wmi_bss_info_hdr);
-       len -= sizeof(struct wmi_bss_info_hdr);
-
-       ath6kl_dbg(ATH6KL_DBG_WMI,
-                  "bss info evt - ch %u, rssi %02x, bssid \"%pM\"\n",
-                  bih->ch, a_sle16_to_cpu(bih->rssi), bih->bssid);
-
-       if (bss != NULL) {
-               /*
-                * Free up the node. We are about to allocate a new node.
-                * In case of hidden AP, beacon will not have ssid,
-                * but a directed probe response will have it,
-                * so cache the probe-resp-ssid if already present.
-                */
-               if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE)) {
-                       ie_ssid = bss->ni_cie.ie_ssid;
-                       if (ie_ssid && (ie_ssid[1] <= IEEE80211_MAX_SSID_LEN) &&
-                           (ie_ssid[2] != 0)) {
-                               cached_ssid_len = ie_ssid[1];
-                               memcpy(cached_ssid, ie_ssid + 2,
-                                      cached_ssid_len);
-                       }
+       if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &vif->flags)
+           && memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
+               const u8 *tim;
+               tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
+                                      len - 8 - 2 - 2);
+               if (tim && tim[1] >= 2) {
+                       vif->assoc_bss_dtim_period = tim[3];
+                       set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
                }
-
-               /*
-                * Use the current average rssi of associated AP base on
-                * assumption
-                *   1. Most os with GUI will update RSSI by
-                *      ath6kl_wmi_get_stats_cmd() periodically.
-                *   2. ath6kl_wmi_get_stats_cmd(..) will be called when calling
-                *      ath6kl_wmi_startscan_cmd(...)
-                * The average value of RSSI give end-user better feeling for
-                * instance value of scan result. It also sync up RSSI info
-                * in GUI between scan result and RSSI signal icon.
-                */
-               if (memcmp(wmi->parent_dev->bssid, bih->bssid, ETH_ALEN) == 0) {
-                       bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
-                       bih->snr = bss->ni_snr;
-               }
-
-               wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
-       }
-
-       /*
-        * beacon/probe response frame format
-        *  [8] time stamp
-        *  [2] beacon interval
-        *  [2] capability information
-        *  [tlv] ssid
-        */
-       beacon_ssid_len = buf[SSID_IE_LEN_INDEX];
-
-       /*
-        * If ssid is cached for this hidden AP, then change
-        * buffer len accordingly.
-        */
-       if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
-           (cached_ssid_len != 0) &&
-           (beacon_ssid_len == 0 || (cached_ssid_len > beacon_ssid_len &&
-                                     buf[SSID_IE_LEN_INDEX + 1] == 0))) {
-
-               len += (cached_ssid_len - beacon_ssid_len);
        }
 
-       bss = wlan_node_alloc(len);
-       if (!bss)
-               return -ENOMEM;
-
-       bss->ni_snr = bih->snr;
-       bss->ni_rssi = a_sle16_to_cpu(bih->rssi);
-
-       if (WARN_ON(!bss->ni_buf))
-               return -EINVAL;
-
        /*
-        * In case of hidden AP, beacon will not have ssid,
-        * but a directed probe response will have it,
-        * so place the cached-ssid(probe-resp) in the bss info.
+        * In theory, use of cfg80211_inform_bss() would be more natural here
+        * since we do not have the full frame. However, at least for now,
+        * cfg80211 can only distinguish Beacon and Probe Response frames from
+        * each other when using cfg80211_inform_bss_frame(), so let's build a
+        * fake IEEE 802.11 header to be able to take benefit of this.
         */
-       if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
-           (cached_ssid_len != 0) &&
-           (beacon_ssid_len == 0 || (beacon_ssid_len &&
-                                     buf[SSID_IE_LEN_INDEX + 1] == 0))) {
-               ni_buf = bss->ni_buf;
-               buf_len = len;
-
-               /*
-                * Copy the first 14 bytes:
-                * time-stamp(8), beacon-interval(2),
-                * cap-info(2), ssid-id(1), ssid-len(1).
-                */
-               memcpy(ni_buf, buf, SSID_IE_LEN_INDEX + 1);
-
-               ni_buf[SSID_IE_LEN_INDEX] = cached_ssid_len;
-               ni_buf += (SSID_IE_LEN_INDEX + 1);
-
-               buf += (SSID_IE_LEN_INDEX + 1);
-               buf_len -= (SSID_IE_LEN_INDEX + 1);
-
-               memcpy(ni_buf, cached_ssid, cached_ssid_len);
-               ni_buf += cached_ssid_len;
-
-               buf += beacon_ssid_len;
-               buf_len -= beacon_ssid_len;
-
-               if (cached_ssid_len > beacon_ssid_len)
-                       buf_len -= (cached_ssid_len - beacon_ssid_len);
-
-               memcpy(ni_buf, buf, buf_len);
-       } else
-               memcpy(bss->ni_buf, buf, len);
-
-       bss->ni_framelen = len;
-
-       ret = ath6kl_wlan_parse_beacon(bss->ni_buf, len, &bss->ni_cie);
-       if (ret) {
-               wlan_node_free(bss);
+       mgmt = kmalloc(24 + len, GFP_ATOMIC);
+       if (mgmt == NULL)
                return -EINVAL;
-       }
 
-       /*
-        * Update the frequency in ie_chan, overwriting of channel number
-        * which is done in ath6kl_wlan_parse_beacon
-        */
-       bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
-       wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
-
-       return 0;
-}
-
-static int ath6kl_wmi_opt_frame_event_rx(struct wmi *wmi, u8 *datap, int len)
-{
-       struct bss *bss;
-       struct wmi_opt_rx_info_hdr *bih;
-       u8 *buf;
-
-       if (len <= sizeof(struct wmi_opt_rx_info_hdr))
-               return -EINVAL;
-
-       bih = (struct wmi_opt_rx_info_hdr *) datap;
-       buf = datap + sizeof(struct wmi_opt_rx_info_hdr);
-       len -= sizeof(struct wmi_opt_rx_info_hdr);
-
-       ath6kl_dbg(ATH6KL_DBG_WMI, "opt frame event %2.2x:%2.2x\n",
-                  bih->bssid[4], bih->bssid[5]);
+       if (bih->frame_type == BEACON_FTYPE) {
+               mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
+                                                 IEEE80211_STYPE_BEACON);
+               memset(mgmt->da, 0xff, ETH_ALEN);
+       } else {
+               struct net_device *dev = vif->ndev;
 
-       bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
-       if (bss != NULL) {
-               /* Free up the node. We are about to allocate a new node. */
-               wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
+               mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
+                                                 IEEE80211_STYPE_PROBE_RESP);
+               memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
        }
-
-       bss = wlan_node_alloc(len);
-       if (!bss)
+       mgmt->duration = cpu_to_le16(0);
+       memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
+       memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
+       mgmt->seq_ctrl = cpu_to_le16(0);
+
+       memcpy(&mgmt->u.beacon, buf, len);
+
+       bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
+                                       24 + len, (bih->snr - 95) * 100,
+                                       GFP_ATOMIC);
+       kfree(mgmt);
+       if (bss == NULL)
                return -ENOMEM;
-
-       bss->ni_snr = bih->snr;
-       bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
-
-       if (WARN_ON(!bss->ni_buf))
-               return -EINVAL;
-
-       memcpy(bss->ni_buf, buf, len);
-       wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
+       cfg80211_put_bss(bss);
 
        return 0;
 }
@@ -1105,6 +1123,13 @@ static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
        return 0;
 }
 
+static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
+{
+       ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
+
+       return 0;
+}
+
 static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
 {
        if (len < sizeof(struct wmi_fix_rates_reply))
@@ -1148,21 +1173,48 @@ static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
        return 0;
 }
 
-static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
+                                      struct ath6kl_vif *vif)
 {
        struct wmi_scan_complete_event *ev;
 
        ev = (struct wmi_scan_complete_event *) datap;
 
-       if (a_sle32_to_cpu(ev->status) == 0)
-               wlan_refresh_inactive_nodes(wmi->parent_dev);
-
-       ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
+       ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
        wmi->is_probe_ssid = false;
 
        return 0;
 }
 
+static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
+                                              int len, struct ath6kl_vif *vif)
+{
+       struct wmi_neighbor_report_event *ev;
+       u8 i;
+
+       if (len < sizeof(*ev))
+               return -EINVAL;
+       ev = (struct wmi_neighbor_report_event *) datap;
+       if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
+           > len) {
+               ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
+                          "(num=%d len=%d)\n", ev->num_neighbors, len);
+               return -EINVAL;
+       }
+       for (i = 0; i < ev->num_neighbors; i++) {
+               ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
+                          i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
+                          ev->neighbor[i].bss_flags);
+               cfg80211_pmksa_candidate_notify(vif->ndev, i,
+                                               ev->neighbor[i].bssid,
+                                               !!(ev->neighbor[i].bss_flags &
+                                                  WMI_PREAUTH_CAPABLE_BSS),
+                                               GFP_ATOMIC);
+       }
+
+       return 0;
+}
+
 /*
  * Target is reporting a programming error.  This is for
  * developer aid only.  Target only checks a few common violations
@@ -1194,9 +1246,10 @@ static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
        return 0;
 }
 
-static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                    struct ath6kl_vif *vif)
 {
-       ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
+       ath6kl_tgt_stats_event(vif, datap, len);
 
        return 0;
 }
@@ -1250,7 +1303,7 @@ static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
        cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
        memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
 
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
@@ -1350,7 +1403,8 @@ static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
        return 0;
 }
 
-static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                  struct ath6kl_vif *vif)
 {
        struct wmi_cac_event *reply;
        struct ieee80211_tspec_ie *ts;
@@ -1371,7 +1425,8 @@ static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
                tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
                        IEEE80211_WMM_IE_TSPEC_TID_MASK;
 
-               ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
+               ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
+                                             reply->ac, tsid);
        } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
                /*
                 * Following assumes that there is only one outstanding
@@ -1386,7 +1441,8 @@ static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
                                break;
                }
                if (index < (sizeof(active_tsids) * 8))
-                       ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
+                       ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
+                                                     reply->ac, index);
        }
 
        /*
@@ -1431,7 +1487,7 @@ static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
        cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
        memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
 
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
@@ -1556,18 +1612,22 @@ static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
        return 0;
 }
 
-int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
+int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
                        enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
 {
        struct wmi_cmd_hdr *cmd_hdr;
        enum htc_endpoint_id ep_id = wmi->ep_id;
        int ret;
+       u16 info1;
 
-       ath6kl_dbg(ATH6KL_DBG_WMI, "%s: cmd_id=%d\n", __func__, cmd_id);
-
-       if (WARN_ON(skb == NULL))
+       if (WARN_ON(skb == NULL || (if_idx > (MAX_NUM_VIF - 1))))
                return -EINVAL;
 
+       ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
+                  cmd_id, skb->len, sync_flag);
+       ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
+                       skb->data, skb->len);
+
        if (sync_flag >= END_WMIFLAG) {
                dev_kfree_skb(skb);
                return -EINVAL;
@@ -1579,19 +1639,20 @@ int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
                 * Make sure all data currently queued is transmitted before
                 * the cmd execution.  Establish a new sync point.
                 */
-               ath6kl_wmi_sync_point(wmi);
+               ath6kl_wmi_sync_point(wmi, if_idx);
        }
 
        skb_push(skb, sizeof(struct wmi_cmd_hdr));
 
        cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
        cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
-       cmd_hdr->info1 = 0;     /* added for virtual interface */
+       info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
+       cmd_hdr->info1 = cpu_to_le16(info1);
 
        /* Only for OPT_TX_CMD, use BE endpoint. */
        if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
                ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
-                                             false, false, 0, NULL);
+                                             false, false, 0, NULL, if_idx);
                if (ret) {
                        dev_kfree_skb(skb);
                        return ret;
@@ -1607,13 +1668,14 @@ int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
                 * Make sure all new data queued waits for the command to
                 * execute. Establish a new sync point.
                 */
-               ath6kl_wmi_sync_point(wmi);
+               ath6kl_wmi_sync_point(wmi, if_idx);
        }
 
        return 0;
 }
 
-int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
+int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
+                          enum network_type nw_type,
                           enum dot11_auth_mode dot11_auth_mode,
                           enum auth_mode auth_mode,
                           enum crypto_type pairwise_crypto,
@@ -1626,6 +1688,13 @@ int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
        struct wmi_connect_cmd *cc;
        int ret;
 
+       ath6kl_dbg(ATH6KL_DBG_WMI,
+                  "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
+                  "type %d dot11_auth %d auth %d pairwise %d group %d\n",
+                  bssid, channel, ctrl_flags, ssid_len, nw_type,
+                  dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
+       ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
+
        wmi->traffic_class = 100;
 
        if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
@@ -1657,20 +1726,22 @@ int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
        if (bssid != NULL)
                memcpy(cc->bssid, bssid, ETH_ALEN);
 
-       wmi->pair_crypto_type = pairwise_crypto;
-       wmi->grp_crypto_type = group_crypto;
-
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
+                                 NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
-int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
+int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
+                            u16 channel)
 {
        struct sk_buff *skb;
        struct wmi_reconnect_cmd *cc;
        int ret;
 
+       ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
+                  bssid, channel);
+
        wmi->traffic_class = 100;
 
        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
@@ -1683,25 +1754,28 @@ int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
        if (bssid != NULL)
                memcpy(cc->bssid, bssid, ETH_ALEN);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
-int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
+int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
 {
        int ret;
 
+       ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
+
        wmi->traffic_class = 100;
 
        /* Disconnect command does not need to do a SYNC before. */
-       ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
+       ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
 
        return ret;
 }
 
-int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
+int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
+                            enum wmi_scan_type scan_type,
                             u32 force_fgscan, u32 is_legacy,
                             u32 home_dwell_time, u32 force_scan_interval,
                             s8 num_chan, u16 *ch_list)
@@ -1709,7 +1783,7 @@ int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
        struct sk_buff *skb;
        struct wmi_start_scan_cmd *sc;
        s8 size;
-       int ret;
+       int i, ret;
 
        size = sizeof(struct wmi_start_scan_cmd);
 
@@ -1734,16 +1808,17 @@ int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
        sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
        sc->num_ch = num_chan;
 
-       if (num_chan)
-               memcpy(sc->ch_list, ch_list, num_chan * sizeof(u16));
+       for (i = 0; i < num_chan; i++)
+               sc->ch_list[i] = cpu_to_le16(ch_list[i]);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
-int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
+int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
+                             u16 fg_start_sec,
                              u16 fg_end_sec, u16 bg_sec,
                              u16 minact_chdw_msec, u16 maxact_chdw_msec,
                              u16 pas_chdw_msec, u8 short_scan_ratio,
@@ -1770,12 +1845,12 @@ int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
        sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
        sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
+int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
 {
        struct sk_buff *skb;
        struct wmi_bss_filter_cmd *cmd;
@@ -1792,12 +1867,12 @@ int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
        cmd->bss_filter = filter;
        cmd->ie_mask = cpu_to_le32(ie_mask);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
+int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
                              u8 ssid_len, u8 *ssid)
 {
        struct sk_buff *skb;
@@ -1829,12 +1904,13 @@ int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
        cmd->ssid_len = ssid_len;
        memcpy(cmd->ssid, ssid, ssid_len);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
+int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
+                                 u16 listen_interval,
                                  u16 listen_beacons)
 {
        struct sk_buff *skb;
@@ -1849,12 +1925,12 @@ int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
        cmd->listen_intvl = cpu_to_le16(listen_interval);
        cmd->num_beacons = cpu_to_le16(listen_beacons);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
+int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
 {
        struct sk_buff *skb;
        struct wmi_power_mode_cmd *cmd;
@@ -1868,12 +1944,12 @@ int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
        cmd->pwr_mode = pwr_mode;
        wmi->pwr_mode = pwr_mode;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
+int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
                            u16 ps_poll_num, u16 dtim_policy,
                            u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
                            u16 ps_fail_event_policy)
@@ -1894,12 +1970,12 @@ int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
        pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
        pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
+int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
 {
        struct sk_buff *skb;
        struct wmi_disc_timeout_cmd *cmd;
@@ -1912,15 +1988,20 @@ int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
        cmd = (struct wmi_disc_timeout_cmd *) skb->data;
        cmd->discon_timeout = timeout;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
                                  NO_SYNC_WMIFLAG);
+
+       if (ret == 0)
+               ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
+
        return ret;
 }
 
-int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
+int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
                          enum crypto_type key_type,
                          u8 key_usage, u8 key_len,
-                         u8 *key_rsc, u8 *key_material,
+                         u8 *key_rsc, unsigned int key_rsc_len,
+                         u8 *key_material,
                          u8 key_op_ctrl, u8 *mac_addr,
                          enum wmi_sync_flag sync_flag)
 {
@@ -1933,7 +2014,7 @@ int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
                   key_index, key_type, key_usage, key_len, key_op_ctrl);
 
        if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
-           (key_material == NULL))
+           (key_material == NULL) || key_rsc_len > 8)
                return -EINVAL;
 
        if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
@@ -1951,20 +2032,20 @@ int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
        memcpy(cmd->key, key_material, key_len);
 
        if (key_rsc != NULL)
-               memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
+               memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
 
        cmd->key_op_ctrl = key_op_ctrl;
 
        if (mac_addr)
                memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
                                  sync_flag);
 
        return ret;
 }
 
-int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
+int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
 {
        struct sk_buff *skb;
        struct wmi_add_krk_cmd *cmd;
@@ -1977,12 +2058,13 @@ int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
        cmd = (struct wmi_add_krk_cmd *) skb->data;
        memcpy(cmd->krk, krk, WMI_KRK_LEN);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
+                                 NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
-int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
+int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
 {
        struct sk_buff *skb;
        struct wmi_delete_cipher_key_cmd *cmd;
@@ -1998,13 +2080,13 @@ int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
        cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
        cmd->key_index = key_index;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
-int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
+int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
                            const u8 *pmkid, bool set)
 {
        struct sk_buff *skb;
@@ -2031,14 +2113,14 @@ int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
                cmd->enable = PMKID_DISABLE;
        }
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
 static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
-                             enum htc_endpoint_id ep_id)
+                             enum htc_endpoint_id ep_id, u8 if_idx)
 {
        struct wmi_data_hdr *data_hdr;
        int ret;
@@ -2050,14 +2132,14 @@ static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
 
        data_hdr = (struct wmi_data_hdr *) skb->data;
        data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
-       data_hdr->info3 = 0;
+       data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
 
        ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
 
        return ret;
 }
 
-static int ath6kl_wmi_sync_point(struct wmi *wmi)
+static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
 {
        struct sk_buff *skb;
        struct wmi_sync_cmd *cmd;
@@ -2113,7 +2195,7 @@ static int ath6kl_wmi_sync_point(struct wmi *wmi)
         * Send sync cmd followed by sync data messages on all
         * endpoints being used
         */
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        if (ret)
@@ -2132,7 +2214,7 @@ static int ath6kl_wmi_sync_point(struct wmi *wmi)
                                               traffic_class);
                ret =
                    ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
-                                             ep_id);
+                                             ep_id, if_idx);
 
                if (ret)
                        break;
@@ -2155,7 +2237,7 @@ free_skb:
        return ret;
 }
 
-int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
+int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
                                  struct wmi_create_pstream_cmd *params)
 {
        struct sk_buff *skb;
@@ -2244,12 +2326,13 @@ int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
                ath6kl_indicate_tx_activity(wmi->parent_dev,
                                            params->traffic_class, true);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
+int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
+                                 u8 tsid)
 {
        struct sk_buff *skb;
        struct wmi_delete_pstream_cmd *cmd;
@@ -2285,7 +2368,7 @@ int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
                   "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
                   traffic_class, tsid);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
                                  SYNC_BEFORE_WMIFLAG);
 
        spin_lock_bh(&wmi->lock);
@@ -2324,7 +2407,8 @@ int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
        cmd = (struct wmi_set_ip_cmd *) skb->data;
        memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
+       ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_IP_CMDID,
+                                 NO_SYNC_WMIFLAG);
        return ret;
 }
 
@@ -2349,7 +2433,7 @@ static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
        cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
        cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
+       ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
 
        return ret;
 }
@@ -2373,12 +2457,31 @@ int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
        return ret;
 }
 
-int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
+int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
+{
+       struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
+       struct sk_buff *skb;
+       int ret;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
+       cmd->valid = cpu_to_le32(valid);
+       cmd->config = cpu_to_le32(config);
+
+       ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
+                                      NO_SYNC_WMIFLAG);
+       return ret;
+}
+
+int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
 {
-       return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
+       return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
 }
 
-int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
+int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
 {
        struct sk_buff *skb;
        struct wmi_set_tx_pwr_cmd *cmd;
@@ -2391,18 +2494,24 @@ int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
        cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
        cmd->dbM = dbM;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
-int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
+int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
+{
+       return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
+}
+
+int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
 {
-       return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
+       return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
 }
 
-int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
+int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
+                                u8 preamble_policy)
 {
        struct sk_buff *skb;
        struct wmi_set_lpreamble_cmd *cmd;
@@ -2416,7 +2525,7 @@ int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
        cmd->status = status;
        cmd->preamble_policy = preamble_policy;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
@@ -2434,11 +2543,12 @@ int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
        cmd = (struct wmi_set_rts_cmd *) skb->data;
        cmd->threshold = cpu_to_le16(threshold);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
+       ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
+                                 NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
+int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
 {
        struct sk_buff *skb;
        struct wmi_set_wmm_txop_cmd *cmd;
@@ -2454,12 +2564,13 @@ int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
        cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
        cmd->txop_enable = cfg;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
+int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
+                                u8 keep_alive_intvl)
 {
        struct sk_buff *skb;
        struct wmi_set_keepalive_cmd *cmd;
@@ -2471,56 +2582,39 @@ int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
 
        cmd = (struct wmi_set_keepalive_cmd *) skb->data;
        cmd->keep_alive_intvl = keep_alive_intvl;
-       wmi->keep_alive_intvl = keep_alive_intvl;
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
                                  NO_SYNC_WMIFLAG);
-       return ret;
-}
 
-s32 ath6kl_wmi_get_rate(s8 rate_index)
-{
-       if (rate_index == RATE_AUTO)
-               return 0;
+       if (ret == 0)
+               ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
 
-       return wmi_rate_tbl[(u32) rate_index][0];
-}
-
-void ath6kl_wmi_node_return(struct wmi *wmi, struct bss *bss)
-{
-       if (bss)
-               wlan_node_return(&wmi->parent_dev->scan_table, bss);
+       return ret;
 }
 
-struct bss *ath6kl_wmi_find_ssid_node(struct wmi *wmi, u8 * ssid,
-                                     u32 ssid_len, bool is_wpa2,
-                                     bool match_ssid)
+int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
 {
-       struct bss *node = NULL;
+       struct sk_buff *skb;
+       int ret;
 
-       node = wlan_find_ssid_node(&wmi->parent_dev->scan_table, ssid,
-                                 ssid_len, is_wpa2, match_ssid);
-       return node;
-}
+       skb = ath6kl_wmi_get_new_buf(len);
+       if (!skb)
+               return -ENOMEM;
 
-struct bss *ath6kl_wmi_find_node(struct wmi *wmi, const u8 * mac_addr)
-{
-       struct bss *ni = NULL;
+       memcpy(skb->data, buf, len);
 
-       ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
+       ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
 
-       return ni;
+       return ret;
 }
 
-void ath6kl_wmi_node_free(struct wmi *wmi, const u8 * mac_addr)
-{
-       struct bss *ni = NULL;
 
-       ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
-       if (ni != NULL)
-               wlan_node_reclaim(&wmi->parent_dev->scan_table, ni);
+s32 ath6kl_wmi_get_rate(s8 rate_index)
+{
+       if (rate_index == RATE_AUTO)
+               return 0;
 
-       return;
+       return wmi_rate_tbl[(u32) rate_index][0];
 }
 
 static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
@@ -2542,28 +2636,31 @@ static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
        return 0;
 }
 
-static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                        struct ath6kl_vif *vif)
 {
        struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
 
-       aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
+       aggr_recv_addba_req_evt(vif, cmd->tid,
                                le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
 
        return 0;
 }
 
-static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                        struct ath6kl_vif *vif)
 {
        struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
 
-       aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
+       aggr_recv_delba_req_evt(vif, cmd->tid);
 
        return 0;
 }
 
 /*  AP mode functions */
 
-int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
+int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
+                                struct wmi_connect_cmd *p)
 {
        struct sk_buff *skb;
        struct wmi_connect_cmd *cm;
@@ -2576,7 +2673,7 @@ int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
        cm = (struct wmi_connect_cmd *) skb->data;
        memcpy(cm, p, sizeof(*cm));
 
-       res = ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_CONFIG_COMMIT_CMDID,
+       res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
                                  NO_SYNC_WMIFLAG);
        ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
                   "ctrl_flags=0x%x-> res=%d\n",
@@ -2585,7 +2682,8 @@ int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
        return res;
 }
 
-int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
+int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
+                          u16 reason)
 {
        struct sk_buff *skb;
        struct wmi_ap_set_mlme_cmd *cm;
@@ -2599,11 +2697,12 @@ int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
        cm->reason = cpu_to_le16(reason);
        cm->cmd = cmd;
 
-       return ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_SET_MLME_CMDID,
+       return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
-static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                     struct ath6kl_vif *vif)
 {
        struct wmi_pspoll_event *ev;
 
@@ -2612,19 +2711,21 @@ static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
 
        ev = (struct wmi_pspoll_event *) datap;
 
-       ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
+       ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
 
        return 0;
 }
 
-static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
+static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
+                                         struct ath6kl_vif *vif)
 {
-       ath6kl_dtimexpiry_event(wmi->parent_dev);
+       ath6kl_dtimexpiry_event(vif);
 
        return 0;
 }
 
-int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
+int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
+                          bool flag)
 {
        struct sk_buff *skb;
        struct wmi_ap_set_pvb_cmd *cmd;
@@ -2636,15 +2737,17 @@ int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
 
        cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
        cmd->aid = cpu_to_le16(aid);
+       cmd->rsvd = cpu_to_le16(0);
        cmd->flag = cpu_to_le32(flag);
 
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        return 0;
 }
 
-int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
+int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
+                                      u8 rx_meta_ver,
                                       bool rx_dot11_hdr, bool defrag_on_host)
 {
        struct sk_buff *skb;
@@ -2661,14 +2764,14 @@ int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
        cmd->meta_ver = rx_meta_ver;
 
        /* Delete the local aggr state, on host */
-       ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
                                  NO_SYNC_WMIFLAG);
 
        return ret;
 }
 
-int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
-                            u8 ie_len)
+int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
+                            const u8 *ie, u8 ie_len)
 {
        struct sk_buff *skb;
        struct wmi_set_appie_cmd *p;
@@ -2683,7 +2786,7 @@ int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
        p->mgmt_frm_type = mgmt_frm_type;
        p->ie_len = ie_len;
        memcpy(p->ie_info, ie, ie_len);
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_APPIE_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
@@ -2701,11 +2804,11 @@ int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
        cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
        cmd->disable = disable ? 1 : 0;
 
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_DISABLE_11B_RATES_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
-int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
+int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
 {
        struct sk_buff *skb;
        struct wmi_remain_on_chnl_cmd *p;
@@ -2719,22 +2822,34 @@ int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
        p = (struct wmi_remain_on_chnl_cmd *) skb->data;
        p->freq = cpu_to_le32(freq);
        p->duration = cpu_to_le32(dur);
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_REMAIN_ON_CHNL_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
-int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
-                              const u8 *data, u16 data_len)
+int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
+                              u32 wait, const u8 *data, u16 data_len)
 {
        struct sk_buff *skb;
        struct wmi_send_action_cmd *p;
+       u8 *buf;
 
        if (wait)
                return -EINVAL; /* Offload for wait not supported */
 
+       buf = kmalloc(data_len, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
        skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
-       if (!skb)
+       if (!skb) {
+               kfree(buf);
                return -ENOMEM;
+       }
+
+       kfree(wmi->last_mgmt_tx_frame);
+       memcpy(buf, data, data_len);
+       wmi->last_mgmt_tx_frame = buf;
+       wmi->last_mgmt_tx_frame_len = data_len;
 
        ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
                   "len=%u\n", id, freq, wait, data_len);
@@ -2744,13 +2859,13 @@ int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
        p->wait = cpu_to_le32(wait);
        p->len = cpu_to_le16(data_len);
        memcpy(p->data, data, data_len);
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_ACTION_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
-int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
-                                      const u8 *dst,
-                                      const u8 *data, u16 data_len)
+int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
+                                      const u8 *dst, const u8 *data,
+                                      u16 data_len)
 {
        struct sk_buff *skb;
        struct wmi_p2p_probe_response_cmd *p;
@@ -2766,11 +2881,12 @@ int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
        memcpy(p->destination_addr, dst, ETH_ALEN);
        p->len = cpu_to_le16(data_len);
        memcpy(p->data, data, data_len);
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_PROBE_RESPONSE_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
+                                  WMI_SEND_PROBE_RESPONSE_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
-int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
+int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
 {
        struct sk_buff *skb;
        struct wmi_probe_req_report_cmd *p;
@@ -2783,11 +2899,11 @@ int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
                   enable);
        p = (struct wmi_probe_req_report_cmd *) skb->data;
        p->enable = enable ? 1 : 0;
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_PROBE_REQ_REPORT_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
-int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
+int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
 {
        struct sk_buff *skb;
        struct wmi_get_p2p_info *p;
@@ -2800,14 +2916,15 @@ int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
                   info_req_flags);
        p = (struct wmi_get_p2p_info *) skb->data;
        p->info_req_flags = cpu_to_le32(info_req_flags);
-       return ath6kl_wmi_cmd_send(wmi, skb, WMI_GET_P2P_INFO_CMDID,
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
 
-int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi)
+int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
 {
        ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
-       return ath6kl_wmi_simple_cmd(wmi, WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
+       return ath6kl_wmi_simple_cmd(wmi, if_idx,
+                                    WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
 }
 
 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
@@ -2820,7 +2937,6 @@ static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
 
        if (skb->len < sizeof(struct wmix_cmd_hdr)) {
                ath6kl_err("bad packet 1\n");
-               wmi->stat.cmd_len_err++;
                return -EINVAL;
        }
 
@@ -2834,12 +2950,14 @@ static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
 
        switch (id) {
        case WMIX_HB_CHALLENGE_RESP_EVENTID:
+               ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
                break;
        case WMIX_DBGLOG_EVENTID:
+               ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
+               ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
                break;
        default:
-               ath6kl_err("unknown cmd id 0x%x\n", id);
-               wmi->stat.cmd_id_err++;
+               ath6kl_warn("unknown cmd id 0x%x\n", id);
                ret = -EINVAL;
                break;
        }
@@ -2847,12 +2965,19 @@ static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
        return ret;
 }
 
+static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
+{
+       return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
+}
+
 /* Control Path */
 int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
 {
        struct wmi_cmd_hdr *cmd;
+       struct ath6kl_vif *vif;
        u32 len;
        u16 id;
+       u8 if_idx;
        u8 *datap;
        int ret = 0;
 
@@ -2862,20 +2987,30 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
        if (skb->len < sizeof(struct wmi_cmd_hdr)) {
                ath6kl_err("bad packet 1\n");
                dev_kfree_skb(skb);
-               wmi->stat.cmd_len_err++;
                return -EINVAL;
        }
 
        cmd = (struct wmi_cmd_hdr *) skb->data;
        id = le16_to_cpu(cmd->cmd_id);
+       if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
 
        skb_pull(skb, sizeof(struct wmi_cmd_hdr));
 
        datap = skb->data;
        len = skb->len;
 
-       ath6kl_dbg(ATH6KL_DBG_WMI, "%s: wmi id: %d\n", __func__, id);
-       ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "msg payload ", datap, len);
+       ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
+       ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
+                       datap, len);
+
+       vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
+       if (!vif) {
+               ath6kl_dbg(ATH6KL_DBG_WMI,
+                          "Wmi event for unavailable vif, vif_index:%d\n",
+                           if_idx);
+               dev_kfree_skb(skb);
+               return -EINVAL;
+       }
 
        switch (id) {
        case WMI_GET_BITRATE_CMDID:
@@ -2896,11 +3031,11 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_CONNECT_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
-               ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
                break;
        case WMI_DISCONNECT_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
-               ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
                break;
        case WMI_PEER_NODE_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
@@ -2908,15 +3043,15 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_TKIP_MICERR_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
-               ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
                break;
        case WMI_BSSINFO_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
-               ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(skb, datap);
-               ret = ath6kl_wmi_bssinfo_event_rx(wmi, skb->data, skb->len);
+               ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
                break;
        case WMI_REGDOMAIN_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
+               ath6kl_wmi_regdomain_event(wmi, datap, len);
                break;
        case WMI_PSTREAM_TIMEOUT_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
@@ -2924,10 +3059,12 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_NEIGHBOR_REPORT_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
+               ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
+                                                         vif);
                break;
        case WMI_SCAN_COMPLETE_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
-               ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
+               ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
                break;
        case WMI_CMDERROR_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
@@ -2935,7 +3072,7 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_REPORT_STATISTICS_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
-               ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
                break;
        case WMI_RSSI_THRESHOLD_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
@@ -2946,10 +3083,11 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_OPT_RX_FRAME_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
-               ret = ath6kl_wmi_opt_frame_event_rx(wmi, datap, len);
+               /* this event has been deprecated */
                break;
        case WMI_REPORT_ROAM_TBL_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
+               ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
                break;
        case WMI_EXTENSION_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
@@ -2957,7 +3095,7 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_CAC_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
-               ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
                break;
        case WMI_CHANNEL_CHANGE_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
@@ -2965,6 +3103,10 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
        case WMI_REPORT_ROAM_DATA_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
                break;
+       case WMI_TEST_EVENTID:
+               ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
+               ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
+               break;
        case WMI_GET_FIXRATES_CMDID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
                ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
@@ -2997,25 +3139,25 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_PSPOLL_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
-               ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
                break;
        case WMI_DTIMEXPIRY_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
-               ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
                break;
        case WMI_SET_PARAMS_REPLY_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
                break;
        case WMI_ADDBA_REQ_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
-               ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
                break;
        case WMI_ADDBA_RESP_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
                break;
        case WMI_DELBA_REQ_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
-               ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
                break;
        case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI,
@@ -3031,21 +3173,21 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_REMAIN_ON_CHNL_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
-               ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
+               ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
                break;
        case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI,
                           "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
                ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
-                                                               len);
+                                                               len, vif);
                break;
        case WMI_TX_STATUS_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
-               ret = ath6kl_wmi_tx_status_event_rx(datap, len);
+               ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
                break;
        case WMI_RX_PROBE_REQ_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
-               ret = ath6kl_wmi_rx_probe_req_event_rx(datap, len);
+               ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
                break;
        case WMI_P2P_CAPABILITIES_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
@@ -3053,7 +3195,7 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_RX_ACTION_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
-               ret = ath6kl_wmi_rx_action_event_rx(datap, len);
+               ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
                break;
        case WMI_P2P_INFO_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
@@ -3061,7 +3203,6 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        default:
                ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
-               wmi->stat.cmd_id_err++;
                ret = -EINVAL;
                break;
        }
@@ -3071,11 +3212,8 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
        return ret;
 }
 
-static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
+void ath6kl_wmi_reset(struct wmi *wmi)
 {
-       if (!wmi)
-               return;
-
        spin_lock_bh(&wmi->lock);
 
        wmi->fat_pipe_exist = 0;
@@ -3096,16 +3234,9 @@ void *ath6kl_wmi_init(struct ath6kl *dev)
 
        wmi->parent_dev = dev;
 
-       ath6kl_wmi_qos_state_init(wmi);
-
        wmi->pwr_mode = REC_POWER;
-       wmi->phy_mode = WMI_11G_MODE;
-
-       wmi->pair_crypto_type = NONE_CRYPT;
-       wmi->grp_crypto_type = NONE_CRYPT;
 
-       wmi->ht_allowed[A_BAND_24GHZ] = 1;
-       wmi->ht_allowed[A_BAND_5GHZ] = 1;
+       ath6kl_wmi_reset(wmi);
 
        return wmi;
 }
@@ -3115,5 +3246,6 @@ void ath6kl_wmi_shutdown(struct wmi *wmi)
        if (!wmi)
                return;
 
+       kfree(wmi->last_mgmt_tx_frame);
        kfree(wmi);
 }
This page took 0.078005 seconds and 5 git commands to generate.