ath6kl: check usb_register() return value
[deliverable/linux.git] / drivers / net / wireless / ath / ath6kl / wmi.c
CommitLineData
bdcd8170
KV
1/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
1b2df407 3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
bdcd8170
KV
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <linux/ip.h>
1560ac7d 19#include <linux/in.h>
bdcd8170
KV
20#include "core.h"
21#include "debug.h"
003353b0 22#include "testmode.h"
06033760
VN
23#include "../regd.h"
24#include "../regd_common.h"
bdcd8170 25
240d2799 26static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
bdcd8170
KV
27
28static const s32 wmi_rate_tbl[][2] = {
29 /* {W/O SGI, with SGI} */
30 {1000, 1000},
31 {2000, 2000},
32 {5500, 5500},
33 {11000, 11000},
34 {6000, 6000},
35 {9000, 9000},
36 {12000, 12000},
37 {18000, 18000},
38 {24000, 24000},
39 {36000, 36000},
40 {48000, 48000},
41 {54000, 54000},
42 {6500, 7200},
43 {13000, 14400},
44 {19500, 21700},
45 {26000, 28900},
46 {39000, 43300},
47 {52000, 57800},
48 {58500, 65000},
49 {65000, 72200},
50 {13500, 15000},
51 {27000, 30000},
52 {40500, 45000},
53 {54000, 60000},
54 {81000, 90000},
55 {108000, 120000},
56 {121500, 135000},
57 {135000, 150000},
58 {0, 0}
59};
60
61/* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
62static const u8 up_to_ac[] = {
63 WMM_AC_BE,
64 WMM_AC_BK,
65 WMM_AC_BK,
66 WMM_AC_BE,
67 WMM_AC_VI,
68 WMM_AC_VI,
69 WMM_AC_VO,
70 WMM_AC_VO,
71};
72
73void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
74{
75 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
76 return;
77
78 wmi->ep_id = ep_id;
79}
80
81enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
82{
83 return wmi->ep_id;
84}
85
6765d0aa 86struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
240d2799 87{
990bd915
VT
88 struct ath6kl_vif *vif, *found = NULL;
89
71f96ee6 90 if (WARN_ON(if_idx > (ar->vif_max - 1)))
240d2799
VT
91 return NULL;
92
990bd915 93 /* FIXME: Locking */
11f6e40d 94 spin_lock_bh(&ar->list_lock);
990bd915
VT
95 list_for_each_entry(vif, &ar->vif_list, list) {
96 if (vif->fw_vif_idx == if_idx) {
97 found = vif;
98 break;
99 }
100 }
11f6e40d 101 spin_unlock_bh(&ar->list_lock);
990bd915
VT
102
103 return found;
240d2799
VT
104}
105
bdcd8170
KV
106/* Performs DIX to 802.3 encapsulation for transmit packets.
107 * Assumes the entire DIX header is contigous and that there is
108 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
109 */
110int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
111{
112 struct ath6kl_llc_snap_hdr *llc_hdr;
113 struct ethhdr *eth_hdr;
114 size_t new_len;
115 __be16 type;
116 u8 *datap;
117 u16 size;
118
119 if (WARN_ON(skb == NULL))
120 return -EINVAL;
121
122 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
123 if (skb_headroom(skb) < size)
124 return -ENOMEM;
125
126 eth_hdr = (struct ethhdr *) skb->data;
127 type = eth_hdr->h_proto;
128
129 if (!is_ethertype(be16_to_cpu(type))) {
130 ath6kl_dbg(ATH6KL_DBG_WMI,
96f1fadc 131 "%s: pkt is already in 802.3 format\n", __func__);
bdcd8170
KV
132 return 0;
133 }
134
135 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
136
137 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
138 datap = skb->data;
139
140 eth_hdr->h_proto = cpu_to_be16(new_len);
141
142 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
143
144 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
145 llc_hdr->dsap = 0xAA;
146 llc_hdr->ssap = 0xAA;
147 llc_hdr->cntl = 0x03;
148 llc_hdr->org_code[0] = 0x0;
149 llc_hdr->org_code[1] = 0x0;
150 llc_hdr->org_code[2] = 0x0;
151 llc_hdr->eth_type = type;
152
153 return 0;
154}
155
156static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
157 u8 *version, void *tx_meta_info)
158{
159 struct wmi_tx_meta_v1 *v1;
160 struct wmi_tx_meta_v2 *v2;
161
162 if (WARN_ON(skb == NULL || version == NULL))
163 return -EINVAL;
164
165 switch (*version) {
166 case WMI_META_VERSION_1:
167 skb_push(skb, WMI_MAX_TX_META_SZ);
168 v1 = (struct wmi_tx_meta_v1 *) skb->data;
169 v1->pkt_id = 0;
170 v1->rate_plcy_id = 0;
171 *version = WMI_META_VERSION_1;
172 break;
173 case WMI_META_VERSION_2:
174 skb_push(skb, WMI_MAX_TX_META_SZ);
175 v2 = (struct wmi_tx_meta_v2 *) skb->data;
176 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
177 sizeof(struct wmi_tx_meta_v2));
178 break;
179 }
180
181 return 0;
182}
183
184int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
c1762a3f 185 u8 msg_type, u32 flags,
bdcd8170 186 enum wmi_data_hdr_data_type data_type,
6765d0aa 187 u8 meta_ver, void *tx_meta_info, u8 if_idx)
bdcd8170
KV
188{
189 struct wmi_data_hdr *data_hdr;
190 int ret;
191
71f96ee6 192 if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
bdcd8170
KV
193 return -EINVAL;
194
3ce6ff50
VT
195 if (tx_meta_info) {
196 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
197 if (ret)
198 return ret;
199 }
bdcd8170
KV
200
201 skb_push(skb, sizeof(struct wmi_data_hdr));
202
203 data_hdr = (struct wmi_data_hdr *)skb->data;
204 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
205
206 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
207 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
208
c1762a3f
TP
209 if (flags & WMI_DATA_HDR_FLAGS_MORE)
210 data_hdr->info |= WMI_DATA_HDR_MORE;
bdcd8170 211
c1762a3f
TP
212 if (flags & WMI_DATA_HDR_FLAGS_EOSP)
213 data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
214
215 data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
216 data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
bdcd8170
KV
217
218 return 0;
219}
220
c1762a3f 221u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
bdcd8170
KV
222{
223 struct iphdr *ip_hdr = (struct iphdr *) pkt;
224 u8 ip_pri;
225
226 /*
227 * Determine IPTOS priority
228 *
229 * IP-TOS - 8bits
230 * : DSCP(6-bits) ECN(2-bits)
231 * : DSCP - P2 P1 P0 X X X
232 * where (P2 P1 P0) form 802.1D
233 */
234 ip_pri = ip_hdr->tos >> 5;
235 ip_pri &= 0x7;
236
237 if ((layer2_pri & 0x7) > ip_pri)
238 return (u8) layer2_pri & 0x7;
239 else
240 return ip_pri;
241}
242
c1762a3f
TP
243u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
244{
245 return up_to_ac[user_priority & 0x7];
246}
247
240d2799
VT
248int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
249 struct sk_buff *skb,
bdcd8170
KV
250 u32 layer2_priority, bool wmm_enabled,
251 u8 *ac)
252{
253 struct wmi_data_hdr *data_hdr;
254 struct ath6kl_llc_snap_hdr *llc_hdr;
255 struct wmi_create_pstream_cmd cmd;
256 u32 meta_size, hdr_size;
257 u16 ip_type = IP_ETHERTYPE;
258 u8 stream_exist, usr_pri;
259 u8 traffic_class = WMM_AC_BE;
260 u8 *datap;
261
262 if (WARN_ON(skb == NULL))
263 return -EINVAL;
264
265 datap = skb->data;
266 data_hdr = (struct wmi_data_hdr *) datap;
267
268 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
269 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
270
271 if (!wmm_enabled) {
272 /* If WMM is disabled all traffic goes as BE traffic */
273 usr_pri = 0;
274 } else {
275 hdr_size = sizeof(struct ethhdr);
276
277 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
278 sizeof(struct
279 wmi_data_hdr) +
280 meta_size + hdr_size);
281
282 if (llc_hdr->eth_type == htons(ip_type)) {
283 /*
284 * Extract the endpoint info from the TOS field
285 * in the IP header.
286 */
287 usr_pri =
288 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
289 sizeof(struct ath6kl_llc_snap_hdr),
290 layer2_priority);
291 } else
292 usr_pri = layer2_priority & 0x7;
f3740572
VN
293
294 /*
295 * Queue the EAPOL frames in the same WMM_AC_VO queue
296 * as that of management frames.
297 */
298 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
299 usr_pri = WMI_VOICE_USER_PRIORITY;
bdcd8170
KV
300 }
301
a7f0c58b
KV
302 /*
303 * workaround for WMM S5
304 *
305 * FIXME: wmi->traffic_class is always 100 so this test doesn't
306 * make sense
307 */
bdcd8170
KV
308 if ((wmi->traffic_class == WMM_AC_VI) &&
309 ((usr_pri == 5) || (usr_pri == 4)))
310 usr_pri = 1;
311
312 /* Convert user priority to traffic class */
313 traffic_class = up_to_ac[usr_pri & 0x7];
314
315 wmi_data_hdr_set_up(data_hdr, usr_pri);
316
317 spin_lock_bh(&wmi->lock);
318 stream_exist = wmi->fat_pipe_exist;
319 spin_unlock_bh(&wmi->lock);
320
321 if (!(stream_exist & (1 << traffic_class))) {
322 memset(&cmd, 0, sizeof(cmd));
323 cmd.traffic_class = traffic_class;
324 cmd.user_pri = usr_pri;
325 cmd.inactivity_int =
326 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
327 /* Implicit streams are created with TSID 0xFF */
328 cmd.tsid = WMI_IMPLICIT_PSTREAM;
240d2799 329 ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
bdcd8170
KV
330 }
331
332 *ac = traffic_class;
333
334 return 0;
335}
336
337int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
338{
339 struct ieee80211_hdr_3addr *pwh, wh;
340 struct ath6kl_llc_snap_hdr *llc_hdr;
341 struct ethhdr eth_hdr;
342 u32 hdr_size;
343 u8 *datap;
344 __le16 sub_type;
345
346 if (WARN_ON(skb == NULL))
347 return -EINVAL;
348
349 datap = skb->data;
350 pwh = (struct ieee80211_hdr_3addr *) datap;
351
352 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
353
354 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
355
356 /* Strip off the 802.11 header */
357 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
358 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
359 sizeof(u32));
360 skb_pull(skb, hdr_size);
361 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
362 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
363
364 datap = skb->data;
365 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
366
c8790cba 367 memset(&eth_hdr, 0, sizeof(eth_hdr));
bdcd8170 368 eth_hdr.h_proto = llc_hdr->eth_type;
bdcd8170
KV
369
370 switch ((le16_to_cpu(wh.frame_control)) &
371 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
372 case 0:
373 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
374 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
375 break;
376 case IEEE80211_FCTL_TODS:
377 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
378 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
379 break;
380 case IEEE80211_FCTL_FROMDS:
381 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
382 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
383 break;
384 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
385 break;
386 }
387
388 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
389 skb_push(skb, sizeof(eth_hdr));
390
391 datap = skb->data;
392
393 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
394
395 return 0;
396}
397
398/*
399 * Performs 802.3 to DIX encapsulation for received packets.
400 * Assumes the entire 802.3 header is contigous.
401 */
402int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
403{
404 struct ath6kl_llc_snap_hdr *llc_hdr;
405 struct ethhdr eth_hdr;
406 u8 *datap;
407
408 if (WARN_ON(skb == NULL))
409 return -EINVAL;
410
411 datap = skb->data;
412
413 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
414
415 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
416 eth_hdr.h_proto = llc_hdr->eth_type;
417
418 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
419 datap = skb->data;
420
421 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
422
423 return 0;
424}
425
bdcd8170
KV
426static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
427{
428 struct tx_complete_msg_v1 *msg_v1;
429 struct wmi_tx_complete_event *evt;
430 int index;
431 u16 size;
432
433 evt = (struct wmi_tx_complete_event *) datap;
434
435 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
436 evt->num_msg, evt->msg_len, evt->msg_type);
437
bdcd8170
KV
438 for (index = 0; index < evt->num_msg; index++) {
439 size = sizeof(struct wmi_tx_complete_event) +
440 (index * sizeof(struct tx_complete_msg_v1));
441 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
442
443 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
444 msg_v1->status, msg_v1->pkt_id,
445 msg_v1->rate_idx, msg_v1->ack_failures);
446 }
447
448 return 0;
449}
450
f9e5f05c 451static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
240d2799 452 int len, struct ath6kl_vif *vif)
6465ddcf
JM
453{
454 struct wmi_remain_on_chnl_event *ev;
455 u32 freq;
456 u32 dur;
f9e5f05c
JM
457 struct ieee80211_channel *chan;
458 struct ath6kl *ar = wmi->parent_dev;
1052261e 459 u32 id;
6465ddcf
JM
460
461 if (len < sizeof(*ev))
462 return -EINVAL;
463
464 ev = (struct wmi_remain_on_chnl_event *) datap;
465 freq = le32_to_cpu(ev->freq);
466 dur = le32_to_cpu(ev->duration);
467 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
468 freq, dur);
be98e3a4 469 chan = ieee80211_get_channel(ar->wiphy, freq);
f9e5f05c 470 if (!chan) {
cdeb8602
KV
471 ath6kl_dbg(ATH6KL_DBG_WMI,
472 "remain_on_chnl: Unknown channel (freq=%u)\n",
473 freq);
f9e5f05c
JM
474 return -EINVAL;
475 }
1052261e 476 id = vif->last_roc_id;
71bbc994 477 cfg80211_ready_on_channel(&vif->wdev, id, chan, NL80211_CHAN_NO_HT,
f9e5f05c 478 dur, GFP_ATOMIC);
6465ddcf
JM
479
480 return 0;
481}
482
f9e5f05c 483static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
240d2799
VT
484 u8 *datap, int len,
485 struct ath6kl_vif *vif)
6465ddcf
JM
486{
487 struct wmi_cancel_remain_on_chnl_event *ev;
488 u32 freq;
489 u32 dur;
f9e5f05c
JM
490 struct ieee80211_channel *chan;
491 struct ath6kl *ar = wmi->parent_dev;
1052261e 492 u32 id;
6465ddcf
JM
493
494 if (len < sizeof(*ev))
495 return -EINVAL;
496
497 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
498 freq = le32_to_cpu(ev->freq);
499 dur = le32_to_cpu(ev->duration);
cdeb8602
KV
500 ath6kl_dbg(ATH6KL_DBG_WMI,
501 "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
502 freq, dur, ev->status);
be98e3a4 503 chan = ieee80211_get_channel(ar->wiphy, freq);
f9e5f05c 504 if (!chan) {
cdeb8602
KV
505 ath6kl_dbg(ATH6KL_DBG_WMI,
506 "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
507 freq);
f9e5f05c
JM
508 return -EINVAL;
509 }
1052261e
JM
510 if (vif->last_cancel_roc_id &&
511 vif->last_cancel_roc_id + 1 == vif->last_roc_id)
512 id = vif->last_cancel_roc_id; /* event for cancel command */
513 else
514 id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
515 vif->last_cancel_roc_id = 0;
71bbc994 516 cfg80211_remain_on_channel_expired(&vif->wdev, id, chan,
f9e5f05c 517 NL80211_CHAN_NO_HT, GFP_ATOMIC);
6465ddcf
JM
518
519 return 0;
520}
521
240d2799
VT
522static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
523 struct ath6kl_vif *vif)
6465ddcf
JM
524{
525 struct wmi_tx_status_event *ev;
526 u32 id;
527
528 if (len < sizeof(*ev))
529 return -EINVAL;
530
531 ev = (struct wmi_tx_status_event *) datap;
532 id = le32_to_cpu(ev->id);
533 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
534 id, ev->ack_status);
a0df5db1 535 if (wmi->last_mgmt_tx_frame) {
71bbc994 536 cfg80211_mgmt_tx_status(&vif->wdev, id,
a0df5db1
JM
537 wmi->last_mgmt_tx_frame,
538 wmi->last_mgmt_tx_frame_len,
539 !!ev->ack_status, GFP_ATOMIC);
540 kfree(wmi->last_mgmt_tx_frame);
541 wmi->last_mgmt_tx_frame = NULL;
542 wmi->last_mgmt_tx_frame_len = 0;
543 }
6465ddcf
JM
544
545 return 0;
546}
547
240d2799
VT
548static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
549 struct ath6kl_vif *vif)
6465ddcf
JM
550{
551 struct wmi_p2p_rx_probe_req_event *ev;
ae32c30a 552 u32 freq;
6465ddcf
JM
553 u16 dlen;
554
555 if (len < sizeof(*ev))
556 return -EINVAL;
557
558 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
ae32c30a 559 freq = le32_to_cpu(ev->freq);
6465ddcf 560 dlen = le16_to_cpu(ev->len);
ae32c30a 561 if (datap + len < ev->data + dlen) {
cdeb8602
KV
562 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
563 len, dlen);
ae32c30a
JM
564 return -EINVAL;
565 }
cdeb8602
KV
566 ath6kl_dbg(ATH6KL_DBG_WMI,
567 "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
cf5333d7 568 dlen, freq, vif->probe_req_report);
ae32c30a 569
cf5333d7 570 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
71bbc994 571 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
804483e9 572 ev->data, dlen, GFP_ATOMIC);
6465ddcf
JM
573
574 return 0;
575}
576
577static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
578{
579 struct wmi_p2p_capabilities_event *ev;
580 u16 dlen;
581
582 if (len < sizeof(*ev))
583 return -EINVAL;
584
585 ev = (struct wmi_p2p_capabilities_event *) datap;
586 dlen = le16_to_cpu(ev->len);
587 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
588
589 return 0;
590}
591
240d2799
VT
592static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
593 struct ath6kl_vif *vif)
6465ddcf
JM
594{
595 struct wmi_rx_action_event *ev;
9809d8ef 596 u32 freq;
6465ddcf
JM
597 u16 dlen;
598
599 if (len < sizeof(*ev))
600 return -EINVAL;
601
602 ev = (struct wmi_rx_action_event *) datap;
9809d8ef 603 freq = le32_to_cpu(ev->freq);
6465ddcf 604 dlen = le16_to_cpu(ev->len);
9809d8ef 605 if (datap + len < ev->data + dlen) {
cdeb8602
KV
606 ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
607 len, dlen);
9809d8ef
JM
608 return -EINVAL;
609 }
610 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
71bbc994 611 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
804483e9 612 ev->data, dlen, GFP_ATOMIC);
6465ddcf
JM
613
614 return 0;
615}
616
617static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
618{
619 struct wmi_p2p_info_event *ev;
620 u32 flags;
621 u16 dlen;
622
623 if (len < sizeof(*ev))
624 return -EINVAL;
625
626 ev = (struct wmi_p2p_info_event *) datap;
627 flags = le32_to_cpu(ev->info_req_flags);
628 dlen = le16_to_cpu(ev->len);
629 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
630
631 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
632 struct wmi_p2p_capabilities *cap;
633 if (dlen < sizeof(*cap))
634 return -EINVAL;
635 cap = (struct wmi_p2p_capabilities *) ev->data;
636 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
637 cap->go_power_save);
638 }
639
640 if (flags & P2P_FLAG_MACADDR_REQ) {
641 struct wmi_p2p_macaddr *mac;
642 if (dlen < sizeof(*mac))
643 return -EINVAL;
644 mac = (struct wmi_p2p_macaddr *) ev->data;
645 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
646 mac->mac_addr);
647 }
648
649 if (flags & P2P_FLAG_HMODEL_REQ) {
650 struct wmi_p2p_hmodel *mod;
651 if (dlen < sizeof(*mod))
652 return -EINVAL;
653 mod = (struct wmi_p2p_hmodel *) ev->data;
654 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
655 mod->p2p_model,
656 mod->p2p_model ? "host" : "firmware");
657 }
658 return 0;
659}
660
bdcd8170
KV
661static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
662{
663 struct sk_buff *skb;
664
665 skb = ath6kl_buf_alloc(size);
666 if (!skb)
667 return NULL;
668
669 skb_put(skb, size);
670 if (size)
671 memset(skb->data, 0, size);
672
673 return skb;
674}
675
676/* Send a "simple" wmi command -- one with no arguments */
334234b5
VT
677static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
678 enum wmi_cmd_id cmd_id)
bdcd8170
KV
679{
680 struct sk_buff *skb;
681 int ret;
682
683 skb = ath6kl_wmi_get_new_buf(0);
684 if (!skb)
685 return -ENOMEM;
686
334234b5 687 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
bdcd8170
KV
688
689 return ret;
690}
691
692static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
693{
694 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
695
696 if (len < sizeof(struct wmi_ready_event_2))
697 return -EINVAL;
698
bdcd8170
KV
699 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
700 le32_to_cpu(ev->sw_version),
d92917e4 701 le32_to_cpu(ev->abi_version), ev->phy_cap);
bdcd8170
KV
702
703 return 0;
704}
705
e5090444
VN
706/*
707 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
708 * at which the station has to roam can be passed with
709 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
710 * in dBm.
711 */
712int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
713{
714 struct sk_buff *skb;
715 struct roam_ctrl_cmd *cmd;
716
717 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
718 if (!skb)
719 return -ENOMEM;
720
721 cmd = (struct roam_ctrl_cmd *) skb->data;
722
723 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
724 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
725 DEF_SCAN_FOR_ROAM_INTVL);
726 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
727 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
728 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
729
334234b5
VT
730 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
731 NO_SYNC_WMIFLAG);
e5090444
VN
732
733 return 0;
734}
735
1261875f
JM
736int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
737{
738 struct sk_buff *skb;
739 struct roam_ctrl_cmd *cmd;
740
741 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
742 if (!skb)
743 return -ENOMEM;
744
745 cmd = (struct roam_ctrl_cmd *) skb->data;
1261875f
JM
746
747 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
748 cmd->roam_ctrl = WMI_FORCE_ROAM;
749
750 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
334234b5 751 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
1261875f
JM
752 NO_SYNC_WMIFLAG);
753}
754
d154f32e
EL
755int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
756{
757 struct sk_buff *skb;
758 struct set_dtim_cmd *cmd;
759
760 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
761 if (!skb)
762 return -ENOMEM;
763
764 cmd = (struct set_dtim_cmd *) skb->data;
765
766 cmd->dtim_period = cpu_to_le32(dtim_period);
767 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
768 WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
769}
770
1261875f
JM
771int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
772{
773 struct sk_buff *skb;
774 struct roam_ctrl_cmd *cmd;
775
776 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
777 if (!skb)
778 return -ENOMEM;
779
780 cmd = (struct roam_ctrl_cmd *) skb->data;
1261875f
JM
781
782 cmd->info.roam_mode = mode;
783 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
784
785 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
334234b5 786 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
1261875f
JM
787 NO_SYNC_WMIFLAG);
788}
789
240d2799
VT
790static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
791 struct ath6kl_vif *vif)
bdcd8170
KV
792{
793 struct wmi_connect_event *ev;
794 u8 *pie, *peie;
795
796 if (len < sizeof(struct wmi_connect_event))
797 return -EINVAL;
798
799 ev = (struct wmi_connect_event *) datap;
800
f5938f24 801 if (vif->nw_type == AP_NETWORK) {
572e27c0 802 /* AP mode start/STA connected event */
240d2799 803 struct net_device *dev = vif->ndev;
572e27c0 804 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
cdeb8602
KV
805 ath6kl_dbg(ATH6KL_DBG_WMI,
806 "%s: freq %d bssid %pM (AP started)\n",
572e27c0
JM
807 __func__, le16_to_cpu(ev->u.ap_bss.ch),
808 ev->u.ap_bss.bssid);
809 ath6kl_connect_ap_mode_bss(
240d2799 810 vif, le16_to_cpu(ev->u.ap_bss.ch));
572e27c0 811 } else {
cdeb8602
KV
812 ath6kl_dbg(ATH6KL_DBG_WMI,
813 "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
572e27c0
JM
814 __func__, ev->u.ap_sta.aid,
815 ev->u.ap_sta.mac_addr,
816 ev->u.ap_sta.auth,
817 ev->u.ap_sta.keymgmt,
818 le16_to_cpu(ev->u.ap_sta.cipher),
819 ev->u.ap_sta.apsd_info);
c1762a3f 820
572e27c0 821 ath6kl_connect_ap_mode_sta(
240d2799 822 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
572e27c0
JM
823 ev->u.ap_sta.keymgmt,
824 le16_to_cpu(ev->u.ap_sta.cipher),
825 ev->u.ap_sta.auth, ev->assoc_req_len,
c1762a3f
TP
826 ev->assoc_info + ev->beacon_ie_len,
827 ev->u.ap_sta.apsd_info);
572e27c0
JM
828 }
829 return 0;
830 }
831
832 /* STA/IBSS mode connection event */
833
b9b6ee60
KV
834 ath6kl_dbg(ATH6KL_DBG_WMI,
835 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
836 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
837 le16_to_cpu(ev->u.sta.listen_intvl),
838 le16_to_cpu(ev->u.sta.beacon_intvl),
839 le32_to_cpu(ev->u.sta.nw_type));
bdcd8170 840
bdcd8170
KV
841 /* Start of assoc rsp IEs */
842 pie = ev->assoc_info + ev->beacon_ie_len +
843 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
844
845 /* End of assoc rsp IEs */
846 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
847 ev->assoc_resp_len;
848
849 while (pie < peie) {
850 switch (*pie) {
851 case WLAN_EID_VENDOR_SPECIFIC:
852 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
853 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
854 /* WMM OUT (00:50:F2) */
ddc3d77c
KV
855 if (pie[1] > 5 &&
856 pie[6] == WMM_PARAM_OUI_SUBTYPE)
bdcd8170
KV
857 wmi->is_wmm_enabled = true;
858 }
859 break;
860 }
861
862 if (wmi->is_wmm_enabled)
863 break;
864
865 pie += pie[1] + 2;
866 }
867
240d2799 868 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
572e27c0
JM
869 ev->u.sta.bssid,
870 le16_to_cpu(ev->u.sta.listen_intvl),
871 le16_to_cpu(ev->u.sta.beacon_intvl),
872 le32_to_cpu(ev->u.sta.nw_type),
bdcd8170
KV
873 ev->beacon_ie_len, ev->assoc_req_len,
874 ev->assoc_resp_len, ev->assoc_info);
875
876 return 0;
877}
878
06033760
VN
879static struct country_code_to_enum_rd *
880ath6kl_regd_find_country(u16 countryCode)
881{
882 int i;
883
884 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
885 if (allCountries[i].countryCode == countryCode)
886 return &allCountries[i];
887 }
888
889 return NULL;
890}
891
892static struct reg_dmn_pair_mapping *
893ath6kl_get_regpair(u16 regdmn)
894{
895 int i;
896
897 if (regdmn == NO_ENUMRD)
898 return NULL;
899
900 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
901 if (regDomainPairs[i].regDmnEnum == regdmn)
902 return &regDomainPairs[i];
903 }
904
905 return NULL;
906}
907
908static struct country_code_to_enum_rd *
909ath6kl_regd_find_country_by_rd(u16 regdmn)
910{
911 int i;
912
913 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
914 if (allCountries[i].regDmnEnum == regdmn)
915 return &allCountries[i];
916 }
917
918 return NULL;
919}
920
921static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
922{
923
924 struct ath6kl_wmi_regdomain *ev;
925 struct country_code_to_enum_rd *country = NULL;
926 struct reg_dmn_pair_mapping *regpair = NULL;
927 char alpha2[2];
928 u32 reg_code;
929
930 ev = (struct ath6kl_wmi_regdomain *) datap;
931 reg_code = le32_to_cpu(ev->reg_code);
932
933 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
934 country = ath6kl_regd_find_country((u16) reg_code);
935 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
936
937 regpair = ath6kl_get_regpair((u16) reg_code);
938 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
b9b6ee60 939 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
96f1fadc 940 regpair->regDmnEnum);
06033760
VN
941 }
942
e5348a1e 943 if (country && wmi->parent_dev->wiphy_registered) {
06033760
VN
944 alpha2[0] = country->isoName[0];
945 alpha2[1] = country->isoName[1];
946
be98e3a4 947 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
06033760 948
b9b6ee60 949 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
96f1fadc 950 alpha2[0], alpha2[1]);
06033760
VN
951 }
952}
953
240d2799
VT
954static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
955 struct ath6kl_vif *vif)
bdcd8170
KV
956{
957 struct wmi_disconnect_event *ev;
958 wmi->traffic_class = 100;
959
960 if (len < sizeof(struct wmi_disconnect_event))
961 return -EINVAL;
962
963 ev = (struct wmi_disconnect_event *) datap;
bdcd8170 964
b9b6ee60
KV
965 ath6kl_dbg(ATH6KL_DBG_WMI,
966 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
967 le16_to_cpu(ev->proto_reason_status), ev->bssid,
968 ev->disconn_reason, ev->assoc_resp_len);
969
bdcd8170 970 wmi->is_wmm_enabled = false;
bdcd8170 971
240d2799 972 ath6kl_disconnect_event(vif, ev->disconn_reason,
bdcd8170
KV
973 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
974 le16_to_cpu(ev->proto_reason_status));
975
976 return 0;
977}
978
979static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
980{
981 struct wmi_peer_node_event *ev;
982
983 if (len < sizeof(struct wmi_peer_node_event))
984 return -EINVAL;
985
986 ev = (struct wmi_peer_node_event *) datap;
987
988 if (ev->event_code == PEER_NODE_JOIN_EVENT)
989 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
990 ev->peer_mac_addr);
991 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
992 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
993 ev->peer_mac_addr);
994
995 return 0;
996}
997
240d2799
VT
998static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
999 struct ath6kl_vif *vif)
bdcd8170
KV
1000{
1001 struct wmi_tkip_micerr_event *ev;
1002
1003 if (len < sizeof(struct wmi_tkip_micerr_event))
1004 return -EINVAL;
1005
1006 ev = (struct wmi_tkip_micerr_event *) datap;
1007
240d2799 1008 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
bdcd8170
KV
1009
1010 return 0;
1011}
1012
10509f90
KV
1013void ath6kl_wmi_sscan_timer(unsigned long ptr)
1014{
1015 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
1016
1017 cfg80211_sched_scan_results(vif->ar->wiphy);
1018}
1019
240d2799
VT
1020static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
1021 struct ath6kl_vif *vif)
bdcd8170 1022{
82e14f56 1023 struct wmi_bss_info_hdr2 *bih;
1aaa8c74
JM
1024 u8 *buf;
1025 struct ieee80211_channel *channel;
1026 struct ath6kl *ar = wmi->parent_dev;
1027 struct ieee80211_mgmt *mgmt;
1028 struct cfg80211_bss *bss;
bdcd8170 1029
82e14f56 1030 if (len <= sizeof(struct wmi_bss_info_hdr2))
bdcd8170
KV
1031 return -EINVAL;
1032
82e14f56
JM
1033 bih = (struct wmi_bss_info_hdr2 *) datap;
1034 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1035 len -= sizeof(struct wmi_bss_info_hdr2);
bdcd8170
KV
1036
1037 ath6kl_dbg(ATH6KL_DBG_WMI,
1aaa8c74
JM
1038 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1039 "frame_type=%d\n",
82e14f56 1040 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
1aaa8c74 1041 bih->frame_type);
bdcd8170 1042
1aaa8c74
JM
1043 if (bih->frame_type != BEACON_FTYPE &&
1044 bih->frame_type != PROBERESP_FTYPE)
1045 return 0; /* Only update BSS table for now */
bdcd8170 1046
551185ca 1047 if (bih->frame_type == BEACON_FTYPE &&
59c98449
VT
1048 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1049 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
240d2799
VT
1050 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1051 NONE_BSS_FILTER, 0);
551185ca
JM
1052 }
1053
be98e3a4 1054 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
1aaa8c74
JM
1055 if (channel == NULL)
1056 return -EINVAL;
bdcd8170 1057
1aaa8c74 1058 if (len < 8 + 2 + 2)
bdcd8170
KV
1059 return -EINVAL;
1060
ddc3d77c
KV
1061 if (bih->frame_type == BEACON_FTYPE &&
1062 test_bit(CONNECTED, &vif->flags) &&
1063 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
32c10874
JM
1064 const u8 *tim;
1065 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1066 len - 8 - 2 - 2);
1067 if (tim && tim[1] >= 2) {
cf5333d7 1068 vif->assoc_bss_dtim_period = tim[3];
59c98449 1069 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
32c10874
JM
1070 }
1071 }
1072
bdcd8170 1073 /*
1aaa8c74
JM
1074 * In theory, use of cfg80211_inform_bss() would be more natural here
1075 * since we do not have the full frame. However, at least for now,
1076 * cfg80211 can only distinguish Beacon and Probe Response frames from
1077 * each other when using cfg80211_inform_bss_frame(), so let's build a
1078 * fake IEEE 802.11 header to be able to take benefit of this.
bdcd8170 1079 */
1aaa8c74
JM
1080 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1081 if (mgmt == NULL)
1082 return -EINVAL;
bdcd8170 1083
1aaa8c74
JM
1084 if (bih->frame_type == BEACON_FTYPE) {
1085 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1086 IEEE80211_STYPE_BEACON);
1087 memset(mgmt->da, 0xff, ETH_ALEN);
1088 } else {
240d2799 1089 struct net_device *dev = vif->ndev;
bdcd8170 1090
1aaa8c74
JM
1091 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1092 IEEE80211_STYPE_PROBE_RESP);
1093 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
bdcd8170 1094 }
1aaa8c74
JM
1095 mgmt->duration = cpu_to_le16(0);
1096 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1097 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1098 mgmt->seq_ctrl = cpu_to_le16(0);
bdcd8170 1099
1aaa8c74
JM
1100 memcpy(&mgmt->u.beacon, buf, len);
1101
be98e3a4 1102 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
82e14f56
JM
1103 24 + len, (bih->snr - 95) * 100,
1104 GFP_ATOMIC);
1aaa8c74
JM
1105 kfree(mgmt);
1106 if (bss == NULL)
1107 return -ENOMEM;
1108 cfg80211_put_bss(bss);
bdcd8170 1109
10509f90
KV
1110 /*
1111 * Firmware doesn't return any event when scheduled scan has
1112 * finished, so we need to use a timer to find out when there are
1113 * no more results.
1114 *
1115 * The timer is started from the first bss info received, otherwise
1116 * the timer would not ever fire if the scan interval is short
1117 * enough.
1118 */
1119 if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
1120 !timer_pending(&vif->sched_scan_timer)) {
1121 mod_timer(&vif->sched_scan_timer, jiffies +
1122 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1123 }
1124
bdcd8170
KV
1125 return 0;
1126}
1127
bdcd8170
KV
1128/* Inactivity timeout of a fatpipe(pstream) at the target */
1129static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1130 int len)
1131{
1132 struct wmi_pstream_timeout_event *ev;
1133
1134 if (len < sizeof(struct wmi_pstream_timeout_event))
1135 return -EINVAL;
1136
1137 ev = (struct wmi_pstream_timeout_event *) datap;
1138
1139 /*
1140 * When the pstream (fat pipe == AC) timesout, it means there were
1141 * no thinStreams within this pstream & it got implicitly created
1142 * due to data flow on this AC. We start the inactivity timer only
1143 * for implicitly created pstream. Just reset the host state.
1144 */
1145 spin_lock_bh(&wmi->lock);
1146 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1147 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1148 spin_unlock_bh(&wmi->lock);
1149
1150 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1151 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1152
1153 return 0;
1154}
1155
1156static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1157{
1158 struct wmi_bit_rate_reply *reply;
1159 s32 rate;
1160 u32 sgi, index;
1161
1162 if (len < sizeof(struct wmi_bit_rate_reply))
1163 return -EINVAL;
1164
1165 reply = (struct wmi_bit_rate_reply *) datap;
1166
1167 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1168
1169 if (reply->rate_index == (s8) RATE_AUTO) {
1170 rate = RATE_AUTO;
1171 } else {
1172 index = reply->rate_index & 0x7f;
1173 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1174 rate = wmi_rate_tbl[index][sgi];
1175 }
1176
1177 ath6kl_wakeup_event(wmi->parent_dev);
1178
1179 return 0;
1180}
1181
4f34dace 1182static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
003353b0 1183{
4f34dace 1184 ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
003353b0
KV
1185
1186 return 0;
1187}
1188
bdcd8170
KV
1189static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1190{
1191 if (len < sizeof(struct wmi_fix_rates_reply))
1192 return -EINVAL;
1193
1194 ath6kl_wakeup_event(wmi->parent_dev);
1195
1196 return 0;
1197}
1198
1199static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1200{
1201 if (len < sizeof(struct wmi_channel_list_reply))
1202 return -EINVAL;
1203
1204 ath6kl_wakeup_event(wmi->parent_dev);
1205
1206 return 0;
1207}
1208
1209static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1210{
1211 struct wmi_tx_pwr_reply *reply;
1212
1213 if (len < sizeof(struct wmi_tx_pwr_reply))
1214 return -EINVAL;
1215
1216 reply = (struct wmi_tx_pwr_reply *) datap;
1217 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1218
1219 return 0;
1220}
1221
1222static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1223{
1224 if (len < sizeof(struct wmi_get_keepalive_cmd))
1225 return -EINVAL;
1226
1227 ath6kl_wakeup_event(wmi->parent_dev);
1228
1229 return 0;
1230}
1231
240d2799
VT
1232static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1233 struct ath6kl_vif *vif)
bdcd8170
KV
1234{
1235 struct wmi_scan_complete_event *ev;
1236
1237 ev = (struct wmi_scan_complete_event *) datap;
1238
240d2799 1239 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
bdcd8170
KV
1240 wmi->is_probe_ssid = false;
1241
1242 return 0;
1243}
1244
86512136 1245static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
240d2799 1246 int len, struct ath6kl_vif *vif)
86512136
JM
1247{
1248 struct wmi_neighbor_report_event *ev;
1249 u8 i;
1250
1251 if (len < sizeof(*ev))
1252 return -EINVAL;
1253 ev = (struct wmi_neighbor_report_event *) datap;
1254 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1255 > len) {
cdeb8602
KV
1256 ath6kl_dbg(ATH6KL_DBG_WMI,
1257 "truncated neighbor event (num=%d len=%d)\n",
1258 ev->num_neighbors, len);
86512136
JM
1259 return -EINVAL;
1260 }
1261 for (i = 0; i < ev->num_neighbors; i++) {
1262 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1263 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1264 ev->neighbor[i].bss_flags);
240d2799 1265 cfg80211_pmksa_candidate_notify(vif->ndev, i,
86512136
JM
1266 ev->neighbor[i].bssid,
1267 !!(ev->neighbor[i].bss_flags &
1268 WMI_PREAUTH_CAPABLE_BSS),
1269 GFP_ATOMIC);
1270 }
1271
1272 return 0;
1273}
1274
bdcd8170
KV
1275/*
1276 * Target is reporting a programming error. This is for
1277 * developer aid only. Target only checks a few common violations
1278 * and it is responsibility of host to do all error checking.
1279 * Behavior of target after wmi error event is undefined.
1280 * A reset is recommended.
1281 */
1282static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1283{
1284 const char *type = "unknown error";
1285 struct wmi_cmd_error_event *ev;
1286 ev = (struct wmi_cmd_error_event *) datap;
1287
1288 switch (ev->err_code) {
1289 case INVALID_PARAM:
1290 type = "invalid parameter";
1291 break;
1292 case ILLEGAL_STATE:
1293 type = "invalid state";
1294 break;
1295 case INTERNAL_ERROR:
1296 type = "internal error";
1297 break;
1298 }
1299
1300 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1301 ev->cmd_id, type);
1302
1303 return 0;
1304}
1305
240d2799
VT
1306static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1307 struct ath6kl_vif *vif)
bdcd8170 1308{
240d2799 1309 ath6kl_tgt_stats_event(vif, datap, len);
bdcd8170
KV
1310
1311 return 0;
1312}
1313
1314static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1315 struct sq_threshold_params *sq_thresh,
1316 u32 size)
1317{
1318 u32 index;
1319 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1320
1321 /* The list is already in sorted order. Get the next lower value */
1322 for (index = 0; index < size; index++) {
1323 if (rssi < sq_thresh->upper_threshold[index]) {
1324 threshold = (u8) sq_thresh->upper_threshold[index];
1325 break;
1326 }
1327 }
1328
1329 return threshold;
1330}
1331
1332static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1333 struct sq_threshold_params *sq_thresh,
1334 u32 size)
1335{
1336 u32 index;
1337 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1338
1339 /* The list is already in sorted order. Get the next lower value */
1340 for (index = 0; index < size; index++) {
1341 if (rssi > sq_thresh->lower_threshold[index]) {
1342 threshold = (u8) sq_thresh->lower_threshold[index];
1343 break;
1344 }
1345 }
1346
1347 return threshold;
1348}
1349
1350static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1351 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1352{
1353 struct sk_buff *skb;
1354 struct wmi_rssi_threshold_params_cmd *cmd;
1355
1356 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1357 if (!skb)
1358 return -ENOMEM;
1359
1360 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1361 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1362
334234b5 1363 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
bdcd8170
KV
1364 NO_SYNC_WMIFLAG);
1365}
1366
1367static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1368 int len)
1369{
1370 struct wmi_rssi_threshold_event *reply;
1371 struct wmi_rssi_threshold_params_cmd cmd;
1372 struct sq_threshold_params *sq_thresh;
1373 enum wmi_rssi_threshold_val new_threshold;
1374 u8 upper_rssi_threshold, lower_rssi_threshold;
1375 s16 rssi;
1376 int ret;
1377
1378 if (len < sizeof(struct wmi_rssi_threshold_event))
1379 return -EINVAL;
1380
1381 reply = (struct wmi_rssi_threshold_event *) datap;
1382 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1383 rssi = a_sle16_to_cpu(reply->rssi);
1384
1385 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1386
1387 /*
1388 * Identify the threshold breached and communicate that to the app.
1389 * After that install a new set of thresholds based on the signal
1390 * quality reported by the target
1391 */
1392 if (new_threshold) {
1393 /* Upper threshold breached */
1394 if (rssi < sq_thresh->upper_threshold[0]) {
1395 ath6kl_dbg(ATH6KL_DBG_WMI,
96f1fadc
KV
1396 "spurious upper rssi threshold event: %d\n",
1397 rssi);
bdcd8170
KV
1398 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1399 (rssi >= sq_thresh->upper_threshold[0])) {
1400 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1401 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1402 (rssi >= sq_thresh->upper_threshold[1])) {
1403 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1404 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1405 (rssi >= sq_thresh->upper_threshold[2])) {
1406 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1407 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1408 (rssi >= sq_thresh->upper_threshold[3])) {
1409 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1410 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1411 (rssi >= sq_thresh->upper_threshold[4])) {
1412 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1413 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1414 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1415 }
1416 } else {
1417 /* Lower threshold breached */
1418 if (rssi > sq_thresh->lower_threshold[0]) {
1419 ath6kl_dbg(ATH6KL_DBG_WMI,
96f1fadc 1420 "spurious lower rssi threshold event: %d %d\n",
bdcd8170
KV
1421 rssi, sq_thresh->lower_threshold[0]);
1422 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1423 (rssi <= sq_thresh->lower_threshold[0])) {
1424 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1425 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1426 (rssi <= sq_thresh->lower_threshold[1])) {
1427 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1428 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1429 (rssi <= sq_thresh->lower_threshold[2])) {
1430 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1431 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1432 (rssi <= sq_thresh->lower_threshold[3])) {
1433 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1434 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1435 (rssi <= sq_thresh->lower_threshold[4])) {
1436 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1437 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1438 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1439 }
1440 }
1441
1442 /* Calculate and install the next set of thresholds */
1443 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1444 sq_thresh->lower_threshold_valid_count);
1445 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1446 sq_thresh->upper_threshold_valid_count);
1447
1448 /* Issue a wmi command to install the thresholds */
1449 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1450 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1451 cmd.weight = sq_thresh->weight;
1452 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1453
1454 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1455 if (ret) {
1456 ath6kl_err("unable to configure rssi thresholds\n");
1457 return -EIO;
1458 }
1459
1460 return 0;
1461}
1462
240d2799
VT
1463static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1464 struct ath6kl_vif *vif)
bdcd8170
KV
1465{
1466 struct wmi_cac_event *reply;
1467 struct ieee80211_tspec_ie *ts;
1468 u16 active_tsids, tsinfo;
1469 u8 tsid, index;
1470 u8 ts_id;
1471
1472 if (len < sizeof(struct wmi_cac_event))
1473 return -EINVAL;
1474
1475 reply = (struct wmi_cac_event *) datap;
1476
1477 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1478 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1479
1480 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1481 tsinfo = le16_to_cpu(ts->tsinfo);
1482 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1483 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1484
240d2799
VT
1485 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1486 reply->ac, tsid);
bdcd8170
KV
1487 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1488 /*
1489 * Following assumes that there is only one outstanding
1490 * ADDTS request when this event is received
1491 */
1492 spin_lock_bh(&wmi->lock);
1493 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1494 spin_unlock_bh(&wmi->lock);
1495
1496 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1497 if ((active_tsids >> index) & 1)
1498 break;
1499 }
1500 if (index < (sizeof(active_tsids) * 8))
240d2799
VT
1501 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1502 reply->ac, index);
bdcd8170
KV
1503 }
1504
1505 /*
1506 * Clear active tsids and Add missing handling
1507 * for delete qos stream from AP
1508 */
1509 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1510
1511 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1512 tsinfo = le16_to_cpu(ts->tsinfo);
1513 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1514 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1515
1516 spin_lock_bh(&wmi->lock);
1517 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1518 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1519 spin_unlock_bh(&wmi->lock);
1520
1521 /* Indicate stream inactivity to driver layer only if all tsids
1522 * within this AC are deleted.
1523 */
1524 if (!active_tsids) {
1525 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1526 false);
1527 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1528 }
1529 }
1530
1531 return 0;
1532}
1533
279b2862
TP
1534static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
1535 struct ath6kl_vif *vif)
1536{
1537 struct wmi_txe_notify_event *ev;
1538 u32 rate, pkts;
1539
1540 if (len < sizeof(*ev))
1541 return -EINVAL;
1542
1543 if (vif->sme_state != SME_CONNECTED)
1544 return -ENOTCONN;
1545
1546 ev = (struct wmi_txe_notify_event *) datap;
1547 rate = le32_to_cpu(ev->rate);
1548 pkts = le32_to_cpu(ev->pkts);
1549
1550 ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d% pkts %d intvl %ds\n",
1551 vif->bssid, rate, pkts, vif->txe_intvl);
1552
1553 cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
1554 rate, vif->txe_intvl, GFP_KERNEL);
1555
1556 return 0;
1557}
1558
1559int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
1560 u32 rate, u32 pkts, u32 intvl)
1561{
1562 struct sk_buff *skb;
1563 struct wmi_txe_notify_cmd *cmd;
1564
1565 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1566 if (!skb)
1567 return -ENOMEM;
1568
1569 cmd = (struct wmi_txe_notify_cmd *) skb->data;
1570 cmd->rate = cpu_to_le32(rate);
1571 cmd->pkts = cpu_to_le32(pkts);
1572 cmd->intvl = cpu_to_le32(intvl);
1573
1574 return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
1575 NO_SYNC_WMIFLAG);
1576}
1577
85b20fc2
TP
1578int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
1579{
1580 struct sk_buff *skb;
1581 struct wmi_set_rssi_filter_cmd *cmd;
1582 int ret;
1583
1584 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1585 if (!skb)
1586 return -ENOMEM;
1587
1588 cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
1589 cmd->rssi = rssi;
1590
1591 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
1592 NO_SYNC_WMIFLAG);
1593 return ret;
1594}
1595
bdcd8170
KV
1596static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1597 struct wmi_snr_threshold_params_cmd *snr_cmd)
1598{
1599 struct sk_buff *skb;
1600 struct wmi_snr_threshold_params_cmd *cmd;
1601
1602 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1603 if (!skb)
1604 return -ENOMEM;
1605
1606 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1607 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1608
334234b5 1609 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
bdcd8170
KV
1610 NO_SYNC_WMIFLAG);
1611}
1612
1613static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1614 int len)
1615{
1616 struct wmi_snr_threshold_event *reply;
1617 struct sq_threshold_params *sq_thresh;
1618 struct wmi_snr_threshold_params_cmd cmd;
1619 enum wmi_snr_threshold_val new_threshold;
1620 u8 upper_snr_threshold, lower_snr_threshold;
1621 s16 snr;
1622 int ret;
1623
1624 if (len < sizeof(struct wmi_snr_threshold_event))
1625 return -EINVAL;
1626
1627 reply = (struct wmi_snr_threshold_event *) datap;
1628
1629 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1630 snr = reply->snr;
1631
1632 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1633
1634 /*
1635 * Identify the threshold breached and communicate that to the app.
1636 * After that install a new set of thresholds based on the signal
1637 * quality reported by the target.
1638 */
1639 if (new_threshold) {
1640 /* Upper threshold breached */
1641 if (snr < sq_thresh->upper_threshold[0]) {
1642 ath6kl_dbg(ATH6KL_DBG_WMI,
96f1fadc
KV
1643 "spurious upper snr threshold event: %d\n",
1644 snr);
bdcd8170
KV
1645 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1646 (snr >= sq_thresh->upper_threshold[0])) {
1647 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1648 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1649 (snr >= sq_thresh->upper_threshold[1])) {
1650 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1651 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1652 (snr >= sq_thresh->upper_threshold[2])) {
1653 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1654 } else if (snr >= sq_thresh->upper_threshold[3]) {
1655 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1656 }
1657 } else {
1658 /* Lower threshold breached */
1659 if (snr > sq_thresh->lower_threshold[0]) {
1660 ath6kl_dbg(ATH6KL_DBG_WMI,
96f1fadc
KV
1661 "spurious lower snr threshold event: %d\n",
1662 sq_thresh->lower_threshold[0]);
bdcd8170
KV
1663 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1664 (snr <= sq_thresh->lower_threshold[0])) {
1665 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1666 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1667 (snr <= sq_thresh->lower_threshold[1])) {
1668 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1669 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1670 (snr <= sq_thresh->lower_threshold[2])) {
1671 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1672 } else if (snr <= sq_thresh->lower_threshold[3]) {
1673 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1674 }
1675 }
1676
1677 /* Calculate and install the next set of thresholds */
1678 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1679 sq_thresh->lower_threshold_valid_count);
1680 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1681 sq_thresh->upper_threshold_valid_count);
1682
1683 /* Issue a wmi command to install the thresholds */
1684 cmd.thresh_above1_val = upper_snr_threshold;
1685 cmd.thresh_below1_val = lower_snr_threshold;
1686 cmd.weight = sq_thresh->weight;
1687 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1688
1689 ath6kl_dbg(ATH6KL_DBG_WMI,
1690 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1691 snr, new_threshold,
1692 lower_snr_threshold, upper_snr_threshold);
1693
1694 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1695 if (ret) {
1696 ath6kl_err("unable to configure snr threshold\n");
1697 return -EIO;
1698 }
1699
1700 return 0;
1701}
1702
1703static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1704{
1705 u16 ap_info_entry_size;
1706 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1707 struct wmi_ap_info_v1 *ap_info_v1;
1708 u8 index;
1709
1710 if (len < sizeof(struct wmi_aplist_event) ||
1711 ev->ap_list_ver != APLIST_VER1)
1712 return -EINVAL;
1713
1714 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1715 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1716
1717 ath6kl_dbg(ATH6KL_DBG_WMI,
1718 "number of APs in aplist event: %d\n", ev->num_ap);
1719
1720 if (len < (int) (sizeof(struct wmi_aplist_event) +
1721 (ev->num_ap - 1) * ap_info_entry_size))
1722 return -EINVAL;
1723
1724 /* AP list version 1 contents */
1725 for (index = 0; index < ev->num_ap; index++) {
1726 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1727 index, ap_info_v1->bssid, ap_info_v1->channel);
1728 ap_info_v1++;
1729 }
1730
1731 return 0;
1732}
1733
334234b5 1734int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
bdcd8170
KV
1735 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1736{
1737 struct wmi_cmd_hdr *cmd_hdr;
1738 enum htc_endpoint_id ep_id = wmi->ep_id;
1739 int ret;
334234b5 1740 u16 info1;
bdcd8170 1741
0616dc1f
VT
1742 if (WARN_ON(skb == NULL ||
1743 (if_idx > (wmi->parent_dev->vif_max - 1)))) {
1744 dev_kfree_skb(skb);
bdcd8170 1745 return -EINVAL;
0616dc1f 1746 }
bdcd8170 1747
b9b6ee60
KV
1748 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1749 cmd_id, skb->len, sync_flag);
1750 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1751 skb->data, skb->len);
1752
bdcd8170
KV
1753 if (sync_flag >= END_WMIFLAG) {
1754 dev_kfree_skb(skb);
1755 return -EINVAL;
1756 }
1757
1758 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1759 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1760 /*
1761 * Make sure all data currently queued is transmitted before
1762 * the cmd execution. Establish a new sync point.
1763 */
240d2799 1764 ath6kl_wmi_sync_point(wmi, if_idx);
bdcd8170
KV
1765 }
1766
1767 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1768
1769 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1770 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
334234b5
VT
1771 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1772 cmd_hdr->info1 = cpu_to_le16(info1);
bdcd8170
KV
1773
1774 /* Only for OPT_TX_CMD, use BE endpoint. */
1775 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1776 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
6765d0aa 1777 false, false, 0, NULL, if_idx);
bdcd8170
KV
1778 if (ret) {
1779 dev_kfree_skb(skb);
1780 return ret;
1781 }
1782 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1783 }
1784
1785 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1786
1787 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1788 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1789 /*
1790 * Make sure all new data queued waits for the command to
1791 * execute. Establish a new sync point.
1792 */
240d2799 1793 ath6kl_wmi_sync_point(wmi, if_idx);
bdcd8170
KV
1794 }
1795
1796 return 0;
1797}
1798
334234b5
VT
1799int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1800 enum network_type nw_type,
bdcd8170
KV
1801 enum dot11_auth_mode dot11_auth_mode,
1802 enum auth_mode auth_mode,
1803 enum crypto_type pairwise_crypto,
1804 u8 pairwise_crypto_len,
1805 enum crypto_type group_crypto,
1806 u8 group_crypto_len, int ssid_len, u8 *ssid,
3ca9d1fc
AT
1807 u8 *bssid, u16 channel, u32 ctrl_flags,
1808 u8 nw_subtype)
bdcd8170
KV
1809{
1810 struct sk_buff *skb;
1811 struct wmi_connect_cmd *cc;
1812 int ret;
1813
b9b6ee60
KV
1814 ath6kl_dbg(ATH6KL_DBG_WMI,
1815 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1816 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1817 bssid, channel, ctrl_flags, ssid_len, nw_type,
1818 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1819 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1820
bdcd8170
KV
1821 wmi->traffic_class = 100;
1822
1823 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1824 return -EINVAL;
1825
1826 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1827 return -EINVAL;
1828
1829 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1830 if (!skb)
1831 return -ENOMEM;
1832
1833 cc = (struct wmi_connect_cmd *) skb->data;
1834
1835 if (ssid_len)
1836 memcpy(cc->ssid, ssid, ssid_len);
1837
1838 cc->ssid_len = ssid_len;
1839 cc->nw_type = nw_type;
1840 cc->dot11_auth_mode = dot11_auth_mode;
1841 cc->auth_mode = auth_mode;
1842 cc->prwise_crypto_type = pairwise_crypto;
1843 cc->prwise_crypto_len = pairwise_crypto_len;
1844 cc->grp_crypto_type = group_crypto;
1845 cc->grp_crypto_len = group_crypto_len;
1846 cc->ch = cpu_to_le16(channel);
1847 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
3ca9d1fc 1848 cc->nw_subtype = nw_subtype;
bdcd8170
KV
1849
1850 if (bssid != NULL)
1851 memcpy(cc->bssid, bssid, ETH_ALEN);
1852
334234b5
VT
1853 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1854 NO_SYNC_WMIFLAG);
bdcd8170
KV
1855
1856 return ret;
1857}
1858
334234b5
VT
1859int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1860 u16 channel)
bdcd8170
KV
1861{
1862 struct sk_buff *skb;
1863 struct wmi_reconnect_cmd *cc;
1864 int ret;
1865
b9b6ee60
KV
1866 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1867 bssid, channel);
1868
bdcd8170
KV
1869 wmi->traffic_class = 100;
1870
1871 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1872 if (!skb)
1873 return -ENOMEM;
1874
1875 cc = (struct wmi_reconnect_cmd *) skb->data;
1876 cc->channel = cpu_to_le16(channel);
1877
1878 if (bssid != NULL)
1879 memcpy(cc->bssid, bssid, ETH_ALEN);
1880
334234b5 1881 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
bdcd8170
KV
1882 NO_SYNC_WMIFLAG);
1883
1884 return ret;
1885}
1886
334234b5 1887int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
bdcd8170
KV
1888{
1889 int ret;
1890
b9b6ee60
KV
1891 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1892
bdcd8170
KV
1893 wmi->traffic_class = 100;
1894
1895 /* Disconnect command does not need to do a SYNC before. */
334234b5 1896 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
bdcd8170
KV
1897
1898 return ret;
1899}
1900
c8c72b74
KV
1901/* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1902 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1903 * mgmt operations using station interface.
1904 */
11f0bfcf
KV
1905static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1906 enum wmi_scan_type scan_type,
1907 u32 force_fgscan, u32 is_legacy,
1908 u32 home_dwell_time,
1909 u32 force_scan_interval,
1910 s8 num_chan, u16 *ch_list)
3ca9d1fc
AT
1911{
1912 struct sk_buff *skb;
c8c72b74
KV
1913 struct wmi_start_scan_cmd *sc;
1914 s8 size;
1915 int i, ret;
3ca9d1fc 1916
c8c72b74 1917 size = sizeof(struct wmi_start_scan_cmd);
3ca9d1fc
AT
1918
1919 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1920 return -EINVAL;
1921
1922 if (num_chan > WMI_MAX_CHANNELS)
1923 return -EINVAL;
1924
1925 if (num_chan)
1926 size += sizeof(u16) * (num_chan - 1);
1927
1928 skb = ath6kl_wmi_get_new_buf(size);
1929 if (!skb)
1930 return -ENOMEM;
1931
c8c72b74 1932 sc = (struct wmi_start_scan_cmd *) skb->data;
3ca9d1fc
AT
1933 sc->scan_type = scan_type;
1934 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1935 sc->is_legacy = cpu_to_le32(is_legacy);
1936 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1937 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
3ca9d1fc
AT
1938 sc->num_ch = num_chan;
1939
3ca9d1fc
AT
1940 for (i = 0; i < num_chan; i++)
1941 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1942
c8c72b74 1943 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
3ca9d1fc
AT
1944 NO_SYNC_WMIFLAG);
1945
1946 return ret;
1947}
1948
11f0bfcf
KV
1949/*
1950 * beginscan supports (compared to old startscan) P2P mgmt operations using
1951 * station interface, send additional information like supported rates to
1952 * advertise and xmit rates for probe requests
1953 */
c8c72b74 1954int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
334234b5 1955 enum wmi_scan_type scan_type,
bdcd8170
KV
1956 u32 force_fgscan, u32 is_legacy,
1957 u32 home_dwell_time, u32 force_scan_interval,
c8c72b74 1958 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
bdcd8170 1959{
c8c72b74 1960 struct ieee80211_supported_band *sband;
bdcd8170 1961 struct sk_buff *skb;
c8c72b74
KV
1962 struct wmi_begin_scan_cmd *sc;
1963 s8 size, *supp_rates;
1964 int i, band, ret;
1965 struct ath6kl *ar = wmi->parent_dev;
1966 int num_rates;
1967 u32 ratemask;
bdcd8170 1968
11f0bfcf
KV
1969 if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
1970 ar->fw_capabilities)) {
1971 return ath6kl_wmi_startscan_cmd(wmi, if_idx,
1972 scan_type, force_fgscan,
1973 is_legacy, home_dwell_time,
1974 force_scan_interval,
1975 num_chan, ch_list);
1976 }
1977
c8c72b74 1978 size = sizeof(struct wmi_begin_scan_cmd);
bdcd8170
KV
1979
1980 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1981 return -EINVAL;
1982
1983 if (num_chan > WMI_MAX_CHANNELS)
1984 return -EINVAL;
1985
1986 if (num_chan)
1987 size += sizeof(u16) * (num_chan - 1);
1988
1989 skb = ath6kl_wmi_get_new_buf(size);
1990 if (!skb)
1991 return -ENOMEM;
1992
c8c72b74 1993 sc = (struct wmi_begin_scan_cmd *) skb->data;
bdcd8170
KV
1994 sc->scan_type = scan_type;
1995 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1996 sc->is_legacy = cpu_to_le32(is_legacy);
1997 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1998 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
c8c72b74 1999 sc->no_cck = cpu_to_le32(no_cck);
bdcd8170
KV
2000 sc->num_ch = num_chan;
2001
c8c72b74
KV
2002 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2003 sband = ar->wiphy->bands[band];
2004
2005 if (!sband)
2006 continue;
2007
2008 ratemask = rates[band];
2009 supp_rates = sc->supp_rates[band].rates;
2010 num_rates = 0;
2011
2012 for (i = 0; i < sband->n_bitrates; i++) {
2013 if ((BIT(i) & ratemask) == 0)
2014 continue; /* skip rate */
2015 supp_rates[num_rates++] =
2016 (u8) (sband->bitrates[i].bitrate / 5);
2017 }
2018 sc->supp_rates[band].nrates = num_rates;
2019 }
2020
1276c9ef
EL
2021 for (i = 0; i < num_chan; i++)
2022 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
bdcd8170 2023
c8c72b74 2024 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
bdcd8170
KV
2025 NO_SYNC_WMIFLAG);
2026
2027 return ret;
2028}
2029
334234b5
VT
2030int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
2031 u16 fg_start_sec,
bdcd8170
KV
2032 u16 fg_end_sec, u16 bg_sec,
2033 u16 minact_chdw_msec, u16 maxact_chdw_msec,
2034 u16 pas_chdw_msec, u8 short_scan_ratio,
2035 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
2036 u16 maxact_scan_per_ssid)
2037{
2038 struct sk_buff *skb;
2039 struct wmi_scan_params_cmd *sc;
2040 int ret;
2041
2042 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2043 if (!skb)
2044 return -ENOMEM;
2045
2046 sc = (struct wmi_scan_params_cmd *) skb->data;
2047 sc->fg_start_period = cpu_to_le16(fg_start_sec);
2048 sc->fg_end_period = cpu_to_le16(fg_end_sec);
2049 sc->bg_period = cpu_to_le16(bg_sec);
2050 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
2051 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
2052 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
2053 sc->short_scan_ratio = short_scan_ratio;
2054 sc->scan_ctrl_flags = scan_ctrl_flag;
2055 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
2056 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
2057
334234b5 2058 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
bdcd8170
KV
2059 NO_SYNC_WMIFLAG);
2060 return ret;
2061}
2062
240d2799 2063int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
bdcd8170
KV
2064{
2065 struct sk_buff *skb;
2066 struct wmi_bss_filter_cmd *cmd;
2067 int ret;
2068
2069 if (filter >= LAST_BSS_FILTER)
2070 return -EINVAL;
2071
2072 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2073 if (!skb)
2074 return -ENOMEM;
2075
2076 cmd = (struct wmi_bss_filter_cmd *) skb->data;
2077 cmd->bss_filter = filter;
2078 cmd->ie_mask = cpu_to_le32(ie_mask);
2079
240d2799 2080 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
bdcd8170
KV
2081 NO_SYNC_WMIFLAG);
2082 return ret;
2083}
2084
334234b5 2085int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
bdcd8170
KV
2086 u8 ssid_len, u8 *ssid)
2087{
2088 struct sk_buff *skb;
2089 struct wmi_probed_ssid_cmd *cmd;
2090 int ret;
2091
8ab5415d 2092 if (index >= MAX_PROBED_SSIDS)
bdcd8170
KV
2093 return -EINVAL;
2094
2095 if (ssid_len > sizeof(cmd->ssid))
2096 return -EINVAL;
2097
2098 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
2099 return -EINVAL;
2100
2101 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
2102 return -EINVAL;
2103
2104 if (flag & SPECIFIC_SSID_FLAG)
2105 wmi->is_probe_ssid = true;
2106
2107 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2108 if (!skb)
2109 return -ENOMEM;
2110
2111 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2112 cmd->entry_index = index;
2113 cmd->flag = flag;
2114 cmd->ssid_len = ssid_len;
2115 memcpy(cmd->ssid, ssid, ssid_len);
2116
334234b5 2117 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
bdcd8170
KV
2118 NO_SYNC_WMIFLAG);
2119 return ret;
2120}
2121
334234b5
VT
2122int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2123 u16 listen_interval,
bdcd8170
KV
2124 u16 listen_beacons)
2125{
2126 struct sk_buff *skb;
2127 struct wmi_listen_int_cmd *cmd;
2128 int ret;
2129
2130 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2131 if (!skb)
2132 return -ENOMEM;
2133
2134 cmd = (struct wmi_listen_int_cmd *) skb->data;
2135 cmd->listen_intvl = cpu_to_le16(listen_interval);
2136 cmd->num_beacons = cpu_to_le16(listen_beacons);
2137
334234b5 2138 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
bdcd8170
KV
2139 NO_SYNC_WMIFLAG);
2140 return ret;
2141}
2142
ce0dc0cf
RM
2143int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2144 u16 bmiss_time, u16 num_beacons)
2145{
2146 struct sk_buff *skb;
2147 struct wmi_bmiss_time_cmd *cmd;
2148 int ret;
2149
2150 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2151 if (!skb)
2152 return -ENOMEM;
2153
2154 cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2155 cmd->bmiss_time = cpu_to_le16(bmiss_time);
2156 cmd->num_beacons = cpu_to_le16(num_beacons);
2157
2158 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2159 NO_SYNC_WMIFLAG);
2160 return ret;
2161}
2162
334234b5 2163int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
bdcd8170
KV
2164{
2165 struct sk_buff *skb;
2166 struct wmi_power_mode_cmd *cmd;
2167 int ret;
2168
2169 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2170 if (!skb)
2171 return -ENOMEM;
2172
2173 cmd = (struct wmi_power_mode_cmd *) skb->data;
2174 cmd->pwr_mode = pwr_mode;
2175 wmi->pwr_mode = pwr_mode;
2176
334234b5 2177 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
bdcd8170
KV
2178 NO_SYNC_WMIFLAG);
2179 return ret;
2180}
2181
0ce59445 2182int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
bdcd8170
KV
2183 u16 ps_poll_num, u16 dtim_policy,
2184 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2185 u16 ps_fail_event_policy)
2186{
2187 struct sk_buff *skb;
2188 struct wmi_power_params_cmd *pm;
2189 int ret;
2190
2191 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2192 if (!skb)
2193 return -ENOMEM;
2194
2195 pm = (struct wmi_power_params_cmd *)skb->data;
2196 pm->idle_period = cpu_to_le16(idle_period);
2197 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2198 pm->dtim_policy = cpu_to_le16(dtim_policy);
2199 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2200 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2201 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2202
0ce59445 2203 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
bdcd8170
KV
2204 NO_SYNC_WMIFLAG);
2205 return ret;
2206}
2207
0ce59445 2208int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
bdcd8170
KV
2209{
2210 struct sk_buff *skb;
2211 struct wmi_disc_timeout_cmd *cmd;
2212 int ret;
2213
2214 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2215 if (!skb)
2216 return -ENOMEM;
2217
2218 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2219 cmd->discon_timeout = timeout;
2220
0ce59445 2221 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
bdcd8170 2222 NO_SYNC_WMIFLAG);
334234b5 2223
ff0b0075
JM
2224 if (ret == 0)
2225 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
334234b5 2226
bdcd8170
KV
2227 return ret;
2228}
2229
334234b5 2230int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
bdcd8170
KV
2231 enum crypto_type key_type,
2232 u8 key_usage, u8 key_len,
f4bb9a6f
JM
2233 u8 *key_rsc, unsigned int key_rsc_len,
2234 u8 *key_material,
bdcd8170
KV
2235 u8 key_op_ctrl, u8 *mac_addr,
2236 enum wmi_sync_flag sync_flag)
2237{
2238 struct sk_buff *skb;
2239 struct wmi_add_cipher_key_cmd *cmd;
2240 int ret;
2241
cdeb8602
KV
2242 ath6kl_dbg(ATH6KL_DBG_WMI,
2243 "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
9a5b1318
JM
2244 key_index, key_type, key_usage, key_len, key_op_ctrl);
2245
bdcd8170 2246 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
f4bb9a6f 2247 (key_material == NULL) || key_rsc_len > 8)
bdcd8170
KV
2248 return -EINVAL;
2249
2250 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2251 return -EINVAL;
2252
2253 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2254 if (!skb)
2255 return -ENOMEM;
2256
2257 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2258 cmd->key_index = key_index;
2259 cmd->key_type = key_type;
2260 cmd->key_usage = key_usage;
2261 cmd->key_len = key_len;
2262 memcpy(cmd->key, key_material, key_len);
2263
2264 if (key_rsc != NULL)
f4bb9a6f 2265 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
bdcd8170
KV
2266
2267 cmd->key_op_ctrl = key_op_ctrl;
2268
2269 if (mac_addr)
2270 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2271
334234b5 2272 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
bdcd8170
KV
2273 sync_flag);
2274
2275 return ret;
2276}
2277
240d2799 2278int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
bdcd8170
KV
2279{
2280 struct sk_buff *skb;
2281 struct wmi_add_krk_cmd *cmd;
2282 int ret;
2283
2284 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2285 if (!skb)
2286 return -ENOMEM;
2287
2288 cmd = (struct wmi_add_krk_cmd *) skb->data;
2289 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2290
240d2799 2291 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
334234b5 2292 NO_SYNC_WMIFLAG);
bdcd8170
KV
2293
2294 return ret;
2295}
2296
334234b5 2297int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
bdcd8170
KV
2298{
2299 struct sk_buff *skb;
2300 struct wmi_delete_cipher_key_cmd *cmd;
2301 int ret;
2302
2303 if (key_index > WMI_MAX_KEY_INDEX)
2304 return -EINVAL;
2305
2306 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2307 if (!skb)
2308 return -ENOMEM;
2309
2310 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2311 cmd->key_index = key_index;
2312
334234b5 2313 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
bdcd8170
KV
2314 NO_SYNC_WMIFLAG);
2315
2316 return ret;
2317}
2318
334234b5 2319int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
bdcd8170
KV
2320 const u8 *pmkid, bool set)
2321{
2322 struct sk_buff *skb;
2323 struct wmi_setpmkid_cmd *cmd;
2324 int ret;
2325
2326 if (bssid == NULL)
2327 return -EINVAL;
2328
2329 if (set && pmkid == NULL)
2330 return -EINVAL;
2331
2332 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2333 if (!skb)
2334 return -ENOMEM;
2335
2336 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2337 memcpy(cmd->bssid, bssid, ETH_ALEN);
2338 if (set) {
2339 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2340 cmd->enable = PMKID_ENABLE;
2341 } else {
2342 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2343 cmd->enable = PMKID_DISABLE;
2344 }
2345
334234b5 2346 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
bdcd8170
KV
2347 NO_SYNC_WMIFLAG);
2348
2349 return ret;
2350}
2351
2352static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
6765d0aa 2353 enum htc_endpoint_id ep_id, u8 if_idx)
bdcd8170
KV
2354{
2355 struct wmi_data_hdr *data_hdr;
2356 int ret;
2357
0616dc1f
VT
2358 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) {
2359 dev_kfree_skb(skb);
bdcd8170 2360 return -EINVAL;
0616dc1f 2361 }
bdcd8170
KV
2362
2363 skb_push(skb, sizeof(struct wmi_data_hdr));
2364
2365 data_hdr = (struct wmi_data_hdr *) skb->data;
2366 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
6765d0aa 2367 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
bdcd8170
KV
2368
2369 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2370
2371 return ret;
2372}
2373
240d2799 2374static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
bdcd8170
KV
2375{
2376 struct sk_buff *skb;
2377 struct wmi_sync_cmd *cmd;
2378 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2379 enum htc_endpoint_id ep_id;
2380 u8 index, num_pri_streams = 0;
2381 int ret = 0;
2382
2383 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2384
2385 spin_lock_bh(&wmi->lock);
2386
2387 for (index = 0; index < WMM_NUM_AC; index++) {
2388 if (wmi->fat_pipe_exist & (1 << index)) {
2389 num_pri_streams++;
2390 data_sync_bufs[num_pri_streams - 1].traffic_class =
2391 index;
2392 }
2393 }
2394
2395 spin_unlock_bh(&wmi->lock);
2396
2397 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
0616dc1f
VT
2398 if (!skb)
2399 return -ENOMEM;
bdcd8170
KV
2400
2401 cmd = (struct wmi_sync_cmd *) skb->data;
2402
2403 /*
2404 * In the SYNC cmd sent on the control Ep, send a bitmap
2405 * of the data eps on which the Data Sync will be sent
2406 */
2407 cmd->data_sync_map = wmi->fat_pipe_exist;
2408
2409 for (index = 0; index < num_pri_streams; index++) {
2410 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2411 if (data_sync_bufs[index].skb == NULL) {
2412 ret = -ENOMEM;
2413 break;
2414 }
2415 }
2416
2417 /*
2418 * If buffer allocation for any of the dataSync fails,
2419 * then do not send the Synchronize cmd on the control ep
2420 */
2421 if (ret)
0616dc1f 2422 goto free_cmd_skb;
bdcd8170
KV
2423
2424 /*
2425 * Send sync cmd followed by sync data messages on all
2426 * endpoints being used
2427 */
240d2799 2428 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
bdcd8170
KV
2429 NO_SYNC_WMIFLAG);
2430
2431 if (ret)
0616dc1f 2432 goto free_data_skb;
bdcd8170
KV
2433
2434 for (index = 0; index < num_pri_streams; index++) {
2435
2436 if (WARN_ON(!data_sync_bufs[index].skb))
0616dc1f 2437 goto free_data_skb;
bdcd8170
KV
2438
2439 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2440 data_sync_bufs[index].
2441 traffic_class);
2442 ret =
2443 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
6765d0aa 2444 ep_id, if_idx);
bdcd8170 2445
bdcd8170 2446 data_sync_bufs[index].skb = NULL;
0616dc1f
VT
2447
2448 if (ret)
2449 goto free_data_skb;
bdcd8170
KV
2450 }
2451
0616dc1f
VT
2452 return 0;
2453
2454free_cmd_skb:
bdcd8170
KV
2455 /* free up any resources left over (possibly due to an error) */
2456 if (skb)
2457 dev_kfree_skb(skb);
2458
0616dc1f 2459free_data_skb:
bdcd8170
KV
2460 for (index = 0; index < num_pri_streams; index++) {
2461 if (data_sync_bufs[index].skb != NULL) {
2462 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2463 skb);
2464 }
2465 }
2466
2467 return ret;
2468}
2469
240d2799 2470int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
bdcd8170
KV
2471 struct wmi_create_pstream_cmd *params)
2472{
2473 struct sk_buff *skb;
2474 struct wmi_create_pstream_cmd *cmd;
2475 u8 fatpipe_exist_for_ac = 0;
2476 s32 min_phy = 0;
2477 s32 nominal_phy = 0;
2478 int ret;
2479
2480 if (!((params->user_pri < 8) &&
2481 (params->user_pri <= 0x7) &&
2482 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2483 (params->traffic_direc == UPLINK_TRAFFIC ||
2484 params->traffic_direc == DNLINK_TRAFFIC ||
2485 params->traffic_direc == BIDIR_TRAFFIC) &&
2486 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2487 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2488 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2489 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2490 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2491 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2492 params->tsid <= WMI_MAX_THINSTREAM))) {
2493 return -EINVAL;
2494 }
2495
2496 /*
2497 * Check nominal PHY rate is >= minimalPHY,
2498 * so that DUT can allow TSRS IE
2499 */
2500
2501 /* Get the physical rate (units of bps) */
2502 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2503
2504 /* Check minimal phy < nominal phy rate */
2505 if (params->nominal_phy >= min_phy) {
2506 /* unit of 500 kbps */
2507 nominal_phy = (params->nominal_phy * 1000) / 500;
2508 ath6kl_dbg(ATH6KL_DBG_WMI,
2509 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2510 min_phy, nominal_phy);
2511
2512 params->nominal_phy = nominal_phy;
2513 } else {
2514 params->nominal_phy = 0;
2515 }
2516
2517 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2518 if (!skb)
2519 return -ENOMEM;
2520
2521 ath6kl_dbg(ATH6KL_DBG_WMI,
2522 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2523 params->traffic_class, params->tsid);
2524
2525 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2526 memcpy(cmd, params, sizeof(*cmd));
2527
2528 /* This is an implicitly created Fat pipe */
2529 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2530 spin_lock_bh(&wmi->lock);
2531 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2532 (1 << params->traffic_class));
2533 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2534 spin_unlock_bh(&wmi->lock);
2535 } else {
2536 /* explicitly created thin stream within a fat pipe */
2537 spin_lock_bh(&wmi->lock);
2538 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2539 (1 << params->traffic_class));
2540 wmi->stream_exist_for_ac[params->traffic_class] |=
2541 (1 << params->tsid);
2542 /*
2543 * If a thinstream becomes active, the fat pipe automatically
2544 * becomes active
2545 */
2546 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2547 spin_unlock_bh(&wmi->lock);
2548 }
2549
2550 /*
2551 * Indicate activty change to driver layer only if this is the
2552 * first TSID to get created in this AC explicitly or an implicit
2553 * fat pipe is getting created.
2554 */
2555 if (!fatpipe_exist_for_ac)
2556 ath6kl_indicate_tx_activity(wmi->parent_dev,
2557 params->traffic_class, true);
2558
240d2799 2559 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
bdcd8170
KV
2560 NO_SYNC_WMIFLAG);
2561 return ret;
2562}
2563
240d2799
VT
2564int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2565 u8 tsid)
bdcd8170
KV
2566{
2567 struct sk_buff *skb;
2568 struct wmi_delete_pstream_cmd *cmd;
2569 u16 active_tsids = 0;
2570 int ret;
2571
2572 if (traffic_class > 3) {
2573 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2574 return -EINVAL;
2575 }
2576
2577 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2578 if (!skb)
2579 return -ENOMEM;
2580
2581 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2582 cmd->traffic_class = traffic_class;
2583 cmd->tsid = tsid;
2584
2585 spin_lock_bh(&wmi->lock);
2586 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2587 spin_unlock_bh(&wmi->lock);
2588
2589 if (!(active_tsids & (1 << tsid))) {
2590 dev_kfree_skb(skb);
2591 ath6kl_dbg(ATH6KL_DBG_WMI,
2592 "TSID %d doesn't exist for traffic class: %d\n",
2593 tsid, traffic_class);
2594 return -ENODATA;
2595 }
2596
2597 ath6kl_dbg(ATH6KL_DBG_WMI,
2598 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2599 traffic_class, tsid);
2600
240d2799 2601 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
bdcd8170
KV
2602 SYNC_BEFORE_WMIFLAG);
2603
2604 spin_lock_bh(&wmi->lock);
2605 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2606 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2607 spin_unlock_bh(&wmi->lock);
2608
2609 /*
2610 * Indicate stream inactivity to driver layer only if all tsids
2611 * within this AC are deleted.
2612 */
2613 if (!active_tsids) {
2614 ath6kl_indicate_tx_activity(wmi->parent_dev,
2615 traffic_class, false);
2616 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2617 }
2618
2619 return ret;
2620}
2621
ca1d16a0
RM
2622int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2623 __be32 ips0, __be32 ips1)
bdcd8170
KV
2624{
2625 struct sk_buff *skb;
2626 struct wmi_set_ip_cmd *cmd;
2627 int ret;
2628
2629 /* Multicast address are not valid */
ca1d16a0
RM
2630 if (ipv4_is_multicast(ips0) ||
2631 ipv4_is_multicast(ips1))
bdcd8170
KV
2632 return -EINVAL;
2633
2634 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2635 if (!skb)
2636 return -ENOMEM;
2637
2638 cmd = (struct wmi_set_ip_cmd *) skb->data;
ca1d16a0
RM
2639 cmd->ips[0] = ips0;
2640 cmd->ips[1] = ips1;
bdcd8170 2641
ca1d16a0 2642 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
334234b5 2643 NO_SYNC_WMIFLAG);
bdcd8170
KV
2644 return ret;
2645}
2646
45cf110b
RM
2647static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2648{
2649 u16 active_tsids;
2650 u8 stream_exist;
2651 int i;
2652
2653 /*
2654 * Relinquish credits from all implicitly created pstreams
2655 * since when we go to sleep. If user created explicit
2656 * thinstreams exists with in a fatpipe leave them intact
2657 * for the user to delete.
2658 */
2659 spin_lock_bh(&wmi->lock);
2660 stream_exist = wmi->fat_pipe_exist;
2661 spin_unlock_bh(&wmi->lock);
2662
2663 for (i = 0; i < WMM_NUM_AC; i++) {
2664 if (stream_exist & (1 << i)) {
2665
2666 /*
2667 * FIXME: Is this lock & unlock inside
2668 * for loop correct? may need rework.
2669 */
2670 spin_lock_bh(&wmi->lock);
2671 active_tsids = wmi->stream_exist_for_ac[i];
2672 spin_unlock_bh(&wmi->lock);
2673
2674 /*
2675 * If there are no user created thin streams
2676 * delete the fatpipe
2677 */
2678 if (!active_tsids) {
2679 stream_exist &= ~(1 << i);
2680 /*
2681 * Indicate inactivity to driver layer for
2682 * this fatpipe (pstream)
2683 */
2684 ath6kl_indicate_tx_activity(wmi->parent_dev,
2685 i, false);
2686 }
2687 }
2688 }
2689
2690 /* FIXME: Can we do this assignment without locking ? */
2691 spin_lock_bh(&wmi->lock);
2692 wmi->fat_pipe_exist = stream_exist;
2693 spin_unlock_bh(&wmi->lock);
2694}
2695
06e360ac
BS
2696static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
2697 const struct cfg80211_bitrate_mask *mask)
2698{
2699 struct sk_buff *skb;
2700 int ret, mode, band;
f8c03053 2701 u64 mcsrate, ratemask[ATH6KL_NUM_BANDS];
06e360ac
BS
2702 struct wmi_set_tx_select_rates64_cmd *cmd;
2703
2704 memset(&ratemask, 0, sizeof(ratemask));
f8c03053
KV
2705
2706 /* only check 2.4 and 5 GHz bands, skip the rest */
2707 for (band = 0; band <= IEEE80211_BAND_5GHZ; band++) {
06e360ac
BS
2708 /* copy legacy rate mask */
2709 ratemask[band] = mask->control[band].legacy;
2710 if (band == IEEE80211_BAND_5GHZ)
2711 ratemask[band] =
2712 mask->control[band].legacy << 4;
2713
2714 /* copy mcs rate mask */
2715 mcsrate = mask->control[band].mcs[1];
2716 mcsrate <<= 8;
2717 mcsrate |= mask->control[band].mcs[0];
2718 ratemask[band] |= mcsrate << 12;
2719 ratemask[band] |= mcsrate << 28;
2720 }
2721
2722 ath6kl_dbg(ATH6KL_DBG_WMI,
2723 "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
2724 ratemask[0], ratemask[1]);
2725
2726 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2727 if (!skb)
2728 return -ENOMEM;
2729
2730 cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
2731 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2732 /* A mode operate in 5GHZ band */
2733 if (mode == WMI_RATES_MODE_11A ||
2734 mode == WMI_RATES_MODE_11A_HT20 ||
2735 mode == WMI_RATES_MODE_11A_HT40)
2736 band = IEEE80211_BAND_5GHZ;
2737 else
2738 band = IEEE80211_BAND_2GHZ;
2739 cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
2740 }
2741
2742 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2743 WMI_SET_TX_SELECT_RATES_CMDID,
2744 NO_SYNC_WMIFLAG);
2745 return ret;
2746}
2747
2748static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
2749 const struct cfg80211_bitrate_mask *mask)
2750{
2751 struct sk_buff *skb;
2752 int ret, mode, band;
f8c03053 2753 u32 mcsrate, ratemask[ATH6KL_NUM_BANDS];
06e360ac
BS
2754 struct wmi_set_tx_select_rates32_cmd *cmd;
2755
2756 memset(&ratemask, 0, sizeof(ratemask));
f8c03053
KV
2757
2758 /* only check 2.4 and 5 GHz bands, skip the rest */
2759 for (band = 0; band <= IEEE80211_BAND_5GHZ; band++) {
06e360ac
BS
2760 /* copy legacy rate mask */
2761 ratemask[band] = mask->control[band].legacy;
2762 if (band == IEEE80211_BAND_5GHZ)
2763 ratemask[band] =
2764 mask->control[band].legacy << 4;
2765
2766 /* copy mcs rate mask */
2767 mcsrate = mask->control[band].mcs[0];
2768 ratemask[band] |= mcsrate << 12;
2769 ratemask[band] |= mcsrate << 20;
2770 }
2771
2772 ath6kl_dbg(ATH6KL_DBG_WMI,
2773 "Ratemask 32 bit: 2.4:%x 5:%x\n",
2774 ratemask[0], ratemask[1]);
2775
2776 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2777 if (!skb)
2778 return -ENOMEM;
2779
2780 cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
2781 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2782 /* A mode operate in 5GHZ band */
2783 if (mode == WMI_RATES_MODE_11A ||
2784 mode == WMI_RATES_MODE_11A_HT20 ||
2785 mode == WMI_RATES_MODE_11A_HT40)
2786 band = IEEE80211_BAND_5GHZ;
2787 else
2788 band = IEEE80211_BAND_2GHZ;
2789 cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
2790 }
2791
2792 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2793 WMI_SET_TX_SELECT_RATES_CMDID,
2794 NO_SYNC_WMIFLAG);
2795 return ret;
2796}
2797
2798int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
2799 const struct cfg80211_bitrate_mask *mask)
2800{
2801 struct ath6kl *ar = wmi->parent_dev;
2802
2803 if (ar->hw.flags & ATH6KL_HW_FLAG_64BIT_RATES)
2804 return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
2805 else
2806 return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
2807}
2808
45cf110b
RM
2809int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2810 enum ath6kl_host_mode host_mode)
2811{
2812 struct sk_buff *skb;
2813 struct wmi_set_host_sleep_mode_cmd *cmd;
2814 int ret;
2815
2816 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2817 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2818 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2819 return -EINVAL;
2820 }
2821
2822 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2823 if (!skb)
2824 return -ENOMEM;
2825
2826 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2827
2828 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2829 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2830 cmd->asleep = cpu_to_le32(1);
2831 } else
2832 cmd->awake = cpu_to_le32(1);
2833
2834 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2835 WMI_SET_HOST_SLEEP_MODE_CMDID,
2836 NO_SYNC_WMIFLAG);
2837 return ret;
2838}
2839
081c7a84
RM
2840/* This command has zero length payload */
2841static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2842 struct ath6kl_vif *vif)
2843{
2844 struct ath6kl *ar = wmi->parent_dev;
2845
2846 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2847 wake_up(&ar->event_wq);
2848
2849 return 0;
2850}
2851
45cf110b
RM
2852int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2853 enum ath6kl_wow_mode wow_mode,
2854 u32 filter, u16 host_req_delay)
2855{
2856 struct sk_buff *skb;
2857 struct wmi_set_wow_mode_cmd *cmd;
2858 int ret;
2859
2860 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
96f1fadc 2861 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
45cf110b
RM
2862 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2863 return -EINVAL;
2864 }
2865
2866 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2867 if (!skb)
2868 return -ENOMEM;
2869
2870 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2871 cmd->enable_wow = cpu_to_le32(wow_mode);
2872 cmd->filter = cpu_to_le32(filter);
2873 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2874
2875 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2876 NO_SYNC_WMIFLAG);
2877 return ret;
2878}
2879
5c9b4fa1
RM
2880int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2881 u8 list_id, u8 filter_size,
d91e8eee
RM
2882 u8 filter_offset, const u8 *filter,
2883 const u8 *mask)
5c9b4fa1
RM
2884{
2885 struct sk_buff *skb;
2886 struct wmi_add_wow_pattern_cmd *cmd;
2887 u16 size;
2888 u8 *filter_mask;
2889 int ret;
2890
2891 /*
2892 * Allocate additional memory in the buffer to hold
2893 * filter and mask value, which is twice of filter_size.
2894 */
2895 size = sizeof(*cmd) + (2 * filter_size);
2896
2897 skb = ath6kl_wmi_get_new_buf(size);
2898 if (!skb)
2899 return -ENOMEM;
2900
2901 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2902 cmd->filter_list_id = list_id;
2903 cmd->filter_size = filter_size;
2904 cmd->filter_offset = filter_offset;
2905
2906 memcpy(cmd->filter, filter, filter_size);
2907
2908 filter_mask = (u8 *) (cmd->filter + filter_size);
2909 memcpy(filter_mask, mask, filter_size);
2910
2911 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2912 NO_SYNC_WMIFLAG);
2913
2914 return ret;
2915}
2916
2917int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2918 u16 list_id, u16 filter_id)
2919{
2920 struct sk_buff *skb;
2921 struct wmi_del_wow_pattern_cmd *cmd;
2922 int ret;
2923
2924 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2925 if (!skb)
2926 return -ENOMEM;
2927
2928 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
2929 cmd->filter_list_id = cpu_to_le16(list_id);
2930 cmd->filter_id = cpu_to_le16(filter_id);
2931
2932 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
2933 NO_SYNC_WMIFLAG);
2934 return ret;
2935}
2936
bdcd8170
KV
2937static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2938 enum wmix_command_id cmd_id,
2939 enum wmi_sync_flag sync_flag)
2940{
2941 struct wmix_cmd_hdr *cmd_hdr;
2942 int ret;
2943
2944 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2945
2946 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2947 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2948
334234b5 2949 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
bdcd8170
KV
2950
2951 return ret;
2952}
2953
2954int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2955{
2956 struct sk_buff *skb;
2957 struct wmix_hb_challenge_resp_cmd *cmd;
2958 int ret;
2959
2960 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2961 if (!skb)
2962 return -ENOMEM;
2963
2964 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2965 cmd->cookie = cpu_to_le32(cookie);
2966 cmd->source = cpu_to_le32(source);
2967
2968 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2969 NO_SYNC_WMIFLAG);
2970 return ret;
2971}
2972
939f1cce
KV
2973int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2974{
2975 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2976 struct sk_buff *skb;
2977 int ret;
2978
2979 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2980 if (!skb)
2981 return -ENOMEM;
2982
2983 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2984 cmd->valid = cpu_to_le32(valid);
2985 cmd->config = cpu_to_le32(config);
2986
2987 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2988 NO_SYNC_WMIFLAG);
2989 return ret;
2990}
2991
334234b5 2992int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
bdcd8170 2993{
334234b5 2994 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
bdcd8170
KV
2995}
2996
990bd915 2997int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
bdcd8170
KV
2998{
2999 struct sk_buff *skb;
3000 struct wmi_set_tx_pwr_cmd *cmd;
3001 int ret;
3002
3003 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
3004 if (!skb)
3005 return -ENOMEM;
3006
3007 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
3008 cmd->dbM = dbM;
3009
990bd915 3010 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
bdcd8170
KV
3011 NO_SYNC_WMIFLAG);
3012
3013 return ret;
3014}
3015
990bd915 3016int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
bdcd8170 3017{
990bd915 3018 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
bdcd8170
KV
3019}
3020
4b28a80d
JM
3021int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
3022{
334234b5 3023 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
4b28a80d
JM
3024}
3025
0ce59445
VT
3026int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
3027 u8 preamble_policy)
bdcd8170
KV
3028{
3029 struct sk_buff *skb;
3030 struct wmi_set_lpreamble_cmd *cmd;
3031 int ret;
3032
3033 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
3034 if (!skb)
3035 return -ENOMEM;
3036
3037 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
3038 cmd->status = status;
3039 cmd->preamble_policy = preamble_policy;
3040
0ce59445 3041 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
bdcd8170
KV
3042 NO_SYNC_WMIFLAG);
3043 return ret;
3044}
3045
3046int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
3047{
3048 struct sk_buff *skb;
3049 struct wmi_set_rts_cmd *cmd;
3050 int ret;
3051
3052 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
3053 if (!skb)
3054 return -ENOMEM;
3055
3056 cmd = (struct wmi_set_rts_cmd *) skb->data;
3057 cmd->threshold = cpu_to_le16(threshold);
3058
334234b5
VT
3059 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
3060 NO_SYNC_WMIFLAG);
bdcd8170
KV
3061 return ret;
3062}
3063
0ce59445 3064int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
bdcd8170
KV
3065{
3066 struct sk_buff *skb;
3067 struct wmi_set_wmm_txop_cmd *cmd;
3068 int ret;
3069
3070 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
3071 return -EINVAL;
3072
3073 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
3074 if (!skb)
3075 return -ENOMEM;
3076
3077 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
3078 cmd->txop_enable = cfg;
3079
0ce59445 3080 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
bdcd8170
KV
3081 NO_SYNC_WMIFLAG);
3082 return ret;
3083}
3084
0ce59445
VT
3085int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
3086 u8 keep_alive_intvl)
bdcd8170
KV
3087{
3088 struct sk_buff *skb;
3089 struct wmi_set_keepalive_cmd *cmd;
3090 int ret;
3091
3092 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3093 if (!skb)
3094 return -ENOMEM;
3095
3096 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
3097 cmd->keep_alive_intvl = keep_alive_intvl;
bdcd8170 3098
0ce59445 3099 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
bdcd8170 3100 NO_SYNC_WMIFLAG);
334234b5 3101
ff0b0075
JM
3102 if (ret == 0)
3103 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
334234b5 3104
bdcd8170
KV
3105 return ret;
3106}
3107
df90b369
VT
3108int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
3109 enum ieee80211_band band,
3110 struct ath6kl_htcap *htcap)
3111{
3112 struct sk_buff *skb;
3113 struct wmi_set_htcap_cmd *cmd;
3114
3115 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3116 if (!skb)
3117 return -ENOMEM;
3118
3119 cmd = (struct wmi_set_htcap_cmd *) skb->data;
3120
3121 /*
3122 * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely
3123 * this will be changed in firmware. If at all there is any change in
3124 * band value, the host needs to be fixed.
3125 */
3126 cmd->band = band;
3127 cmd->ht_enable = !!htcap->ht_enable;
3128 cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
3129 cmd->ht40_supported =
3130 !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
3131 cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
3132 cmd->intolerant_40mhz =
3133 !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
3134 cmd->max_ampdu_len_exp = htcap->ampdu_factor;
3135
3136 ath6kl_dbg(ATH6KL_DBG_WMI,
3137 "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
3138 cmd->band, cmd->ht_enable, cmd->ht40_supported,
3139 cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
3140 cmd->max_ampdu_len_exp);
3141 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
3142 NO_SYNC_WMIFLAG);
3143}
3144
003353b0
KV
3145int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
3146{
3147 struct sk_buff *skb;
3148 int ret;
3149
3150 skb = ath6kl_wmi_get_new_buf(len);
3151 if (!skb)
3152 return -ENOMEM;
3153
3154 memcpy(skb->data, buf, len);
3155
334234b5 3156 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
003353b0
KV
3157
3158 return ret;
3159}
3160
3f3c4ee7
VT
3161int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
3162{
3163 struct sk_buff *skb;
3164 struct wmi_mcast_filter_cmd *cmd;
3165 int ret;
3166
3167 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3168 if (!skb)
3169 return -ENOMEM;
3170
3171 cmd = (struct wmi_mcast_filter_cmd *) skb->data;
3172 cmd->mcast_all_enable = mc_all_on;
3173
3174 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
3175 NO_SYNC_WMIFLAG);
3176 return ret;
3177}
003353b0 3178
f914edd3
VT
3179int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
3180 u8 *filter, bool add_filter)
3181{
3182 struct sk_buff *skb;
3183 struct wmi_mcast_filter_add_del_cmd *cmd;
3184 int ret;
3185
3186 if ((filter[0] != 0x33 || filter[1] != 0x33) &&
3187 (filter[0] != 0x01 || filter[1] != 0x00 ||
3188 filter[2] != 0x5e || filter[3] > 0x7f)) {
3189 ath6kl_warn("invalid multicast filter address\n");
3190 return -EINVAL;
3191 }
3192
3193 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3194 if (!skb)
3195 return -ENOMEM;
3196
3197 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
3198 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
3199 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3200 add_filter ? WMI_SET_MCAST_FILTER_CMDID :
3201 WMI_DEL_MCAST_FILTER_CMDID,
3202 NO_SYNC_WMIFLAG);
3203
3204 return ret;
3205}
3206
c422d52d
TP
3207int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
3208{
3209 struct sk_buff *skb;
3210 struct wmi_sta_bmiss_enhance_cmd *cmd;
3211 int ret;
3212
3213 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3214 if (!skb)
3215 return -ENOMEM;
3216
3217 cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
3218 cmd->enable = enhance ? 1 : 0;
3219
3220 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3221 WMI_STA_BMISS_ENHANCE_CMDID,
3222 NO_SYNC_WMIFLAG);
3223 return ret;
3224}
3225
84841ba2
KV
3226int ath6kl_wmi_set_regdomain_cmd(struct wmi *wmi, const char *alpha2)
3227{
3228 struct sk_buff *skb;
3229 struct wmi_set_regdomain_cmd *cmd;
3230
3231 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3232 if (!skb)
3233 return -ENOMEM;
3234
3235 cmd = (struct wmi_set_regdomain_cmd *) skb->data;
3236 memcpy(cmd->iso_name, alpha2, 2);
3237
3238 return ath6kl_wmi_cmd_send(wmi, 0, skb,
3239 WMI_SET_REGDOMAIN_CMDID,
3240 NO_SYNC_WMIFLAG);
3241}
3242
bdcd8170
KV
3243s32 ath6kl_wmi_get_rate(s8 rate_index)
3244{
3245 if (rate_index == RATE_AUTO)
3246 return 0;
3247
3248 return wmi_rate_tbl[(u32) rate_index][0];
3249}
3250
bdcd8170
KV
3251static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
3252 u32 len)
3253{
3254 struct wmi_pmkid_list_reply *reply;
3255 u32 expected_len;
3256
3257 if (len < sizeof(struct wmi_pmkid_list_reply))
3258 return -EINVAL;
3259
3260 reply = (struct wmi_pmkid_list_reply *)datap;
3261 expected_len = sizeof(reply->num_pmkid) +
3262 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
3263
3264 if (len < expected_len)
3265 return -EINVAL;
3266
3267 return 0;
3268}
3269
240d2799
VT
3270static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3271 struct ath6kl_vif *vif)
bdcd8170
KV
3272{
3273 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
3274
240d2799 3275 aggr_recv_addba_req_evt(vif, cmd->tid,
bdcd8170
KV
3276 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
3277
3278 return 0;
3279}
3280
240d2799
VT
3281static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3282 struct ath6kl_vif *vif)
bdcd8170
KV
3283{
3284 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
3285
240d2799 3286 aggr_recv_delba_req_evt(vif, cmd->tid);
bdcd8170
KV
3287
3288 return 0;
3289}
3290
3291/* AP mode functions */
6a7c9bad 3292
334234b5
VT
3293int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
3294 struct wmi_connect_cmd *p)
6a7c9bad
JM
3295{
3296 struct sk_buff *skb;
3297 struct wmi_connect_cmd *cm;
3298 int res;
3299
3300 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3301 if (!skb)
3302 return -ENOMEM;
3303
3304 cm = (struct wmi_connect_cmd *) skb->data;
3305 memcpy(cm, p, sizeof(*cm));
3306
334234b5 3307 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
6a7c9bad 3308 NO_SYNC_WMIFLAG);
cdeb8602
KV
3309 ath6kl_dbg(ATH6KL_DBG_WMI,
3310 "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
6a7c9bad
JM
3311 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
3312 le32_to_cpu(p->ctrl_flags), res);
3313 return res;
3314}
3315
334234b5
VT
3316int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3317 u16 reason)
23875136
JM
3318{
3319 struct sk_buff *skb;
3320 struct wmi_ap_set_mlme_cmd *cm;
3321
3322 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3323 if (!skb)
3324 return -ENOMEM;
3325
3326 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
3327 memcpy(cm->mac, mac, ETH_ALEN);
3328 cm->reason = cpu_to_le16(reason);
3329 cm->cmd = cmd;
3330
7397ddeb
AT
3331 ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
3332 cm->reason);
3333
334234b5 3334 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
23875136
JM
3335 NO_SYNC_WMIFLAG);
3336}
3337
67cd22e4
TP
3338int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
3339{
3340 struct sk_buff *skb;
3341 struct wmi_ap_hidden_ssid_cmd *cmd;
3342
3343 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3344 if (!skb)
3345 return -ENOMEM;
3346
3347 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
3348 cmd->hidden_ssid = enable ? 1 : 0;
3349
3350 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
3351 NO_SYNC_WMIFLAG);
3352}
3353
c1762a3f
TP
3354/* This command will be used to enable/disable AP uAPSD feature */
3355int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3356{
3357 struct wmi_ap_set_apsd_cmd *cmd;
3358 struct sk_buff *skb;
3359
3360 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3361 if (!skb)
3362 return -ENOMEM;
3363
3364 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3365 cmd->enable = enable;
3366
3367 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3368 NO_SYNC_WMIFLAG);
3369}
3370
3371int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3372 u16 aid, u16 bitmap, u32 flags)
3373{
3374 struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3375 struct sk_buff *skb;
3376
3377 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3378 if (!skb)
3379 return -ENOMEM;
3380
3381 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3382 cmd->aid = cpu_to_le16(aid);
3383 cmd->bitmap = cpu_to_le16(bitmap);
3384 cmd->flags = cpu_to_le32(flags);
3385
3386 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3387 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3388 NO_SYNC_WMIFLAG);
3389}
3390
240d2799
VT
3391static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3392 struct ath6kl_vif *vif)
bdcd8170
KV
3393{
3394 struct wmi_pspoll_event *ev;
3395
3396 if (len < sizeof(struct wmi_pspoll_event))
3397 return -EINVAL;
3398
3399 ev = (struct wmi_pspoll_event *) datap;
3400
240d2799 3401 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
bdcd8170
KV
3402
3403 return 0;
3404}
3405
240d2799
VT
3406static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3407 struct ath6kl_vif *vif)
bdcd8170 3408{
240d2799 3409 ath6kl_dtimexpiry_event(vif);
bdcd8170
KV
3410
3411 return 0;
3412}
3413
334234b5
VT
3414int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3415 bool flag)
bdcd8170
KV
3416{
3417 struct sk_buff *skb;
3418 struct wmi_ap_set_pvb_cmd *cmd;
3419 int ret;
3420
3421 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3422 if (!skb)
3423 return -ENOMEM;
3424
3425 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3426 cmd->aid = cpu_to_le16(aid);
d6e51e6a 3427 cmd->rsvd = cpu_to_le16(0);
bdcd8170
KV
3428 cmd->flag = cpu_to_le32(flag);
3429
334234b5 3430 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
bdcd8170
KV
3431 NO_SYNC_WMIFLAG);
3432
3433 return 0;
3434}
3435
0ce59445
VT
3436int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
3437 u8 rx_meta_ver,
bdcd8170
KV
3438 bool rx_dot11_hdr, bool defrag_on_host)
3439{
3440 struct sk_buff *skb;
3441 struct wmi_rx_frame_format_cmd *cmd;
3442 int ret;
3443
3444 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3445 if (!skb)
3446 return -ENOMEM;
3447
3448 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3449 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3450 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3451 cmd->meta_ver = rx_meta_ver;
3452
3453 /* Delete the local aggr state, on host */
0ce59445 3454 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
bdcd8170
KV
3455 NO_SYNC_WMIFLAG);
3456
3457 return ret;
3458}
3459
334234b5
VT
3460int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3461 const u8 *ie, u8 ie_len)
6a7c9bad
JM
3462{
3463 struct sk_buff *skb;
3464 struct wmi_set_appie_cmd *p;
3465
3466 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3467 if (!skb)
3468 return -ENOMEM;
3469
cdeb8602
KV
3470 ath6kl_dbg(ATH6KL_DBG_WMI,
3471 "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
3472 mgmt_frm_type, ie_len);
6a7c9bad
JM
3473 p = (struct wmi_set_appie_cmd *) skb->data;
3474 p->mgmt_frm_type = mgmt_frm_type;
3475 p->ie_len = ie_len;
10509f90
KV
3476
3477 if (ie != NULL && ie_len > 0)
3478 memcpy(p->ie_info, ie, ie_len);
3479
334234b5 3480 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
6a7c9bad
JM
3481 NO_SYNC_WMIFLAG);
3482}
3483
d97c121b
VT
3484int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
3485 const u8 *ie_info, u8 ie_len)
3486{
3487 struct sk_buff *skb;
3488 struct wmi_set_ie_cmd *p;
3489
3490 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3491 if (!skb)
3492 return -ENOMEM;
3493
3494 ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
3495 ie_id, ie_field, ie_len);
3496 p = (struct wmi_set_ie_cmd *) skb->data;
3497 p->ie_id = ie_id;
3498 p->ie_field = ie_field;
3499 p->ie_len = ie_len;
3500 if (ie_info && ie_len > 0)
3501 memcpy(p->ie_info, ie_info, ie_len);
3502
3503 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
3504 NO_SYNC_WMIFLAG);
3505}
3506
6465ddcf
JM
3507int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
3508{
3509 struct sk_buff *skb;
3510 struct wmi_disable_11b_rates_cmd *cmd;
3511
3512 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3513 if (!skb)
3514 return -ENOMEM;
3515
3516 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
3517 disable);
3518 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
3519 cmd->disable = disable ? 1 : 0;
3520
334234b5 3521 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
6465ddcf
JM
3522 NO_SYNC_WMIFLAG);
3523}
3524
334234b5 3525int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
6465ddcf
JM
3526{
3527 struct sk_buff *skb;
3528 struct wmi_remain_on_chnl_cmd *p;
3529
3530 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3531 if (!skb)
3532 return -ENOMEM;
3533
3534 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3535 freq, dur);
3536 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3537 p->freq = cpu_to_le32(freq);
3538 p->duration = cpu_to_le32(dur);
334234b5 3539 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
6465ddcf
JM
3540 NO_SYNC_WMIFLAG);
3541}
3542
3ca9d1fc
AT
3543/* ath6kl_wmi_send_action_cmd is to be deprecated. Use
3544 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
3545 * mgmt operations using station interface.
3546 */
d0ff7383
NG
3547static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3548 u32 freq, u32 wait, const u8 *data,
3549 u16 data_len)
6465ddcf
JM
3550{
3551 struct sk_buff *skb;
3552 struct wmi_send_action_cmd *p;
a0df5db1 3553 u8 *buf;
6465ddcf
JM
3554
3555 if (wait)
3556 return -EINVAL; /* Offload for wait not supported */
3557
a0df5db1
JM
3558 buf = kmalloc(data_len, GFP_KERNEL);
3559 if (!buf)
3560 return -ENOMEM;
3561
6465ddcf 3562 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
a0df5db1
JM
3563 if (!skb) {
3564 kfree(buf);
6465ddcf 3565 return -ENOMEM;
a0df5db1
JM
3566 }
3567
3568 kfree(wmi->last_mgmt_tx_frame);
3101edef 3569 memcpy(buf, data, data_len);
a0df5db1
JM
3570 wmi->last_mgmt_tx_frame = buf;
3571 wmi->last_mgmt_tx_frame_len = data_len;
6465ddcf 3572
cdeb8602
KV
3573 ath6kl_dbg(ATH6KL_DBG_WMI,
3574 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3575 id, freq, wait, data_len);
6465ddcf
JM
3576 p = (struct wmi_send_action_cmd *) skb->data;
3577 p->id = cpu_to_le32(id);
3578 p->freq = cpu_to_le32(freq);
3579 p->wait = cpu_to_le32(wait);
3580 p->len = cpu_to_le16(data_len);
3581 memcpy(p->data, data, data_len);
334234b5 3582 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
6465ddcf
JM
3583 NO_SYNC_WMIFLAG);
3584}
3585
d0ff7383
NG
3586static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3587 u32 freq, u32 wait, const u8 *data,
3588 u16 data_len, u32 no_cck)
3ca9d1fc
AT
3589{
3590 struct sk_buff *skb;
3591 struct wmi_send_mgmt_cmd *p;
3592 u8 *buf;
3593
3594 if (wait)
3595 return -EINVAL; /* Offload for wait not supported */
3596
3597 buf = kmalloc(data_len, GFP_KERNEL);
3598 if (!buf)
3599 return -ENOMEM;
3600
3601 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3602 if (!skb) {
3603 kfree(buf);
3604 return -ENOMEM;
3605 }
3606
3607 kfree(wmi->last_mgmt_tx_frame);
3608 memcpy(buf, data, data_len);
3609 wmi->last_mgmt_tx_frame = buf;
3610 wmi->last_mgmt_tx_frame_len = data_len;
3611
cdeb8602
KV
3612 ath6kl_dbg(ATH6KL_DBG_WMI,
3613 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3614 id, freq, wait, data_len);
3ca9d1fc
AT
3615 p = (struct wmi_send_mgmt_cmd *) skb->data;
3616 p->id = cpu_to_le32(id);
3617 p->freq = cpu_to_le32(freq);
3618 p->wait = cpu_to_le32(wait);
3619 p->no_cck = cpu_to_le32(no_cck);
3620 p->len = cpu_to_le16(data_len);
3621 memcpy(p->data, data, data_len);
3622 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
3623 NO_SYNC_WMIFLAG);
3624}
3625
d0ff7383
NG
3626int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3627 u32 wait, const u8 *data, u16 data_len,
3628 u32 no_cck)
3629{
3630 int status;
3631 struct ath6kl *ar = wmi->parent_dev;
3632
3633 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3634 ar->fw_capabilities)) {
3635 /*
3636 * If capable of doing P2P mgmt operations using
3637 * station interface, send additional information like
3638 * supported rates to advertise and xmit rates for
3639 * probe requests
3640 */
3641 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3642 wait, data, data_len,
3643 no_cck);
3644 } else {
3645 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3646 wait, data, data_len);
3647 }
3648
3649 return status;
3650}
3651
334234b5
VT
3652int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3653 const u8 *dst, const u8 *data,
3654 u16 data_len)
6465ddcf
JM
3655{
3656 struct sk_buff *skb;
3657 struct wmi_p2p_probe_response_cmd *p;
bd24a50f 3658 size_t cmd_len = sizeof(*p) + data_len;
6465ddcf 3659
bd24a50f
AT
3660 if (data_len == 0)
3661 cmd_len++; /* work around target minimum length requirement */
3662
3663 skb = ath6kl_wmi_get_new_buf(cmd_len);
6465ddcf
JM
3664 if (!skb)
3665 return -ENOMEM;
3666
cdeb8602
KV
3667 ath6kl_dbg(ATH6KL_DBG_WMI,
3668 "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
3669 freq, dst, data_len);
6465ddcf
JM
3670 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3671 p->freq = cpu_to_le32(freq);
3672 memcpy(p->destination_addr, dst, ETH_ALEN);
3673 p->len = cpu_to_le16(data_len);
3674 memcpy(p->data, data, data_len);
334234b5
VT
3675 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3676 WMI_SEND_PROBE_RESPONSE_CMDID,
6465ddcf
JM
3677 NO_SYNC_WMIFLAG);
3678}
3679
0ce59445 3680int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
6465ddcf
JM
3681{
3682 struct sk_buff *skb;
3683 struct wmi_probe_req_report_cmd *p;
3684
3685 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3686 if (!skb)
3687 return -ENOMEM;
3688
3689 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3690 enable);
3691 p = (struct wmi_probe_req_report_cmd *) skb->data;
3692 p->enable = enable ? 1 : 0;
0ce59445 3693 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
6465ddcf
JM
3694 NO_SYNC_WMIFLAG);
3695}
3696
0ce59445 3697int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
6465ddcf
JM
3698{
3699 struct sk_buff *skb;
3700 struct wmi_get_p2p_info *p;
3701
3702 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3703 if (!skb)
3704 return -ENOMEM;
3705
3706 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3707 info_req_flags);
3708 p = (struct wmi_get_p2p_info *) skb->data;
3709 p->info_req_flags = cpu_to_le32(info_req_flags);
0ce59445 3710 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
6465ddcf
JM
3711 NO_SYNC_WMIFLAG);
3712}
3713
334234b5 3714int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
6465ddcf
JM
3715{
3716 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
334234b5
VT
3717 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3718 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
6465ddcf
JM
3719}
3720
03bdeb0d
VT
3721int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
3722{
3723 struct sk_buff *skb;
3724 struct wmi_set_inact_period_cmd *cmd;
3725
3726 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3727 if (!skb)
3728 return -ENOMEM;
3729
3730 cmd = (struct wmi_set_inact_period_cmd *) skb->data;
3731 cmd->inact_period = cpu_to_le32(inact_timeout);
3732 cmd->num_null_func = 0;
3733
3734 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
3735 NO_SYNC_WMIFLAG);
3736}
3737
bdcd8170
KV
3738static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3739{
3740 struct wmix_cmd_hdr *cmd;
3741 u32 len;
3742 u16 id;
3743 u8 *datap;
3744 int ret = 0;
3745
3746 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3747 ath6kl_err("bad packet 1\n");
bdcd8170
KV
3748 return -EINVAL;
3749 }
3750
3751 cmd = (struct wmix_cmd_hdr *) skb->data;
3752 id = le32_to_cpu(cmd->cmd_id);
3753
3754 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3755
3756 datap = skb->data;
3757 len = skb->len;
3758
3759 switch (id) {
3760 case WMIX_HB_CHALLENGE_RESP_EVENTID:
b9b6ee60 3761 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
bdcd8170
KV
3762 break;
3763 case WMIX_DBGLOG_EVENTID:
b9b6ee60 3764 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
bdf5396b 3765 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
bdcd8170
KV
3766 break;
3767 default:
b9b6ee60 3768 ath6kl_warn("unknown cmd id 0x%x\n", id);
bdcd8170
KV
3769 ret = -EINVAL;
3770 break;
3771 }
3772
3773 return ret;
3774}
3775
4b28a80d
JM
3776static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3777{
3778 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3779}
3780
5dbc811f
VT
3781/* Process interface specific wmi events, caller would free the datap */
3782static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
3783 u8 *datap, u32 len)
bdcd8170 3784{
240d2799 3785 struct ath6kl_vif *vif;
bdcd8170 3786
5dbc811f
VT
3787 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3788 if (!vif) {
3789 ath6kl_dbg(ATH6KL_DBG_WMI,
3790 "Wmi event for unavailable vif, vif_index:%d\n",
3791 if_idx);
bdcd8170 3792 return -EINVAL;
5dbc811f 3793 }
bdcd8170 3794
5dbc811f
VT
3795 switch (cmd_id) {
3796 case WMI_CONNECT_EVENTID:
3797 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3798 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3799 case WMI_DISCONNECT_EVENTID:
3800 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3801 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3802 case WMI_TKIP_MICERR_EVENTID:
3803 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3804 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3805 case WMI_BSSINFO_EVENTID:
3806 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3807 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3808 case WMI_NEIGHBOR_REPORT_EVENTID:
3809 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3810 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3811 vif);
3812 case WMI_SCAN_COMPLETE_EVENTID:
3813 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3814 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3815 case WMI_REPORT_STATISTICS_EVENTID:
3816 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3817 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3818 case WMI_CAC_EVENTID:
3819 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3820 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3821 case WMI_PSPOLL_EVENTID:
3822 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3823 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3824 case WMI_DTIMEXPIRY_EVENTID:
3825 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3826 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3827 case WMI_ADDBA_REQ_EVENTID:
3828 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3829 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3830 case WMI_DELBA_REQ_EVENTID:
3831 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3832 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3833 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
3834 ath6kl_dbg(ATH6KL_DBG_WMI,
3835 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
3836 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
3837 case WMI_REMAIN_ON_CHNL_EVENTID:
3838 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3839 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3840 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3841 ath6kl_dbg(ATH6KL_DBG_WMI,
3842 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3843 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3844 len, vif);
3845 case WMI_TX_STATUS_EVENTID:
3846 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3847 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3848 case WMI_RX_PROBE_REQ_EVENTID:
3849 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3850 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3851 case WMI_RX_ACTION_EVENTID:
3852 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3853 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
279b2862
TP
3854 case WMI_TXE_NOTIFY_EVENTID:
3855 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
3856 return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
5dbc811f
VT
3857 default:
3858 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
bdcd8170
KV
3859 return -EINVAL;
3860 }
3861
5dbc811f
VT
3862 return 0;
3863}
3864
3865static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
3866{
3867 struct wmi_cmd_hdr *cmd;
3868 int ret = 0;
3869 u32 len;
3870 u16 id;
3871 u8 if_idx;
3872 u8 *datap;
3873
bdcd8170
KV
3874 cmd = (struct wmi_cmd_hdr *) skb->data;
3875 id = le16_to_cpu(cmd->cmd_id);
240d2799 3876 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
bdcd8170
KV
3877
3878 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
bdcd8170
KV
3879 datap = skb->data;
3880 len = skb->len;
3881
b9b6ee60
KV
3882 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3883 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
ef094103 3884 datap, len);
bdcd8170
KV
3885
3886 switch (id) {
3887 case WMI_GET_BITRATE_CMDID:
3888 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3889 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3890 break;
3891 case WMI_GET_CHANNEL_LIST_CMDID:
3892 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3893 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3894 break;
3895 case WMI_GET_TX_PWR_CMDID:
3896 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3897 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3898 break;
3899 case WMI_READY_EVENTID:
3900 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3901 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3902 break;
bdcd8170
KV
3903 case WMI_PEER_NODE_EVENTID:
3904 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3905 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3906 break;
bdcd8170
KV
3907 case WMI_REGDOMAIN_EVENTID:
3908 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
06033760 3909 ath6kl_wmi_regdomain_event(wmi, datap, len);
bdcd8170
KV
3910 break;
3911 case WMI_PSTREAM_TIMEOUT_EVENTID:
3912 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3913 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3914 break;
bdcd8170
KV
3915 case WMI_CMDERROR_EVENTID:
3916 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3917 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3918 break;
bdcd8170
KV
3919 case WMI_RSSI_THRESHOLD_EVENTID:
3920 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3921 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3922 break;
3923 case WMI_ERROR_REPORT_EVENTID:
3924 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3925 break;
3926 case WMI_OPT_RX_FRAME_EVENTID:
3927 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
f195d507 3928 /* this event has been deprecated */
bdcd8170
KV
3929 break;
3930 case WMI_REPORT_ROAM_TBL_EVENTID:
3931 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
4b28a80d 3932 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
bdcd8170
KV
3933 break;
3934 case WMI_EXTENSION_EVENTID:
3935 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3936 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3937 break;
bdcd8170
KV
3938 case WMI_CHANNEL_CHANGE_EVENTID:
3939 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3940 break;
3941 case WMI_REPORT_ROAM_DATA_EVENTID:
3942 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3943 break;
003353b0
KV
3944 case WMI_TEST_EVENTID:
3945 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
4f34dace 3946 ret = ath6kl_wmi_test_rx(wmi, datap, len);
003353b0 3947 break;
bdcd8170
KV
3948 case WMI_GET_FIXRATES_CMDID:
3949 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3950 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3951 break;
3952 case WMI_TX_RETRY_ERR_EVENTID:
3953 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3954 break;
3955 case WMI_SNR_THRESHOLD_EVENTID:
3956 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3957 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3958 break;
3959 case WMI_LQ_THRESHOLD_EVENTID:
3960 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3961 break;
3962 case WMI_APLIST_EVENTID:
3963 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3964 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3965 break;
3966 case WMI_GET_KEEPALIVE_CMDID:
3967 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3968 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3969 break;
3970 case WMI_GET_WOW_LIST_EVENTID:
3971 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
bdcd8170
KV
3972 break;
3973 case WMI_GET_PMKID_LIST_EVENTID:
3974 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3975 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3976 break;
bdcd8170
KV
3977 case WMI_SET_PARAMS_REPLY_EVENTID:
3978 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3979 break;
bdcd8170
KV
3980 case WMI_ADDBA_RESP_EVENTID:
3981 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3982 break;
bdcd8170
KV
3983 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3984 ath6kl_dbg(ATH6KL_DBG_WMI,
3985 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3986 break;
3987 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3988 ath6kl_dbg(ATH6KL_DBG_WMI,
3989 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3990 break;
3991 case WMI_TX_COMPLETE_EVENTID:
3992 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3993 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3994 break;
6465ddcf
JM
3995 case WMI_P2P_CAPABILITIES_EVENTID:
3996 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3997 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3998 break;
6465ddcf
JM
3999 case WMI_P2P_INFO_EVENTID:
4000 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
4001 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
4002 break;
bdcd8170 4003 default:
5dbc811f
VT
4004 /* may be the event is interface specific */
4005 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
bdcd8170
KV
4006 break;
4007 }
4008
4009 dev_kfree_skb(skb);
bdcd8170
KV
4010 return ret;
4011}
4012
5dbc811f
VT
4013/* Control Path */
4014int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
4015{
4016 if (WARN_ON(skb == NULL))
4017 return -EINVAL;
4018
4019 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
4020 ath6kl_err("bad packet 1\n");
4021 dev_kfree_skb(skb);
4022 return -EINVAL;
4023 }
4024
4025 return ath6kl_wmi_proc_events(wmi, skb);
4026}
4027
c89c591d 4028void ath6kl_wmi_reset(struct wmi *wmi)
bdcd8170 4029{
bdcd8170
KV
4030 spin_lock_bh(&wmi->lock);
4031
4032 wmi->fat_pipe_exist = 0;
4033 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
4034
4035 spin_unlock_bh(&wmi->lock);
4036}
4037
2865785e 4038void *ath6kl_wmi_init(struct ath6kl *dev)
bdcd8170
KV
4039{
4040 struct wmi *wmi;
4041
4042 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
4043 if (!wmi)
4044 return NULL;
4045
4046 spin_lock_init(&wmi->lock);
4047
4048 wmi->parent_dev = dev;
4049
bdcd8170 4050 wmi->pwr_mode = REC_POWER;
bdcd8170 4051
c89c591d 4052 ath6kl_wmi_reset(wmi);
bdcd8170
KV
4053
4054 return wmi;
4055}
4056
4057void ath6kl_wmi_shutdown(struct wmi *wmi)
4058{
4059 if (!wmi)
4060 return;
4061
a0df5db1 4062 kfree(wmi->last_mgmt_tx_frame);
bdcd8170
KV
4063 kfree(wmi);
4064}
This page took 0.490364 seconds and 5 git commands to generate.