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