ath6kl: Avoid taking struct as argument in ath6kl_wmi_set_ip_cmd
[deliverable/linux.git] / drivers / net / wireless / ath / ath6kl / wmi.c
index ece67a5c37b31a19e7b40f9ec4a770d02decc4e3..1e31c38abb4fecd529566f79ae8aacd4c2ccc503 100644 (file)
@@ -85,7 +85,7 @@ 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)))
+       if (WARN_ON(if_idx > (ar->vif_max - 1)))
                return NULL;
 
        /* FIXME: Locking */
@@ -187,7 +187,7 @@ int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
        struct wmi_data_hdr *data_hdr;
        int ret;
 
-       if (WARN_ON(skb == NULL || (if_idx > MAX_NUM_VIF - 1)))
+       if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
                return -EINVAL;
 
        if (tx_meta_info) {
@@ -977,6 +977,13 @@ static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
        return 0;
 }
 
+void ath6kl_wmi_sscan_timer(unsigned long ptr)
+{
+       struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
+
+       cfg80211_sched_scan_results(vif->ar->wiphy);
+}
+
 static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
                                       struct ath6kl_vif *vif)
 {
@@ -1066,6 +1073,21 @@ static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
                return -ENOMEM;
        cfg80211_put_bss(bss);
 
+       /*
+        * Firmware doesn't return any event when scheduled scan has
+        * finished, so we need to use a timer to find out when there are
+        * no more results.
+        *
+        * The timer is started from the first bss info received, otherwise
+        * the timer would not ever fire if the scan interval is short
+        * enough.
+        */
+       if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
+           !timer_pending(&vif->sched_scan_timer)) {
+               mod_timer(&vif->sched_scan_timer, jiffies +
+                         msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
+       }
+
        return 0;
 }
 
@@ -1620,7 +1642,7 @@ int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
        int ret;
        u16 info1;
 
-       if (WARN_ON(skb == NULL || (if_idx > (MAX_NUM_VIF - 1))))
+       if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1))))
                return -EINVAL;
 
        ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
@@ -1682,7 +1704,8 @@ int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
                           u8 pairwise_crypto_len,
                           enum crypto_type group_crypto,
                           u8 group_crypto_len, int ssid_len, u8 *ssid,
-                          u8 *bssid, u16 channel, u32 ctrl_flags)
+                          u8 *bssid, u16 channel, u32 ctrl_flags,
+                          u8 nw_subtype)
 {
        struct sk_buff *skb;
        struct wmi_connect_cmd *cc;
@@ -1722,6 +1745,7 @@ int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
        cc->grp_crypto_len = group_crypto_len;
        cc->ch = cpu_to_le16(channel);
        cc->ctrl_flags = cpu_to_le32(ctrl_flags);
+       cc->nw_subtype = nw_subtype;
 
        if (bssid != NULL)
                memcpy(cc->bssid, bssid, ETH_ALEN);
@@ -1774,6 +1798,72 @@ int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
        return ret;
 }
 
+int ath6kl_wmi_beginscan_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, u32 no_cck, u32 *rates)
+{
+       struct sk_buff *skb;
+       struct wmi_begin_scan_cmd *sc;
+       s8 size;
+       int i, band, ret;
+       struct ath6kl *ar = wmi->parent_dev;
+       int num_rates;
+
+       size = sizeof(struct wmi_begin_scan_cmd);
+
+       if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
+               return -EINVAL;
+
+       if (num_chan > WMI_MAX_CHANNELS)
+               return -EINVAL;
+
+       if (num_chan)
+               size += sizeof(u16) * (num_chan - 1);
+
+       skb = ath6kl_wmi_get_new_buf(size);
+       if (!skb)
+               return -ENOMEM;
+
+       sc = (struct wmi_begin_scan_cmd *) skb->data;
+       sc->scan_type = scan_type;
+       sc->force_fg_scan = cpu_to_le32(force_fgscan);
+       sc->is_legacy = cpu_to_le32(is_legacy);
+       sc->home_dwell_time = cpu_to_le32(home_dwell_time);
+       sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
+       sc->no_cck = cpu_to_le32(no_cck);
+       sc->num_ch = num_chan;
+
+       for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
+               struct ieee80211_supported_band *sband =
+                   ar->wiphy->bands[band];
+               u32 ratemask = rates[band];
+               u8 *supp_rates = sc->supp_rates[band].rates;
+               num_rates = 0;
+
+               for (i = 0; i < sband->n_bitrates; i++) {
+                       if ((BIT(i) & ratemask) == 0)
+                               continue; /* skip rate */
+                       supp_rates[num_rates++] =
+                           (u8) (sband->bitrates[i].bitrate / 5);
+               }
+               sc->supp_rates[band].nrates = num_rates;
+       }
+
+       for (i = 0; i < num_chan; i++)
+               sc->ch_list[i] = cpu_to_le16(ch_list[i]);
+
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
+                                 NO_SYNC_WMIFLAG);
+
+       return ret;
+}
+
+/* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
+ * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
+ * mgmt operations using station interface.
+ */
 int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
                             enum wmi_scan_type scan_type,
                             u32 force_fgscan, u32 is_legacy,
