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