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