ath6kl: Process regulatory requests from firmware.
[deliverable/linux.git] / drivers / net / wireless / ath / ath6kl / wmi.c
1 /*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <linux/ip.h>
18 #include "core.h"
19 #include "debug.h"
20 #include "testmode.h"
21 #include "../regd.h"
22 #include "../regd_common.h"
23
24 static int ath6kl_wmi_sync_point(struct wmi *wmi);
25
26 static const s32 wmi_rate_tbl[][2] = {
27 /* {W/O SGI, with SGI} */
28 {1000, 1000},
29 {2000, 2000},
30 {5500, 5500},
31 {11000, 11000},
32 {6000, 6000},
33 {9000, 9000},
34 {12000, 12000},
35 {18000, 18000},
36 {24000, 24000},
37 {36000, 36000},
38 {48000, 48000},
39 {54000, 54000},
40 {6500, 7200},
41 {13000, 14400},
42 {19500, 21700},
43 {26000, 28900},
44 {39000, 43300},
45 {52000, 57800},
46 {58500, 65000},
47 {65000, 72200},
48 {13500, 15000},
49 {27000, 30000},
50 {40500, 45000},
51 {54000, 60000},
52 {81000, 90000},
53 {108000, 120000},
54 {121500, 135000},
55 {135000, 150000},
56 {0, 0}
57 };
58
59 /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
60 static const u8 up_to_ac[] = {
61 WMM_AC_BE,
62 WMM_AC_BK,
63 WMM_AC_BK,
64 WMM_AC_BE,
65 WMM_AC_VI,
66 WMM_AC_VI,
67 WMM_AC_VO,
68 WMM_AC_VO,
69 };
70
71 void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
72 {
73 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
74 return;
75
76 wmi->ep_id = ep_id;
77 }
78
79 enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
80 {
81 return wmi->ep_id;
82 }
83
84 /* Performs DIX to 802.3 encapsulation for transmit packets.
85 * Assumes the entire DIX header is contigous and that there is
86 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
87 */
88 int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
89 {
90 struct ath6kl_llc_snap_hdr *llc_hdr;
91 struct ethhdr *eth_hdr;
92 size_t new_len;
93 __be16 type;
94 u8 *datap;
95 u16 size;
96
97 if (WARN_ON(skb == NULL))
98 return -EINVAL;
99
100 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
101 if (skb_headroom(skb) < size)
102 return -ENOMEM;
103
104 eth_hdr = (struct ethhdr *) skb->data;
105 type = eth_hdr->h_proto;
106
107 if (!is_ethertype(be16_to_cpu(type))) {
108 ath6kl_dbg(ATH6KL_DBG_WMI,
109 "%s: pkt is already in 802.3 format\n", __func__);
110 return 0;
111 }
112
113 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
114
115 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
116 datap = skb->data;
117
118 eth_hdr->h_proto = cpu_to_be16(new_len);
119
120 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
121
122 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
123 llc_hdr->dsap = 0xAA;
124 llc_hdr->ssap = 0xAA;
125 llc_hdr->cntl = 0x03;
126 llc_hdr->org_code[0] = 0x0;
127 llc_hdr->org_code[1] = 0x0;
128 llc_hdr->org_code[2] = 0x0;
129 llc_hdr->eth_type = type;
130
131 return 0;
132 }
133
134 static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
135 u8 *version, void *tx_meta_info)
136 {
137 struct wmi_tx_meta_v1 *v1;
138 struct wmi_tx_meta_v2 *v2;
139
140 if (WARN_ON(skb == NULL || version == NULL))
141 return -EINVAL;
142
143 switch (*version) {
144 case WMI_META_VERSION_1:
145 skb_push(skb, WMI_MAX_TX_META_SZ);
146 v1 = (struct wmi_tx_meta_v1 *) skb->data;
147 v1->pkt_id = 0;
148 v1->rate_plcy_id = 0;
149 *version = WMI_META_VERSION_1;
150 break;
151 case WMI_META_VERSION_2:
152 skb_push(skb, WMI_MAX_TX_META_SZ);
153 v2 = (struct wmi_tx_meta_v2 *) skb->data;
154 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
155 sizeof(struct wmi_tx_meta_v2));
156 break;
157 }
158
159 return 0;
160 }
161
162 int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
163 u8 msg_type, bool more_data,
164 enum wmi_data_hdr_data_type data_type,
165 u8 meta_ver, void *tx_meta_info)
166 {
167 struct wmi_data_hdr *data_hdr;
168 int ret;
169
170 if (WARN_ON(skb == NULL))
171 return -EINVAL;
172
173 if (tx_meta_info) {
174 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
175 if (ret)
176 return ret;
177 }
178
179 skb_push(skb, sizeof(struct wmi_data_hdr));
180
181 data_hdr = (struct wmi_data_hdr *)skb->data;
182 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
183
184 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
185 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
186
187 if (more_data)
188 data_hdr->info |=
189 WMI_DATA_HDR_MORE_MASK << WMI_DATA_HDR_MORE_SHIFT;
190
191 data_hdr->info2 = cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
192 data_hdr->info3 = 0;
193
194 return 0;
195 }
196
197 static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
198 {
199 struct iphdr *ip_hdr = (struct iphdr *) pkt;
200 u8 ip_pri;
201
202 /*
203 * Determine IPTOS priority
204 *
205 * IP-TOS - 8bits
206 * : DSCP(6-bits) ECN(2-bits)
207 * : DSCP - P2 P1 P0 X X X
208 * where (P2 P1 P0) form 802.1D
209 */
210 ip_pri = ip_hdr->tos >> 5;
211 ip_pri &= 0x7;
212
213 if ((layer2_pri & 0x7) > ip_pri)
214 return (u8) layer2_pri & 0x7;
215 else
216 return ip_pri;
217 }
218
219 int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
220 u32 layer2_priority, bool wmm_enabled,
221 u8 *ac)
222 {
223 struct wmi_data_hdr *data_hdr;
224 struct ath6kl_llc_snap_hdr *llc_hdr;
225 struct wmi_create_pstream_cmd cmd;
226 u32 meta_size, hdr_size;
227 u16 ip_type = IP_ETHERTYPE;
228 u8 stream_exist, usr_pri;
229 u8 traffic_class = WMM_AC_BE;
230 u8 *datap;
231
232 if (WARN_ON(skb == NULL))
233 return -EINVAL;
234
235 datap = skb->data;
236 data_hdr = (struct wmi_data_hdr *) datap;
237
238 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
239 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
240
241 if (!wmm_enabled) {
242 /* If WMM is disabled all traffic goes as BE traffic */
243 usr_pri = 0;
244 } else {
245 hdr_size = sizeof(struct ethhdr);
246
247 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
248 sizeof(struct
249 wmi_data_hdr) +
250 meta_size + hdr_size);
251
252 if (llc_hdr->eth_type == htons(ip_type)) {
253 /*
254 * Extract the endpoint info from the TOS field
255 * in the IP header.
256 */
257 usr_pri =
258 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
259 sizeof(struct ath6kl_llc_snap_hdr),
260 layer2_priority);
261 } else
262 usr_pri = layer2_priority & 0x7;
263 }
264
265 /* workaround for WMM S5 */
266 if ((wmi->traffic_class == WMM_AC_VI) &&
267 ((usr_pri == 5) || (usr_pri == 4)))
268 usr_pri = 1;
269
270 /* Convert user priority to traffic class */
271 traffic_class = up_to_ac[usr_pri & 0x7];
272
273 wmi_data_hdr_set_up(data_hdr, usr_pri);
274
275 spin_lock_bh(&wmi->lock);
276 stream_exist = wmi->fat_pipe_exist;
277 spin_unlock_bh(&wmi->lock);
278
279 if (!(stream_exist & (1 << traffic_class))) {
280 memset(&cmd, 0, sizeof(cmd));
281 cmd.traffic_class = traffic_class;
282 cmd.user_pri = usr_pri;
283 cmd.inactivity_int =
284 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
285 /* Implicit streams are created with TSID 0xFF */
286 cmd.tsid = WMI_IMPLICIT_PSTREAM;
287 ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
288 }
289
290 *ac = traffic_class;
291
292 return 0;
293 }
294
295 int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
296 {
297 struct ieee80211_hdr_3addr *pwh, wh;
298 struct ath6kl_llc_snap_hdr *llc_hdr;
299 struct ethhdr eth_hdr;
300 u32 hdr_size;
301 u8 *datap;
302 __le16 sub_type;
303
304 if (WARN_ON(skb == NULL))
305 return -EINVAL;
306
307 datap = skb->data;
308 pwh = (struct ieee80211_hdr_3addr *) datap;
309
310 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
311
312 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
313
314 /* Strip off the 802.11 header */
315 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
316 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
317 sizeof(u32));
318 skb_pull(skb, hdr_size);
319 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
320 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
321
322 datap = skb->data;
323 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
324
325 memset(&eth_hdr, 0, sizeof(eth_hdr));
326 eth_hdr.h_proto = llc_hdr->eth_type;
327
328 switch ((le16_to_cpu(wh.frame_control)) &
329 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
330 case 0:
331 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
332 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
333 break;
334 case IEEE80211_FCTL_TODS:
335 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
336 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
337 break;
338 case IEEE80211_FCTL_FROMDS:
339 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
340 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
341 break;
342 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
343 break;
344 }
345
346 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
347 skb_push(skb, sizeof(eth_hdr));
348
349 datap = skb->data;
350
351 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
352
353 return 0;
354 }
355
356 /*
357 * Performs 802.3 to DIX encapsulation for received packets.
358 * Assumes the entire 802.3 header is contigous.
359 */
360 int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
361 {
362 struct ath6kl_llc_snap_hdr *llc_hdr;
363 struct ethhdr eth_hdr;
364 u8 *datap;
365
366 if (WARN_ON(skb == NULL))
367 return -EINVAL;
368
369 datap = skb->data;
370
371 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
372
373 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
374 eth_hdr.h_proto = llc_hdr->eth_type;
375
376 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
377 datap = skb->data;
378
379 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
380
381 return 0;
382 }
383
384 static void ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(struct sk_buff *skb,
385 u8 *datap)
386 {
387 struct wmi_bss_info_hdr2 bih2;
388 struct wmi_bss_info_hdr *bih;
389
390 memcpy(&bih2, datap, sizeof(struct wmi_bss_info_hdr2));
391
392 skb_push(skb, 4);
393 bih = (struct wmi_bss_info_hdr *) skb->data;
394
395 bih->ch = bih2.ch;
396 bih->frame_type = bih2.frame_type;
397 bih->snr = bih2.snr;
398 bih->rssi = a_cpu_to_sle16(bih2.snr - 95);
399 bih->ie_mask = cpu_to_le32(le16_to_cpu(bih2.ie_mask));
400 memcpy(bih->bssid, bih2.bssid, ETH_ALEN);
401 }
402
403 static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
404 {
405 struct tx_complete_msg_v1 *msg_v1;
406 struct wmi_tx_complete_event *evt;
407 int index;
408 u16 size;
409
410 evt = (struct wmi_tx_complete_event *) datap;
411
412 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
413 evt->num_msg, evt->msg_len, evt->msg_type);
414
415 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
416 return 0;
417
418 for (index = 0; index < evt->num_msg; index++) {
419 size = sizeof(struct wmi_tx_complete_event) +
420 (index * sizeof(struct tx_complete_msg_v1));
421 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
422
423 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
424 msg_v1->status, msg_v1->pkt_id,
425 msg_v1->rate_idx, msg_v1->ack_failures);
426 }
427
428 return 0;
429 }
430
431 static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
432 int len)
433 {
434 struct wmi_remain_on_chnl_event *ev;
435 u32 freq;
436 u32 dur;
437 struct ieee80211_channel *chan;
438 struct ath6kl *ar = wmi->parent_dev;
439
440 if (len < sizeof(*ev))
441 return -EINVAL;
442
443 ev = (struct wmi_remain_on_chnl_event *) datap;
444 freq = le32_to_cpu(ev->freq);
445 dur = le32_to_cpu(ev->duration);
446 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
447 freq, dur);
448 chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
449 if (!chan) {
450 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
451 "(freq=%u)\n", freq);
452 return -EINVAL;
453 }
454 cfg80211_ready_on_channel(ar->net_dev, 1, chan, NL80211_CHAN_NO_HT,
455 dur, GFP_ATOMIC);
456
457 return 0;
458 }
459
460 static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
461 u8 *datap, int len)
462 {
463 struct wmi_cancel_remain_on_chnl_event *ev;
464 u32 freq;
465 u32 dur;
466 struct ieee80211_channel *chan;
467 struct ath6kl *ar = wmi->parent_dev;
468
469 if (len < sizeof(*ev))
470 return -EINVAL;
471
472 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
473 freq = le32_to_cpu(ev->freq);
474 dur = le32_to_cpu(ev->duration);
475 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
476 "status=%u\n", freq, dur, ev->status);
477 chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
478 if (!chan) {
479 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
480 "channel (freq=%u)\n", freq);
481 return -EINVAL;
482 }
483 cfg80211_remain_on_channel_expired(ar->net_dev, 1, chan,
484 NL80211_CHAN_NO_HT, GFP_ATOMIC);
485
486 return 0;
487 }
488
489 static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len)
490 {
491 struct wmi_tx_status_event *ev;
492 u32 id;
493 struct ath6kl *ar = wmi->parent_dev;
494
495 if (len < sizeof(*ev))
496 return -EINVAL;
497
498 ev = (struct wmi_tx_status_event *) datap;
499 id = le32_to_cpu(ev->id);
500 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
501 id, ev->ack_status);
502 if (wmi->last_mgmt_tx_frame) {
503 cfg80211_mgmt_tx_status(ar->net_dev, id,
504 wmi->last_mgmt_tx_frame,
505 wmi->last_mgmt_tx_frame_len,
506 !!ev->ack_status, GFP_ATOMIC);
507 kfree(wmi->last_mgmt_tx_frame);
508 wmi->last_mgmt_tx_frame = NULL;
509 wmi->last_mgmt_tx_frame_len = 0;
510 }
511
512 return 0;
513 }
514
515 static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len)
516 {
517 struct wmi_p2p_rx_probe_req_event *ev;
518 u32 freq;
519 u16 dlen;
520 struct ath6kl *ar = wmi->parent_dev;
521
522 if (len < sizeof(*ev))
523 return -EINVAL;
524
525 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
526 freq = le32_to_cpu(ev->freq);
527 dlen = le16_to_cpu(ev->len);
528 if (datap + len < ev->data + dlen) {
529 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
530 "len=%d dlen=%u\n", len, dlen);
531 return -EINVAL;
532 }
533 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
534 "probe_req_report=%d\n",
535 dlen, freq, ar->probe_req_report);
536
537 if (ar->probe_req_report || ar->nw_type == AP_NETWORK)
538 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
539
540 return 0;
541 }
542
543 static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
544 {
545 struct wmi_p2p_capabilities_event *ev;
546 u16 dlen;
547
548 if (len < sizeof(*ev))
549 return -EINVAL;
550
551 ev = (struct wmi_p2p_capabilities_event *) datap;
552 dlen = le16_to_cpu(ev->len);
553 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
554
555 return 0;
556 }
557
558 static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len)
559 {
560 struct wmi_rx_action_event *ev;
561 u32 freq;
562 u16 dlen;
563 struct ath6kl *ar = wmi->parent_dev;
564
565 if (len < sizeof(*ev))
566 return -EINVAL;
567
568 ev = (struct wmi_rx_action_event *) datap;
569 freq = le32_to_cpu(ev->freq);
570 dlen = le16_to_cpu(ev->len);
571 if (datap + len < ev->data + dlen) {
572 ath6kl_err("invalid wmi_rx_action_event: "
573 "len=%d dlen=%u\n", len, dlen);
574 return -EINVAL;
575 }
576 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
577 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
578
579 return 0;
580 }
581
582 static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
583 {
584 struct wmi_p2p_info_event *ev;
585 u32 flags;
586 u16 dlen;
587
588 if (len < sizeof(*ev))
589 return -EINVAL;
590
591 ev = (struct wmi_p2p_info_event *) datap;
592 flags = le32_to_cpu(ev->info_req_flags);
593 dlen = le16_to_cpu(ev->len);
594 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
595
596 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
597 struct wmi_p2p_capabilities *cap;
598 if (dlen < sizeof(*cap))
599 return -EINVAL;
600 cap = (struct wmi_p2p_capabilities *) ev->data;
601 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
602 cap->go_power_save);
603 }
604
605 if (flags & P2P_FLAG_MACADDR_REQ) {
606 struct wmi_p2p_macaddr *mac;
607 if (dlen < sizeof(*mac))
608 return -EINVAL;
609 mac = (struct wmi_p2p_macaddr *) ev->data;
610 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
611 mac->mac_addr);
612 }
613
614 if (flags & P2P_FLAG_HMODEL_REQ) {
615 struct wmi_p2p_hmodel *mod;
616 if (dlen < sizeof(*mod))
617 return -EINVAL;
618 mod = (struct wmi_p2p_hmodel *) ev->data;
619 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
620 mod->p2p_model,
621 mod->p2p_model ? "host" : "firmware");
622 }
623 return 0;
624 }
625
626 static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
627 {
628 struct sk_buff *skb;
629
630 skb = ath6kl_buf_alloc(size);
631 if (!skb)
632 return NULL;
633
634 skb_put(skb, size);
635 if (size)
636 memset(skb->data, 0, size);
637
638 return skb;
639 }
640
641 /* Send a "simple" wmi command -- one with no arguments */
642 static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
643 {
644 struct sk_buff *skb;
645 int ret;
646
647 skb = ath6kl_wmi_get_new_buf(0);
648 if (!skb)
649 return -ENOMEM;
650
651 ret = ath6kl_wmi_cmd_send(wmi, skb, cmd_id, NO_SYNC_WMIFLAG);
652
653 return ret;
654 }
655
656 static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
657 {
658 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
659
660 if (len < sizeof(struct wmi_ready_event_2))
661 return -EINVAL;
662
663 wmi->ready = true;
664 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
665 le32_to_cpu(ev->sw_version),
666 le32_to_cpu(ev->abi_version));
667
668 return 0;
669 }
670
671 /*
672 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
673 * at which the station has to roam can be passed with
674 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
675 * in dBm.
676 */
677 int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
678 {
679 struct sk_buff *skb;
680 struct roam_ctrl_cmd *cmd;
681
682 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
683 if (!skb)
684 return -ENOMEM;
685
686 cmd = (struct roam_ctrl_cmd *) skb->data;
687
688 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
689 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
690 DEF_SCAN_FOR_ROAM_INTVL);
691 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
692 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
693 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
694
695 ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_ROAM_CTRL_CMDID, NO_SYNC_WMIFLAG);
696
697 return 0;
698 }
699
700 static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
701 {
702 struct wmi_connect_event *ev;
703 u8 *pie, *peie;
704 struct ath6kl *ar = wmi->parent_dev;
705
706 if (len < sizeof(struct wmi_connect_event))
707 return -EINVAL;
708
709 ev = (struct wmi_connect_event *) datap;
710
711 if (ar->nw_type == AP_NETWORK) {
712 /* AP mode start/STA connected event */
713 struct net_device *dev = ar->net_dev;
714 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
715 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
716 "(AP started)\n",
717 __func__, le16_to_cpu(ev->u.ap_bss.ch),
718 ev->u.ap_bss.bssid);
719 ath6kl_connect_ap_mode_bss(
720 ar, le16_to_cpu(ev->u.ap_bss.ch));
721 } else {
722 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
723 "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
724 "(STA connected)\n",
725 __func__, ev->u.ap_sta.aid,
726 ev->u.ap_sta.mac_addr,
727 ev->u.ap_sta.auth,
728 ev->u.ap_sta.keymgmt,
729 le16_to_cpu(ev->u.ap_sta.cipher),
730 ev->u.ap_sta.apsd_info);
731 ath6kl_connect_ap_mode_sta(
732 ar, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
733 ev->u.ap_sta.keymgmt,
734 le16_to_cpu(ev->u.ap_sta.cipher),
735 ev->u.ap_sta.auth, ev->assoc_req_len,
736 ev->assoc_info + ev->beacon_ie_len);
737 }
738 return 0;
739 }
740
741 /* STA/IBSS mode connection event */
742
743 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM\n",
744 __func__, le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid);
745
746 /* Start of assoc rsp IEs */
747 pie = ev->assoc_info + ev->beacon_ie_len +
748 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
749
750 /* End of assoc rsp IEs */
751 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
752 ev->assoc_resp_len;
753
754 while (pie < peie) {
755 switch (*pie) {
756 case WLAN_EID_VENDOR_SPECIFIC:
757 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
758 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
759 /* WMM OUT (00:50:F2) */
760 if (pie[1] > 5
761 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
762 wmi->is_wmm_enabled = true;
763 }
764 break;
765 }
766
767 if (wmi->is_wmm_enabled)
768 break;
769
770 pie += pie[1] + 2;
771 }
772
773 ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->u.sta.ch),
774 ev->u.sta.bssid,
775 le16_to_cpu(ev->u.sta.listen_intvl),
776 le16_to_cpu(ev->u.sta.beacon_intvl),
777 le32_to_cpu(ev->u.sta.nw_type),
778 ev->beacon_ie_len, ev->assoc_req_len,
779 ev->assoc_resp_len, ev->assoc_info);
780
781 return 0;
782 }
783
784 static struct country_code_to_enum_rd *
785 ath6kl_regd_find_country(u16 countryCode)
786 {
787 int i;
788
789 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
790 if (allCountries[i].countryCode == countryCode)
791 return &allCountries[i];
792 }
793
794 return NULL;
795 }
796
797 static struct reg_dmn_pair_mapping *
798 ath6kl_get_regpair(u16 regdmn)
799 {
800 int i;
801
802 if (regdmn == NO_ENUMRD)
803 return NULL;
804
805 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
806 if (regDomainPairs[i].regDmnEnum == regdmn)
807 return &regDomainPairs[i];
808 }
809
810 return NULL;
811 }
812
813 static struct country_code_to_enum_rd *
814 ath6kl_regd_find_country_by_rd(u16 regdmn)
815 {
816 int i;
817
818 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
819 if (allCountries[i].regDmnEnum == regdmn)
820 return &allCountries[i];
821 }
822
823 return NULL;
824 }
825
826 static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
827 {
828
829 struct ath6kl_wmi_regdomain *ev;
830 struct country_code_to_enum_rd *country = NULL;
831 struct reg_dmn_pair_mapping *regpair = NULL;
832 char alpha2[2];
833 u32 reg_code;
834
835 ev = (struct ath6kl_wmi_regdomain *) datap;
836 reg_code = le32_to_cpu(ev->reg_code);
837
838 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
839 country = ath6kl_regd_find_country((u16) reg_code);
840 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
841
842 regpair = ath6kl_get_regpair((u16) reg_code);
843 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
844 ath6kl_dbg(ATH6KL_DBG_WMI, "ath6kl: Regpair used: 0x%0x\n",
845 regpair->regDmnEnum);
846 }
847
848 if (country) {
849 alpha2[0] = country->isoName[0];
850 alpha2[1] = country->isoName[1];
851
852 regulatory_hint(wmi->parent_dev->wdev->wiphy, alpha2);
853
854 ath6kl_dbg(ATH6KL_DBG_WMI, "ath6kl: Country alpha2 being used: %c%c\n",
855 alpha2[0], alpha2[1]);
856 }
857 }
858
859 static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
860 {
861 struct wmi_disconnect_event *ev;
862 wmi->traffic_class = 100;
863
864 if (len < sizeof(struct wmi_disconnect_event))
865 return -EINVAL;
866
867 ev = (struct wmi_disconnect_event *) datap;
868
869 wmi->is_wmm_enabled = false;
870 wmi->pair_crypto_type = NONE_CRYPT;
871 wmi->grp_crypto_type = NONE_CRYPT;
872
873 ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
874 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
875 le16_to_cpu(ev->proto_reason_status));
876
877 return 0;
878 }
879
880 static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
881 {
882 struct wmi_peer_node_event *ev;
883
884 if (len < sizeof(struct wmi_peer_node_event))
885 return -EINVAL;
886
887 ev = (struct wmi_peer_node_event *) datap;
888
889 if (ev->event_code == PEER_NODE_JOIN_EVENT)
890 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
891 ev->peer_mac_addr);
892 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
893 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
894 ev->peer_mac_addr);
895
896 return 0;
897 }
898
899 static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
900 {
901 struct wmi_tkip_micerr_event *ev;
902
903 if (len < sizeof(struct wmi_tkip_micerr_event))
904 return -EINVAL;
905
906 ev = (struct wmi_tkip_micerr_event *) datap;
907
908 ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
909
910 return 0;
911 }
912
913 static int ath6kl_wlan_parse_beacon(u8 *buf, int frame_len,
914 struct ath6kl_common_ie *cie)
915 {
916 u8 *frm, *efrm;
917 u8 elemid_ssid = false;
918
919 frm = buf;
920 efrm = (u8 *) (frm + frame_len);
921
922 /*
923 * beacon/probe response frame format
924 * [8] time stamp
925 * [2] beacon interval
926 * [2] capability information
927 * [tlv] ssid
928 * [tlv] supported rates
929 * [tlv] country information
930 * [tlv] parameter set (FH/DS)
931 * [tlv] erp information
932 * [tlv] extended supported rates
933 * [tlv] WMM
934 * [tlv] WPA or RSN
935 * [tlv] Atheros Advanced Capabilities
936 */
937 if ((efrm - frm) < 12)
938 return -EINVAL;
939
940 memset(cie, 0, sizeof(*cie));
941
942 cie->ie_tstamp = frm;
943 frm += 8;
944 cie->ie_beaconInt = *(u16 *) frm;
945 frm += 2;
946 cie->ie_capInfo = *(u16 *) frm;
947 frm += 2;
948 cie->ie_chan = 0;
949
950 while (frm < efrm) {
951 switch (*frm) {
952 case WLAN_EID_SSID:
953 if (!elemid_ssid) {
954 cie->ie_ssid = frm;
955 elemid_ssid = true;
956 }
957 break;
958 case WLAN_EID_SUPP_RATES:
959 cie->ie_rates = frm;
960 break;
961 case WLAN_EID_COUNTRY:
962 cie->ie_country = frm;
963 break;
964 case WLAN_EID_FH_PARAMS:
965 break;
966 case WLAN_EID_DS_PARAMS:
967 cie->ie_chan = frm[2];
968 break;
969 case WLAN_EID_TIM:
970 cie->ie_tim = frm;
971 break;
972 case WLAN_EID_IBSS_PARAMS:
973 break;
974 case WLAN_EID_EXT_SUPP_RATES:
975 cie->ie_xrates = frm;
976 break;
977 case WLAN_EID_ERP_INFO:
978 if (frm[1] != 1)
979 return -EINVAL;
980
981 cie->ie_erp = frm[2];
982 break;
983 case WLAN_EID_RSN:
984 cie->ie_rsn = frm;
985 break;
986 case WLAN_EID_HT_CAPABILITY:
987 cie->ie_htcap = frm;
988 break;
989 case WLAN_EID_HT_INFORMATION:
990 cie->ie_htop = frm;
991 break;
992 case WLAN_EID_VENDOR_SPECIFIC:
993 if (frm[1] > 3 && frm[2] == 0x00 && frm[3] == 0x50 &&
994 frm[4] == 0xf2) {
995 /* OUT Type (00:50:F2) */
996
997 if (frm[5] == WPA_OUI_TYPE) {
998 /* WPA OUT */
999 cie->ie_wpa = frm;
1000 } else if (frm[5] == WMM_OUI_TYPE) {
1001 /* WMM OUT */
1002 cie->ie_wmm = frm;
1003 } else if (frm[5] == WSC_OUT_TYPE) {
1004 /* WSC OUT */
1005 cie->ie_wsc = frm;
1006 }
1007
1008 } else if (frm[1] > 3 && frm[2] == 0x00
1009 && frm[3] == 0x03 && frm[4] == 0x7f
1010 && frm[5] == ATH_OUI_TYPE) {
1011 /* Atheros OUI (00:03:7f) */
1012 cie->ie_ath = frm;
1013 }
1014 break;
1015 default:
1016 break;
1017 }
1018 frm += frm[1] + 2;
1019 }
1020
1021 if ((cie->ie_rates == NULL)
1022 || (cie->ie_rates[1] > ATH6KL_RATE_MAXSIZE))
1023 return -EINVAL;
1024
1025 if ((cie->ie_ssid == NULL)
1026 || (cie->ie_ssid[1] > IEEE80211_MAX_SSID_LEN))
1027 return -EINVAL;
1028
1029 return 0;
1030 }
1031
1032 static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
1033 {
1034 struct bss *bss = NULL;
1035 struct wmi_bss_info_hdr *bih;
1036 u8 cached_ssid_len = 0;
1037 u8 cached_ssid[IEEE80211_MAX_SSID_LEN] = { 0 };
1038 u8 beacon_ssid_len = 0;
1039 u8 *buf, *ie_ssid;
1040 u8 *ni_buf;
1041 int buf_len;
1042
1043 int ret;
1044
1045 if (len <= sizeof(struct wmi_bss_info_hdr))
1046 return -EINVAL;
1047
1048 bih = (struct wmi_bss_info_hdr *) datap;
1049 bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
1050
1051 if (a_sle16_to_cpu(bih->rssi) > 0) {
1052 if (bss == NULL)
1053 return 0;
1054 else
1055 bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
1056 }
1057
1058 buf = datap + sizeof(struct wmi_bss_info_hdr);
1059 len -= sizeof(struct wmi_bss_info_hdr);
1060
1061 ath6kl_dbg(ATH6KL_DBG_WMI,
1062 "bss info evt - ch %u, rssi %02x, bssid \"%pM\"\n",
1063 bih->ch, a_sle16_to_cpu(bih->rssi), bih->bssid);
1064
1065 if (bss != NULL) {
1066 /*
1067 * Free up the node. We are about to allocate a new node.
1068 * In case of hidden AP, beacon will not have ssid,
1069 * but a directed probe response will have it,
1070 * so cache the probe-resp-ssid if already present.
1071 */
1072 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE)) {
1073 ie_ssid = bss->ni_cie.ie_ssid;
1074 if (ie_ssid && (ie_ssid[1] <= IEEE80211_MAX_SSID_LEN) &&
1075 (ie_ssid[2] != 0)) {
1076 cached_ssid_len = ie_ssid[1];
1077 memcpy(cached_ssid, ie_ssid + 2,
1078 cached_ssid_len);
1079 }
1080 }
1081
1082 /*
1083 * Use the current average rssi of associated AP base on
1084 * assumption
1085 * 1. Most os with GUI will update RSSI by
1086 * ath6kl_wmi_get_stats_cmd() periodically.
1087 * 2. ath6kl_wmi_get_stats_cmd(..) will be called when calling
1088 * ath6kl_wmi_startscan_cmd(...)
1089 * The average value of RSSI give end-user better feeling for
1090 * instance value of scan result. It also sync up RSSI info
1091 * in GUI between scan result and RSSI signal icon.
1092 */
1093 if (memcmp(wmi->parent_dev->bssid, bih->bssid, ETH_ALEN) == 0) {
1094 bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
1095 bih->snr = bss->ni_snr;
1096 }
1097
1098 wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
1099 }
1100
1101 /*
1102 * beacon/probe response frame format
1103 * [8] time stamp
1104 * [2] beacon interval
1105 * [2] capability information
1106 * [tlv] ssid
1107 */
1108 beacon_ssid_len = buf[SSID_IE_LEN_INDEX];
1109
1110 /*
1111 * If ssid is cached for this hidden AP, then change
1112 * buffer len accordingly.
1113 */
1114 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
1115 (cached_ssid_len != 0) &&
1116 (beacon_ssid_len == 0 || (cached_ssid_len > beacon_ssid_len &&
1117 buf[SSID_IE_LEN_INDEX + 1] == 0))) {
1118
1119 len += (cached_ssid_len - beacon_ssid_len);
1120 }
1121
1122 bss = wlan_node_alloc(len);
1123 if (!bss)
1124 return -ENOMEM;
1125
1126 bss->ni_snr = bih->snr;
1127 bss->ni_rssi = a_sle16_to_cpu(bih->rssi);
1128
1129 if (WARN_ON(!bss->ni_buf))
1130 return -EINVAL;
1131
1132 /*
1133 * In case of hidden AP, beacon will not have ssid,
1134 * but a directed probe response will have it,
1135 * so place the cached-ssid(probe-resp) in the bss info.
1136 */
1137 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
1138 (cached_ssid_len != 0) &&
1139 (beacon_ssid_len == 0 || (beacon_ssid_len &&
1140 buf[SSID_IE_LEN_INDEX + 1] == 0))) {
1141 ni_buf = bss->ni_buf;
1142 buf_len = len;
1143
1144 /*
1145 * Copy the first 14 bytes:
1146 * time-stamp(8), beacon-interval(2),
1147 * cap-info(2), ssid-id(1), ssid-len(1).
1148 */
1149 memcpy(ni_buf, buf, SSID_IE_LEN_INDEX + 1);
1150
1151 ni_buf[SSID_IE_LEN_INDEX] = cached_ssid_len;
1152 ni_buf += (SSID_IE_LEN_INDEX + 1);
1153
1154 buf += (SSID_IE_LEN_INDEX + 1);
1155 buf_len -= (SSID_IE_LEN_INDEX + 1);
1156
1157 memcpy(ni_buf, cached_ssid, cached_ssid_len);
1158 ni_buf += cached_ssid_len;
1159
1160 buf += beacon_ssid_len;
1161 buf_len -= beacon_ssid_len;
1162
1163 if (cached_ssid_len > beacon_ssid_len)
1164 buf_len -= (cached_ssid_len - beacon_ssid_len);
1165
1166 memcpy(ni_buf, buf, buf_len);
1167 } else
1168 memcpy(bss->ni_buf, buf, len);
1169
1170 bss->ni_framelen = len;
1171
1172 ret = ath6kl_wlan_parse_beacon(bss->ni_buf, len, &bss->ni_cie);
1173 if (ret) {
1174 wlan_node_free(bss);
1175 return -EINVAL;
1176 }
1177
1178 /*
1179 * Update the frequency in ie_chan, overwriting of channel number
1180 * which is done in ath6kl_wlan_parse_beacon
1181 */
1182 bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
1183 wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
1184
1185 return 0;
1186 }
1187
1188 static int ath6kl_wmi_opt_frame_event_rx(struct wmi *wmi, u8 *datap, int len)
1189 {
1190 struct bss *bss;
1191 struct wmi_opt_rx_info_hdr *bih;
1192 u8 *buf;
1193
1194 if (len <= sizeof(struct wmi_opt_rx_info_hdr))
1195 return -EINVAL;
1196
1197 bih = (struct wmi_opt_rx_info_hdr *) datap;
1198 buf = datap + sizeof(struct wmi_opt_rx_info_hdr);
1199 len -= sizeof(struct wmi_opt_rx_info_hdr);
1200
1201 ath6kl_dbg(ATH6KL_DBG_WMI, "opt frame event %2.2x:%2.2x\n",
1202 bih->bssid[4], bih->bssid[5]);
1203
1204 bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
1205 if (bss != NULL) {
1206 /* Free up the node. We are about to allocate a new node. */
1207 wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
1208 }
1209
1210 bss = wlan_node_alloc(len);
1211 if (!bss)
1212 return -ENOMEM;
1213
1214 bss->ni_snr = bih->snr;
1215 bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
1216
1217 if (WARN_ON(!bss->ni_buf))
1218 return -EINVAL;
1219
1220 memcpy(bss->ni_buf, buf, len);
1221 wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
1222
1223 return 0;
1224 }
1225
1226 /* Inactivity timeout of a fatpipe(pstream) at the target */
1227 static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1228 int len)
1229 {
1230 struct wmi_pstream_timeout_event *ev;
1231
1232 if (len < sizeof(struct wmi_pstream_timeout_event))
1233 return -EINVAL;
1234
1235 ev = (struct wmi_pstream_timeout_event *) datap;
1236
1237 /*
1238 * When the pstream (fat pipe == AC) timesout, it means there were
1239 * no thinStreams within this pstream & it got implicitly created
1240 * due to data flow on this AC. We start the inactivity timer only
1241 * for implicitly created pstream. Just reset the host state.
1242 */
1243 spin_lock_bh(&wmi->lock);
1244 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1245 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1246 spin_unlock_bh(&wmi->lock);
1247
1248 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1249 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1250
1251 return 0;
1252 }
1253
1254 static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1255 {
1256 struct wmi_bit_rate_reply *reply;
1257 s32 rate;
1258 u32 sgi, index;
1259
1260 if (len < sizeof(struct wmi_bit_rate_reply))
1261 return -EINVAL;
1262
1263 reply = (struct wmi_bit_rate_reply *) datap;
1264
1265 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1266
1267 if (reply->rate_index == (s8) RATE_AUTO) {
1268 rate = RATE_AUTO;
1269 } else {
1270 index = reply->rate_index & 0x7f;
1271 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1272 rate = wmi_rate_tbl[index][sgi];
1273 }
1274
1275 ath6kl_wakeup_event(wmi->parent_dev);
1276
1277 return 0;
1278 }
1279
1280 static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
1281 {
1282 ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
1283
1284 return 0;
1285 }
1286
1287 static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1288 {
1289 if (len < sizeof(struct wmi_fix_rates_reply))
1290 return -EINVAL;
1291
1292 ath6kl_wakeup_event(wmi->parent_dev);
1293
1294 return 0;
1295 }
1296
1297 static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1298 {
1299 if (len < sizeof(struct wmi_channel_list_reply))
1300 return -EINVAL;
1301
1302 ath6kl_wakeup_event(wmi->parent_dev);
1303
1304 return 0;
1305 }
1306
1307 static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1308 {
1309 struct wmi_tx_pwr_reply *reply;
1310
1311 if (len < sizeof(struct wmi_tx_pwr_reply))
1312 return -EINVAL;
1313
1314 reply = (struct wmi_tx_pwr_reply *) datap;
1315 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1316
1317 return 0;
1318 }
1319
1320 static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1321 {
1322 if (len < sizeof(struct wmi_get_keepalive_cmd))
1323 return -EINVAL;
1324
1325 ath6kl_wakeup_event(wmi->parent_dev);
1326
1327 return 0;
1328 }
1329
1330 static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
1331 {
1332 struct wmi_scan_complete_event *ev;
1333
1334 ev = (struct wmi_scan_complete_event *) datap;
1335
1336 if (a_sle32_to_cpu(ev->status) == 0)
1337 wlan_refresh_inactive_nodes(wmi->parent_dev);
1338
1339 ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
1340 wmi->is_probe_ssid = false;
1341
1342 return 0;
1343 }
1344
1345 /*
1346 * Target is reporting a programming error. This is for
1347 * developer aid only. Target only checks a few common violations
1348 * and it is responsibility of host to do all error checking.
1349 * Behavior of target after wmi error event is undefined.
1350 * A reset is recommended.
1351 */
1352 static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1353 {
1354 const char *type = "unknown error";
1355 struct wmi_cmd_error_event *ev;
1356 ev = (struct wmi_cmd_error_event *) datap;
1357
1358 switch (ev->err_code) {
1359 case INVALID_PARAM:
1360 type = "invalid parameter";
1361 break;
1362 case ILLEGAL_STATE:
1363 type = "invalid state";
1364 break;
1365 case INTERNAL_ERROR:
1366 type = "internal error";
1367 break;
1368 }
1369
1370 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1371 ev->cmd_id, type);
1372
1373 return 0;
1374 }
1375
1376 static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
1377 {
1378 ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
1379
1380 return 0;
1381 }
1382
1383 static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1384 struct sq_threshold_params *sq_thresh,
1385 u32 size)
1386 {
1387 u32 index;
1388 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1389
1390 /* The list is already in sorted order. Get the next lower value */
1391 for (index = 0; index < size; index++) {
1392 if (rssi < sq_thresh->upper_threshold[index]) {
1393 threshold = (u8) sq_thresh->upper_threshold[index];
1394 break;
1395 }
1396 }
1397
1398 return threshold;
1399 }
1400
1401 static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1402 struct sq_threshold_params *sq_thresh,
1403 u32 size)
1404 {
1405 u32 index;
1406 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1407
1408 /* The list is already in sorted order. Get the next lower value */
1409 for (index = 0; index < size; index++) {
1410 if (rssi > sq_thresh->lower_threshold[index]) {
1411 threshold = (u8) sq_thresh->lower_threshold[index];
1412 break;
1413 }
1414 }
1415
1416 return threshold;
1417 }
1418
1419 static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1420 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1421 {
1422 struct sk_buff *skb;
1423 struct wmi_rssi_threshold_params_cmd *cmd;
1424
1425 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1426 if (!skb)
1427 return -ENOMEM;
1428
1429 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1430 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1431
1432 return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1433 NO_SYNC_WMIFLAG);
1434 }
1435
1436 static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1437 int len)
1438 {
1439 struct wmi_rssi_threshold_event *reply;
1440 struct wmi_rssi_threshold_params_cmd cmd;
1441 struct sq_threshold_params *sq_thresh;
1442 enum wmi_rssi_threshold_val new_threshold;
1443 u8 upper_rssi_threshold, lower_rssi_threshold;
1444 s16 rssi;
1445 int ret;
1446
1447 if (len < sizeof(struct wmi_rssi_threshold_event))
1448 return -EINVAL;
1449
1450 reply = (struct wmi_rssi_threshold_event *) datap;
1451 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1452 rssi = a_sle16_to_cpu(reply->rssi);
1453
1454 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1455
1456 /*
1457 * Identify the threshold breached and communicate that to the app.
1458 * After that install a new set of thresholds based on the signal
1459 * quality reported by the target
1460 */
1461 if (new_threshold) {
1462 /* Upper threshold breached */
1463 if (rssi < sq_thresh->upper_threshold[0]) {
1464 ath6kl_dbg(ATH6KL_DBG_WMI,
1465 "spurious upper rssi threshold event: %d\n",
1466 rssi);
1467 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1468 (rssi >= sq_thresh->upper_threshold[0])) {
1469 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1470 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1471 (rssi >= sq_thresh->upper_threshold[1])) {
1472 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1473 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1474 (rssi >= sq_thresh->upper_threshold[2])) {
1475 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1476 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1477 (rssi >= sq_thresh->upper_threshold[3])) {
1478 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1479 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1480 (rssi >= sq_thresh->upper_threshold[4])) {
1481 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1482 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1483 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1484 }
1485 } else {
1486 /* Lower threshold breached */
1487 if (rssi > sq_thresh->lower_threshold[0]) {
1488 ath6kl_dbg(ATH6KL_DBG_WMI,
1489 "spurious lower rssi threshold event: %d %d\n",
1490 rssi, sq_thresh->lower_threshold[0]);
1491 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1492 (rssi <= sq_thresh->lower_threshold[0])) {
1493 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1494 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1495 (rssi <= sq_thresh->lower_threshold[1])) {
1496 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1497 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1498 (rssi <= sq_thresh->lower_threshold[2])) {
1499 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1500 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1501 (rssi <= sq_thresh->lower_threshold[3])) {
1502 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1503 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1504 (rssi <= sq_thresh->lower_threshold[4])) {
1505 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1506 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1507 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1508 }
1509 }
1510
1511 /* Calculate and install the next set of thresholds */
1512 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1513 sq_thresh->lower_threshold_valid_count);
1514 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1515 sq_thresh->upper_threshold_valid_count);
1516
1517 /* Issue a wmi command to install the thresholds */
1518 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1519 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1520 cmd.weight = sq_thresh->weight;
1521 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1522
1523 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1524 if (ret) {
1525 ath6kl_err("unable to configure rssi thresholds\n");
1526 return -EIO;
1527 }
1528
1529 return 0;
1530 }
1531
1532 static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
1533 {
1534 struct wmi_cac_event *reply;
1535 struct ieee80211_tspec_ie *ts;
1536 u16 active_tsids, tsinfo;
1537 u8 tsid, index;
1538 u8 ts_id;
1539
1540 if (len < sizeof(struct wmi_cac_event))
1541 return -EINVAL;
1542
1543 reply = (struct wmi_cac_event *) datap;
1544
1545 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1546 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1547
1548 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1549 tsinfo = le16_to_cpu(ts->tsinfo);
1550 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1551 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1552
1553 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
1554 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1555 /*
1556 * Following assumes that there is only one outstanding
1557 * ADDTS request when this event is received
1558 */
1559 spin_lock_bh(&wmi->lock);
1560 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1561 spin_unlock_bh(&wmi->lock);
1562
1563 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1564 if ((active_tsids >> index) & 1)
1565 break;
1566 }
1567 if (index < (sizeof(active_tsids) * 8))
1568 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
1569 }
1570
1571 /*
1572 * Clear active tsids and Add missing handling
1573 * for delete qos stream from AP
1574 */
1575 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1576
1577 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1578 tsinfo = le16_to_cpu(ts->tsinfo);
1579 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1580 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1581
1582 spin_lock_bh(&wmi->lock);
1583 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1584 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1585 spin_unlock_bh(&wmi->lock);
1586
1587 /* Indicate stream inactivity to driver layer only if all tsids
1588 * within this AC are deleted.
1589 */
1590 if (!active_tsids) {
1591 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1592 false);
1593 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1594 }
1595 }
1596
1597 return 0;
1598 }
1599
1600 static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1601 struct wmi_snr_threshold_params_cmd *snr_cmd)
1602 {
1603 struct sk_buff *skb;
1604 struct wmi_snr_threshold_params_cmd *cmd;
1605
1606 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1607 if (!skb)
1608 return -ENOMEM;
1609
1610 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1611 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1612
1613 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1614 NO_SYNC_WMIFLAG);
1615 }
1616
1617 static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1618 int len)
1619 {
1620 struct wmi_snr_threshold_event *reply;
1621 struct sq_threshold_params *sq_thresh;
1622 struct wmi_snr_threshold_params_cmd cmd;
1623 enum wmi_snr_threshold_val new_threshold;
1624 u8 upper_snr_threshold, lower_snr_threshold;
1625 s16 snr;
1626 int ret;
1627
1628 if (len < sizeof(struct wmi_snr_threshold_event))
1629 return -EINVAL;
1630
1631 reply = (struct wmi_snr_threshold_event *) datap;
1632
1633 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1634 snr = reply->snr;
1635
1636 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1637
1638 /*
1639 * Identify the threshold breached and communicate that to the app.
1640 * After that install a new set of thresholds based on the signal
1641 * quality reported by the target.
1642 */
1643 if (new_threshold) {
1644 /* Upper threshold breached */
1645 if (snr < sq_thresh->upper_threshold[0]) {
1646 ath6kl_dbg(ATH6KL_DBG_WMI,
1647 "spurious upper snr threshold event: %d\n",
1648 snr);
1649 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1650 (snr >= sq_thresh->upper_threshold[0])) {
1651 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1652 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1653 (snr >= sq_thresh->upper_threshold[1])) {
1654 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1655 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1656 (snr >= sq_thresh->upper_threshold[2])) {
1657 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1658 } else if (snr >= sq_thresh->upper_threshold[3]) {
1659 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1660 }
1661 } else {
1662 /* Lower threshold breached */
1663 if (snr > sq_thresh->lower_threshold[0]) {
1664 ath6kl_dbg(ATH6KL_DBG_WMI,
1665 "spurious lower snr threshold event: %d\n",
1666 sq_thresh->lower_threshold[0]);
1667 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1668 (snr <= sq_thresh->lower_threshold[0])) {
1669 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1670 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1671 (snr <= sq_thresh->lower_threshold[1])) {
1672 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1673 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1674 (snr <= sq_thresh->lower_threshold[2])) {
1675 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1676 } else if (snr <= sq_thresh->lower_threshold[3]) {
1677 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1678 }
1679 }
1680
1681 /* Calculate and install the next set of thresholds */
1682 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1683 sq_thresh->lower_threshold_valid_count);
1684 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1685 sq_thresh->upper_threshold_valid_count);
1686
1687 /* Issue a wmi command to install the thresholds */
1688 cmd.thresh_above1_val = upper_snr_threshold;
1689 cmd.thresh_below1_val = lower_snr_threshold;
1690 cmd.weight = sq_thresh->weight;
1691 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1692
1693 ath6kl_dbg(ATH6KL_DBG_WMI,
1694 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1695 snr, new_threshold,
1696 lower_snr_threshold, upper_snr_threshold);
1697
1698 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1699 if (ret) {
1700 ath6kl_err("unable to configure snr threshold\n");
1701 return -EIO;
1702 }
1703
1704 return 0;
1705 }
1706
1707 static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1708 {
1709 u16 ap_info_entry_size;
1710 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1711 struct wmi_ap_info_v1 *ap_info_v1;
1712 u8 index;
1713
1714 if (len < sizeof(struct wmi_aplist_event) ||
1715 ev->ap_list_ver != APLIST_VER1)
1716 return -EINVAL;
1717
1718 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1719 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1720
1721 ath6kl_dbg(ATH6KL_DBG_WMI,
1722 "number of APs in aplist event: %d\n", ev->num_ap);
1723
1724 if (len < (int) (sizeof(struct wmi_aplist_event) +
1725 (ev->num_ap - 1) * ap_info_entry_size))
1726 return -EINVAL;
1727
1728 /* AP list version 1 contents */
1729 for (index = 0; index < ev->num_ap; index++) {
1730 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1731 index, ap_info_v1->bssid, ap_info_v1->channel);
1732 ap_info_v1++;
1733 }
1734
1735 return 0;
1736 }
1737
1738 int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
1739 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1740 {
1741 struct wmi_cmd_hdr *cmd_hdr;
1742 enum htc_endpoint_id ep_id = wmi->ep_id;
1743 int ret;
1744
1745 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: cmd_id=%d\n", __func__, cmd_id);
1746
1747 if (WARN_ON(skb == NULL))
1748 return -EINVAL;
1749
1750 if (sync_flag >= END_WMIFLAG) {
1751 dev_kfree_skb(skb);
1752 return -EINVAL;
1753 }
1754
1755 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1756 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1757 /*
1758 * Make sure all data currently queued is transmitted before
1759 * the cmd execution. Establish a new sync point.
1760 */
1761 ath6kl_wmi_sync_point(wmi);
1762 }
1763
1764 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1765
1766 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1767 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1768 cmd_hdr->info1 = 0; /* added for virtual interface */
1769
1770 /* Only for OPT_TX_CMD, use BE endpoint. */
1771 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1772 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1773 false, false, 0, NULL);
1774 if (ret) {
1775 dev_kfree_skb(skb);
1776 return ret;
1777 }
1778 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1779 }
1780
1781 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1782
1783 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1784 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1785 /*
1786 * Make sure all new data queued waits for the command to
1787 * execute. Establish a new sync point.
1788 */
1789 ath6kl_wmi_sync_point(wmi);
1790 }
1791
1792 return 0;
1793 }
1794
1795 int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
1796 enum dot11_auth_mode dot11_auth_mode,
1797 enum auth_mode auth_mode,
1798 enum crypto_type pairwise_crypto,
1799 u8 pairwise_crypto_len,
1800 enum crypto_type group_crypto,
1801 u8 group_crypto_len, int ssid_len, u8 *ssid,
1802 u8 *bssid, u16 channel, u32 ctrl_flags)
1803 {
1804 struct sk_buff *skb;
1805 struct wmi_connect_cmd *cc;
1806 int ret;
1807
1808 wmi->traffic_class = 100;
1809
1810 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1811 return -EINVAL;
1812
1813 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1814 return -EINVAL;
1815
1816 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1817 if (!skb)
1818 return -ENOMEM;
1819
1820 cc = (struct wmi_connect_cmd *) skb->data;
1821
1822 if (ssid_len)
1823 memcpy(cc->ssid, ssid, ssid_len);
1824
1825 cc->ssid_len = ssid_len;
1826 cc->nw_type = nw_type;
1827 cc->dot11_auth_mode = dot11_auth_mode;
1828 cc->auth_mode = auth_mode;
1829 cc->prwise_crypto_type = pairwise_crypto;
1830 cc->prwise_crypto_len = pairwise_crypto_len;
1831 cc->grp_crypto_type = group_crypto;
1832 cc->grp_crypto_len = group_crypto_len;
1833 cc->ch = cpu_to_le16(channel);
1834 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1835
1836 if (bssid != NULL)
1837 memcpy(cc->bssid, bssid, ETH_ALEN);
1838
1839 wmi->pair_crypto_type = pairwise_crypto;
1840 wmi->grp_crypto_type = group_crypto;
1841
1842 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
1843
1844 return ret;
1845 }
1846
1847 int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
1848 {
1849 struct sk_buff *skb;
1850 struct wmi_reconnect_cmd *cc;
1851 int ret;
1852
1853 wmi->traffic_class = 100;
1854
1855 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1856 if (!skb)
1857 return -ENOMEM;
1858
1859 cc = (struct wmi_reconnect_cmd *) skb->data;
1860 cc->channel = cpu_to_le16(channel);
1861
1862 if (bssid != NULL)
1863 memcpy(cc->bssid, bssid, ETH_ALEN);
1864
1865 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
1866 NO_SYNC_WMIFLAG);
1867
1868 return ret;
1869 }
1870
1871 int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
1872 {
1873 int ret;
1874
1875 wmi->traffic_class = 100;
1876
1877 /* Disconnect command does not need to do a SYNC before. */
1878 ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
1879
1880 return ret;
1881 }
1882
1883 int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
1884 u32 force_fgscan, u32 is_legacy,
1885 u32 home_dwell_time, u32 force_scan_interval,
1886 s8 num_chan, u16 *ch_list)
1887 {
1888 struct sk_buff *skb;
1889 struct wmi_start_scan_cmd *sc;
1890 s8 size;
1891 int i, ret;
1892
1893 size = sizeof(struct wmi_start_scan_cmd);
1894
1895 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1896 return -EINVAL;
1897
1898 if (num_chan > WMI_MAX_CHANNELS)
1899 return -EINVAL;
1900
1901 if (num_chan)
1902 size += sizeof(u16) * (num_chan - 1);
1903
1904 skb = ath6kl_wmi_get_new_buf(size);
1905 if (!skb)
1906 return -ENOMEM;
1907
1908 sc = (struct wmi_start_scan_cmd *) skb->data;
1909 sc->scan_type = scan_type;
1910 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1911 sc->is_legacy = cpu_to_le32(is_legacy);
1912 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1913 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1914 sc->num_ch = num_chan;
1915
1916 for (i = 0; i < num_chan; i++)
1917 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1918
1919 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
1920 NO_SYNC_WMIFLAG);
1921
1922 return ret;
1923 }
1924
1925 int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
1926 u16 fg_end_sec, u16 bg_sec,
1927 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1928 u16 pas_chdw_msec, u8 short_scan_ratio,
1929 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1930 u16 maxact_scan_per_ssid)
1931 {
1932 struct sk_buff *skb;
1933 struct wmi_scan_params_cmd *sc;
1934 int ret;
1935
1936 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1937 if (!skb)
1938 return -ENOMEM;
1939
1940 sc = (struct wmi_scan_params_cmd *) skb->data;
1941 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1942 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1943 sc->bg_period = cpu_to_le16(bg_sec);
1944 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1945 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1946 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1947 sc->short_scan_ratio = short_scan_ratio;
1948 sc->scan_ctrl_flags = scan_ctrl_flag;
1949 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1950 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1951
1952 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
1953 NO_SYNC_WMIFLAG);
1954 return ret;
1955 }
1956
1957 int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
1958 {
1959 struct sk_buff *skb;
1960 struct wmi_bss_filter_cmd *cmd;
1961 int ret;
1962
1963 if (filter >= LAST_BSS_FILTER)
1964 return -EINVAL;
1965
1966 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1967 if (!skb)
1968 return -ENOMEM;
1969
1970 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1971 cmd->bss_filter = filter;
1972 cmd->ie_mask = cpu_to_le32(ie_mask);
1973
1974 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
1975 NO_SYNC_WMIFLAG);
1976 return ret;
1977 }
1978
1979 int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
1980 u8 ssid_len, u8 *ssid)
1981 {
1982 struct sk_buff *skb;
1983 struct wmi_probed_ssid_cmd *cmd;
1984 int ret;
1985
1986 if (index > MAX_PROBED_SSID_INDEX)
1987 return -EINVAL;
1988
1989 if (ssid_len > sizeof(cmd->ssid))
1990 return -EINVAL;
1991
1992 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1993 return -EINVAL;
1994
1995 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1996 return -EINVAL;
1997
1998 if (flag & SPECIFIC_SSID_FLAG)
1999 wmi->is_probe_ssid = true;
2000
2001 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2002 if (!skb)
2003 return -ENOMEM;
2004
2005 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2006 cmd->entry_index = index;
2007 cmd->flag = flag;
2008 cmd->ssid_len = ssid_len;
2009 memcpy(cmd->ssid, ssid, ssid_len);
2010
2011 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
2012 NO_SYNC_WMIFLAG);
2013 return ret;
2014 }
2015
2016 int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
2017 u16 listen_beacons)
2018 {
2019 struct sk_buff *skb;
2020 struct wmi_listen_int_cmd *cmd;
2021 int ret;
2022
2023 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2024 if (!skb)
2025 return -ENOMEM;
2026
2027 cmd = (struct wmi_listen_int_cmd *) skb->data;
2028 cmd->listen_intvl = cpu_to_le16(listen_interval);
2029 cmd->num_beacons = cpu_to_le16(listen_beacons);
2030
2031 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
2032 NO_SYNC_WMIFLAG);
2033 return ret;
2034 }
2035
2036 int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
2037 {
2038 struct sk_buff *skb;
2039 struct wmi_power_mode_cmd *cmd;
2040 int ret;
2041
2042 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2043 if (!skb)
2044 return -ENOMEM;
2045
2046 cmd = (struct wmi_power_mode_cmd *) skb->data;
2047 cmd->pwr_mode = pwr_mode;
2048 wmi->pwr_mode = pwr_mode;
2049
2050 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
2051 NO_SYNC_WMIFLAG);
2052 return ret;
2053 }
2054
2055 int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
2056 u16 ps_poll_num, u16 dtim_policy,
2057 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2058 u16 ps_fail_event_policy)
2059 {
2060 struct sk_buff *skb;
2061 struct wmi_power_params_cmd *pm;
2062 int ret;
2063
2064 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2065 if (!skb)
2066 return -ENOMEM;
2067
2068 pm = (struct wmi_power_params_cmd *)skb->data;
2069 pm->idle_period = cpu_to_le16(idle_period);
2070 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2071 pm->dtim_policy = cpu_to_le16(dtim_policy);
2072 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2073 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2074 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2075
2076 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
2077 NO_SYNC_WMIFLAG);
2078 return ret;
2079 }
2080
2081 int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
2082 {
2083 struct sk_buff *skb;
2084 struct wmi_disc_timeout_cmd *cmd;
2085 int ret;
2086
2087 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2088 if (!skb)
2089 return -ENOMEM;
2090
2091 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2092 cmd->discon_timeout = timeout;
2093
2094 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
2095 NO_SYNC_WMIFLAG);
2096 return ret;
2097 }
2098
2099 int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
2100 enum crypto_type key_type,
2101 u8 key_usage, u8 key_len,
2102 u8 *key_rsc, u8 *key_material,
2103 u8 key_op_ctrl, u8 *mac_addr,
2104 enum wmi_sync_flag sync_flag)
2105 {
2106 struct sk_buff *skb;
2107 struct wmi_add_cipher_key_cmd *cmd;
2108 int ret;
2109
2110 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
2111 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
2112 key_index, key_type, key_usage, key_len, key_op_ctrl);
2113
2114 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
2115 (key_material == NULL))
2116 return -EINVAL;
2117
2118 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2119 return -EINVAL;
2120
2121 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2122 if (!skb)
2123 return -ENOMEM;
2124
2125 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2126 cmd->key_index = key_index;
2127 cmd->key_type = key_type;
2128 cmd->key_usage = key_usage;
2129 cmd->key_len = key_len;
2130 memcpy(cmd->key, key_material, key_len);
2131
2132 if (key_rsc != NULL)
2133 memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
2134
2135 cmd->key_op_ctrl = key_op_ctrl;
2136
2137 if (mac_addr)
2138 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2139
2140 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
2141 sync_flag);
2142
2143 return ret;
2144 }
2145
2146 int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
2147 {
2148 struct sk_buff *skb;
2149 struct wmi_add_krk_cmd *cmd;
2150 int ret;
2151
2152 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2153 if (!skb)
2154 return -ENOMEM;
2155
2156 cmd = (struct wmi_add_krk_cmd *) skb->data;
2157 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2158
2159 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
2160
2161 return ret;
2162 }
2163
2164 int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
2165 {
2166 struct sk_buff *skb;
2167 struct wmi_delete_cipher_key_cmd *cmd;
2168 int ret;
2169
2170 if (key_index > WMI_MAX_KEY_INDEX)
2171 return -EINVAL;
2172
2173 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2174 if (!skb)
2175 return -ENOMEM;
2176
2177 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2178 cmd->key_index = key_index;
2179
2180 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
2181 NO_SYNC_WMIFLAG);
2182
2183 return ret;
2184 }
2185
2186 int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
2187 const u8 *pmkid, bool set)
2188 {
2189 struct sk_buff *skb;
2190 struct wmi_setpmkid_cmd *cmd;
2191 int ret;
2192
2193 if (bssid == NULL)
2194 return -EINVAL;
2195
2196 if (set && pmkid == NULL)
2197 return -EINVAL;
2198
2199 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2200 if (!skb)
2201 return -ENOMEM;
2202
2203 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2204 memcpy(cmd->bssid, bssid, ETH_ALEN);
2205 if (set) {
2206 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2207 cmd->enable = PMKID_ENABLE;
2208 } else {
2209 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2210 cmd->enable = PMKID_DISABLE;
2211 }
2212
2213 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
2214 NO_SYNC_WMIFLAG);
2215
2216 return ret;
2217 }
2218
2219 static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2220 enum htc_endpoint_id ep_id)
2221 {
2222 struct wmi_data_hdr *data_hdr;
2223 int ret;
2224
2225 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2226 return -EINVAL;
2227
2228 skb_push(skb, sizeof(struct wmi_data_hdr));
2229
2230 data_hdr = (struct wmi_data_hdr *) skb->data;
2231 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2232 data_hdr->info3 = 0;
2233
2234 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2235
2236 return ret;
2237 }
2238
2239 static int ath6kl_wmi_sync_point(struct wmi *wmi)
2240 {
2241 struct sk_buff *skb;
2242 struct wmi_sync_cmd *cmd;
2243 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2244 enum htc_endpoint_id ep_id;
2245 u8 index, num_pri_streams = 0;
2246 int ret = 0;
2247
2248 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2249
2250 spin_lock_bh(&wmi->lock);
2251
2252 for (index = 0; index < WMM_NUM_AC; index++) {
2253 if (wmi->fat_pipe_exist & (1 << index)) {
2254 num_pri_streams++;
2255 data_sync_bufs[num_pri_streams - 1].traffic_class =
2256 index;
2257 }
2258 }
2259
2260 spin_unlock_bh(&wmi->lock);
2261
2262 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2263 if (!skb) {
2264 ret = -ENOMEM;
2265 goto free_skb;
2266 }
2267
2268 cmd = (struct wmi_sync_cmd *) skb->data;
2269
2270 /*
2271 * In the SYNC cmd sent on the control Ep, send a bitmap
2272 * of the data eps on which the Data Sync will be sent
2273 */
2274 cmd->data_sync_map = wmi->fat_pipe_exist;
2275
2276 for (index = 0; index < num_pri_streams; index++) {
2277 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2278 if (data_sync_bufs[index].skb == NULL) {
2279 ret = -ENOMEM;
2280 break;
2281 }
2282 }
2283
2284 /*
2285 * If buffer allocation for any of the dataSync fails,
2286 * then do not send the Synchronize cmd on the control ep
2287 */
2288 if (ret)
2289 goto free_skb;
2290
2291 /*
2292 * Send sync cmd followed by sync data messages on all
2293 * endpoints being used
2294 */
2295 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
2296 NO_SYNC_WMIFLAG);
2297
2298 if (ret)
2299 goto free_skb;
2300
2301 /* cmd buffer sent, we no longer own it */
2302 skb = NULL;
2303
2304 for (index = 0; index < num_pri_streams; index++) {
2305
2306 if (WARN_ON(!data_sync_bufs[index].skb))
2307 break;
2308
2309 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2310 data_sync_bufs[index].
2311 traffic_class);
2312 ret =
2313 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2314 ep_id);
2315
2316 if (ret)
2317 break;
2318
2319 data_sync_bufs[index].skb = NULL;
2320 }
2321
2322 free_skb:
2323 /* free up any resources left over (possibly due to an error) */
2324 if (skb)
2325 dev_kfree_skb(skb);
2326
2327 for (index = 0; index < num_pri_streams; index++) {
2328 if (data_sync_bufs[index].skb != NULL) {
2329 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2330 skb);
2331 }
2332 }
2333
2334 return ret;
2335 }
2336
2337 int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
2338 struct wmi_create_pstream_cmd *params)
2339 {
2340 struct sk_buff *skb;
2341 struct wmi_create_pstream_cmd *cmd;
2342 u8 fatpipe_exist_for_ac = 0;
2343 s32 min_phy = 0;
2344 s32 nominal_phy = 0;
2345 int ret;
2346
2347 if (!((params->user_pri < 8) &&
2348 (params->user_pri <= 0x7) &&
2349 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2350 (params->traffic_direc == UPLINK_TRAFFIC ||
2351 params->traffic_direc == DNLINK_TRAFFIC ||
2352 params->traffic_direc == BIDIR_TRAFFIC) &&
2353 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2354 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2355 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2356 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2357 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2358 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2359 params->tsid <= WMI_MAX_THINSTREAM))) {
2360 return -EINVAL;
2361 }
2362
2363 /*
2364 * Check nominal PHY rate is >= minimalPHY,
2365 * so that DUT can allow TSRS IE
2366 */
2367
2368 /* Get the physical rate (units of bps) */
2369 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2370
2371 /* Check minimal phy < nominal phy rate */
2372 if (params->nominal_phy >= min_phy) {
2373 /* unit of 500 kbps */
2374 nominal_phy = (params->nominal_phy * 1000) / 500;
2375 ath6kl_dbg(ATH6KL_DBG_WMI,
2376 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2377 min_phy, nominal_phy);
2378
2379 params->nominal_phy = nominal_phy;
2380 } else {
2381 params->nominal_phy = 0;
2382 }
2383
2384 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2385 if (!skb)
2386 return -ENOMEM;
2387
2388 ath6kl_dbg(ATH6KL_DBG_WMI,
2389 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2390 params->traffic_class, params->tsid);
2391
2392 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2393 memcpy(cmd, params, sizeof(*cmd));
2394
2395 /* This is an implicitly created Fat pipe */
2396 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2397 spin_lock_bh(&wmi->lock);
2398 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2399 (1 << params->traffic_class));
2400 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2401 spin_unlock_bh(&wmi->lock);
2402 } else {
2403 /* explicitly created thin stream within a fat pipe */
2404 spin_lock_bh(&wmi->lock);
2405 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2406 (1 << params->traffic_class));
2407 wmi->stream_exist_for_ac[params->traffic_class] |=
2408 (1 << params->tsid);
2409 /*
2410 * If a thinstream becomes active, the fat pipe automatically
2411 * becomes active
2412 */
2413 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2414 spin_unlock_bh(&wmi->lock);
2415 }
2416
2417 /*
2418 * Indicate activty change to driver layer only if this is the
2419 * first TSID to get created in this AC explicitly or an implicit
2420 * fat pipe is getting created.
2421 */
2422 if (!fatpipe_exist_for_ac)
2423 ath6kl_indicate_tx_activity(wmi->parent_dev,
2424 params->traffic_class, true);
2425
2426 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
2427 NO_SYNC_WMIFLAG);
2428 return ret;
2429 }
2430
2431 int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
2432 {
2433 struct sk_buff *skb;
2434 struct wmi_delete_pstream_cmd *cmd;
2435 u16 active_tsids = 0;
2436 int ret;
2437
2438 if (traffic_class > 3) {
2439 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2440 return -EINVAL;
2441 }
2442
2443 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2444 if (!skb)
2445 return -ENOMEM;
2446
2447 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2448 cmd->traffic_class = traffic_class;
2449 cmd->tsid = tsid;
2450
2451 spin_lock_bh(&wmi->lock);
2452 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2453 spin_unlock_bh(&wmi->lock);
2454
2455 if (!(active_tsids & (1 << tsid))) {
2456 dev_kfree_skb(skb);
2457 ath6kl_dbg(ATH6KL_DBG_WMI,
2458 "TSID %d doesn't exist for traffic class: %d\n",
2459 tsid, traffic_class);
2460 return -ENODATA;
2461 }
2462
2463 ath6kl_dbg(ATH6KL_DBG_WMI,
2464 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2465 traffic_class, tsid);
2466
2467 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
2468 SYNC_BEFORE_WMIFLAG);
2469
2470 spin_lock_bh(&wmi->lock);
2471 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2472 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2473 spin_unlock_bh(&wmi->lock);
2474
2475 /*
2476 * Indicate stream inactivity to driver layer only if all tsids
2477 * within this AC are deleted.
2478 */
2479 if (!active_tsids) {
2480 ath6kl_indicate_tx_activity(wmi->parent_dev,
2481 traffic_class, false);
2482 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2483 }
2484
2485 return ret;
2486 }
2487
2488 int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2489 {
2490 struct sk_buff *skb;
2491 struct wmi_set_ip_cmd *cmd;
2492 int ret;
2493
2494 /* Multicast address are not valid */
2495 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2496 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2497 return -EINVAL;
2498
2499 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2500 if (!skb)
2501 return -ENOMEM;
2502
2503 cmd = (struct wmi_set_ip_cmd *) skb->data;
2504 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2505
2506 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
2507 return ret;
2508 }
2509
2510 static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2511 int len)
2512 {
2513 if (len < sizeof(struct wmi_get_wow_list_reply))
2514 return -EINVAL;
2515
2516 return 0;
2517 }
2518
2519 static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2520 enum wmix_command_id cmd_id,
2521 enum wmi_sync_flag sync_flag)
2522 {
2523 struct wmix_cmd_hdr *cmd_hdr;
2524 int ret;
2525
2526 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2527
2528 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2529 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2530
2531 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
2532
2533 return ret;
2534 }
2535
2536 int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2537 {
2538 struct sk_buff *skb;
2539 struct wmix_hb_challenge_resp_cmd *cmd;
2540 int ret;
2541
2542 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2543 if (!skb)
2544 return -ENOMEM;
2545
2546 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2547 cmd->cookie = cpu_to_le32(cookie);
2548 cmd->source = cpu_to_le32(source);
2549
2550 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2551 NO_SYNC_WMIFLAG);
2552 return ret;
2553 }
2554
2555 int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2556 {
2557 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2558 struct sk_buff *skb;
2559 int ret;
2560
2561 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2562 if (!skb)
2563 return -ENOMEM;
2564
2565 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2566 cmd->valid = cpu_to_le32(valid);
2567 cmd->config = cpu_to_le32(config);
2568
2569 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2570 NO_SYNC_WMIFLAG);
2571 return ret;
2572 }
2573
2574 int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
2575 {
2576 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
2577 }
2578
2579 int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
2580 {
2581 struct sk_buff *skb;
2582 struct wmi_set_tx_pwr_cmd *cmd;
2583 int ret;
2584
2585 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2586 if (!skb)
2587 return -ENOMEM;
2588
2589 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2590 cmd->dbM = dbM;
2591
2592 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
2593 NO_SYNC_WMIFLAG);
2594
2595 return ret;
2596 }
2597
2598 int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
2599 {
2600 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
2601 }
2602
2603 int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
2604 {
2605 struct sk_buff *skb;
2606 struct wmi_set_lpreamble_cmd *cmd;
2607 int ret;
2608
2609 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2610 if (!skb)
2611 return -ENOMEM;
2612
2613 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2614 cmd->status = status;
2615 cmd->preamble_policy = preamble_policy;
2616
2617 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
2618 NO_SYNC_WMIFLAG);
2619 return ret;
2620 }
2621
2622 int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2623 {
2624 struct sk_buff *skb;
2625 struct wmi_set_rts_cmd *cmd;
2626 int ret;
2627
2628 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2629 if (!skb)
2630 return -ENOMEM;
2631
2632 cmd = (struct wmi_set_rts_cmd *) skb->data;
2633 cmd->threshold = cpu_to_le16(threshold);
2634
2635 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
2636 return ret;
2637 }
2638
2639 int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
2640 {
2641 struct sk_buff *skb;
2642 struct wmi_set_wmm_txop_cmd *cmd;
2643 int ret;
2644
2645 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2646 return -EINVAL;
2647
2648 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2649 if (!skb)
2650 return -ENOMEM;
2651
2652 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2653 cmd->txop_enable = cfg;
2654
2655 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
2656 NO_SYNC_WMIFLAG);
2657 return ret;
2658 }
2659
2660 int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
2661 {
2662 struct sk_buff *skb;
2663 struct wmi_set_keepalive_cmd *cmd;
2664 int ret;
2665
2666 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2667 if (!skb)
2668 return -ENOMEM;
2669
2670 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2671 cmd->keep_alive_intvl = keep_alive_intvl;
2672 wmi->keep_alive_intvl = keep_alive_intvl;
2673
2674 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
2675 NO_SYNC_WMIFLAG);
2676 return ret;
2677 }
2678
2679 int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2680 {
2681 struct sk_buff *skb;
2682 int ret;
2683
2684 skb = ath6kl_wmi_get_new_buf(len);
2685 if (!skb)
2686 return -ENOMEM;
2687
2688 memcpy(skb->data, buf, len);
2689
2690 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
2691
2692 return ret;
2693 }
2694
2695
2696 s32 ath6kl_wmi_get_rate(s8 rate_index)
2697 {
2698 if (rate_index == RATE_AUTO)
2699 return 0;
2700
2701 return wmi_rate_tbl[(u32) rate_index][0];
2702 }
2703
2704 void ath6kl_wmi_node_return(struct wmi *wmi, struct bss *bss)
2705 {
2706 if (bss)
2707 wlan_node_return(&wmi->parent_dev->scan_table, bss);
2708 }
2709
2710 struct bss *ath6kl_wmi_find_ssid_node(struct wmi *wmi, u8 * ssid,
2711 u32 ssid_len, bool is_wpa2,
2712 bool match_ssid)
2713 {
2714 struct bss *node = NULL;
2715
2716 node = wlan_find_ssid_node(&wmi->parent_dev->scan_table, ssid,
2717 ssid_len, is_wpa2, match_ssid);
2718 return node;
2719 }
2720
2721 struct bss *ath6kl_wmi_find_node(struct wmi *wmi, const u8 * mac_addr)
2722 {
2723 struct bss *ni = NULL;
2724
2725 ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
2726
2727 return ni;
2728 }
2729
2730 void ath6kl_wmi_node_free(struct wmi *wmi, const u8 * mac_addr)
2731 {
2732 struct bss *ni = NULL;
2733
2734 ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
2735 if (ni != NULL)
2736 wlan_node_reclaim(&wmi->parent_dev->scan_table, ni);
2737
2738 return;
2739 }
2740
2741 static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2742 u32 len)
2743 {
2744 struct wmi_pmkid_list_reply *reply;
2745 u32 expected_len;
2746
2747 if (len < sizeof(struct wmi_pmkid_list_reply))
2748 return -EINVAL;
2749
2750 reply = (struct wmi_pmkid_list_reply *)datap;
2751 expected_len = sizeof(reply->num_pmkid) +
2752 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2753
2754 if (len < expected_len)
2755 return -EINVAL;
2756
2757 return 0;
2758 }
2759
2760 static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2761 {
2762 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2763
2764 aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
2765 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2766
2767 return 0;
2768 }
2769
2770 static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2771 {
2772 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2773
2774 aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
2775
2776 return 0;
2777 }
2778
2779 /* AP mode functions */
2780
2781 int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
2782 {
2783 struct sk_buff *skb;
2784 struct wmi_connect_cmd *cm;
2785 int res;
2786
2787 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2788 if (!skb)
2789 return -ENOMEM;
2790
2791 cm = (struct wmi_connect_cmd *) skb->data;
2792 memcpy(cm, p, sizeof(*cm));
2793
2794 res = ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_CONFIG_COMMIT_CMDID,
2795 NO_SYNC_WMIFLAG);
2796 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2797 "ctrl_flags=0x%x-> res=%d\n",
2798 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2799 le32_to_cpu(p->ctrl_flags), res);
2800 return res;
2801 }
2802
2803 int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
2804 {
2805 struct sk_buff *skb;
2806 struct wmi_ap_set_mlme_cmd *cm;
2807
2808 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2809 if (!skb)
2810 return -ENOMEM;
2811
2812 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2813 memcpy(cm->mac, mac, ETH_ALEN);
2814 cm->reason = cpu_to_le16(reason);
2815 cm->cmd = cmd;
2816
2817 return ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_SET_MLME_CMDID,
2818 NO_SYNC_WMIFLAG);
2819 }
2820
2821 static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
2822 {
2823 struct wmi_pspoll_event *ev;
2824
2825 if (len < sizeof(struct wmi_pspoll_event))
2826 return -EINVAL;
2827
2828 ev = (struct wmi_pspoll_event *) datap;
2829
2830 ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
2831
2832 return 0;
2833 }
2834
2835 static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
2836 {
2837 ath6kl_dtimexpiry_event(wmi->parent_dev);
2838
2839 return 0;
2840 }
2841
2842 int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
2843 {
2844 struct sk_buff *skb;
2845 struct wmi_ap_set_pvb_cmd *cmd;
2846 int ret;
2847
2848 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2849 if (!skb)
2850 return -ENOMEM;
2851
2852 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2853 cmd->aid = cpu_to_le16(aid);
2854 cmd->rsvd = cpu_to_le16(0);
2855 cmd->flag = cpu_to_le32(flag);
2856
2857 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
2858 NO_SYNC_WMIFLAG);
2859
2860 return 0;
2861 }
2862
2863 int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
2864 bool rx_dot11_hdr, bool defrag_on_host)
2865 {
2866 struct sk_buff *skb;
2867 struct wmi_rx_frame_format_cmd *cmd;
2868 int ret;
2869
2870 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2871 if (!skb)
2872 return -ENOMEM;
2873
2874 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2875 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2876 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2877 cmd->meta_ver = rx_meta_ver;
2878
2879 /* Delete the local aggr state, on host */
2880 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
2881 NO_SYNC_WMIFLAG);
2882
2883 return ret;
2884 }
2885
2886 int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
2887 u8 ie_len)
2888 {
2889 struct sk_buff *skb;
2890 struct wmi_set_appie_cmd *p;
2891
2892 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2893 if (!skb)
2894 return -ENOMEM;
2895
2896 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2897 "ie_len=%u\n", mgmt_frm_type, ie_len);
2898 p = (struct wmi_set_appie_cmd *) skb->data;
2899 p->mgmt_frm_type = mgmt_frm_type;
2900 p->ie_len = ie_len;
2901 memcpy(p->ie_info, ie, ie_len);
2902 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_APPIE_CMDID,
2903 NO_SYNC_WMIFLAG);
2904 }
2905
2906 int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2907 {
2908 struct sk_buff *skb;
2909 struct wmi_disable_11b_rates_cmd *cmd;
2910
2911 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2912 if (!skb)
2913 return -ENOMEM;
2914
2915 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2916 disable);
2917 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2918 cmd->disable = disable ? 1 : 0;
2919
2920 return ath6kl_wmi_cmd_send(wmi, skb, WMI_DISABLE_11B_RATES_CMDID,
2921 NO_SYNC_WMIFLAG);
2922 }
2923
2924 int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
2925 {
2926 struct sk_buff *skb;
2927 struct wmi_remain_on_chnl_cmd *p;
2928
2929 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2930 if (!skb)
2931 return -ENOMEM;
2932
2933 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
2934 freq, dur);
2935 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
2936 p->freq = cpu_to_le32(freq);
2937 p->duration = cpu_to_le32(dur);
2938 return ath6kl_wmi_cmd_send(wmi, skb, WMI_REMAIN_ON_CHNL_CMDID,
2939 NO_SYNC_WMIFLAG);
2940 }
2941
2942 int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
2943 const u8 *data, u16 data_len)
2944 {
2945 struct sk_buff *skb;
2946 struct wmi_send_action_cmd *p;
2947 u8 *buf;
2948
2949 if (wait)
2950 return -EINVAL; /* Offload for wait not supported */
2951
2952 buf = kmalloc(data_len, GFP_KERNEL);
2953 if (!buf)
2954 return -ENOMEM;
2955
2956 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2957 if (!skb) {
2958 kfree(buf);
2959 return -ENOMEM;
2960 }
2961
2962 kfree(wmi->last_mgmt_tx_frame);
2963 wmi->last_mgmt_tx_frame = buf;
2964 wmi->last_mgmt_tx_frame_len = data_len;
2965
2966 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
2967 "len=%u\n", id, freq, wait, data_len);
2968 p = (struct wmi_send_action_cmd *) skb->data;
2969 p->id = cpu_to_le32(id);
2970 p->freq = cpu_to_le32(freq);
2971 p->wait = cpu_to_le32(wait);
2972 p->len = cpu_to_le16(data_len);
2973 memcpy(p->data, data, data_len);
2974 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_ACTION_CMDID,
2975 NO_SYNC_WMIFLAG);
2976 }
2977
2978 int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
2979 const u8 *dst,
2980 const u8 *data, u16 data_len)
2981 {
2982 struct sk_buff *skb;
2983 struct wmi_p2p_probe_response_cmd *p;
2984
2985 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2986 if (!skb)
2987 return -ENOMEM;
2988
2989 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
2990 "len=%u\n", freq, dst, data_len);
2991 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
2992 p->freq = cpu_to_le32(freq);
2993 memcpy(p->destination_addr, dst, ETH_ALEN);
2994 p->len = cpu_to_le16(data_len);
2995 memcpy(p->data, data, data_len);
2996 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_PROBE_RESPONSE_CMDID,
2997 NO_SYNC_WMIFLAG);
2998 }
2999
3000 int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
3001 {
3002 struct sk_buff *skb;
3003 struct wmi_probe_req_report_cmd *p;
3004
3005 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3006 if (!skb)
3007 return -ENOMEM;
3008
3009 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3010 enable);
3011 p = (struct wmi_probe_req_report_cmd *) skb->data;
3012 p->enable = enable ? 1 : 0;
3013 return ath6kl_wmi_cmd_send(wmi, skb, WMI_PROBE_REQ_REPORT_CMDID,
3014 NO_SYNC_WMIFLAG);
3015 }
3016
3017 int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
3018 {
3019 struct sk_buff *skb;
3020 struct wmi_get_p2p_info *p;
3021
3022 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3023 if (!skb)
3024 return -ENOMEM;
3025
3026 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3027 info_req_flags);
3028 p = (struct wmi_get_p2p_info *) skb->data;
3029 p->info_req_flags = cpu_to_le32(info_req_flags);
3030 return ath6kl_wmi_cmd_send(wmi, skb, WMI_GET_P2P_INFO_CMDID,
3031 NO_SYNC_WMIFLAG);
3032 }
3033
3034 int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi)
3035 {
3036 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
3037 return ath6kl_wmi_simple_cmd(wmi, WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
3038 }
3039
3040 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3041 {
3042 struct wmix_cmd_hdr *cmd;
3043 u32 len;
3044 u16 id;
3045 u8 *datap;
3046 int ret = 0;
3047
3048 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3049 ath6kl_err("bad packet 1\n");
3050 wmi->stat.cmd_len_err++;
3051 return -EINVAL;
3052 }
3053
3054 cmd = (struct wmix_cmd_hdr *) skb->data;
3055 id = le32_to_cpu(cmd->cmd_id);
3056
3057 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3058
3059 datap = skb->data;
3060 len = skb->len;
3061
3062 switch (id) {
3063 case WMIX_HB_CHALLENGE_RESP_EVENTID:
3064 break;
3065 case WMIX_DBGLOG_EVENTID:
3066 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
3067 break;
3068 default:
3069 ath6kl_err("unknown cmd id 0x%x\n", id);
3070 wmi->stat.cmd_id_err++;
3071 ret = -EINVAL;
3072 break;
3073 }
3074
3075 return ret;
3076 }
3077
3078 /* Control Path */
3079 int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
3080 {
3081 struct wmi_cmd_hdr *cmd;
3082 u32 len;
3083 u16 id;
3084 u8 *datap;
3085 int ret = 0;
3086
3087 if (WARN_ON(skb == NULL))
3088 return -EINVAL;
3089
3090 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
3091 ath6kl_err("bad packet 1\n");
3092 dev_kfree_skb(skb);
3093 wmi->stat.cmd_len_err++;
3094 return -EINVAL;
3095 }
3096
3097 cmd = (struct wmi_cmd_hdr *) skb->data;
3098 id = le16_to_cpu(cmd->cmd_id);
3099
3100 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3101
3102 datap = skb->data;
3103 len = skb->len;
3104
3105 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: wmi id: %d\n", __func__, id);
3106 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "msg payload ", datap, len);
3107
3108 switch (id) {
3109 case WMI_GET_BITRATE_CMDID:
3110 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3111 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3112 break;
3113 case WMI_GET_CHANNEL_LIST_CMDID:
3114 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3115 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3116 break;
3117 case WMI_GET_TX_PWR_CMDID:
3118 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3119 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3120 break;
3121 case WMI_READY_EVENTID:
3122 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3123 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3124 break;
3125 case WMI_CONNECT_EVENTID:
3126 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3127 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
3128 break;
3129 case WMI_DISCONNECT_EVENTID:
3130 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3131 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
3132 break;
3133 case WMI_PEER_NODE_EVENTID:
3134 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3135 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3136 break;
3137 case WMI_TKIP_MICERR_EVENTID:
3138 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3139 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
3140 break;
3141 case WMI_BSSINFO_EVENTID:
3142 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3143 ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(skb, datap);
3144 ret = ath6kl_wmi_bssinfo_event_rx(wmi, skb->data, skb->len);
3145 break;
3146 case WMI_REGDOMAIN_EVENTID:
3147 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
3148 ath6kl_wmi_regdomain_event(wmi, datap, len);
3149 break;
3150 case WMI_PSTREAM_TIMEOUT_EVENTID:
3151 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3152 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3153 break;
3154 case WMI_NEIGHBOR_REPORT_EVENTID:
3155 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3156 break;
3157 case WMI_SCAN_COMPLETE_EVENTID:
3158 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3159 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
3160 break;
3161 case WMI_CMDERROR_EVENTID:
3162 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3163 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3164 break;
3165 case WMI_REPORT_STATISTICS_EVENTID:
3166 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3167 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
3168 break;
3169 case WMI_RSSI_THRESHOLD_EVENTID:
3170 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3171 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3172 break;
3173 case WMI_ERROR_REPORT_EVENTID:
3174 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3175 break;
3176 case WMI_OPT_RX_FRAME_EVENTID:
3177 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
3178 ret = ath6kl_wmi_opt_frame_event_rx(wmi, datap, len);
3179 break;
3180 case WMI_REPORT_ROAM_TBL_EVENTID:
3181 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
3182 break;
3183 case WMI_EXTENSION_EVENTID:
3184 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3185 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3186 break;
3187 case WMI_CAC_EVENTID:
3188 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3189 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
3190 break;
3191 case WMI_CHANNEL_CHANGE_EVENTID:
3192 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3193 break;
3194 case WMI_REPORT_ROAM_DATA_EVENTID:
3195 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3196 break;
3197 case WMI_TEST_EVENTID:
3198 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
3199 ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
3200 break;
3201 case WMI_GET_FIXRATES_CMDID:
3202 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3203 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3204 break;
3205 case WMI_TX_RETRY_ERR_EVENTID:
3206 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3207 break;
3208 case WMI_SNR_THRESHOLD_EVENTID:
3209 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3210 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3211 break;
3212 case WMI_LQ_THRESHOLD_EVENTID:
3213 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3214 break;
3215 case WMI_APLIST_EVENTID:
3216 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3217 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3218 break;
3219 case WMI_GET_KEEPALIVE_CMDID:
3220 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3221 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3222 break;
3223 case WMI_GET_WOW_LIST_EVENTID:
3224 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
3225 ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
3226 break;
3227 case WMI_GET_PMKID_LIST_EVENTID:
3228 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3229 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3230 break;
3231 case WMI_PSPOLL_EVENTID:
3232 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3233 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
3234 break;
3235 case WMI_DTIMEXPIRY_EVENTID:
3236 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3237 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
3238 break;
3239 case WMI_SET_PARAMS_REPLY_EVENTID:
3240 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3241 break;
3242 case WMI_ADDBA_REQ_EVENTID:
3243 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3244 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
3245 break;
3246 case WMI_ADDBA_RESP_EVENTID:
3247 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3248 break;
3249 case WMI_DELBA_REQ_EVENTID:
3250 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3251 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
3252 break;
3253 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3254 ath6kl_dbg(ATH6KL_DBG_WMI,
3255 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3256 break;
3257 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3258 ath6kl_dbg(ATH6KL_DBG_WMI,
3259 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3260 break;
3261 case WMI_TX_COMPLETE_EVENTID:
3262 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3263 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3264 break;
3265 case WMI_REMAIN_ON_CHNL_EVENTID:
3266 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3267 ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
3268 break;
3269 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3270 ath6kl_dbg(ATH6KL_DBG_WMI,
3271 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3272 ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3273 len);
3274 break;
3275 case WMI_TX_STATUS_EVENTID:
3276 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3277 ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len);
3278 break;
3279 case WMI_RX_PROBE_REQ_EVENTID:
3280 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3281 ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len);
3282 break;
3283 case WMI_P2P_CAPABILITIES_EVENTID:
3284 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3285 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3286 break;
3287 case WMI_RX_ACTION_EVENTID:
3288 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3289 ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len);
3290 break;
3291 case WMI_P2P_INFO_EVENTID:
3292 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3293 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3294 break;
3295 default:
3296 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
3297 wmi->stat.cmd_id_err++;
3298 ret = -EINVAL;
3299 break;
3300 }
3301
3302 dev_kfree_skb(skb);
3303
3304 return ret;
3305 }
3306
3307 static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
3308 {
3309 if (!wmi)
3310 return;
3311
3312 spin_lock_bh(&wmi->lock);
3313
3314 wmi->fat_pipe_exist = 0;
3315 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3316
3317 spin_unlock_bh(&wmi->lock);
3318 }
3319
3320 void *ath6kl_wmi_init(struct ath6kl *dev)
3321 {
3322 struct wmi *wmi;
3323
3324 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3325 if (!wmi)
3326 return NULL;
3327
3328 spin_lock_init(&wmi->lock);
3329
3330 wmi->parent_dev = dev;
3331
3332 ath6kl_wmi_qos_state_init(wmi);
3333
3334 wmi->pwr_mode = REC_POWER;
3335 wmi->phy_mode = WMI_11G_MODE;
3336
3337 wmi->pair_crypto_type = NONE_CRYPT;
3338 wmi->grp_crypto_type = NONE_CRYPT;
3339
3340 wmi->ht_allowed[A_BAND_24GHZ] = 1;
3341 wmi->ht_allowed[A_BAND_5GHZ] = 1;
3342
3343 return wmi;
3344 }
3345
3346 void ath6kl_wmi_shutdown(struct wmi *wmi)
3347 {
3348 if (!wmi)
3349 return;
3350
3351 kfree(wmi->last_mgmt_tx_frame);
3352 kfree(wmi);
3353 }
This page took 0.098407 seconds and 6 git commands to generate.