2 * Copyright (c) 2004-2011 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "../regd_common.h"
24 static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
26 static const s32 wmi_rate_tbl[][2] = {
27 /* {W/O SGI, with SGI} */
59 /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
60 static const u8 up_to_ac[] = {
71 void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
73 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
79 enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
84 struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
86 struct ath6kl_vif *vif, *found = NULL;
88 if (WARN_ON(if_idx > (ar->vif_max - 1)))
92 spin_lock_bh(&ar->list_lock);
93 list_for_each_entry(vif, &ar->vif_list, list) {
94 if (vif->fw_vif_idx == if_idx) {
99 spin_unlock_bh(&ar->list_lock);
104 /* Performs DIX to 802.3 encapsulation for transmit packets.
105 * Assumes the entire DIX header is contigous and that there is
106 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
108 int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
110 struct ath6kl_llc_snap_hdr *llc_hdr;
111 struct ethhdr *eth_hdr;
117 if (WARN_ON(skb == NULL))
120 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
121 if (skb_headroom(skb) < size)
124 eth_hdr = (struct ethhdr *) skb->data;
125 type = eth_hdr->h_proto;
127 if (!is_ethertype(be16_to_cpu(type))) {
128 ath6kl_dbg(ATH6KL_DBG_WMI,
129 "%s: pkt is already in 802.3 format\n", __func__);
133 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
135 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
138 eth_hdr->h_proto = cpu_to_be16(new_len);
140 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
142 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
143 llc_hdr->dsap = 0xAA;
144 llc_hdr->ssap = 0xAA;
145 llc_hdr->cntl = 0x03;
146 llc_hdr->org_code[0] = 0x0;
147 llc_hdr->org_code[1] = 0x0;
148 llc_hdr->org_code[2] = 0x0;
149 llc_hdr->eth_type = type;
154 static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
155 u8 *version, void *tx_meta_info)
157 struct wmi_tx_meta_v1 *v1;
158 struct wmi_tx_meta_v2 *v2;
160 if (WARN_ON(skb == NULL || version == NULL))
164 case WMI_META_VERSION_1:
165 skb_push(skb, WMI_MAX_TX_META_SZ);
166 v1 = (struct wmi_tx_meta_v1 *) skb->data;
168 v1->rate_plcy_id = 0;
169 *version = WMI_META_VERSION_1;
171 case WMI_META_VERSION_2:
172 skb_push(skb, WMI_MAX_TX_META_SZ);
173 v2 = (struct wmi_tx_meta_v2 *) skb->data;
174 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
175 sizeof(struct wmi_tx_meta_v2));
182 int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
183 u8 msg_type, bool more_data,
184 enum wmi_data_hdr_data_type data_type,
185 u8 meta_ver, void *tx_meta_info, u8 if_idx)
187 struct wmi_data_hdr *data_hdr;
190 if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
194 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
199 skb_push(skb, sizeof(struct wmi_data_hdr));
201 data_hdr = (struct wmi_data_hdr *)skb->data;
202 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
204 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
205 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
209 WMI_DATA_HDR_MORE_MASK << WMI_DATA_HDR_MORE_SHIFT;
211 data_hdr->info2 = cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
212 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
217 static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
219 struct iphdr *ip_hdr = (struct iphdr *) pkt;
223 * Determine IPTOS priority
226 * : DSCP(6-bits) ECN(2-bits)
227 * : DSCP - P2 P1 P0 X X X
228 * where (P2 P1 P0) form 802.1D
230 ip_pri = ip_hdr->tos >> 5;
233 if ((layer2_pri & 0x7) > ip_pri)
234 return (u8) layer2_pri & 0x7;
239 int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
241 u32 layer2_priority, bool wmm_enabled,
244 struct wmi_data_hdr *data_hdr;
245 struct ath6kl_llc_snap_hdr *llc_hdr;
246 struct wmi_create_pstream_cmd cmd;
247 u32 meta_size, hdr_size;
248 u16 ip_type = IP_ETHERTYPE;
249 u8 stream_exist, usr_pri;
250 u8 traffic_class = WMM_AC_BE;
253 if (WARN_ON(skb == NULL))
257 data_hdr = (struct wmi_data_hdr *) datap;
259 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
260 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
263 /* If WMM is disabled all traffic goes as BE traffic */
266 hdr_size = sizeof(struct ethhdr);
268 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
271 meta_size + hdr_size);
273 if (llc_hdr->eth_type == htons(ip_type)) {
275 * Extract the endpoint info from the TOS field
279 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
280 sizeof(struct ath6kl_llc_snap_hdr),
283 usr_pri = layer2_priority & 0x7;
287 * workaround for WMM S5
289 * FIXME: wmi->traffic_class is always 100 so this test doesn't
292 if ((wmi->traffic_class == WMM_AC_VI) &&
293 ((usr_pri == 5) || (usr_pri == 4)))
296 /* Convert user priority to traffic class */
297 traffic_class = up_to_ac[usr_pri & 0x7];
299 wmi_data_hdr_set_up(data_hdr, usr_pri);
301 spin_lock_bh(&wmi->lock);
302 stream_exist = wmi->fat_pipe_exist;
303 spin_unlock_bh(&wmi->lock);
305 if (!(stream_exist & (1 << traffic_class))) {
306 memset(&cmd, 0, sizeof(cmd));
307 cmd.traffic_class = traffic_class;
308 cmd.user_pri = usr_pri;
310 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
311 /* Implicit streams are created with TSID 0xFF */
312 cmd.tsid = WMI_IMPLICIT_PSTREAM;
313 ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
321 int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
323 struct ieee80211_hdr_3addr *pwh, wh;
324 struct ath6kl_llc_snap_hdr *llc_hdr;
325 struct ethhdr eth_hdr;
330 if (WARN_ON(skb == NULL))
334 pwh = (struct ieee80211_hdr_3addr *) datap;
336 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
338 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
340 /* Strip off the 802.11 header */
341 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
342 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
344 skb_pull(skb, hdr_size);
345 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
346 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
349 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
351 memset(ð_hdr, 0, sizeof(eth_hdr));
352 eth_hdr.h_proto = llc_hdr->eth_type;
354 switch ((le16_to_cpu(wh.frame_control)) &
355 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
357 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
358 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
360 case IEEE80211_FCTL_TODS:
361 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
362 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
364 case IEEE80211_FCTL_FROMDS:
365 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
366 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
368 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
372 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
373 skb_push(skb, sizeof(eth_hdr));
377 memcpy(datap, ð_hdr, sizeof(eth_hdr));
383 * Performs 802.3 to DIX encapsulation for received packets.
384 * Assumes the entire 802.3 header is contigous.
386 int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
388 struct ath6kl_llc_snap_hdr *llc_hdr;
389 struct ethhdr eth_hdr;
392 if (WARN_ON(skb == NULL))
397 memcpy(ð_hdr, datap, sizeof(eth_hdr));
399 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
400 eth_hdr.h_proto = llc_hdr->eth_type;
402 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
405 memcpy(datap, ð_hdr, sizeof(eth_hdr));
410 static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
412 struct tx_complete_msg_v1 *msg_v1;
413 struct wmi_tx_complete_event *evt;
417 evt = (struct wmi_tx_complete_event *) datap;
419 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
420 evt->num_msg, evt->msg_len, evt->msg_type);
422 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
425 for (index = 0; index < evt->num_msg; index++) {
426 size = sizeof(struct wmi_tx_complete_event) +
427 (index * sizeof(struct tx_complete_msg_v1));
428 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
430 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
431 msg_v1->status, msg_v1->pkt_id,
432 msg_v1->rate_idx, msg_v1->ack_failures);
438 static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
439 int len, struct ath6kl_vif *vif)
441 struct wmi_remain_on_chnl_event *ev;
444 struct ieee80211_channel *chan;
445 struct ath6kl *ar = wmi->parent_dev;
448 if (len < sizeof(*ev))
451 ev = (struct wmi_remain_on_chnl_event *) datap;
452 freq = le32_to_cpu(ev->freq);
453 dur = le32_to_cpu(ev->duration);
454 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
456 chan = ieee80211_get_channel(ar->wiphy, freq);
458 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
459 "(freq=%u)\n", freq);
462 id = vif->last_roc_id;
463 cfg80211_ready_on_channel(vif->ndev, id, chan, NL80211_CHAN_NO_HT,
469 static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
471 struct ath6kl_vif *vif)
473 struct wmi_cancel_remain_on_chnl_event *ev;
476 struct ieee80211_channel *chan;
477 struct ath6kl *ar = wmi->parent_dev;
480 if (len < sizeof(*ev))
483 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
484 freq = le32_to_cpu(ev->freq);
485 dur = le32_to_cpu(ev->duration);
486 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
487 "status=%u\n", freq, dur, ev->status);
488 chan = ieee80211_get_channel(ar->wiphy, freq);
490 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
491 "channel (freq=%u)\n", freq);
494 if (vif->last_cancel_roc_id &&
495 vif->last_cancel_roc_id + 1 == vif->last_roc_id)
496 id = vif->last_cancel_roc_id; /* event for cancel command */
498 id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
499 vif->last_cancel_roc_id = 0;
500 cfg80211_remain_on_channel_expired(vif->ndev, id, chan,
501 NL80211_CHAN_NO_HT, GFP_ATOMIC);
506 static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
507 struct ath6kl_vif *vif)
509 struct wmi_tx_status_event *ev;
512 if (len < sizeof(*ev))
515 ev = (struct wmi_tx_status_event *) datap;
516 id = le32_to_cpu(ev->id);
517 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
519 if (wmi->last_mgmt_tx_frame) {
520 cfg80211_mgmt_tx_status(vif->ndev, id,
521 wmi->last_mgmt_tx_frame,
522 wmi->last_mgmt_tx_frame_len,
523 !!ev->ack_status, GFP_ATOMIC);
524 kfree(wmi->last_mgmt_tx_frame);
525 wmi->last_mgmt_tx_frame = NULL;
526 wmi->last_mgmt_tx_frame_len = 0;
532 static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
533 struct ath6kl_vif *vif)
535 struct wmi_p2p_rx_probe_req_event *ev;
539 if (len < sizeof(*ev))
542 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
543 freq = le32_to_cpu(ev->freq);
544 dlen = le16_to_cpu(ev->len);
545 if (datap + len < ev->data + dlen) {
546 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
547 "len=%d dlen=%u\n", len, dlen);
550 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
551 "probe_req_report=%d\n",
552 dlen, freq, vif->probe_req_report);
554 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
555 cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
560 static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
562 struct wmi_p2p_capabilities_event *ev;
565 if (len < sizeof(*ev))
568 ev = (struct wmi_p2p_capabilities_event *) datap;
569 dlen = le16_to_cpu(ev->len);
570 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
575 static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
576 struct ath6kl_vif *vif)
578 struct wmi_rx_action_event *ev;
582 if (len < sizeof(*ev))
585 ev = (struct wmi_rx_action_event *) datap;
586 freq = le32_to_cpu(ev->freq);
587 dlen = le16_to_cpu(ev->len);
588 if (datap + len < ev->data + dlen) {
589 ath6kl_err("invalid wmi_rx_action_event: "
590 "len=%d dlen=%u\n", len, dlen);
593 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
594 cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
599 static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
601 struct wmi_p2p_info_event *ev;
605 if (len < sizeof(*ev))
608 ev = (struct wmi_p2p_info_event *) datap;
609 flags = le32_to_cpu(ev->info_req_flags);
610 dlen = le16_to_cpu(ev->len);
611 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
613 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
614 struct wmi_p2p_capabilities *cap;
615 if (dlen < sizeof(*cap))
617 cap = (struct wmi_p2p_capabilities *) ev->data;
618 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
622 if (flags & P2P_FLAG_MACADDR_REQ) {
623 struct wmi_p2p_macaddr *mac;
624 if (dlen < sizeof(*mac))
626 mac = (struct wmi_p2p_macaddr *) ev->data;
627 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
631 if (flags & P2P_FLAG_HMODEL_REQ) {
632 struct wmi_p2p_hmodel *mod;
633 if (dlen < sizeof(*mod))
635 mod = (struct wmi_p2p_hmodel *) ev->data;
636 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
638 mod->p2p_model ? "host" : "firmware");
643 static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
647 skb = ath6kl_buf_alloc(size);
653 memset(skb->data, 0, size);
658 /* Send a "simple" wmi command -- one with no arguments */
659 static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
660 enum wmi_cmd_id cmd_id)
665 skb = ath6kl_wmi_get_new_buf(0);
669 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
674 static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
676 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
678 if (len < sizeof(struct wmi_ready_event_2))
681 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
682 le32_to_cpu(ev->sw_version),
683 le32_to_cpu(ev->abi_version));
689 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
690 * at which the station has to roam can be passed with
691 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
694 int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
697 struct roam_ctrl_cmd *cmd;
699 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
703 cmd = (struct roam_ctrl_cmd *) skb->data;
705 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
706 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
707 DEF_SCAN_FOR_ROAM_INTVL);
708 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
709 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
710 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
712 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
718 int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
721 struct roam_ctrl_cmd *cmd;
723 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
727 cmd = (struct roam_ctrl_cmd *) skb->data;
728 memset(cmd, 0, sizeof(*cmd));
730 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
731 cmd->roam_ctrl = WMI_FORCE_ROAM;
733 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
734 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
738 int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
741 struct roam_ctrl_cmd *cmd;
743 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
747 cmd = (struct roam_ctrl_cmd *) skb->data;
748 memset(cmd, 0, sizeof(*cmd));
750 cmd->info.roam_mode = mode;
751 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
753 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
754 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
758 static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
759 struct ath6kl_vif *vif)
761 struct wmi_connect_event *ev;
764 if (len < sizeof(struct wmi_connect_event))
767 ev = (struct wmi_connect_event *) datap;
769 if (vif->nw_type == AP_NETWORK) {
770 /* AP mode start/STA connected event */
771 struct net_device *dev = vif->ndev;
772 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
773 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
775 __func__, le16_to_cpu(ev->u.ap_bss.ch),
777 ath6kl_connect_ap_mode_bss(
778 vif, le16_to_cpu(ev->u.ap_bss.ch));
780 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
781 "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
783 __func__, ev->u.ap_sta.aid,
784 ev->u.ap_sta.mac_addr,
786 ev->u.ap_sta.keymgmt,
787 le16_to_cpu(ev->u.ap_sta.cipher),
788 ev->u.ap_sta.apsd_info);
789 ath6kl_connect_ap_mode_sta(
790 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
791 ev->u.ap_sta.keymgmt,
792 le16_to_cpu(ev->u.ap_sta.cipher),
793 ev->u.ap_sta.auth, ev->assoc_req_len,
794 ev->assoc_info + ev->beacon_ie_len);
799 /* STA/IBSS mode connection event */
801 ath6kl_dbg(ATH6KL_DBG_WMI,
802 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
803 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
804 le16_to_cpu(ev->u.sta.listen_intvl),
805 le16_to_cpu(ev->u.sta.beacon_intvl),
806 le32_to_cpu(ev->u.sta.nw_type));
808 /* Start of assoc rsp IEs */
809 pie = ev->assoc_info + ev->beacon_ie_len +
810 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
812 /* End of assoc rsp IEs */
813 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
818 case WLAN_EID_VENDOR_SPECIFIC:
819 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
820 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
821 /* WMM OUT (00:50:F2) */
823 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
824 wmi->is_wmm_enabled = true;
829 if (wmi->is_wmm_enabled)
835 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
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),
840 ev->beacon_ie_len, ev->assoc_req_len,
841 ev->assoc_resp_len, ev->assoc_info);
846 static struct country_code_to_enum_rd *
847 ath6kl_regd_find_country(u16 countryCode)
851 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
852 if (allCountries[i].countryCode == countryCode)
853 return &allCountries[i];
859 static struct reg_dmn_pair_mapping *
860 ath6kl_get_regpair(u16 regdmn)
864 if (regdmn == NO_ENUMRD)
867 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
868 if (regDomainPairs[i].regDmnEnum == regdmn)
869 return ®DomainPairs[i];
875 static struct country_code_to_enum_rd *
876 ath6kl_regd_find_country_by_rd(u16 regdmn)
880 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
881 if (allCountries[i].regDmnEnum == regdmn)
882 return &allCountries[i];
888 static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
891 struct ath6kl_wmi_regdomain *ev;
892 struct country_code_to_enum_rd *country = NULL;
893 struct reg_dmn_pair_mapping *regpair = NULL;
897 ev = (struct ath6kl_wmi_regdomain *) datap;
898 reg_code = le32_to_cpu(ev->reg_code);
900 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
901 country = ath6kl_regd_find_country((u16) reg_code);
902 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
904 regpair = ath6kl_get_regpair((u16) reg_code);
905 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
906 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
907 regpair->regDmnEnum);
911 alpha2[0] = country->isoName[0];
912 alpha2[1] = country->isoName[1];
914 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
916 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
917 alpha2[0], alpha2[1]);
921 static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
922 struct ath6kl_vif *vif)
924 struct wmi_disconnect_event *ev;
925 wmi->traffic_class = 100;
927 if (len < sizeof(struct wmi_disconnect_event))
930 ev = (struct wmi_disconnect_event *) datap;
932 ath6kl_dbg(ATH6KL_DBG_WMI,
933 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
934 le16_to_cpu(ev->proto_reason_status), ev->bssid,
935 ev->disconn_reason, ev->assoc_resp_len);
937 wmi->is_wmm_enabled = false;
939 ath6kl_disconnect_event(vif, ev->disconn_reason,
940 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
941 le16_to_cpu(ev->proto_reason_status));
946 static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
948 struct wmi_peer_node_event *ev;
950 if (len < sizeof(struct wmi_peer_node_event))
953 ev = (struct wmi_peer_node_event *) datap;
955 if (ev->event_code == PEER_NODE_JOIN_EVENT)
956 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
958 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
959 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
965 static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
966 struct ath6kl_vif *vif)
968 struct wmi_tkip_micerr_event *ev;
970 if (len < sizeof(struct wmi_tkip_micerr_event))
973 ev = (struct wmi_tkip_micerr_event *) datap;
975 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
980 void ath6kl_wmi_sscan_timer(unsigned long ptr)
982 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
984 cfg80211_sched_scan_results(vif->ar->wiphy);
987 static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
988 struct ath6kl_vif *vif)
990 struct wmi_bss_info_hdr2 *bih;
992 struct ieee80211_channel *channel;
993 struct ath6kl *ar = wmi->parent_dev;
994 struct ieee80211_mgmt *mgmt;
995 struct cfg80211_bss *bss;
997 if (len <= sizeof(struct wmi_bss_info_hdr2))
1000 bih = (struct wmi_bss_info_hdr2 *) datap;
1001 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1002 len -= sizeof(struct wmi_bss_info_hdr2);
1004 ath6kl_dbg(ATH6KL_DBG_WMI,
1005 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1007 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
1010 if (bih->frame_type != BEACON_FTYPE &&
1011 bih->frame_type != PROBERESP_FTYPE)
1012 return 0; /* Only update BSS table for now */
1014 if (bih->frame_type == BEACON_FTYPE &&
1015 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1016 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
1017 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1018 NONE_BSS_FILTER, 0);
1021 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
1022 if (channel == NULL)
1025 if (len < 8 + 2 + 2)
1028 if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &vif->flags)
1029 && memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
1031 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1033 if (tim && tim[1] >= 2) {
1034 vif->assoc_bss_dtim_period = tim[3];
1035 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
1040 * In theory, use of cfg80211_inform_bss() would be more natural here
1041 * since we do not have the full frame. However, at least for now,
1042 * cfg80211 can only distinguish Beacon and Probe Response frames from
1043 * each other when using cfg80211_inform_bss_frame(), so let's build a
1044 * fake IEEE 802.11 header to be able to take benefit of this.
1046 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1050 if (bih->frame_type == BEACON_FTYPE) {
1051 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1052 IEEE80211_STYPE_BEACON);
1053 memset(mgmt->da, 0xff, ETH_ALEN);
1055 struct net_device *dev = vif->ndev;
1057 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1058 IEEE80211_STYPE_PROBE_RESP);
1059 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
1061 mgmt->duration = cpu_to_le16(0);
1062 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1063 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1064 mgmt->seq_ctrl = cpu_to_le16(0);
1066 memcpy(&mgmt->u.beacon, buf, len);
1068 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
1069 24 + len, (bih->snr - 95) * 100,
1074 cfg80211_put_bss(bss);
1077 * Firmware doesn't return any event when scheduled scan has
1078 * finished, so we need to use a timer to find out when there are
1081 * The timer is started from the first bss info received, otherwise
1082 * the timer would not ever fire if the scan interval is short
1085 if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
1086 !timer_pending(&vif->sched_scan_timer)) {
1087 mod_timer(&vif->sched_scan_timer, jiffies +
1088 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1094 /* Inactivity timeout of a fatpipe(pstream) at the target */
1095 static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1098 struct wmi_pstream_timeout_event *ev;
1100 if (len < sizeof(struct wmi_pstream_timeout_event))
1103 ev = (struct wmi_pstream_timeout_event *) datap;
1106 * When the pstream (fat pipe == AC) timesout, it means there were
1107 * no thinStreams within this pstream & it got implicitly created
1108 * due to data flow on this AC. We start the inactivity timer only
1109 * for implicitly created pstream. Just reset the host state.
1111 spin_lock_bh(&wmi->lock);
1112 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1113 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1114 spin_unlock_bh(&wmi->lock);
1116 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1117 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1122 static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1124 struct wmi_bit_rate_reply *reply;
1128 if (len < sizeof(struct wmi_bit_rate_reply))
1131 reply = (struct wmi_bit_rate_reply *) datap;
1133 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1135 if (reply->rate_index == (s8) RATE_AUTO) {
1138 index = reply->rate_index & 0x7f;
1139 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1140 rate = wmi_rate_tbl[index][sgi];
1143 ath6kl_wakeup_event(wmi->parent_dev);
1148 static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
1150 ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
1155 static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1157 if (len < sizeof(struct wmi_fix_rates_reply))
1160 ath6kl_wakeup_event(wmi->parent_dev);
1165 static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1167 if (len < sizeof(struct wmi_channel_list_reply))
1170 ath6kl_wakeup_event(wmi->parent_dev);
1175 static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1177 struct wmi_tx_pwr_reply *reply;
1179 if (len < sizeof(struct wmi_tx_pwr_reply))
1182 reply = (struct wmi_tx_pwr_reply *) datap;
1183 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1188 static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1190 if (len < sizeof(struct wmi_get_keepalive_cmd))
1193 ath6kl_wakeup_event(wmi->parent_dev);
1198 static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1199 struct ath6kl_vif *vif)
1201 struct wmi_scan_complete_event *ev;
1203 ev = (struct wmi_scan_complete_event *) datap;
1205 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
1206 wmi->is_probe_ssid = false;
1211 static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
1212 int len, struct ath6kl_vif *vif)
1214 struct wmi_neighbor_report_event *ev;
1217 if (len < sizeof(*ev))
1219 ev = (struct wmi_neighbor_report_event *) datap;
1220 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1222 ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
1223 "(num=%d len=%d)\n", ev->num_neighbors, len);
1226 for (i = 0; i < ev->num_neighbors; i++) {
1227 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1228 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1229 ev->neighbor[i].bss_flags);
1230 cfg80211_pmksa_candidate_notify(vif->ndev, i,
1231 ev->neighbor[i].bssid,
1232 !!(ev->neighbor[i].bss_flags &
1233 WMI_PREAUTH_CAPABLE_BSS),
1241 * Target is reporting a programming error. This is for
1242 * developer aid only. Target only checks a few common violations
1243 * and it is responsibility of host to do all error checking.
1244 * Behavior of target after wmi error event is undefined.
1245 * A reset is recommended.
1247 static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1249 const char *type = "unknown error";
1250 struct wmi_cmd_error_event *ev;
1251 ev = (struct wmi_cmd_error_event *) datap;
1253 switch (ev->err_code) {
1255 type = "invalid parameter";
1258 type = "invalid state";
1260 case INTERNAL_ERROR:
1261 type = "internal error";
1265 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1271 static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1272 struct ath6kl_vif *vif)
1274 ath6kl_tgt_stats_event(vif, datap, len);
1279 static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1280 struct sq_threshold_params *sq_thresh,
1284 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1286 /* The list is already in sorted order. Get the next lower value */
1287 for (index = 0; index < size; index++) {
1288 if (rssi < sq_thresh->upper_threshold[index]) {
1289 threshold = (u8) sq_thresh->upper_threshold[index];
1297 static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1298 struct sq_threshold_params *sq_thresh,
1302 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1304 /* The list is already in sorted order. Get the next lower value */
1305 for (index = 0; index < size; index++) {
1306 if (rssi > sq_thresh->lower_threshold[index]) {
1307 threshold = (u8) sq_thresh->lower_threshold[index];
1315 static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1316 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1318 struct sk_buff *skb;
1319 struct wmi_rssi_threshold_params_cmd *cmd;
1321 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1325 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1326 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1328 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1332 static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1335 struct wmi_rssi_threshold_event *reply;
1336 struct wmi_rssi_threshold_params_cmd cmd;
1337 struct sq_threshold_params *sq_thresh;
1338 enum wmi_rssi_threshold_val new_threshold;
1339 u8 upper_rssi_threshold, lower_rssi_threshold;
1343 if (len < sizeof(struct wmi_rssi_threshold_event))
1346 reply = (struct wmi_rssi_threshold_event *) datap;
1347 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1348 rssi = a_sle16_to_cpu(reply->rssi);
1350 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1353 * Identify the threshold breached and communicate that to the app.
1354 * After that install a new set of thresholds based on the signal
1355 * quality reported by the target
1357 if (new_threshold) {
1358 /* Upper threshold breached */
1359 if (rssi < sq_thresh->upper_threshold[0]) {
1360 ath6kl_dbg(ATH6KL_DBG_WMI,
1361 "spurious upper rssi threshold event: %d\n",
1363 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1364 (rssi >= sq_thresh->upper_threshold[0])) {
1365 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1366 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1367 (rssi >= sq_thresh->upper_threshold[1])) {
1368 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1369 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1370 (rssi >= sq_thresh->upper_threshold[2])) {
1371 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1372 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1373 (rssi >= sq_thresh->upper_threshold[3])) {
1374 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1375 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1376 (rssi >= sq_thresh->upper_threshold[4])) {
1377 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1378 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1379 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1382 /* Lower threshold breached */
1383 if (rssi > sq_thresh->lower_threshold[0]) {
1384 ath6kl_dbg(ATH6KL_DBG_WMI,
1385 "spurious lower rssi threshold event: %d %d\n",
1386 rssi, sq_thresh->lower_threshold[0]);
1387 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1388 (rssi <= sq_thresh->lower_threshold[0])) {
1389 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1390 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1391 (rssi <= sq_thresh->lower_threshold[1])) {
1392 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1393 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1394 (rssi <= sq_thresh->lower_threshold[2])) {
1395 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1396 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1397 (rssi <= sq_thresh->lower_threshold[3])) {
1398 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1399 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1400 (rssi <= sq_thresh->lower_threshold[4])) {
1401 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1402 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1403 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1407 /* Calculate and install the next set of thresholds */
1408 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1409 sq_thresh->lower_threshold_valid_count);
1410 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1411 sq_thresh->upper_threshold_valid_count);
1413 /* Issue a wmi command to install the thresholds */
1414 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1415 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1416 cmd.weight = sq_thresh->weight;
1417 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1419 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1421 ath6kl_err("unable to configure rssi thresholds\n");
1428 static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1429 struct ath6kl_vif *vif)
1431 struct wmi_cac_event *reply;
1432 struct ieee80211_tspec_ie *ts;
1433 u16 active_tsids, tsinfo;
1437 if (len < sizeof(struct wmi_cac_event))
1440 reply = (struct wmi_cac_event *) datap;
1442 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1443 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1445 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1446 tsinfo = le16_to_cpu(ts->tsinfo);
1447 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1448 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1450 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1452 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1454 * Following assumes that there is only one outstanding
1455 * ADDTS request when this event is received
1457 spin_lock_bh(&wmi->lock);
1458 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1459 spin_unlock_bh(&wmi->lock);
1461 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1462 if ((active_tsids >> index) & 1)
1465 if (index < (sizeof(active_tsids) * 8))
1466 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1471 * Clear active tsids and Add missing handling
1472 * for delete qos stream from AP
1474 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1476 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1477 tsinfo = le16_to_cpu(ts->tsinfo);
1478 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1479 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1481 spin_lock_bh(&wmi->lock);
1482 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1483 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1484 spin_unlock_bh(&wmi->lock);
1486 /* Indicate stream inactivity to driver layer only if all tsids
1487 * within this AC are deleted.
1489 if (!active_tsids) {
1490 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1492 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1499 static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1500 struct wmi_snr_threshold_params_cmd *snr_cmd)
1502 struct sk_buff *skb;
1503 struct wmi_snr_threshold_params_cmd *cmd;
1505 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1509 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1510 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1512 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1516 static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1519 struct wmi_snr_threshold_event *reply;
1520 struct sq_threshold_params *sq_thresh;
1521 struct wmi_snr_threshold_params_cmd cmd;
1522 enum wmi_snr_threshold_val new_threshold;
1523 u8 upper_snr_threshold, lower_snr_threshold;
1527 if (len < sizeof(struct wmi_snr_threshold_event))
1530 reply = (struct wmi_snr_threshold_event *) datap;
1532 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1535 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1538 * Identify the threshold breached and communicate that to the app.
1539 * After that install a new set of thresholds based on the signal
1540 * quality reported by the target.
1542 if (new_threshold) {
1543 /* Upper threshold breached */
1544 if (snr < sq_thresh->upper_threshold[0]) {
1545 ath6kl_dbg(ATH6KL_DBG_WMI,
1546 "spurious upper snr threshold event: %d\n",
1548 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1549 (snr >= sq_thresh->upper_threshold[0])) {
1550 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1551 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1552 (snr >= sq_thresh->upper_threshold[1])) {
1553 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1554 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1555 (snr >= sq_thresh->upper_threshold[2])) {
1556 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1557 } else if (snr >= sq_thresh->upper_threshold[3]) {
1558 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1561 /* Lower threshold breached */
1562 if (snr > sq_thresh->lower_threshold[0]) {
1563 ath6kl_dbg(ATH6KL_DBG_WMI,
1564 "spurious lower snr threshold event: %d\n",
1565 sq_thresh->lower_threshold[0]);
1566 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1567 (snr <= sq_thresh->lower_threshold[0])) {
1568 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1569 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1570 (snr <= sq_thresh->lower_threshold[1])) {
1571 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1572 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1573 (snr <= sq_thresh->lower_threshold[2])) {
1574 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1575 } else if (snr <= sq_thresh->lower_threshold[3]) {
1576 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1580 /* Calculate and install the next set of thresholds */
1581 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1582 sq_thresh->lower_threshold_valid_count);
1583 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1584 sq_thresh->upper_threshold_valid_count);
1586 /* Issue a wmi command to install the thresholds */
1587 cmd.thresh_above1_val = upper_snr_threshold;
1588 cmd.thresh_below1_val = lower_snr_threshold;
1589 cmd.weight = sq_thresh->weight;
1590 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1592 ath6kl_dbg(ATH6KL_DBG_WMI,
1593 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1595 lower_snr_threshold, upper_snr_threshold);
1597 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1599 ath6kl_err("unable to configure snr threshold\n");
1606 static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1608 u16 ap_info_entry_size;
1609 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1610 struct wmi_ap_info_v1 *ap_info_v1;
1613 if (len < sizeof(struct wmi_aplist_event) ||
1614 ev->ap_list_ver != APLIST_VER1)
1617 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1618 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1620 ath6kl_dbg(ATH6KL_DBG_WMI,
1621 "number of APs in aplist event: %d\n", ev->num_ap);
1623 if (len < (int) (sizeof(struct wmi_aplist_event) +
1624 (ev->num_ap - 1) * ap_info_entry_size))
1627 /* AP list version 1 contents */
1628 for (index = 0; index < ev->num_ap; index++) {
1629 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1630 index, ap_info_v1->bssid, ap_info_v1->channel);
1637 int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
1638 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1640 struct wmi_cmd_hdr *cmd_hdr;
1641 enum htc_endpoint_id ep_id = wmi->ep_id;
1645 if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1))))
1648 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1649 cmd_id, skb->len, sync_flag);
1650 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1651 skb->data, skb->len);
1653 if (sync_flag >= END_WMIFLAG) {
1658 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1659 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1661 * Make sure all data currently queued is transmitted before
1662 * the cmd execution. Establish a new sync point.
1664 ath6kl_wmi_sync_point(wmi, if_idx);
1667 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1669 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1670 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1671 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1672 cmd_hdr->info1 = cpu_to_le16(info1);
1674 /* Only for OPT_TX_CMD, use BE endpoint. */
1675 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1676 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1677 false, false, 0, NULL, if_idx);
1682 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1685 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1687 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1688 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1690 * Make sure all new data queued waits for the command to
1691 * execute. Establish a new sync point.
1693 ath6kl_wmi_sync_point(wmi, if_idx);
1699 int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1700 enum network_type nw_type,
1701 enum dot11_auth_mode dot11_auth_mode,
1702 enum auth_mode auth_mode,
1703 enum crypto_type pairwise_crypto,
1704 u8 pairwise_crypto_len,
1705 enum crypto_type group_crypto,
1706 u8 group_crypto_len, int ssid_len, u8 *ssid,
1707 u8 *bssid, u16 channel, u32 ctrl_flags)
1709 struct sk_buff *skb;
1710 struct wmi_connect_cmd *cc;
1713 ath6kl_dbg(ATH6KL_DBG_WMI,
1714 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1715 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1716 bssid, channel, ctrl_flags, ssid_len, nw_type,
1717 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1718 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1720 wmi->traffic_class = 100;
1722 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1725 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1728 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1732 cc = (struct wmi_connect_cmd *) skb->data;
1735 memcpy(cc->ssid, ssid, ssid_len);
1737 cc->ssid_len = ssid_len;
1738 cc->nw_type = nw_type;
1739 cc->dot11_auth_mode = dot11_auth_mode;
1740 cc->auth_mode = auth_mode;
1741 cc->prwise_crypto_type = pairwise_crypto;
1742 cc->prwise_crypto_len = pairwise_crypto_len;
1743 cc->grp_crypto_type = group_crypto;
1744 cc->grp_crypto_len = group_crypto_len;
1745 cc->ch = cpu_to_le16(channel);
1746 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1749 memcpy(cc->bssid, bssid, ETH_ALEN);
1751 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1757 int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1760 struct sk_buff *skb;
1761 struct wmi_reconnect_cmd *cc;
1764 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1767 wmi->traffic_class = 100;
1769 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1773 cc = (struct wmi_reconnect_cmd *) skb->data;
1774 cc->channel = cpu_to_le16(channel);
1777 memcpy(cc->bssid, bssid, ETH_ALEN);
1779 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
1785 int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
1789 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1791 wmi->traffic_class = 100;
1793 /* Disconnect command does not need to do a SYNC before. */
1794 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
1799 int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1800 enum wmi_scan_type scan_type,
1801 u32 force_fgscan, u32 is_legacy,
1802 u32 home_dwell_time, u32 force_scan_interval,
1803 s8 num_chan, u16 *ch_list)
1805 struct sk_buff *skb;
1806 struct wmi_start_scan_cmd *sc;
1810 size = sizeof(struct wmi_start_scan_cmd);
1812 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1815 if (num_chan > WMI_MAX_CHANNELS)
1819 size += sizeof(u16) * (num_chan - 1);
1821 skb = ath6kl_wmi_get_new_buf(size);
1825 sc = (struct wmi_start_scan_cmd *) skb->data;
1826 sc->scan_type = scan_type;
1827 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1828 sc->is_legacy = cpu_to_le32(is_legacy);
1829 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1830 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1831 sc->num_ch = num_chan;
1833 for (i = 0; i < num_chan; i++)
1834 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1836 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
1842 int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
1844 u16 fg_end_sec, u16 bg_sec,
1845 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1846 u16 pas_chdw_msec, u8 short_scan_ratio,
1847 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1848 u16 maxact_scan_per_ssid)
1850 struct sk_buff *skb;
1851 struct wmi_scan_params_cmd *sc;
1854 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1858 sc = (struct wmi_scan_params_cmd *) skb->data;
1859 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1860 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1861 sc->bg_period = cpu_to_le16(bg_sec);
1862 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1863 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1864 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1865 sc->short_scan_ratio = short_scan_ratio;
1866 sc->scan_ctrl_flags = scan_ctrl_flag;
1867 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1868 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1870 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
1875 int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
1877 struct sk_buff *skb;
1878 struct wmi_bss_filter_cmd *cmd;
1881 if (filter >= LAST_BSS_FILTER)
1884 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1888 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1889 cmd->bss_filter = filter;
1890 cmd->ie_mask = cpu_to_le32(ie_mask);
1892 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
1897 int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
1898 u8 ssid_len, u8 *ssid)
1900 struct sk_buff *skb;
1901 struct wmi_probed_ssid_cmd *cmd;
1904 if (index > MAX_PROBED_SSID_INDEX)
1907 if (ssid_len > sizeof(cmd->ssid))
1910 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1913 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1916 if (flag & SPECIFIC_SSID_FLAG)
1917 wmi->is_probe_ssid = true;
1919 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1923 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1924 cmd->entry_index = index;
1926 cmd->ssid_len = ssid_len;
1927 memcpy(cmd->ssid, ssid, ssid_len);
1929 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
1934 int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
1935 u16 listen_interval,
1938 struct sk_buff *skb;
1939 struct wmi_listen_int_cmd *cmd;
1942 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1946 cmd = (struct wmi_listen_int_cmd *) skb->data;
1947 cmd->listen_intvl = cpu_to_le16(listen_interval);
1948 cmd->num_beacons = cpu_to_le16(listen_beacons);
1950 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
1955 int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
1957 struct sk_buff *skb;
1958 struct wmi_power_mode_cmd *cmd;
1961 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1965 cmd = (struct wmi_power_mode_cmd *) skb->data;
1966 cmd->pwr_mode = pwr_mode;
1967 wmi->pwr_mode = pwr_mode;
1969 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
1974 int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
1975 u16 ps_poll_num, u16 dtim_policy,
1976 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1977 u16 ps_fail_event_policy)
1979 struct sk_buff *skb;
1980 struct wmi_power_params_cmd *pm;
1983 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1987 pm = (struct wmi_power_params_cmd *)skb->data;
1988 pm->idle_period = cpu_to_le16(idle_period);
1989 pm->pspoll_number = cpu_to_le16(ps_poll_num);
1990 pm->dtim_policy = cpu_to_le16(dtim_policy);
1991 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1992 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1993 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1995 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
2000 int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
2002 struct sk_buff *skb;
2003 struct wmi_disc_timeout_cmd *cmd;
2006 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2010 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2011 cmd->discon_timeout = timeout;
2013 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
2017 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
2022 int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
2023 enum crypto_type key_type,
2024 u8 key_usage, u8 key_len,
2025 u8 *key_rsc, unsigned int key_rsc_len,
2027 u8 key_op_ctrl, u8 *mac_addr,
2028 enum wmi_sync_flag sync_flag)
2030 struct sk_buff *skb;
2031 struct wmi_add_cipher_key_cmd *cmd;
2034 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
2035 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
2036 key_index, key_type, key_usage, key_len, key_op_ctrl);
2038 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
2039 (key_material == NULL) || key_rsc_len > 8)
2042 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2045 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2049 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2050 cmd->key_index = key_index;
2051 cmd->key_type = key_type;
2052 cmd->key_usage = key_usage;
2053 cmd->key_len = key_len;
2054 memcpy(cmd->key, key_material, key_len);
2056 if (key_rsc != NULL)
2057 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
2059 cmd->key_op_ctrl = key_op_ctrl;
2062 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2064 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
2070 int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
2072 struct sk_buff *skb;
2073 struct wmi_add_krk_cmd *cmd;
2076 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2080 cmd = (struct wmi_add_krk_cmd *) skb->data;
2081 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2083 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
2089 int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
2091 struct sk_buff *skb;
2092 struct wmi_delete_cipher_key_cmd *cmd;
2095 if (key_index > WMI_MAX_KEY_INDEX)
2098 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2102 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2103 cmd->key_index = key_index;
2105 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
2111 int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
2112 const u8 *pmkid, bool set)
2114 struct sk_buff *skb;
2115 struct wmi_setpmkid_cmd *cmd;
2121 if (set && pmkid == NULL)
2124 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2128 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2129 memcpy(cmd->bssid, bssid, ETH_ALEN);
2131 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2132 cmd->enable = PMKID_ENABLE;
2134 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2135 cmd->enable = PMKID_DISABLE;
2138 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
2144 static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2145 enum htc_endpoint_id ep_id, u8 if_idx)
2147 struct wmi_data_hdr *data_hdr;
2150 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2153 skb_push(skb, sizeof(struct wmi_data_hdr));
2155 data_hdr = (struct wmi_data_hdr *) skb->data;
2156 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2157 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
2159 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2164 static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
2166 struct sk_buff *skb;
2167 struct wmi_sync_cmd *cmd;
2168 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2169 enum htc_endpoint_id ep_id;
2170 u8 index, num_pri_streams = 0;
2173 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2175 spin_lock_bh(&wmi->lock);
2177 for (index = 0; index < WMM_NUM_AC; index++) {
2178 if (wmi->fat_pipe_exist & (1 << index)) {
2180 data_sync_bufs[num_pri_streams - 1].traffic_class =
2185 spin_unlock_bh(&wmi->lock);
2187 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2193 cmd = (struct wmi_sync_cmd *) skb->data;
2196 * In the SYNC cmd sent on the control Ep, send a bitmap
2197 * of the data eps on which the Data Sync will be sent
2199 cmd->data_sync_map = wmi->fat_pipe_exist;
2201 for (index = 0; index < num_pri_streams; index++) {
2202 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2203 if (data_sync_bufs[index].skb == NULL) {
2210 * If buffer allocation for any of the dataSync fails,
2211 * then do not send the Synchronize cmd on the control ep
2217 * Send sync cmd followed by sync data messages on all
2218 * endpoints being used
2220 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
2226 /* cmd buffer sent, we no longer own it */
2229 for (index = 0; index < num_pri_streams; index++) {
2231 if (WARN_ON(!data_sync_bufs[index].skb))
2234 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2235 data_sync_bufs[index].
2238 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2244 data_sync_bufs[index].skb = NULL;
2248 /* free up any resources left over (possibly due to an error) */
2252 for (index = 0; index < num_pri_streams; index++) {
2253 if (data_sync_bufs[index].skb != NULL) {
2254 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2262 int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
2263 struct wmi_create_pstream_cmd *params)
2265 struct sk_buff *skb;
2266 struct wmi_create_pstream_cmd *cmd;
2267 u8 fatpipe_exist_for_ac = 0;
2269 s32 nominal_phy = 0;
2272 if (!((params->user_pri < 8) &&
2273 (params->user_pri <= 0x7) &&
2274 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2275 (params->traffic_direc == UPLINK_TRAFFIC ||
2276 params->traffic_direc == DNLINK_TRAFFIC ||
2277 params->traffic_direc == BIDIR_TRAFFIC) &&
2278 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2279 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2280 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2281 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2282 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2283 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2284 params->tsid <= WMI_MAX_THINSTREAM))) {
2289 * Check nominal PHY rate is >= minimalPHY,
2290 * so that DUT can allow TSRS IE
2293 /* Get the physical rate (units of bps) */
2294 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2296 /* Check minimal phy < nominal phy rate */
2297 if (params->nominal_phy >= min_phy) {
2298 /* unit of 500 kbps */
2299 nominal_phy = (params->nominal_phy * 1000) / 500;
2300 ath6kl_dbg(ATH6KL_DBG_WMI,
2301 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2302 min_phy, nominal_phy);
2304 params->nominal_phy = nominal_phy;
2306 params->nominal_phy = 0;
2309 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2313 ath6kl_dbg(ATH6KL_DBG_WMI,
2314 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2315 params->traffic_class, params->tsid);
2317 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2318 memcpy(cmd, params, sizeof(*cmd));
2320 /* This is an implicitly created Fat pipe */
2321 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2322 spin_lock_bh(&wmi->lock);
2323 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2324 (1 << params->traffic_class));
2325 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2326 spin_unlock_bh(&wmi->lock);
2328 /* explicitly created thin stream within a fat pipe */
2329 spin_lock_bh(&wmi->lock);
2330 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2331 (1 << params->traffic_class));
2332 wmi->stream_exist_for_ac[params->traffic_class] |=
2333 (1 << params->tsid);
2335 * If a thinstream becomes active, the fat pipe automatically
2338 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2339 spin_unlock_bh(&wmi->lock);
2343 * Indicate activty change to driver layer only if this is the
2344 * first TSID to get created in this AC explicitly or an implicit
2345 * fat pipe is getting created.
2347 if (!fatpipe_exist_for_ac)
2348 ath6kl_indicate_tx_activity(wmi->parent_dev,
2349 params->traffic_class, true);
2351 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
2356 int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2359 struct sk_buff *skb;
2360 struct wmi_delete_pstream_cmd *cmd;
2361 u16 active_tsids = 0;
2364 if (traffic_class > 3) {
2365 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2369 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2373 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2374 cmd->traffic_class = traffic_class;
2377 spin_lock_bh(&wmi->lock);
2378 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2379 spin_unlock_bh(&wmi->lock);
2381 if (!(active_tsids & (1 << tsid))) {
2383 ath6kl_dbg(ATH6KL_DBG_WMI,
2384 "TSID %d doesn't exist for traffic class: %d\n",
2385 tsid, traffic_class);
2389 ath6kl_dbg(ATH6KL_DBG_WMI,
2390 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2391 traffic_class, tsid);
2393 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
2394 SYNC_BEFORE_WMIFLAG);
2396 spin_lock_bh(&wmi->lock);
2397 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2398 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2399 spin_unlock_bh(&wmi->lock);
2402 * Indicate stream inactivity to driver layer only if all tsids
2403 * within this AC are deleted.
2405 if (!active_tsids) {
2406 ath6kl_indicate_tx_activity(wmi->parent_dev,
2407 traffic_class, false);
2408 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2414 int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2416 struct sk_buff *skb;
2417 struct wmi_set_ip_cmd *cmd;
2420 /* Multicast address are not valid */
2421 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2422 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2425 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2429 cmd = (struct wmi_set_ip_cmd *) skb->data;
2430 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2432 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_IP_CMDID,
2437 static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2444 * Relinquish credits from all implicitly created pstreams
2445 * since when we go to sleep. If user created explicit
2446 * thinstreams exists with in a fatpipe leave them intact
2447 * for the user to delete.
2449 spin_lock_bh(&wmi->lock);
2450 stream_exist = wmi->fat_pipe_exist;
2451 spin_unlock_bh(&wmi->lock);
2453 for (i = 0; i < WMM_NUM_AC; i++) {
2454 if (stream_exist & (1 << i)) {
2457 * FIXME: Is this lock & unlock inside
2458 * for loop correct? may need rework.
2460 spin_lock_bh(&wmi->lock);
2461 active_tsids = wmi->stream_exist_for_ac[i];
2462 spin_unlock_bh(&wmi->lock);
2465 * If there are no user created thin streams
2466 * delete the fatpipe
2468 if (!active_tsids) {
2469 stream_exist &= ~(1 << i);
2471 * Indicate inactivity to driver layer for
2472 * this fatpipe (pstream)
2474 ath6kl_indicate_tx_activity(wmi->parent_dev,
2480 /* FIXME: Can we do this assignment without locking ? */
2481 spin_lock_bh(&wmi->lock);
2482 wmi->fat_pipe_exist = stream_exist;
2483 spin_unlock_bh(&wmi->lock);
2486 int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2487 enum ath6kl_host_mode host_mode)
2489 struct sk_buff *skb;
2490 struct wmi_set_host_sleep_mode_cmd *cmd;
2493 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2494 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2495 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2499 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2503 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2505 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2506 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2507 cmd->asleep = cpu_to_le32(1);
2509 cmd->awake = cpu_to_le32(1);
2511 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2512 WMI_SET_HOST_SLEEP_MODE_CMDID,
2517 int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2518 enum ath6kl_wow_mode wow_mode,
2519 u32 filter, u16 host_req_delay)
2521 struct sk_buff *skb;
2522 struct wmi_set_wow_mode_cmd *cmd;
2525 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
2526 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
2527 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2531 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2535 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2536 cmd->enable_wow = cpu_to_le32(wow_mode);
2537 cmd->filter = cpu_to_le32(filter);
2538 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2540 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2545 int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2546 u8 list_id, u8 filter_size,
2547 u8 filter_offset, u8 *filter, u8 *mask)
2549 struct sk_buff *skb;
2550 struct wmi_add_wow_pattern_cmd *cmd;
2556 * Allocate additional memory in the buffer to hold
2557 * filter and mask value, which is twice of filter_size.
2559 size = sizeof(*cmd) + (2 * filter_size);
2561 skb = ath6kl_wmi_get_new_buf(size);
2565 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2566 cmd->filter_list_id = list_id;
2567 cmd->filter_size = filter_size;
2568 cmd->filter_offset = filter_offset;
2570 memcpy(cmd->filter, filter, filter_size);
2572 filter_mask = (u8 *) (cmd->filter + filter_size);
2573 memcpy(filter_mask, mask, filter_size);
2575 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2581 int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2582 u16 list_id, u16 filter_id)
2584 struct sk_buff *skb;
2585 struct wmi_del_wow_pattern_cmd *cmd;
2588 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2592 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
2593 cmd->filter_list_id = cpu_to_le16(list_id);
2594 cmd->filter_id = cpu_to_le16(filter_id);
2596 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
2601 static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2602 enum wmix_command_id cmd_id,
2603 enum wmi_sync_flag sync_flag)
2605 struct wmix_cmd_hdr *cmd_hdr;
2608 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2610 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2611 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2613 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
2618 int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2620 struct sk_buff *skb;
2621 struct wmix_hb_challenge_resp_cmd *cmd;
2624 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2628 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2629 cmd->cookie = cpu_to_le32(cookie);
2630 cmd->source = cpu_to_le32(source);
2632 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2637 int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2639 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2640 struct sk_buff *skb;
2643 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2647 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2648 cmd->valid = cpu_to_le32(valid);
2649 cmd->config = cpu_to_le32(config);
2651 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2656 int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
2658 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
2661 int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
2663 struct sk_buff *skb;
2664 struct wmi_set_tx_pwr_cmd *cmd;
2667 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2671 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2674 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
2680 int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
2682 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
2685 int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
2687 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
2690 int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
2693 struct sk_buff *skb;
2694 struct wmi_set_lpreamble_cmd *cmd;
2697 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2701 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2702 cmd->status = status;
2703 cmd->preamble_policy = preamble_policy;
2705 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
2710 int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2712 struct sk_buff *skb;
2713 struct wmi_set_rts_cmd *cmd;
2716 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2720 cmd = (struct wmi_set_rts_cmd *) skb->data;
2721 cmd->threshold = cpu_to_le16(threshold);
2723 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
2728 int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
2730 struct sk_buff *skb;
2731 struct wmi_set_wmm_txop_cmd *cmd;
2734 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2737 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2741 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2742 cmd->txop_enable = cfg;
2744 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
2749 int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
2750 u8 keep_alive_intvl)
2752 struct sk_buff *skb;
2753 struct wmi_set_keepalive_cmd *cmd;
2756 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2760 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2761 cmd->keep_alive_intvl = keep_alive_intvl;
2763 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
2767 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
2772 int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2774 struct sk_buff *skb;
2777 skb = ath6kl_wmi_get_new_buf(len);
2781 memcpy(skb->data, buf, len);
2783 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
2789 s32 ath6kl_wmi_get_rate(s8 rate_index)
2791 if (rate_index == RATE_AUTO)
2794 return wmi_rate_tbl[(u32) rate_index][0];
2797 static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2800 struct wmi_pmkid_list_reply *reply;
2803 if (len < sizeof(struct wmi_pmkid_list_reply))
2806 reply = (struct wmi_pmkid_list_reply *)datap;
2807 expected_len = sizeof(reply->num_pmkid) +
2808 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2810 if (len < expected_len)
2816 static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
2817 struct ath6kl_vif *vif)
2819 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2821 aggr_recv_addba_req_evt(vif, cmd->tid,
2822 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2827 static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
2828 struct ath6kl_vif *vif)
2830 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2832 aggr_recv_delba_req_evt(vif, cmd->tid);
2837 /* AP mode functions */
2839 int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
2840 struct wmi_connect_cmd *p)
2842 struct sk_buff *skb;
2843 struct wmi_connect_cmd *cm;
2846 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2850 cm = (struct wmi_connect_cmd *) skb->data;
2851 memcpy(cm, p, sizeof(*cm));
2853 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
2855 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2856 "ctrl_flags=0x%x-> res=%d\n",
2857 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2858 le32_to_cpu(p->ctrl_flags), res);
2862 int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
2865 struct sk_buff *skb;
2866 struct wmi_ap_set_mlme_cmd *cm;
2868 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2872 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2873 memcpy(cm->mac, mac, ETH_ALEN);
2874 cm->reason = cpu_to_le16(reason);
2877 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
2881 static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
2882 struct ath6kl_vif *vif)
2884 struct wmi_pspoll_event *ev;
2886 if (len < sizeof(struct wmi_pspoll_event))
2889 ev = (struct wmi_pspoll_event *) datap;
2891 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
2896 static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
2897 struct ath6kl_vif *vif)
2899 ath6kl_dtimexpiry_event(vif);
2904 int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
2907 struct sk_buff *skb;
2908 struct wmi_ap_set_pvb_cmd *cmd;
2911 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2915 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2916 cmd->aid = cpu_to_le16(aid);
2917 cmd->rsvd = cpu_to_le16(0);
2918 cmd->flag = cpu_to_le32(flag);
2920 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
2926 int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
2928 bool rx_dot11_hdr, bool defrag_on_host)
2930 struct sk_buff *skb;
2931 struct wmi_rx_frame_format_cmd *cmd;
2934 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2938 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2939 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2940 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2941 cmd->meta_ver = rx_meta_ver;
2943 /* Delete the local aggr state, on host */
2944 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
2950 int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
2951 const u8 *ie, u8 ie_len)
2953 struct sk_buff *skb;
2954 struct wmi_set_appie_cmd *p;
2956 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2960 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2961 "ie_len=%u\n", mgmt_frm_type, ie_len);
2962 p = (struct wmi_set_appie_cmd *) skb->data;
2963 p->mgmt_frm_type = mgmt_frm_type;
2966 if (ie != NULL && ie_len > 0)
2967 memcpy(p->ie_info, ie, ie_len);
2969 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
2973 int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2975 struct sk_buff *skb;
2976 struct wmi_disable_11b_rates_cmd *cmd;
2978 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2982 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2984 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2985 cmd->disable = disable ? 1 : 0;
2987 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
2991 int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
2993 struct sk_buff *skb;
2994 struct wmi_remain_on_chnl_cmd *p;
2996 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3000 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3002 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3003 p->freq = cpu_to_le32(freq);
3004 p->duration = cpu_to_le32(dur);
3005 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
3009 int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3010 u32 wait, const u8 *data, u16 data_len)
3012 struct sk_buff *skb;
3013 struct wmi_send_action_cmd *p;
3017 return -EINVAL; /* Offload for wait not supported */
3019 buf = kmalloc(data_len, GFP_KERNEL);
3023 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3029 kfree(wmi->last_mgmt_tx_frame);
3030 memcpy(buf, data, data_len);
3031 wmi->last_mgmt_tx_frame = buf;
3032 wmi->last_mgmt_tx_frame_len = data_len;
3034 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
3035 "len=%u\n", id, freq, wait, data_len);
3036 p = (struct wmi_send_action_cmd *) skb->data;
3037 p->id = cpu_to_le32(id);
3038 p->freq = cpu_to_le32(freq);
3039 p->wait = cpu_to_le32(wait);
3040 p->len = cpu_to_le16(data_len);
3041 memcpy(p->data, data, data_len);
3042 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
3046 int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3047 const u8 *dst, const u8 *data,
3050 struct sk_buff *skb;
3051 struct wmi_p2p_probe_response_cmd *p;
3052 size_t cmd_len = sizeof(*p) + data_len;
3055 cmd_len++; /* work around target minimum length requirement */
3057 skb = ath6kl_wmi_get_new_buf(cmd_len);
3061 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
3062 "len=%u\n", freq, dst, data_len);
3063 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3064 p->freq = cpu_to_le32(freq);
3065 memcpy(p->destination_addr, dst, ETH_ALEN);
3066 p->len = cpu_to_le16(data_len);
3067 memcpy(p->data, data, data_len);
3068 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3069 WMI_SEND_PROBE_RESPONSE_CMDID,
3073 int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
3075 struct sk_buff *skb;
3076 struct wmi_probe_req_report_cmd *p;
3078 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3082 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3084 p = (struct wmi_probe_req_report_cmd *) skb->data;
3085 p->enable = enable ? 1 : 0;
3086 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
3090 int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
3092 struct sk_buff *skb;
3093 struct wmi_get_p2p_info *p;
3095 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3099 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3101 p = (struct wmi_get_p2p_info *) skb->data;
3102 p->info_req_flags = cpu_to_le32(info_req_flags);
3103 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
3107 int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
3109 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
3110 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3111 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
3114 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3116 struct wmix_cmd_hdr *cmd;
3122 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3123 ath6kl_err("bad packet 1\n");
3127 cmd = (struct wmix_cmd_hdr *) skb->data;
3128 id = le32_to_cpu(cmd->cmd_id);
3130 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3136 case WMIX_HB_CHALLENGE_RESP_EVENTID:
3137 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
3139 case WMIX_DBGLOG_EVENTID:
3140 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
3141 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
3144 ath6kl_warn("unknown cmd id 0x%x\n", id);
3152 static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3154 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3158 int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
3160 struct wmi_cmd_hdr *cmd;
3161 struct ath6kl_vif *vif;
3168 if (WARN_ON(skb == NULL))
3171 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
3172 ath6kl_err("bad packet 1\n");
3177 cmd = (struct wmi_cmd_hdr *) skb->data;
3178 id = le16_to_cpu(cmd->cmd_id);
3179 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
3181 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3186 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3187 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3190 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3192 ath6kl_dbg(ATH6KL_DBG_WMI,
3193 "Wmi event for unavailable vif, vif_index:%d\n",
3200 case WMI_GET_BITRATE_CMDID:
3201 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3202 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3204 case WMI_GET_CHANNEL_LIST_CMDID:
3205 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3206 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3208 case WMI_GET_TX_PWR_CMDID:
3209 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3210 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3212 case WMI_READY_EVENTID:
3213 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3214 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3216 case WMI_CONNECT_EVENTID:
3217 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3218 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3220 case WMI_DISCONNECT_EVENTID:
3221 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3222 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3224 case WMI_PEER_NODE_EVENTID:
3225 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3226 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3228 case WMI_TKIP_MICERR_EVENTID:
3229 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3230 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3232 case WMI_BSSINFO_EVENTID:
3233 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3234 ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3236 case WMI_REGDOMAIN_EVENTID:
3237 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
3238 ath6kl_wmi_regdomain_event(wmi, datap, len);
3240 case WMI_PSTREAM_TIMEOUT_EVENTID:
3241 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3242 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3244 case WMI_NEIGHBOR_REPORT_EVENTID:
3245 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3246 ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3249 case WMI_SCAN_COMPLETE_EVENTID:
3250 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3251 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3253 case WMI_CMDERROR_EVENTID:
3254 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3255 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3257 case WMI_REPORT_STATISTICS_EVENTID:
3258 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3259 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3261 case WMI_RSSI_THRESHOLD_EVENTID:
3262 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3263 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3265 case WMI_ERROR_REPORT_EVENTID:
3266 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3268 case WMI_OPT_RX_FRAME_EVENTID:
3269 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
3270 /* this event has been deprecated */
3272 case WMI_REPORT_ROAM_TBL_EVENTID:
3273 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
3274 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
3276 case WMI_EXTENSION_EVENTID:
3277 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3278 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3280 case WMI_CAC_EVENTID:
3281 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3282 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3284 case WMI_CHANNEL_CHANGE_EVENTID:
3285 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3287 case WMI_REPORT_ROAM_DATA_EVENTID:
3288 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3290 case WMI_TEST_EVENTID:
3291 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
3292 ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
3294 case WMI_GET_FIXRATES_CMDID:
3295 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3296 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3298 case WMI_TX_RETRY_ERR_EVENTID:
3299 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3301 case WMI_SNR_THRESHOLD_EVENTID:
3302 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3303 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3305 case WMI_LQ_THRESHOLD_EVENTID:
3306 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3308 case WMI_APLIST_EVENTID:
3309 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3310 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3312 case WMI_GET_KEEPALIVE_CMDID:
3313 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3314 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3316 case WMI_GET_WOW_LIST_EVENTID:
3317 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
3319 case WMI_GET_PMKID_LIST_EVENTID:
3320 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3321 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3323 case WMI_PSPOLL_EVENTID:
3324 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3325 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3327 case WMI_DTIMEXPIRY_EVENTID:
3328 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3329 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3331 case WMI_SET_PARAMS_REPLY_EVENTID:
3332 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3334 case WMI_ADDBA_REQ_EVENTID:
3335 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3336 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3338 case WMI_ADDBA_RESP_EVENTID:
3339 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3341 case WMI_DELBA_REQ_EVENTID:
3342 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3343 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3345 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3346 ath6kl_dbg(ATH6KL_DBG_WMI,
3347 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3349 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3350 ath6kl_dbg(ATH6KL_DBG_WMI,
3351 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3353 case WMI_TX_COMPLETE_EVENTID:
3354 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3355 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3357 case WMI_REMAIN_ON_CHNL_EVENTID:
3358 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3359 ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3361 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3362 ath6kl_dbg(ATH6KL_DBG_WMI,
3363 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3364 ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3367 case WMI_TX_STATUS_EVENTID:
3368 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3369 ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3371 case WMI_RX_PROBE_REQ_EVENTID:
3372 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3373 ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3375 case WMI_P2P_CAPABILITIES_EVENTID:
3376 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3377 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3379 case WMI_RX_ACTION_EVENTID:
3380 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3381 ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
3383 case WMI_P2P_INFO_EVENTID:
3384 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3385 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3388 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
3398 void ath6kl_wmi_reset(struct wmi *wmi)
3400 spin_lock_bh(&wmi->lock);
3402 wmi->fat_pipe_exist = 0;
3403 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3405 spin_unlock_bh(&wmi->lock);
3408 void *ath6kl_wmi_init(struct ath6kl *dev)
3412 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3416 spin_lock_init(&wmi->lock);
3418 wmi->parent_dev = dev;
3420 wmi->pwr_mode = REC_POWER;
3422 ath6kl_wmi_reset(wmi);
3427 void ath6kl_wmi_shutdown(struct wmi *wmi)
3432 kfree(wmi->last_mgmt_tx_frame);