blob: 79aa90ba9163f2940f2a8f5e7e8ca124b8f400e8 [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
Vasanthakumar Thiagarajan1b2df402012-02-06 20:15:53 +05303 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
Kalle Valobdcd8172011-07-18 00:22:30 +03004 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <linux/ip.h>
19#include "core.h"
20#include "debug.h"
Kalle Valo003353b0d2011-09-01 10:14:21 +030021#include "testmode.h"
Vivek Natarajan06033762011-09-06 13:01:36 +053022#include "../regd.h"
23#include "../regd_common.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030024
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +053025static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +030026
27static const s32 wmi_rate_tbl[][2] = {
28 /* {W/O SGI, with SGI} */
29 {1000, 1000},
30 {2000, 2000},
31 {5500, 5500},
32 {11000, 11000},
33 {6000, 6000},
34 {9000, 9000},
35 {12000, 12000},
36 {18000, 18000},
37 {24000, 24000},
38 {36000, 36000},
39 {48000, 48000},
40 {54000, 54000},
41 {6500, 7200},
42 {13000, 14400},
43 {19500, 21700},
44 {26000, 28900},
45 {39000, 43300},
46 {52000, 57800},
47 {58500, 65000},
48 {65000, 72200},
49 {13500, 15000},
50 {27000, 30000},
51 {40500, 45000},
52 {54000, 60000},
53 {81000, 90000},
54 {108000, 120000},
55 {121500, 135000},
56 {135000, 150000},
57 {0, 0}
58};
59
60/* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
61static const u8 up_to_ac[] = {
62 WMM_AC_BE,
63 WMM_AC_BK,
64 WMM_AC_BK,
65 WMM_AC_BE,
66 WMM_AC_VI,
67 WMM_AC_VI,
68 WMM_AC_VO,
69 WMM_AC_VO,
70};
71
72void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
73{
74 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
75 return;
76
77 wmi->ep_id = ep_id;
78}
79
80enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
81{
82 return wmi->ep_id;
83}
84
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053085struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +053086{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +053087 struct ath6kl_vif *vif, *found = NULL;
88
Kalle Valo71f96ee2011-11-14 19:31:30 +020089 if (WARN_ON(if_idx > (ar->vif_max - 1)))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +053090 return NULL;
91
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +053092 /* FIXME: Locking */
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +053093 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +053094 list_for_each_entry(vif, &ar->vif_list, list) {
95 if (vif->fw_vif_idx == if_idx) {
96 found = vif;
97 break;
98 }
99 }
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530100 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530101
102 return found;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530103}
104
Kalle Valobdcd8172011-07-18 00:22:30 +0300105/* Performs DIX to 802.3 encapsulation for transmit packets.
106 * Assumes the entire DIX header is contigous and that there is
107 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
108 */
109int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
110{
111 struct ath6kl_llc_snap_hdr *llc_hdr;
112 struct ethhdr *eth_hdr;
113 size_t new_len;
114 __be16 type;
115 u8 *datap;
116 u16 size;
117
118 if (WARN_ON(skb == NULL))
119 return -EINVAL;
120
121 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
122 if (skb_headroom(skb) < size)
123 return -ENOMEM;
124
125 eth_hdr = (struct ethhdr *) skb->data;
126 type = eth_hdr->h_proto;
127
128 if (!is_ethertype(be16_to_cpu(type))) {
129 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +0200130 "%s: pkt is already in 802.3 format\n", __func__);
Kalle Valobdcd8172011-07-18 00:22:30 +0300131 return 0;
132 }
133
134 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
135
136 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
137 datap = skb->data;
138
139 eth_hdr->h_proto = cpu_to_be16(new_len);
140
141 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
142
143 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
144 llc_hdr->dsap = 0xAA;
145 llc_hdr->ssap = 0xAA;
146 llc_hdr->cntl = 0x03;
147 llc_hdr->org_code[0] = 0x0;
148 llc_hdr->org_code[1] = 0x0;
149 llc_hdr->org_code[2] = 0x0;
150 llc_hdr->eth_type = type;
151
152 return 0;
153}
154
155static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
156 u8 *version, void *tx_meta_info)
157{
158 struct wmi_tx_meta_v1 *v1;
159 struct wmi_tx_meta_v2 *v2;
160
161 if (WARN_ON(skb == NULL || version == NULL))
162 return -EINVAL;
163
164 switch (*version) {
165 case WMI_META_VERSION_1:
166 skb_push(skb, WMI_MAX_TX_META_SZ);
167 v1 = (struct wmi_tx_meta_v1 *) skb->data;
168 v1->pkt_id = 0;
169 v1->rate_plcy_id = 0;
170 *version = WMI_META_VERSION_1;
171 break;
172 case WMI_META_VERSION_2:
173 skb_push(skb, WMI_MAX_TX_META_SZ);
174 v2 = (struct wmi_tx_meta_v2 *) skb->data;
175 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
176 sizeof(struct wmi_tx_meta_v2));
177 break;
178 }
179
180 return 0;
181}
182
183int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530184 u8 msg_type, u32 flags,
Kalle Valobdcd8172011-07-18 00:22:30 +0300185 enum wmi_data_hdr_data_type data_type,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530186 u8 meta_ver, void *tx_meta_info, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +0300187{
188 struct wmi_data_hdr *data_hdr;
189 int ret;
190
Kalle Valo71f96ee2011-11-14 19:31:30 +0200191 if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
Kalle Valobdcd8172011-07-18 00:22:30 +0300192 return -EINVAL;
193
Vasanthakumar Thiagarajan3ce6ff52011-08-22 20:40:21 +0530194 if (tx_meta_info) {
195 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
196 if (ret)
197 return ret;
198 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300199
200 skb_push(skb, sizeof(struct wmi_data_hdr));
201
202 data_hdr = (struct wmi_data_hdr *)skb->data;
203 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
204
205 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
206 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
207
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530208 if (flags & WMI_DATA_HDR_FLAGS_MORE)
209 data_hdr->info |= WMI_DATA_HDR_MORE;
Kalle Valobdcd8172011-07-18 00:22:30 +0300210
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530211 if (flags & WMI_DATA_HDR_FLAGS_EOSP)
212 data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
213
214 data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
215 data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +0300216
217 return 0;
218}
219
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530220u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
Kalle Valobdcd8172011-07-18 00:22:30 +0300221{
222 struct iphdr *ip_hdr = (struct iphdr *) pkt;
223 u8 ip_pri;
224
225 /*
226 * Determine IPTOS priority
227 *
228 * IP-TOS - 8bits
229 * : DSCP(6-bits) ECN(2-bits)
230 * : DSCP - P2 P1 P0 X X X
231 * where (P2 P1 P0) form 802.1D
232 */
233 ip_pri = ip_hdr->tos >> 5;
234 ip_pri &= 0x7;
235
236 if ((layer2_pri & 0x7) > ip_pri)
237 return (u8) layer2_pri & 0x7;
238 else
239 return ip_pri;
240}
241
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530242u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
243{
244 return up_to_ac[user_priority & 0x7];
245}
246
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530247int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
248 struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +0300249 u32 layer2_priority, bool wmm_enabled,
250 u8 *ac)
251{
252 struct wmi_data_hdr *data_hdr;
253 struct ath6kl_llc_snap_hdr *llc_hdr;
254 struct wmi_create_pstream_cmd cmd;
255 u32 meta_size, hdr_size;
256 u16 ip_type = IP_ETHERTYPE;
257 u8 stream_exist, usr_pri;
258 u8 traffic_class = WMM_AC_BE;
259 u8 *datap;
260
261 if (WARN_ON(skb == NULL))
262 return -EINVAL;
263
264 datap = skb->data;
265 data_hdr = (struct wmi_data_hdr *) datap;
266
267 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
268 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
269
270 if (!wmm_enabled) {
271 /* If WMM is disabled all traffic goes as BE traffic */
272 usr_pri = 0;
273 } else {
274 hdr_size = sizeof(struct ethhdr);
275
276 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
277 sizeof(struct
278 wmi_data_hdr) +
279 meta_size + hdr_size);
280
281 if (llc_hdr->eth_type == htons(ip_type)) {
282 /*
283 * Extract the endpoint info from the TOS field
284 * in the IP header.
285 */
286 usr_pri =
287 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
288 sizeof(struct ath6kl_llc_snap_hdr),
289 layer2_priority);
290 } else
291 usr_pri = layer2_priority & 0x7;
292 }
293
Kalle Valoa7f0c582011-10-05 12:23:05 +0300294 /*
295 * workaround for WMM S5
296 *
297 * FIXME: wmi->traffic_class is always 100 so this test doesn't
298 * make sense
299 */
Kalle Valobdcd8172011-07-18 00:22:30 +0300300 if ((wmi->traffic_class == WMM_AC_VI) &&
301 ((usr_pri == 5) || (usr_pri == 4)))
302 usr_pri = 1;
303
304 /* Convert user priority to traffic class */
305 traffic_class = up_to_ac[usr_pri & 0x7];
306
307 wmi_data_hdr_set_up(data_hdr, usr_pri);
308
309 spin_lock_bh(&wmi->lock);
310 stream_exist = wmi->fat_pipe_exist;
311 spin_unlock_bh(&wmi->lock);
312
313 if (!(stream_exist & (1 << traffic_class))) {
314 memset(&cmd, 0, sizeof(cmd));
315 cmd.traffic_class = traffic_class;
316 cmd.user_pri = usr_pri;
317 cmd.inactivity_int =
318 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
319 /* Implicit streams are created with TSID 0xFF */
320 cmd.tsid = WMI_IMPLICIT_PSTREAM;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530321 ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
Kalle Valobdcd8172011-07-18 00:22:30 +0300322 }
323
324 *ac = traffic_class;
325
326 return 0;
327}
328
329int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
330{
331 struct ieee80211_hdr_3addr *pwh, wh;
332 struct ath6kl_llc_snap_hdr *llc_hdr;
333 struct ethhdr eth_hdr;
334 u32 hdr_size;
335 u8 *datap;
336 __le16 sub_type;
337
338 if (WARN_ON(skb == NULL))
339 return -EINVAL;
340
341 datap = skb->data;
342 pwh = (struct ieee80211_hdr_3addr *) datap;
343
344 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
345
346 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
347
348 /* Strip off the 802.11 header */
349 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
350 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
351 sizeof(u32));
352 skb_pull(skb, hdr_size);
353 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
354 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
355
356 datap = skb->data;
357 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
358
Raja Manic8790cb2011-07-19 19:27:32 +0530359 memset(&eth_hdr, 0, sizeof(eth_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +0300360 eth_hdr.h_proto = llc_hdr->eth_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300361
362 switch ((le16_to_cpu(wh.frame_control)) &
363 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
364 case 0:
365 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
366 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
367 break;
368 case IEEE80211_FCTL_TODS:
369 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
370 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
371 break;
372 case IEEE80211_FCTL_FROMDS:
373 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
374 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
375 break;
376 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
377 break;
378 }
379
380 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
381 skb_push(skb, sizeof(eth_hdr));
382
383 datap = skb->data;
384
385 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
386
387 return 0;
388}
389
390/*
391 * Performs 802.3 to DIX encapsulation for received packets.
392 * Assumes the entire 802.3 header is contigous.
393 */
394int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
395{
396 struct ath6kl_llc_snap_hdr *llc_hdr;
397 struct ethhdr eth_hdr;
398 u8 *datap;
399
400 if (WARN_ON(skb == NULL))
401 return -EINVAL;
402
403 datap = skb->data;
404
405 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
406
407 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
408 eth_hdr.h_proto = llc_hdr->eth_type;
409
410 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
411 datap = skb->data;
412
413 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
414
415 return 0;
416}
417
Kalle Valobdcd8172011-07-18 00:22:30 +0300418static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
419{
420 struct tx_complete_msg_v1 *msg_v1;
421 struct wmi_tx_complete_event *evt;
422 int index;
423 u16 size;
424
425 evt = (struct wmi_tx_complete_event *) datap;
426
427 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
428 evt->num_msg, evt->msg_len, evt->msg_type);
429
Kalle Valobdcd8172011-07-18 00:22:30 +0300430 for (index = 0; index < evt->num_msg; index++) {
431 size = sizeof(struct wmi_tx_complete_event) +
432 (index * sizeof(struct tx_complete_msg_v1));
433 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
434
435 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
436 msg_v1->status, msg_v1->pkt_id,
437 msg_v1->rate_idx, msg_v1->ack_failures);
438 }
439
440 return 0;
441}
442
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300443static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530444 int len, struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300445{
446 struct wmi_remain_on_chnl_event *ev;
447 u32 freq;
448 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300449 struct ieee80211_channel *chan;
450 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen10522612011-10-27 16:00:13 +0300451 u32 id;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300452
453 if (len < sizeof(*ev))
454 return -EINVAL;
455
456 ev = (struct wmi_remain_on_chnl_event *) datap;
457 freq = le32_to_cpu(ev->freq);
458 dur = le32_to_cpu(ev->duration);
459 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
460 freq, dur);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530461 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300462 if (!chan) {
463 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
464 "(freq=%u)\n", freq);
465 return -EINVAL;
466 }
Jouni Malinen10522612011-10-27 16:00:13 +0300467 id = vif->last_roc_id;
468 cfg80211_ready_on_channel(vif->ndev, id, chan, NL80211_CHAN_NO_HT,
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300469 dur, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300470
471 return 0;
472}
473
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300474static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530475 u8 *datap, int len,
476 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300477{
478 struct wmi_cancel_remain_on_chnl_event *ev;
479 u32 freq;
480 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300481 struct ieee80211_channel *chan;
482 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen10522612011-10-27 16:00:13 +0300483 u32 id;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300484
485 if (len < sizeof(*ev))
486 return -EINVAL;
487
488 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
489 freq = le32_to_cpu(ev->freq);
490 dur = le32_to_cpu(ev->duration);
491 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
492 "status=%u\n", freq, dur, ev->status);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530493 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300494 if (!chan) {
495 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
496 "channel (freq=%u)\n", freq);
497 return -EINVAL;
498 }
Jouni Malinen10522612011-10-27 16:00:13 +0300499 if (vif->last_cancel_roc_id &&
500 vif->last_cancel_roc_id + 1 == vif->last_roc_id)
501 id = vif->last_cancel_roc_id; /* event for cancel command */
502 else
503 id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
504 vif->last_cancel_roc_id = 0;
505 cfg80211_remain_on_channel_expired(vif->ndev, id, chan,
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300506 NL80211_CHAN_NO_HT, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300507
508 return 0;
509}
510
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530511static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
512 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300513{
514 struct wmi_tx_status_event *ev;
515 u32 id;
516
517 if (len < sizeof(*ev))
518 return -EINVAL;
519
520 ev = (struct wmi_tx_status_event *) datap;
521 id = le32_to_cpu(ev->id);
522 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
523 id, ev->ack_status);
Jouni Malinena0df5db2011-08-30 21:58:02 +0300524 if (wmi->last_mgmt_tx_frame) {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530525 cfg80211_mgmt_tx_status(vif->ndev, id,
Jouni Malinena0df5db2011-08-30 21:58:02 +0300526 wmi->last_mgmt_tx_frame,
527 wmi->last_mgmt_tx_frame_len,
528 !!ev->ack_status, GFP_ATOMIC);
529 kfree(wmi->last_mgmt_tx_frame);
530 wmi->last_mgmt_tx_frame = NULL;
531 wmi->last_mgmt_tx_frame_len = 0;
532 }
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300533
534 return 0;
535}
536
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530537static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
538 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300539{
540 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300541 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300542 u16 dlen;
543
544 if (len < sizeof(*ev))
545 return -EINVAL;
546
547 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300548 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300549 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300550 if (datap + len < ev->data + dlen) {
551 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
552 "len=%d dlen=%u\n", len, dlen);
553 return -EINVAL;
554 }
555 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
556 "probe_req_report=%d\n",
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530557 dlen, freq, vif->probe_req_report);
Jouni Malinenae32c302011-08-30 21:58:01 +0300558
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530559 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530560 cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300561
562 return 0;
563}
564
565static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
566{
567 struct wmi_p2p_capabilities_event *ev;
568 u16 dlen;
569
570 if (len < sizeof(*ev))
571 return -EINVAL;
572
573 ev = (struct wmi_p2p_capabilities_event *) datap;
574 dlen = le16_to_cpu(ev->len);
575 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
576
577 return 0;
578}
579
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530580static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
581 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300582{
583 struct wmi_rx_action_event *ev;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300584 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300585 u16 dlen;
586
587 if (len < sizeof(*ev))
588 return -EINVAL;
589
590 ev = (struct wmi_rx_action_event *) datap;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300591 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300592 dlen = le16_to_cpu(ev->len);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300593 if (datap + len < ev->data + dlen) {
594 ath6kl_err("invalid wmi_rx_action_event: "
595 "len=%d dlen=%u\n", len, dlen);
596 return -EINVAL;
597 }
598 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530599 cfg80211_rx_mgmt(vif->ndev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300600
601 return 0;
602}
603
604static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
605{
606 struct wmi_p2p_info_event *ev;
607 u32 flags;
608 u16 dlen;
609
610 if (len < sizeof(*ev))
611 return -EINVAL;
612
613 ev = (struct wmi_p2p_info_event *) datap;
614 flags = le32_to_cpu(ev->info_req_flags);
615 dlen = le16_to_cpu(ev->len);
616 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
617
618 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
619 struct wmi_p2p_capabilities *cap;
620 if (dlen < sizeof(*cap))
621 return -EINVAL;
622 cap = (struct wmi_p2p_capabilities *) ev->data;
623 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
624 cap->go_power_save);
625 }
626
627 if (flags & P2P_FLAG_MACADDR_REQ) {
628 struct wmi_p2p_macaddr *mac;
629 if (dlen < sizeof(*mac))
630 return -EINVAL;
631 mac = (struct wmi_p2p_macaddr *) ev->data;
632 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
633 mac->mac_addr);
634 }
635
636 if (flags & P2P_FLAG_HMODEL_REQ) {
637 struct wmi_p2p_hmodel *mod;
638 if (dlen < sizeof(*mod))
639 return -EINVAL;
640 mod = (struct wmi_p2p_hmodel *) ev->data;
641 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
642 mod->p2p_model,
643 mod->p2p_model ? "host" : "firmware");
644 }
645 return 0;
646}
647
Kalle Valobdcd8172011-07-18 00:22:30 +0300648static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
649{
650 struct sk_buff *skb;
651
652 skb = ath6kl_buf_alloc(size);
653 if (!skb)
654 return NULL;
655
656 skb_put(skb, size);
657 if (size)
658 memset(skb->data, 0, size);
659
660 return skb;
661}
662
663/* Send a "simple" wmi command -- one with no arguments */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530664static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
665 enum wmi_cmd_id cmd_id)
Kalle Valobdcd8172011-07-18 00:22:30 +0300666{
667 struct sk_buff *skb;
668 int ret;
669
670 skb = ath6kl_wmi_get_new_buf(0);
671 if (!skb)
672 return -ENOMEM;
673
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530674 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +0300675
676 return ret;
677}
678
679static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
680{
681 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
682
683 if (len < sizeof(struct wmi_ready_event_2))
684 return -EINVAL;
685
Kalle Valobdcd8172011-07-18 00:22:30 +0300686 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
687 le32_to_cpu(ev->sw_version),
688 le32_to_cpu(ev->abi_version));
689
690 return 0;
691}
692
Vivek Natarajane5090442011-08-31 15:02:19 +0530693/*
694 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
695 * at which the station has to roam can be passed with
696 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
697 * in dBm.
698 */
699int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
700{
701 struct sk_buff *skb;
702 struct roam_ctrl_cmd *cmd;
703
704 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
705 if (!skb)
706 return -ENOMEM;
707
708 cmd = (struct roam_ctrl_cmd *) skb->data;
709
710 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
711 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
712 DEF_SCAN_FOR_ROAM_INTVL);
713 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
714 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
715 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
716
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530717 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
718 NO_SYNC_WMIFLAG);
Vivek Natarajane5090442011-08-31 15:02:19 +0530719
720 return 0;
721}
722
Jouni Malinen12618752011-10-11 17:31:55 +0300723int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
724{
725 struct sk_buff *skb;
726 struct roam_ctrl_cmd *cmd;
727
728 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
729 if (!skb)
730 return -ENOMEM;
731
732 cmd = (struct roam_ctrl_cmd *) skb->data;
733 memset(cmd, 0, sizeof(*cmd));
734
735 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
736 cmd->roam_ctrl = WMI_FORCE_ROAM;
737
738 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530739 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300740 NO_SYNC_WMIFLAG);
741}
742
743int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
744{
745 struct sk_buff *skb;
746 struct roam_ctrl_cmd *cmd;
747
748 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
749 if (!skb)
750 return -ENOMEM;
751
752 cmd = (struct roam_ctrl_cmd *) skb->data;
753 memset(cmd, 0, sizeof(*cmd));
754
755 cmd->info.roam_mode = mode;
756 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
757
758 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530759 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300760 NO_SYNC_WMIFLAG);
761}
762
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530763static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
764 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300765{
766 struct wmi_connect_event *ev;
767 u8 *pie, *peie;
768
769 if (len < sizeof(struct wmi_connect_event))
770 return -EINVAL;
771
772 ev = (struct wmi_connect_event *) datap;
773
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530774 if (vif->nw_type == AP_NETWORK) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300775 /* AP mode start/STA connected event */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530776 struct net_device *dev = vif->ndev;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300777 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
778 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
779 "(AP started)\n",
780 __func__, le16_to_cpu(ev->u.ap_bss.ch),
781 ev->u.ap_bss.bssid);
782 ath6kl_connect_ap_mode_bss(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530783 vif, le16_to_cpu(ev->u.ap_bss.ch));
Jouni Malinen572e27c2011-09-05 17:38:45 +0300784 } else {
785 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
786 "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
787 "(STA connected)\n",
788 __func__, ev->u.ap_sta.aid,
789 ev->u.ap_sta.mac_addr,
790 ev->u.ap_sta.auth,
791 ev->u.ap_sta.keymgmt,
792 le16_to_cpu(ev->u.ap_sta.cipher),
793 ev->u.ap_sta.apsd_info);
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530794
Jouni Malinen572e27c2011-09-05 17:38:45 +0300795 ath6kl_connect_ap_mode_sta(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530796 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300797 ev->u.ap_sta.keymgmt,
798 le16_to_cpu(ev->u.ap_sta.cipher),
799 ev->u.ap_sta.auth, ev->assoc_req_len,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530800 ev->assoc_info + ev->beacon_ie_len,
801 ev->u.ap_sta.apsd_info);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300802 }
803 return 0;
804 }
805
806 /* STA/IBSS mode connection event */
807
Kalle Valob9b6ee62011-09-27 14:31:21 +0300808 ath6kl_dbg(ATH6KL_DBG_WMI,
809 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
810 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
811 le16_to_cpu(ev->u.sta.listen_intvl),
812 le16_to_cpu(ev->u.sta.beacon_intvl),
813 le32_to_cpu(ev->u.sta.nw_type));
Kalle Valobdcd8172011-07-18 00:22:30 +0300814
Kalle Valobdcd8172011-07-18 00:22:30 +0300815 /* Start of assoc rsp IEs */
816 pie = ev->assoc_info + ev->beacon_ie_len +
817 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
818
819 /* End of assoc rsp IEs */
820 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
821 ev->assoc_resp_len;
822
823 while (pie < peie) {
824 switch (*pie) {
825 case WLAN_EID_VENDOR_SPECIFIC:
826 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
827 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
828 /* WMM OUT (00:50:F2) */
Kalle Valoddc3d772012-03-07 20:03:58 +0200829 if (pie[1] > 5 &&
830 pie[6] == WMM_PARAM_OUI_SUBTYPE)
Kalle Valobdcd8172011-07-18 00:22:30 +0300831 wmi->is_wmm_enabled = true;
832 }
833 break;
834 }
835
836 if (wmi->is_wmm_enabled)
837 break;
838
839 pie += pie[1] + 2;
840 }
841
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530842 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
Jouni Malinen572e27c2011-09-05 17:38:45 +0300843 ev->u.sta.bssid,
844 le16_to_cpu(ev->u.sta.listen_intvl),
845 le16_to_cpu(ev->u.sta.beacon_intvl),
846 le32_to_cpu(ev->u.sta.nw_type),
Kalle Valobdcd8172011-07-18 00:22:30 +0300847 ev->beacon_ie_len, ev->assoc_req_len,
848 ev->assoc_resp_len, ev->assoc_info);
849
850 return 0;
851}
852
Vivek Natarajan06033762011-09-06 13:01:36 +0530853static struct country_code_to_enum_rd *
854ath6kl_regd_find_country(u16 countryCode)
855{
856 int i;
857
858 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
859 if (allCountries[i].countryCode == countryCode)
860 return &allCountries[i];
861 }
862
863 return NULL;
864}
865
866static struct reg_dmn_pair_mapping *
867ath6kl_get_regpair(u16 regdmn)
868{
869 int i;
870
871 if (regdmn == NO_ENUMRD)
872 return NULL;
873
874 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
875 if (regDomainPairs[i].regDmnEnum == regdmn)
876 return &regDomainPairs[i];
877 }
878
879 return NULL;
880}
881
882static struct country_code_to_enum_rd *
883ath6kl_regd_find_country_by_rd(u16 regdmn)
884{
885 int i;
886
887 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
888 if (allCountries[i].regDmnEnum == regdmn)
889 return &allCountries[i];
890 }
891
892 return NULL;
893}
894
895static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
896{
897
898 struct ath6kl_wmi_regdomain *ev;
899 struct country_code_to_enum_rd *country = NULL;
900 struct reg_dmn_pair_mapping *regpair = NULL;
901 char alpha2[2];
902 u32 reg_code;
903
904 ev = (struct ath6kl_wmi_regdomain *) datap;
905 reg_code = le32_to_cpu(ev->reg_code);
906
907 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
908 country = ath6kl_regd_find_country((u16) reg_code);
909 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
910
911 regpair = ath6kl_get_regpair((u16) reg_code);
912 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
Kalle Valob9b6ee62011-09-27 14:31:21 +0300913 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +0200914 regpair->regDmnEnum);
Vivek Natarajan06033762011-09-06 13:01:36 +0530915 }
916
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +0530917 if (country && wmi->parent_dev->wiphy_registered) {
Vivek Natarajan06033762011-09-06 13:01:36 +0530918 alpha2[0] = country->isoName[0];
919 alpha2[1] = country->isoName[1];
920
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530921 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
Vivek Natarajan06033762011-09-06 13:01:36 +0530922
Kalle Valob9b6ee62011-09-27 14:31:21 +0300923 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +0200924 alpha2[0], alpha2[1]);
Vivek Natarajan06033762011-09-06 13:01:36 +0530925 }
926}
927
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530928static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
929 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300930{
931 struct wmi_disconnect_event *ev;
932 wmi->traffic_class = 100;
933
934 if (len < sizeof(struct wmi_disconnect_event))
935 return -EINVAL;
936
937 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300938
Kalle Valob9b6ee62011-09-27 14:31:21 +0300939 ath6kl_dbg(ATH6KL_DBG_WMI,
940 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
941 le16_to_cpu(ev->proto_reason_status), ev->bssid,
942 ev->disconn_reason, ev->assoc_resp_len);
943
Kalle Valobdcd8172011-07-18 00:22:30 +0300944 wmi->is_wmm_enabled = false;
Kalle Valobdcd8172011-07-18 00:22:30 +0300945
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530946 ath6kl_disconnect_event(vif, ev->disconn_reason,
Kalle Valobdcd8172011-07-18 00:22:30 +0300947 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
948 le16_to_cpu(ev->proto_reason_status));
949
950 return 0;
951}
952
953static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
954{
955 struct wmi_peer_node_event *ev;
956
957 if (len < sizeof(struct wmi_peer_node_event))
958 return -EINVAL;
959
960 ev = (struct wmi_peer_node_event *) datap;
961
962 if (ev->event_code == PEER_NODE_JOIN_EVENT)
963 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
964 ev->peer_mac_addr);
965 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
966 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
967 ev->peer_mac_addr);
968
969 return 0;
970}
971
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530972static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
973 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300974{
975 struct wmi_tkip_micerr_event *ev;
976
977 if (len < sizeof(struct wmi_tkip_micerr_event))
978 return -EINVAL;
979
980 ev = (struct wmi_tkip_micerr_event *) datap;
981
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530982 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
Kalle Valobdcd8172011-07-18 00:22:30 +0300983
984 return 0;
985}
986
Kalle Valo10509f92011-12-13 14:52:07 +0200987void ath6kl_wmi_sscan_timer(unsigned long ptr)
988{
989 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
990
991 cfg80211_sched_scan_results(vif->ar->wiphy);
992}
993
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530994static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
995 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300996{
Jouni Malinen82e14f52011-09-19 19:15:05 +0300997 struct wmi_bss_info_hdr2 *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300998 u8 *buf;
999 struct ieee80211_channel *channel;
1000 struct ath6kl *ar = wmi->parent_dev;
1001 struct ieee80211_mgmt *mgmt;
1002 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +03001003
Jouni Malinen82e14f52011-09-19 19:15:05 +03001004 if (len <= sizeof(struct wmi_bss_info_hdr2))
Kalle Valobdcd8172011-07-18 00:22:30 +03001005 return -EINVAL;
1006
Jouni Malinen82e14f52011-09-19 19:15:05 +03001007 bih = (struct wmi_bss_info_hdr2 *) datap;
1008 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1009 len -= sizeof(struct wmi_bss_info_hdr2);
Kalle Valobdcd8172011-07-18 00:22:30 +03001010
1011 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001012 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1013 "frame_type=%d\n",
Jouni Malinen82e14f52011-09-19 19:15:05 +03001014 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001015 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +03001016
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001017 if (bih->frame_type != BEACON_FTYPE &&
1018 bih->frame_type != PROBERESP_FTYPE)
1019 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +03001020
Jouni Malinen551185c2011-09-19 19:15:06 +03001021 if (bih->frame_type == BEACON_FTYPE &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301022 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1023 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301024 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1025 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001026 }
1027
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301028 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001029 if (channel == NULL)
1030 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001031
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001032 if (len < 8 + 2 + 2)
1033 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001034
Kalle Valoddc3d772012-03-07 20:03:58 +02001035 if (bih->frame_type == BEACON_FTYPE &&
1036 test_bit(CONNECTED, &vif->flags) &&
1037 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001038 const u8 *tim;
1039 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1040 len - 8 - 2 - 2);
1041 if (tim && tim[1] >= 2) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301042 vif->assoc_bss_dtim_period = tim[3];
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301043 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +03001044 }
1045 }
1046
Kalle Valobdcd8172011-07-18 00:22:30 +03001047 /*
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001048 * In theory, use of cfg80211_inform_bss() would be more natural here
1049 * since we do not have the full frame. However, at least for now,
1050 * cfg80211 can only distinguish Beacon and Probe Response frames from
1051 * each other when using cfg80211_inform_bss_frame(), so let's build a
1052 * fake IEEE 802.11 header to be able to take benefit of this.
Kalle Valobdcd8172011-07-18 00:22:30 +03001053 */
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001054 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1055 if (mgmt == NULL)
1056 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001057
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001058 if (bih->frame_type == BEACON_FTYPE) {
1059 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1060 IEEE80211_STYPE_BEACON);
1061 memset(mgmt->da, 0xff, ETH_ALEN);
1062 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301063 struct net_device *dev = vif->ndev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001064
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001065 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1066 IEEE80211_STYPE_PROBE_RESP);
1067 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +03001068 }
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001069 mgmt->duration = cpu_to_le16(0);
1070 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1071 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1072 mgmt->seq_ctrl = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001073
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001074 memcpy(&mgmt->u.beacon, buf, len);
1075
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301076 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
Jouni Malinen82e14f52011-09-19 19:15:05 +03001077 24 + len, (bih->snr - 95) * 100,
1078 GFP_ATOMIC);
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001079 kfree(mgmt);
1080 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +03001081 return -ENOMEM;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001082 cfg80211_put_bss(bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001083
Kalle Valo10509f92011-12-13 14:52:07 +02001084 /*
1085 * Firmware doesn't return any event when scheduled scan has
1086 * finished, so we need to use a timer to find out when there are
1087 * no more results.
1088 *
1089 * The timer is started from the first bss info received, otherwise
1090 * the timer would not ever fire if the scan interval is short
1091 * enough.
1092 */
1093 if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
1094 !timer_pending(&vif->sched_scan_timer)) {
1095 mod_timer(&vif->sched_scan_timer, jiffies +
1096 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1097 }
1098
Kalle Valobdcd8172011-07-18 00:22:30 +03001099 return 0;
1100}
1101
Kalle Valobdcd8172011-07-18 00:22:30 +03001102/* Inactivity timeout of a fatpipe(pstream) at the target */
1103static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1104 int len)
1105{
1106 struct wmi_pstream_timeout_event *ev;
1107
1108 if (len < sizeof(struct wmi_pstream_timeout_event))
1109 return -EINVAL;
1110
1111 ev = (struct wmi_pstream_timeout_event *) datap;
1112
1113 /*
1114 * When the pstream (fat pipe == AC) timesout, it means there were
1115 * no thinStreams within this pstream & it got implicitly created
1116 * due to data flow on this AC. We start the inactivity timer only
1117 * for implicitly created pstream. Just reset the host state.
1118 */
1119 spin_lock_bh(&wmi->lock);
1120 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1121 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1122 spin_unlock_bh(&wmi->lock);
1123
1124 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1125 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1126
1127 return 0;
1128}
1129
1130static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1131{
1132 struct wmi_bit_rate_reply *reply;
1133 s32 rate;
1134 u32 sgi, index;
1135
1136 if (len < sizeof(struct wmi_bit_rate_reply))
1137 return -EINVAL;
1138
1139 reply = (struct wmi_bit_rate_reply *) datap;
1140
1141 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1142
1143 if (reply->rate_index == (s8) RATE_AUTO) {
1144 rate = RATE_AUTO;
1145 } else {
1146 index = reply->rate_index & 0x7f;
1147 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1148 rate = wmi_rate_tbl[index][sgi];
1149 }
1150
1151 ath6kl_wakeup_event(wmi->parent_dev);
1152
1153 return 0;
1154}
1155
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001156static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
Kalle Valo003353b0d2011-09-01 10:14:21 +03001157{
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001158 ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03001159
1160 return 0;
1161}
1162
Kalle Valobdcd8172011-07-18 00:22:30 +03001163static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1164{
1165 if (len < sizeof(struct wmi_fix_rates_reply))
1166 return -EINVAL;
1167
1168 ath6kl_wakeup_event(wmi->parent_dev);
1169
1170 return 0;
1171}
1172
1173static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1174{
1175 if (len < sizeof(struct wmi_channel_list_reply))
1176 return -EINVAL;
1177
1178 ath6kl_wakeup_event(wmi->parent_dev);
1179
1180 return 0;
1181}
1182
1183static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1184{
1185 struct wmi_tx_pwr_reply *reply;
1186
1187 if (len < sizeof(struct wmi_tx_pwr_reply))
1188 return -EINVAL;
1189
1190 reply = (struct wmi_tx_pwr_reply *) datap;
1191 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1192
1193 return 0;
1194}
1195
1196static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1197{
1198 if (len < sizeof(struct wmi_get_keepalive_cmd))
1199 return -EINVAL;
1200
1201 ath6kl_wakeup_event(wmi->parent_dev);
1202
1203 return 0;
1204}
1205
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301206static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1207 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001208{
1209 struct wmi_scan_complete_event *ev;
1210
1211 ev = (struct wmi_scan_complete_event *) datap;
1212
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301213 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
Kalle Valobdcd8172011-07-18 00:22:30 +03001214 wmi->is_probe_ssid = false;
1215
1216 return 0;
1217}
1218
Jouni Malinen86512132011-09-21 16:57:29 +03001219static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301220 int len, struct ath6kl_vif *vif)
Jouni Malinen86512132011-09-21 16:57:29 +03001221{
1222 struct wmi_neighbor_report_event *ev;
1223 u8 i;
1224
1225 if (len < sizeof(*ev))
1226 return -EINVAL;
1227 ev = (struct wmi_neighbor_report_event *) datap;
1228 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1229 > len) {
1230 ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
1231 "(num=%d len=%d)\n", ev->num_neighbors, len);
1232 return -EINVAL;
1233 }
1234 for (i = 0; i < ev->num_neighbors; i++) {
1235 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1236 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1237 ev->neighbor[i].bss_flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301238 cfg80211_pmksa_candidate_notify(vif->ndev, i,
Jouni Malinen86512132011-09-21 16:57:29 +03001239 ev->neighbor[i].bssid,
1240 !!(ev->neighbor[i].bss_flags &
1241 WMI_PREAUTH_CAPABLE_BSS),
1242 GFP_ATOMIC);
1243 }
1244
1245 return 0;
1246}
1247
Kalle Valobdcd8172011-07-18 00:22:30 +03001248/*
1249 * Target is reporting a programming error. This is for
1250 * developer aid only. Target only checks a few common violations
1251 * and it is responsibility of host to do all error checking.
1252 * Behavior of target after wmi error event is undefined.
1253 * A reset is recommended.
1254 */
1255static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1256{
1257 const char *type = "unknown error";
1258 struct wmi_cmd_error_event *ev;
1259 ev = (struct wmi_cmd_error_event *) datap;
1260
1261 switch (ev->err_code) {
1262 case INVALID_PARAM:
1263 type = "invalid parameter";
1264 break;
1265 case ILLEGAL_STATE:
1266 type = "invalid state";
1267 break;
1268 case INTERNAL_ERROR:
1269 type = "internal error";
1270 break;
1271 }
1272
1273 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1274 ev->cmd_id, type);
1275
1276 return 0;
1277}
1278
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301279static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1280 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001281{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301282 ath6kl_tgt_stats_event(vif, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001283
1284 return 0;
1285}
1286
1287static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1288 struct sq_threshold_params *sq_thresh,
1289 u32 size)
1290{
1291 u32 index;
1292 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1293
1294 /* The list is already in sorted order. Get the next lower value */
1295 for (index = 0; index < size; index++) {
1296 if (rssi < sq_thresh->upper_threshold[index]) {
1297 threshold = (u8) sq_thresh->upper_threshold[index];
1298 break;
1299 }
1300 }
1301
1302 return threshold;
1303}
1304
1305static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1306 struct sq_threshold_params *sq_thresh,
1307 u32 size)
1308{
1309 u32 index;
1310 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1311
1312 /* The list is already in sorted order. Get the next lower value */
1313 for (index = 0; index < size; index++) {
1314 if (rssi > sq_thresh->lower_threshold[index]) {
1315 threshold = (u8) sq_thresh->lower_threshold[index];
1316 break;
1317 }
1318 }
1319
1320 return threshold;
1321}
1322
1323static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1324 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1325{
1326 struct sk_buff *skb;
1327 struct wmi_rssi_threshold_params_cmd *cmd;
1328
1329 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1330 if (!skb)
1331 return -ENOMEM;
1332
1333 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1334 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1335
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301336 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001337 NO_SYNC_WMIFLAG);
1338}
1339
1340static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1341 int len)
1342{
1343 struct wmi_rssi_threshold_event *reply;
1344 struct wmi_rssi_threshold_params_cmd cmd;
1345 struct sq_threshold_params *sq_thresh;
1346 enum wmi_rssi_threshold_val new_threshold;
1347 u8 upper_rssi_threshold, lower_rssi_threshold;
1348 s16 rssi;
1349 int ret;
1350
1351 if (len < sizeof(struct wmi_rssi_threshold_event))
1352 return -EINVAL;
1353
1354 reply = (struct wmi_rssi_threshold_event *) datap;
1355 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1356 rssi = a_sle16_to_cpu(reply->rssi);
1357
1358 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1359
1360 /*
1361 * Identify the threshold breached and communicate that to the app.
1362 * After that install a new set of thresholds based on the signal
1363 * quality reported by the target
1364 */
1365 if (new_threshold) {
1366 /* Upper threshold breached */
1367 if (rssi < sq_thresh->upper_threshold[0]) {
1368 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001369 "spurious upper rssi threshold event: %d\n",
1370 rssi);
Kalle Valobdcd8172011-07-18 00:22:30 +03001371 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1372 (rssi >= sq_thresh->upper_threshold[0])) {
1373 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1374 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1375 (rssi >= sq_thresh->upper_threshold[1])) {
1376 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1377 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1378 (rssi >= sq_thresh->upper_threshold[2])) {
1379 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1380 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1381 (rssi >= sq_thresh->upper_threshold[3])) {
1382 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1383 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1384 (rssi >= sq_thresh->upper_threshold[4])) {
1385 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1386 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1387 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1388 }
1389 } else {
1390 /* Lower threshold breached */
1391 if (rssi > sq_thresh->lower_threshold[0]) {
1392 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001393 "spurious lower rssi threshold event: %d %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +03001394 rssi, sq_thresh->lower_threshold[0]);
1395 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1396 (rssi <= sq_thresh->lower_threshold[0])) {
1397 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1398 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1399 (rssi <= sq_thresh->lower_threshold[1])) {
1400 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1401 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1402 (rssi <= sq_thresh->lower_threshold[2])) {
1403 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1404 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1405 (rssi <= sq_thresh->lower_threshold[3])) {
1406 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1407 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1408 (rssi <= sq_thresh->lower_threshold[4])) {
1409 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1410 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1411 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1412 }
1413 }
1414
1415 /* Calculate and install the next set of thresholds */
1416 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1417 sq_thresh->lower_threshold_valid_count);
1418 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1419 sq_thresh->upper_threshold_valid_count);
1420
1421 /* Issue a wmi command to install the thresholds */
1422 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1423 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1424 cmd.weight = sq_thresh->weight;
1425 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1426
1427 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1428 if (ret) {
1429 ath6kl_err("unable to configure rssi thresholds\n");
1430 return -EIO;
1431 }
1432
1433 return 0;
1434}
1435
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301436static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1437 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001438{
1439 struct wmi_cac_event *reply;
1440 struct ieee80211_tspec_ie *ts;
1441 u16 active_tsids, tsinfo;
1442 u8 tsid, index;
1443 u8 ts_id;
1444
1445 if (len < sizeof(struct wmi_cac_event))
1446 return -EINVAL;
1447
1448 reply = (struct wmi_cac_event *) datap;
1449
1450 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1451 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1452
1453 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1454 tsinfo = le16_to_cpu(ts->tsinfo);
1455 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1456 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1457
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301458 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1459 reply->ac, tsid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001460 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1461 /*
1462 * Following assumes that there is only one outstanding
1463 * ADDTS request when this event is received
1464 */
1465 spin_lock_bh(&wmi->lock);
1466 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1467 spin_unlock_bh(&wmi->lock);
1468
1469 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1470 if ((active_tsids >> index) & 1)
1471 break;
1472 }
1473 if (index < (sizeof(active_tsids) * 8))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301474 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1475 reply->ac, index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001476 }
1477
1478 /*
1479 * Clear active tsids and Add missing handling
1480 * for delete qos stream from AP
1481 */
1482 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1483
1484 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1485 tsinfo = le16_to_cpu(ts->tsinfo);
1486 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1487 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1488
1489 spin_lock_bh(&wmi->lock);
1490 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1491 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1492 spin_unlock_bh(&wmi->lock);
1493
1494 /* Indicate stream inactivity to driver layer only if all tsids
1495 * within this AC are deleted.
1496 */
1497 if (!active_tsids) {
1498 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1499 false);
1500 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1501 }
1502 }
1503
1504 return 0;
1505}
1506
1507static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1508 struct wmi_snr_threshold_params_cmd *snr_cmd)
1509{
1510 struct sk_buff *skb;
1511 struct wmi_snr_threshold_params_cmd *cmd;
1512
1513 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1514 if (!skb)
1515 return -ENOMEM;
1516
1517 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1518 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1519
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301520 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001521 NO_SYNC_WMIFLAG);
1522}
1523
1524static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1525 int len)
1526{
1527 struct wmi_snr_threshold_event *reply;
1528 struct sq_threshold_params *sq_thresh;
1529 struct wmi_snr_threshold_params_cmd cmd;
1530 enum wmi_snr_threshold_val new_threshold;
1531 u8 upper_snr_threshold, lower_snr_threshold;
1532 s16 snr;
1533 int ret;
1534
1535 if (len < sizeof(struct wmi_snr_threshold_event))
1536 return -EINVAL;
1537
1538 reply = (struct wmi_snr_threshold_event *) datap;
1539
1540 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1541 snr = reply->snr;
1542
1543 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1544
1545 /*
1546 * Identify the threshold breached and communicate that to the app.
1547 * After that install a new set of thresholds based on the signal
1548 * quality reported by the target.
1549 */
1550 if (new_threshold) {
1551 /* Upper threshold breached */
1552 if (snr < sq_thresh->upper_threshold[0]) {
1553 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001554 "spurious upper snr threshold event: %d\n",
1555 snr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001556 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1557 (snr >= sq_thresh->upper_threshold[0])) {
1558 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1559 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1560 (snr >= sq_thresh->upper_threshold[1])) {
1561 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1562 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1563 (snr >= sq_thresh->upper_threshold[2])) {
1564 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1565 } else if (snr >= sq_thresh->upper_threshold[3]) {
1566 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1567 }
1568 } else {
1569 /* Lower threshold breached */
1570 if (snr > sq_thresh->lower_threshold[0]) {
1571 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001572 "spurious lower snr threshold event: %d\n",
1573 sq_thresh->lower_threshold[0]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001574 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1575 (snr <= sq_thresh->lower_threshold[0])) {
1576 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1577 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1578 (snr <= sq_thresh->lower_threshold[1])) {
1579 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1580 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1581 (snr <= sq_thresh->lower_threshold[2])) {
1582 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1583 } else if (snr <= sq_thresh->lower_threshold[3]) {
1584 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1585 }
1586 }
1587
1588 /* Calculate and install the next set of thresholds */
1589 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1590 sq_thresh->lower_threshold_valid_count);
1591 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1592 sq_thresh->upper_threshold_valid_count);
1593
1594 /* Issue a wmi command to install the thresholds */
1595 cmd.thresh_above1_val = upper_snr_threshold;
1596 cmd.thresh_below1_val = lower_snr_threshold;
1597 cmd.weight = sq_thresh->weight;
1598 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1599
1600 ath6kl_dbg(ATH6KL_DBG_WMI,
1601 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1602 snr, new_threshold,
1603 lower_snr_threshold, upper_snr_threshold);
1604
1605 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1606 if (ret) {
1607 ath6kl_err("unable to configure snr threshold\n");
1608 return -EIO;
1609 }
1610
1611 return 0;
1612}
1613
1614static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1615{
1616 u16 ap_info_entry_size;
1617 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1618 struct wmi_ap_info_v1 *ap_info_v1;
1619 u8 index;
1620
1621 if (len < sizeof(struct wmi_aplist_event) ||
1622 ev->ap_list_ver != APLIST_VER1)
1623 return -EINVAL;
1624
1625 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1626 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1627
1628 ath6kl_dbg(ATH6KL_DBG_WMI,
1629 "number of APs in aplist event: %d\n", ev->num_ap);
1630
1631 if (len < (int) (sizeof(struct wmi_aplist_event) +
1632 (ev->num_ap - 1) * ap_info_entry_size))
1633 return -EINVAL;
1634
1635 /* AP list version 1 contents */
1636 for (index = 0; index < ev->num_ap; index++) {
1637 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1638 index, ap_info_v1->bssid, ap_info_v1->channel);
1639 ap_info_v1++;
1640 }
1641
1642 return 0;
1643}
1644
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301645int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +03001646 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1647{
1648 struct wmi_cmd_hdr *cmd_hdr;
1649 enum htc_endpoint_id ep_id = wmi->ep_id;
1650 int ret;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301651 u16 info1;
Kalle Valobdcd8172011-07-18 00:22:30 +03001652
Kalle Valo71f96ee2011-11-14 19:31:30 +02001653 if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1))))
Kalle Valobdcd8172011-07-18 00:22:30 +03001654 return -EINVAL;
1655
Kalle Valob9b6ee62011-09-27 14:31:21 +03001656 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1657 cmd_id, skb->len, sync_flag);
1658 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1659 skb->data, skb->len);
1660
Kalle Valobdcd8172011-07-18 00:22:30 +03001661 if (sync_flag >= END_WMIFLAG) {
1662 dev_kfree_skb(skb);
1663 return -EINVAL;
1664 }
1665
1666 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1667 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1668 /*
1669 * Make sure all data currently queued is transmitted before
1670 * the cmd execution. Establish a new sync point.
1671 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301672 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001673 }
1674
1675 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1676
1677 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1678 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301679 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1680 cmd_hdr->info1 = cpu_to_le16(info1);
Kalle Valobdcd8172011-07-18 00:22:30 +03001681
1682 /* Only for OPT_TX_CMD, use BE endpoint. */
1683 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1684 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301685 false, false, 0, NULL, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001686 if (ret) {
1687 dev_kfree_skb(skb);
1688 return ret;
1689 }
1690 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1691 }
1692
1693 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1694
1695 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1696 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1697 /*
1698 * Make sure all new data queued waits for the command to
1699 * execute. Establish a new sync point.
1700 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301701 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001702 }
1703
1704 return 0;
1705}
1706
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301707int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1708 enum network_type nw_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001709 enum dot11_auth_mode dot11_auth_mode,
1710 enum auth_mode auth_mode,
1711 enum crypto_type pairwise_crypto,
1712 u8 pairwise_crypto_len,
1713 enum crypto_type group_crypto,
1714 u8 group_crypto_len, int ssid_len, u8 *ssid,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001715 u8 *bssid, u16 channel, u32 ctrl_flags,
1716 u8 nw_subtype)
Kalle Valobdcd8172011-07-18 00:22:30 +03001717{
1718 struct sk_buff *skb;
1719 struct wmi_connect_cmd *cc;
1720 int ret;
1721
Kalle Valob9b6ee62011-09-27 14:31:21 +03001722 ath6kl_dbg(ATH6KL_DBG_WMI,
1723 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1724 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1725 bssid, channel, ctrl_flags, ssid_len, nw_type,
1726 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1727 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1728
Kalle Valobdcd8172011-07-18 00:22:30 +03001729 wmi->traffic_class = 100;
1730
1731 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1732 return -EINVAL;
1733
1734 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1735 return -EINVAL;
1736
1737 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1738 if (!skb)
1739 return -ENOMEM;
1740
1741 cc = (struct wmi_connect_cmd *) skb->data;
1742
1743 if (ssid_len)
1744 memcpy(cc->ssid, ssid, ssid_len);
1745
1746 cc->ssid_len = ssid_len;
1747 cc->nw_type = nw_type;
1748 cc->dot11_auth_mode = dot11_auth_mode;
1749 cc->auth_mode = auth_mode;
1750 cc->prwise_crypto_type = pairwise_crypto;
1751 cc->prwise_crypto_len = pairwise_crypto_len;
1752 cc->grp_crypto_type = group_crypto;
1753 cc->grp_crypto_len = group_crypto_len;
1754 cc->ch = cpu_to_le16(channel);
1755 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001756 cc->nw_subtype = nw_subtype;
Kalle Valobdcd8172011-07-18 00:22:30 +03001757
1758 if (bssid != NULL)
1759 memcpy(cc->bssid, bssid, ETH_ALEN);
1760
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301761 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1762 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001763
1764 return ret;
1765}
1766
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301767int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1768 u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +03001769{
1770 struct sk_buff *skb;
1771 struct wmi_reconnect_cmd *cc;
1772 int ret;
1773
Kalle Valob9b6ee62011-09-27 14:31:21 +03001774 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1775 bssid, channel);
1776
Kalle Valobdcd8172011-07-18 00:22:30 +03001777 wmi->traffic_class = 100;
1778
1779 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1780 if (!skb)
1781 return -ENOMEM;
1782
1783 cc = (struct wmi_reconnect_cmd *) skb->data;
1784 cc->channel = cpu_to_le16(channel);
1785
1786 if (bssid != NULL)
1787 memcpy(cc->bssid, bssid, ETH_ALEN);
1788
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301789 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001790 NO_SYNC_WMIFLAG);
1791
1792 return ret;
1793}
1794
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301795int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03001796{
1797 int ret;
1798
Kalle Valob9b6ee62011-09-27 14:31:21 +03001799 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1800
Kalle Valobdcd8172011-07-18 00:22:30 +03001801 wmi->traffic_class = 100;
1802
1803 /* Disconnect command does not need to do a SYNC before. */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301804 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03001805
1806 return ret;
1807}
1808
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001809int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
1810 enum wmi_scan_type scan_type,
1811 u32 force_fgscan, u32 is_legacy,
1812 u32 home_dwell_time, u32 force_scan_interval,
1813 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
1814{
1815 struct sk_buff *skb;
1816 struct wmi_begin_scan_cmd *sc;
1817 s8 size;
1818 int i, band, ret;
1819 struct ath6kl *ar = wmi->parent_dev;
1820 int num_rates;
1821
1822 size = sizeof(struct wmi_begin_scan_cmd);
1823
1824 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1825 return -EINVAL;
1826
1827 if (num_chan > WMI_MAX_CHANNELS)
1828 return -EINVAL;
1829
1830 if (num_chan)
1831 size += sizeof(u16) * (num_chan - 1);
1832
1833 skb = ath6kl_wmi_get_new_buf(size);
1834 if (!skb)
1835 return -ENOMEM;
1836
1837 sc = (struct wmi_begin_scan_cmd *) skb->data;
1838 sc->scan_type = scan_type;
1839 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1840 sc->is_legacy = cpu_to_le32(is_legacy);
1841 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1842 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1843 sc->no_cck = cpu_to_le32(no_cck);
1844 sc->num_ch = num_chan;
1845
1846 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1847 struct ieee80211_supported_band *sband =
1848 ar->wiphy->bands[band];
1849 u32 ratemask = rates[band];
1850 u8 *supp_rates = sc->supp_rates[band].rates;
1851 num_rates = 0;
1852
1853 for (i = 0; i < sband->n_bitrates; i++) {
1854 if ((BIT(i) & ratemask) == 0)
1855 continue; /* skip rate */
1856 supp_rates[num_rates++] =
1857 (u8) (sband->bitrates[i].bitrate / 5);
1858 }
1859 sc->supp_rates[band].nrates = num_rates;
1860 }
1861
1862 for (i = 0; i < num_chan; i++)
1863 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1864
1865 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
1866 NO_SYNC_WMIFLAG);
1867
1868 return ret;
1869}
1870
1871/* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1872 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1873 * mgmt operations using station interface.
1874 */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301875int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1876 enum wmi_scan_type scan_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001877 u32 force_fgscan, u32 is_legacy,
1878 u32 home_dwell_time, u32 force_scan_interval,
1879 s8 num_chan, u16 *ch_list)
1880{
1881 struct sk_buff *skb;
1882 struct wmi_start_scan_cmd *sc;
1883 s8 size;
Edward Lu1276c9e2011-08-30 21:58:00 +03001884 int i, ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03001885
1886 size = sizeof(struct wmi_start_scan_cmd);
1887
1888 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1889 return -EINVAL;
1890
1891 if (num_chan > WMI_MAX_CHANNELS)
1892 return -EINVAL;
1893
1894 if (num_chan)
1895 size += sizeof(u16) * (num_chan - 1);
1896
1897 skb = ath6kl_wmi_get_new_buf(size);
1898 if (!skb)
1899 return -ENOMEM;
1900
1901 sc = (struct wmi_start_scan_cmd *) skb->data;
1902 sc->scan_type = scan_type;
1903 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1904 sc->is_legacy = cpu_to_le32(is_legacy);
1905 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1906 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1907 sc->num_ch = num_chan;
1908
Edward Lu1276c9e2011-08-30 21:58:00 +03001909 for (i = 0; i < num_chan; i++)
1910 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001911
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301912 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001913 NO_SYNC_WMIFLAG);
1914
1915 return ret;
1916}
1917
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301918int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
1919 u16 fg_start_sec,
Kalle Valobdcd8172011-07-18 00:22:30 +03001920 u16 fg_end_sec, u16 bg_sec,
1921 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1922 u16 pas_chdw_msec, u8 short_scan_ratio,
1923 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1924 u16 maxact_scan_per_ssid)
1925{
1926 struct sk_buff *skb;
1927 struct wmi_scan_params_cmd *sc;
1928 int ret;
1929
1930 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1931 if (!skb)
1932 return -ENOMEM;
1933
1934 sc = (struct wmi_scan_params_cmd *) skb->data;
1935 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1936 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1937 sc->bg_period = cpu_to_le16(bg_sec);
1938 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1939 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1940 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1941 sc->short_scan_ratio = short_scan_ratio;
1942 sc->scan_ctrl_flags = scan_ctrl_flag;
1943 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1944 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1945
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301946 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001947 NO_SYNC_WMIFLAG);
1948 return ret;
1949}
1950
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301951int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
Kalle Valobdcd8172011-07-18 00:22:30 +03001952{
1953 struct sk_buff *skb;
1954 struct wmi_bss_filter_cmd *cmd;
1955 int ret;
1956
1957 if (filter >= LAST_BSS_FILTER)
1958 return -EINVAL;
1959
1960 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1961 if (!skb)
1962 return -ENOMEM;
1963
1964 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1965 cmd->bss_filter = filter;
1966 cmd->ie_mask = cpu_to_le32(ie_mask);
1967
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301968 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001969 NO_SYNC_WMIFLAG);
1970 return ret;
1971}
1972
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301973int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
Kalle Valobdcd8172011-07-18 00:22:30 +03001974 u8 ssid_len, u8 *ssid)
1975{
1976 struct sk_buff *skb;
1977 struct wmi_probed_ssid_cmd *cmd;
1978 int ret;
1979
1980 if (index > MAX_PROBED_SSID_INDEX)
1981 return -EINVAL;
1982
1983 if (ssid_len > sizeof(cmd->ssid))
1984 return -EINVAL;
1985
1986 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1987 return -EINVAL;
1988
1989 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1990 return -EINVAL;
1991
1992 if (flag & SPECIFIC_SSID_FLAG)
1993 wmi->is_probe_ssid = true;
1994
1995 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1996 if (!skb)
1997 return -ENOMEM;
1998
1999 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2000 cmd->entry_index = index;
2001 cmd->flag = flag;
2002 cmd->ssid_len = ssid_len;
2003 memcpy(cmd->ssid, ssid, ssid_len);
2004
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302005 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002006 NO_SYNC_WMIFLAG);
2007 return ret;
2008}
2009
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302010int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2011 u16 listen_interval,
Kalle Valobdcd8172011-07-18 00:22:30 +03002012 u16 listen_beacons)
2013{
2014 struct sk_buff *skb;
2015 struct wmi_listen_int_cmd *cmd;
2016 int ret;
2017
2018 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2019 if (!skb)
2020 return -ENOMEM;
2021
2022 cmd = (struct wmi_listen_int_cmd *) skb->data;
2023 cmd->listen_intvl = cpu_to_le16(listen_interval);
2024 cmd->num_beacons = cpu_to_le16(listen_beacons);
2025
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302026 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002027 NO_SYNC_WMIFLAG);
2028 return ret;
2029}
2030
Raja Manice0dc0c2012-02-20 19:08:08 +05302031int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2032 u16 bmiss_time, u16 num_beacons)
2033{
2034 struct sk_buff *skb;
2035 struct wmi_bmiss_time_cmd *cmd;
2036 int ret;
2037
2038 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2039 if (!skb)
2040 return -ENOMEM;
2041
2042 cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2043 cmd->bmiss_time = cpu_to_le16(bmiss_time);
2044 cmd->num_beacons = cpu_to_le16(num_beacons);
2045
2046 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2047 NO_SYNC_WMIFLAG);
2048 return ret;
2049}
2050
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302051int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
Kalle Valobdcd8172011-07-18 00:22:30 +03002052{
2053 struct sk_buff *skb;
2054 struct wmi_power_mode_cmd *cmd;
2055 int ret;
2056
2057 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2058 if (!skb)
2059 return -ENOMEM;
2060
2061 cmd = (struct wmi_power_mode_cmd *) skb->data;
2062 cmd->pwr_mode = pwr_mode;
2063 wmi->pwr_mode = pwr_mode;
2064
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302065 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002066 NO_SYNC_WMIFLAG);
2067 return ret;
2068}
2069
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302070int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
Kalle Valobdcd8172011-07-18 00:22:30 +03002071 u16 ps_poll_num, u16 dtim_policy,
2072 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2073 u16 ps_fail_event_policy)
2074{
2075 struct sk_buff *skb;
2076 struct wmi_power_params_cmd *pm;
2077 int ret;
2078
2079 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2080 if (!skb)
2081 return -ENOMEM;
2082
2083 pm = (struct wmi_power_params_cmd *)skb->data;
2084 pm->idle_period = cpu_to_le16(idle_period);
2085 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2086 pm->dtim_policy = cpu_to_le16(dtim_policy);
2087 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2088 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2089 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2090
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302091 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002092 NO_SYNC_WMIFLAG);
2093 return ret;
2094}
2095
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302096int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
Kalle Valobdcd8172011-07-18 00:22:30 +03002097{
2098 struct sk_buff *skb;
2099 struct wmi_disc_timeout_cmd *cmd;
2100 int ret;
2101
2102 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2103 if (!skb)
2104 return -ENOMEM;
2105
2106 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2107 cmd->discon_timeout = timeout;
2108
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302109 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002110 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302111
Jouni Malinenff0b0072011-10-11 17:31:56 +03002112 if (ret == 0)
2113 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302114
Kalle Valobdcd8172011-07-18 00:22:30 +03002115 return ret;
2116}
2117
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302118int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
Kalle Valobdcd8172011-07-18 00:22:30 +03002119 enum crypto_type key_type,
2120 u8 key_usage, u8 key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002121 u8 *key_rsc, unsigned int key_rsc_len,
2122 u8 *key_material,
Kalle Valobdcd8172011-07-18 00:22:30 +03002123 u8 key_op_ctrl, u8 *mac_addr,
2124 enum wmi_sync_flag sync_flag)
2125{
2126 struct sk_buff *skb;
2127 struct wmi_add_cipher_key_cmd *cmd;
2128 int ret;
2129
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002130 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
2131 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
2132 key_index, key_type, key_usage, key_len, key_op_ctrl);
2133
Kalle Valobdcd8172011-07-18 00:22:30 +03002134 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002135 (key_material == NULL) || key_rsc_len > 8)
Kalle Valobdcd8172011-07-18 00:22:30 +03002136 return -EINVAL;
2137
2138 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2139 return -EINVAL;
2140
2141 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2142 if (!skb)
2143 return -ENOMEM;
2144
2145 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2146 cmd->key_index = key_index;
2147 cmd->key_type = key_type;
2148 cmd->key_usage = key_usage;
2149 cmd->key_len = key_len;
2150 memcpy(cmd->key, key_material, key_len);
2151
2152 if (key_rsc != NULL)
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002153 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002154
2155 cmd->key_op_ctrl = key_op_ctrl;
2156
2157 if (mac_addr)
2158 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2159
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302160 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002161 sync_flag);
2162
2163 return ret;
2164}
2165
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302166int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
Kalle Valobdcd8172011-07-18 00:22:30 +03002167{
2168 struct sk_buff *skb;
2169 struct wmi_add_krk_cmd *cmd;
2170 int ret;
2171
2172 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2173 if (!skb)
2174 return -ENOMEM;
2175
2176 cmd = (struct wmi_add_krk_cmd *) skb->data;
2177 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2178
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302179 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302180 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002181
2182 return ret;
2183}
2184
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302185int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
Kalle Valobdcd8172011-07-18 00:22:30 +03002186{
2187 struct sk_buff *skb;
2188 struct wmi_delete_cipher_key_cmd *cmd;
2189 int ret;
2190
2191 if (key_index > WMI_MAX_KEY_INDEX)
2192 return -EINVAL;
2193
2194 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2195 if (!skb)
2196 return -ENOMEM;
2197
2198 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2199 cmd->key_index = key_index;
2200
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302201 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002202 NO_SYNC_WMIFLAG);
2203
2204 return ret;
2205}
2206
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302207int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002208 const u8 *pmkid, bool set)
2209{
2210 struct sk_buff *skb;
2211 struct wmi_setpmkid_cmd *cmd;
2212 int ret;
2213
2214 if (bssid == NULL)
2215 return -EINVAL;
2216
2217 if (set && pmkid == NULL)
2218 return -EINVAL;
2219
2220 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2221 if (!skb)
2222 return -ENOMEM;
2223
2224 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2225 memcpy(cmd->bssid, bssid, ETH_ALEN);
2226 if (set) {
2227 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2228 cmd->enable = PMKID_ENABLE;
2229 } else {
2230 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2231 cmd->enable = PMKID_DISABLE;
2232 }
2233
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302234 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002235 NO_SYNC_WMIFLAG);
2236
2237 return ret;
2238}
2239
2240static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302241 enum htc_endpoint_id ep_id, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002242{
2243 struct wmi_data_hdr *data_hdr;
2244 int ret;
2245
2246 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2247 return -EINVAL;
2248
2249 skb_push(skb, sizeof(struct wmi_data_hdr));
2250
2251 data_hdr = (struct wmi_data_hdr *) skb->data;
2252 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302253 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +03002254
2255 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2256
2257 return ret;
2258}
2259
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302260static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002261{
2262 struct sk_buff *skb;
2263 struct wmi_sync_cmd *cmd;
2264 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2265 enum htc_endpoint_id ep_id;
2266 u8 index, num_pri_streams = 0;
2267 int ret = 0;
2268
2269 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2270
2271 spin_lock_bh(&wmi->lock);
2272
2273 for (index = 0; index < WMM_NUM_AC; index++) {
2274 if (wmi->fat_pipe_exist & (1 << index)) {
2275 num_pri_streams++;
2276 data_sync_bufs[num_pri_streams - 1].traffic_class =
2277 index;
2278 }
2279 }
2280
2281 spin_unlock_bh(&wmi->lock);
2282
2283 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2284 if (!skb) {
2285 ret = -ENOMEM;
2286 goto free_skb;
2287 }
2288
2289 cmd = (struct wmi_sync_cmd *) skb->data;
2290
2291 /*
2292 * In the SYNC cmd sent on the control Ep, send a bitmap
2293 * of the data eps on which the Data Sync will be sent
2294 */
2295 cmd->data_sync_map = wmi->fat_pipe_exist;
2296
2297 for (index = 0; index < num_pri_streams; index++) {
2298 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2299 if (data_sync_bufs[index].skb == NULL) {
2300 ret = -ENOMEM;
2301 break;
2302 }
2303 }
2304
2305 /*
2306 * If buffer allocation for any of the dataSync fails,
2307 * then do not send the Synchronize cmd on the control ep
2308 */
2309 if (ret)
2310 goto free_skb;
2311
2312 /*
2313 * Send sync cmd followed by sync data messages on all
2314 * endpoints being used
2315 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302316 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002317 NO_SYNC_WMIFLAG);
2318
2319 if (ret)
2320 goto free_skb;
2321
2322 /* cmd buffer sent, we no longer own it */
2323 skb = NULL;
2324
2325 for (index = 0; index < num_pri_streams; index++) {
2326
2327 if (WARN_ON(!data_sync_bufs[index].skb))
2328 break;
2329
2330 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2331 data_sync_bufs[index].
2332 traffic_class);
2333 ret =
2334 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302335 ep_id, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03002336
2337 if (ret)
2338 break;
2339
2340 data_sync_bufs[index].skb = NULL;
2341 }
2342
2343free_skb:
2344 /* free up any resources left over (possibly due to an error) */
2345 if (skb)
2346 dev_kfree_skb(skb);
2347
2348 for (index = 0; index < num_pri_streams; index++) {
2349 if (data_sync_bufs[index].skb != NULL) {
2350 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2351 skb);
2352 }
2353 }
2354
2355 return ret;
2356}
2357
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302358int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +03002359 struct wmi_create_pstream_cmd *params)
2360{
2361 struct sk_buff *skb;
2362 struct wmi_create_pstream_cmd *cmd;
2363 u8 fatpipe_exist_for_ac = 0;
2364 s32 min_phy = 0;
2365 s32 nominal_phy = 0;
2366 int ret;
2367
2368 if (!((params->user_pri < 8) &&
2369 (params->user_pri <= 0x7) &&
2370 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2371 (params->traffic_direc == UPLINK_TRAFFIC ||
2372 params->traffic_direc == DNLINK_TRAFFIC ||
2373 params->traffic_direc == BIDIR_TRAFFIC) &&
2374 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2375 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2376 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2377 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2378 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2379 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2380 params->tsid <= WMI_MAX_THINSTREAM))) {
2381 return -EINVAL;
2382 }
2383
2384 /*
2385 * Check nominal PHY rate is >= minimalPHY,
2386 * so that DUT can allow TSRS IE
2387 */
2388
2389 /* Get the physical rate (units of bps) */
2390 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2391
2392 /* Check minimal phy < nominal phy rate */
2393 if (params->nominal_phy >= min_phy) {
2394 /* unit of 500 kbps */
2395 nominal_phy = (params->nominal_phy * 1000) / 500;
2396 ath6kl_dbg(ATH6KL_DBG_WMI,
2397 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2398 min_phy, nominal_phy);
2399
2400 params->nominal_phy = nominal_phy;
2401 } else {
2402 params->nominal_phy = 0;
2403 }
2404
2405 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2406 if (!skb)
2407 return -ENOMEM;
2408
2409 ath6kl_dbg(ATH6KL_DBG_WMI,
2410 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2411 params->traffic_class, params->tsid);
2412
2413 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2414 memcpy(cmd, params, sizeof(*cmd));
2415
2416 /* This is an implicitly created Fat pipe */
2417 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2418 spin_lock_bh(&wmi->lock);
2419 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2420 (1 << params->traffic_class));
2421 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2422 spin_unlock_bh(&wmi->lock);
2423 } else {
2424 /* explicitly created thin stream within a fat pipe */
2425 spin_lock_bh(&wmi->lock);
2426 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2427 (1 << params->traffic_class));
2428 wmi->stream_exist_for_ac[params->traffic_class] |=
2429 (1 << params->tsid);
2430 /*
2431 * If a thinstream becomes active, the fat pipe automatically
2432 * becomes active
2433 */
2434 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2435 spin_unlock_bh(&wmi->lock);
2436 }
2437
2438 /*
2439 * Indicate activty change to driver layer only if this is the
2440 * first TSID to get created in this AC explicitly or an implicit
2441 * fat pipe is getting created.
2442 */
2443 if (!fatpipe_exist_for_ac)
2444 ath6kl_indicate_tx_activity(wmi->parent_dev,
2445 params->traffic_class, true);
2446
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302447 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002448 NO_SYNC_WMIFLAG);
2449 return ret;
2450}
2451
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302452int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2453 u8 tsid)
Kalle Valobdcd8172011-07-18 00:22:30 +03002454{
2455 struct sk_buff *skb;
2456 struct wmi_delete_pstream_cmd *cmd;
2457 u16 active_tsids = 0;
2458 int ret;
2459
2460 if (traffic_class > 3) {
2461 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2462 return -EINVAL;
2463 }
2464
2465 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2466 if (!skb)
2467 return -ENOMEM;
2468
2469 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2470 cmd->traffic_class = traffic_class;
2471 cmd->tsid = tsid;
2472
2473 spin_lock_bh(&wmi->lock);
2474 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2475 spin_unlock_bh(&wmi->lock);
2476
2477 if (!(active_tsids & (1 << tsid))) {
2478 dev_kfree_skb(skb);
2479 ath6kl_dbg(ATH6KL_DBG_WMI,
2480 "TSID %d doesn't exist for traffic class: %d\n",
2481 tsid, traffic_class);
2482 return -ENODATA;
2483 }
2484
2485 ath6kl_dbg(ATH6KL_DBG_WMI,
2486 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2487 traffic_class, tsid);
2488
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302489 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002490 SYNC_BEFORE_WMIFLAG);
2491
2492 spin_lock_bh(&wmi->lock);
2493 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2494 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2495 spin_unlock_bh(&wmi->lock);
2496
2497 /*
2498 * Indicate stream inactivity to driver layer only if all tsids
2499 * within this AC are deleted.
2500 */
2501 if (!active_tsids) {
2502 ath6kl_indicate_tx_activity(wmi->parent_dev,
2503 traffic_class, false);
2504 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2505 }
2506
2507 return ret;
2508}
2509
Raja Manica1d16a2011-12-16 14:24:23 +05302510int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2511 __be32 ips0, __be32 ips1)
Kalle Valobdcd8172011-07-18 00:22:30 +03002512{
2513 struct sk_buff *skb;
2514 struct wmi_set_ip_cmd *cmd;
2515 int ret;
2516
2517 /* Multicast address are not valid */
Raja Manica1d16a2011-12-16 14:24:23 +05302518 if (ipv4_is_multicast(ips0) ||
2519 ipv4_is_multicast(ips1))
Kalle Valobdcd8172011-07-18 00:22:30 +03002520 return -EINVAL;
2521
2522 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2523 if (!skb)
2524 return -ENOMEM;
2525
2526 cmd = (struct wmi_set_ip_cmd *) skb->data;
Raja Manica1d16a2011-12-16 14:24:23 +05302527 cmd->ips[0] = ips0;
2528 cmd->ips[1] = ips1;
Kalle Valobdcd8172011-07-18 00:22:30 +03002529
Raja Manica1d16a2011-12-16 14:24:23 +05302530 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302531 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002532 return ret;
2533}
2534
Raja Mani45cf1102011-11-07 22:52:45 +02002535static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2536{
2537 u16 active_tsids;
2538 u8 stream_exist;
2539 int i;
2540
2541 /*
2542 * Relinquish credits from all implicitly created pstreams
2543 * since when we go to sleep. If user created explicit
2544 * thinstreams exists with in a fatpipe leave them intact
2545 * for the user to delete.
2546 */
2547 spin_lock_bh(&wmi->lock);
2548 stream_exist = wmi->fat_pipe_exist;
2549 spin_unlock_bh(&wmi->lock);
2550
2551 for (i = 0; i < WMM_NUM_AC; i++) {
2552 if (stream_exist & (1 << i)) {
2553
2554 /*
2555 * FIXME: Is this lock & unlock inside
2556 * for loop correct? may need rework.
2557 */
2558 spin_lock_bh(&wmi->lock);
2559 active_tsids = wmi->stream_exist_for_ac[i];
2560 spin_unlock_bh(&wmi->lock);
2561
2562 /*
2563 * If there are no user created thin streams
2564 * delete the fatpipe
2565 */
2566 if (!active_tsids) {
2567 stream_exist &= ~(1 << i);
2568 /*
2569 * Indicate inactivity to driver layer for
2570 * this fatpipe (pstream)
2571 */
2572 ath6kl_indicate_tx_activity(wmi->parent_dev,
2573 i, false);
2574 }
2575 }
2576 }
2577
2578 /* FIXME: Can we do this assignment without locking ? */
2579 spin_lock_bh(&wmi->lock);
2580 wmi->fat_pipe_exist = stream_exist;
2581 spin_unlock_bh(&wmi->lock);
2582}
2583
2584int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2585 enum ath6kl_host_mode host_mode)
2586{
2587 struct sk_buff *skb;
2588 struct wmi_set_host_sleep_mode_cmd *cmd;
2589 int ret;
2590
2591 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2592 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2593 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2594 return -EINVAL;
2595 }
2596
2597 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2598 if (!skb)
2599 return -ENOMEM;
2600
2601 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2602
2603 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2604 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2605 cmd->asleep = cpu_to_le32(1);
2606 } else
2607 cmd->awake = cpu_to_le32(1);
2608
2609 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2610 WMI_SET_HOST_SLEEP_MODE_CMDID,
2611 NO_SYNC_WMIFLAG);
2612 return ret;
2613}
2614
Raja Mani081c7a82012-01-30 17:13:11 +05302615/* This command has zero length payload */
2616static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2617 struct ath6kl_vif *vif)
2618{
2619 struct ath6kl *ar = wmi->parent_dev;
2620
2621 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2622 wake_up(&ar->event_wq);
2623
2624 return 0;
2625}
2626
Raja Mani45cf1102011-11-07 22:52:45 +02002627int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2628 enum ath6kl_wow_mode wow_mode,
2629 u32 filter, u16 host_req_delay)
2630{
2631 struct sk_buff *skb;
2632 struct wmi_set_wow_mode_cmd *cmd;
2633 int ret;
2634
2635 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
Kalle Valo96f1fad2012-03-07 20:03:57 +02002636 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
Raja Mani45cf1102011-11-07 22:52:45 +02002637 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2638 return -EINVAL;
2639 }
2640
2641 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2642 if (!skb)
2643 return -ENOMEM;
2644
2645 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2646 cmd->enable_wow = cpu_to_le32(wow_mode);
2647 cmd->filter = cpu_to_le32(filter);
2648 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2649
2650 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2651 NO_SYNC_WMIFLAG);
2652 return ret;
2653}
2654
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002655int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2656 u8 list_id, u8 filter_size,
Raja Manid91e8ee2012-01-30 17:13:10 +05302657 u8 filter_offset, const u8 *filter,
2658 const u8 *mask)
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002659{
2660 struct sk_buff *skb;
2661 struct wmi_add_wow_pattern_cmd *cmd;
2662 u16 size;
2663 u8 *filter_mask;
2664 int ret;
2665
2666 /*
2667 * Allocate additional memory in the buffer to hold
2668 * filter and mask value, which is twice of filter_size.
2669 */
2670 size = sizeof(*cmd) + (2 * filter_size);
2671
2672 skb = ath6kl_wmi_get_new_buf(size);
2673 if (!skb)
2674 return -ENOMEM;
2675
2676 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2677 cmd->filter_list_id = list_id;
2678 cmd->filter_size = filter_size;
2679 cmd->filter_offset = filter_offset;
2680
2681 memcpy(cmd->filter, filter, filter_size);
2682
2683 filter_mask = (u8 *) (cmd->filter + filter_size);
2684 memcpy(filter_mask, mask, filter_size);
2685
2686 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2687 NO_SYNC_WMIFLAG);
2688
2689 return ret;
2690}
2691
2692int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2693 u16 list_id, u16 filter_id)
2694{
2695 struct sk_buff *skb;
2696 struct wmi_del_wow_pattern_cmd *cmd;
2697 int ret;
2698
2699 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2700 if (!skb)
2701 return -ENOMEM;
2702
2703 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
2704 cmd->filter_list_id = cpu_to_le16(list_id);
2705 cmd->filter_id = cpu_to_le16(filter_id);
2706
2707 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
2708 NO_SYNC_WMIFLAG);
2709 return ret;
2710}
2711
Kalle Valobdcd8172011-07-18 00:22:30 +03002712static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2713 enum wmix_command_id cmd_id,
2714 enum wmi_sync_flag sync_flag)
2715{
2716 struct wmix_cmd_hdr *cmd_hdr;
2717 int ret;
2718
2719 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2720
2721 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2722 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2723
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302724 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03002725
2726 return ret;
2727}
2728
2729int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2730{
2731 struct sk_buff *skb;
2732 struct wmix_hb_challenge_resp_cmd *cmd;
2733 int ret;
2734
2735 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2736 if (!skb)
2737 return -ENOMEM;
2738
2739 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2740 cmd->cookie = cpu_to_le32(cookie);
2741 cmd->source = cpu_to_le32(source);
2742
2743 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2744 NO_SYNC_WMIFLAG);
2745 return ret;
2746}
2747
Kalle Valo939f1cc2011-09-02 10:32:04 +03002748int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2749{
2750 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2751 struct sk_buff *skb;
2752 int ret;
2753
2754 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2755 if (!skb)
2756 return -ENOMEM;
2757
2758 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2759 cmd->valid = cpu_to_le32(valid);
2760 cmd->config = cpu_to_le32(config);
2761
2762 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2763 NO_SYNC_WMIFLAG);
2764 return ret;
2765}
2766
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302767int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002768{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302769 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002770}
2771
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302772int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
Kalle Valobdcd8172011-07-18 00:22:30 +03002773{
2774 struct sk_buff *skb;
2775 struct wmi_set_tx_pwr_cmd *cmd;
2776 int ret;
2777
2778 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2779 if (!skb)
2780 return -ENOMEM;
2781
2782 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2783 cmd->dbM = dbM;
2784
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302785 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002786 NO_SYNC_WMIFLAG);
2787
2788 return ret;
2789}
2790
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302791int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002792{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302793 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002794}
2795
Jouni Malinen4b28a802011-10-11 17:31:54 +03002796int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
2797{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302798 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
Jouni Malinen4b28a802011-10-11 17:31:54 +03002799}
2800
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302801int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
2802 u8 preamble_policy)
Kalle Valobdcd8172011-07-18 00:22:30 +03002803{
2804 struct sk_buff *skb;
2805 struct wmi_set_lpreamble_cmd *cmd;
2806 int ret;
2807
2808 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2809 if (!skb)
2810 return -ENOMEM;
2811
2812 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2813 cmd->status = status;
2814 cmd->preamble_policy = preamble_policy;
2815
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302816 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002817 NO_SYNC_WMIFLAG);
2818 return ret;
2819}
2820
2821int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2822{
2823 struct sk_buff *skb;
2824 struct wmi_set_rts_cmd *cmd;
2825 int ret;
2826
2827 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2828 if (!skb)
2829 return -ENOMEM;
2830
2831 cmd = (struct wmi_set_rts_cmd *) skb->data;
2832 cmd->threshold = cpu_to_le16(threshold);
2833
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302834 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
2835 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002836 return ret;
2837}
2838
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302839int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
Kalle Valobdcd8172011-07-18 00:22:30 +03002840{
2841 struct sk_buff *skb;
2842 struct wmi_set_wmm_txop_cmd *cmd;
2843 int ret;
2844
2845 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2846 return -EINVAL;
2847
2848 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2849 if (!skb)
2850 return -ENOMEM;
2851
2852 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2853 cmd->txop_enable = cfg;
2854
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302855 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002856 NO_SYNC_WMIFLAG);
2857 return ret;
2858}
2859
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302860int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
2861 u8 keep_alive_intvl)
Kalle Valobdcd8172011-07-18 00:22:30 +03002862{
2863 struct sk_buff *skb;
2864 struct wmi_set_keepalive_cmd *cmd;
2865 int ret;
2866
2867 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2868 if (!skb)
2869 return -ENOMEM;
2870
2871 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2872 cmd->keep_alive_intvl = keep_alive_intvl;
Kalle Valobdcd8172011-07-18 00:22:30 +03002873
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302874 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002875 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302876
Jouni Malinenff0b0072011-10-11 17:31:56 +03002877 if (ret == 0)
2878 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302879
Kalle Valobdcd8172011-07-18 00:22:30 +03002880 return ret;
2881}
2882
Kalle Valo003353b0d2011-09-01 10:14:21 +03002883int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2884{
2885 struct sk_buff *skb;
2886 int ret;
2887
2888 skb = ath6kl_wmi_get_new_buf(len);
2889 if (!skb)
2890 return -ENOMEM;
2891
2892 memcpy(skb->data, buf, len);
2893
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302894 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
Kalle Valo003353b0d2011-09-01 10:14:21 +03002895
2896 return ret;
2897}
2898
Vasanthakumar Thiagarajan3f3c4ee2012-01-03 14:41:59 +05302899int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
2900{
2901 struct sk_buff *skb;
2902 struct wmi_mcast_filter_cmd *cmd;
2903 int ret;
2904
2905 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2906 if (!skb)
2907 return -ENOMEM;
2908
2909 cmd = (struct wmi_mcast_filter_cmd *) skb->data;
2910 cmd->mcast_all_enable = mc_all_on;
2911
2912 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
2913 NO_SYNC_WMIFLAG);
2914 return ret;
2915}
Kalle Valo003353b0d2011-09-01 10:14:21 +03002916
Vasanthakumar Thiagarajanf914edd2012-01-03 14:42:00 +05302917int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
2918 u8 *filter, bool add_filter)
2919{
2920 struct sk_buff *skb;
2921 struct wmi_mcast_filter_add_del_cmd *cmd;
2922 int ret;
2923
2924 if ((filter[0] != 0x33 || filter[1] != 0x33) &&
2925 (filter[0] != 0x01 || filter[1] != 0x00 ||
2926 filter[2] != 0x5e || filter[3] > 0x7f)) {
2927 ath6kl_warn("invalid multicast filter address\n");
2928 return -EINVAL;
2929 }
2930
2931 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2932 if (!skb)
2933 return -ENOMEM;
2934
2935 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
2936 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
2937 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2938 add_filter ? WMI_SET_MCAST_FILTER_CMDID :
2939 WMI_DEL_MCAST_FILTER_CMDID,
2940 NO_SYNC_WMIFLAG);
2941
2942 return ret;
2943}
2944
Kalle Valobdcd8172011-07-18 00:22:30 +03002945s32 ath6kl_wmi_get_rate(s8 rate_index)
2946{
2947 if (rate_index == RATE_AUTO)
2948 return 0;
2949
2950 return wmi_rate_tbl[(u32) rate_index][0];
2951}
2952
Kalle Valobdcd8172011-07-18 00:22:30 +03002953static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2954 u32 len)
2955{
2956 struct wmi_pmkid_list_reply *reply;
2957 u32 expected_len;
2958
2959 if (len < sizeof(struct wmi_pmkid_list_reply))
2960 return -EINVAL;
2961
2962 reply = (struct wmi_pmkid_list_reply *)datap;
2963 expected_len = sizeof(reply->num_pmkid) +
2964 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2965
2966 if (len < expected_len)
2967 return -EINVAL;
2968
2969 return 0;
2970}
2971
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302972static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
2973 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03002974{
2975 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2976
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302977 aggr_recv_addba_req_evt(vif, cmd->tid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002978 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2979
2980 return 0;
2981}
2982
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302983static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
2984 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03002985{
2986 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2987
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302988 aggr_recv_delba_req_evt(vif, cmd->tid);
Kalle Valobdcd8172011-07-18 00:22:30 +03002989
2990 return 0;
2991}
2992
2993/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002994
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302995int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
2996 struct wmi_connect_cmd *p)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002997{
2998 struct sk_buff *skb;
2999 struct wmi_connect_cmd *cm;
3000 int res;
3001
3002 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3003 if (!skb)
3004 return -ENOMEM;
3005
3006 cm = (struct wmi_connect_cmd *) skb->data;
3007 memcpy(cm, p, sizeof(*cm));
3008
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303009 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003010 NO_SYNC_WMIFLAG);
3011 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
3012 "ctrl_flags=0x%x-> res=%d\n",
3013 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
3014 le32_to_cpu(p->ctrl_flags), res);
3015 return res;
3016}
3017
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303018int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3019 u16 reason)
Jouni Malinen23875132011-08-30 21:57:53 +03003020{
3021 struct sk_buff *skb;
3022 struct wmi_ap_set_mlme_cmd *cm;
3023
3024 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3025 if (!skb)
3026 return -ENOMEM;
3027
3028 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
3029 memcpy(cm->mac, mac, ETH_ALEN);
3030 cm->reason = cpu_to_le16(reason);
3031 cm->cmd = cmd;
3032
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303033 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
Jouni Malinen23875132011-08-30 21:57:53 +03003034 NO_SYNC_WMIFLAG);
3035}
3036
Thomas Pedersen67cd22e2012-02-28 15:08:46 -08003037int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
3038{
3039 struct sk_buff *skb;
3040 struct wmi_ap_hidden_ssid_cmd *cmd;
3041
3042 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3043 if (!skb)
3044 return -ENOMEM;
3045
3046 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
3047 cmd->hidden_ssid = enable ? 1 : 0;
3048
3049 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
3050 NO_SYNC_WMIFLAG);
3051}
3052
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05303053/* This command will be used to enable/disable AP uAPSD feature */
3054int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3055{
3056 struct wmi_ap_set_apsd_cmd *cmd;
3057 struct sk_buff *skb;
3058
3059 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3060 if (!skb)
3061 return -ENOMEM;
3062
3063 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3064 cmd->enable = enable;
3065
3066 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3067 NO_SYNC_WMIFLAG);
3068}
3069
3070int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3071 u16 aid, u16 bitmap, u32 flags)
3072{
3073 struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3074 struct sk_buff *skb;
3075
3076 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3077 if (!skb)
3078 return -ENOMEM;
3079
3080 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3081 cmd->aid = cpu_to_le16(aid);
3082 cmd->bitmap = cpu_to_le16(bitmap);
3083 cmd->flags = cpu_to_le32(flags);
3084
3085 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3086 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3087 NO_SYNC_WMIFLAG);
3088}
3089
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303090static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3091 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003092{
3093 struct wmi_pspoll_event *ev;
3094
3095 if (len < sizeof(struct wmi_pspoll_event))
3096 return -EINVAL;
3097
3098 ev = (struct wmi_pspoll_event *) datap;
3099
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303100 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
Kalle Valobdcd8172011-07-18 00:22:30 +03003101
3102 return 0;
3103}
3104
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303105static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3106 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003107{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303108 ath6kl_dtimexpiry_event(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03003109
3110 return 0;
3111}
3112
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303113int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3114 bool flag)
Kalle Valobdcd8172011-07-18 00:22:30 +03003115{
3116 struct sk_buff *skb;
3117 struct wmi_ap_set_pvb_cmd *cmd;
3118 int ret;
3119
3120 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3121 if (!skb)
3122 return -ENOMEM;
3123
3124 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3125 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03003126 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03003127 cmd->flag = cpu_to_le32(flag);
3128
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303129 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003130 NO_SYNC_WMIFLAG);
3131
3132 return 0;
3133}
3134
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303135int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
3136 u8 rx_meta_ver,
Kalle Valobdcd8172011-07-18 00:22:30 +03003137 bool rx_dot11_hdr, bool defrag_on_host)
3138{
3139 struct sk_buff *skb;
3140 struct wmi_rx_frame_format_cmd *cmd;
3141 int ret;
3142
3143 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3144 if (!skb)
3145 return -ENOMEM;
3146
3147 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3148 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3149 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3150 cmd->meta_ver = rx_meta_ver;
3151
3152 /* Delete the local aggr state, on host */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303153 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003154 NO_SYNC_WMIFLAG);
3155
3156 return ret;
3157}
3158
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303159int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3160 const u8 *ie, u8 ie_len)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003161{
3162 struct sk_buff *skb;
3163 struct wmi_set_appie_cmd *p;
3164
3165 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3166 if (!skb)
3167 return -ENOMEM;
3168
3169 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
3170 "ie_len=%u\n", mgmt_frm_type, ie_len);
3171 p = (struct wmi_set_appie_cmd *) skb->data;
3172 p->mgmt_frm_type = mgmt_frm_type;
3173 p->ie_len = ie_len;
Kalle Valo10509f92011-12-13 14:52:07 +02003174
3175 if (ie != NULL && ie_len > 0)
3176 memcpy(p->ie_info, ie, ie_len);
3177
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303178 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003179 NO_SYNC_WMIFLAG);
3180}
3181
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003182int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
3183{
3184 struct sk_buff *skb;
3185 struct wmi_disable_11b_rates_cmd *cmd;
3186
3187 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3188 if (!skb)
3189 return -ENOMEM;
3190
3191 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
3192 disable);
3193 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
3194 cmd->disable = disable ? 1 : 0;
3195
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303196 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003197 NO_SYNC_WMIFLAG);
3198}
3199
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303200int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003201{
3202 struct sk_buff *skb;
3203 struct wmi_remain_on_chnl_cmd *p;
3204
3205 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3206 if (!skb)
3207 return -ENOMEM;
3208
3209 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3210 freq, dur);
3211 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3212 p->freq = cpu_to_le32(freq);
3213 p->duration = cpu_to_le32(dur);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303214 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003215 NO_SYNC_WMIFLAG);
3216}
3217
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003218/* ath6kl_wmi_send_action_cmd is to be deprecated. Use
3219 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
3220 * mgmt operations using station interface.
3221 */
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003222static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3223 u32 freq, u32 wait, const u8 *data,
3224 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003225{
3226 struct sk_buff *skb;
3227 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03003228 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003229
3230 if (wait)
3231 return -EINVAL; /* Offload for wait not supported */
3232
Jouni Malinena0df5db2011-08-30 21:58:02 +03003233 buf = kmalloc(data_len, GFP_KERNEL);
3234 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003235 return -ENOMEM;
3236
Jouni Malinena0df5db2011-08-30 21:58:02 +03003237 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3238 if (!skb) {
3239 kfree(buf);
3240 return -ENOMEM;
3241 }
3242
3243 kfree(wmi->last_mgmt_tx_frame);
Aarthi Thiruvengadam3101ede2011-10-27 09:35:56 -07003244 memcpy(buf, data, data_len);
Jouni Malinena0df5db2011-08-30 21:58:02 +03003245 wmi->last_mgmt_tx_frame = buf;
3246 wmi->last_mgmt_tx_frame_len = data_len;
3247
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003248 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
3249 "len=%u\n", id, freq, wait, data_len);
3250 p = (struct wmi_send_action_cmd *) skb->data;
3251 p->id = cpu_to_le32(id);
3252 p->freq = cpu_to_le32(freq);
3253 p->wait = cpu_to_le32(wait);
3254 p->len = cpu_to_le16(data_len);
3255 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303256 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003257 NO_SYNC_WMIFLAG);
3258}
3259
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003260static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3261 u32 freq, u32 wait, const u8 *data,
3262 u16 data_len, u32 no_cck)
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003263{
3264 struct sk_buff *skb;
3265 struct wmi_send_mgmt_cmd *p;
3266 u8 *buf;
3267
3268 if (wait)
3269 return -EINVAL; /* Offload for wait not supported */
3270
3271 buf = kmalloc(data_len, GFP_KERNEL);
3272 if (!buf)
3273 return -ENOMEM;
3274
3275 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3276 if (!skb) {
3277 kfree(buf);
3278 return -ENOMEM;
3279 }
3280
3281 kfree(wmi->last_mgmt_tx_frame);
3282 memcpy(buf, data, data_len);
3283 wmi->last_mgmt_tx_frame = buf;
3284 wmi->last_mgmt_tx_frame_len = data_len;
3285
3286 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
3287 "len=%u\n", id, freq, wait, data_len);
3288 p = (struct wmi_send_mgmt_cmd *) skb->data;
3289 p->id = cpu_to_le32(id);
3290 p->freq = cpu_to_le32(freq);
3291 p->wait = cpu_to_le32(wait);
3292 p->no_cck = cpu_to_le32(no_cck);
3293 p->len = cpu_to_le16(data_len);
3294 memcpy(p->data, data, data_len);
3295 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
3296 NO_SYNC_WMIFLAG);
3297}
3298
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003299int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3300 u32 wait, const u8 *data, u16 data_len,
3301 u32 no_cck)
3302{
3303 int status;
3304 struct ath6kl *ar = wmi->parent_dev;
3305
3306 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3307 ar->fw_capabilities)) {
3308 /*
3309 * If capable of doing P2P mgmt operations using
3310 * station interface, send additional information like
3311 * supported rates to advertise and xmit rates for
3312 * probe requests
3313 */
3314 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3315 wait, data, data_len,
3316 no_cck);
3317 } else {
3318 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3319 wait, data, data_len);
3320 }
3321
3322 return status;
3323}
3324
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303325int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3326 const u8 *dst, const u8 *data,
3327 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003328{
3329 struct sk_buff *skb;
3330 struct wmi_p2p_probe_response_cmd *p;
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003331 size_t cmd_len = sizeof(*p) + data_len;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003332
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003333 if (data_len == 0)
3334 cmd_len++; /* work around target minimum length requirement */
3335
3336 skb = ath6kl_wmi_get_new_buf(cmd_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003337 if (!skb)
3338 return -ENOMEM;
3339
3340 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
3341 "len=%u\n", freq, dst, data_len);
3342 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3343 p->freq = cpu_to_le32(freq);
3344 memcpy(p->destination_addr, dst, ETH_ALEN);
3345 p->len = cpu_to_le16(data_len);
3346 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303347 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3348 WMI_SEND_PROBE_RESPONSE_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003349 NO_SYNC_WMIFLAG);
3350}
3351
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303352int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003353{
3354 struct sk_buff *skb;
3355 struct wmi_probe_req_report_cmd *p;
3356
3357 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3358 if (!skb)
3359 return -ENOMEM;
3360
3361 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3362 enable);
3363 p = (struct wmi_probe_req_report_cmd *) skb->data;
3364 p->enable = enable ? 1 : 0;
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303365 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003366 NO_SYNC_WMIFLAG);
3367}
3368
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303369int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003370{
3371 struct sk_buff *skb;
3372 struct wmi_get_p2p_info *p;
3373
3374 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3375 if (!skb)
3376 return -ENOMEM;
3377
3378 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3379 info_req_flags);
3380 p = (struct wmi_get_p2p_info *) skb->data;
3381 p->info_req_flags = cpu_to_le32(info_req_flags);
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303382 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003383 NO_SYNC_WMIFLAG);
3384}
3385
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303386int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003387{
3388 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303389 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3390 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003391}
3392
Kalle Valobdcd8172011-07-18 00:22:30 +03003393static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3394{
3395 struct wmix_cmd_hdr *cmd;
3396 u32 len;
3397 u16 id;
3398 u8 *datap;
3399 int ret = 0;
3400
3401 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3402 ath6kl_err("bad packet 1\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003403 return -EINVAL;
3404 }
3405
3406 cmd = (struct wmix_cmd_hdr *) skb->data;
3407 id = le32_to_cpu(cmd->cmd_id);
3408
3409 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3410
3411 datap = skb->data;
3412 len = skb->len;
3413
3414 switch (id) {
3415 case WMIX_HB_CHALLENGE_RESP_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003416 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003417 break;
3418 case WMIX_DBGLOG_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003419 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
Kalle Valobdf53962011-09-02 10:32:04 +03003420 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003421 break;
3422 default:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003423 ath6kl_warn("unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03003424 ret = -EINVAL;
3425 break;
3426 }
3427
3428 return ret;
3429}
3430
Jouni Malinen4b28a802011-10-11 17:31:54 +03003431static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3432{
3433 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3434}
3435
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303436/* Process interface specific wmi events, caller would free the datap */
3437static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
3438 u8 *datap, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03003439{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303440 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03003441
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303442 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3443 if (!vif) {
3444 ath6kl_dbg(ATH6KL_DBG_WMI,
3445 "Wmi event for unavailable vif, vif_index:%d\n",
3446 if_idx);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303447 return -EINVAL;
3448 }
3449
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303450 switch (cmd_id) {
3451 case WMI_CONNECT_EVENTID:
3452 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3453 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3454 case WMI_DISCONNECT_EVENTID:
3455 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3456 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3457 case WMI_TKIP_MICERR_EVENTID:
3458 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3459 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3460 case WMI_BSSINFO_EVENTID:
3461 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3462 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3463 case WMI_NEIGHBOR_REPORT_EVENTID:
3464 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3465 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3466 vif);
3467 case WMI_SCAN_COMPLETE_EVENTID:
3468 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3469 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3470 case WMI_REPORT_STATISTICS_EVENTID:
3471 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3472 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3473 case WMI_CAC_EVENTID:
3474 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3475 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3476 case WMI_PSPOLL_EVENTID:
3477 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3478 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3479 case WMI_DTIMEXPIRY_EVENTID:
3480 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3481 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3482 case WMI_ADDBA_REQ_EVENTID:
3483 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3484 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3485 case WMI_DELBA_REQ_EVENTID:
3486 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3487 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3488 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
3489 ath6kl_dbg(ATH6KL_DBG_WMI,
3490 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
3491 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
3492 case WMI_REMAIN_ON_CHNL_EVENTID:
3493 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3494 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3495 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3496 ath6kl_dbg(ATH6KL_DBG_WMI,
3497 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3498 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3499 len, vif);
3500 case WMI_TX_STATUS_EVENTID:
3501 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3502 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3503 case WMI_RX_PROBE_REQ_EVENTID:
3504 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3505 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3506 case WMI_RX_ACTION_EVENTID:
3507 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3508 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
3509 default:
3510 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
3511 return -EINVAL;
3512 }
3513
3514 return 0;
3515}
3516
3517static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
3518{
3519 struct wmi_cmd_hdr *cmd;
3520 int ret = 0;
3521 u32 len;
3522 u16 id;
3523 u8 if_idx;
3524 u8 *datap;
3525
3526 cmd = (struct wmi_cmd_hdr *) skb->data;
3527 id = le16_to_cpu(cmd->cmd_id);
3528 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
3529
3530 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3531 datap = skb->data;
3532 len = skb->len;
3533
3534 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3535 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3536 datap, len);
3537
Kalle Valobdcd8172011-07-18 00:22:30 +03003538 switch (id) {
3539 case WMI_GET_BITRATE_CMDID:
3540 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3541 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3542 break;
3543 case WMI_GET_CHANNEL_LIST_CMDID:
3544 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3545 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3546 break;
3547 case WMI_GET_TX_PWR_CMDID:
3548 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3549 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3550 break;
3551 case WMI_READY_EVENTID:
3552 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3553 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3554 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003555 case WMI_PEER_NODE_EVENTID:
3556 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3557 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3558 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003559 case WMI_REGDOMAIN_EVENTID:
3560 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05303561 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003562 break;
3563 case WMI_PSTREAM_TIMEOUT_EVENTID:
3564 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3565 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3566 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003567 case WMI_CMDERROR_EVENTID:
3568 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3569 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3570 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003571 case WMI_RSSI_THRESHOLD_EVENTID:
3572 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3573 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3574 break;
3575 case WMI_ERROR_REPORT_EVENTID:
3576 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3577 break;
3578 case WMI_OPT_RX_FRAME_EVENTID:
3579 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03003580 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03003581 break;
3582 case WMI_REPORT_ROAM_TBL_EVENTID:
3583 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
Jouni Malinen4b28a802011-10-11 17:31:54 +03003584 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003585 break;
3586 case WMI_EXTENSION_EVENTID:
3587 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3588 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3589 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003590 case WMI_CHANNEL_CHANGE_EVENTID:
3591 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3592 break;
3593 case WMI_REPORT_ROAM_DATA_EVENTID:
3594 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3595 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03003596 case WMI_TEST_EVENTID:
3597 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08003598 ret = ath6kl_wmi_test_rx(wmi, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003599 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003600 case WMI_GET_FIXRATES_CMDID:
3601 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3602 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3603 break;
3604 case WMI_TX_RETRY_ERR_EVENTID:
3605 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3606 break;
3607 case WMI_SNR_THRESHOLD_EVENTID:
3608 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3609 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3610 break;
3611 case WMI_LQ_THRESHOLD_EVENTID:
3612 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3613 break;
3614 case WMI_APLIST_EVENTID:
3615 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3616 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3617 break;
3618 case WMI_GET_KEEPALIVE_CMDID:
3619 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3620 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3621 break;
3622 case WMI_GET_WOW_LIST_EVENTID:
3623 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003624 break;
3625 case WMI_GET_PMKID_LIST_EVENTID:
3626 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3627 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3628 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003629 case WMI_SET_PARAMS_REPLY_EVENTID:
3630 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3631 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003632 case WMI_ADDBA_RESP_EVENTID:
3633 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3634 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003635 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3636 ath6kl_dbg(ATH6KL_DBG_WMI,
3637 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3638 break;
3639 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3640 ath6kl_dbg(ATH6KL_DBG_WMI,
3641 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3642 break;
3643 case WMI_TX_COMPLETE_EVENTID:
3644 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3645 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3646 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003647 case WMI_P2P_CAPABILITIES_EVENTID:
3648 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3649 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3650 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003651 case WMI_P2P_INFO_EVENTID:
3652 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3653 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3654 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003655 default:
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303656 /* may be the event is interface specific */
3657 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003658 break;
3659 }
3660
3661 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03003662 return ret;
3663}
3664
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303665/* Control Path */
3666int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
3667{
3668 if (WARN_ON(skb == NULL))
3669 return -EINVAL;
3670
3671 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
3672 ath6kl_err("bad packet 1\n");
3673 dev_kfree_skb(skb);
3674 return -EINVAL;
3675 }
3676
3677 return ath6kl_wmi_proc_events(wmi, skb);
3678}
3679
Kalle Valoc89c5912011-10-27 18:48:00 +03003680void ath6kl_wmi_reset(struct wmi *wmi)
Kalle Valobdcd8172011-07-18 00:22:30 +03003681{
Kalle Valobdcd8172011-07-18 00:22:30 +03003682 spin_lock_bh(&wmi->lock);
3683
3684 wmi->fat_pipe_exist = 0;
3685 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3686
3687 spin_unlock_bh(&wmi->lock);
3688}
3689
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05303690void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03003691{
3692 struct wmi *wmi;
3693
3694 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3695 if (!wmi)
3696 return NULL;
3697
3698 spin_lock_init(&wmi->lock);
3699
3700 wmi->parent_dev = dev;
3701
Kalle Valobdcd8172011-07-18 00:22:30 +03003702 wmi->pwr_mode = REC_POWER;
Kalle Valobdcd8172011-07-18 00:22:30 +03003703
Kalle Valoc89c5912011-10-27 18:48:00 +03003704 ath6kl_wmi_reset(wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03003705
3706 return wmi;
3707}
3708
3709void ath6kl_wmi_shutdown(struct wmi *wmi)
3710{
3711 if (!wmi)
3712 return;
3713
Jouni Malinena0df5db2011-08-30 21:58:02 +03003714 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03003715 kfree(wmi);
3716}