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