@@ -2000,7 +2090,8 @@ int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
 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)
 {
@@ -2013,7 +2104,7 @@ int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, 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))
@@ -2031,7 +2122,7 @@ int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, 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;
 
@@ -2388,15 +2479,16 @@ int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
        return ret;
 }
 
-int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
+int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
+                         __be32 ips0, __be32 ips1)
 {
        struct sk_buff *skb;
        struct wmi_set_ip_cmd *cmd;
        int ret;
 
        /* Multicast address are not valid */
-       if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
-           (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
+       if (ipv4_is_multicast(ips0) ||
+           ipv4_is_multicast(ips1))
                return -EINVAL;
 
        skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
@@ -2404,20 +2496,176 @@ int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
                return -ENOMEM;
 
        cmd = (struct wmi_set_ip_cmd *) skb->data;
-       memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
+       cmd->ips[0] = ips0;
+       cmd->ips[1] = ips1;
 
-       ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_IP_CMDID,
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
                                  NO_SYNC_WMIFLAG);
        return ret;
 }
 
-static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
-                                           int len)
+static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
 {
-       if (len < sizeof(struct wmi_get_wow_list_reply))
+       u16 active_tsids;
+       u8 stream_exist;
+       int i;
+
+       /*
+        * Relinquish credits from all implicitly created pstreams
+        * since when we go to sleep. If user created explicit
+        * thinstreams exists with in a fatpipe leave them intact
+        * for the user to delete.
+        */
+       spin_lock_bh(&wmi->lock);
+       stream_exist = wmi->fat_pipe_exist;
+       spin_unlock_bh(&wmi->lock);
+
+       for (i = 0; i < WMM_NUM_AC; i++) {
+               if (stream_exist & (1 << i)) {
+
+                       /*
+                        * FIXME: Is this lock & unlock inside
+                        * for loop correct? may need rework.
+                        */
+                       spin_lock_bh(&wmi->lock);
+                       active_tsids = wmi->stream_exist_for_ac[i];
+                       spin_unlock_bh(&wmi->lock);
+
+                       /*
+                        * If there are no user created thin streams
+                        * delete the fatpipe
+                        */
+                       if (!active_tsids) {
+                               stream_exist &= ~(1 << i);
+                               /*
+                                * Indicate inactivity to driver layer for
+                                * this fatpipe (pstream)
+                                */
+                               ath6kl_indicate_tx_activity(wmi->parent_dev,
+                                                           i, false);
+                       }
+               }
+       }
+
+       /* FIXME: Can we do this assignment without locking ? */
+       spin_lock_bh(&wmi->lock);
+       wmi->fat_pipe_exist = stream_exist;
+       spin_unlock_bh(&wmi->lock);
+}
+
+int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
+                                      enum ath6kl_host_mode host_mode)
+{
+       struct sk_buff *skb;
+       struct wmi_set_host_sleep_mode_cmd *cmd;
+       int ret;
+
+       if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
+           (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
+               ath6kl_err("invalid host sleep mode: %d\n", host_mode);
                return -EINVAL;
+       }
 
-       return 0;
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
+
+       if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
+               ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
+               cmd->asleep = cpu_to_le32(1);
+       } else
+               cmd->awake = cpu_to_le32(1);
+
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
+                                 WMI_SET_HOST_SLEEP_MODE_CMDID,
+                                 NO_SYNC_WMIFLAG);
+       return ret;
+}
+
+int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
+                               enum ath6kl_wow_mode wow_mode,
+                               u32 filter, u16 host_req_delay)
+{
+       struct sk_buff *skb;
+       struct wmi_set_wow_mode_cmd *cmd;
+       int ret;
+
+       if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
+            wow_mode != ATH6KL_WOW_MODE_DISABLE) {
+               ath6kl_err("invalid wow mode: %d\n", wow_mode);
+               return -EINVAL;
+       }
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
+       cmd->enable_wow = cpu_to_le32(wow_mode);
+       cmd->filter = cpu_to_le32(filter);
+       cmd->host_req_delay = cpu_to_le16(host_req_delay);
+
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
+                                 NO_SYNC_WMIFLAG);
+       return ret;
+}
+
+int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
+                                  u8 list_id, u8 filter_size,
+                                  u8 filter_offset, u8 *filter, u8 *mask)
+{
+       struct sk_buff *skb;
+       struct wmi_add_wow_pattern_cmd *cmd;
+       u16 size;
+       u8 *filter_mask;
+       int ret;
+
+       /*
+        * Allocate additional memory in the buffer to hold
+        * filter and mask value, which is twice of filter_size.
+        */
+       size = sizeof(*cmd) + (2 * filter_size);
+
+       skb = ath6kl_wmi_get_new_buf(size);
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
+       cmd->filter_list_id = list_id;
+       cmd->filter_size = filter_size;
+       cmd->filter_offset = filter_offset;
+
+       memcpy(cmd->filter, filter, filter_size);
+
+       filter_mask = (u8 *) (cmd->filter + filter_size);
+       memcpy(filter_mask, mask, filter_size);
+
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
+                                 NO_SYNC_WMIFLAG);
+
+       return ret;
+}
+
+int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
+                                  u16 list_id, u16 filter_id)
+{
+       struct sk_buff *skb;
+       struct wmi_del_wow_pattern_cmd *cmd;
+       int ret;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
+       cmd->filter_list_id = cpu_to_le16(list_id);
+       cmd->filter_id = cpu_to_le16(filter_id);
+
+       ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
+                                 NO_SYNC_WMIFLAG);
+       return ret;
 }
 
 static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
