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.
21 static int ath6kl_wmi_sync_point(struct wmi *wmi);
23 static const s32 wmi_rate_tbl[][2] = {
24 /* {W/O SGI, with SGI} */
56 /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
57 static const u8 up_to_ac[] = {
68 void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
70 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
76 enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
81 /* Performs DIX to 802.3 encapsulation for transmit packets.
82 * Assumes the entire DIX header is contigous and that there is
83 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
85 int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
87 struct ath6kl_llc_snap_hdr *llc_hdr;
88 struct ethhdr *eth_hdr;
94 if (WARN_ON(skb == NULL))
97 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
98 if (skb_headroom(skb) < size)
101 eth_hdr = (struct ethhdr *) skb->data;
102 type = eth_hdr->h_proto;
104 if (!is_ethertype(be16_to_cpu(type))) {
105 ath6kl_dbg(ATH6KL_DBG_WMI,
106 "%s: pkt is already in 802.3 format\n", __func__);
110 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
112 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
115 eth_hdr->h_proto = cpu_to_be16(new_len);
117 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
119 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
120 llc_hdr->dsap = 0xAA;
121 llc_hdr->ssap = 0xAA;
122 llc_hdr->cntl = 0x03;
123 llc_hdr->org_code[0] = 0x0;
124 llc_hdr->org_code[1] = 0x0;
125 llc_hdr->org_code[2] = 0x0;
126 llc_hdr->eth_type = type;
131 static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
132 u8 *version, void *tx_meta_info)
134 struct wmi_tx_meta_v1 *v1;
135 struct wmi_tx_meta_v2 *v2;
137 if (WARN_ON(skb == NULL || version == NULL))
141 case WMI_META_VERSION_1:
142 skb_push(skb, WMI_MAX_TX_META_SZ);
143 v1 = (struct wmi_tx_meta_v1 *) skb->data;
145 v1->rate_plcy_id = 0;
146 *version = WMI_META_VERSION_1;
148 case WMI_META_VERSION_2:
149 skb_push(skb, WMI_MAX_TX_META_SZ);
150 v2 = (struct wmi_tx_meta_v2 *) skb->data;
151 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
152 sizeof(struct wmi_tx_meta_v2));
159 int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
160 u8 msg_type, bool more_data,
161 enum wmi_data_hdr_data_type data_type,
162 u8 meta_ver, void *tx_meta_info)
164 struct wmi_data_hdr *data_hdr;
167 if (WARN_ON(skb == NULL))
171 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
176 skb_push(skb, sizeof(struct wmi_data_hdr));
178 data_hdr = (struct wmi_data_hdr *)skb->data;
179 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
181 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
182 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
186 WMI_DATA_HDR_MORE_MASK << WMI_DATA_HDR_MORE_SHIFT;
188 data_hdr->info2 = cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
194 static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
196 struct iphdr *ip_hdr = (struct iphdr *) pkt;
200 * Determine IPTOS priority
203 * : DSCP(6-bits) ECN(2-bits)
204 * : DSCP - P2 P1 P0 X X X
205 * where (P2 P1 P0) form 802.1D
207 ip_pri = ip_hdr->tos >> 5;
210 if ((layer2_pri & 0x7) > ip_pri)
211 return (u8) layer2_pri & 0x7;
216 int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
217 u32 layer2_priority, bool wmm_enabled,
220 struct wmi_data_hdr *data_hdr;
221 struct ath6kl_llc_snap_hdr *llc_hdr;
222 struct wmi_create_pstream_cmd cmd;
223 u32 meta_size, hdr_size;
224 u16 ip_type = IP_ETHERTYPE;
225 u8 stream_exist, usr_pri;
226 u8 traffic_class = WMM_AC_BE;
229 if (WARN_ON(skb == NULL))
233 data_hdr = (struct wmi_data_hdr *) datap;
235 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
236 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
239 /* If WMM is disabled all traffic goes as BE traffic */
242 hdr_size = sizeof(struct ethhdr);
244 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
247 meta_size + hdr_size);
249 if (llc_hdr->eth_type == htons(ip_type)) {
251 * Extract the endpoint info from the TOS field
255 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
256 sizeof(struct ath6kl_llc_snap_hdr),
259 usr_pri = layer2_priority & 0x7;
262 /* workaround for WMM S5 */
263 if ((wmi->traffic_class == WMM_AC_VI) &&
264 ((usr_pri == 5) || (usr_pri == 4)))
267 /* Convert user priority to traffic class */
268 traffic_class = up_to_ac[usr_pri & 0x7];
270 wmi_data_hdr_set_up(data_hdr, usr_pri);
272 spin_lock_bh(&wmi->lock);
273 stream_exist = wmi->fat_pipe_exist;
274 spin_unlock_bh(&wmi->lock);
276 if (!(stream_exist & (1 << traffic_class))) {
277 memset(&cmd, 0, sizeof(cmd));
278 cmd.traffic_class = traffic_class;
279 cmd.user_pri = usr_pri;
281 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
282 /* Implicit streams are created with TSID 0xFF */
283 cmd.tsid = WMI_IMPLICIT_PSTREAM;
284 ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
292 int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
294 struct ieee80211_hdr_3addr *pwh, wh;
295 struct ath6kl_llc_snap_hdr *llc_hdr;
296 struct ethhdr eth_hdr;
301 if (WARN_ON(skb == NULL))
305 pwh = (struct ieee80211_hdr_3addr *) datap;
307 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
309 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
311 /* Strip off the 802.11 header */
312 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
313 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
315 skb_pull(skb, hdr_size);
316 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
317 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
320 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
322 memset(ð_hdr, 0, sizeof(eth_hdr));
323 eth_hdr.h_proto = llc_hdr->eth_type;
325 switch ((le16_to_cpu(wh.frame_control)) &
326 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
328 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
329 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
331 case IEEE80211_FCTL_TODS:
332 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
333 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
335 case IEEE80211_FCTL_FROMDS:
336 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
337 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
339 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
343 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
344 skb_push(skb, sizeof(eth_hdr));
348 memcpy(datap, ð_hdr, sizeof(eth_hdr));
354 * Performs 802.3 to DIX encapsulation for received packets.
355 * Assumes the entire 802.3 header is contigous.
357 int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
359 struct ath6kl_llc_snap_hdr *llc_hdr;
360 struct ethhdr eth_hdr;
363 if (WARN_ON(skb == NULL))
368 memcpy(ð_hdr, datap, sizeof(eth_hdr));
370 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
371 eth_hdr.h_proto = llc_hdr->eth_type;
373 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
376 memcpy(datap, ð_hdr, sizeof(eth_hdr));
381 static void ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(struct sk_buff *skb,
384 struct wmi_bss_info_hdr2 bih2;
385 struct wmi_bss_info_hdr *bih;
387 memcpy(&bih2, datap, sizeof(struct wmi_bss_info_hdr2));
390 bih = (struct wmi_bss_info_hdr *) skb->data;
393 bih->frame_type = bih2.frame_type;
395 bih->rssi = a_cpu_to_sle16(bih2.snr - 95);
396 bih->ie_mask = cpu_to_le32(le16_to_cpu(bih2.ie_mask));
397 memcpy(bih->bssid, bih2.bssid, ETH_ALEN);
400 static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
402 struct tx_complete_msg_v1 *msg_v1;
403 struct wmi_tx_complete_event *evt;
407 evt = (struct wmi_tx_complete_event *) datap;
409 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
410 evt->num_msg, evt->msg_len, evt->msg_type);
412 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
415 for (index = 0; index < evt->num_msg; index++) {
416 size = sizeof(struct wmi_tx_complete_event) +
417 (index * sizeof(struct tx_complete_msg_v1));
418 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
420 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
421 msg_v1->status, msg_v1->pkt_id,
422 msg_v1->rate_idx, msg_v1->ack_failures);
428 static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
432 skb = ath6kl_buf_alloc(size);
438 memset(skb->data, 0, size);
443 /* Send a "simple" wmi command -- one with no arguments */
444 static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
449 skb = ath6kl_wmi_get_new_buf(0);
453 ret = ath6kl_wmi_cmd_send(wmi, skb, cmd_id, NO_SYNC_WMIFLAG);
458 static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
460 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
462 if (len < sizeof(struct wmi_ready_event_2))
466 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
467 le32_to_cpu(ev->sw_version),
468 le32_to_cpu(ev->abi_version));
473 static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
475 struct wmi_connect_event *ev;
478 if (len < sizeof(struct wmi_connect_event))
481 ev = (struct wmi_connect_event *) datap;
483 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM\n",
484 __func__, ev->ch, ev->bssid);
486 /* Start of assoc rsp IEs */
487 pie = ev->assoc_info + ev->beacon_ie_len +
488 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
490 /* End of assoc rsp IEs */
491 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
496 case WLAN_EID_VENDOR_SPECIFIC:
497 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
498 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
499 /* WMM OUT (00:50:F2) */
501 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
502 wmi->is_wmm_enabled = true;
507 if (wmi->is_wmm_enabled)
513 ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->ch), ev->bssid,
514 le16_to_cpu(ev->listen_intvl),
515 le16_to_cpu(ev->beacon_intvl),
516 le32_to_cpu(ev->nw_type),
517 ev->beacon_ie_len, ev->assoc_req_len,
518 ev->assoc_resp_len, ev->assoc_info);
523 static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
525 struct wmi_disconnect_event *ev;
526 wmi->traffic_class = 100;
528 if (len < sizeof(struct wmi_disconnect_event))
531 ev = (struct wmi_disconnect_event *) datap;
533 wmi->is_wmm_enabled = false;
534 wmi->pair_crypto_type = NONE_CRYPT;
535 wmi->grp_crypto_type = NONE_CRYPT;
537 ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
538 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
539 le16_to_cpu(ev->proto_reason_status));
544 static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
546 struct wmi_peer_node_event *ev;
548 if (len < sizeof(struct wmi_peer_node_event))
551 ev = (struct wmi_peer_node_event *) datap;
553 if (ev->event_code == PEER_NODE_JOIN_EVENT)
554 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
556 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
557 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
563 static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
565 struct wmi_tkip_micerr_event *ev;
567 if (len < sizeof(struct wmi_tkip_micerr_event))
570 ev = (struct wmi_tkip_micerr_event *) datap;
572 ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
577 static int ath6kl_wlan_parse_beacon(u8 *buf, int frame_len,
578 struct ath6kl_common_ie *cie)
581 u8 elemid_ssid = false;
584 efrm = (u8 *) (frm + frame_len);
587 * beacon/probe response frame format
589 * [2] beacon interval
590 * [2] capability information
592 * [tlv] supported rates
593 * [tlv] country information
594 * [tlv] parameter set (FH/DS)
595 * [tlv] erp information
596 * [tlv] extended supported rates
599 * [tlv] Atheros Advanced Capabilities
601 if ((efrm - frm) < 12)
604 memset(cie, 0, sizeof(*cie));
606 cie->ie_tstamp = frm;
608 cie->ie_beaconInt = *(u16 *) frm;
610 cie->ie_capInfo = *(u16 *) frm;
622 case WLAN_EID_SUPP_RATES:
625 case WLAN_EID_COUNTRY:
626 cie->ie_country = frm;
628 case WLAN_EID_FH_PARAMS:
630 case WLAN_EID_DS_PARAMS:
631 cie->ie_chan = frm[2];
636 case WLAN_EID_IBSS_PARAMS:
638 case WLAN_EID_EXT_SUPP_RATES:
639 cie->ie_xrates = frm;
641 case WLAN_EID_ERP_INFO:
645 cie->ie_erp = frm[2];
650 case WLAN_EID_HT_CAPABILITY:
653 case WLAN_EID_HT_INFORMATION:
656 case WLAN_EID_VENDOR_SPECIFIC:
657 if (frm[1] > 3 && frm[2] == 0x00 && frm[3] == 0x50 &&
659 /* OUT Type (00:50:F2) */
661 if (frm[5] == WPA_OUI_TYPE) {
664 } else if (frm[5] == WMM_OUI_TYPE) {
667 } else if (frm[5] == WSC_OUT_TYPE) {
672 } else if (frm[1] > 3 && frm[2] == 0x00
673 && frm[3] == 0x03 && frm[4] == 0x7f
674 && frm[5] == ATH_OUI_TYPE) {
675 /* Atheros OUI (00:03:7f) */
685 if ((cie->ie_rates == NULL)
686 || (cie->ie_rates[1] > ATH6KL_RATE_MAXSIZE))
689 if ((cie->ie_ssid == NULL)
690 || (cie->ie_ssid[1] > IEEE80211_MAX_SSID_LEN))
696 static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
698 struct bss *bss = NULL;
699 struct wmi_bss_info_hdr *bih;
700 u8 cached_ssid_len = 0;
701 u8 cached_ssid[IEEE80211_MAX_SSID_LEN] = { 0 };
702 u8 beacon_ssid_len = 0;
709 if (len <= sizeof(struct wmi_bss_info_hdr))
712 bih = (struct wmi_bss_info_hdr *) datap;
713 bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
715 if (a_sle16_to_cpu(bih->rssi) > 0) {
719 bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
722 buf = datap + sizeof(struct wmi_bss_info_hdr);
723 len -= sizeof(struct wmi_bss_info_hdr);
725 ath6kl_dbg(ATH6KL_DBG_WMI,
726 "bss info evt - ch %u, rssi %02x, bssid \"%pM\"\n",
727 bih->ch, a_sle16_to_cpu(bih->rssi), bih->bssid);
731 * Free up the node. We are about to allocate a new node.
732 * In case of hidden AP, beacon will not have ssid,
733 * but a directed probe response will have it,
734 * so cache the probe-resp-ssid if already present.
736 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE)) {
737 ie_ssid = bss->ni_cie.ie_ssid;
738 if (ie_ssid && (ie_ssid[1] <= IEEE80211_MAX_SSID_LEN) &&
740 cached_ssid_len = ie_ssid[1];
741 memcpy(cached_ssid, ie_ssid + 2,
747 * Use the current average rssi of associated AP base on
749 * 1. Most os with GUI will update RSSI by
750 * ath6kl_wmi_get_stats_cmd() periodically.
751 * 2. ath6kl_wmi_get_stats_cmd(..) will be called when calling
752 * ath6kl_wmi_startscan_cmd(...)
753 * The average value of RSSI give end-user better feeling for
754 * instance value of scan result. It also sync up RSSI info
755 * in GUI between scan result and RSSI signal icon.
757 if (memcmp(wmi->parent_dev->bssid, bih->bssid, ETH_ALEN) == 0) {
758 bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
759 bih->snr = bss->ni_snr;
762 wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
766 * beacon/probe response frame format
768 * [2] beacon interval
769 * [2] capability information
772 beacon_ssid_len = buf[SSID_IE_LEN_INDEX];
775 * If ssid is cached for this hidden AP, then change
776 * buffer len accordingly.
778 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
779 (cached_ssid_len != 0) &&
780 (beacon_ssid_len == 0 || (cached_ssid_len > beacon_ssid_len &&
781 buf[SSID_IE_LEN_INDEX + 1] == 0))) {
783 len += (cached_ssid_len - beacon_ssid_len);
786 bss = wlan_node_alloc(len);
790 bss->ni_snr = bih->snr;
791 bss->ni_rssi = a_sle16_to_cpu(bih->rssi);
793 if (WARN_ON(!bss->ni_buf))
797 * In case of hidden AP, beacon will not have ssid,
798 * but a directed probe response will have it,
799 * so place the cached-ssid(probe-resp) in the bss info.
801 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
802 (cached_ssid_len != 0) &&
803 (beacon_ssid_len == 0 || (beacon_ssid_len &&
804 buf[SSID_IE_LEN_INDEX + 1] == 0))) {
805 ni_buf = bss->ni_buf;
809 * Copy the first 14 bytes:
810 * time-stamp(8), beacon-interval(2),
811 * cap-info(2), ssid-id(1), ssid-len(1).
813 memcpy(ni_buf, buf, SSID_IE_LEN_INDEX + 1);
815 ni_buf[SSID_IE_LEN_INDEX] = cached_ssid_len;
816 ni_buf += (SSID_IE_LEN_INDEX + 1);
818 buf += (SSID_IE_LEN_INDEX + 1);
819 buf_len -= (SSID_IE_LEN_INDEX + 1);
821 memcpy(ni_buf, cached_ssid, cached_ssid_len);
822 ni_buf += cached_ssid_len;
824 buf += beacon_ssid_len;
825 buf_len -= beacon_ssid_len;
827 if (cached_ssid_len > beacon_ssid_len)
828 buf_len -= (cached_ssid_len - beacon_ssid_len);
830 memcpy(ni_buf, buf, buf_len);
832 memcpy(bss->ni_buf, buf, len);
834 bss->ni_framelen = len;
836 ret = ath6kl_wlan_parse_beacon(bss->ni_buf, len, &bss->ni_cie);
843 * Update the frequency in ie_chan, overwriting of channel number
844 * which is done in ath6kl_wlan_parse_beacon
846 bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
847 wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
852 static int ath6kl_wmi_opt_frame_event_rx(struct wmi *wmi, u8 *datap, int len)
855 struct wmi_opt_rx_info_hdr *bih;
858 if (len <= sizeof(struct wmi_opt_rx_info_hdr))
861 bih = (struct wmi_opt_rx_info_hdr *) datap;
862 buf = datap + sizeof(struct wmi_opt_rx_info_hdr);
863 len -= sizeof(struct wmi_opt_rx_info_hdr);
865 ath6kl_dbg(ATH6KL_DBG_WMI, "opt frame event %2.2x:%2.2x\n",
866 bih->bssid[4], bih->bssid[5]);
868 bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
870 /* Free up the node. We are about to allocate a new node. */
871 wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
874 bss = wlan_node_alloc(len);
878 bss->ni_snr = bih->snr;
879 bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
881 if (WARN_ON(!bss->ni_buf))
884 memcpy(bss->ni_buf, buf, len);
885 wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
890 /* Inactivity timeout of a fatpipe(pstream) at the target */
891 static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
894 struct wmi_pstream_timeout_event *ev;
896 if (len < sizeof(struct wmi_pstream_timeout_event))
899 ev = (struct wmi_pstream_timeout_event *) datap;
902 * When the pstream (fat pipe == AC) timesout, it means there were
903 * no thinStreams within this pstream & it got implicitly created
904 * due to data flow on this AC. We start the inactivity timer only
905 * for implicitly created pstream. Just reset the host state.
907 spin_lock_bh(&wmi->lock);
908 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
909 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
910 spin_unlock_bh(&wmi->lock);
912 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
913 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
918 static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
920 struct wmi_bit_rate_reply *reply;
924 if (len < sizeof(struct wmi_bit_rate_reply))
927 reply = (struct wmi_bit_rate_reply *) datap;
929 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
931 if (reply->rate_index == (s8) RATE_AUTO) {
934 index = reply->rate_index & 0x7f;
935 sgi = (reply->rate_index & 0x80) ? 1 : 0;
936 rate = wmi_rate_tbl[index][sgi];
939 ath6kl_wakeup_event(wmi->parent_dev);
944 static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
946 if (len < sizeof(struct wmi_fix_rates_reply))
949 ath6kl_wakeup_event(wmi->parent_dev);
954 static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
956 if (len < sizeof(struct wmi_channel_list_reply))
959 ath6kl_wakeup_event(wmi->parent_dev);
964 static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
966 struct wmi_tx_pwr_reply *reply;
968 if (len < sizeof(struct wmi_tx_pwr_reply))
971 reply = (struct wmi_tx_pwr_reply *) datap;
972 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
977 static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
979 if (len < sizeof(struct wmi_get_keepalive_cmd))
982 ath6kl_wakeup_event(wmi->parent_dev);
987 static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
989 struct wmi_scan_complete_event *ev;
991 ev = (struct wmi_scan_complete_event *) datap;
993 if (a_sle32_to_cpu(ev->status) == 0)
994 wlan_refresh_inactive_nodes(wmi->parent_dev);
996 ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
997 wmi->is_probe_ssid = false;
1003 * Target is reporting a programming error. This is for
1004 * developer aid only. Target only checks a few common violations
1005 * and it is responsibility of host to do all error checking.
1006 * Behavior of target after wmi error event is undefined.
1007 * A reset is recommended.
1009 static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1011 const char *type = "unknown error";
1012 struct wmi_cmd_error_event *ev;
1013 ev = (struct wmi_cmd_error_event *) datap;
1015 switch (ev->err_code) {
1017 type = "invalid parameter";
1020 type = "invalid state";
1022 case INTERNAL_ERROR:
1023 type = "internal error";
1027 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1033 static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
1035 ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
1040 static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1041 struct sq_threshold_params *sq_thresh,
1045 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1047 /* The list is already in sorted order. Get the next lower value */
1048 for (index = 0; index < size; index++) {
1049 if (rssi < sq_thresh->upper_threshold[index]) {
1050 threshold = (u8) sq_thresh->upper_threshold[index];
1058 static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1059 struct sq_threshold_params *sq_thresh,
1063 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1065 /* The list is already in sorted order. Get the next lower value */
1066 for (index = 0; index < size; index++) {
1067 if (rssi > sq_thresh->lower_threshold[index]) {
1068 threshold = (u8) sq_thresh->lower_threshold[index];
1076 static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1077 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1079 struct sk_buff *skb;
1080 struct wmi_rssi_threshold_params_cmd *cmd;
1082 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1086 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1087 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1089 return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1093 static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1096 struct wmi_rssi_threshold_event *reply;
1097 struct wmi_rssi_threshold_params_cmd cmd;
1098 struct sq_threshold_params *sq_thresh;
1099 enum wmi_rssi_threshold_val new_threshold;
1100 u8 upper_rssi_threshold, lower_rssi_threshold;
1104 if (len < sizeof(struct wmi_rssi_threshold_event))
1107 reply = (struct wmi_rssi_threshold_event *) datap;
1108 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1109 rssi = a_sle16_to_cpu(reply->rssi);
1111 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1114 * Identify the threshold breached and communicate that to the app.
1115 * After that install a new set of thresholds based on the signal
1116 * quality reported by the target
1118 if (new_threshold) {
1119 /* Upper threshold breached */
1120 if (rssi < sq_thresh->upper_threshold[0]) {
1121 ath6kl_dbg(ATH6KL_DBG_WMI,
1122 "spurious upper rssi threshold event: %d\n",
1124 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1125 (rssi >= sq_thresh->upper_threshold[0])) {
1126 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1127 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1128 (rssi >= sq_thresh->upper_threshold[1])) {
1129 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1130 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1131 (rssi >= sq_thresh->upper_threshold[2])) {
1132 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1133 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1134 (rssi >= sq_thresh->upper_threshold[3])) {
1135 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1136 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1137 (rssi >= sq_thresh->upper_threshold[4])) {
1138 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1139 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1140 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1143 /* Lower threshold breached */
1144 if (rssi > sq_thresh->lower_threshold[0]) {
1145 ath6kl_dbg(ATH6KL_DBG_WMI,
1146 "spurious lower rssi threshold event: %d %d\n",
1147 rssi, sq_thresh->lower_threshold[0]);
1148 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1149 (rssi <= sq_thresh->lower_threshold[0])) {
1150 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1151 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1152 (rssi <= sq_thresh->lower_threshold[1])) {
1153 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1154 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1155 (rssi <= sq_thresh->lower_threshold[2])) {
1156 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1157 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1158 (rssi <= sq_thresh->lower_threshold[3])) {
1159 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1160 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1161 (rssi <= sq_thresh->lower_threshold[4])) {
1162 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1163 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1164 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1168 /* Calculate and install the next set of thresholds */
1169 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1170 sq_thresh->lower_threshold_valid_count);
1171 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1172 sq_thresh->upper_threshold_valid_count);
1174 /* Issue a wmi command to install the thresholds */
1175 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1176 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1177 cmd.weight = sq_thresh->weight;
1178 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1180 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1182 ath6kl_err("unable to configure rssi thresholds\n");
1189 static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
1191 struct wmi_cac_event *reply;
1192 struct ieee80211_tspec_ie *ts;
1193 u16 active_tsids, tsinfo;
1197 if (len < sizeof(struct wmi_cac_event))
1200 reply = (struct wmi_cac_event *) datap;
1202 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1203 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1205 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1206 tsinfo = le16_to_cpu(ts->tsinfo);
1207 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1208 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1210 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
1211 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1213 * Following assumes that there is only one outstanding
1214 * ADDTS request when this event is received
1216 spin_lock_bh(&wmi->lock);
1217 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1218 spin_unlock_bh(&wmi->lock);
1220 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1221 if ((active_tsids >> index) & 1)
1224 if (index < (sizeof(active_tsids) * 8))
1225 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
1229 * Clear active tsids and Add missing handling
1230 * for delete qos stream from AP
1232 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1234 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1235 tsinfo = le16_to_cpu(ts->tsinfo);
1236 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1237 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1239 spin_lock_bh(&wmi->lock);
1240 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1241 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1242 spin_unlock_bh(&wmi->lock);
1244 /* Indicate stream inactivity to driver layer only if all tsids
1245 * within this AC are deleted.
1247 if (!active_tsids) {
1248 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1250 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1257 static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1258 struct wmi_snr_threshold_params_cmd *snr_cmd)
1260 struct sk_buff *skb;
1261 struct wmi_snr_threshold_params_cmd *cmd;
1263 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1267 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1268 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1270 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1274 static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1277 struct wmi_snr_threshold_event *reply;
1278 struct sq_threshold_params *sq_thresh;
1279 struct wmi_snr_threshold_params_cmd cmd;
1280 enum wmi_snr_threshold_val new_threshold;
1281 u8 upper_snr_threshold, lower_snr_threshold;
1285 if (len < sizeof(struct wmi_snr_threshold_event))
1288 reply = (struct wmi_snr_threshold_event *) datap;
1290 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1293 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1296 * Identify the threshold breached and communicate that to the app.
1297 * After that install a new set of thresholds based on the signal
1298 * quality reported by the target.
1300 if (new_threshold) {
1301 /* Upper threshold breached */
1302 if (snr < sq_thresh->upper_threshold[0]) {
1303 ath6kl_dbg(ATH6KL_DBG_WMI,
1304 "spurious upper snr threshold event: %d\n",
1306 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1307 (snr >= sq_thresh->upper_threshold[0])) {
1308 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1309 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1310 (snr >= sq_thresh->upper_threshold[1])) {
1311 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1312 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1313 (snr >= sq_thresh->upper_threshold[2])) {
1314 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1315 } else if (snr >= sq_thresh->upper_threshold[3]) {
1316 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1319 /* Lower threshold breached */
1320 if (snr > sq_thresh->lower_threshold[0]) {
1321 ath6kl_dbg(ATH6KL_DBG_WMI,
1322 "spurious lower snr threshold event: %d\n",
1323 sq_thresh->lower_threshold[0]);
1324 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1325 (snr <= sq_thresh->lower_threshold[0])) {
1326 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1327 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1328 (snr <= sq_thresh->lower_threshold[1])) {
1329 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1330 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1331 (snr <= sq_thresh->lower_threshold[2])) {
1332 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1333 } else if (snr <= sq_thresh->lower_threshold[3]) {
1334 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1338 /* Calculate and install the next set of thresholds */
1339 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1340 sq_thresh->lower_threshold_valid_count);
1341 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1342 sq_thresh->upper_threshold_valid_count);
1344 /* Issue a wmi command to install the thresholds */
1345 cmd.thresh_above1_val = upper_snr_threshold;
1346 cmd.thresh_below1_val = lower_snr_threshold;
1347 cmd.weight = sq_thresh->weight;
1348 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1350 ath6kl_dbg(ATH6KL_DBG_WMI,
1351 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1353 lower_snr_threshold, upper_snr_threshold);
1355 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1357 ath6kl_err("unable to configure snr threshold\n");
1364 static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1366 u16 ap_info_entry_size;
1367 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1368 struct wmi_ap_info_v1 *ap_info_v1;
1371 if (len < sizeof(struct wmi_aplist_event) ||
1372 ev->ap_list_ver != APLIST_VER1)
1375 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1376 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1378 ath6kl_dbg(ATH6KL_DBG_WMI,
1379 "number of APs in aplist event: %d\n", ev->num_ap);
1381 if (len < (int) (sizeof(struct wmi_aplist_event) +
1382 (ev->num_ap - 1) * ap_info_entry_size))
1385 /* AP list version 1 contents */
1386 for (index = 0; index < ev->num_ap; index++) {
1387 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1388 index, ap_info_v1->bssid, ap_info_v1->channel);
1395 int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
1396 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1398 struct wmi_cmd_hdr *cmd_hdr;
1399 enum htc_endpoint_id ep_id = wmi->ep_id;
1402 if (WARN_ON(skb == NULL))
1405 if (sync_flag >= END_WMIFLAG) {
1410 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1411 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1413 * Make sure all data currently queued is transmitted before
1414 * the cmd execution. Establish a new sync point.
1416 ath6kl_wmi_sync_point(wmi);
1419 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1421 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1422 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1423 cmd_hdr->info1 = 0; /* added for virtual interface */
1425 /* Only for OPT_TX_CMD, use BE endpoint. */
1426 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1427 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1428 false, false, 0, NULL);
1433 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1436 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1438 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1439 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1441 * Make sure all new data queued waits for the command to
1442 * execute. Establish a new sync point.
1444 ath6kl_wmi_sync_point(wmi);
1450 int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
1451 enum dot11_auth_mode dot11_auth_mode,
1452 enum auth_mode auth_mode,
1453 enum crypto_type pairwise_crypto,
1454 u8 pairwise_crypto_len,
1455 enum crypto_type group_crypto,
1456 u8 group_crypto_len, int ssid_len, u8 *ssid,
1457 u8 *bssid, u16 channel, u32 ctrl_flags)
1459 struct sk_buff *skb;
1460 struct wmi_connect_cmd *cc;
1463 wmi->traffic_class = 100;
1465 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1468 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1471 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1475 cc = (struct wmi_connect_cmd *) skb->data;
1478 memcpy(cc->ssid, ssid, ssid_len);
1480 cc->ssid_len = ssid_len;
1481 cc->nw_type = nw_type;
1482 cc->dot11_auth_mode = dot11_auth_mode;
1483 cc->auth_mode = auth_mode;
1484 cc->prwise_crypto_type = pairwise_crypto;
1485 cc->prwise_crypto_len = pairwise_crypto_len;
1486 cc->grp_crypto_type = group_crypto;
1487 cc->grp_crypto_len = group_crypto_len;
1488 cc->ch = cpu_to_le16(channel);
1489 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1492 memcpy(cc->bssid, bssid, ETH_ALEN);
1494 wmi->pair_crypto_type = pairwise_crypto;
1495 wmi->grp_crypto_type = group_crypto;
1497 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
1502 int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
1504 struct sk_buff *skb;
1505 struct wmi_reconnect_cmd *cc;
1508 wmi->traffic_class = 100;
1510 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1514 cc = (struct wmi_reconnect_cmd *) skb->data;
1515 cc->channel = cpu_to_le16(channel);
1518 memcpy(cc->bssid, bssid, ETH_ALEN);
1520 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
1526 int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
1530 wmi->traffic_class = 100;
1532 /* Disconnect command does not need to do a SYNC before. */
1533 ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
1538 int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
1539 u32 force_fgscan, u32 is_legacy,
1540 u32 home_dwell_time, u32 force_scan_interval,
1541 s8 num_chan, u16 *ch_list)
1543 struct sk_buff *skb;
1544 struct wmi_start_scan_cmd *sc;
1548 size = sizeof(struct wmi_start_scan_cmd);
1550 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1553 if (num_chan > WMI_MAX_CHANNELS)
1557 size += sizeof(u16) * (num_chan - 1);
1559 skb = ath6kl_wmi_get_new_buf(size);
1563 sc = (struct wmi_start_scan_cmd *) skb->data;
1564 sc->scan_type = scan_type;
1565 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1566 sc->is_legacy = cpu_to_le32(is_legacy);
1567 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1568 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1569 sc->num_ch = num_chan;
1572 memcpy(sc->ch_list, ch_list, num_chan * sizeof(u16));
1574 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
1580 int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
1581 u16 fg_end_sec, u16 bg_sec,
1582 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1583 u16 pas_chdw_msec, u8 short_scan_ratio,
1584 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1585 u16 maxact_scan_per_ssid)
1587 struct sk_buff *skb;
1588 struct wmi_scan_params_cmd *sc;
1591 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1595 sc = (struct wmi_scan_params_cmd *) skb->data;
1596 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1597 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1598 sc->bg_period = cpu_to_le16(bg_sec);
1599 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1600 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1601 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1602 sc->short_scan_ratio = short_scan_ratio;
1603 sc->scan_ctrl_flags = scan_ctrl_flag;
1604 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1605 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1607 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
1612 int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
1614 struct sk_buff *skb;
1615 struct wmi_bss_filter_cmd *cmd;
1618 if (filter >= LAST_BSS_FILTER)
1621 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1625 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1626 cmd->bss_filter = filter;
1627 cmd->ie_mask = cpu_to_le32(ie_mask);
1629 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
1634 int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
1635 u8 ssid_len, u8 *ssid)
1637 struct sk_buff *skb;
1638 struct wmi_probed_ssid_cmd *cmd;
1641 if (index > MAX_PROBED_SSID_INDEX)
1644 if (ssid_len > sizeof(cmd->ssid))
1647 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1650 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1653 if (flag & SPECIFIC_SSID_FLAG)
1654 wmi->is_probe_ssid = true;
1656 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1660 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1661 cmd->entry_index = index;
1663 cmd->ssid_len = ssid_len;
1664 memcpy(cmd->ssid, ssid, ssid_len);
1666 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
1671 int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
1674 struct sk_buff *skb;
1675 struct wmi_listen_int_cmd *cmd;
1678 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1682 cmd = (struct wmi_listen_int_cmd *) skb->data;
1683 cmd->listen_intvl = cpu_to_le16(listen_interval);
1684 cmd->num_beacons = cpu_to_le16(listen_beacons);
1686 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
1691 int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
1693 struct sk_buff *skb;
1694 struct wmi_power_mode_cmd *cmd;
1697 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1701 cmd = (struct wmi_power_mode_cmd *) skb->data;
1702 cmd->pwr_mode = pwr_mode;
1703 wmi->pwr_mode = pwr_mode;
1705 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
1710 int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
1711 u16 ps_poll_num, u16 dtim_policy,
1712 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1713 u16 ps_fail_event_policy)
1715 struct sk_buff *skb;
1716 struct wmi_power_params_cmd *pm;
1719 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1723 pm = (struct wmi_power_params_cmd *)skb->data;
1724 pm->idle_period = cpu_to_le16(idle_period);
1725 pm->pspoll_number = cpu_to_le16(ps_poll_num);
1726 pm->dtim_policy = cpu_to_le16(dtim_policy);
1727 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1728 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1729 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1731 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
1736 int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
1738 struct sk_buff *skb;
1739 struct wmi_disc_timeout_cmd *cmd;
1742 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1746 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
1747 cmd->discon_timeout = timeout;
1749 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
1754 int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
1755 enum crypto_type key_type,
1756 u8 key_usage, u8 key_len,
1757 u8 *key_rsc, u8 *key_material,
1758 u8 key_op_ctrl, u8 *mac_addr,
1759 enum wmi_sync_flag sync_flag)
1761 struct sk_buff *skb;
1762 struct wmi_add_cipher_key_cmd *cmd;
1765 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
1766 (key_material == NULL))
1769 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
1772 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1776 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
1777 cmd->key_index = key_index;
1778 cmd->key_type = key_type;
1779 cmd->key_usage = key_usage;
1780 cmd->key_len = key_len;
1781 memcpy(cmd->key, key_material, key_len);
1783 if (key_rsc != NULL)
1784 memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
1786 cmd->key_op_ctrl = key_op_ctrl;
1789 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
1791 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
1797 int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
1799 struct sk_buff *skb;
1800 struct wmi_add_krk_cmd *cmd;
1803 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1807 cmd = (struct wmi_add_krk_cmd *) skb->data;
1808 memcpy(cmd->krk, krk, WMI_KRK_LEN);
1810 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
1815 int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
1817 struct sk_buff *skb;
1818 struct wmi_delete_cipher_key_cmd *cmd;
1821 if (key_index > WMI_MAX_KEY_INDEX)
1824 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1828 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
1829 cmd->key_index = key_index;
1831 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
1837 int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
1838 const u8 *pmkid, bool set)
1840 struct sk_buff *skb;
1841 struct wmi_setpmkid_cmd *cmd;
1847 if (set && pmkid == NULL)
1850 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1854 cmd = (struct wmi_setpmkid_cmd *) skb->data;
1855 memcpy(cmd->bssid, bssid, ETH_ALEN);
1857 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
1858 cmd->enable = PMKID_ENABLE;
1860 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
1861 cmd->enable = PMKID_DISABLE;
1864 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
1870 static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
1871 enum htc_endpoint_id ep_id)
1873 struct wmi_data_hdr *data_hdr;
1876 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
1879 skb_push(skb, sizeof(struct wmi_data_hdr));
1881 data_hdr = (struct wmi_data_hdr *) skb->data;
1882 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
1883 data_hdr->info3 = 0;
1885 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1890 static int ath6kl_wmi_sync_point(struct wmi *wmi)
1892 struct sk_buff *skb;
1893 struct wmi_sync_cmd *cmd;
1894 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
1895 enum htc_endpoint_id ep_id;
1896 u8 index, num_pri_streams = 0;
1899 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
1901 spin_lock_bh(&wmi->lock);
1903 for (index = 0; index < WMM_NUM_AC; index++) {
1904 if (wmi->fat_pipe_exist & (1 << index)) {
1906 data_sync_bufs[num_pri_streams - 1].traffic_class =
1911 spin_unlock_bh(&wmi->lock);
1913 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1919 cmd = (struct wmi_sync_cmd *) skb->data;
1922 * In the SYNC cmd sent on the control Ep, send a bitmap
1923 * of the data eps on which the Data Sync will be sent
1925 cmd->data_sync_map = wmi->fat_pipe_exist;
1927 for (index = 0; index < num_pri_streams; index++) {
1928 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
1929 if (data_sync_bufs[index].skb == NULL) {
1936 * If buffer allocation for any of the dataSync fails,
1937 * then do not send the Synchronize cmd on the control ep
1943 * Send sync cmd followed by sync data messages on all
1944 * endpoints being used
1946 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
1952 /* cmd buffer sent, we no longer own it */
1955 for (index = 0; index < num_pri_streams; index++) {
1957 if (WARN_ON(!data_sync_bufs[index].skb))
1960 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
1961 data_sync_bufs[index].
1964 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
1970 data_sync_bufs[index].skb = NULL;
1974 /* free up any resources left over (possibly due to an error) */
1978 for (index = 0; index < num_pri_streams; index++) {
1979 if (data_sync_bufs[index].skb != NULL) {
1980 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
1988 int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
1989 struct wmi_create_pstream_cmd *params)
1991 struct sk_buff *skb;
1992 struct wmi_create_pstream_cmd *cmd;
1993 u8 fatpipe_exist_for_ac = 0;
1995 s32 nominal_phy = 0;
1998 if (!((params->user_pri < 8) &&
1999 (params->user_pri <= 0x7) &&
2000 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2001 (params->traffic_direc == UPLINK_TRAFFIC ||
2002 params->traffic_direc == DNLINK_TRAFFIC ||
2003 params->traffic_direc == BIDIR_TRAFFIC) &&
2004 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2005 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2006 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2007 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2008 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2009 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2010 params->tsid <= WMI_MAX_THINSTREAM))) {
2015 * Check nominal PHY rate is >= minimalPHY,
2016 * so that DUT can allow TSRS IE
2019 /* Get the physical rate (units of bps) */
2020 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2022 /* Check minimal phy < nominal phy rate */
2023 if (params->nominal_phy >= min_phy) {
2024 /* unit of 500 kbps */
2025 nominal_phy = (params->nominal_phy * 1000) / 500;
2026 ath6kl_dbg(ATH6KL_DBG_WMI,
2027 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2028 min_phy, nominal_phy);
2030 params->nominal_phy = nominal_phy;
2032 params->nominal_phy = 0;
2035 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2039 ath6kl_dbg(ATH6KL_DBG_WMI,
2040 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2041 params->traffic_class, params->tsid);
2043 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2044 memcpy(cmd, params, sizeof(*cmd));
2046 /* This is an implicitly created Fat pipe */
2047 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2048 spin_lock_bh(&wmi->lock);
2049 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2050 (1 << params->traffic_class));
2051 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2052 spin_unlock_bh(&wmi->lock);
2054 /* explicitly created thin stream within a fat pipe */
2055 spin_lock_bh(&wmi->lock);
2056 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2057 (1 << params->traffic_class));
2058 wmi->stream_exist_for_ac[params->traffic_class] |=
2059 (1 << params->tsid);
2061 * If a thinstream becomes active, the fat pipe automatically
2064 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2065 spin_unlock_bh(&wmi->lock);
2069 * Indicate activty change to driver layer only if this is the
2070 * first TSID to get created in this AC explicitly or an implicit
2071 * fat pipe is getting created.
2073 if (!fatpipe_exist_for_ac)
2074 ath6kl_indicate_tx_activity(wmi->parent_dev,
2075 params->traffic_class, true);
2077 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
2082 int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
2084 struct sk_buff *skb;
2085 struct wmi_delete_pstream_cmd *cmd;
2086 u16 active_tsids = 0;
2089 if (traffic_class > 3) {
2090 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2094 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2098 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2099 cmd->traffic_class = traffic_class;
2102 spin_lock_bh(&wmi->lock);
2103 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2104 spin_unlock_bh(&wmi->lock);
2106 if (!(active_tsids & (1 << tsid))) {
2108 ath6kl_dbg(ATH6KL_DBG_WMI,
2109 "TSID %d doesn't exist for traffic class: %d\n",
2110 tsid, traffic_class);
2114 ath6kl_dbg(ATH6KL_DBG_WMI,
2115 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2116 traffic_class, tsid);
2118 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
2119 SYNC_BEFORE_WMIFLAG);
2121 spin_lock_bh(&wmi->lock);
2122 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2123 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2124 spin_unlock_bh(&wmi->lock);
2127 * Indicate stream inactivity to driver layer only if all tsids
2128 * within this AC are deleted.
2130 if (!active_tsids) {
2131 ath6kl_indicate_tx_activity(wmi->parent_dev,
2132 traffic_class, false);
2133 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2139 int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2141 struct sk_buff *skb;
2142 struct wmi_set_ip_cmd *cmd;
2145 /* Multicast address are not valid */
2146 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2147 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2150 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2154 cmd = (struct wmi_set_ip_cmd *) skb->data;
2155 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2157 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
2161 static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2164 if (len < sizeof(struct wmi_get_wow_list_reply))
2170 static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2171 enum wmix_command_id cmd_id,
2172 enum wmi_sync_flag sync_flag)
2174 struct wmix_cmd_hdr *cmd_hdr;
2177 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2179 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2180 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2182 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
2187 int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2189 struct sk_buff *skb;
2190 struct wmix_hb_challenge_resp_cmd *cmd;
2193 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2197 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2198 cmd->cookie = cpu_to_le32(cookie);
2199 cmd->source = cpu_to_le32(source);
2201 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2206 int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
2208 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
2211 int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
2213 struct sk_buff *skb;
2214 struct wmi_set_tx_pwr_cmd *cmd;
2217 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2221 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2224 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
2230 int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
2232 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
2235 int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
2237 struct sk_buff *skb;
2238 struct wmi_set_lpreamble_cmd *cmd;
2241 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2245 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2246 cmd->status = status;
2247 cmd->preamble_policy = preamble_policy;
2249 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
2254 int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2256 struct sk_buff *skb;
2257 struct wmi_set_rts_cmd *cmd;
2260 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2264 cmd = (struct wmi_set_rts_cmd *) skb->data;
2265 cmd->threshold = cpu_to_le16(threshold);
2267 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
2271 int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
2273 struct sk_buff *skb;
2274 struct wmi_set_wmm_txop_cmd *cmd;
2277 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2280 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2284 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2285 cmd->txop_enable = cfg;
2287 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
2292 int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
2294 struct sk_buff *skb;
2295 struct wmi_set_keepalive_cmd *cmd;
2298 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2302 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2303 cmd->keep_alive_intvl = keep_alive_intvl;
2304 wmi->keep_alive_intvl = keep_alive_intvl;
2306 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
2311 s32 ath6kl_wmi_get_rate(s8 rate_index)
2313 if (rate_index == RATE_AUTO)
2316 return wmi_rate_tbl[(u32) rate_index][0];
2319 void ath6kl_wmi_node_return(struct wmi *wmi, struct bss *bss)
2322 wlan_node_return(&wmi->parent_dev->scan_table, bss);
2325 struct bss *ath6kl_wmi_find_ssid_node(struct wmi *wmi, u8 * ssid,
2326 u32 ssid_len, bool is_wpa2,
2329 struct bss *node = NULL;
2331 node = wlan_find_ssid_node(&wmi->parent_dev->scan_table, ssid,
2332 ssid_len, is_wpa2, match_ssid);
2336 struct bss *ath6kl_wmi_find_node(struct wmi *wmi, const u8 * mac_addr)
2338 struct bss *ni = NULL;
2340 ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
2345 void ath6kl_wmi_node_free(struct wmi *wmi, const u8 * mac_addr)
2347 struct bss *ni = NULL;
2349 ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
2351 wlan_node_reclaim(&wmi->parent_dev->scan_table, ni);
2356 static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2359 struct wmi_pmkid_list_reply *reply;
2362 if (len < sizeof(struct wmi_pmkid_list_reply))
2365 reply = (struct wmi_pmkid_list_reply *)datap;
2366 expected_len = sizeof(reply->num_pmkid) +
2367 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2369 if (len < expected_len)
2375 static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2377 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2379 aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
2380 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2385 static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2387 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2389 aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
2394 /* AP mode functions */
2395 static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
2397 struct wmi_pspoll_event *ev;
2399 if (len < sizeof(struct wmi_pspoll_event))
2402 ev = (struct wmi_pspoll_event *) datap;
2404 ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
2409 static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
2411 ath6kl_dtimexpiry_event(wmi->parent_dev);
2416 int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
2418 struct sk_buff *skb;
2419 struct wmi_ap_set_pvb_cmd *cmd;
2422 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2426 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2427 cmd->aid = cpu_to_le16(aid);
2428 cmd->flag = cpu_to_le32(flag);
2430 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
2436 int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
2437 bool rx_dot11_hdr, bool defrag_on_host)
2439 struct sk_buff *skb;
2440 struct wmi_rx_frame_format_cmd *cmd;
2443 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2447 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2448 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2449 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2450 cmd->meta_ver = rx_meta_ver;
2452 /* Delete the local aggr state, on host */
2453 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
2459 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
2461 struct wmix_cmd_hdr *cmd;
2467 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
2468 ath6kl_err("bad packet 1\n");
2469 wmi->stat.cmd_len_err++;
2473 cmd = (struct wmix_cmd_hdr *) skb->data;
2474 id = le32_to_cpu(cmd->cmd_id);
2476 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
2482 case WMIX_HB_CHALLENGE_RESP_EVENTID:
2484 case WMIX_DBGLOG_EVENTID:
2487 ath6kl_err("unknown cmd id 0x%x\n", id);
2488 wmi->stat.cmd_id_err++;
2497 int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
2499 struct wmi_cmd_hdr *cmd;
2505 if (WARN_ON(skb == NULL))
2508 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
2509 ath6kl_err("bad packet 1\n");
2511 wmi->stat.cmd_len_err++;
2515 cmd = (struct wmi_cmd_hdr *) skb->data;
2516 id = le16_to_cpu(cmd->cmd_id);
2518 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
2523 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: wmi id: %d\n", __func__, id);
2524 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "msg payload ", datap, len);
2527 case WMI_GET_BITRATE_CMDID:
2528 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
2529 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
2531 case WMI_GET_CHANNEL_LIST_CMDID:
2532 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
2533 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
2535 case WMI_GET_TX_PWR_CMDID:
2536 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
2537 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
2539 case WMI_READY_EVENTID:
2540 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
2541 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
2543 case WMI_CONNECT_EVENTID:
2544 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
2545 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
2547 case WMI_DISCONNECT_EVENTID:
2548 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
2549 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
2551 case WMI_PEER_NODE_EVENTID:
2552 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
2553 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
2555 case WMI_TKIP_MICERR_EVENTID:
2556 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
2557 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
2559 case WMI_BSSINFO_EVENTID:
2560 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
2561 ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(skb, datap);
2562 ret = ath6kl_wmi_bssinfo_event_rx(wmi, skb->data, skb->len);
2564 case WMI_REGDOMAIN_EVENTID:
2565 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
2567 case WMI_PSTREAM_TIMEOUT_EVENTID:
2568 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
2569 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
2571 case WMI_NEIGHBOR_REPORT_EVENTID:
2572 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
2574 case WMI_SCAN_COMPLETE_EVENTID:
2575 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
2576 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
2578 case WMI_CMDERROR_EVENTID:
2579 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
2580 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
2582 case WMI_REPORT_STATISTICS_EVENTID:
2583 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
2584 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
2586 case WMI_RSSI_THRESHOLD_EVENTID:
2587 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
2588 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
2590 case WMI_ERROR_REPORT_EVENTID:
2591 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
2593 case WMI_OPT_RX_FRAME_EVENTID:
2594 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
2595 ret = ath6kl_wmi_opt_frame_event_rx(wmi, datap, len);
2597 case WMI_REPORT_ROAM_TBL_EVENTID:
2598 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
2600 case WMI_EXTENSION_EVENTID:
2601 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
2602 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
2604 case WMI_CAC_EVENTID:
2605 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
2606 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
2608 case WMI_CHANNEL_CHANGE_EVENTID:
2609 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
2611 case WMI_REPORT_ROAM_DATA_EVENTID:
2612 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
2614 case WMI_GET_FIXRATES_CMDID:
2615 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
2616 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
2618 case WMI_TX_RETRY_ERR_EVENTID:
2619 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
2621 case WMI_SNR_THRESHOLD_EVENTID:
2622 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
2623 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
2625 case WMI_LQ_THRESHOLD_EVENTID:
2626 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
2628 case WMI_APLIST_EVENTID:
2629 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
2630 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
2632 case WMI_GET_KEEPALIVE_CMDID:
2633 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
2634 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
2636 case WMI_GET_WOW_LIST_EVENTID:
2637 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
2638 ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
2640 case WMI_GET_PMKID_LIST_EVENTID:
2641 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
2642 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
2644 case WMI_PSPOLL_EVENTID:
2645 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
2646 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
2648 case WMI_DTIMEXPIRY_EVENTID:
2649 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
2650 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
2652 case WMI_SET_PARAMS_REPLY_EVENTID:
2653 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
2655 case WMI_ADDBA_REQ_EVENTID:
2656 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
2657 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
2659 case WMI_ADDBA_RESP_EVENTID:
2660 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
2662 case WMI_DELBA_REQ_EVENTID:
2663 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
2664 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
2666 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
2667 ath6kl_dbg(ATH6KL_DBG_WMI,
2668 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
2670 case WMI_REPORT_BTCOEX_STATS_EVENTID:
2671 ath6kl_dbg(ATH6KL_DBG_WMI,
2672 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
2674 case WMI_TX_COMPLETE_EVENTID:
2675 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
2676 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
2679 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
2680 wmi->stat.cmd_id_err++;
2690 static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
2695 spin_lock_bh(&wmi->lock);
2697 wmi->fat_pipe_exist = 0;
2698 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
2700 spin_unlock_bh(&wmi->lock);
2703 void *ath6kl_wmi_init(struct ath6kl *dev)
2707 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
2711 spin_lock_init(&wmi->lock);
2713 wmi->parent_dev = dev;
2715 ath6kl_wmi_qos_state_init(wmi);
2717 wmi->pwr_mode = REC_POWER;
2718 wmi->phy_mode = WMI_11G_MODE;
2720 wmi->pair_crypto_type = NONE_CRYPT;
2721 wmi->grp_crypto_type = NONE_CRYPT;
2723 wmi->ht_allowed[A_BAND_24GHZ] = 1;
2724 wmi->ht_allowed[A_BAND_5GHZ] = 1;
2729 void ath6kl_wmi_shutdown(struct wmi *wmi)