2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include "../regd_common.h"
26 static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
28 static const s32 wmi_rate_tbl[][2] = {
29 /* {W/O SGI, with SGI} */
61 /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
62 static const u8 up_to_ac[] = {
73 void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
75 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
81 enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
86 struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
88 struct ath6kl_vif *vif, *found = NULL;
90 if (WARN_ON(if_idx > (ar->vif_max - 1)))
94 spin_lock_bh(&ar->list_lock);
95 list_for_each_entry(vif, &ar->vif_list, list) {
96 if (vif->fw_vif_idx == if_idx) {
101 spin_unlock_bh(&ar->list_lock);
106 /* Performs DIX to 802.3 encapsulation for transmit packets.
107 * Assumes the entire DIX header is contigous and that there is
108 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
110 int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
112 struct ath6kl_llc_snap_hdr *llc_hdr;
113 struct ethhdr *eth_hdr;
119 if (WARN_ON(skb == NULL))
122 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
123 if (skb_headroom(skb) < size)
126 eth_hdr = (struct ethhdr *) skb->data;
127 type = eth_hdr->h_proto;
129 if (!is_ethertype(be16_to_cpu(type))) {
130 ath6kl_dbg(ATH6KL_DBG_WMI,
131 "%s: pkt is already in 802.3 format\n", __func__);
135 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
137 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
140 eth_hdr->h_proto = cpu_to_be16(new_len);
142 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
144 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
145 llc_hdr->dsap = 0xAA;
146 llc_hdr->ssap = 0xAA;
147 llc_hdr->cntl = 0x03;
148 llc_hdr->org_code[0] = 0x0;
149 llc_hdr->org_code[1] = 0x0;
150 llc_hdr->org_code[2] = 0x0;
151 llc_hdr->eth_type = type;
156 static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
157 u8 *version, void *tx_meta_info)
159 struct wmi_tx_meta_v1 *v1;
160 struct wmi_tx_meta_v2 *v2;
162 if (WARN_ON(skb == NULL || version == NULL))
166 case WMI_META_VERSION_1:
167 skb_push(skb, WMI_MAX_TX_META_SZ);
168 v1 = (struct wmi_tx_meta_v1 *) skb->data;
170 v1->rate_plcy_id = 0;
171 *version = WMI_META_VERSION_1;
173 case WMI_META_VERSION_2:
174 skb_push(skb, WMI_MAX_TX_META_SZ);
175 v2 = (struct wmi_tx_meta_v2 *) skb->data;
176 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
177 sizeof(struct wmi_tx_meta_v2));
184 int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
185 u8 msg_type, u32 flags,
186 enum wmi_data_hdr_data_type data_type,
187 u8 meta_ver, void *tx_meta_info, u8 if_idx)
189 struct wmi_data_hdr *data_hdr;
192 if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
196 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
201 skb_push(skb, sizeof(struct wmi_data_hdr));
203 data_hdr = (struct wmi_data_hdr *)skb->data;
204 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
206 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
207 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
209 if (flags & WMI_DATA_HDR_FLAGS_MORE)
210 data_hdr->info |= WMI_DATA_HDR_MORE;
212 if (flags & WMI_DATA_HDR_FLAGS_EOSP)
213 data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
215 data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
216 data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
221 u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
223 struct iphdr *ip_hdr = (struct iphdr *) pkt;
227 * Determine IPTOS priority
230 * : DSCP(6-bits) ECN(2-bits)
231 * : DSCP - P2 P1 P0 X X X
232 * where (P2 P1 P0) form 802.1D
234 ip_pri = ip_hdr->tos >> 5;
237 if ((layer2_pri & 0x7) > ip_pri)
238 return (u8) layer2_pri & 0x7;
243 u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
245 return up_to_ac[user_priority & 0x7];
248 int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
250 u32 layer2_priority, bool wmm_enabled,
253 struct wmi_data_hdr *data_hdr;
254 struct ath6kl_llc_snap_hdr *llc_hdr;
255 struct wmi_create_pstream_cmd cmd;
256 u32 meta_size, hdr_size;
257 u16 ip_type = IP_ETHERTYPE;
258 u8 stream_exist, usr_pri;
259 u8 traffic_class = WMM_AC_BE;
262 if (WARN_ON(skb == NULL))
266 data_hdr = (struct wmi_data_hdr *) datap;
268 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
269 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
272 /* If WMM is disabled all traffic goes as BE traffic */
275 hdr_size = sizeof(struct ethhdr);
277 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
280 meta_size + hdr_size);
282 if (llc_hdr->eth_type == htons(ip_type)) {
284 * Extract the endpoint info from the TOS field
288 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
289 sizeof(struct ath6kl_llc_snap_hdr),
292 usr_pri = layer2_priority & 0x7;
295 * Queue the EAPOL frames in the same WMM_AC_VO queue
296 * as that of management frames.
298 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
299 usr_pri = WMI_VOICE_USER_PRIORITY;
303 * workaround for WMM S5
305 * FIXME: wmi->traffic_class is always 100 so this test doesn't
308 if ((wmi->traffic_class == WMM_AC_VI) &&
309 ((usr_pri == 5) || (usr_pri == 4)))
312 /* Convert user priority to traffic class */
313 traffic_class = up_to_ac[usr_pri & 0x7];
315 wmi_data_hdr_set_up(data_hdr, usr_pri);
317 spin_lock_bh(&wmi->lock);
318 stream_exist = wmi->fat_pipe_exist;
319 spin_unlock_bh(&wmi->lock);
321 if (!(stream_exist & (1 << traffic_class))) {
322 memset(&cmd, 0, sizeof(cmd));
323 cmd.traffic_class = traffic_class;
324 cmd.user_pri = usr_pri;
326 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
327 /* Implicit streams are created with TSID 0xFF */
328 cmd.tsid = WMI_IMPLICIT_PSTREAM;
329 ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
337 int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
339 struct ieee80211_hdr_3addr *pwh, wh;
340 struct ath6kl_llc_snap_hdr *llc_hdr;
341 struct ethhdr eth_hdr;
346 if (WARN_ON(skb == NULL))
350 pwh = (struct ieee80211_hdr_3addr *) datap;
352 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
354 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
356 /* Strip off the 802.11 header */
357 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
358 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
360 skb_pull(skb, hdr_size);
361 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
362 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
365 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
367 memset(ð_hdr, 0, sizeof(eth_hdr));
368 eth_hdr.h_proto = llc_hdr->eth_type;
370 switch ((le16_to_cpu(wh.frame_control)) &
371 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
373 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
374 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
376 case IEEE80211_FCTL_TODS:
377 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
378 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
380 case IEEE80211_FCTL_FROMDS:
381 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
382 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
384 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
388 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
389 skb_push(skb, sizeof(eth_hdr));
393 memcpy(datap, ð_hdr, sizeof(eth_hdr));
399 * Performs 802.3 to DIX encapsulation for received packets.
400 * Assumes the entire 802.3 header is contigous.
402 int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
404 struct ath6kl_llc_snap_hdr *llc_hdr;
405 struct ethhdr eth_hdr;
408 if (WARN_ON(skb == NULL))
413 memcpy(ð_hdr, datap, sizeof(eth_hdr));
415 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
416 eth_hdr.h_proto = llc_hdr->eth_type;
418 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
421 memcpy(datap, ð_hdr, sizeof(eth_hdr));
426 static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
428 struct tx_complete_msg_v1 *msg_v1;
429 struct wmi_tx_complete_event *evt;
433 evt = (struct wmi_tx_complete_event *) datap;
435 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
436 evt->num_msg, evt->msg_len, evt->msg_type);
438 for (index = 0; index < evt->num_msg; index++) {
439 size = sizeof(struct wmi_tx_complete_event) +
440 (index * sizeof(struct tx_complete_msg_v1));
441 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
443 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
444 msg_v1->status, msg_v1->pkt_id,
445 msg_v1->rate_idx, msg_v1->ack_failures);
451 static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
452 int len, struct ath6kl_vif *vif)
454 struct wmi_remain_on_chnl_event *ev;
457 struct ieee80211_channel *chan;
458 struct ath6kl *ar = wmi->parent_dev;
461 if (len < sizeof(*ev))
464 ev = (struct wmi_remain_on_chnl_event *) datap;
465 freq = le32_to_cpu(ev->freq);
466 dur = le32_to_cpu(ev->duration);
467 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
469 chan = ieee80211_get_channel(ar->wiphy, freq);
471 ath6kl_dbg(ATH6KL_DBG_WMI,
472 "remain_on_chnl: Unknown channel (freq=%u)\n",
476 id = vif->last_roc_id;
477 cfg80211_ready_on_channel(&vif->wdev, id, chan, NL80211_CHAN_NO_HT,
483 static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
485 struct ath6kl_vif *vif)
487 struct wmi_cancel_remain_on_chnl_event *ev;
490 struct ieee80211_channel *chan;
491 struct ath6kl *ar = wmi->parent_dev;
494 if (len < sizeof(*ev))
497 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
498 freq = le32_to_cpu(ev->freq);
499 dur = le32_to_cpu(ev->duration);
500 ath6kl_dbg(ATH6KL_DBG_WMI,
501 "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
502 freq, dur, ev->status);
503 chan = ieee80211_get_channel(ar->wiphy, freq);
505 ath6kl_dbg(ATH6KL_DBG_WMI,
506 "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
510 if (vif->last_cancel_roc_id &&
511 vif->last_cancel_roc_id + 1 == vif->last_roc_id)
512 id = vif->last_cancel_roc_id; /* event for cancel command */
514 id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
515 vif->last_cancel_roc_id = 0;
516 cfg80211_remain_on_channel_expired(&vif->wdev, id, chan,
517 NL80211_CHAN_NO_HT, GFP_ATOMIC);
522 static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
523 struct ath6kl_vif *vif)
525 struct wmi_tx_status_event *ev;
528 if (len < sizeof(*ev))
531 ev = (struct wmi_tx_status_event *) datap;
532 id = le32_to_cpu(ev->id);
533 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
535 if (wmi->last_mgmt_tx_frame) {
536 cfg80211_mgmt_tx_status(&vif->wdev, id,
537 wmi->last_mgmt_tx_frame,
538 wmi->last_mgmt_tx_frame_len,
539 !!ev->ack_status, GFP_ATOMIC);
540 kfree(wmi->last_mgmt_tx_frame);
541 wmi->last_mgmt_tx_frame = NULL;
542 wmi->last_mgmt_tx_frame_len = 0;
548 static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
549 struct ath6kl_vif *vif)
551 struct wmi_p2p_rx_probe_req_event *ev;
555 if (len < sizeof(*ev))
558 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
559 freq = le32_to_cpu(ev->freq);
560 dlen = le16_to_cpu(ev->len);
561 if (datap + len < ev->data + dlen) {
562 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
566 ath6kl_dbg(ATH6KL_DBG_WMI,
567 "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
568 dlen, freq, vif->probe_req_report);
570 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
571 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
572 ev->data, dlen, GFP_ATOMIC);
577 static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
579 struct wmi_p2p_capabilities_event *ev;
582 if (len < sizeof(*ev))
585 ev = (struct wmi_p2p_capabilities_event *) datap;
586 dlen = le16_to_cpu(ev->len);
587 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
592 static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
593 struct ath6kl_vif *vif)
595 struct wmi_rx_action_event *ev;
599 if (len < sizeof(*ev))
602 ev = (struct wmi_rx_action_event *) datap;
603 freq = le32_to_cpu(ev->freq);
604 dlen = le16_to_cpu(ev->len);
605 if (datap + len < ev->data + dlen) {
606 ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
610 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
611 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
612 ev->data, dlen, GFP_ATOMIC);
617 static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
619 struct wmi_p2p_info_event *ev;
623 if (len < sizeof(*ev))
626 ev = (struct wmi_p2p_info_event *) datap;
627 flags = le32_to_cpu(ev->info_req_flags);
628 dlen = le16_to_cpu(ev->len);
629 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
631 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
632 struct wmi_p2p_capabilities *cap;
633 if (dlen < sizeof(*cap))
635 cap = (struct wmi_p2p_capabilities *) ev->data;
636 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
640 if (flags & P2P_FLAG_MACADDR_REQ) {
641 struct wmi_p2p_macaddr *mac;
642 if (dlen < sizeof(*mac))
644 mac = (struct wmi_p2p_macaddr *) ev->data;
645 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
649 if (flags & P2P_FLAG_HMODEL_REQ) {
650 struct wmi_p2p_hmodel *mod;
651 if (dlen < sizeof(*mod))
653 mod = (struct wmi_p2p_hmodel *) ev->data;
654 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
656 mod->p2p_model ? "host" : "firmware");
661 static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
665 skb = ath6kl_buf_alloc(size);
671 memset(skb->data, 0, size);
676 /* Send a "simple" wmi command -- one with no arguments */
677 static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
678 enum wmi_cmd_id cmd_id)
683 skb = ath6kl_wmi_get_new_buf(0);
687 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
692 static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
694 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
696 if (len < sizeof(struct wmi_ready_event_2))
699 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
700 le32_to_cpu(ev->sw_version),
701 le32_to_cpu(ev->abi_version), ev->phy_cap);
707 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
708 * at which the station has to roam can be passed with
709 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
712 int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
715 struct roam_ctrl_cmd *cmd;
717 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
721 cmd = (struct roam_ctrl_cmd *) skb->data;
723 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
724 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
725 DEF_SCAN_FOR_ROAM_INTVL);
726 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
727 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
728 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
730 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
736 int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
739 struct roam_ctrl_cmd *cmd;
741 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
745 cmd = (struct roam_ctrl_cmd *) skb->data;
747 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
748 cmd->roam_ctrl = WMI_FORCE_ROAM;
750 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
751 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
755 int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
758 struct set_dtim_cmd *cmd;
760 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
764 cmd = (struct set_dtim_cmd *) skb->data;
766 cmd->dtim_period = cpu_to_le32(dtim_period);
767 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
768 WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
771 int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
774 struct roam_ctrl_cmd *cmd;
776 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
780 cmd = (struct roam_ctrl_cmd *) skb->data;
782 cmd->info.roam_mode = mode;
783 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
785 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
786 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
790 static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
791 struct ath6kl_vif *vif)
793 struct wmi_connect_event *ev;
796 if (len < sizeof(struct wmi_connect_event))
799 ev = (struct wmi_connect_event *) datap;
801 if (vif->nw_type == AP_NETWORK) {
802 /* AP mode start/STA connected event */
803 struct net_device *dev = vif->ndev;
804 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
805 ath6kl_dbg(ATH6KL_DBG_WMI,
806 "%s: freq %d bssid %pM (AP started)\n",
807 __func__, le16_to_cpu(ev->u.ap_bss.ch),
809 ath6kl_connect_ap_mode_bss(
810 vif, le16_to_cpu(ev->u.ap_bss.ch));
812 ath6kl_dbg(ATH6KL_DBG_WMI,
813 "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
814 __func__, ev->u.ap_sta.aid,
815 ev->u.ap_sta.mac_addr,
817 ev->u.ap_sta.keymgmt,
818 le16_to_cpu(ev->u.ap_sta.cipher),
819 ev->u.ap_sta.apsd_info);
821 ath6kl_connect_ap_mode_sta(
822 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
823 ev->u.ap_sta.keymgmt,
824 le16_to_cpu(ev->u.ap_sta.cipher),
825 ev->u.ap_sta.auth, ev->assoc_req_len,
826 ev->assoc_info + ev->beacon_ie_len,
827 ev->u.ap_sta.apsd_info);
832 /* STA/IBSS mode connection event */
834 ath6kl_dbg(ATH6KL_DBG_WMI,
835 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
836 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
837 le16_to_cpu(ev->u.sta.listen_intvl),
838 le16_to_cpu(ev->u.sta.beacon_intvl),
839 le32_to_cpu(ev->u.sta.nw_type));
841 /* Start of assoc rsp IEs */
842 pie = ev->assoc_info + ev->beacon_ie_len +
843 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
845 /* End of assoc rsp IEs */
846 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
851 case WLAN_EID_VENDOR_SPECIFIC:
852 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
853 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
854 /* WMM OUT (00:50:F2) */
856 pie[6] == WMM_PARAM_OUI_SUBTYPE)
857 wmi->is_wmm_enabled = true;
862 if (wmi->is_wmm_enabled)
868 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
870 le16_to_cpu(ev->u.sta.listen_intvl),
871 le16_to_cpu(ev->u.sta.beacon_intvl),
872 le32_to_cpu(ev->u.sta.nw_type),
873 ev->beacon_ie_len, ev->assoc_req_len,
874 ev->assoc_resp_len, ev->assoc_info);
879 static struct country_code_to_enum_rd *
880 ath6kl_regd_find_country(u16 countryCode)
884 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
885 if (allCountries[i].countryCode == countryCode)
886 return &allCountries[i];
892 static struct reg_dmn_pair_mapping *
893 ath6kl_get_regpair(u16 regdmn)
897 if (regdmn == NO_ENUMRD)
900 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
901 if (regDomainPairs[i].regDmnEnum == regdmn)
902 return ®DomainPairs[i];
908 static struct country_code_to_enum_rd *
909 ath6kl_regd_find_country_by_rd(u16 regdmn)
913 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
914 if (allCountries[i].regDmnEnum == regdmn)
915 return &allCountries[i];
921 static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
924 struct ath6kl_wmi_regdomain *ev;
925 struct country_code_to_enum_rd *country = NULL;
926 struct reg_dmn_pair_mapping *regpair = NULL;
930 ev = (struct ath6kl_wmi_regdomain *) datap;
931 reg_code = le32_to_cpu(ev->reg_code);
933 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
934 country = ath6kl_regd_find_country((u16) reg_code);
935 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
937 regpair = ath6kl_get_regpair((u16) reg_code);
938 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
939 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
940 regpair->regDmnEnum);
943 if (country && wmi->parent_dev->wiphy_registered) {
944 alpha2[0] = country->isoName[0];
945 alpha2[1] = country->isoName[1];
947 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
949 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
950 alpha2[0], alpha2[1]);
954 static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
955 struct ath6kl_vif *vif)
957 struct wmi_disconnect_event *ev;
958 wmi->traffic_class = 100;
960 if (len < sizeof(struct wmi_disconnect_event))
963 ev = (struct wmi_disconnect_event *) datap;
965 ath6kl_dbg(ATH6KL_DBG_WMI,
966 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
967 le16_to_cpu(ev->proto_reason_status), ev->bssid,
968 ev->disconn_reason, ev->assoc_resp_len);
970 wmi->is_wmm_enabled = false;
972 ath6kl_disconnect_event(vif, ev->disconn_reason,
973 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
974 le16_to_cpu(ev->proto_reason_status));
979 static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
981 struct wmi_peer_node_event *ev;
983 if (len < sizeof(struct wmi_peer_node_event))
986 ev = (struct wmi_peer_node_event *) datap;
988 if (ev->event_code == PEER_NODE_JOIN_EVENT)
989 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
991 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
992 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
998 static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
999 struct ath6kl_vif *vif)
1001 struct wmi_tkip_micerr_event *ev;
1003 if (len < sizeof(struct wmi_tkip_micerr_event))
1006 ev = (struct wmi_tkip_micerr_event *) datap;
1008 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
1013 void ath6kl_wmi_sscan_timer(unsigned long ptr)
1015 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
1017 cfg80211_sched_scan_results(vif->ar->wiphy);
1020 static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
1021 struct ath6kl_vif *vif)
1023 struct wmi_bss_info_hdr2 *bih;
1025 struct ieee80211_channel *channel;
1026 struct ath6kl *ar = wmi->parent_dev;
1027 struct ieee80211_mgmt *mgmt;
1028 struct cfg80211_bss *bss;
1030 if (len <= sizeof(struct wmi_bss_info_hdr2))
1033 bih = (struct wmi_bss_info_hdr2 *) datap;
1034 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1035 len -= sizeof(struct wmi_bss_info_hdr2);
1037 ath6kl_dbg(ATH6KL_DBG_WMI,
1038 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1040 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
1043 if (bih->frame_type != BEACON_FTYPE &&
1044 bih->frame_type != PROBERESP_FTYPE)
1045 return 0; /* Only update BSS table for now */
1047 if (bih->frame_type == BEACON_FTYPE &&
1048 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1049 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
1050 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1051 NONE_BSS_FILTER, 0);
1054 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
1055 if (channel == NULL)
1058 if (len < 8 + 2 + 2)
1061 if (bih->frame_type == BEACON_FTYPE &&
1062 test_bit(CONNECTED, &vif->flags) &&
1063 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
1065 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1067 if (tim && tim[1] >= 2) {
1068 vif->assoc_bss_dtim_period = tim[3];
1069 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
1074 * In theory, use of cfg80211_inform_bss() would be more natural here
1075 * since we do not have the full frame. However, at least for now,
1076 * cfg80211 can only distinguish Beacon and Probe Response frames from
1077 * each other when using cfg80211_inform_bss_frame(), so let's build a
1078 * fake IEEE 802.11 header to be able to take benefit of this.
1080 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1084 if (bih->frame_type == BEACON_FTYPE) {
1085 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1086 IEEE80211_STYPE_BEACON);
1087 memset(mgmt->da, 0xff, ETH_ALEN);
1089 struct net_device *dev = vif->ndev;
1091 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1092 IEEE80211_STYPE_PROBE_RESP);
1093 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
1095 mgmt->duration = cpu_to_le16(0);
1096 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1097 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1098 mgmt->seq_ctrl = cpu_to_le16(0);
1100 memcpy(&mgmt->u.beacon, buf, len);
1102 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
1103 24 + len, (bih->snr - 95) * 100,
1108 cfg80211_put_bss(bss);
1111 * Firmware doesn't return any event when scheduled scan has
1112 * finished, so we need to use a timer to find out when there are
1115 * The timer is started from the first bss info received, otherwise
1116 * the timer would not ever fire if the scan interval is short
1119 if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
1120 !timer_pending(&vif->sched_scan_timer)) {
1121 mod_timer(&vif->sched_scan_timer, jiffies +
1122 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1128 /* Inactivity timeout of a fatpipe(pstream) at the target */
1129 static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1132 struct wmi_pstream_timeout_event *ev;
1134 if (len < sizeof(struct wmi_pstream_timeout_event))
1137 ev = (struct wmi_pstream_timeout_event *) datap;
1140 * When the pstream (fat pipe == AC) timesout, it means there were
1141 * no thinStreams within this pstream & it got implicitly created
1142 * due to data flow on this AC. We start the inactivity timer only
1143 * for implicitly created pstream. Just reset the host state.
1145 spin_lock_bh(&wmi->lock);
1146 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1147 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1148 spin_unlock_bh(&wmi->lock);
1150 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1151 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1156 static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1158 struct wmi_bit_rate_reply *reply;
1162 if (len < sizeof(struct wmi_bit_rate_reply))
1165 reply = (struct wmi_bit_rate_reply *) datap;
1167 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1169 if (reply->rate_index == (s8) RATE_AUTO) {
1172 index = reply->rate_index & 0x7f;
1173 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1174 rate = wmi_rate_tbl[index][sgi];
1177 ath6kl_wakeup_event(wmi->parent_dev);
1182 static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
1184 ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
1189 static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1191 if (len < sizeof(struct wmi_fix_rates_reply))
1194 ath6kl_wakeup_event(wmi->parent_dev);
1199 static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1201 if (len < sizeof(struct wmi_channel_list_reply))
1204 ath6kl_wakeup_event(wmi->parent_dev);
1209 static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1211 struct wmi_tx_pwr_reply *reply;
1213 if (len < sizeof(struct wmi_tx_pwr_reply))
1216 reply = (struct wmi_tx_pwr_reply *) datap;
1217 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1222 static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1224 if (len < sizeof(struct wmi_get_keepalive_cmd))
1227 ath6kl_wakeup_event(wmi->parent_dev);
1232 static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1233 struct ath6kl_vif *vif)
1235 struct wmi_scan_complete_event *ev;
1237 ev = (struct wmi_scan_complete_event *) datap;
1239 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
1240 wmi->is_probe_ssid = false;
1245 static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
1246 int len, struct ath6kl_vif *vif)
1248 struct wmi_neighbor_report_event *ev;
1251 if (len < sizeof(*ev))
1253 ev = (struct wmi_neighbor_report_event *) datap;
1254 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1256 ath6kl_dbg(ATH6KL_DBG_WMI,
1257 "truncated neighbor event (num=%d len=%d)\n",
1258 ev->num_neighbors, len);
1261 for (i = 0; i < ev->num_neighbors; i++) {
1262 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1263 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1264 ev->neighbor[i].bss_flags);
1265 cfg80211_pmksa_candidate_notify(vif->ndev, i,
1266 ev->neighbor[i].bssid,
1267 !!(ev->neighbor[i].bss_flags &
1268 WMI_PREAUTH_CAPABLE_BSS),
1276 * Target is reporting a programming error. This is for
1277 * developer aid only. Target only checks a few common violations
1278 * and it is responsibility of host to do all error checking.
1279 * Behavior of target after wmi error event is undefined.
1280 * A reset is recommended.
1282 static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1284 const char *type = "unknown error";
1285 struct wmi_cmd_error_event *ev;
1286 ev = (struct wmi_cmd_error_event *) datap;
1288 switch (ev->err_code) {
1290 type = "invalid parameter";
1293 type = "invalid state";
1295 case INTERNAL_ERROR:
1296 type = "internal error";
1300 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1306 static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1307 struct ath6kl_vif *vif)
1309 ath6kl_tgt_stats_event(vif, datap, len);
1314 static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1315 struct sq_threshold_params *sq_thresh,
1319 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1321 /* The list is already in sorted order. Get the next lower value */
1322 for (index = 0; index < size; index++) {
1323 if (rssi < sq_thresh->upper_threshold[index]) {
1324 threshold = (u8) sq_thresh->upper_threshold[index];
1332 static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1333 struct sq_threshold_params *sq_thresh,
1337 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1339 /* The list is already in sorted order. Get the next lower value */
1340 for (index = 0; index < size; index++) {
1341 if (rssi > sq_thresh->lower_threshold[index]) {
1342 threshold = (u8) sq_thresh->lower_threshold[index];
1350 static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1351 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1353 struct sk_buff *skb;
1354 struct wmi_rssi_threshold_params_cmd *cmd;
1356 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1360 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1361 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1363 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1367 static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1370 struct wmi_rssi_threshold_event *reply;
1371 struct wmi_rssi_threshold_params_cmd cmd;
1372 struct sq_threshold_params *sq_thresh;
1373 enum wmi_rssi_threshold_val new_threshold;
1374 u8 upper_rssi_threshold, lower_rssi_threshold;
1378 if (len < sizeof(struct wmi_rssi_threshold_event))
1381 reply = (struct wmi_rssi_threshold_event *) datap;
1382 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1383 rssi = a_sle16_to_cpu(reply->rssi);
1385 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1388 * Identify the threshold breached and communicate that to the app.
1389 * After that install a new set of thresholds based on the signal
1390 * quality reported by the target
1392 if (new_threshold) {
1393 /* Upper threshold breached */
1394 if (rssi < sq_thresh->upper_threshold[0]) {
1395 ath6kl_dbg(ATH6KL_DBG_WMI,
1396 "spurious upper rssi threshold event: %d\n",
1398 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1399 (rssi >= sq_thresh->upper_threshold[0])) {
1400 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1401 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1402 (rssi >= sq_thresh->upper_threshold[1])) {
1403 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1404 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1405 (rssi >= sq_thresh->upper_threshold[2])) {
1406 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1407 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1408 (rssi >= sq_thresh->upper_threshold[3])) {
1409 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1410 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1411 (rssi >= sq_thresh->upper_threshold[4])) {
1412 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1413 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1414 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1417 /* Lower threshold breached */
1418 if (rssi > sq_thresh->lower_threshold[0]) {
1419 ath6kl_dbg(ATH6KL_DBG_WMI,
1420 "spurious lower rssi threshold event: %d %d\n",
1421 rssi, sq_thresh->lower_threshold[0]);
1422 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1423 (rssi <= sq_thresh->lower_threshold[0])) {
1424 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1425 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1426 (rssi <= sq_thresh->lower_threshold[1])) {
1427 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1428 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1429 (rssi <= sq_thresh->lower_threshold[2])) {
1430 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1431 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1432 (rssi <= sq_thresh->lower_threshold[3])) {
1433 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1434 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1435 (rssi <= sq_thresh->lower_threshold[4])) {
1436 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1437 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1438 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1442 /* Calculate and install the next set of thresholds */
1443 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1444 sq_thresh->lower_threshold_valid_count);
1445 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1446 sq_thresh->upper_threshold_valid_count);
1448 /* Issue a wmi command to install the thresholds */
1449 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1450 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1451 cmd.weight = sq_thresh->weight;
1452 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1454 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1456 ath6kl_err("unable to configure rssi thresholds\n");
1463 static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1464 struct ath6kl_vif *vif)
1466 struct wmi_cac_event *reply;
1467 struct ieee80211_tspec_ie *ts;
1468 u16 active_tsids, tsinfo;
1472 if (len < sizeof(struct wmi_cac_event))
1475 reply = (struct wmi_cac_event *) datap;
1477 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1478 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1480 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1481 tsinfo = le16_to_cpu(ts->tsinfo);
1482 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1483 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1485 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1487 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1489 * Following assumes that there is only one outstanding
1490 * ADDTS request when this event is received
1492 spin_lock_bh(&wmi->lock);
1493 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1494 spin_unlock_bh(&wmi->lock);
1496 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1497 if ((active_tsids >> index) & 1)
1500 if (index < (sizeof(active_tsids) * 8))
1501 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1506 * Clear active tsids and Add missing handling
1507 * for delete qos stream from AP
1509 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1511 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1512 tsinfo = le16_to_cpu(ts->tsinfo);
1513 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1514 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1516 spin_lock_bh(&wmi->lock);
1517 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1518 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1519 spin_unlock_bh(&wmi->lock);
1521 /* Indicate stream inactivity to driver layer only if all tsids
1522 * within this AC are deleted.
1524 if (!active_tsids) {
1525 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1527 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1534 static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
1535 struct ath6kl_vif *vif)
1537 struct wmi_txe_notify_event *ev;
1540 if (len < sizeof(*ev))
1543 if (vif->sme_state != SME_CONNECTED)
1546 ev = (struct wmi_txe_notify_event *) datap;
1547 rate = le32_to_cpu(ev->rate);
1548 pkts = le32_to_cpu(ev->pkts);
1550 ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d% pkts %d intvl %ds\n",
1551 vif->bssid, rate, pkts, vif->txe_intvl);
1553 cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
1554 rate, vif->txe_intvl, GFP_KERNEL);
1559 int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
1560 u32 rate, u32 pkts, u32 intvl)
1562 struct sk_buff *skb;
1563 struct wmi_txe_notify_cmd *cmd;
1565 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1569 cmd = (struct wmi_txe_notify_cmd *) skb->data;
1570 cmd->rate = cpu_to_le32(rate);
1571 cmd->pkts = cpu_to_le32(pkts);
1572 cmd->intvl = cpu_to_le32(intvl);
1574 return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
1578 int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
1580 struct sk_buff *skb;
1581 struct wmi_set_rssi_filter_cmd *cmd;
1584 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1588 cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
1591 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
1596 static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1597 struct wmi_snr_threshold_params_cmd *snr_cmd)
1599 struct sk_buff *skb;
1600 struct wmi_snr_threshold_params_cmd *cmd;
1602 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1606 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1607 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1609 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1613 static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1616 struct wmi_snr_threshold_event *reply;
1617 struct sq_threshold_params *sq_thresh;
1618 struct wmi_snr_threshold_params_cmd cmd;
1619 enum wmi_snr_threshold_val new_threshold;
1620 u8 upper_snr_threshold, lower_snr_threshold;
1624 if (len < sizeof(struct wmi_snr_threshold_event))
1627 reply = (struct wmi_snr_threshold_event *) datap;
1629 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1632 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1635 * Identify the threshold breached and communicate that to the app.
1636 * After that install a new set of thresholds based on the signal
1637 * quality reported by the target.
1639 if (new_threshold) {
1640 /* Upper threshold breached */
1641 if (snr < sq_thresh->upper_threshold[0]) {
1642 ath6kl_dbg(ATH6KL_DBG_WMI,
1643 "spurious upper snr threshold event: %d\n",
1645 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1646 (snr >= sq_thresh->upper_threshold[0])) {
1647 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1648 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1649 (snr >= sq_thresh->upper_threshold[1])) {
1650 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1651 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1652 (snr >= sq_thresh->upper_threshold[2])) {
1653 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1654 } else if (snr >= sq_thresh->upper_threshold[3]) {
1655 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1658 /* Lower threshold breached */
1659 if (snr > sq_thresh->lower_threshold[0]) {
1660 ath6kl_dbg(ATH6KL_DBG_WMI,
1661 "spurious lower snr threshold event: %d\n",
1662 sq_thresh->lower_threshold[0]);
1663 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1664 (snr <= sq_thresh->lower_threshold[0])) {
1665 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1666 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1667 (snr <= sq_thresh->lower_threshold[1])) {
1668 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1669 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1670 (snr <= sq_thresh->lower_threshold[2])) {
1671 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1672 } else if (snr <= sq_thresh->lower_threshold[3]) {
1673 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1677 /* Calculate and install the next set of thresholds */
1678 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1679 sq_thresh->lower_threshold_valid_count);
1680 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1681 sq_thresh->upper_threshold_valid_count);
1683 /* Issue a wmi command to install the thresholds */
1684 cmd.thresh_above1_val = upper_snr_threshold;
1685 cmd.thresh_below1_val = lower_snr_threshold;
1686 cmd.weight = sq_thresh->weight;
1687 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1689 ath6kl_dbg(ATH6KL_DBG_WMI,
1690 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1692 lower_snr_threshold, upper_snr_threshold);
1694 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1696 ath6kl_err("unable to configure snr threshold\n");
1703 static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1705 u16 ap_info_entry_size;
1706 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1707 struct wmi_ap_info_v1 *ap_info_v1;
1710 if (len < sizeof(struct wmi_aplist_event) ||
1711 ev->ap_list_ver != APLIST_VER1)
1714 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1715 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1717 ath6kl_dbg(ATH6KL_DBG_WMI,
1718 "number of APs in aplist event: %d\n", ev->num_ap);
1720 if (len < (int) (sizeof(struct wmi_aplist_event) +
1721 (ev->num_ap - 1) * ap_info_entry_size))
1724 /* AP list version 1 contents */
1725 for (index = 0; index < ev->num_ap; index++) {
1726 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1727 index, ap_info_v1->bssid, ap_info_v1->channel);
1734 int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
1735 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1737 struct wmi_cmd_hdr *cmd_hdr;
1738 enum htc_endpoint_id ep_id = wmi->ep_id;
1742 if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1))))
1745 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1746 cmd_id, skb->len, sync_flag);
1747 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1748 skb->data, skb->len);
1750 if (sync_flag >= END_WMIFLAG) {
1755 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1756 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1758 * Make sure all data currently queued is transmitted before
1759 * the cmd execution. Establish a new sync point.
1761 ath6kl_wmi_sync_point(wmi, if_idx);
1764 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1766 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1767 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1768 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1769 cmd_hdr->info1 = cpu_to_le16(info1);
1771 /* Only for OPT_TX_CMD, use BE endpoint. */
1772 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1773 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1774 false, false, 0, NULL, if_idx);
1779 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1782 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1784 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1785 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1787 * Make sure all new data queued waits for the command to
1788 * execute. Establish a new sync point.
1790 ath6kl_wmi_sync_point(wmi, if_idx);
1796 int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1797 enum network_type nw_type,
1798 enum dot11_auth_mode dot11_auth_mode,
1799 enum auth_mode auth_mode,
1800 enum crypto_type pairwise_crypto,
1801 u8 pairwise_crypto_len,
1802 enum crypto_type group_crypto,
1803 u8 group_crypto_len, int ssid_len, u8 *ssid,
1804 u8 *bssid, u16 channel, u32 ctrl_flags,
1807 struct sk_buff *skb;
1808 struct wmi_connect_cmd *cc;
1811 ath6kl_dbg(ATH6KL_DBG_WMI,
1812 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1813 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1814 bssid, channel, ctrl_flags, ssid_len, nw_type,
1815 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1816 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1818 wmi->traffic_class = 100;
1820 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1823 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1826 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1830 cc = (struct wmi_connect_cmd *) skb->data;
1833 memcpy(cc->ssid, ssid, ssid_len);
1835 cc->ssid_len = ssid_len;
1836 cc->nw_type = nw_type;
1837 cc->dot11_auth_mode = dot11_auth_mode;
1838 cc->auth_mode = auth_mode;
1839 cc->prwise_crypto_type = pairwise_crypto;
1840 cc->prwise_crypto_len = pairwise_crypto_len;
1841 cc->grp_crypto_type = group_crypto;
1842 cc->grp_crypto_len = group_crypto_len;
1843 cc->ch = cpu_to_le16(channel);
1844 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1845 cc->nw_subtype = nw_subtype;
1848 memcpy(cc->bssid, bssid, ETH_ALEN);
1850 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1856 int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1859 struct sk_buff *skb;
1860 struct wmi_reconnect_cmd *cc;
1863 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1866 wmi->traffic_class = 100;
1868 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1872 cc = (struct wmi_reconnect_cmd *) skb->data;
1873 cc->channel = cpu_to_le16(channel);
1876 memcpy(cc->bssid, bssid, ETH_ALEN);
1878 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
1884 int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
1888 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1890 wmi->traffic_class = 100;
1892 /* Disconnect command does not need to do a SYNC before. */
1893 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
1898 /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1899 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1900 * mgmt operations using station interface.
1902 static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1903 enum wmi_scan_type scan_type,
1904 u32 force_fgscan, u32 is_legacy,
1905 u32 home_dwell_time,
1906 u32 force_scan_interval,
1907 s8 num_chan, u16 *ch_list)
1909 struct sk_buff *skb;
1910 struct wmi_start_scan_cmd *sc;
1914 size = sizeof(struct wmi_start_scan_cmd);
1916 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1919 if (num_chan > WMI_MAX_CHANNELS)
1923 size += sizeof(u16) * (num_chan - 1);
1925 skb = ath6kl_wmi_get_new_buf(size);
1929 sc = (struct wmi_start_scan_cmd *) skb->data;
1930 sc->scan_type = scan_type;
1931 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1932 sc->is_legacy = cpu_to_le32(is_legacy);
1933 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1934 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1935 sc->num_ch = num_chan;
1937 for (i = 0; i < num_chan; i++)
1938 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1940 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
1947 * beginscan supports (compared to old startscan) P2P mgmt operations using
1948 * station interface, send additional information like supported rates to
1949 * advertise and xmit rates for probe requests
1951 int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
1952 enum wmi_scan_type scan_type,
1953 u32 force_fgscan, u32 is_legacy,
1954 u32 home_dwell_time, u32 force_scan_interval,
1955 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
1957 struct ieee80211_supported_band *sband;
1958 struct sk_buff *skb;
1959 struct wmi_begin_scan_cmd *sc;
1960 s8 size, *supp_rates;
1962 struct ath6kl *ar = wmi->parent_dev;
1966 if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
1967 ar->fw_capabilities)) {
1968 return ath6kl_wmi_startscan_cmd(wmi, if_idx,
1969 scan_type, force_fgscan,
1970 is_legacy, home_dwell_time,
1971 force_scan_interval,
1975 size = sizeof(struct wmi_begin_scan_cmd);
1977 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1980 if (num_chan > WMI_MAX_CHANNELS)
1984 size += sizeof(u16) * (num_chan - 1);
1986 skb = ath6kl_wmi_get_new_buf(size);
1990 sc = (struct wmi_begin_scan_cmd *) skb->data;
1991 sc->scan_type = scan_type;
1992 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1993 sc->is_legacy = cpu_to_le32(is_legacy);
1994 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1995 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1996 sc->no_cck = cpu_to_le32(no_cck);
1997 sc->num_ch = num_chan;
1999 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2000 sband = ar->wiphy->bands[band];
2005 ratemask = rates[band];
2006 supp_rates = sc->supp_rates[band].rates;
2009 for (i = 0; i < sband->n_bitrates; i++) {
2010 if ((BIT(i) & ratemask) == 0)
2011 continue; /* skip rate */
2012 supp_rates[num_rates++] =
2013 (u8) (sband->bitrates[i].bitrate / 5);
2015 sc->supp_rates[band].nrates = num_rates;
2018 for (i = 0; i < num_chan; i++)
2019 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
2021 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
2027 int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
2029 u16 fg_end_sec, u16 bg_sec,
2030 u16 minact_chdw_msec, u16 maxact_chdw_msec,
2031 u16 pas_chdw_msec, u8 short_scan_ratio,
2032 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
2033 u16 maxact_scan_per_ssid)
2035 struct sk_buff *skb;
2036 struct wmi_scan_params_cmd *sc;
2039 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2043 sc = (struct wmi_scan_params_cmd *) skb->data;
2044 sc->fg_start_period = cpu_to_le16(fg_start_sec);
2045 sc->fg_end_period = cpu_to_le16(fg_end_sec);
2046 sc->bg_period = cpu_to_le16(bg_sec);
2047 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
2048 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
2049 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
2050 sc->short_scan_ratio = short_scan_ratio;
2051 sc->scan_ctrl_flags = scan_ctrl_flag;
2052 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
2053 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
2055 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
2060 int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
2062 struct sk_buff *skb;
2063 struct wmi_bss_filter_cmd *cmd;
2066 if (filter >= LAST_BSS_FILTER)
2069 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2073 cmd = (struct wmi_bss_filter_cmd *) skb->data;
2074 cmd->bss_filter = filter;
2075 cmd->ie_mask = cpu_to_le32(ie_mask);
2077 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
2082 int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
2083 u8 ssid_len, u8 *ssid)
2085 struct sk_buff *skb;
2086 struct wmi_probed_ssid_cmd *cmd;
2089 if (index >= MAX_PROBED_SSIDS)
2092 if (ssid_len > sizeof(cmd->ssid))
2095 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
2098 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
2101 if (flag & SPECIFIC_SSID_FLAG)
2102 wmi->is_probe_ssid = true;
2104 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2108 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2109 cmd->entry_index = index;
2111 cmd->ssid_len = ssid_len;
2112 memcpy(cmd->ssid, ssid, ssid_len);
2114 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
2119 int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2120 u16 listen_interval,
2123 struct sk_buff *skb;
2124 struct wmi_listen_int_cmd *cmd;
2127 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2131 cmd = (struct wmi_listen_int_cmd *) skb->data;
2132 cmd->listen_intvl = cpu_to_le16(listen_interval);
2133 cmd->num_beacons = cpu_to_le16(listen_beacons);
2135 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
2140 int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2141 u16 bmiss_time, u16 num_beacons)
2143 struct sk_buff *skb;
2144 struct wmi_bmiss_time_cmd *cmd;
2147 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2151 cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2152 cmd->bmiss_time = cpu_to_le16(bmiss_time);
2153 cmd->num_beacons = cpu_to_le16(num_beacons);
2155 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2160 int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
2162 struct sk_buff *skb;
2163 struct wmi_power_mode_cmd *cmd;
2166 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2170 cmd = (struct wmi_power_mode_cmd *) skb->data;
2171 cmd->pwr_mode = pwr_mode;
2172 wmi->pwr_mode = pwr_mode;
2174 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
2179 int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
2180 u16 ps_poll_num, u16 dtim_policy,
2181 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2182 u16 ps_fail_event_policy)
2184 struct sk_buff *skb;
2185 struct wmi_power_params_cmd *pm;
2188 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2192 pm = (struct wmi_power_params_cmd *)skb->data;
2193 pm->idle_period = cpu_to_le16(idle_period);
2194 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2195 pm->dtim_policy = cpu_to_le16(dtim_policy);
2196 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2197 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2198 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2200 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
2205 int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
2207 struct sk_buff *skb;
2208 struct wmi_disc_timeout_cmd *cmd;
2211 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2215 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2216 cmd->discon_timeout = timeout;
2218 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
2222 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
2227 int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
2228 enum crypto_type key_type,
2229 u8 key_usage, u8 key_len,
2230 u8 *key_rsc, unsigned int key_rsc_len,
2232 u8 key_op_ctrl, u8 *mac_addr,
2233 enum wmi_sync_flag sync_flag)
2235 struct sk_buff *skb;
2236 struct wmi_add_cipher_key_cmd *cmd;
2239 ath6kl_dbg(ATH6KL_DBG_WMI,
2240 "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
2241 key_index, key_type, key_usage, key_len, key_op_ctrl);
2243 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
2244 (key_material == NULL) || key_rsc_len > 8)
2247 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2250 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2254 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2255 cmd->key_index = key_index;
2256 cmd->key_type = key_type;
2257 cmd->key_usage = key_usage;
2258 cmd->key_len = key_len;
2259 memcpy(cmd->key, key_material, key_len);
2261 if (key_rsc != NULL)
2262 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
2264 cmd->key_op_ctrl = key_op_ctrl;
2267 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2269 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
2275 int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
2277 struct sk_buff *skb;
2278 struct wmi_add_krk_cmd *cmd;
2281 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2285 cmd = (struct wmi_add_krk_cmd *) skb->data;
2286 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2288 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
2294 int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
2296 struct sk_buff *skb;
2297 struct wmi_delete_cipher_key_cmd *cmd;
2300 if (key_index > WMI_MAX_KEY_INDEX)
2303 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2307 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2308 cmd->key_index = key_index;
2310 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
2316 int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
2317 const u8 *pmkid, bool set)
2319 struct sk_buff *skb;
2320 struct wmi_setpmkid_cmd *cmd;
2326 if (set && pmkid == NULL)
2329 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2333 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2334 memcpy(cmd->bssid, bssid, ETH_ALEN);
2336 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2337 cmd->enable = PMKID_ENABLE;
2339 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2340 cmd->enable = PMKID_DISABLE;
2343 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
2349 static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2350 enum htc_endpoint_id ep_id, u8 if_idx)
2352 struct wmi_data_hdr *data_hdr;
2355 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2358 skb_push(skb, sizeof(struct wmi_data_hdr));
2360 data_hdr = (struct wmi_data_hdr *) skb->data;
2361 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2362 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
2364 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2369 static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
2371 struct sk_buff *skb;
2372 struct wmi_sync_cmd *cmd;
2373 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2374 enum htc_endpoint_id ep_id;
2375 u8 index, num_pri_streams = 0;
2378 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2380 spin_lock_bh(&wmi->lock);
2382 for (index = 0; index < WMM_NUM_AC; index++) {
2383 if (wmi->fat_pipe_exist & (1 << index)) {
2385 data_sync_bufs[num_pri_streams - 1].traffic_class =
2390 spin_unlock_bh(&wmi->lock);
2392 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2398 cmd = (struct wmi_sync_cmd *) skb->data;
2401 * In the SYNC cmd sent on the control Ep, send a bitmap
2402 * of the data eps on which the Data Sync will be sent
2404 cmd->data_sync_map = wmi->fat_pipe_exist;
2406 for (index = 0; index < num_pri_streams; index++) {
2407 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2408 if (data_sync_bufs[index].skb == NULL) {
2415 * If buffer allocation for any of the dataSync fails,
2416 * then do not send the Synchronize cmd on the control ep
2422 * Send sync cmd followed by sync data messages on all
2423 * endpoints being used
2425 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
2431 /* cmd buffer sent, we no longer own it */
2434 for (index = 0; index < num_pri_streams; index++) {
2436 if (WARN_ON(!data_sync_bufs[index].skb))
2439 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2440 data_sync_bufs[index].
2443 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2449 data_sync_bufs[index].skb = NULL;
2453 /* free up any resources left over (possibly due to an error) */
2457 for (index = 0; index < num_pri_streams; index++) {
2458 if (data_sync_bufs[index].skb != NULL) {
2459 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2467 int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
2468 struct wmi_create_pstream_cmd *params)
2470 struct sk_buff *skb;
2471 struct wmi_create_pstream_cmd *cmd;
2472 u8 fatpipe_exist_for_ac = 0;
2474 s32 nominal_phy = 0;
2477 if (!((params->user_pri < 8) &&
2478 (params->user_pri <= 0x7) &&
2479 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2480 (params->traffic_direc == UPLINK_TRAFFIC ||
2481 params->traffic_direc == DNLINK_TRAFFIC ||
2482 params->traffic_direc == BIDIR_TRAFFIC) &&
2483 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2484 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2485 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2486 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2487 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2488 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2489 params->tsid <= WMI_MAX_THINSTREAM))) {
2494 * Check nominal PHY rate is >= minimalPHY,
2495 * so that DUT can allow TSRS IE
2498 /* Get the physical rate (units of bps) */
2499 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2501 /* Check minimal phy < nominal phy rate */
2502 if (params->nominal_phy >= min_phy) {
2503 /* unit of 500 kbps */
2504 nominal_phy = (params->nominal_phy * 1000) / 500;
2505 ath6kl_dbg(ATH6KL_DBG_WMI,
2506 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2507 min_phy, nominal_phy);
2509 params->nominal_phy = nominal_phy;
2511 params->nominal_phy = 0;
2514 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2518 ath6kl_dbg(ATH6KL_DBG_WMI,
2519 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2520 params->traffic_class, params->tsid);
2522 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2523 memcpy(cmd, params, sizeof(*cmd));
2525 /* This is an implicitly created Fat pipe */
2526 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2527 spin_lock_bh(&wmi->lock);
2528 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2529 (1 << params->traffic_class));
2530 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2531 spin_unlock_bh(&wmi->lock);
2533 /* explicitly created thin stream within a fat pipe */
2534 spin_lock_bh(&wmi->lock);
2535 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2536 (1 << params->traffic_class));
2537 wmi->stream_exist_for_ac[params->traffic_class] |=
2538 (1 << params->tsid);
2540 * If a thinstream becomes active, the fat pipe automatically
2543 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2544 spin_unlock_bh(&wmi->lock);
2548 * Indicate activty change to driver layer only if this is the
2549 * first TSID to get created in this AC explicitly or an implicit
2550 * fat pipe is getting created.
2552 if (!fatpipe_exist_for_ac)
2553 ath6kl_indicate_tx_activity(wmi->parent_dev,
2554 params->traffic_class, true);
2556 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
2561 int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2564 struct sk_buff *skb;
2565 struct wmi_delete_pstream_cmd *cmd;
2566 u16 active_tsids = 0;
2569 if (traffic_class > 3) {
2570 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2574 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2578 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2579 cmd->traffic_class = traffic_class;
2582 spin_lock_bh(&wmi->lock);
2583 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2584 spin_unlock_bh(&wmi->lock);
2586 if (!(active_tsids & (1 << tsid))) {
2588 ath6kl_dbg(ATH6KL_DBG_WMI,
2589 "TSID %d doesn't exist for traffic class: %d\n",
2590 tsid, traffic_class);
2594 ath6kl_dbg(ATH6KL_DBG_WMI,
2595 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2596 traffic_class, tsid);
2598 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
2599 SYNC_BEFORE_WMIFLAG);
2601 spin_lock_bh(&wmi->lock);
2602 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2603 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2604 spin_unlock_bh(&wmi->lock);
2607 * Indicate stream inactivity to driver layer only if all tsids
2608 * within this AC are deleted.
2610 if (!active_tsids) {
2611 ath6kl_indicate_tx_activity(wmi->parent_dev,
2612 traffic_class, false);
2613 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2619 int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2620 __be32 ips0, __be32 ips1)
2622 struct sk_buff *skb;
2623 struct wmi_set_ip_cmd *cmd;
2626 /* Multicast address are not valid */
2627 if (ipv4_is_multicast(ips0) ||
2628 ipv4_is_multicast(ips1))
2631 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2635 cmd = (struct wmi_set_ip_cmd *) skb->data;
2639 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
2644 static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2651 * Relinquish credits from all implicitly created pstreams
2652 * since when we go to sleep. If user created explicit
2653 * thinstreams exists with in a fatpipe leave them intact
2654 * for the user to delete.
2656 spin_lock_bh(&wmi->lock);
2657 stream_exist = wmi->fat_pipe_exist;
2658 spin_unlock_bh(&wmi->lock);
2660 for (i = 0; i < WMM_NUM_AC; i++) {
2661 if (stream_exist & (1 << i)) {
2664 * FIXME: Is this lock & unlock inside
2665 * for loop correct? may need rework.
2667 spin_lock_bh(&wmi->lock);
2668 active_tsids = wmi->stream_exist_for_ac[i];
2669 spin_unlock_bh(&wmi->lock);
2672 * If there are no user created thin streams
2673 * delete the fatpipe
2675 if (!active_tsids) {
2676 stream_exist &= ~(1 << i);
2678 * Indicate inactivity to driver layer for
2679 * this fatpipe (pstream)
2681 ath6kl_indicate_tx_activity(wmi->parent_dev,
2687 /* FIXME: Can we do this assignment without locking ? */
2688 spin_lock_bh(&wmi->lock);
2689 wmi->fat_pipe_exist = stream_exist;
2690 spin_unlock_bh(&wmi->lock);
2693 static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
2694 const struct cfg80211_bitrate_mask *mask)
2696 struct sk_buff *skb;
2697 int ret, mode, band;
2698 u64 mcsrate, ratemask[IEEE80211_NUM_BANDS];
2699 struct wmi_set_tx_select_rates64_cmd *cmd;
2701 memset(&ratemask, 0, sizeof(ratemask));
2702 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2703 /* copy legacy rate mask */
2704 ratemask[band] = mask->control[band].legacy;
2705 if (band == IEEE80211_BAND_5GHZ)
2707 mask->control[band].legacy << 4;
2709 /* copy mcs rate mask */
2710 mcsrate = mask->control[band].mcs[1];
2712 mcsrate |= mask->control[band].mcs[0];
2713 ratemask[band] |= mcsrate << 12;
2714 ratemask[band] |= mcsrate << 28;
2717 ath6kl_dbg(ATH6KL_DBG_WMI,
2718 "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
2719 ratemask[0], ratemask[1]);
2721 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2725 cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
2726 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2727 /* A mode operate in 5GHZ band */
2728 if (mode == WMI_RATES_MODE_11A ||
2729 mode == WMI_RATES_MODE_11A_HT20 ||
2730 mode == WMI_RATES_MODE_11A_HT40)
2731 band = IEEE80211_BAND_5GHZ;
2733 band = IEEE80211_BAND_2GHZ;
2734 cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
2737 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2738 WMI_SET_TX_SELECT_RATES_CMDID,
2743 static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
2744 const struct cfg80211_bitrate_mask *mask)
2746 struct sk_buff *skb;
2747 int ret, mode, band;
2748 u32 mcsrate, ratemask[IEEE80211_NUM_BANDS];
2749 struct wmi_set_tx_select_rates32_cmd *cmd;
2751 memset(&ratemask, 0, sizeof(ratemask));
2752 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2753 /* copy legacy rate mask */
2754 ratemask[band] = mask->control[band].legacy;
2755 if (band == IEEE80211_BAND_5GHZ)
2757 mask->control[band].legacy << 4;
2759 /* copy mcs rate mask */
2760 mcsrate = mask->control[band].mcs[0];
2761 ratemask[band] |= mcsrate << 12;
2762 ratemask[band] |= mcsrate << 20;
2765 ath6kl_dbg(ATH6KL_DBG_WMI,
2766 "Ratemask 32 bit: 2.4:%x 5:%x\n",
2767 ratemask[0], ratemask[1]);
2769 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2773 cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
2774 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2775 /* A mode operate in 5GHZ band */
2776 if (mode == WMI_RATES_MODE_11A ||
2777 mode == WMI_RATES_MODE_11A_HT20 ||
2778 mode == WMI_RATES_MODE_11A_HT40)
2779 band = IEEE80211_BAND_5GHZ;
2781 band = IEEE80211_BAND_2GHZ;
2782 cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
2785 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2786 WMI_SET_TX_SELECT_RATES_CMDID,
2791 int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
2792 const struct cfg80211_bitrate_mask *mask)
2794 struct ath6kl *ar = wmi->parent_dev;
2796 if (ar->hw.flags & ATH6KL_HW_FLAG_64BIT_RATES)
2797 return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
2799 return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
2802 int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2803 enum ath6kl_host_mode host_mode)
2805 struct sk_buff *skb;
2806 struct wmi_set_host_sleep_mode_cmd *cmd;
2809 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2810 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2811 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2815 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2819 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2821 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2822 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2823 cmd->asleep = cpu_to_le32(1);
2825 cmd->awake = cpu_to_le32(1);
2827 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2828 WMI_SET_HOST_SLEEP_MODE_CMDID,
2833 /* This command has zero length payload */
2834 static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2835 struct ath6kl_vif *vif)
2837 struct ath6kl *ar = wmi->parent_dev;
2839 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2840 wake_up(&ar->event_wq);
2845 int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2846 enum ath6kl_wow_mode wow_mode,
2847 u32 filter, u16 host_req_delay)
2849 struct sk_buff *skb;
2850 struct wmi_set_wow_mode_cmd *cmd;
2853 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
2854 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
2855 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2859 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2863 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2864 cmd->enable_wow = cpu_to_le32(wow_mode);
2865 cmd->filter = cpu_to_le32(filter);
2866 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2868 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2873 int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2874 u8 list_id, u8 filter_size,
2875 u8 filter_offset, const u8 *filter,
2878 struct sk_buff *skb;
2879 struct wmi_add_wow_pattern_cmd *cmd;
2885 * Allocate additional memory in the buffer to hold
2886 * filter and mask value, which is twice of filter_size.
2888 size = sizeof(*cmd) + (2 * filter_size);
2890 skb = ath6kl_wmi_get_new_buf(size);
2894 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2895 cmd->filter_list_id = list_id;
2896 cmd->filter_size = filter_size;
2897 cmd->filter_offset = filter_offset;
2899 memcpy(cmd->filter, filter, filter_size);
2901 filter_mask = (u8 *) (cmd->filter + filter_size);
2902 memcpy(filter_mask, mask, filter_size);
2904 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2910 int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2911 u16 list_id, u16 filter_id)
2913 struct sk_buff *skb;
2914 struct wmi_del_wow_pattern_cmd *cmd;
2917 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2921 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
2922 cmd->filter_list_id = cpu_to_le16(list_id);
2923 cmd->filter_id = cpu_to_le16(filter_id);
2925 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
2930 static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2931 enum wmix_command_id cmd_id,
2932 enum wmi_sync_flag sync_flag)
2934 struct wmix_cmd_hdr *cmd_hdr;
2937 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2939 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2940 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2942 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
2947 int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2949 struct sk_buff *skb;
2950 struct wmix_hb_challenge_resp_cmd *cmd;
2953 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2957 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2958 cmd->cookie = cpu_to_le32(cookie);
2959 cmd->source = cpu_to_le32(source);
2961 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2966 int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2968 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2969 struct sk_buff *skb;
2972 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2976 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2977 cmd->valid = cpu_to_le32(valid);
2978 cmd->config = cpu_to_le32(config);
2980 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2985 int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
2987 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
2990 int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
2992 struct sk_buff *skb;
2993 struct wmi_set_tx_pwr_cmd *cmd;
2996 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
3000 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
3003 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
3009 int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
3011 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
3014 int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
3016 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
3019 int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
3022 struct sk_buff *skb;
3023 struct wmi_set_lpreamble_cmd *cmd;
3026 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
3030 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
3031 cmd->status = status;
3032 cmd->preamble_policy = preamble_policy;
3034 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
3039 int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
3041 struct sk_buff *skb;
3042 struct wmi_set_rts_cmd *cmd;
3045 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
3049 cmd = (struct wmi_set_rts_cmd *) skb->data;
3050 cmd->threshold = cpu_to_le16(threshold);
3052 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
3057 int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
3059 struct sk_buff *skb;
3060 struct wmi_set_wmm_txop_cmd *cmd;
3063 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
3066 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
3070 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
3071 cmd->txop_enable = cfg;
3073 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
3078 int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
3079 u8 keep_alive_intvl)
3081 struct sk_buff *skb;
3082 struct wmi_set_keepalive_cmd *cmd;
3085 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3089 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
3090 cmd->keep_alive_intvl = keep_alive_intvl;
3092 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
3096 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
3101 int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
3102 enum ieee80211_band band,
3103 struct ath6kl_htcap *htcap)
3105 struct sk_buff *skb;
3106 struct wmi_set_htcap_cmd *cmd;
3108 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3112 cmd = (struct wmi_set_htcap_cmd *) skb->data;
3115 * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely
3116 * this will be changed in firmware. If at all there is any change in
3117 * band value, the host needs to be fixed.
3120 cmd->ht_enable = !!htcap->ht_enable;
3121 cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
3122 cmd->ht40_supported =
3123 !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
3124 cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
3125 cmd->intolerant_40mhz =
3126 !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
3127 cmd->max_ampdu_len_exp = htcap->ampdu_factor;
3129 ath6kl_dbg(ATH6KL_DBG_WMI,
3130 "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
3131 cmd->band, cmd->ht_enable, cmd->ht40_supported,
3132 cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
3133 cmd->max_ampdu_len_exp);
3134 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
3138 int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
3140 struct sk_buff *skb;
3143 skb = ath6kl_wmi_get_new_buf(len);
3147 memcpy(skb->data, buf, len);
3149 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
3154 int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
3156 struct sk_buff *skb;
3157 struct wmi_mcast_filter_cmd *cmd;
3160 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3164 cmd = (struct wmi_mcast_filter_cmd *) skb->data;
3165 cmd->mcast_all_enable = mc_all_on;
3167 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
3172 int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
3173 u8 *filter, bool add_filter)
3175 struct sk_buff *skb;
3176 struct wmi_mcast_filter_add_del_cmd *cmd;
3179 if ((filter[0] != 0x33 || filter[1] != 0x33) &&
3180 (filter[0] != 0x01 || filter[1] != 0x00 ||
3181 filter[2] != 0x5e || filter[3] > 0x7f)) {
3182 ath6kl_warn("invalid multicast filter address\n");
3186 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3190 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
3191 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
3192 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3193 add_filter ? WMI_SET_MCAST_FILTER_CMDID :
3194 WMI_DEL_MCAST_FILTER_CMDID,
3200 int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
3202 struct sk_buff *skb;
3203 struct wmi_sta_bmiss_enhance_cmd *cmd;
3206 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3210 cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
3211 cmd->enable = enhance ? 1 : 0;
3213 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3214 WMI_STA_BMISS_ENHANCE_CMDID,
3219 int ath6kl_wmi_set_regdomain_cmd(struct wmi *wmi, const char *alpha2)
3221 struct sk_buff *skb;
3222 struct wmi_set_regdomain_cmd *cmd;
3224 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3228 cmd = (struct wmi_set_regdomain_cmd *) skb->data;
3229 memcpy(cmd->iso_name, alpha2, 2);
3231 return ath6kl_wmi_cmd_send(wmi, 0, skb,
3232 WMI_SET_REGDOMAIN_CMDID,
3236 s32 ath6kl_wmi_get_rate(s8 rate_index)
3238 if (rate_index == RATE_AUTO)
3241 return wmi_rate_tbl[(u32) rate_index][0];
3244 static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
3247 struct wmi_pmkid_list_reply *reply;
3250 if (len < sizeof(struct wmi_pmkid_list_reply))
3253 reply = (struct wmi_pmkid_list_reply *)datap;
3254 expected_len = sizeof(reply->num_pmkid) +
3255 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
3257 if (len < expected_len)
3263 static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3264 struct ath6kl_vif *vif)
3266 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
3268 aggr_recv_addba_req_evt(vif, cmd->tid,
3269 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
3274 static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3275 struct ath6kl_vif *vif)
3277 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
3279 aggr_recv_delba_req_evt(vif, cmd->tid);
3284 /* AP mode functions */
3286 int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
3287 struct wmi_connect_cmd *p)
3289 struct sk_buff *skb;
3290 struct wmi_connect_cmd *cm;
3293 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3297 cm = (struct wmi_connect_cmd *) skb->data;
3298 memcpy(cm, p, sizeof(*cm));
3300 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
3302 ath6kl_dbg(ATH6KL_DBG_WMI,
3303 "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
3304 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
3305 le32_to_cpu(p->ctrl_flags), res);
3309 int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3312 struct sk_buff *skb;
3313 struct wmi_ap_set_mlme_cmd *cm;
3315 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3319 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
3320 memcpy(cm->mac, mac, ETH_ALEN);
3321 cm->reason = cpu_to_le16(reason);
3324 ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
3327 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
3331 int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
3333 struct sk_buff *skb;
3334 struct wmi_ap_hidden_ssid_cmd *cmd;
3336 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3340 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
3341 cmd->hidden_ssid = enable ? 1 : 0;
3343 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
3347 /* This command will be used to enable/disable AP uAPSD feature */
3348 int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3350 struct wmi_ap_set_apsd_cmd *cmd;
3351 struct sk_buff *skb;
3353 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3357 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3358 cmd->enable = enable;
3360 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3364 int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3365 u16 aid, u16 bitmap, u32 flags)
3367 struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3368 struct sk_buff *skb;
3370 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3374 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3375 cmd->aid = cpu_to_le16(aid);
3376 cmd->bitmap = cpu_to_le16(bitmap);
3377 cmd->flags = cpu_to_le32(flags);
3379 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3380 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3384 static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3385 struct ath6kl_vif *vif)
3387 struct wmi_pspoll_event *ev;
3389 if (len < sizeof(struct wmi_pspoll_event))
3392 ev = (struct wmi_pspoll_event *) datap;
3394 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
3399 static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3400 struct ath6kl_vif *vif)
3402 ath6kl_dtimexpiry_event(vif);
3407 int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3410 struct sk_buff *skb;
3411 struct wmi_ap_set_pvb_cmd *cmd;
3414 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3418 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3419 cmd->aid = cpu_to_le16(aid);
3420 cmd->rsvd = cpu_to_le16(0);
3421 cmd->flag = cpu_to_le32(flag);
3423 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
3429 int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
3431 bool rx_dot11_hdr, bool defrag_on_host)
3433 struct sk_buff *skb;
3434 struct wmi_rx_frame_format_cmd *cmd;
3437 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3441 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3442 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3443 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3444 cmd->meta_ver = rx_meta_ver;
3446 /* Delete the local aggr state, on host */
3447 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
3453 int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3454 const u8 *ie, u8 ie_len)
3456 struct sk_buff *skb;
3457 struct wmi_set_appie_cmd *p;
3459 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3463 ath6kl_dbg(ATH6KL_DBG_WMI,
3464 "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
3465 mgmt_frm_type, ie_len);
3466 p = (struct wmi_set_appie_cmd *) skb->data;
3467 p->mgmt_frm_type = mgmt_frm_type;
3470 if (ie != NULL && ie_len > 0)
3471 memcpy(p->ie_info, ie, ie_len);
3473 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
3477 int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
3478 const u8 *ie_info, u8 ie_len)
3480 struct sk_buff *skb;
3481 struct wmi_set_ie_cmd *p;
3483 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3487 ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
3488 ie_id, ie_field, ie_len);
3489 p = (struct wmi_set_ie_cmd *) skb->data;
3491 p->ie_field = ie_field;
3493 if (ie_info && ie_len > 0)
3494 memcpy(p->ie_info, ie_info, ie_len);
3496 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
3500 int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
3502 struct sk_buff *skb;
3503 struct wmi_disable_11b_rates_cmd *cmd;
3505 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3509 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
3511 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
3512 cmd->disable = disable ? 1 : 0;
3514 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
3518 int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
3520 struct sk_buff *skb;
3521 struct wmi_remain_on_chnl_cmd *p;
3523 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3527 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3529 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3530 p->freq = cpu_to_le32(freq);
3531 p->duration = cpu_to_le32(dur);
3532 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
3536 /* ath6kl_wmi_send_action_cmd is to be deprecated. Use
3537 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
3538 * mgmt operations using station interface.
3540 static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3541 u32 freq, u32 wait, const u8 *data,
3544 struct sk_buff *skb;
3545 struct wmi_send_action_cmd *p;
3549 return -EINVAL; /* Offload for wait not supported */
3551 buf = kmalloc(data_len, GFP_KERNEL);
3555 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3561 kfree(wmi->last_mgmt_tx_frame);
3562 memcpy(buf, data, data_len);
3563 wmi->last_mgmt_tx_frame = buf;
3564 wmi->last_mgmt_tx_frame_len = data_len;
3566 ath6kl_dbg(ATH6KL_DBG_WMI,
3567 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3568 id, freq, wait, data_len);
3569 p = (struct wmi_send_action_cmd *) skb->data;
3570 p->id = cpu_to_le32(id);
3571 p->freq = cpu_to_le32(freq);
3572 p->wait = cpu_to_le32(wait);
3573 p->len = cpu_to_le16(data_len);
3574 memcpy(p->data, data, data_len);
3575 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
3579 static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3580 u32 freq, u32 wait, const u8 *data,
3581 u16 data_len, u32 no_cck)
3583 struct sk_buff *skb;
3584 struct wmi_send_mgmt_cmd *p;
3588 return -EINVAL; /* Offload for wait not supported */
3590 buf = kmalloc(data_len, GFP_KERNEL);
3594 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3600 kfree(wmi->last_mgmt_tx_frame);
3601 memcpy(buf, data, data_len);
3602 wmi->last_mgmt_tx_frame = buf;
3603 wmi->last_mgmt_tx_frame_len = data_len;
3605 ath6kl_dbg(ATH6KL_DBG_WMI,
3606 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3607 id, freq, wait, data_len);
3608 p = (struct wmi_send_mgmt_cmd *) skb->data;
3609 p->id = cpu_to_le32(id);
3610 p->freq = cpu_to_le32(freq);
3611 p->wait = cpu_to_le32(wait);
3612 p->no_cck = cpu_to_le32(no_cck);
3613 p->len = cpu_to_le16(data_len);
3614 memcpy(p->data, data, data_len);
3615 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
3619 int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3620 u32 wait, const u8 *data, u16 data_len,
3624 struct ath6kl *ar = wmi->parent_dev;
3626 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3627 ar->fw_capabilities)) {
3629 * If capable of doing P2P mgmt operations using
3630 * station interface, send additional information like
3631 * supported rates to advertise and xmit rates for
3634 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3635 wait, data, data_len,
3638 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3639 wait, data, data_len);
3645 int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3646 const u8 *dst, const u8 *data,
3649 struct sk_buff *skb;
3650 struct wmi_p2p_probe_response_cmd *p;
3651 size_t cmd_len = sizeof(*p) + data_len;
3654 cmd_len++; /* work around target minimum length requirement */
3656 skb = ath6kl_wmi_get_new_buf(cmd_len);
3660 ath6kl_dbg(ATH6KL_DBG_WMI,
3661 "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
3662 freq, dst, data_len);
3663 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3664 p->freq = cpu_to_le32(freq);
3665 memcpy(p->destination_addr, dst, ETH_ALEN);
3666 p->len = cpu_to_le16(data_len);
3667 memcpy(p->data, data, data_len);
3668 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3669 WMI_SEND_PROBE_RESPONSE_CMDID,
3673 int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
3675 struct sk_buff *skb;
3676 struct wmi_probe_req_report_cmd *p;
3678 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3682 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3684 p = (struct wmi_probe_req_report_cmd *) skb->data;
3685 p->enable = enable ? 1 : 0;
3686 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
3690 int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
3692 struct sk_buff *skb;
3693 struct wmi_get_p2p_info *p;
3695 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3699 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3701 p = (struct wmi_get_p2p_info *) skb->data;
3702 p->info_req_flags = cpu_to_le32(info_req_flags);
3703 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
3707 int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
3709 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
3710 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3711 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
3714 int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
3716 struct sk_buff *skb;
3717 struct wmi_set_inact_period_cmd *cmd;
3719 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3723 cmd = (struct wmi_set_inact_period_cmd *) skb->data;
3724 cmd->inact_period = cpu_to_le32(inact_timeout);
3725 cmd->num_null_func = 0;
3727 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
3731 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3733 struct wmix_cmd_hdr *cmd;
3739 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3740 ath6kl_err("bad packet 1\n");
3744 cmd = (struct wmix_cmd_hdr *) skb->data;
3745 id = le32_to_cpu(cmd->cmd_id);
3747 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3753 case WMIX_HB_CHALLENGE_RESP_EVENTID:
3754 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
3756 case WMIX_DBGLOG_EVENTID:
3757 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
3758 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
3761 ath6kl_warn("unknown cmd id 0x%x\n", id);
3769 static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3771 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3774 /* Process interface specific wmi events, caller would free the datap */
3775 static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
3778 struct ath6kl_vif *vif;
3780 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3782 ath6kl_dbg(ATH6KL_DBG_WMI,
3783 "Wmi event for unavailable vif, vif_index:%d\n",
3789 case WMI_CONNECT_EVENTID:
3790 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3791 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3792 case WMI_DISCONNECT_EVENTID:
3793 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3794 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3795 case WMI_TKIP_MICERR_EVENTID:
3796 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3797 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3798 case WMI_BSSINFO_EVENTID:
3799 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3800 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3801 case WMI_NEIGHBOR_REPORT_EVENTID:
3802 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3803 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3805 case WMI_SCAN_COMPLETE_EVENTID:
3806 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3807 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3808 case WMI_REPORT_STATISTICS_EVENTID:
3809 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3810 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3811 case WMI_CAC_EVENTID:
3812 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3813 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3814 case WMI_PSPOLL_EVENTID:
3815 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3816 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3817 case WMI_DTIMEXPIRY_EVENTID:
3818 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3819 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3820 case WMI_ADDBA_REQ_EVENTID:
3821 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3822 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3823 case WMI_DELBA_REQ_EVENTID:
3824 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3825 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3826 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
3827 ath6kl_dbg(ATH6KL_DBG_WMI,
3828 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
3829 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
3830 case WMI_REMAIN_ON_CHNL_EVENTID:
3831 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3832 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3833 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3834 ath6kl_dbg(ATH6KL_DBG_WMI,
3835 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3836 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3838 case WMI_TX_STATUS_EVENTID:
3839 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3840 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3841 case WMI_RX_PROBE_REQ_EVENTID:
3842 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3843 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3844 case WMI_RX_ACTION_EVENTID:
3845 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3846 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
3847 case WMI_TXE_NOTIFY_EVENTID:
3848 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
3849 return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
3851 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
3858 static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
3860 struct wmi_cmd_hdr *cmd;
3867 cmd = (struct wmi_cmd_hdr *) skb->data;
3868 id = le16_to_cpu(cmd->cmd_id);
3869 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
3871 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3875 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3876 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3880 case WMI_GET_BITRATE_CMDID:
3881 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3882 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3884 case WMI_GET_CHANNEL_LIST_CMDID:
3885 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3886 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3888 case WMI_GET_TX_PWR_CMDID:
3889 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3890 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3892 case WMI_READY_EVENTID:
3893 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3894 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3896 case WMI_PEER_NODE_EVENTID:
3897 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3898 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3900 case WMI_REGDOMAIN_EVENTID:
3901 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
3902 ath6kl_wmi_regdomain_event(wmi, datap, len);
3904 case WMI_PSTREAM_TIMEOUT_EVENTID:
3905 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3906 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3908 case WMI_CMDERROR_EVENTID:
3909 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3910 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3912 case WMI_RSSI_THRESHOLD_EVENTID:
3913 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3914 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3916 case WMI_ERROR_REPORT_EVENTID:
3917 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3919 case WMI_OPT_RX_FRAME_EVENTID:
3920 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
3921 /* this event has been deprecated */
3923 case WMI_REPORT_ROAM_TBL_EVENTID:
3924 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
3925 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
3927 case WMI_EXTENSION_EVENTID:
3928 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3929 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3931 case WMI_CHANNEL_CHANGE_EVENTID:
3932 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3934 case WMI_REPORT_ROAM_DATA_EVENTID:
3935 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3937 case WMI_TEST_EVENTID:
3938 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
3939 ret = ath6kl_wmi_test_rx(wmi, datap, len);
3941 case WMI_GET_FIXRATES_CMDID:
3942 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3943 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3945 case WMI_TX_RETRY_ERR_EVENTID:
3946 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3948 case WMI_SNR_THRESHOLD_EVENTID:
3949 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3950 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3952 case WMI_LQ_THRESHOLD_EVENTID:
3953 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3955 case WMI_APLIST_EVENTID:
3956 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3957 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3959 case WMI_GET_KEEPALIVE_CMDID:
3960 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3961 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3963 case WMI_GET_WOW_LIST_EVENTID:
3964 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
3966 case WMI_GET_PMKID_LIST_EVENTID:
3967 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3968 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3970 case WMI_SET_PARAMS_REPLY_EVENTID:
3971 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3973 case WMI_ADDBA_RESP_EVENTID:
3974 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3976 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3977 ath6kl_dbg(ATH6KL_DBG_WMI,
3978 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3980 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3981 ath6kl_dbg(ATH6KL_DBG_WMI,
3982 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3984 case WMI_TX_COMPLETE_EVENTID:
3985 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3986 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3988 case WMI_P2P_CAPABILITIES_EVENTID:
3989 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3990 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3992 case WMI_P2P_INFO_EVENTID:
3993 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3994 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3997 /* may be the event is interface specific */
3998 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
4007 int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
4009 if (WARN_ON(skb == NULL))
4012 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
4013 ath6kl_err("bad packet 1\n");
4018 return ath6kl_wmi_proc_events(wmi, skb);
4021 void ath6kl_wmi_reset(struct wmi *wmi)
4023 spin_lock_bh(&wmi->lock);
4025 wmi->fat_pipe_exist = 0;
4026 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
4028 spin_unlock_bh(&wmi->lock);
4031 void *ath6kl_wmi_init(struct ath6kl *dev)
4035 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
4039 spin_lock_init(&wmi->lock);
4041 wmi->parent_dev = dev;
4043 wmi->pwr_mode = REC_POWER;
4045 ath6kl_wmi_reset(wmi);
4050 void ath6kl_wmi_shutdown(struct wmi *wmi)
4055 kfree(wmi->last_mgmt_tx_frame);