@@ -2784,7 +3032,10 @@ int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
        p = (struct wmi_set_appie_cmd *) skb->data;
        p->mgmt_frm_type = mgmt_frm_type;
        p->ie_len = ie_len;
-       memcpy(p->ie_info, ie, ie_len);
+
+       if (ie != NULL && ie_len > 0)
+               memcpy(p->ie_info, ie, ie_len);
+
        return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
@@ -2825,6 +3076,10 @@ int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
                                   NO_SYNC_WMIFLAG);
 }
 
+/* ath6kl_wmi_send_action_cmd is to be deprecated. Use
+ * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
+ * mgmt operations using station interface.
+ */
 int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
                               u32 wait, const u8 *data, u16 data_len)
 {
@@ -2862,14 +3117,57 @@ int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
                                   NO_SYNC_WMIFLAG);
 }
 
+int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
+                              u32 wait, const u8 *data, u16 data_len,
+                              u32 no_cck)
+{
+       struct sk_buff *skb;
+       struct wmi_send_mgmt_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) {
+               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);
+       p = (struct wmi_send_mgmt_cmd *) skb->data;
+       p->id = cpu_to_le32(id);
+       p->freq = cpu_to_le32(freq);
+       p->wait = cpu_to_le32(wait);
+       p->no_cck = cpu_to_le32(no_cck);
+       p->len = cpu_to_le16(data_len);
+       memcpy(p->data, data, data_len);
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
+                                  NO_SYNC_WMIFLAG);
+}
+
 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;
+       size_t cmd_len = sizeof(*p) + data_len;
 
-       skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
+       if (data_len == 0)
+               cmd_len++; /* work around target minimum length requirement */
+
+       skb = ath6kl_wmi_get_new_buf(cmd_len);
        if (!skb)
                return -ENOMEM;
 
@@ -3130,7 +3428,6 @@ int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
                break;
        case WMI_GET_WOW_LIST_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
-               ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
                break;
        case WMI_GET_PMKID_LIST_EVENTID:
                ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
This page took 0.03024 seconds and 5 git commands to generate.