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