ath6kl: Report unique remain-on-channel cookie values
[linux-2.6.git] / drivers / net / wireless / ath / ath6kl / wmi.c
blobddefc8e4a66b51325093e4f60d7bf6cff1b8895f
1 /*
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.
17 #include <linux/ip.h>
18 #include "core.h"
19 #include "debug.h"
20 #include "testmode.h"
21 #include "../regd.h"
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} */
28 {1000, 1000},
29 {2000, 2000},
30 {5500, 5500},
31 {11000, 11000},
32 {6000, 6000},
33 {9000, 9000},
34 {12000, 12000},
35 {18000, 18000},
36 {24000, 24000},
37 {36000, 36000},
38 {48000, 48000},
39 {54000, 54000},
40 {6500, 7200},
41 {13000, 14400},
42 {19500, 21700},
43 {26000, 28900},
44 {39000, 43300},
45 {52000, 57800},
46 {58500, 65000},
47 {65000, 72200},
48 {13500, 15000},
49 {27000, 30000},
50 {40500, 45000},
51 {54000, 60000},
52 {81000, 90000},
53 {108000, 120000},
54 {121500, 135000},
55 {135000, 150000},
56 {0, 0}
59 /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
60 static const u8 up_to_ac[] = {
61 WMM_AC_BE,
62 WMM_AC_BK,
63 WMM_AC_BK,
64 WMM_AC_BE,
65 WMM_AC_VI,
66 WMM_AC_VI,
67 WMM_AC_VO,
68 WMM_AC_VO,
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))
74 return;
76 wmi->ep_id = ep_id;
79 enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
81 return wmi->ep_id;
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 > (MAX_NUM_VIF - 1)))
89 return NULL;
91 /* FIXME: Locking */
92 spin_lock(&ar->list_lock);
93 list_for_each_entry(vif, &ar->vif_list, list) {
94 if (vif->fw_vif_idx == if_idx) {
95 found = vif;
96 break;
99 spin_unlock(&ar->list_lock);
101 return found;
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;
112 size_t new_len;
113 __be16 type;
114 u8 *datap;
115 u16 size;
117 if (WARN_ON(skb == NULL))
118 return -EINVAL;
120 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
121 if (skb_headroom(skb) < size)
122 return -ENOMEM;
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__);
130 return 0;
133 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
135 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
136 datap = skb->data;
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;
151 return 0;
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))
161 return -EINVAL;
163 switch (*version) {
164 case WMI_META_VERSION_1:
165 skb_push(skb, WMI_MAX_TX_META_SZ);
166 v1 = (struct wmi_tx_meta_v1 *) skb->data;
167 v1->pkt_id = 0;
168 v1->rate_plcy_id = 0;
169 *version = WMI_META_VERSION_1;
170 break;
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));
176 break;
179 return 0;
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;
188 int ret;
190 if (WARN_ON(skb == NULL || (if_idx > MAX_NUM_VIF - 1)))
191 return -EINVAL;
193 if (tx_meta_info) {
194 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
195 if (ret)
196 return ret;
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;
207 if (more_data)
208 data_hdr->info |=
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);
214 return 0;
217 static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
219 struct iphdr *ip_hdr = (struct iphdr *) pkt;
220 u8 ip_pri;
223 * Determine IPTOS priority
225 * IP-TOS - 8bits
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;
231 ip_pri &= 0x7;
233 if ((layer2_pri & 0x7) > ip_pri)
234 return (u8) layer2_pri & 0x7;
235 else
236 return ip_pri;
239 int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
240 struct sk_buff *skb,
241 u32 layer2_priority, bool wmm_enabled,
242 u8 *ac)
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;
251 u8 *datap;
253 if (WARN_ON(skb == NULL))
254 return -EINVAL;
256 datap = skb->data;
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;
262 if (!wmm_enabled) {
263 /* If WMM is disabled all traffic goes as BE traffic */
264 usr_pri = 0;
265 } else {
266 hdr_size = sizeof(struct ethhdr);
268 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
269 sizeof(struct
270 wmi_data_hdr) +
271 meta_size + hdr_size);
273 if (llc_hdr->eth_type == htons(ip_type)) {
275 * Extract the endpoint info from the TOS field
276 * in the IP header.
278 usr_pri =
279 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
280 sizeof(struct ath6kl_llc_snap_hdr),
281 layer2_priority);
282 } else
283 usr_pri = layer2_priority & 0x7;
287 * workaround for WMM S5
289 * FIXME: wmi->traffic_class is always 100 so this test doesn't
290 * make sense
292 if ((wmi->traffic_class == WMM_AC_VI) &&
293 ((usr_pri == 5) || (usr_pri == 4)))
294 usr_pri = 1;
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;
309 cmd.inactivity_int =
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);
316 *ac = traffic_class;
318 return 0;
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;
326 u32 hdr_size;
327 u8 *datap;
328 __le16 sub_type;
330 if (WARN_ON(skb == NULL))
331 return -EINVAL;
333 datap = skb->data;
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),
343 sizeof(u32));
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));
348 datap = skb->data;
349 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
351 memset(&eth_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)) {
356 case 0:
357 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
358 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
359 break;
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);
363 break;
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);
367 break;
368 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
369 break;
372 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
373 skb_push(skb, sizeof(eth_hdr));
375 datap = skb->data;
377 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
379 return 0;
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;
390 u8 *datap;
392 if (WARN_ON(skb == NULL))
393 return -EINVAL;
395 datap = skb->data;
397 memcpy(&eth_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));
403 datap = skb->data;
405 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
407 return 0;
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;
414 int index;
415 u16 size;
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))
423 return 0;
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);
435 return 0;
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;
442 u32 freq;
443 u32 dur;
444 struct ieee80211_channel *chan;
445 struct ath6kl *ar = wmi->parent_dev;
446 u32 id;
448 if (len < sizeof(*ev))
449 return -EINVAL;
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",
455 freq, dur);
456 chan = ieee80211_get_channel(ar->wiphy, freq);
457 if (!chan) {
458 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
459 "(freq=%u)\n", freq);
460 return -EINVAL;
462 id = vif->last_roc_id;
463 cfg80211_ready_on_channel(vif->ndev, id, chan, NL80211_CHAN_NO_HT,
464 dur, GFP_ATOMIC);
466 return 0;
469 static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
470 u8 *datap, int len,
471 struct ath6kl_vif *vif)
473 struct wmi_cancel_remain_on_chnl_event *ev;
474 u32 freq;
475 u32 dur;
476 struct ieee80211_channel *chan;
477 struct ath6kl *ar = wmi->parent_dev;
478 u32 id;
480 if (len < sizeof(*ev))
481 return -EINVAL;
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);
489 if (!chan) {
490 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
491 "channel (freq=%u)\n", freq);
492 return -EINVAL;
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 */
497 else
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);
503 return 0;
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;
510 u32 id;
512 if (len < sizeof(*ev))
513 return -EINVAL;
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",
518 id, ev->ack_status);
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;
529 return 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;
536 u32 freq;
537 u16 dlen;
539 if (len < sizeof(*ev))
540 return -EINVAL;
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);
548 return -EINVAL;
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);
557 return 0;
560 static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
562 struct wmi_p2p_capabilities_event *ev;
563 u16 dlen;
565 if (len < sizeof(*ev))
566 return -EINVAL;
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);
572 return 0;
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;
579 u32 freq;
580 u16 dlen;
582 if (len < sizeof(*ev))
583 return -EINVAL;
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);
591 return -EINVAL;
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);
596 return 0;
599 static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
601 struct wmi_p2p_info_event *ev;
602 u32 flags;
603 u16 dlen;
605 if (len < sizeof(*ev))
606 return -EINVAL;
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))
616 return -EINVAL;
617 cap = (struct wmi_p2p_capabilities *) ev->data;
618 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
619 cap->go_power_save);
622 if (flags & P2P_FLAG_MACADDR_REQ) {
623 struct wmi_p2p_macaddr *mac;
624 if (dlen < sizeof(*mac))
625 return -EINVAL;
626 mac = (struct wmi_p2p_macaddr *) ev->data;
627 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
628 mac->mac_addr);
631 if (flags & P2P_FLAG_HMODEL_REQ) {
632 struct wmi_p2p_hmodel *mod;
633 if (dlen < sizeof(*mod))
634 return -EINVAL;
635 mod = (struct wmi_p2p_hmodel *) ev->data;
636 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
637 mod->p2p_model,
638 mod->p2p_model ? "host" : "firmware");
640 return 0;
643 static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
645 struct sk_buff *skb;
647 skb = ath6kl_buf_alloc(size);
648 if (!skb)
649 return NULL;
651 skb_put(skb, size);
652 if (size)
653 memset(skb->data, 0, size);
655 return skb;
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)
662 struct sk_buff *skb;
663 int ret;
665 skb = ath6kl_wmi_get_new_buf(0);
666 if (!skb)
667 return -ENOMEM;
669 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
671 return ret;
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))
679 return -EINVAL;
681 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
682 le32_to_cpu(ev->sw_version),
683 le32_to_cpu(ev->abi_version));
685 return 0;
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
692 * in dBm.
694 int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
696 struct sk_buff *skb;
697 struct roam_ctrl_cmd *cmd;
699 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
700 if (!skb)
701 return -ENOMEM;
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,
713 NO_SYNC_WMIFLAG);
715 return 0;
718 int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
720 struct sk_buff *skb;
721 struct roam_ctrl_cmd *cmd;
723 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
724 if (!skb)
725 return -ENOMEM;
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,
735 NO_SYNC_WMIFLAG);
738 int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
740 struct sk_buff *skb;
741 struct roam_ctrl_cmd *cmd;
743 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
744 if (!skb)
745 return -ENOMEM;
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,
755 NO_SYNC_WMIFLAG);
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;
762 u8 *pie, *peie;
764 if (len < sizeof(struct wmi_connect_event))
765 return -EINVAL;
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 "
774 "(AP started)\n",
775 __func__, le16_to_cpu(ev->u.ap_bss.ch),
776 ev->u.ap_bss.bssid);
777 ath6kl_connect_ap_mode_bss(
778 vif, le16_to_cpu(ev->u.ap_bss.ch));
779 } else {
780 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
781 "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
782 "(STA connected)\n",
783 __func__, ev->u.ap_sta.aid,
784 ev->u.ap_sta.mac_addr,
785 ev->u.ap_sta.auth,
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);
796 return 0;
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 +
814 ev->assoc_resp_len;
816 while (pie < peie) {
817 switch (*pie) {
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) */
822 if (pie[1] > 5
823 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
824 wmi->is_wmm_enabled = true;
826 break;
829 if (wmi->is_wmm_enabled)
830 break;
832 pie += pie[1] + 2;
835 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
836 ev->u.sta.bssid,
837 le16_to_cpu(ev->u.sta.listen_intvl),
838 le16_to_cpu(ev->u.sta.beacon_intvl),
839 le32_to_cpu(ev->u.sta.nw_type),
840 ev->beacon_ie_len, ev->assoc_req_len,
841 ev->assoc_resp_len, ev->assoc_info);
843 return 0;
846 static struct country_code_to_enum_rd *
847 ath6kl_regd_find_country(u16 countryCode)
849 int i;
851 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
852 if (allCountries[i].countryCode == countryCode)
853 return &allCountries[i];
856 return NULL;
859 static struct reg_dmn_pair_mapping *
860 ath6kl_get_regpair(u16 regdmn)
862 int i;
864 if (regdmn == NO_ENUMRD)
865 return NULL;
867 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
868 if (regDomainPairs[i].regDmnEnum == regdmn)
869 return &regDomainPairs[i];
872 return NULL;
875 static struct country_code_to_enum_rd *
876 ath6kl_regd_find_country_by_rd(u16 regdmn)
878 int i;
880 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
881 if (allCountries[i].regDmnEnum == regdmn)
882 return &allCountries[i];
885 return NULL;
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;
894 char alpha2[2];
895 u32 reg_code;
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);
910 if (country) {
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))
928 return -EINVAL;
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));
943 return 0;
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))
951 return -EINVAL;
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",
957 ev->peer_mac_addr);
958 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
959 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
960 ev->peer_mac_addr);
962 return 0;
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))
971 return -EINVAL;
973 ev = (struct wmi_tkip_micerr_event *) datap;
975 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
977 return 0;
980 static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
981 struct ath6kl_vif *vif)
983 struct wmi_bss_info_hdr2 *bih;
984 u8 *buf;
985 struct ieee80211_channel *channel;
986 struct ath6kl *ar = wmi->parent_dev;
987 struct ieee80211_mgmt *mgmt;
988 struct cfg80211_bss *bss;
990 if (len <= sizeof(struct wmi_bss_info_hdr2))
991 return -EINVAL;
993 bih = (struct wmi_bss_info_hdr2 *) datap;
994 buf = datap + sizeof(struct wmi_bss_info_hdr2);
995 len -= sizeof(struct wmi_bss_info_hdr2);
997 ath6kl_dbg(ATH6KL_DBG_WMI,
998 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
999 "frame_type=%d\n",
1000 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
1001 bih->frame_type);
1003 if (bih->frame_type != BEACON_FTYPE &&
1004 bih->frame_type != PROBERESP_FTYPE)
1005 return 0; /* Only update BSS table for now */
1007 if (bih->frame_type == BEACON_FTYPE &&
1008 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1009 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
1010 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1011 NONE_BSS_FILTER, 0);
1014 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
1015 if (channel == NULL)
1016 return -EINVAL;
1018 if (len < 8 + 2 + 2)
1019 return -EINVAL;
1021 if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &vif->flags)
1022 && memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
1023 const u8 *tim;
1024 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1025 len - 8 - 2 - 2);
1026 if (tim && tim[1] >= 2) {
1027 vif->assoc_bss_dtim_period = tim[3];
1028 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
1033 * In theory, use of cfg80211_inform_bss() would be more natural here
1034 * since we do not have the full frame. However, at least for now,
1035 * cfg80211 can only distinguish Beacon and Probe Response frames from
1036 * each other when using cfg80211_inform_bss_frame(), so let's build a
1037 * fake IEEE 802.11 header to be able to take benefit of this.
1039 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1040 if (mgmt == NULL)
1041 return -EINVAL;
1043 if (bih->frame_type == BEACON_FTYPE) {
1044 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1045 IEEE80211_STYPE_BEACON);
1046 memset(mgmt->da, 0xff, ETH_ALEN);
1047 } else {
1048 struct net_device *dev = vif->ndev;
1050 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1051 IEEE80211_STYPE_PROBE_RESP);
1052 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
1054 mgmt->duration = cpu_to_le16(0);
1055 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1056 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1057 mgmt->seq_ctrl = cpu_to_le16(0);
1059 memcpy(&mgmt->u.beacon, buf, len);
1061 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
1062 24 + len, (bih->snr - 95) * 100,
1063 GFP_ATOMIC);
1064 kfree(mgmt);
1065 if (bss == NULL)
1066 return -ENOMEM;
1067 cfg80211_put_bss(bss);
1069 return 0;
1072 /* Inactivity timeout of a fatpipe(pstream) at the target */
1073 static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1074 int len)
1076 struct wmi_pstream_timeout_event *ev;
1078 if (len < sizeof(struct wmi_pstream_timeout_event))
1079 return -EINVAL;
1081 ev = (struct wmi_pstream_timeout_event *) datap;
1084 * When the pstream (fat pipe == AC) timesout, it means there were
1085 * no thinStreams within this pstream & it got implicitly created
1086 * due to data flow on this AC. We start the inactivity timer only
1087 * for implicitly created pstream. Just reset the host state.
1089 spin_lock_bh(&wmi->lock);
1090 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1091 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1092 spin_unlock_bh(&wmi->lock);
1094 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1095 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1097 return 0;
1100 static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1102 struct wmi_bit_rate_reply *reply;
1103 s32 rate;
1104 u32 sgi, index;
1106 if (len < sizeof(struct wmi_bit_rate_reply))
1107 return -EINVAL;
1109 reply = (struct wmi_bit_rate_reply *) datap;
1111 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1113 if (reply->rate_index == (s8) RATE_AUTO) {
1114 rate = RATE_AUTO;
1115 } else {
1116 index = reply->rate_index & 0x7f;
1117 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1118 rate = wmi_rate_tbl[index][sgi];
1121 ath6kl_wakeup_event(wmi->parent_dev);
1123 return 0;
1126 static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
1128 ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
1130 return 0;
1133 static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1135 if (len < sizeof(struct wmi_fix_rates_reply))
1136 return -EINVAL;
1138 ath6kl_wakeup_event(wmi->parent_dev);
1140 return 0;
1143 static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1145 if (len < sizeof(struct wmi_channel_list_reply))
1146 return -EINVAL;
1148 ath6kl_wakeup_event(wmi->parent_dev);
1150 return 0;
1153 static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1155 struct wmi_tx_pwr_reply *reply;
1157 if (len < sizeof(struct wmi_tx_pwr_reply))
1158 return -EINVAL;
1160 reply = (struct wmi_tx_pwr_reply *) datap;
1161 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1163 return 0;
1166 static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1168 if (len < sizeof(struct wmi_get_keepalive_cmd))
1169 return -EINVAL;
1171 ath6kl_wakeup_event(wmi->parent_dev);
1173 return 0;
1176 static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1177 struct ath6kl_vif *vif)
1179 struct wmi_scan_complete_event *ev;
1181 ev = (struct wmi_scan_complete_event *) datap;
1183 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
1184 wmi->is_probe_ssid = false;
1186 return 0;
1189 static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
1190 int len, struct ath6kl_vif *vif)
1192 struct wmi_neighbor_report_event *ev;
1193 u8 i;
1195 if (len < sizeof(*ev))
1196 return -EINVAL;
1197 ev = (struct wmi_neighbor_report_event *) datap;
1198 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1199 > len) {
1200 ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
1201 "(num=%d len=%d)\n", ev->num_neighbors, len);
1202 return -EINVAL;
1204 for (i = 0; i < ev->num_neighbors; i++) {
1205 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1206 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1207 ev->neighbor[i].bss_flags);
1208 cfg80211_pmksa_candidate_notify(vif->ndev, i,
1209 ev->neighbor[i].bssid,
1210 !!(ev->neighbor[i].bss_flags &
1211 WMI_PREAUTH_CAPABLE_BSS),
1212 GFP_ATOMIC);
1215 return 0;
1219 * Target is reporting a programming error. This is for
1220 * developer aid only. Target only checks a few common violations
1221 * and it is responsibility of host to do all error checking.
1222 * Behavior of target after wmi error event is undefined.
1223 * A reset is recommended.
1225 static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1227 const char *type = "unknown error";
1228 struct wmi_cmd_error_event *ev;
1229 ev = (struct wmi_cmd_error_event *) datap;
1231 switch (ev->err_code) {
1232 case INVALID_PARAM:
1233 type = "invalid parameter";
1234 break;
1235 case ILLEGAL_STATE:
1236 type = "invalid state";
1237 break;
1238 case INTERNAL_ERROR:
1239 type = "internal error";
1240 break;
1243 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1244 ev->cmd_id, type);
1246 return 0;
1249 static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1250 struct ath6kl_vif *vif)
1252 ath6kl_tgt_stats_event(vif, datap, len);
1254 return 0;
1257 static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1258 struct sq_threshold_params *sq_thresh,
1259 u32 size)
1261 u32 index;
1262 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1264 /* The list is already in sorted order. Get the next lower value */
1265 for (index = 0; index < size; index++) {
1266 if (rssi < sq_thresh->upper_threshold[index]) {
1267 threshold = (u8) sq_thresh->upper_threshold[index];
1268 break;
1272 return threshold;
1275 static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1276 struct sq_threshold_params *sq_thresh,
1277 u32 size)
1279 u32 index;
1280 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1282 /* The list is already in sorted order. Get the next lower value */
1283 for (index = 0; index < size; index++) {
1284 if (rssi > sq_thresh->lower_threshold[index]) {
1285 threshold = (u8) sq_thresh->lower_threshold[index];
1286 break;
1290 return threshold;
1293 static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1294 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1296 struct sk_buff *skb;
1297 struct wmi_rssi_threshold_params_cmd *cmd;
1299 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1300 if (!skb)
1301 return -ENOMEM;
1303 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1304 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1306 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1307 NO_SYNC_WMIFLAG);
1310 static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1311 int len)
1313 struct wmi_rssi_threshold_event *reply;
1314 struct wmi_rssi_threshold_params_cmd cmd;
1315 struct sq_threshold_params *sq_thresh;
1316 enum wmi_rssi_threshold_val new_threshold;
1317 u8 upper_rssi_threshold, lower_rssi_threshold;
1318 s16 rssi;
1319 int ret;
1321 if (len < sizeof(struct wmi_rssi_threshold_event))
1322 return -EINVAL;
1324 reply = (struct wmi_rssi_threshold_event *) datap;
1325 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1326 rssi = a_sle16_to_cpu(reply->rssi);
1328 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1331 * Identify the threshold breached and communicate that to the app.
1332 * After that install a new set of thresholds based on the signal
1333 * quality reported by the target
1335 if (new_threshold) {
1336 /* Upper threshold breached */
1337 if (rssi < sq_thresh->upper_threshold[0]) {
1338 ath6kl_dbg(ATH6KL_DBG_WMI,
1339 "spurious upper rssi threshold event: %d\n",
1340 rssi);
1341 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1342 (rssi >= sq_thresh->upper_threshold[0])) {
1343 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1344 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1345 (rssi >= sq_thresh->upper_threshold[1])) {
1346 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1347 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1348 (rssi >= sq_thresh->upper_threshold[2])) {
1349 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1350 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1351 (rssi >= sq_thresh->upper_threshold[3])) {
1352 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1353 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1354 (rssi >= sq_thresh->upper_threshold[4])) {
1355 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1356 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1357 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1359 } else {
1360 /* Lower threshold breached */
1361 if (rssi > sq_thresh->lower_threshold[0]) {
1362 ath6kl_dbg(ATH6KL_DBG_WMI,
1363 "spurious lower rssi threshold event: %d %d\n",
1364 rssi, sq_thresh->lower_threshold[0]);
1365 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1366 (rssi <= sq_thresh->lower_threshold[0])) {
1367 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1368 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1369 (rssi <= sq_thresh->lower_threshold[1])) {
1370 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1371 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1372 (rssi <= sq_thresh->lower_threshold[2])) {
1373 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1374 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1375 (rssi <= sq_thresh->lower_threshold[3])) {
1376 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1377 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1378 (rssi <= sq_thresh->lower_threshold[4])) {
1379 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1380 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1381 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1385 /* Calculate and install the next set of thresholds */
1386 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1387 sq_thresh->lower_threshold_valid_count);
1388 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1389 sq_thresh->upper_threshold_valid_count);
1391 /* Issue a wmi command to install the thresholds */
1392 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1393 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1394 cmd.weight = sq_thresh->weight;
1395 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1397 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1398 if (ret) {
1399 ath6kl_err("unable to configure rssi thresholds\n");
1400 return -EIO;
1403 return 0;
1406 static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1407 struct ath6kl_vif *vif)
1409 struct wmi_cac_event *reply;
1410 struct ieee80211_tspec_ie *ts;
1411 u16 active_tsids, tsinfo;
1412 u8 tsid, index;
1413 u8 ts_id;
1415 if (len < sizeof(struct wmi_cac_event))
1416 return -EINVAL;
1418 reply = (struct wmi_cac_event *) datap;
1420 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1421 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1423 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1424 tsinfo = le16_to_cpu(ts->tsinfo);
1425 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1426 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1428 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1429 reply->ac, tsid);
1430 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1432 * Following assumes that there is only one outstanding
1433 * ADDTS request when this event is received
1435 spin_lock_bh(&wmi->lock);
1436 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1437 spin_unlock_bh(&wmi->lock);
1439 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1440 if ((active_tsids >> index) & 1)
1441 break;
1443 if (index < (sizeof(active_tsids) * 8))
1444 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1445 reply->ac, index);
1449 * Clear active tsids and Add missing handling
1450 * for delete qos stream from AP
1452 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1454 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1455 tsinfo = le16_to_cpu(ts->tsinfo);
1456 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1457 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1459 spin_lock_bh(&wmi->lock);
1460 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1461 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1462 spin_unlock_bh(&wmi->lock);
1464 /* Indicate stream inactivity to driver layer only if all tsids
1465 * within this AC are deleted.
1467 if (!active_tsids) {
1468 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1469 false);
1470 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1474 return 0;
1477 static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1478 struct wmi_snr_threshold_params_cmd *snr_cmd)
1480 struct sk_buff *skb;
1481 struct wmi_snr_threshold_params_cmd *cmd;
1483 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1484 if (!skb)
1485 return -ENOMEM;
1487 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1488 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1490 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1491 NO_SYNC_WMIFLAG);
1494 static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1495 int len)
1497 struct wmi_snr_threshold_event *reply;
1498 struct sq_threshold_params *sq_thresh;
1499 struct wmi_snr_threshold_params_cmd cmd;
1500 enum wmi_snr_threshold_val new_threshold;
1501 u8 upper_snr_threshold, lower_snr_threshold;
1502 s16 snr;
1503 int ret;
1505 if (len < sizeof(struct wmi_snr_threshold_event))
1506 return -EINVAL;
1508 reply = (struct wmi_snr_threshold_event *) datap;
1510 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1511 snr = reply->snr;
1513 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1516 * Identify the threshold breached and communicate that to the app.
1517 * After that install a new set of thresholds based on the signal
1518 * quality reported by the target.
1520 if (new_threshold) {
1521 /* Upper threshold breached */
1522 if (snr < sq_thresh->upper_threshold[0]) {
1523 ath6kl_dbg(ATH6KL_DBG_WMI,
1524 "spurious upper snr threshold event: %d\n",
1525 snr);
1526 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1527 (snr >= sq_thresh->upper_threshold[0])) {
1528 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1529 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1530 (snr >= sq_thresh->upper_threshold[1])) {
1531 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1532 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1533 (snr >= sq_thresh->upper_threshold[2])) {
1534 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1535 } else if (snr >= sq_thresh->upper_threshold[3]) {
1536 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1538 } else {
1539 /* Lower threshold breached */
1540 if (snr > sq_thresh->lower_threshold[0]) {
1541 ath6kl_dbg(ATH6KL_DBG_WMI,
1542 "spurious lower snr threshold event: %d\n",
1543 sq_thresh->lower_threshold[0]);
1544 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1545 (snr <= sq_thresh->lower_threshold[0])) {
1546 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1547 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1548 (snr <= sq_thresh->lower_threshold[1])) {
1549 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1550 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1551 (snr <= sq_thresh->lower_threshold[2])) {
1552 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1553 } else if (snr <= sq_thresh->lower_threshold[3]) {
1554 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1558 /* Calculate and install the next set of thresholds */
1559 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1560 sq_thresh->lower_threshold_valid_count);
1561 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1562 sq_thresh->upper_threshold_valid_count);
1564 /* Issue a wmi command to install the thresholds */
1565 cmd.thresh_above1_val = upper_snr_threshold;
1566 cmd.thresh_below1_val = lower_snr_threshold;
1567 cmd.weight = sq_thresh->weight;
1568 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1570 ath6kl_dbg(ATH6KL_DBG_WMI,
1571 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1572 snr, new_threshold,
1573 lower_snr_threshold, upper_snr_threshold);
1575 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1576 if (ret) {
1577 ath6kl_err("unable to configure snr threshold\n");
1578 return -EIO;
1581 return 0;
1584 static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1586 u16 ap_info_entry_size;
1587 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1588 struct wmi_ap_info_v1 *ap_info_v1;
1589 u8 index;
1591 if (len < sizeof(struct wmi_aplist_event) ||
1592 ev->ap_list_ver != APLIST_VER1)
1593 return -EINVAL;
1595 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1596 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1598 ath6kl_dbg(ATH6KL_DBG_WMI,
1599 "number of APs in aplist event: %d\n", ev->num_ap);
1601 if (len < (int) (sizeof(struct wmi_aplist_event) +
1602 (ev->num_ap - 1) * ap_info_entry_size))
1603 return -EINVAL;
1605 /* AP list version 1 contents */
1606 for (index = 0; index < ev->num_ap; index++) {
1607 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1608 index, ap_info_v1->bssid, ap_info_v1->channel);
1609 ap_info_v1++;
1612 return 0;
1615 int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
1616 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1618 struct wmi_cmd_hdr *cmd_hdr;
1619 enum htc_endpoint_id ep_id = wmi->ep_id;
1620 int ret;
1621 u16 info1;
1623 if (WARN_ON(skb == NULL || (if_idx > (MAX_NUM_VIF - 1))))
1624 return -EINVAL;
1626 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1627 cmd_id, skb->len, sync_flag);
1628 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1629 skb->data, skb->len);
1631 if (sync_flag >= END_WMIFLAG) {
1632 dev_kfree_skb(skb);
1633 return -EINVAL;
1636 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1637 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1639 * Make sure all data currently queued is transmitted before
1640 * the cmd execution. Establish a new sync point.
1642 ath6kl_wmi_sync_point(wmi, if_idx);
1645 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1647 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1648 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1649 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1650 cmd_hdr->info1 = cpu_to_le16(info1);
1652 /* Only for OPT_TX_CMD, use BE endpoint. */
1653 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1654 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1655 false, false, 0, NULL, if_idx);
1656 if (ret) {
1657 dev_kfree_skb(skb);
1658 return ret;
1660 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1663 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1665 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1666 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1668 * Make sure all new data queued waits for the command to
1669 * execute. Establish a new sync point.
1671 ath6kl_wmi_sync_point(wmi, if_idx);
1674 return 0;
1677 int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1678 enum network_type nw_type,
1679 enum dot11_auth_mode dot11_auth_mode,
1680 enum auth_mode auth_mode,
1681 enum crypto_type pairwise_crypto,
1682 u8 pairwise_crypto_len,
1683 enum crypto_type group_crypto,
1684 u8 group_crypto_len, int ssid_len, u8 *ssid,
1685 u8 *bssid, u16 channel, u32 ctrl_flags)
1687 struct sk_buff *skb;
1688 struct wmi_connect_cmd *cc;
1689 int ret;
1691 ath6kl_dbg(ATH6KL_DBG_WMI,
1692 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1693 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1694 bssid, channel, ctrl_flags, ssid_len, nw_type,
1695 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1696 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1698 wmi->traffic_class = 100;
1700 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1701 return -EINVAL;
1703 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1704 return -EINVAL;
1706 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1707 if (!skb)
1708 return -ENOMEM;
1710 cc = (struct wmi_connect_cmd *) skb->data;
1712 if (ssid_len)
1713 memcpy(cc->ssid, ssid, ssid_len);
1715 cc->ssid_len = ssid_len;
1716 cc->nw_type = nw_type;
1717 cc->dot11_auth_mode = dot11_auth_mode;
1718 cc->auth_mode = auth_mode;
1719 cc->prwise_crypto_type = pairwise_crypto;
1720 cc->prwise_crypto_len = pairwise_crypto_len;
1721 cc->grp_crypto_type = group_crypto;
1722 cc->grp_crypto_len = group_crypto_len;
1723 cc->ch = cpu_to_le16(channel);
1724 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1726 if (bssid != NULL)
1727 memcpy(cc->bssid, bssid, ETH_ALEN);
1729 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1730 NO_SYNC_WMIFLAG);
1732 return ret;
1735 int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1736 u16 channel)
1738 struct sk_buff *skb;
1739 struct wmi_reconnect_cmd *cc;
1740 int ret;
1742 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1743 bssid, channel);
1745 wmi->traffic_class = 100;
1747 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1748 if (!skb)
1749 return -ENOMEM;
1751 cc = (struct wmi_reconnect_cmd *) skb->data;
1752 cc->channel = cpu_to_le16(channel);
1754 if (bssid != NULL)
1755 memcpy(cc->bssid, bssid, ETH_ALEN);
1757 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
1758 NO_SYNC_WMIFLAG);
1760 return ret;
1763 int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
1765 int ret;
1767 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1769 wmi->traffic_class = 100;
1771 /* Disconnect command does not need to do a SYNC before. */
1772 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
1774 return ret;
1777 int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1778 enum wmi_scan_type scan_type,
1779 u32 force_fgscan, u32 is_legacy,
1780 u32 home_dwell_time, u32 force_scan_interval,
1781 s8 num_chan, u16 *ch_list)
1783 struct sk_buff *skb;
1784 struct wmi_start_scan_cmd *sc;
1785 s8 size;
1786 int i, ret;
1788 size = sizeof(struct wmi_start_scan_cmd);
1790 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1791 return -EINVAL;
1793 if (num_chan > WMI_MAX_CHANNELS)
1794 return -EINVAL;
1796 if (num_chan)
1797 size += sizeof(u16) * (num_chan - 1);
1799 skb = ath6kl_wmi_get_new_buf(size);
1800 if (!skb)
1801 return -ENOMEM;
1803 sc = (struct wmi_start_scan_cmd *) skb->data;
1804 sc->scan_type = scan_type;
1805 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1806 sc->is_legacy = cpu_to_le32(is_legacy);
1807 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1808 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1809 sc->num_ch = num_chan;
1811 for (i = 0; i < num_chan; i++)
1812 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1814 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
1815 NO_SYNC_WMIFLAG);
1817 return ret;
1820 int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
1821 u16 fg_start_sec,
1822 u16 fg_end_sec, u16 bg_sec,
1823 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1824 u16 pas_chdw_msec, u8 short_scan_ratio,
1825 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1826 u16 maxact_scan_per_ssid)
1828 struct sk_buff *skb;
1829 struct wmi_scan_params_cmd *sc;
1830 int ret;
1832 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1833 if (!skb)
1834 return -ENOMEM;
1836 sc = (struct wmi_scan_params_cmd *) skb->data;
1837 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1838 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1839 sc->bg_period = cpu_to_le16(bg_sec);
1840 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1841 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1842 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1843 sc->short_scan_ratio = short_scan_ratio;
1844 sc->scan_ctrl_flags = scan_ctrl_flag;
1845 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1846 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1848 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
1849 NO_SYNC_WMIFLAG);
1850 return ret;
1853 int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
1855 struct sk_buff *skb;
1856 struct wmi_bss_filter_cmd *cmd;
1857 int ret;
1859 if (filter >= LAST_BSS_FILTER)
1860 return -EINVAL;
1862 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1863 if (!skb)
1864 return -ENOMEM;
1866 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1867 cmd->bss_filter = filter;
1868 cmd->ie_mask = cpu_to_le32(ie_mask);
1870 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
1871 NO_SYNC_WMIFLAG);
1872 return ret;
1875 int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
1876 u8 ssid_len, u8 *ssid)
1878 struct sk_buff *skb;
1879 struct wmi_probed_ssid_cmd *cmd;
1880 int ret;
1882 if (index > MAX_PROBED_SSID_INDEX)
1883 return -EINVAL;
1885 if (ssid_len > sizeof(cmd->ssid))
1886 return -EINVAL;
1888 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1889 return -EINVAL;
1891 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1892 return -EINVAL;
1894 if (flag & SPECIFIC_SSID_FLAG)
1895 wmi->is_probe_ssid = true;
1897 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1898 if (!skb)
1899 return -ENOMEM;
1901 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1902 cmd->entry_index = index;
1903 cmd->flag = flag;
1904 cmd->ssid_len = ssid_len;
1905 memcpy(cmd->ssid, ssid, ssid_len);
1907 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
1908 NO_SYNC_WMIFLAG);
1909 return ret;
1912 int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
1913 u16 listen_interval,
1914 u16 listen_beacons)
1916 struct sk_buff *skb;
1917 struct wmi_listen_int_cmd *cmd;
1918 int ret;
1920 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1921 if (!skb)
1922 return -ENOMEM;
1924 cmd = (struct wmi_listen_int_cmd *) skb->data;
1925 cmd->listen_intvl = cpu_to_le16(listen_interval);
1926 cmd->num_beacons = cpu_to_le16(listen_beacons);
1928 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
1929 NO_SYNC_WMIFLAG);
1930 return ret;
1933 int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
1935 struct sk_buff *skb;
1936 struct wmi_power_mode_cmd *cmd;
1937 int ret;
1939 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1940 if (!skb)
1941 return -ENOMEM;
1943 cmd = (struct wmi_power_mode_cmd *) skb->data;
1944 cmd->pwr_mode = pwr_mode;
1945 wmi->pwr_mode = pwr_mode;
1947 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
1948 NO_SYNC_WMIFLAG);
1949 return ret;
1952 int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
1953 u16 ps_poll_num, u16 dtim_policy,
1954 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1955 u16 ps_fail_event_policy)
1957 struct sk_buff *skb;
1958 struct wmi_power_params_cmd *pm;
1959 int ret;
1961 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1962 if (!skb)
1963 return -ENOMEM;
1965 pm = (struct wmi_power_params_cmd *)skb->data;
1966 pm->idle_period = cpu_to_le16(idle_period);
1967 pm->pspoll_number = cpu_to_le16(ps_poll_num);
1968 pm->dtim_policy = cpu_to_le16(dtim_policy);
1969 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1970 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1971 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1973 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
1974 NO_SYNC_WMIFLAG);
1975 return ret;
1978 int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
1980 struct sk_buff *skb;
1981 struct wmi_disc_timeout_cmd *cmd;
1982 int ret;
1984 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1985 if (!skb)
1986 return -ENOMEM;
1988 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
1989 cmd->discon_timeout = timeout;
1991 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
1992 NO_SYNC_WMIFLAG);
1994 if (ret == 0)
1995 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
1997 return ret;
2000 int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
2001 enum crypto_type key_type,
2002 u8 key_usage, u8 key_len,
2003 u8 *key_rsc, u8 *key_material,
2004 u8 key_op_ctrl, u8 *mac_addr,
2005 enum wmi_sync_flag sync_flag)
2007 struct sk_buff *skb;
2008 struct wmi_add_cipher_key_cmd *cmd;
2009 int ret;
2011 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
2012 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
2013 key_index, key_type, key_usage, key_len, key_op_ctrl);
2015 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
2016 (key_material == NULL))
2017 return -EINVAL;
2019 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2020 return -EINVAL;
2022 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2023 if (!skb)
2024 return -ENOMEM;
2026 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2027 cmd->key_index = key_index;
2028 cmd->key_type = key_type;
2029 cmd->key_usage = key_usage;
2030 cmd->key_len = key_len;
2031 memcpy(cmd->key, key_material, key_len);
2033 if (key_rsc != NULL)
2034 memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
2036 cmd->key_op_ctrl = key_op_ctrl;
2038 if (mac_addr)
2039 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2041 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
2042 sync_flag);
2044 return ret;
2047 int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
2049 struct sk_buff *skb;
2050 struct wmi_add_krk_cmd *cmd;
2051 int ret;
2053 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2054 if (!skb)
2055 return -ENOMEM;
2057 cmd = (struct wmi_add_krk_cmd *) skb->data;
2058 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2060 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
2061 NO_SYNC_WMIFLAG);
2063 return ret;
2066 int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
2068 struct sk_buff *skb;
2069 struct wmi_delete_cipher_key_cmd *cmd;
2070 int ret;
2072 if (key_index > WMI_MAX_KEY_INDEX)
2073 return -EINVAL;
2075 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2076 if (!skb)
2077 return -ENOMEM;
2079 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2080 cmd->key_index = key_index;
2082 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
2083 NO_SYNC_WMIFLAG);
2085 return ret;
2088 int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
2089 const u8 *pmkid, bool set)
2091 struct sk_buff *skb;
2092 struct wmi_setpmkid_cmd *cmd;
2093 int ret;
2095 if (bssid == NULL)
2096 return -EINVAL;
2098 if (set && pmkid == NULL)
2099 return -EINVAL;
2101 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2102 if (!skb)
2103 return -ENOMEM;
2105 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2106 memcpy(cmd->bssid, bssid, ETH_ALEN);
2107 if (set) {
2108 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2109 cmd->enable = PMKID_ENABLE;
2110 } else {
2111 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2112 cmd->enable = PMKID_DISABLE;
2115 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
2116 NO_SYNC_WMIFLAG);
2118 return ret;
2121 static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2122 enum htc_endpoint_id ep_id, u8 if_idx)
2124 struct wmi_data_hdr *data_hdr;
2125 int ret;
2127 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2128 return -EINVAL;
2130 skb_push(skb, sizeof(struct wmi_data_hdr));
2132 data_hdr = (struct wmi_data_hdr *) skb->data;
2133 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2134 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
2136 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2138 return ret;
2141 static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
2143 struct sk_buff *skb;
2144 struct wmi_sync_cmd *cmd;
2145 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2146 enum htc_endpoint_id ep_id;
2147 u8 index, num_pri_streams = 0;
2148 int ret = 0;
2150 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2152 spin_lock_bh(&wmi->lock);
2154 for (index = 0; index < WMM_NUM_AC; index++) {
2155 if (wmi->fat_pipe_exist & (1 << index)) {
2156 num_pri_streams++;
2157 data_sync_bufs[num_pri_streams - 1].traffic_class =
2158 index;
2162 spin_unlock_bh(&wmi->lock);
2164 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2165 if (!skb) {
2166 ret = -ENOMEM;
2167 goto free_skb;
2170 cmd = (struct wmi_sync_cmd *) skb->data;
2173 * In the SYNC cmd sent on the control Ep, send a bitmap
2174 * of the data eps on which the Data Sync will be sent
2176 cmd->data_sync_map = wmi->fat_pipe_exist;
2178 for (index = 0; index < num_pri_streams; index++) {
2179 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2180 if (data_sync_bufs[index].skb == NULL) {
2181 ret = -ENOMEM;
2182 break;
2187 * If buffer allocation for any of the dataSync fails,
2188 * then do not send the Synchronize cmd on the control ep
2190 if (ret)
2191 goto free_skb;
2194 * Send sync cmd followed by sync data messages on all
2195 * endpoints being used
2197 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
2198 NO_SYNC_WMIFLAG);
2200 if (ret)
2201 goto free_skb;
2203 /* cmd buffer sent, we no longer own it */
2204 skb = NULL;
2206 for (index = 0; index < num_pri_streams; index++) {
2208 if (WARN_ON(!data_sync_bufs[index].skb))
2209 break;
2211 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2212 data_sync_bufs[index].
2213 traffic_class);
2214 ret =
2215 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2216 ep_id, if_idx);
2218 if (ret)
2219 break;
2221 data_sync_bufs[index].skb = NULL;
2224 free_skb:
2225 /* free up any resources left over (possibly due to an error) */
2226 if (skb)
2227 dev_kfree_skb(skb);
2229 for (index = 0; index < num_pri_streams; index++) {
2230 if (data_sync_bufs[index].skb != NULL) {
2231 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2232 skb);
2236 return ret;
2239 int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
2240 struct wmi_create_pstream_cmd *params)
2242 struct sk_buff *skb;
2243 struct wmi_create_pstream_cmd *cmd;
2244 u8 fatpipe_exist_for_ac = 0;
2245 s32 min_phy = 0;
2246 s32 nominal_phy = 0;
2247 int ret;
2249 if (!((params->user_pri < 8) &&
2250 (params->user_pri <= 0x7) &&
2251 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2252 (params->traffic_direc == UPLINK_TRAFFIC ||
2253 params->traffic_direc == DNLINK_TRAFFIC ||
2254 params->traffic_direc == BIDIR_TRAFFIC) &&
2255 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2256 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2257 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2258 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2259 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2260 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2261 params->tsid <= WMI_MAX_THINSTREAM))) {
2262 return -EINVAL;
2266 * Check nominal PHY rate is >= minimalPHY,
2267 * so that DUT can allow TSRS IE
2270 /* Get the physical rate (units of bps) */
2271 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2273 /* Check minimal phy < nominal phy rate */
2274 if (params->nominal_phy >= min_phy) {
2275 /* unit of 500 kbps */
2276 nominal_phy = (params->nominal_phy * 1000) / 500;
2277 ath6kl_dbg(ATH6KL_DBG_WMI,
2278 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2279 min_phy, nominal_phy);
2281 params->nominal_phy = nominal_phy;
2282 } else {
2283 params->nominal_phy = 0;
2286 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2287 if (!skb)
2288 return -ENOMEM;
2290 ath6kl_dbg(ATH6KL_DBG_WMI,
2291 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2292 params->traffic_class, params->tsid);
2294 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2295 memcpy(cmd, params, sizeof(*cmd));
2297 /* This is an implicitly created Fat pipe */
2298 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2299 spin_lock_bh(&wmi->lock);
2300 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2301 (1 << params->traffic_class));
2302 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2303 spin_unlock_bh(&wmi->lock);
2304 } else {
2305 /* explicitly created thin stream within a fat pipe */
2306 spin_lock_bh(&wmi->lock);
2307 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2308 (1 << params->traffic_class));
2309 wmi->stream_exist_for_ac[params->traffic_class] |=
2310 (1 << params->tsid);
2312 * If a thinstream becomes active, the fat pipe automatically
2313 * becomes active
2315 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2316 spin_unlock_bh(&wmi->lock);
2320 * Indicate activty change to driver layer only if this is the
2321 * first TSID to get created in this AC explicitly or an implicit
2322 * fat pipe is getting created.
2324 if (!fatpipe_exist_for_ac)
2325 ath6kl_indicate_tx_activity(wmi->parent_dev,
2326 params->traffic_class, true);
2328 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
2329 NO_SYNC_WMIFLAG);
2330 return ret;
2333 int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2334 u8 tsid)
2336 struct sk_buff *skb;
2337 struct wmi_delete_pstream_cmd *cmd;
2338 u16 active_tsids = 0;
2339 int ret;
2341 if (traffic_class > 3) {
2342 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2343 return -EINVAL;
2346 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2347 if (!skb)
2348 return -ENOMEM;
2350 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2351 cmd->traffic_class = traffic_class;
2352 cmd->tsid = tsid;
2354 spin_lock_bh(&wmi->lock);
2355 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2356 spin_unlock_bh(&wmi->lock);
2358 if (!(active_tsids & (1 << tsid))) {
2359 dev_kfree_skb(skb);
2360 ath6kl_dbg(ATH6KL_DBG_WMI,
2361 "TSID %d doesn't exist for traffic class: %d\n",
2362 tsid, traffic_class);
2363 return -ENODATA;
2366 ath6kl_dbg(ATH6KL_DBG_WMI,
2367 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2368 traffic_class, tsid);
2370 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
2371 SYNC_BEFORE_WMIFLAG);
2373 spin_lock_bh(&wmi->lock);
2374 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2375 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2376 spin_unlock_bh(&wmi->lock);
2379 * Indicate stream inactivity to driver layer only if all tsids
2380 * within this AC are deleted.
2382 if (!active_tsids) {
2383 ath6kl_indicate_tx_activity(wmi->parent_dev,
2384 traffic_class, false);
2385 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2388 return ret;
2391 int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2393 struct sk_buff *skb;
2394 struct wmi_set_ip_cmd *cmd;
2395 int ret;
2397 /* Multicast address are not valid */
2398 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2399 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2400 return -EINVAL;
2402 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2403 if (!skb)
2404 return -ENOMEM;
2406 cmd = (struct wmi_set_ip_cmd *) skb->data;
2407 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2409 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_IP_CMDID,
2410 NO_SYNC_WMIFLAG);
2411 return ret;
2414 static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2415 int len)
2417 if (len < sizeof(struct wmi_get_wow_list_reply))
2418 return -EINVAL;
2420 return 0;
2423 static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2424 enum wmix_command_id cmd_id,
2425 enum wmi_sync_flag sync_flag)
2427 struct wmix_cmd_hdr *cmd_hdr;
2428 int ret;
2430 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2432 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2433 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2435 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
2437 return ret;
2440 int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2442 struct sk_buff *skb;
2443 struct wmix_hb_challenge_resp_cmd *cmd;
2444 int ret;
2446 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2447 if (!skb)
2448 return -ENOMEM;
2450 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2451 cmd->cookie = cpu_to_le32(cookie);
2452 cmd->source = cpu_to_le32(source);
2454 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2455 NO_SYNC_WMIFLAG);
2456 return ret;
2459 int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2461 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2462 struct sk_buff *skb;
2463 int ret;
2465 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2466 if (!skb)
2467 return -ENOMEM;
2469 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2470 cmd->valid = cpu_to_le32(valid);
2471 cmd->config = cpu_to_le32(config);
2473 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2474 NO_SYNC_WMIFLAG);
2475 return ret;
2478 int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
2480 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
2483 int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
2485 struct sk_buff *skb;
2486 struct wmi_set_tx_pwr_cmd *cmd;
2487 int ret;
2489 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2490 if (!skb)
2491 return -ENOMEM;
2493 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2494 cmd->dbM = dbM;
2496 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
2497 NO_SYNC_WMIFLAG);
2499 return ret;
2502 int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
2504 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
2507 int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
2509 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
2512 int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
2513 u8 preamble_policy)
2515 struct sk_buff *skb;
2516 struct wmi_set_lpreamble_cmd *cmd;
2517 int ret;
2519 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2520 if (!skb)
2521 return -ENOMEM;
2523 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2524 cmd->status = status;
2525 cmd->preamble_policy = preamble_policy;
2527 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
2528 NO_SYNC_WMIFLAG);
2529 return ret;
2532 int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2534 struct sk_buff *skb;
2535 struct wmi_set_rts_cmd *cmd;
2536 int ret;
2538 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2539 if (!skb)
2540 return -ENOMEM;
2542 cmd = (struct wmi_set_rts_cmd *) skb->data;
2543 cmd->threshold = cpu_to_le16(threshold);
2545 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
2546 NO_SYNC_WMIFLAG);
2547 return ret;
2550 int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
2552 struct sk_buff *skb;
2553 struct wmi_set_wmm_txop_cmd *cmd;
2554 int ret;
2556 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2557 return -EINVAL;
2559 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2560 if (!skb)
2561 return -ENOMEM;
2563 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2564 cmd->txop_enable = cfg;
2566 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
2567 NO_SYNC_WMIFLAG);
2568 return ret;
2571 int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
2572 u8 keep_alive_intvl)
2574 struct sk_buff *skb;
2575 struct wmi_set_keepalive_cmd *cmd;
2576 int ret;
2578 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2579 if (!skb)
2580 return -ENOMEM;
2582 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2583 cmd->keep_alive_intvl = keep_alive_intvl;
2585 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
2586 NO_SYNC_WMIFLAG);
2588 if (ret == 0)
2589 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
2591 return ret;
2594 int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2596 struct sk_buff *skb;
2597 int ret;
2599 skb = ath6kl_wmi_get_new_buf(len);
2600 if (!skb)
2601 return -ENOMEM;
2603 memcpy(skb->data, buf, len);
2605 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
2607 return ret;
2611 s32 ath6kl_wmi_get_rate(s8 rate_index)
2613 if (rate_index == RATE_AUTO)
2614 return 0;
2616 return wmi_rate_tbl[(u32) rate_index][0];
2619 static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2620 u32 len)
2622 struct wmi_pmkid_list_reply *reply;
2623 u32 expected_len;
2625 if (len < sizeof(struct wmi_pmkid_list_reply))
2626 return -EINVAL;
2628 reply = (struct wmi_pmkid_list_reply *)datap;
2629 expected_len = sizeof(reply->num_pmkid) +
2630 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2632 if (len < expected_len)
2633 return -EINVAL;
2635 return 0;
2638 static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
2639 struct ath6kl_vif *vif)
2641 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2643 aggr_recv_addba_req_evt(vif, cmd->tid,
2644 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2646 return 0;
2649 static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
2650 struct ath6kl_vif *vif)
2652 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2654 aggr_recv_delba_req_evt(vif, cmd->tid);
2656 return 0;
2659 /* AP mode functions */
2661 int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
2662 struct wmi_connect_cmd *p)
2664 struct sk_buff *skb;
2665 struct wmi_connect_cmd *cm;
2666 int res;
2668 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2669 if (!skb)
2670 return -ENOMEM;
2672 cm = (struct wmi_connect_cmd *) skb->data;
2673 memcpy(cm, p, sizeof(*cm));
2675 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
2676 NO_SYNC_WMIFLAG);
2677 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2678 "ctrl_flags=0x%x-> res=%d\n",
2679 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2680 le32_to_cpu(p->ctrl_flags), res);
2681 return res;
2684 int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
2685 u16 reason)
2687 struct sk_buff *skb;
2688 struct wmi_ap_set_mlme_cmd *cm;
2690 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2691 if (!skb)
2692 return -ENOMEM;
2694 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2695 memcpy(cm->mac, mac, ETH_ALEN);
2696 cm->reason = cpu_to_le16(reason);
2697 cm->cmd = cmd;
2699 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
2700 NO_SYNC_WMIFLAG);
2703 static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
2704 struct ath6kl_vif *vif)
2706 struct wmi_pspoll_event *ev;
2708 if (len < sizeof(struct wmi_pspoll_event))
2709 return -EINVAL;
2711 ev = (struct wmi_pspoll_event *) datap;
2713 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
2715 return 0;
2718 static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
2719 struct ath6kl_vif *vif)
2721 ath6kl_dtimexpiry_event(vif);
2723 return 0;
2726 int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
2727 bool flag)
2729 struct sk_buff *skb;
2730 struct wmi_ap_set_pvb_cmd *cmd;
2731 int ret;
2733 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2734 if (!skb)
2735 return -ENOMEM;
2737 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2738 cmd->aid = cpu_to_le16(aid);
2739 cmd->rsvd = cpu_to_le16(0);
2740 cmd->flag = cpu_to_le32(flag);
2742 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
2743 NO_SYNC_WMIFLAG);
2745 return 0;
2748 int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
2749 u8 rx_meta_ver,
2750 bool rx_dot11_hdr, bool defrag_on_host)
2752 struct sk_buff *skb;
2753 struct wmi_rx_frame_format_cmd *cmd;
2754 int ret;
2756 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2757 if (!skb)
2758 return -ENOMEM;
2760 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2761 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2762 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2763 cmd->meta_ver = rx_meta_ver;
2765 /* Delete the local aggr state, on host */
2766 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
2767 NO_SYNC_WMIFLAG);
2769 return ret;
2772 int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
2773 const u8 *ie, u8 ie_len)
2775 struct sk_buff *skb;
2776 struct wmi_set_appie_cmd *p;
2778 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2779 if (!skb)
2780 return -ENOMEM;
2782 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2783 "ie_len=%u\n", mgmt_frm_type, ie_len);
2784 p = (struct wmi_set_appie_cmd *) skb->data;
2785 p->mgmt_frm_type = mgmt_frm_type;
2786 p->ie_len = ie_len;
2787 memcpy(p->ie_info, ie, ie_len);
2788 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
2789 NO_SYNC_WMIFLAG);
2792 int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2794 struct sk_buff *skb;
2795 struct wmi_disable_11b_rates_cmd *cmd;
2797 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2798 if (!skb)
2799 return -ENOMEM;
2801 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2802 disable);
2803 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2804 cmd->disable = disable ? 1 : 0;
2806 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
2807 NO_SYNC_WMIFLAG);
2810 int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
2812 struct sk_buff *skb;
2813 struct wmi_remain_on_chnl_cmd *p;
2815 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2816 if (!skb)
2817 return -ENOMEM;
2819 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
2820 freq, dur);
2821 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
2822 p->freq = cpu_to_le32(freq);
2823 p->duration = cpu_to_le32(dur);
2824 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
2825 NO_SYNC_WMIFLAG);
2828 int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
2829 u32 wait, const u8 *data, u16 data_len)
2831 struct sk_buff *skb;
2832 struct wmi_send_action_cmd *p;
2833 u8 *buf;
2835 if (wait)
2836 return -EINVAL; /* Offload for wait not supported */
2838 buf = kmalloc(data_len, GFP_KERNEL);
2839 if (!buf)
2840 return -ENOMEM;
2842 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2843 if (!skb) {
2844 kfree(buf);
2845 return -ENOMEM;
2848 kfree(wmi->last_mgmt_tx_frame);
2849 wmi->last_mgmt_tx_frame = buf;
2850 wmi->last_mgmt_tx_frame_len = data_len;
2852 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
2853 "len=%u\n", id, freq, wait, data_len);
2854 p = (struct wmi_send_action_cmd *) skb->data;
2855 p->id = cpu_to_le32(id);
2856 p->freq = cpu_to_le32(freq);
2857 p->wait = cpu_to_le32(wait);
2858 p->len = cpu_to_le16(data_len);
2859 memcpy(p->data, data, data_len);
2860 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
2861 NO_SYNC_WMIFLAG);
2864 int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
2865 const u8 *dst, const u8 *data,
2866 u16 data_len)
2868 struct sk_buff *skb;
2869 struct wmi_p2p_probe_response_cmd *p;
2871 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2872 if (!skb)
2873 return -ENOMEM;
2875 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
2876 "len=%u\n", freq, dst, data_len);
2877 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
2878 p->freq = cpu_to_le32(freq);
2879 memcpy(p->destination_addr, dst, ETH_ALEN);
2880 p->len = cpu_to_le16(data_len);
2881 memcpy(p->data, data, data_len);
2882 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2883 WMI_SEND_PROBE_RESPONSE_CMDID,
2884 NO_SYNC_WMIFLAG);
2887 int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
2889 struct sk_buff *skb;
2890 struct wmi_probe_req_report_cmd *p;
2892 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2893 if (!skb)
2894 return -ENOMEM;
2896 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
2897 enable);
2898 p = (struct wmi_probe_req_report_cmd *) skb->data;
2899 p->enable = enable ? 1 : 0;
2900 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
2901 NO_SYNC_WMIFLAG);
2904 int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
2906 struct sk_buff *skb;
2907 struct wmi_get_p2p_info *p;
2909 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2910 if (!skb)
2911 return -ENOMEM;
2913 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
2914 info_req_flags);
2915 p = (struct wmi_get_p2p_info *) skb->data;
2916 p->info_req_flags = cpu_to_le32(info_req_flags);
2917 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
2918 NO_SYNC_WMIFLAG);
2921 int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
2923 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
2924 return ath6kl_wmi_simple_cmd(wmi, if_idx,
2925 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
2928 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
2930 struct wmix_cmd_hdr *cmd;
2931 u32 len;
2932 u16 id;
2933 u8 *datap;
2934 int ret = 0;
2936 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
2937 ath6kl_err("bad packet 1\n");
2938 return -EINVAL;
2941 cmd = (struct wmix_cmd_hdr *) skb->data;
2942 id = le32_to_cpu(cmd->cmd_id);
2944 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
2946 datap = skb->data;
2947 len = skb->len;
2949 switch (id) {
2950 case WMIX_HB_CHALLENGE_RESP_EVENTID:
2951 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
2952 break;
2953 case WMIX_DBGLOG_EVENTID:
2954 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
2955 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
2956 break;
2957 default:
2958 ath6kl_warn("unknown cmd id 0x%x\n", id);
2959 ret = -EINVAL;
2960 break;
2963 return ret;
2966 static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
2968 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
2971 /* Control Path */
2972 int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
2974 struct wmi_cmd_hdr *cmd;
2975 struct ath6kl_vif *vif;
2976 u32 len;
2977 u16 id;
2978 u8 if_idx;
2979 u8 *datap;
2980 int ret = 0;
2982 if (WARN_ON(skb == NULL))
2983 return -EINVAL;
2985 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
2986 ath6kl_err("bad packet 1\n");
2987 dev_kfree_skb(skb);
2988 return -EINVAL;
2991 cmd = (struct wmi_cmd_hdr *) skb->data;
2992 id = le16_to_cpu(cmd->cmd_id);
2993 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
2995 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
2997 datap = skb->data;
2998 len = skb->len;
3000 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3001 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3002 datap, len);
3004 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3005 if (!vif) {
3006 ath6kl_dbg(ATH6KL_DBG_WMI,
3007 "Wmi event for unavailable vif, vif_index:%d\n",
3008 if_idx);
3009 dev_kfree_skb(skb);
3010 return -EINVAL;
3013 switch (id) {
3014 case WMI_GET_BITRATE_CMDID:
3015 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3016 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3017 break;
3018 case WMI_GET_CHANNEL_LIST_CMDID:
3019 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3020 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3021 break;
3022 case WMI_GET_TX_PWR_CMDID:
3023 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3024 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3025 break;
3026 case WMI_READY_EVENTID:
3027 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3028 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3029 break;
3030 case WMI_CONNECT_EVENTID:
3031 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3032 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3033 break;
3034 case WMI_DISCONNECT_EVENTID:
3035 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3036 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3037 break;
3038 case WMI_PEER_NODE_EVENTID:
3039 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3040 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3041 break;
3042 case WMI_TKIP_MICERR_EVENTID:
3043 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3044 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3045 break;
3046 case WMI_BSSINFO_EVENTID:
3047 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3048 ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3049 break;
3050 case WMI_REGDOMAIN_EVENTID:
3051 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
3052 ath6kl_wmi_regdomain_event(wmi, datap, len);
3053 break;
3054 case WMI_PSTREAM_TIMEOUT_EVENTID:
3055 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3056 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3057 break;
3058 case WMI_NEIGHBOR_REPORT_EVENTID:
3059 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3060 ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3061 vif);
3062 break;
3063 case WMI_SCAN_COMPLETE_EVENTID:
3064 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3065 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3066 break;
3067 case WMI_CMDERROR_EVENTID:
3068 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3069 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3070 break;
3071 case WMI_REPORT_STATISTICS_EVENTID:
3072 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3073 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3074 break;
3075 case WMI_RSSI_THRESHOLD_EVENTID:
3076 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3077 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3078 break;
3079 case WMI_ERROR_REPORT_EVENTID:
3080 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3081 break;
3082 case WMI_OPT_RX_FRAME_EVENTID:
3083 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
3084 /* this event has been deprecated */
3085 break;
3086 case WMI_REPORT_ROAM_TBL_EVENTID:
3087 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
3088 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
3089 break;
3090 case WMI_EXTENSION_EVENTID:
3091 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3092 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3093 break;
3094 case WMI_CAC_EVENTID:
3095 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3096 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3097 break;
3098 case WMI_CHANNEL_CHANGE_EVENTID:
3099 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3100 break;
3101 case WMI_REPORT_ROAM_DATA_EVENTID:
3102 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3103 break;
3104 case WMI_TEST_EVENTID:
3105 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
3106 ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
3107 break;
3108 case WMI_GET_FIXRATES_CMDID:
3109 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3110 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3111 break;
3112 case WMI_TX_RETRY_ERR_EVENTID:
3113 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3114 break;
3115 case WMI_SNR_THRESHOLD_EVENTID:
3116 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3117 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3118 break;
3119 case WMI_LQ_THRESHOLD_EVENTID:
3120 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3121 break;
3122 case WMI_APLIST_EVENTID:
3123 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3124 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3125 break;
3126 case WMI_GET_KEEPALIVE_CMDID:
3127 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3128 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3129 break;
3130 case WMI_GET_WOW_LIST_EVENTID:
3131 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
3132 ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
3133 break;
3134 case WMI_GET_PMKID_LIST_EVENTID:
3135 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3136 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3137 break;
3138 case WMI_PSPOLL_EVENTID:
3139 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3140 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3141 break;
3142 case WMI_DTIMEXPIRY_EVENTID:
3143 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3144 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3145 break;
3146 case WMI_SET_PARAMS_REPLY_EVENTID:
3147 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3148 break;
3149 case WMI_ADDBA_REQ_EVENTID:
3150 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3151 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3152 break;
3153 case WMI_ADDBA_RESP_EVENTID:
3154 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3155 break;
3156 case WMI_DELBA_REQ_EVENTID:
3157 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3158 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3159 break;
3160 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3161 ath6kl_dbg(ATH6KL_DBG_WMI,
3162 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3163 break;
3164 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3165 ath6kl_dbg(ATH6KL_DBG_WMI,
3166 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3167 break;
3168 case WMI_TX_COMPLETE_EVENTID:
3169 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3170 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3171 break;
3172 case WMI_REMAIN_ON_CHNL_EVENTID:
3173 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3174 ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3175 break;
3176 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3177 ath6kl_dbg(ATH6KL_DBG_WMI,
3178 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3179 ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3180 len, vif);
3181 break;
3182 case WMI_TX_STATUS_EVENTID:
3183 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3184 ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3185 break;
3186 case WMI_RX_PROBE_REQ_EVENTID:
3187 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3188 ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3189 break;
3190 case WMI_P2P_CAPABILITIES_EVENTID:
3191 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3192 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3193 break;
3194 case WMI_RX_ACTION_EVENTID:
3195 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3196 ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
3197 break;
3198 case WMI_P2P_INFO_EVENTID:
3199 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3200 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3201 break;
3202 default:
3203 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
3204 ret = -EINVAL;
3205 break;
3208 dev_kfree_skb(skb);
3210 return ret;
3213 static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
3215 if (!wmi)
3216 return;
3218 spin_lock_bh(&wmi->lock);
3220 wmi->fat_pipe_exist = 0;
3221 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3223 spin_unlock_bh(&wmi->lock);
3226 void *ath6kl_wmi_init(struct ath6kl *dev)
3228 struct wmi *wmi;
3230 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3231 if (!wmi)
3232 return NULL;
3234 spin_lock_init(&wmi->lock);
3236 wmi->parent_dev = dev;
3238 wmi->pwr_mode = REC_POWER;
3240 ath6kl_wmi_qos_state_init(wmi);
3242 return wmi;
3245 void ath6kl_wmi_shutdown(struct wmi *wmi)
3247 if (!wmi)
3248 return;
3250 kfree(wmi->last_mgmt_tx_frame);
3251 kfree(wmi);