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