blob: a71d77311251e0ca60b63db45191add549b0b354 [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
Kalle Valoa7f0c582011-10-05 12:23:05 +0300265 /*
266 * workaround for WMM S5
267 *
268 * FIXME: wmi->traffic_class is always 100 so this test doesn't
269 * make sense
270 */
Kalle Valobdcd8172011-07-18 00:22:30 +0300271 if ((wmi->traffic_class == WMM_AC_VI) &&
272 ((usr_pri == 5) || (usr_pri == 4)))
273 usr_pri = 1;
274
275 /* Convert user priority to traffic class */
276 traffic_class = up_to_ac[usr_pri & 0x7];
277
278 wmi_data_hdr_set_up(data_hdr, usr_pri);
279
280 spin_lock_bh(&wmi->lock);
281 stream_exist = wmi->fat_pipe_exist;
282 spin_unlock_bh(&wmi->lock);
283
284 if (!(stream_exist & (1 << traffic_class))) {
285 memset(&cmd, 0, sizeof(cmd));
286 cmd.traffic_class = traffic_class;
287 cmd.user_pri = usr_pri;
288 cmd.inactivity_int =
289 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
290 /* Implicit streams are created with TSID 0xFF */
291 cmd.tsid = WMI_IMPLICIT_PSTREAM;
292 ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
293 }
294
295 *ac = traffic_class;
296
297 return 0;
298}
299
300int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
301{
302 struct ieee80211_hdr_3addr *pwh, wh;
303 struct ath6kl_llc_snap_hdr *llc_hdr;
304 struct ethhdr eth_hdr;
305 u32 hdr_size;
306 u8 *datap;
307 __le16 sub_type;
308
309 if (WARN_ON(skb == NULL))
310 return -EINVAL;
311
312 datap = skb->data;
313 pwh = (struct ieee80211_hdr_3addr *) datap;
314
315 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
316
317 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
318
319 /* Strip off the 802.11 header */
320 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
321 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
322 sizeof(u32));
323 skb_pull(skb, hdr_size);
324 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
325 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
326
327 datap = skb->data;
328 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
329
Raja Manic8790cba2011-07-19 19:27:32 +0530330 memset(&eth_hdr, 0, sizeof(eth_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +0300331 eth_hdr.h_proto = llc_hdr->eth_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300332
333 switch ((le16_to_cpu(wh.frame_control)) &
334 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
335 case 0:
336 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
337 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
338 break;
339 case IEEE80211_FCTL_TODS:
340 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
341 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
342 break;
343 case IEEE80211_FCTL_FROMDS:
344 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
345 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
346 break;
347 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
348 break;
349 }
350
351 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
352 skb_push(skb, sizeof(eth_hdr));
353
354 datap = skb->data;
355
356 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
357
358 return 0;
359}
360
361/*
362 * Performs 802.3 to DIX encapsulation for received packets.
363 * Assumes the entire 802.3 header is contigous.
364 */
365int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
366{
367 struct ath6kl_llc_snap_hdr *llc_hdr;
368 struct ethhdr eth_hdr;
369 u8 *datap;
370
371 if (WARN_ON(skb == NULL))
372 return -EINVAL;
373
374 datap = skb->data;
375
376 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
377
378 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
379 eth_hdr.h_proto = llc_hdr->eth_type;
380
381 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
382 datap = skb->data;
383
384 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
385
386 return 0;
387}
388
Kalle Valobdcd8172011-07-18 00:22:30 +0300389static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
390{
391 struct tx_complete_msg_v1 *msg_v1;
392 struct wmi_tx_complete_event *evt;
393 int index;
394 u16 size;
395
396 evt = (struct wmi_tx_complete_event *) datap;
397
398 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
399 evt->num_msg, evt->msg_len, evt->msg_type);
400
401 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
402 return 0;
403
404 for (index = 0; index < evt->num_msg; index++) {
405 size = sizeof(struct wmi_tx_complete_event) +
406 (index * sizeof(struct tx_complete_msg_v1));
407 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
408
409 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
410 msg_v1->status, msg_v1->pkt_id,
411 msg_v1->rate_idx, msg_v1->ack_failures);
412 }
413
414 return 0;
415}
416
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300417static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
418 int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300419{
420 struct wmi_remain_on_chnl_event *ev;
421 u32 freq;
422 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300423 struct ieee80211_channel *chan;
424 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300425
426 if (len < sizeof(*ev))
427 return -EINVAL;
428
429 ev = (struct wmi_remain_on_chnl_event *) datap;
430 freq = le32_to_cpu(ev->freq);
431 dur = le32_to_cpu(ev->duration);
432 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
433 freq, dur);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530434 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300435 if (!chan) {
436 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
437 "(freq=%u)\n", freq);
438 return -EINVAL;
439 }
440 cfg80211_ready_on_channel(ar->net_dev, 1, chan, NL80211_CHAN_NO_HT,
441 dur, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300442
443 return 0;
444}
445
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300446static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
447 u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300448{
449 struct wmi_cancel_remain_on_chnl_event *ev;
450 u32 freq;
451 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300452 struct ieee80211_channel *chan;
453 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300454
455 if (len < sizeof(*ev))
456 return -EINVAL;
457
458 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
459 freq = le32_to_cpu(ev->freq);
460 dur = le32_to_cpu(ev->duration);
461 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
462 "status=%u\n", freq, dur, ev->status);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530463 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300464 if (!chan) {
465 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
466 "channel (freq=%u)\n", freq);
467 return -EINVAL;
468 }
469 cfg80211_remain_on_channel_expired(ar->net_dev, 1, chan,
470 NL80211_CHAN_NO_HT, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300471
472 return 0;
473}
474
Jouni Malinena0df5db2011-08-30 21:58:02 +0300475static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300476{
477 struct wmi_tx_status_event *ev;
478 u32 id;
Jouni Malinena0df5db2011-08-30 21:58:02 +0300479 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300480
481 if (len < sizeof(*ev))
482 return -EINVAL;
483
484 ev = (struct wmi_tx_status_event *) datap;
485 id = le32_to_cpu(ev->id);
486 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
487 id, ev->ack_status);
Jouni Malinena0df5db2011-08-30 21:58:02 +0300488 if (wmi->last_mgmt_tx_frame) {
489 cfg80211_mgmt_tx_status(ar->net_dev, id,
490 wmi->last_mgmt_tx_frame,
491 wmi->last_mgmt_tx_frame_len,
492 !!ev->ack_status, GFP_ATOMIC);
493 kfree(wmi->last_mgmt_tx_frame);
494 wmi->last_mgmt_tx_frame = NULL;
495 wmi->last_mgmt_tx_frame_len = 0;
496 }
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300497
498 return 0;
499}
500
Jouni Malinenae32c302011-08-30 21:58:01 +0300501static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300502{
503 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300504 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300505 u16 dlen;
Jouni Malinenae32c302011-08-30 21:58:01 +0300506 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300507
508 if (len < sizeof(*ev))
509 return -EINVAL;
510
511 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300512 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300513 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300514 if (datap + len < ev->data + dlen) {
515 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
516 "len=%d dlen=%u\n", len, dlen);
517 return -EINVAL;
518 }
519 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
520 "probe_req_report=%d\n",
521 dlen, freq, ar->probe_req_report);
522
523 if (ar->probe_req_report || ar->nw_type == AP_NETWORK)
524 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300525
526 return 0;
527}
528
529static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
530{
531 struct wmi_p2p_capabilities_event *ev;
532 u16 dlen;
533
534 if (len < sizeof(*ev))
535 return -EINVAL;
536
537 ev = (struct wmi_p2p_capabilities_event *) datap;
538 dlen = le16_to_cpu(ev->len);
539 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
540
541 return 0;
542}
543
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300544static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300545{
546 struct wmi_rx_action_event *ev;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300547 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300548 u16 dlen;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300549 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300550
551 if (len < sizeof(*ev))
552 return -EINVAL;
553
554 ev = (struct wmi_rx_action_event *) datap;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300555 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300556 dlen = le16_to_cpu(ev->len);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300557 if (datap + len < ev->data + dlen) {
558 ath6kl_err("invalid wmi_rx_action_event: "
559 "len=%d dlen=%u\n", len, dlen);
560 return -EINVAL;
561 }
562 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
563 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300564
565 return 0;
566}
567
568static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
569{
570 struct wmi_p2p_info_event *ev;
571 u32 flags;
572 u16 dlen;
573
574 if (len < sizeof(*ev))
575 return -EINVAL;
576
577 ev = (struct wmi_p2p_info_event *) datap;
578 flags = le32_to_cpu(ev->info_req_flags);
579 dlen = le16_to_cpu(ev->len);
580 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
581
582 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
583 struct wmi_p2p_capabilities *cap;
584 if (dlen < sizeof(*cap))
585 return -EINVAL;
586 cap = (struct wmi_p2p_capabilities *) ev->data;
587 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
588 cap->go_power_save);
589 }
590
591 if (flags & P2P_FLAG_MACADDR_REQ) {
592 struct wmi_p2p_macaddr *mac;
593 if (dlen < sizeof(*mac))
594 return -EINVAL;
595 mac = (struct wmi_p2p_macaddr *) ev->data;
596 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
597 mac->mac_addr);
598 }
599
600 if (flags & P2P_FLAG_HMODEL_REQ) {
601 struct wmi_p2p_hmodel *mod;
602 if (dlen < sizeof(*mod))
603 return -EINVAL;
604 mod = (struct wmi_p2p_hmodel *) ev->data;
605 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
606 mod->p2p_model,
607 mod->p2p_model ? "host" : "firmware");
608 }
609 return 0;
610}
611
Kalle Valobdcd8172011-07-18 00:22:30 +0300612static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
613{
614 struct sk_buff *skb;
615
616 skb = ath6kl_buf_alloc(size);
617 if (!skb)
618 return NULL;
619
620 skb_put(skb, size);
621 if (size)
622 memset(skb->data, 0, size);
623
624 return skb;
625}
626
627/* Send a "simple" wmi command -- one with no arguments */
628static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
629{
630 struct sk_buff *skb;
631 int ret;
632
633 skb = ath6kl_wmi_get_new_buf(0);
634 if (!skb)
635 return -ENOMEM;
636
637 ret = ath6kl_wmi_cmd_send(wmi, skb, cmd_id, NO_SYNC_WMIFLAG);
638
639 return ret;
640}
641
642static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
643{
644 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
645
646 if (len < sizeof(struct wmi_ready_event_2))
647 return -EINVAL;
648
Kalle Valobdcd8172011-07-18 00:22:30 +0300649 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
650 le32_to_cpu(ev->sw_version),
651 le32_to_cpu(ev->abi_version));
652
653 return 0;
654}
655
Vivek Natarajane5090442011-08-31 15:02:19 +0530656/*
657 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
658 * at which the station has to roam can be passed with
659 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
660 * in dBm.
661 */
662int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
663{
664 struct sk_buff *skb;
665 struct roam_ctrl_cmd *cmd;
666
667 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
668 if (!skb)
669 return -ENOMEM;
670
671 cmd = (struct roam_ctrl_cmd *) skb->data;
672
673 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
674 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
675 DEF_SCAN_FOR_ROAM_INTVL);
676 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
677 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
678 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
679
680 ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_ROAM_CTRL_CMDID, NO_SYNC_WMIFLAG);
681
682 return 0;
683}
684
Jouni Malinen12618752011-10-11 17:31:55 +0300685int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
686{
687 struct sk_buff *skb;
688 struct roam_ctrl_cmd *cmd;
689
690 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
691 if (!skb)
692 return -ENOMEM;
693
694 cmd = (struct roam_ctrl_cmd *) skb->data;
695 memset(cmd, 0, sizeof(*cmd));
696
697 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
698 cmd->roam_ctrl = WMI_FORCE_ROAM;
699
700 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
701 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_ROAM_CTRL_CMDID,
702 NO_SYNC_WMIFLAG);
703}
704
705int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
706{
707 struct sk_buff *skb;
708 struct roam_ctrl_cmd *cmd;
709
710 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
711 if (!skb)
712 return -ENOMEM;
713
714 cmd = (struct roam_ctrl_cmd *) skb->data;
715 memset(cmd, 0, sizeof(*cmd));
716
717 cmd->info.roam_mode = mode;
718 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
719
720 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
721 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_ROAM_CTRL_CMDID,
722 NO_SYNC_WMIFLAG);
723}
724
Kalle Valobdcd8172011-07-18 00:22:30 +0300725static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
726{
727 struct wmi_connect_event *ev;
728 u8 *pie, *peie;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300729 struct ath6kl *ar = wmi->parent_dev;
Kalle Valobdcd8172011-07-18 00:22:30 +0300730
731 if (len < sizeof(struct wmi_connect_event))
732 return -EINVAL;
733
734 ev = (struct wmi_connect_event *) datap;
735
Jouni Malinen572e27c2011-09-05 17:38:45 +0300736 if (ar->nw_type == AP_NETWORK) {
737 /* AP mode start/STA connected event */
738 struct net_device *dev = ar->net_dev;
739 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
740 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
741 "(AP started)\n",
742 __func__, le16_to_cpu(ev->u.ap_bss.ch),
743 ev->u.ap_bss.bssid);
744 ath6kl_connect_ap_mode_bss(
745 ar, le16_to_cpu(ev->u.ap_bss.ch));
746 } else {
747 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
748 "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
749 "(STA connected)\n",
750 __func__, ev->u.ap_sta.aid,
751 ev->u.ap_sta.mac_addr,
752 ev->u.ap_sta.auth,
753 ev->u.ap_sta.keymgmt,
754 le16_to_cpu(ev->u.ap_sta.cipher),
755 ev->u.ap_sta.apsd_info);
756 ath6kl_connect_ap_mode_sta(
757 ar, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
758 ev->u.ap_sta.keymgmt,
759 le16_to_cpu(ev->u.ap_sta.cipher),
760 ev->u.ap_sta.auth, ev->assoc_req_len,
761 ev->assoc_info + ev->beacon_ie_len);
762 }
763 return 0;
764 }
765
766 /* STA/IBSS mode connection event */
767
Kalle Valob9b6ee62011-09-27 14:31:21 +0300768 ath6kl_dbg(ATH6KL_DBG_WMI,
769 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
770 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
771 le16_to_cpu(ev->u.sta.listen_intvl),
772 le16_to_cpu(ev->u.sta.beacon_intvl),
773 le32_to_cpu(ev->u.sta.nw_type));
Kalle Valobdcd8172011-07-18 00:22:30 +0300774
Kalle Valobdcd8172011-07-18 00:22:30 +0300775 /* Start of assoc rsp IEs */
776 pie = ev->assoc_info + ev->beacon_ie_len +
777 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
778
779 /* End of assoc rsp IEs */
780 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
781 ev->assoc_resp_len;
782
783 while (pie < peie) {
784 switch (*pie) {
785 case WLAN_EID_VENDOR_SPECIFIC:
786 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
787 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
788 /* WMM OUT (00:50:F2) */
789 if (pie[1] > 5
790 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
791 wmi->is_wmm_enabled = true;
792 }
793 break;
794 }
795
796 if (wmi->is_wmm_enabled)
797 break;
798
799 pie += pie[1] + 2;
800 }
801
Jouni Malinen572e27c2011-09-05 17:38:45 +0300802 ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->u.sta.ch),
803 ev->u.sta.bssid,
804 le16_to_cpu(ev->u.sta.listen_intvl),
805 le16_to_cpu(ev->u.sta.beacon_intvl),
806 le32_to_cpu(ev->u.sta.nw_type),
Kalle Valobdcd8172011-07-18 00:22:30 +0300807 ev->beacon_ie_len, ev->assoc_req_len,
808 ev->assoc_resp_len, ev->assoc_info);
809
810 return 0;
811}
812
Vivek Natarajan06033762011-09-06 13:01:36 +0530813static struct country_code_to_enum_rd *
814ath6kl_regd_find_country(u16 countryCode)
815{
816 int i;
817
818 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
819 if (allCountries[i].countryCode == countryCode)
820 return &allCountries[i];
821 }
822
823 return NULL;
824}
825
826static struct reg_dmn_pair_mapping *
827ath6kl_get_regpair(u16 regdmn)
828{
829 int i;
830
831 if (regdmn == NO_ENUMRD)
832 return NULL;
833
834 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
835 if (regDomainPairs[i].regDmnEnum == regdmn)
836 return &regDomainPairs[i];
837 }
838
839 return NULL;
840}
841
842static struct country_code_to_enum_rd *
843ath6kl_regd_find_country_by_rd(u16 regdmn)
844{
845 int i;
846
847 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
848 if (allCountries[i].regDmnEnum == regdmn)
849 return &allCountries[i];
850 }
851
852 return NULL;
853}
854
855static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
856{
857
858 struct ath6kl_wmi_regdomain *ev;
859 struct country_code_to_enum_rd *country = NULL;
860 struct reg_dmn_pair_mapping *regpair = NULL;
861 char alpha2[2];
862 u32 reg_code;
863
864 ev = (struct ath6kl_wmi_regdomain *) datap;
865 reg_code = le32_to_cpu(ev->reg_code);
866
867 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
868 country = ath6kl_regd_find_country((u16) reg_code);
869 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
870
871 regpair = ath6kl_get_regpair((u16) reg_code);
872 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
Kalle Valob9b6ee62011-09-27 14:31:21 +0300873 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
Vivek Natarajan06033762011-09-06 13:01:36 +0530874 regpair->regDmnEnum);
875 }
876
877 if (country) {
878 alpha2[0] = country->isoName[0];
879 alpha2[1] = country->isoName[1];
880
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530881 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
Vivek Natarajan06033762011-09-06 13:01:36 +0530882
Kalle Valob9b6ee62011-09-27 14:31:21 +0300883 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
Vivek Natarajan06033762011-09-06 13:01:36 +0530884 alpha2[0], alpha2[1]);
885 }
886}
887
Kalle Valobdcd8172011-07-18 00:22:30 +0300888static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
889{
890 struct wmi_disconnect_event *ev;
891 wmi->traffic_class = 100;
892
893 if (len < sizeof(struct wmi_disconnect_event))
894 return -EINVAL;
895
896 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300897
Kalle Valob9b6ee62011-09-27 14:31:21 +0300898 ath6kl_dbg(ATH6KL_DBG_WMI,
899 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
900 le16_to_cpu(ev->proto_reason_status), ev->bssid,
901 ev->disconn_reason, ev->assoc_resp_len);
902
Kalle Valobdcd8172011-07-18 00:22:30 +0300903 wmi->is_wmm_enabled = false;
Kalle Valobdcd8172011-07-18 00:22:30 +0300904
905 ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
906 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
907 le16_to_cpu(ev->proto_reason_status));
908
909 return 0;
910}
911
912static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
913{
914 struct wmi_peer_node_event *ev;
915
916 if (len < sizeof(struct wmi_peer_node_event))
917 return -EINVAL;
918
919 ev = (struct wmi_peer_node_event *) datap;
920
921 if (ev->event_code == PEER_NODE_JOIN_EVENT)
922 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
923 ev->peer_mac_addr);
924 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
925 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
926 ev->peer_mac_addr);
927
928 return 0;
929}
930
931static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
932{
933 struct wmi_tkip_micerr_event *ev;
934
935 if (len < sizeof(struct wmi_tkip_micerr_event))
936 return -EINVAL;
937
938 ev = (struct wmi_tkip_micerr_event *) datap;
939
940 ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
941
942 return 0;
943}
944
Kalle Valobdcd8172011-07-18 00:22:30 +0300945static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
946{
Jouni Malinen82e14f52011-09-19 19:15:05 +0300947 struct wmi_bss_info_hdr2 *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300948 u8 *buf;
949 struct ieee80211_channel *channel;
950 struct ath6kl *ar = wmi->parent_dev;
951 struct ieee80211_mgmt *mgmt;
952 struct cfg80211_bss *bss;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530953 /*TODO: Findout vif properly */
954 struct ath6kl_vif *vif = ar->vif;
Kalle Valobdcd8172011-07-18 00:22:30 +0300955
Jouni Malinen82e14f52011-09-19 19:15:05 +0300956 if (len <= sizeof(struct wmi_bss_info_hdr2))
Kalle Valobdcd8172011-07-18 00:22:30 +0300957 return -EINVAL;
958
Jouni Malinen82e14f52011-09-19 19:15:05 +0300959 bih = (struct wmi_bss_info_hdr2 *) datap;
960 buf = datap + sizeof(struct wmi_bss_info_hdr2);
961 len -= sizeof(struct wmi_bss_info_hdr2);
Kalle Valobdcd8172011-07-18 00:22:30 +0300962
963 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300964 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
965 "frame_type=%d\n",
Jouni Malinen82e14f52011-09-19 19:15:05 +0300966 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300967 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +0300968
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300969 if (bih->frame_type != BEACON_FTYPE &&
970 bih->frame_type != PROBERESP_FTYPE)
971 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +0300972
Jouni Malinen551185c2011-09-19 19:15:06 +0300973 if (bih->frame_type == BEACON_FTYPE &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530974 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
975 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Jouni Malinen551185c2011-09-19 19:15:06 +0300976 ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0);
977 }
978
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530979 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300980 if (channel == NULL)
981 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300982
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300983 if (len < 8 + 2 + 2)
984 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300985
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530986 if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &vif->flags)
987 && memcmp(bih->bssid, ar->bssid, ETH_ALEN) == 0) {
Jouni Malinen32c10872011-09-19 19:15:07 +0300988 const u8 *tim;
989 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
990 len - 8 - 2 - 2);
991 if (tim && tim[1] >= 2) {
992 ar->assoc_bss_dtim_period = tim[3];
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530993 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +0300994 }
995 }
996
Kalle Valobdcd8172011-07-18 00:22:30 +0300997 /*
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300998 * In theory, use of cfg80211_inform_bss() would be more natural here
999 * since we do not have the full frame. However, at least for now,
1000 * cfg80211 can only distinguish Beacon and Probe Response frames from
1001 * each other when using cfg80211_inform_bss_frame(), so let's build a
1002 * fake IEEE 802.11 header to be able to take benefit of this.
Kalle Valobdcd8172011-07-18 00:22:30 +03001003 */
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001004 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1005 if (mgmt == NULL)
1006 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001007
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001008 if (bih->frame_type == BEACON_FTYPE) {
1009 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1010 IEEE80211_STYPE_BEACON);
1011 memset(mgmt->da, 0xff, ETH_ALEN);
1012 } else {
1013 struct net_device *dev = ar->net_dev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001014
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001015 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1016 IEEE80211_STYPE_PROBE_RESP);
1017 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +03001018 }
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001019 mgmt->duration = cpu_to_le16(0);
1020 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1021 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1022 mgmt->seq_ctrl = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001023
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001024 memcpy(&mgmt->u.beacon, buf, len);
1025
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301026 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
Jouni Malinen82e14f52011-09-19 19:15:05 +03001027 24 + len, (bih->snr - 95) * 100,
1028 GFP_ATOMIC);
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001029 kfree(mgmt);
1030 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +03001031 return -ENOMEM;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001032 cfg80211_put_bss(bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001033
1034 return 0;
1035}
1036
Kalle Valobdcd8172011-07-18 00:22:30 +03001037/* Inactivity timeout of a fatpipe(pstream) at the target */
1038static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1039 int len)
1040{
1041 struct wmi_pstream_timeout_event *ev;
1042
1043 if (len < sizeof(struct wmi_pstream_timeout_event))
1044 return -EINVAL;
1045
1046 ev = (struct wmi_pstream_timeout_event *) datap;
1047
1048 /*
1049 * When the pstream (fat pipe == AC) timesout, it means there were
1050 * no thinStreams within this pstream & it got implicitly created
1051 * due to data flow on this AC. We start the inactivity timer only
1052 * for implicitly created pstream. Just reset the host state.
1053 */
1054 spin_lock_bh(&wmi->lock);
1055 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1056 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1057 spin_unlock_bh(&wmi->lock);
1058
1059 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1060 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1061
1062 return 0;
1063}
1064
1065static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1066{
1067 struct wmi_bit_rate_reply *reply;
1068 s32 rate;
1069 u32 sgi, index;
1070
1071 if (len < sizeof(struct wmi_bit_rate_reply))
1072 return -EINVAL;
1073
1074 reply = (struct wmi_bit_rate_reply *) datap;
1075
1076 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1077
1078 if (reply->rate_index == (s8) RATE_AUTO) {
1079 rate = RATE_AUTO;
1080 } else {
1081 index = reply->rate_index & 0x7f;
1082 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1083 rate = wmi_rate_tbl[index][sgi];
1084 }
1085
1086 ath6kl_wakeup_event(wmi->parent_dev);
1087
1088 return 0;
1089}
1090
Kalle Valo003353b0d2011-09-01 10:14:21 +03001091static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
1092{
1093 ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
1094
1095 return 0;
1096}
1097
Kalle Valobdcd8172011-07-18 00:22:30 +03001098static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1099{
1100 if (len < sizeof(struct wmi_fix_rates_reply))
1101 return -EINVAL;
1102
1103 ath6kl_wakeup_event(wmi->parent_dev);
1104
1105 return 0;
1106}
1107
1108static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1109{
1110 if (len < sizeof(struct wmi_channel_list_reply))
1111 return -EINVAL;
1112
1113 ath6kl_wakeup_event(wmi->parent_dev);
1114
1115 return 0;
1116}
1117
1118static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1119{
1120 struct wmi_tx_pwr_reply *reply;
1121
1122 if (len < sizeof(struct wmi_tx_pwr_reply))
1123 return -EINVAL;
1124
1125 reply = (struct wmi_tx_pwr_reply *) datap;
1126 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1127
1128 return 0;
1129}
1130
1131static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1132{
1133 if (len < sizeof(struct wmi_get_keepalive_cmd))
1134 return -EINVAL;
1135
1136 ath6kl_wakeup_event(wmi->parent_dev);
1137
1138 return 0;
1139}
1140
1141static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
1142{
1143 struct wmi_scan_complete_event *ev;
1144
1145 ev = (struct wmi_scan_complete_event *) datap;
1146
Kalle Valobdcd8172011-07-18 00:22:30 +03001147 ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
1148 wmi->is_probe_ssid = false;
1149
1150 return 0;
1151}
1152
Jouni Malinen86512132011-09-21 16:57:29 +03001153static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
1154 int len)
1155{
1156 struct wmi_neighbor_report_event *ev;
1157 u8 i;
1158
1159 if (len < sizeof(*ev))
1160 return -EINVAL;
1161 ev = (struct wmi_neighbor_report_event *) datap;
1162 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1163 > len) {
1164 ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
1165 "(num=%d len=%d)\n", ev->num_neighbors, len);
1166 return -EINVAL;
1167 }
1168 for (i = 0; i < ev->num_neighbors; i++) {
1169 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1170 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1171 ev->neighbor[i].bss_flags);
1172 cfg80211_pmksa_candidate_notify(wmi->parent_dev->net_dev, i,
1173 ev->neighbor[i].bssid,
1174 !!(ev->neighbor[i].bss_flags &
1175 WMI_PREAUTH_CAPABLE_BSS),
1176 GFP_ATOMIC);
1177 }
1178
1179 return 0;
1180}
1181
Kalle Valobdcd8172011-07-18 00:22:30 +03001182/*
1183 * Target is reporting a programming error. This is for
1184 * developer aid only. Target only checks a few common violations
1185 * and it is responsibility of host to do all error checking.
1186 * Behavior of target after wmi error event is undefined.
1187 * A reset is recommended.
1188 */
1189static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1190{
1191 const char *type = "unknown error";
1192 struct wmi_cmd_error_event *ev;
1193 ev = (struct wmi_cmd_error_event *) datap;
1194
1195 switch (ev->err_code) {
1196 case INVALID_PARAM:
1197 type = "invalid parameter";
1198 break;
1199 case ILLEGAL_STATE:
1200 type = "invalid state";
1201 break;
1202 case INTERNAL_ERROR:
1203 type = "internal error";
1204 break;
1205 }
1206
1207 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1208 ev->cmd_id, type);
1209
1210 return 0;
1211}
1212
1213static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
1214{
1215 ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
1216
1217 return 0;
1218}
1219
1220static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1221 struct sq_threshold_params *sq_thresh,
1222 u32 size)
1223{
1224 u32 index;
1225 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1226
1227 /* The list is already in sorted order. Get the next lower value */
1228 for (index = 0; index < size; index++) {
1229 if (rssi < sq_thresh->upper_threshold[index]) {
1230 threshold = (u8) sq_thresh->upper_threshold[index];
1231 break;
1232 }
1233 }
1234
1235 return threshold;
1236}
1237
1238static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1239 struct sq_threshold_params *sq_thresh,
1240 u32 size)
1241{
1242 u32 index;
1243 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1244
1245 /* The list is already in sorted order. Get the next lower value */
1246 for (index = 0; index < size; index++) {
1247 if (rssi > sq_thresh->lower_threshold[index]) {
1248 threshold = (u8) sq_thresh->lower_threshold[index];
1249 break;
1250 }
1251 }
1252
1253 return threshold;
1254}
1255
1256static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1257 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1258{
1259 struct sk_buff *skb;
1260 struct wmi_rssi_threshold_params_cmd *cmd;
1261
1262 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1263 if (!skb)
1264 return -ENOMEM;
1265
1266 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1267 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1268
1269 return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1270 NO_SYNC_WMIFLAG);
1271}
1272
1273static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1274 int len)
1275{
1276 struct wmi_rssi_threshold_event *reply;
1277 struct wmi_rssi_threshold_params_cmd cmd;
1278 struct sq_threshold_params *sq_thresh;
1279 enum wmi_rssi_threshold_val new_threshold;
1280 u8 upper_rssi_threshold, lower_rssi_threshold;
1281 s16 rssi;
1282 int ret;
1283
1284 if (len < sizeof(struct wmi_rssi_threshold_event))
1285 return -EINVAL;
1286
1287 reply = (struct wmi_rssi_threshold_event *) datap;
1288 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1289 rssi = a_sle16_to_cpu(reply->rssi);
1290
1291 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1292
1293 /*
1294 * Identify the threshold breached and communicate that to the app.
1295 * After that install a new set of thresholds based on the signal
1296 * quality reported by the target
1297 */
1298 if (new_threshold) {
1299 /* Upper threshold breached */
1300 if (rssi < sq_thresh->upper_threshold[0]) {
1301 ath6kl_dbg(ATH6KL_DBG_WMI,
1302 "spurious upper rssi threshold event: %d\n",
1303 rssi);
1304 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1305 (rssi >= sq_thresh->upper_threshold[0])) {
1306 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1307 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1308 (rssi >= sq_thresh->upper_threshold[1])) {
1309 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1310 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1311 (rssi >= sq_thresh->upper_threshold[2])) {
1312 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1313 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1314 (rssi >= sq_thresh->upper_threshold[3])) {
1315 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1316 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1317 (rssi >= sq_thresh->upper_threshold[4])) {
1318 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1319 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1320 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1321 }
1322 } else {
1323 /* Lower threshold breached */
1324 if (rssi > sq_thresh->lower_threshold[0]) {
1325 ath6kl_dbg(ATH6KL_DBG_WMI,
1326 "spurious lower rssi threshold event: %d %d\n",
1327 rssi, sq_thresh->lower_threshold[0]);
1328 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1329 (rssi <= sq_thresh->lower_threshold[0])) {
1330 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1331 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1332 (rssi <= sq_thresh->lower_threshold[1])) {
1333 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1334 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1335 (rssi <= sq_thresh->lower_threshold[2])) {
1336 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1337 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1338 (rssi <= sq_thresh->lower_threshold[3])) {
1339 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1340 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1341 (rssi <= sq_thresh->lower_threshold[4])) {
1342 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1343 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1344 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1345 }
1346 }
1347
1348 /* Calculate and install the next set of thresholds */
1349 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1350 sq_thresh->lower_threshold_valid_count);
1351 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1352 sq_thresh->upper_threshold_valid_count);
1353
1354 /* Issue a wmi command to install the thresholds */
1355 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1356 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1357 cmd.weight = sq_thresh->weight;
1358 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1359
1360 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1361 if (ret) {
1362 ath6kl_err("unable to configure rssi thresholds\n");
1363 return -EIO;
1364 }
1365
1366 return 0;
1367}
1368
1369static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
1370{
1371 struct wmi_cac_event *reply;
1372 struct ieee80211_tspec_ie *ts;
1373 u16 active_tsids, tsinfo;
1374 u8 tsid, index;
1375 u8 ts_id;
1376
1377 if (len < sizeof(struct wmi_cac_event))
1378 return -EINVAL;
1379
1380 reply = (struct wmi_cac_event *) datap;
1381
1382 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1383 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1384
1385 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1386 tsinfo = le16_to_cpu(ts->tsinfo);
1387 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1388 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1389
1390 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
1391 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1392 /*
1393 * Following assumes that there is only one outstanding
1394 * ADDTS request when this event is received
1395 */
1396 spin_lock_bh(&wmi->lock);
1397 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1398 spin_unlock_bh(&wmi->lock);
1399
1400 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1401 if ((active_tsids >> index) & 1)
1402 break;
1403 }
1404 if (index < (sizeof(active_tsids) * 8))
1405 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
1406 }
1407
1408 /*
1409 * Clear active tsids and Add missing handling
1410 * for delete qos stream from AP
1411 */
1412 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1413
1414 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1415 tsinfo = le16_to_cpu(ts->tsinfo);
1416 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1417 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1418
1419 spin_lock_bh(&wmi->lock);
1420 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1421 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1422 spin_unlock_bh(&wmi->lock);
1423
1424 /* Indicate stream inactivity to driver layer only if all tsids
1425 * within this AC are deleted.
1426 */
1427 if (!active_tsids) {
1428 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1429 false);
1430 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1431 }
1432 }
1433
1434 return 0;
1435}
1436
1437static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1438 struct wmi_snr_threshold_params_cmd *snr_cmd)
1439{
1440 struct sk_buff *skb;
1441 struct wmi_snr_threshold_params_cmd *cmd;
1442
1443 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1444 if (!skb)
1445 return -ENOMEM;
1446
1447 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1448 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1449
1450 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1451 NO_SYNC_WMIFLAG);
1452}
1453
1454static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1455 int len)
1456{
1457 struct wmi_snr_threshold_event *reply;
1458 struct sq_threshold_params *sq_thresh;
1459 struct wmi_snr_threshold_params_cmd cmd;
1460 enum wmi_snr_threshold_val new_threshold;
1461 u8 upper_snr_threshold, lower_snr_threshold;
1462 s16 snr;
1463 int ret;
1464
1465 if (len < sizeof(struct wmi_snr_threshold_event))
1466 return -EINVAL;
1467
1468 reply = (struct wmi_snr_threshold_event *) datap;
1469
1470 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1471 snr = reply->snr;
1472
1473 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1474
1475 /*
1476 * Identify the threshold breached and communicate that to the app.
1477 * After that install a new set of thresholds based on the signal
1478 * quality reported by the target.
1479 */
1480 if (new_threshold) {
1481 /* Upper threshold breached */
1482 if (snr < sq_thresh->upper_threshold[0]) {
1483 ath6kl_dbg(ATH6KL_DBG_WMI,
1484 "spurious upper snr threshold event: %d\n",
1485 snr);
1486 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1487 (snr >= sq_thresh->upper_threshold[0])) {
1488 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1489 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1490 (snr >= sq_thresh->upper_threshold[1])) {
1491 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1492 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1493 (snr >= sq_thresh->upper_threshold[2])) {
1494 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1495 } else if (snr >= sq_thresh->upper_threshold[3]) {
1496 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1497 }
1498 } else {
1499 /* Lower threshold breached */
1500 if (snr > sq_thresh->lower_threshold[0]) {
1501 ath6kl_dbg(ATH6KL_DBG_WMI,
1502 "spurious lower snr threshold event: %d\n",
1503 sq_thresh->lower_threshold[0]);
1504 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1505 (snr <= sq_thresh->lower_threshold[0])) {
1506 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1507 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1508 (snr <= sq_thresh->lower_threshold[1])) {
1509 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1510 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1511 (snr <= sq_thresh->lower_threshold[2])) {
1512 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1513 } else if (snr <= sq_thresh->lower_threshold[3]) {
1514 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1515 }
1516 }
1517
1518 /* Calculate and install the next set of thresholds */
1519 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1520 sq_thresh->lower_threshold_valid_count);
1521 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1522 sq_thresh->upper_threshold_valid_count);
1523
1524 /* Issue a wmi command to install the thresholds */
1525 cmd.thresh_above1_val = upper_snr_threshold;
1526 cmd.thresh_below1_val = lower_snr_threshold;
1527 cmd.weight = sq_thresh->weight;
1528 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1529
1530 ath6kl_dbg(ATH6KL_DBG_WMI,
1531 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1532 snr, new_threshold,
1533 lower_snr_threshold, upper_snr_threshold);
1534
1535 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1536 if (ret) {
1537 ath6kl_err("unable to configure snr threshold\n");
1538 return -EIO;
1539 }
1540
1541 return 0;
1542}
1543
1544static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1545{
1546 u16 ap_info_entry_size;
1547 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1548 struct wmi_ap_info_v1 *ap_info_v1;
1549 u8 index;
1550
1551 if (len < sizeof(struct wmi_aplist_event) ||
1552 ev->ap_list_ver != APLIST_VER1)
1553 return -EINVAL;
1554
1555 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1556 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1557
1558 ath6kl_dbg(ATH6KL_DBG_WMI,
1559 "number of APs in aplist event: %d\n", ev->num_ap);
1560
1561 if (len < (int) (sizeof(struct wmi_aplist_event) +
1562 (ev->num_ap - 1) * ap_info_entry_size))
1563 return -EINVAL;
1564
1565 /* AP list version 1 contents */
1566 for (index = 0; index < ev->num_ap; index++) {
1567 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1568 index, ap_info_v1->bssid, ap_info_v1->channel);
1569 ap_info_v1++;
1570 }
1571
1572 return 0;
1573}
1574
1575int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
1576 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1577{
1578 struct wmi_cmd_hdr *cmd_hdr;
1579 enum htc_endpoint_id ep_id = wmi->ep_id;
1580 int ret;
1581
1582 if (WARN_ON(skb == NULL))
1583 return -EINVAL;
1584
Kalle Valob9b6ee62011-09-27 14:31:21 +03001585 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1586 cmd_id, skb->len, sync_flag);
1587 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1588 skb->data, skb->len);
1589
Kalle Valobdcd8172011-07-18 00:22:30 +03001590 if (sync_flag >= END_WMIFLAG) {
1591 dev_kfree_skb(skb);
1592 return -EINVAL;
1593 }
1594
1595 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1596 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1597 /*
1598 * Make sure all data currently queued is transmitted before
1599 * the cmd execution. Establish a new sync point.
1600 */
1601 ath6kl_wmi_sync_point(wmi);
1602 }
1603
1604 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1605
1606 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1607 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1608 cmd_hdr->info1 = 0; /* added for virtual interface */
1609
1610 /* Only for OPT_TX_CMD, use BE endpoint. */
1611 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1612 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1613 false, false, 0, NULL);
1614 if (ret) {
1615 dev_kfree_skb(skb);
1616 return ret;
1617 }
1618 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1619 }
1620
1621 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1622
1623 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1624 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1625 /*
1626 * Make sure all new data queued waits for the command to
1627 * execute. Establish a new sync point.
1628 */
1629 ath6kl_wmi_sync_point(wmi);
1630 }
1631
1632 return 0;
1633}
1634
1635int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
1636 enum dot11_auth_mode dot11_auth_mode,
1637 enum auth_mode auth_mode,
1638 enum crypto_type pairwise_crypto,
1639 u8 pairwise_crypto_len,
1640 enum crypto_type group_crypto,
1641 u8 group_crypto_len, int ssid_len, u8 *ssid,
1642 u8 *bssid, u16 channel, u32 ctrl_flags)
1643{
1644 struct sk_buff *skb;
1645 struct wmi_connect_cmd *cc;
1646 int ret;
1647
Kalle Valob9b6ee62011-09-27 14:31:21 +03001648 ath6kl_dbg(ATH6KL_DBG_WMI,
1649 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1650 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1651 bssid, channel, ctrl_flags, ssid_len, nw_type,
1652 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1653 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1654
Kalle Valobdcd8172011-07-18 00:22:30 +03001655 wmi->traffic_class = 100;
1656
1657 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1658 return -EINVAL;
1659
1660 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1661 return -EINVAL;
1662
1663 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1664 if (!skb)
1665 return -ENOMEM;
1666
1667 cc = (struct wmi_connect_cmd *) skb->data;
1668
1669 if (ssid_len)
1670 memcpy(cc->ssid, ssid, ssid_len);
1671
1672 cc->ssid_len = ssid_len;
1673 cc->nw_type = nw_type;
1674 cc->dot11_auth_mode = dot11_auth_mode;
1675 cc->auth_mode = auth_mode;
1676 cc->prwise_crypto_type = pairwise_crypto;
1677 cc->prwise_crypto_len = pairwise_crypto_len;
1678 cc->grp_crypto_type = group_crypto;
1679 cc->grp_crypto_len = group_crypto_len;
1680 cc->ch = cpu_to_le16(channel);
1681 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1682
1683 if (bssid != NULL)
1684 memcpy(cc->bssid, bssid, ETH_ALEN);
1685
Kalle Valobdcd8172011-07-18 00:22:30 +03001686 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
1687
1688 return ret;
1689}
1690
1691int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
1692{
1693 struct sk_buff *skb;
1694 struct wmi_reconnect_cmd *cc;
1695 int ret;
1696
Kalle Valob9b6ee62011-09-27 14:31:21 +03001697 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1698 bssid, channel);
1699
Kalle Valobdcd8172011-07-18 00:22:30 +03001700 wmi->traffic_class = 100;
1701
1702 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1703 if (!skb)
1704 return -ENOMEM;
1705
1706 cc = (struct wmi_reconnect_cmd *) skb->data;
1707 cc->channel = cpu_to_le16(channel);
1708
1709 if (bssid != NULL)
1710 memcpy(cc->bssid, bssid, ETH_ALEN);
1711
1712 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
1713 NO_SYNC_WMIFLAG);
1714
1715 return ret;
1716}
1717
1718int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
1719{
1720 int ret;
1721
Kalle Valob9b6ee62011-09-27 14:31:21 +03001722 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1723
Kalle Valobdcd8172011-07-18 00:22:30 +03001724 wmi->traffic_class = 100;
1725
1726 /* Disconnect command does not need to do a SYNC before. */
1727 ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
1728
1729 return ret;
1730}
1731
1732int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
1733 u32 force_fgscan, u32 is_legacy,
1734 u32 home_dwell_time, u32 force_scan_interval,
1735 s8 num_chan, u16 *ch_list)
1736{
1737 struct sk_buff *skb;
1738 struct wmi_start_scan_cmd *sc;
1739 s8 size;
Edward Lu1276c9e2011-08-30 21:58:00 +03001740 int i, ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03001741
1742 size = sizeof(struct wmi_start_scan_cmd);
1743
1744 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1745 return -EINVAL;
1746
1747 if (num_chan > WMI_MAX_CHANNELS)
1748 return -EINVAL;
1749
1750 if (num_chan)
1751 size += sizeof(u16) * (num_chan - 1);
1752
1753 skb = ath6kl_wmi_get_new_buf(size);
1754 if (!skb)
1755 return -ENOMEM;
1756
1757 sc = (struct wmi_start_scan_cmd *) skb->data;
1758 sc->scan_type = scan_type;
1759 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1760 sc->is_legacy = cpu_to_le32(is_legacy);
1761 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1762 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1763 sc->num_ch = num_chan;
1764
Edward Lu1276c9e2011-08-30 21:58:00 +03001765 for (i = 0; i < num_chan; i++)
1766 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001767
1768 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
1769 NO_SYNC_WMIFLAG);
1770
1771 return ret;
1772}
1773
1774int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
1775 u16 fg_end_sec, u16 bg_sec,
1776 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1777 u16 pas_chdw_msec, u8 short_scan_ratio,
1778 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1779 u16 maxact_scan_per_ssid)
1780{
1781 struct sk_buff *skb;
1782 struct wmi_scan_params_cmd *sc;
1783 int ret;
1784
1785 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1786 if (!skb)
1787 return -ENOMEM;
1788
1789 sc = (struct wmi_scan_params_cmd *) skb->data;
1790 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1791 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1792 sc->bg_period = cpu_to_le16(bg_sec);
1793 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1794 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1795 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1796 sc->short_scan_ratio = short_scan_ratio;
1797 sc->scan_ctrl_flags = scan_ctrl_flag;
1798 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1799 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1800
1801 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
1802 NO_SYNC_WMIFLAG);
1803 return ret;
1804}
1805
1806int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
1807{
1808 struct sk_buff *skb;
1809 struct wmi_bss_filter_cmd *cmd;
1810 int ret;
1811
1812 if (filter >= LAST_BSS_FILTER)
1813 return -EINVAL;
1814
1815 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1816 if (!skb)
1817 return -ENOMEM;
1818
1819 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1820 cmd->bss_filter = filter;
1821 cmd->ie_mask = cpu_to_le32(ie_mask);
1822
1823 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
1824 NO_SYNC_WMIFLAG);
1825 return ret;
1826}
1827
1828int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
1829 u8 ssid_len, u8 *ssid)
1830{
1831 struct sk_buff *skb;
1832 struct wmi_probed_ssid_cmd *cmd;
1833 int ret;
1834
1835 if (index > MAX_PROBED_SSID_INDEX)
1836 return -EINVAL;
1837
1838 if (ssid_len > sizeof(cmd->ssid))
1839 return -EINVAL;
1840
1841 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1842 return -EINVAL;
1843
1844 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1845 return -EINVAL;
1846
1847 if (flag & SPECIFIC_SSID_FLAG)
1848 wmi->is_probe_ssid = true;
1849
1850 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1851 if (!skb)
1852 return -ENOMEM;
1853
1854 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1855 cmd->entry_index = index;
1856 cmd->flag = flag;
1857 cmd->ssid_len = ssid_len;
1858 memcpy(cmd->ssid, ssid, ssid_len);
1859
1860 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
1861 NO_SYNC_WMIFLAG);
1862 return ret;
1863}
1864
1865int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
1866 u16 listen_beacons)
1867{
1868 struct sk_buff *skb;
1869 struct wmi_listen_int_cmd *cmd;
1870 int ret;
1871
1872 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1873 if (!skb)
1874 return -ENOMEM;
1875
1876 cmd = (struct wmi_listen_int_cmd *) skb->data;
1877 cmd->listen_intvl = cpu_to_le16(listen_interval);
1878 cmd->num_beacons = cpu_to_le16(listen_beacons);
1879
1880 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
1881 NO_SYNC_WMIFLAG);
1882 return ret;
1883}
1884
1885int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
1886{
1887 struct sk_buff *skb;
1888 struct wmi_power_mode_cmd *cmd;
1889 int ret;
1890
1891 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1892 if (!skb)
1893 return -ENOMEM;
1894
1895 cmd = (struct wmi_power_mode_cmd *) skb->data;
1896 cmd->pwr_mode = pwr_mode;
1897 wmi->pwr_mode = pwr_mode;
1898
1899 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
1900 NO_SYNC_WMIFLAG);
1901 return ret;
1902}
1903
1904int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
1905 u16 ps_poll_num, u16 dtim_policy,
1906 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1907 u16 ps_fail_event_policy)
1908{
1909 struct sk_buff *skb;
1910 struct wmi_power_params_cmd *pm;
1911 int ret;
1912
1913 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1914 if (!skb)
1915 return -ENOMEM;
1916
1917 pm = (struct wmi_power_params_cmd *)skb->data;
1918 pm->idle_period = cpu_to_le16(idle_period);
1919 pm->pspoll_number = cpu_to_le16(ps_poll_num);
1920 pm->dtim_policy = cpu_to_le16(dtim_policy);
1921 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1922 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1923 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1924
1925 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
1926 NO_SYNC_WMIFLAG);
1927 return ret;
1928}
1929
1930int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
1931{
1932 struct sk_buff *skb;
1933 struct wmi_disc_timeout_cmd *cmd;
1934 int ret;
1935
1936 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1937 if (!skb)
1938 return -ENOMEM;
1939
1940 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
1941 cmd->discon_timeout = timeout;
1942
1943 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
1944 NO_SYNC_WMIFLAG);
Jouni Malinenff0b0072011-10-11 17:31:56 +03001945 if (ret == 0)
1946 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
Kalle Valobdcd8172011-07-18 00:22:30 +03001947 return ret;
1948}
1949
1950int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
1951 enum crypto_type key_type,
1952 u8 key_usage, u8 key_len,
1953 u8 *key_rsc, u8 *key_material,
1954 u8 key_op_ctrl, u8 *mac_addr,
1955 enum wmi_sync_flag sync_flag)
1956{
1957 struct sk_buff *skb;
1958 struct wmi_add_cipher_key_cmd *cmd;
1959 int ret;
1960
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001961 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
1962 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
1963 key_index, key_type, key_usage, key_len, key_op_ctrl);
1964
Kalle Valobdcd8172011-07-18 00:22:30 +03001965 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
1966 (key_material == NULL))
1967 return -EINVAL;
1968
1969 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
1970 return -EINVAL;
1971
1972 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1973 if (!skb)
1974 return -ENOMEM;
1975
1976 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
1977 cmd->key_index = key_index;
1978 cmd->key_type = key_type;
1979 cmd->key_usage = key_usage;
1980 cmd->key_len = key_len;
1981 memcpy(cmd->key, key_material, key_len);
1982
1983 if (key_rsc != NULL)
1984 memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
1985
1986 cmd->key_op_ctrl = key_op_ctrl;
1987
1988 if (mac_addr)
1989 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
1990
1991 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
1992 sync_flag);
1993
1994 return ret;
1995}
1996
1997int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
1998{
1999 struct sk_buff *skb;
2000 struct wmi_add_krk_cmd *cmd;
2001 int ret;
2002
2003 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2004 if (!skb)
2005 return -ENOMEM;
2006
2007 cmd = (struct wmi_add_krk_cmd *) skb->data;
2008 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2009
2010 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
2011
2012 return ret;
2013}
2014
2015int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
2016{
2017 struct sk_buff *skb;
2018 struct wmi_delete_cipher_key_cmd *cmd;
2019 int ret;
2020
2021 if (key_index > WMI_MAX_KEY_INDEX)
2022 return -EINVAL;
2023
2024 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2025 if (!skb)
2026 return -ENOMEM;
2027
2028 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2029 cmd->key_index = key_index;
2030
2031 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
2032 NO_SYNC_WMIFLAG);
2033
2034 return ret;
2035}
2036
2037int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
2038 const u8 *pmkid, bool set)
2039{
2040 struct sk_buff *skb;
2041 struct wmi_setpmkid_cmd *cmd;
2042 int ret;
2043
2044 if (bssid == NULL)
2045 return -EINVAL;
2046
2047 if (set && pmkid == NULL)
2048 return -EINVAL;
2049
2050 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2051 if (!skb)
2052 return -ENOMEM;
2053
2054 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2055 memcpy(cmd->bssid, bssid, ETH_ALEN);
2056 if (set) {
2057 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2058 cmd->enable = PMKID_ENABLE;
2059 } else {
2060 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2061 cmd->enable = PMKID_DISABLE;
2062 }
2063
2064 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
2065 NO_SYNC_WMIFLAG);
2066
2067 return ret;
2068}
2069
2070static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2071 enum htc_endpoint_id ep_id)
2072{
2073 struct wmi_data_hdr *data_hdr;
2074 int ret;
2075
2076 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2077 return -EINVAL;
2078
2079 skb_push(skb, sizeof(struct wmi_data_hdr));
2080
2081 data_hdr = (struct wmi_data_hdr *) skb->data;
2082 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2083 data_hdr->info3 = 0;
2084
2085 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2086
2087 return ret;
2088}
2089
2090static int ath6kl_wmi_sync_point(struct wmi *wmi)
2091{
2092 struct sk_buff *skb;
2093 struct wmi_sync_cmd *cmd;
2094 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2095 enum htc_endpoint_id ep_id;
2096 u8 index, num_pri_streams = 0;
2097 int ret = 0;
2098
2099 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2100
2101 spin_lock_bh(&wmi->lock);
2102
2103 for (index = 0; index < WMM_NUM_AC; index++) {
2104 if (wmi->fat_pipe_exist & (1 << index)) {
2105 num_pri_streams++;
2106 data_sync_bufs[num_pri_streams - 1].traffic_class =
2107 index;
2108 }
2109 }
2110
2111 spin_unlock_bh(&wmi->lock);
2112
2113 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2114 if (!skb) {
2115 ret = -ENOMEM;
2116 goto free_skb;
2117 }
2118
2119 cmd = (struct wmi_sync_cmd *) skb->data;
2120
2121 /*
2122 * In the SYNC cmd sent on the control Ep, send a bitmap
2123 * of the data eps on which the Data Sync will be sent
2124 */
2125 cmd->data_sync_map = wmi->fat_pipe_exist;
2126
2127 for (index = 0; index < num_pri_streams; index++) {
2128 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2129 if (data_sync_bufs[index].skb == NULL) {
2130 ret = -ENOMEM;
2131 break;
2132 }
2133 }
2134
2135 /*
2136 * If buffer allocation for any of the dataSync fails,
2137 * then do not send the Synchronize cmd on the control ep
2138 */
2139 if (ret)
2140 goto free_skb;
2141
2142 /*
2143 * Send sync cmd followed by sync data messages on all
2144 * endpoints being used
2145 */
2146 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
2147 NO_SYNC_WMIFLAG);
2148
2149 if (ret)
2150 goto free_skb;
2151
2152 /* cmd buffer sent, we no longer own it */
2153 skb = NULL;
2154
2155 for (index = 0; index < num_pri_streams; index++) {
2156
2157 if (WARN_ON(!data_sync_bufs[index].skb))
2158 break;
2159
2160 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2161 data_sync_bufs[index].
2162 traffic_class);
2163 ret =
2164 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2165 ep_id);
2166
2167 if (ret)
2168 break;
2169
2170 data_sync_bufs[index].skb = NULL;
2171 }
2172
2173free_skb:
2174 /* free up any resources left over (possibly due to an error) */
2175 if (skb)
2176 dev_kfree_skb(skb);
2177
2178 for (index = 0; index < num_pri_streams; index++) {
2179 if (data_sync_bufs[index].skb != NULL) {
2180 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2181 skb);
2182 }
2183 }
2184
2185 return ret;
2186}
2187
2188int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
2189 struct wmi_create_pstream_cmd *params)
2190{
2191 struct sk_buff *skb;
2192 struct wmi_create_pstream_cmd *cmd;
2193 u8 fatpipe_exist_for_ac = 0;
2194 s32 min_phy = 0;
2195 s32 nominal_phy = 0;
2196 int ret;
2197
2198 if (!((params->user_pri < 8) &&
2199 (params->user_pri <= 0x7) &&
2200 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2201 (params->traffic_direc == UPLINK_TRAFFIC ||
2202 params->traffic_direc == DNLINK_TRAFFIC ||
2203 params->traffic_direc == BIDIR_TRAFFIC) &&
2204 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2205 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2206 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2207 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2208 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2209 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2210 params->tsid <= WMI_MAX_THINSTREAM))) {
2211 return -EINVAL;
2212 }
2213
2214 /*
2215 * Check nominal PHY rate is >= minimalPHY,
2216 * so that DUT can allow TSRS IE
2217 */
2218
2219 /* Get the physical rate (units of bps) */
2220 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2221
2222 /* Check minimal phy < nominal phy rate */
2223 if (params->nominal_phy >= min_phy) {
2224 /* unit of 500 kbps */
2225 nominal_phy = (params->nominal_phy * 1000) / 500;
2226 ath6kl_dbg(ATH6KL_DBG_WMI,
2227 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2228 min_phy, nominal_phy);
2229
2230 params->nominal_phy = nominal_phy;
2231 } else {
2232 params->nominal_phy = 0;
2233 }
2234
2235 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2236 if (!skb)
2237 return -ENOMEM;
2238
2239 ath6kl_dbg(ATH6KL_DBG_WMI,
2240 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2241 params->traffic_class, params->tsid);
2242
2243 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2244 memcpy(cmd, params, sizeof(*cmd));
2245
2246 /* This is an implicitly created Fat pipe */
2247 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2248 spin_lock_bh(&wmi->lock);
2249 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2250 (1 << params->traffic_class));
2251 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2252 spin_unlock_bh(&wmi->lock);
2253 } else {
2254 /* explicitly created thin stream within a fat pipe */
2255 spin_lock_bh(&wmi->lock);
2256 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2257 (1 << params->traffic_class));
2258 wmi->stream_exist_for_ac[params->traffic_class] |=
2259 (1 << params->tsid);
2260 /*
2261 * If a thinstream becomes active, the fat pipe automatically
2262 * becomes active
2263 */
2264 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2265 spin_unlock_bh(&wmi->lock);
2266 }
2267
2268 /*
2269 * Indicate activty change to driver layer only if this is the
2270 * first TSID to get created in this AC explicitly or an implicit
2271 * fat pipe is getting created.
2272 */
2273 if (!fatpipe_exist_for_ac)
2274 ath6kl_indicate_tx_activity(wmi->parent_dev,
2275 params->traffic_class, true);
2276
2277 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
2278 NO_SYNC_WMIFLAG);
2279 return ret;
2280}
2281
2282int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
2283{
2284 struct sk_buff *skb;
2285 struct wmi_delete_pstream_cmd *cmd;
2286 u16 active_tsids = 0;
2287 int ret;
2288
2289 if (traffic_class > 3) {
2290 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2291 return -EINVAL;
2292 }
2293
2294 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2295 if (!skb)
2296 return -ENOMEM;
2297
2298 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2299 cmd->traffic_class = traffic_class;
2300 cmd->tsid = tsid;
2301
2302 spin_lock_bh(&wmi->lock);
2303 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2304 spin_unlock_bh(&wmi->lock);
2305
2306 if (!(active_tsids & (1 << tsid))) {
2307 dev_kfree_skb(skb);
2308 ath6kl_dbg(ATH6KL_DBG_WMI,
2309 "TSID %d doesn't exist for traffic class: %d\n",
2310 tsid, traffic_class);
2311 return -ENODATA;
2312 }
2313
2314 ath6kl_dbg(ATH6KL_DBG_WMI,
2315 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2316 traffic_class, tsid);
2317
2318 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
2319 SYNC_BEFORE_WMIFLAG);
2320
2321 spin_lock_bh(&wmi->lock);
2322 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2323 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2324 spin_unlock_bh(&wmi->lock);
2325
2326 /*
2327 * Indicate stream inactivity to driver layer only if all tsids
2328 * within this AC are deleted.
2329 */
2330 if (!active_tsids) {
2331 ath6kl_indicate_tx_activity(wmi->parent_dev,
2332 traffic_class, false);
2333 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2334 }
2335
2336 return ret;
2337}
2338
2339int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2340{
2341 struct sk_buff *skb;
2342 struct wmi_set_ip_cmd *cmd;
2343 int ret;
2344
2345 /* Multicast address are not valid */
2346 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2347 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2348 return -EINVAL;
2349
2350 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2351 if (!skb)
2352 return -ENOMEM;
2353
2354 cmd = (struct wmi_set_ip_cmd *) skb->data;
2355 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2356
2357 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
2358 return ret;
2359}
2360
2361static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2362 int len)
2363{
2364 if (len < sizeof(struct wmi_get_wow_list_reply))
2365 return -EINVAL;
2366
2367 return 0;
2368}
2369
2370static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2371 enum wmix_command_id cmd_id,
2372 enum wmi_sync_flag sync_flag)
2373{
2374 struct wmix_cmd_hdr *cmd_hdr;
2375 int ret;
2376
2377 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2378
2379 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2380 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2381
2382 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
2383
2384 return ret;
2385}
2386
2387int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2388{
2389 struct sk_buff *skb;
2390 struct wmix_hb_challenge_resp_cmd *cmd;
2391 int ret;
2392
2393 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2394 if (!skb)
2395 return -ENOMEM;
2396
2397 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2398 cmd->cookie = cpu_to_le32(cookie);
2399 cmd->source = cpu_to_le32(source);
2400
2401 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2402 NO_SYNC_WMIFLAG);
2403 return ret;
2404}
2405
Kalle Valo939f1cc2011-09-02 10:32:04 +03002406int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2407{
2408 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2409 struct sk_buff *skb;
2410 int ret;
2411
2412 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2413 if (!skb)
2414 return -ENOMEM;
2415
2416 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2417 cmd->valid = cpu_to_le32(valid);
2418 cmd->config = cpu_to_le32(config);
2419
2420 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2421 NO_SYNC_WMIFLAG);
2422 return ret;
2423}
2424
Kalle Valobdcd8172011-07-18 00:22:30 +03002425int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
2426{
2427 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
2428}
2429
2430int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
2431{
2432 struct sk_buff *skb;
2433 struct wmi_set_tx_pwr_cmd *cmd;
2434 int ret;
2435
2436 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2437 if (!skb)
2438 return -ENOMEM;
2439
2440 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2441 cmd->dbM = dbM;
2442
2443 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
2444 NO_SYNC_WMIFLAG);
2445
2446 return ret;
2447}
2448
2449int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
2450{
2451 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
2452}
2453
Jouni Malinen4b28a802011-10-11 17:31:54 +03002454int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
2455{
2456 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_ROAM_TBL_CMDID);
2457}
2458
Kalle Valobdcd8172011-07-18 00:22:30 +03002459int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
2460{
2461 struct sk_buff *skb;
2462 struct wmi_set_lpreamble_cmd *cmd;
2463 int ret;
2464
2465 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2466 if (!skb)
2467 return -ENOMEM;
2468
2469 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2470 cmd->status = status;
2471 cmd->preamble_policy = preamble_policy;
2472
2473 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
2474 NO_SYNC_WMIFLAG);
2475 return ret;
2476}
2477
2478int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2479{
2480 struct sk_buff *skb;
2481 struct wmi_set_rts_cmd *cmd;
2482 int ret;
2483
2484 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2485 if (!skb)
2486 return -ENOMEM;
2487
2488 cmd = (struct wmi_set_rts_cmd *) skb->data;
2489 cmd->threshold = cpu_to_le16(threshold);
2490
2491 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
2492 return ret;
2493}
2494
2495int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
2496{
2497 struct sk_buff *skb;
2498 struct wmi_set_wmm_txop_cmd *cmd;
2499 int ret;
2500
2501 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2502 return -EINVAL;
2503
2504 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2505 if (!skb)
2506 return -ENOMEM;
2507
2508 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2509 cmd->txop_enable = cfg;
2510
2511 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
2512 NO_SYNC_WMIFLAG);
2513 return ret;
2514}
2515
2516int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
2517{
2518 struct sk_buff *skb;
2519 struct wmi_set_keepalive_cmd *cmd;
2520 int ret;
2521
2522 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2523 if (!skb)
2524 return -ENOMEM;
2525
2526 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2527 cmd->keep_alive_intvl = keep_alive_intvl;
Kalle Valobdcd8172011-07-18 00:22:30 +03002528
2529 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
2530 NO_SYNC_WMIFLAG);
Jouni Malinenff0b0072011-10-11 17:31:56 +03002531 if (ret == 0)
2532 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
Kalle Valobdcd8172011-07-18 00:22:30 +03002533 return ret;
2534}
2535
Kalle Valo003353b0d2011-09-01 10:14:21 +03002536int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2537{
2538 struct sk_buff *skb;
2539 int ret;
2540
2541 skb = ath6kl_wmi_get_new_buf(len);
2542 if (!skb)
2543 return -ENOMEM;
2544
2545 memcpy(skb->data, buf, len);
2546
2547 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
2548
2549 return ret;
2550}
2551
2552
Kalle Valobdcd8172011-07-18 00:22:30 +03002553s32 ath6kl_wmi_get_rate(s8 rate_index)
2554{
2555 if (rate_index == RATE_AUTO)
2556 return 0;
2557
2558 return wmi_rate_tbl[(u32) rate_index][0];
2559}
2560
Kalle Valobdcd8172011-07-18 00:22:30 +03002561static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2562 u32 len)
2563{
2564 struct wmi_pmkid_list_reply *reply;
2565 u32 expected_len;
2566
2567 if (len < sizeof(struct wmi_pmkid_list_reply))
2568 return -EINVAL;
2569
2570 reply = (struct wmi_pmkid_list_reply *)datap;
2571 expected_len = sizeof(reply->num_pmkid) +
2572 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2573
2574 if (len < expected_len)
2575 return -EINVAL;
2576
2577 return 0;
2578}
2579
2580static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2581{
2582 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2583
2584 aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
2585 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2586
2587 return 0;
2588}
2589
2590static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2591{
2592 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2593
2594 aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
2595
2596 return 0;
2597}
2598
2599/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002600
2601int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
2602{
2603 struct sk_buff *skb;
2604 struct wmi_connect_cmd *cm;
2605 int res;
2606
2607 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2608 if (!skb)
2609 return -ENOMEM;
2610
2611 cm = (struct wmi_connect_cmd *) skb->data;
2612 memcpy(cm, p, sizeof(*cm));
2613
2614 res = ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_CONFIG_COMMIT_CMDID,
2615 NO_SYNC_WMIFLAG);
2616 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2617 "ctrl_flags=0x%x-> res=%d\n",
2618 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2619 le32_to_cpu(p->ctrl_flags), res);
2620 return res;
2621}
2622
Jouni Malinen23875132011-08-30 21:57:53 +03002623int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
2624{
2625 struct sk_buff *skb;
2626 struct wmi_ap_set_mlme_cmd *cm;
2627
2628 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2629 if (!skb)
2630 return -ENOMEM;
2631
2632 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2633 memcpy(cm->mac, mac, ETH_ALEN);
2634 cm->reason = cpu_to_le16(reason);
2635 cm->cmd = cmd;
2636
2637 return ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_SET_MLME_CMDID,
2638 NO_SYNC_WMIFLAG);
2639}
2640
Kalle Valobdcd8172011-07-18 00:22:30 +03002641static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
2642{
2643 struct wmi_pspoll_event *ev;
2644
2645 if (len < sizeof(struct wmi_pspoll_event))
2646 return -EINVAL;
2647
2648 ev = (struct wmi_pspoll_event *) datap;
2649
2650 ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
2651
2652 return 0;
2653}
2654
2655static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
2656{
2657 ath6kl_dtimexpiry_event(wmi->parent_dev);
2658
2659 return 0;
2660}
2661
2662int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
2663{
2664 struct sk_buff *skb;
2665 struct wmi_ap_set_pvb_cmd *cmd;
2666 int ret;
2667
2668 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2669 if (!skb)
2670 return -ENOMEM;
2671
2672 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2673 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03002674 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03002675 cmd->flag = cpu_to_le32(flag);
2676
2677 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
2678 NO_SYNC_WMIFLAG);
2679
2680 return 0;
2681}
2682
2683int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
2684 bool rx_dot11_hdr, bool defrag_on_host)
2685{
2686 struct sk_buff *skb;
2687 struct wmi_rx_frame_format_cmd *cmd;
2688 int ret;
2689
2690 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2691 if (!skb)
2692 return -ENOMEM;
2693
2694 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2695 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2696 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2697 cmd->meta_ver = rx_meta_ver;
2698
2699 /* Delete the local aggr state, on host */
2700 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
2701 NO_SYNC_WMIFLAG);
2702
2703 return ret;
2704}
2705
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002706int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
2707 u8 ie_len)
2708{
2709 struct sk_buff *skb;
2710 struct wmi_set_appie_cmd *p;
2711
2712 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2713 if (!skb)
2714 return -ENOMEM;
2715
2716 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2717 "ie_len=%u\n", mgmt_frm_type, ie_len);
2718 p = (struct wmi_set_appie_cmd *) skb->data;
2719 p->mgmt_frm_type = mgmt_frm_type;
2720 p->ie_len = ie_len;
2721 memcpy(p->ie_info, ie, ie_len);
2722 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_APPIE_CMDID,
2723 NO_SYNC_WMIFLAG);
2724}
2725
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002726int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2727{
2728 struct sk_buff *skb;
2729 struct wmi_disable_11b_rates_cmd *cmd;
2730
2731 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2732 if (!skb)
2733 return -ENOMEM;
2734
2735 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2736 disable);
2737 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2738 cmd->disable = disable ? 1 : 0;
2739
2740 return ath6kl_wmi_cmd_send(wmi, skb, WMI_DISABLE_11B_RATES_CMDID,
2741 NO_SYNC_WMIFLAG);
2742}
2743
2744int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
2745{
2746 struct sk_buff *skb;
2747 struct wmi_remain_on_chnl_cmd *p;
2748
2749 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2750 if (!skb)
2751 return -ENOMEM;
2752
2753 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
2754 freq, dur);
2755 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
2756 p->freq = cpu_to_le32(freq);
2757 p->duration = cpu_to_le32(dur);
2758 return ath6kl_wmi_cmd_send(wmi, skb, WMI_REMAIN_ON_CHNL_CMDID,
2759 NO_SYNC_WMIFLAG);
2760}
2761
2762int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
2763 const u8 *data, u16 data_len)
2764{
2765 struct sk_buff *skb;
2766 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03002767 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002768
2769 if (wait)
2770 return -EINVAL; /* Offload for wait not supported */
2771
Jouni Malinena0df5db2011-08-30 21:58:02 +03002772 buf = kmalloc(data_len, GFP_KERNEL);
2773 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002774 return -ENOMEM;
2775
Jouni Malinena0df5db2011-08-30 21:58:02 +03002776 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2777 if (!skb) {
2778 kfree(buf);
2779 return -ENOMEM;
2780 }
2781
2782 kfree(wmi->last_mgmt_tx_frame);
2783 wmi->last_mgmt_tx_frame = buf;
2784 wmi->last_mgmt_tx_frame_len = data_len;
2785
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002786 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
2787 "len=%u\n", id, freq, wait, data_len);
2788 p = (struct wmi_send_action_cmd *) skb->data;
2789 p->id = cpu_to_le32(id);
2790 p->freq = cpu_to_le32(freq);
2791 p->wait = cpu_to_le32(wait);
2792 p->len = cpu_to_le16(data_len);
2793 memcpy(p->data, data, data_len);
2794 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_ACTION_CMDID,
2795 NO_SYNC_WMIFLAG);
2796}
2797
2798int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
2799 const u8 *dst,
2800 const u8 *data, u16 data_len)
2801{
2802 struct sk_buff *skb;
2803 struct wmi_p2p_probe_response_cmd *p;
2804
2805 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2806 if (!skb)
2807 return -ENOMEM;
2808
2809 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
2810 "len=%u\n", freq, dst, data_len);
2811 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
2812 p->freq = cpu_to_le32(freq);
2813 memcpy(p->destination_addr, dst, ETH_ALEN);
2814 p->len = cpu_to_le16(data_len);
2815 memcpy(p->data, data, data_len);
2816 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_PROBE_RESPONSE_CMDID,
2817 NO_SYNC_WMIFLAG);
2818}
2819
2820int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
2821{
2822 struct sk_buff *skb;
2823 struct wmi_probe_req_report_cmd *p;
2824
2825 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2826 if (!skb)
2827 return -ENOMEM;
2828
2829 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
2830 enable);
2831 p = (struct wmi_probe_req_report_cmd *) skb->data;
2832 p->enable = enable ? 1 : 0;
2833 return ath6kl_wmi_cmd_send(wmi, skb, WMI_PROBE_REQ_REPORT_CMDID,
2834 NO_SYNC_WMIFLAG);
2835}
2836
2837int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
2838{
2839 struct sk_buff *skb;
2840 struct wmi_get_p2p_info *p;
2841
2842 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2843 if (!skb)
2844 return -ENOMEM;
2845
2846 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
2847 info_req_flags);
2848 p = (struct wmi_get_p2p_info *) skb->data;
2849 p->info_req_flags = cpu_to_le32(info_req_flags);
2850 return ath6kl_wmi_cmd_send(wmi, skb, WMI_GET_P2P_INFO_CMDID,
2851 NO_SYNC_WMIFLAG);
2852}
2853
2854int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi)
2855{
2856 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
2857 return ath6kl_wmi_simple_cmd(wmi, WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
2858}
2859
Kalle Valobdcd8172011-07-18 00:22:30 +03002860static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
2861{
2862 struct wmix_cmd_hdr *cmd;
2863 u32 len;
2864 u16 id;
2865 u8 *datap;
2866 int ret = 0;
2867
2868 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
2869 ath6kl_err("bad packet 1\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03002870 return -EINVAL;
2871 }
2872
2873 cmd = (struct wmix_cmd_hdr *) skb->data;
2874 id = le32_to_cpu(cmd->cmd_id);
2875
2876 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
2877
2878 datap = skb->data;
2879 len = skb->len;
2880
2881 switch (id) {
2882 case WMIX_HB_CHALLENGE_RESP_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03002883 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03002884 break;
2885 case WMIX_DBGLOG_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03002886 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
Kalle Valobdf53962011-09-02 10:32:04 +03002887 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002888 break;
2889 default:
Kalle Valob9b6ee62011-09-27 14:31:21 +03002890 ath6kl_warn("unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03002891 ret = -EINVAL;
2892 break;
2893 }
2894
2895 return ret;
2896}
2897
Jouni Malinen4b28a802011-10-11 17:31:54 +03002898static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
2899{
2900 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
2901}
2902
Kalle Valobdcd8172011-07-18 00:22:30 +03002903/* Control Path */
2904int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
2905{
2906 struct wmi_cmd_hdr *cmd;
2907 u32 len;
2908 u16 id;
2909 u8 *datap;
2910 int ret = 0;
2911
2912 if (WARN_ON(skb == NULL))
2913 return -EINVAL;
2914
2915 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
2916 ath6kl_err("bad packet 1\n");
2917 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002918 return -EINVAL;
2919 }
2920
2921 cmd = (struct wmi_cmd_hdr *) skb->data;
2922 id = le16_to_cpu(cmd->cmd_id);
2923
2924 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
2925
2926 datap = skb->data;
2927 len = skb->len;
2928
Kalle Valob9b6ee62011-09-27 14:31:21 +03002929 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
2930 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
Kalle Valoef094102011-09-27 14:30:45 +03002931 datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002932
2933 switch (id) {
2934 case WMI_GET_BITRATE_CMDID:
2935 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
2936 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
2937 break;
2938 case WMI_GET_CHANNEL_LIST_CMDID:
2939 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
2940 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
2941 break;
2942 case WMI_GET_TX_PWR_CMDID:
2943 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
2944 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
2945 break;
2946 case WMI_READY_EVENTID:
2947 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
2948 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
2949 break;
2950 case WMI_CONNECT_EVENTID:
2951 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
2952 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
2953 break;
2954 case WMI_DISCONNECT_EVENTID:
2955 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
2956 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
2957 break;
2958 case WMI_PEER_NODE_EVENTID:
2959 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
2960 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
2961 break;
2962 case WMI_TKIP_MICERR_EVENTID:
2963 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
2964 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
2965 break;
2966 case WMI_BSSINFO_EVENTID:
2967 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
Jouni Malinen82e14f52011-09-19 19:15:05 +03002968 ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002969 break;
2970 case WMI_REGDOMAIN_EVENTID:
2971 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05302972 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002973 break;
2974 case WMI_PSTREAM_TIMEOUT_EVENTID:
2975 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
2976 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
2977 break;
2978 case WMI_NEIGHBOR_REPORT_EVENTID:
2979 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
Jouni Malinen86512132011-09-21 16:57:29 +03002980 ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002981 break;
2982 case WMI_SCAN_COMPLETE_EVENTID:
2983 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
2984 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
2985 break;
2986 case WMI_CMDERROR_EVENTID:
2987 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
2988 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
2989 break;
2990 case WMI_REPORT_STATISTICS_EVENTID:
2991 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
2992 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
2993 break;
2994 case WMI_RSSI_THRESHOLD_EVENTID:
2995 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
2996 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
2997 break;
2998 case WMI_ERROR_REPORT_EVENTID:
2999 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3000 break;
3001 case WMI_OPT_RX_FRAME_EVENTID:
3002 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03003003 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03003004 break;
3005 case WMI_REPORT_ROAM_TBL_EVENTID:
3006 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
Jouni Malinen4b28a802011-10-11 17:31:54 +03003007 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003008 break;
3009 case WMI_EXTENSION_EVENTID:
3010 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3011 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3012 break;
3013 case WMI_CAC_EVENTID:
3014 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3015 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
3016 break;
3017 case WMI_CHANNEL_CHANGE_EVENTID:
3018 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3019 break;
3020 case WMI_REPORT_ROAM_DATA_EVENTID:
3021 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3022 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03003023 case WMI_TEST_EVENTID:
3024 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
3025 ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
3026 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003027 case WMI_GET_FIXRATES_CMDID:
3028 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3029 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3030 break;
3031 case WMI_TX_RETRY_ERR_EVENTID:
3032 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3033 break;
3034 case WMI_SNR_THRESHOLD_EVENTID:
3035 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3036 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3037 break;
3038 case WMI_LQ_THRESHOLD_EVENTID:
3039 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3040 break;
3041 case WMI_APLIST_EVENTID:
3042 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3043 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3044 break;
3045 case WMI_GET_KEEPALIVE_CMDID:
3046 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3047 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3048 break;
3049 case WMI_GET_WOW_LIST_EVENTID:
3050 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
3051 ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
3052 break;
3053 case WMI_GET_PMKID_LIST_EVENTID:
3054 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3055 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3056 break;
3057 case WMI_PSPOLL_EVENTID:
3058 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3059 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
3060 break;
3061 case WMI_DTIMEXPIRY_EVENTID:
3062 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3063 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
3064 break;
3065 case WMI_SET_PARAMS_REPLY_EVENTID:
3066 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3067 break;
3068 case WMI_ADDBA_REQ_EVENTID:
3069 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3070 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
3071 break;
3072 case WMI_ADDBA_RESP_EVENTID:
3073 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3074 break;
3075 case WMI_DELBA_REQ_EVENTID:
3076 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3077 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
3078 break;
3079 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3080 ath6kl_dbg(ATH6KL_DBG_WMI,
3081 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3082 break;
3083 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3084 ath6kl_dbg(ATH6KL_DBG_WMI,
3085 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3086 break;
3087 case WMI_TX_COMPLETE_EVENTID:
3088 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3089 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3090 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003091 case WMI_REMAIN_ON_CHNL_EVENTID:
3092 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03003093 ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003094 break;
3095 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3096 ath6kl_dbg(ATH6KL_DBG_WMI,
3097 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03003098 ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3099 len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003100 break;
3101 case WMI_TX_STATUS_EVENTID:
3102 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
Jouni Malinena0df5db2011-08-30 21:58:02 +03003103 ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003104 break;
3105 case WMI_RX_PROBE_REQ_EVENTID:
3106 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
Jouni Malinenae32c302011-08-30 21:58:01 +03003107 ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003108 break;
3109 case WMI_P2P_CAPABILITIES_EVENTID:
3110 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3111 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3112 break;
3113 case WMI_RX_ACTION_EVENTID:
3114 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
Jouni Malinen9809d8e2011-08-30 21:58:03 +03003115 ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003116 break;
3117 case WMI_P2P_INFO_EVENTID:
3118 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3119 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3120 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003121 default:
3122 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03003123 ret = -EINVAL;
3124 break;
3125 }
3126
3127 dev_kfree_skb(skb);
3128
3129 return ret;
3130}
3131
3132static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
3133{
3134 if (!wmi)
3135 return;
3136
3137 spin_lock_bh(&wmi->lock);
3138
3139 wmi->fat_pipe_exist = 0;
3140 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3141
3142 spin_unlock_bh(&wmi->lock);
3143}
3144
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05303145void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03003146{
3147 struct wmi *wmi;
3148
3149 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3150 if (!wmi)
3151 return NULL;
3152
3153 spin_lock_init(&wmi->lock);
3154
3155 wmi->parent_dev = dev;
3156
Kalle Valobdcd8172011-07-18 00:22:30 +03003157 wmi->pwr_mode = REC_POWER;
Kalle Valobdcd8172011-07-18 00:22:30 +03003158
Kalle Valoa7f0c582011-10-05 12:23:05 +03003159 ath6kl_wmi_qos_state_init(wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03003160
3161 return wmi;
3162}
3163
3164void ath6kl_wmi_shutdown(struct wmi *wmi)
3165{
3166 if (!wmi)
3167 return;
3168
Jouni Malinena0df5db2011-08-30 21:58:02 +03003169 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03003170 kfree(wmi);
3171}