blob: 4762fa5706307cd5b1cfea7a2cc68e71ffe80764 [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>
Luis R. Rodriguez1560ac72012-04-23 19:58:50 -070019#include <linux/in.h>
Kalle Valobdcd8172011-07-18 00:22:30 +030020#include "core.h"
21#include "debug.h"
Kalle Valo003353b0d2011-09-01 10:14:21 +030022#include "testmode.h"
Vivek Natarajan06033762011-09-06 13:01:36 +053023#include "../regd.h"
24#include "../regd_common.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030025
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +053026static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +030027
28static const s32 wmi_rate_tbl[][2] = {
29 /* {W/O SGI, with SGI} */
30 {1000, 1000},
31 {2000, 2000},
32 {5500, 5500},
33 {11000, 11000},
34 {6000, 6000},
35 {9000, 9000},
36 {12000, 12000},
37 {18000, 18000},
38 {24000, 24000},
39 {36000, 36000},
40 {48000, 48000},
41 {54000, 54000},
42 {6500, 7200},
43 {13000, 14400},
44 {19500, 21700},
45 {26000, 28900},
46 {39000, 43300},
47 {52000, 57800},
48 {58500, 65000},
49 {65000, 72200},
50 {13500, 15000},
51 {27000, 30000},
52 {40500, 45000},
53 {54000, 60000},
54 {81000, 90000},
55 {108000, 120000},
56 {121500, 135000},
57 {135000, 150000},
58 {0, 0}
59};
60
61/* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
62static const u8 up_to_ac[] = {
63 WMM_AC_BE,
64 WMM_AC_BK,
65 WMM_AC_BK,
66 WMM_AC_BE,
67 WMM_AC_VI,
68 WMM_AC_VI,
69 WMM_AC_VO,
70 WMM_AC_VO,
71};
72
73void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
74{
75 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
76 return;
77
78 wmi->ep_id = ep_id;
79}
80
81enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
82{
83 return wmi->ep_id;
84}
85
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +053086struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +053087{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +053088 struct ath6kl_vif *vif, *found = NULL;
89
Kalle Valo71f96ee2011-11-14 19:31:30 +020090 if (WARN_ON(if_idx > (ar->vif_max - 1)))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +053091 return NULL;
92
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +053093 /* FIXME: Locking */
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +053094 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +053095 list_for_each_entry(vif, &ar->vif_list, list) {
96 if (vif->fw_vif_idx == if_idx) {
97 found = vif;
98 break;
99 }
100 }
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +0530101 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +0530102
103 return found;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530104}
105
Kalle Valobdcd8172011-07-18 00:22:30 +0300106/* Performs DIX to 802.3 encapsulation for transmit packets.
107 * Assumes the entire DIX header is contigous and that there is
108 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
109 */
110int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
111{
112 struct ath6kl_llc_snap_hdr *llc_hdr;
113 struct ethhdr *eth_hdr;
114 size_t new_len;
115 __be16 type;
116 u8 *datap;
117 u16 size;
118
119 if (WARN_ON(skb == NULL))
120 return -EINVAL;
121
122 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
123 if (skb_headroom(skb) < size)
124 return -ENOMEM;
125
126 eth_hdr = (struct ethhdr *) skb->data;
127 type = eth_hdr->h_proto;
128
129 if (!is_ethertype(be16_to_cpu(type))) {
130 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +0200131 "%s: pkt is already in 802.3 format\n", __func__);
Kalle Valobdcd8172011-07-18 00:22:30 +0300132 return 0;
133 }
134
135 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
136
137 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
138 datap = skb->data;
139
140 eth_hdr->h_proto = cpu_to_be16(new_len);
141
142 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
143
144 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
145 llc_hdr->dsap = 0xAA;
146 llc_hdr->ssap = 0xAA;
147 llc_hdr->cntl = 0x03;
148 llc_hdr->org_code[0] = 0x0;
149 llc_hdr->org_code[1] = 0x0;
150 llc_hdr->org_code[2] = 0x0;
151 llc_hdr->eth_type = type;
152
153 return 0;
154}
155
156static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
157 u8 *version, void *tx_meta_info)
158{
159 struct wmi_tx_meta_v1 *v1;
160 struct wmi_tx_meta_v2 *v2;
161
162 if (WARN_ON(skb == NULL || version == NULL))
163 return -EINVAL;
164
165 switch (*version) {
166 case WMI_META_VERSION_1:
167 skb_push(skb, WMI_MAX_TX_META_SZ);
168 v1 = (struct wmi_tx_meta_v1 *) skb->data;
169 v1->pkt_id = 0;
170 v1->rate_plcy_id = 0;
171 *version = WMI_META_VERSION_1;
172 break;
173 case WMI_META_VERSION_2:
174 skb_push(skb, WMI_MAX_TX_META_SZ);
175 v2 = (struct wmi_tx_meta_v2 *) skb->data;
176 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
177 sizeof(struct wmi_tx_meta_v2));
178 break;
179 }
180
181 return 0;
182}
183
184int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530185 u8 msg_type, u32 flags,
Kalle Valobdcd8172011-07-18 00:22:30 +0300186 enum wmi_data_hdr_data_type data_type,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +0530187 u8 meta_ver, void *tx_meta_info, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +0300188{
189 struct wmi_data_hdr *data_hdr;
190 int ret;
191
Kalle Valo71f96ee2011-11-14 19:31:30 +0200192 if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
Kalle Valobdcd8172011-07-18 00:22:30 +0300193 return -EINVAL;
194
Vasanthakumar Thiagarajan3ce6ff52011-08-22 20:40:21 +0530195 if (tx_meta_info) {
196 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
197 if (ret)
198 return ret;
199 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300200
201 skb_push(skb, sizeof(struct wmi_data_hdr));
202
203 data_hdr = (struct wmi_data_hdr *)skb->data;
204 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
205
206 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
207 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
208
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530209 if (flags & WMI_DATA_HDR_FLAGS_MORE)
210 data_hdr->info |= WMI_DATA_HDR_MORE;
Kalle Valobdcd8172011-07-18 00:22:30 +0300211
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530212 if (flags & WMI_DATA_HDR_FLAGS_EOSP)
213 data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
214
215 data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
216 data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +0300217
218 return 0;
219}
220
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530221u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
Kalle Valobdcd8172011-07-18 00:22:30 +0300222{
223 struct iphdr *ip_hdr = (struct iphdr *) pkt;
224 u8 ip_pri;
225
226 /*
227 * Determine IPTOS priority
228 *
229 * IP-TOS - 8bits
230 * : DSCP(6-bits) ECN(2-bits)
231 * : DSCP - P2 P1 P0 X X X
232 * where (P2 P1 P0) form 802.1D
233 */
234 ip_pri = ip_hdr->tos >> 5;
235 ip_pri &= 0x7;
236
237 if ((layer2_pri & 0x7) > ip_pri)
238 return (u8) layer2_pri & 0x7;
239 else
240 return ip_pri;
241}
242
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530243u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
244{
245 return up_to_ac[user_priority & 0x7];
246}
247
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530248int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
249 struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +0300250 u32 layer2_priority, bool wmm_enabled,
251 u8 *ac)
252{
253 struct wmi_data_hdr *data_hdr;
254 struct ath6kl_llc_snap_hdr *llc_hdr;
255 struct wmi_create_pstream_cmd cmd;
256 u32 meta_size, hdr_size;
257 u16 ip_type = IP_ETHERTYPE;
258 u8 stream_exist, usr_pri;
259 u8 traffic_class = WMM_AC_BE;
260 u8 *datap;
261
262 if (WARN_ON(skb == NULL))
263 return -EINVAL;
264
265 datap = skb->data;
266 data_hdr = (struct wmi_data_hdr *) datap;
267
268 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
269 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
270
271 if (!wmm_enabled) {
272 /* If WMM is disabled all traffic goes as BE traffic */
273 usr_pri = 0;
274 } else {
275 hdr_size = sizeof(struct ethhdr);
276
277 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
278 sizeof(struct
279 wmi_data_hdr) +
280 meta_size + hdr_size);
281
282 if (llc_hdr->eth_type == htons(ip_type)) {
283 /*
284 * Extract the endpoint info from the TOS field
285 * in the IP header.
286 */
287 usr_pri =
288 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
289 sizeof(struct ath6kl_llc_snap_hdr),
290 layer2_priority);
291 } else
292 usr_pri = layer2_priority & 0x7;
Vivek Natarajanf3740572012-05-02 14:55:25 +0530293
294 /*
295 * Queue the EAPOL frames in the same WMM_AC_VO queue
296 * as that of management frames.
297 */
298 if (skb->protocol == cpu_to_be16(ETH_P_PAE))
299 usr_pri = WMI_VOICE_USER_PRIORITY;
Kalle Valobdcd8172011-07-18 00:22:30 +0300300 }
301
Kalle Valoa7f0c582011-10-05 12:23:05 +0300302 /*
303 * workaround for WMM S5
304 *
305 * FIXME: wmi->traffic_class is always 100 so this test doesn't
306 * make sense
307 */
Kalle Valobdcd8172011-07-18 00:22:30 +0300308 if ((wmi->traffic_class == WMM_AC_VI) &&
309 ((usr_pri == 5) || (usr_pri == 4)))
310 usr_pri = 1;
311
312 /* Convert user priority to traffic class */
313 traffic_class = up_to_ac[usr_pri & 0x7];
314
315 wmi_data_hdr_set_up(data_hdr, usr_pri);
316
317 spin_lock_bh(&wmi->lock);
318 stream_exist = wmi->fat_pipe_exist;
319 spin_unlock_bh(&wmi->lock);
320
321 if (!(stream_exist & (1 << traffic_class))) {
322 memset(&cmd, 0, sizeof(cmd));
323 cmd.traffic_class = traffic_class;
324 cmd.user_pri = usr_pri;
325 cmd.inactivity_int =
326 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
327 /* Implicit streams are created with TSID 0xFF */
328 cmd.tsid = WMI_IMPLICIT_PSTREAM;
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530329 ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
Kalle Valobdcd8172011-07-18 00:22:30 +0300330 }
331
332 *ac = traffic_class;
333
334 return 0;
335}
336
337int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
338{
339 struct ieee80211_hdr_3addr *pwh, wh;
340 struct ath6kl_llc_snap_hdr *llc_hdr;
341 struct ethhdr eth_hdr;
342 u32 hdr_size;
343 u8 *datap;
344 __le16 sub_type;
345
346 if (WARN_ON(skb == NULL))
347 return -EINVAL;
348
349 datap = skb->data;
350 pwh = (struct ieee80211_hdr_3addr *) datap;
351
352 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
353
354 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
355
356 /* Strip off the 802.11 header */
357 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
358 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
359 sizeof(u32));
360 skb_pull(skb, hdr_size);
361 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
362 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
363
364 datap = skb->data;
365 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
366
Raja Manic8790cba2011-07-19 19:27:32 +0530367 memset(&eth_hdr, 0, sizeof(eth_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +0300368 eth_hdr.h_proto = llc_hdr->eth_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300369
370 switch ((le16_to_cpu(wh.frame_control)) &
371 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
372 case 0:
373 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
374 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
375 break;
376 case IEEE80211_FCTL_TODS:
377 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
378 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
379 break;
380 case IEEE80211_FCTL_FROMDS:
381 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
382 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
383 break;
384 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
385 break;
386 }
387
388 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
389 skb_push(skb, sizeof(eth_hdr));
390
391 datap = skb->data;
392
393 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
394
395 return 0;
396}
397
398/*
399 * Performs 802.3 to DIX encapsulation for received packets.
400 * Assumes the entire 802.3 header is contigous.
401 */
402int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
403{
404 struct ath6kl_llc_snap_hdr *llc_hdr;
405 struct ethhdr eth_hdr;
406 u8 *datap;
407
408 if (WARN_ON(skb == NULL))
409 return -EINVAL;
410
411 datap = skb->data;
412
413 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
414
415 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
416 eth_hdr.h_proto = llc_hdr->eth_type;
417
418 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
419 datap = skb->data;
420
421 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
422
423 return 0;
424}
425
Kalle Valobdcd8172011-07-18 00:22:30 +0300426static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
427{
428 struct tx_complete_msg_v1 *msg_v1;
429 struct wmi_tx_complete_event *evt;
430 int index;
431 u16 size;
432
433 evt = (struct wmi_tx_complete_event *) datap;
434
435 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
436 evt->num_msg, evt->msg_len, evt->msg_type);
437
Kalle Valobdcd8172011-07-18 00:22:30 +0300438 for (index = 0; index < evt->num_msg; index++) {
439 size = sizeof(struct wmi_tx_complete_event) +
440 (index * sizeof(struct tx_complete_msg_v1));
441 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
442
443 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
444 msg_v1->status, msg_v1->pkt_id,
445 msg_v1->rate_idx, msg_v1->ack_failures);
446 }
447
448 return 0;
449}
450
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300451static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530452 int len, struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300453{
454 struct wmi_remain_on_chnl_event *ev;
455 u32 freq;
456 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300457 struct ieee80211_channel *chan;
458 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen10522612011-10-27 16:00:13 +0300459 u32 id;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300460
461 if (len < sizeof(*ev))
462 return -EINVAL;
463
464 ev = (struct wmi_remain_on_chnl_event *) datap;
465 freq = le32_to_cpu(ev->freq);
466 dur = le32_to_cpu(ev->duration);
467 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
468 freq, dur);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530469 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300470 if (!chan) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300471 ath6kl_dbg(ATH6KL_DBG_WMI,
472 "remain_on_chnl: Unknown channel (freq=%u)\n",
473 freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300474 return -EINVAL;
475 }
Jouni Malinen10522612011-10-27 16:00:13 +0300476 id = vif->last_roc_id;
Johannes Berg71bbc992012-06-15 15:30:18 +0200477 cfg80211_ready_on_channel(&vif->wdev, id, chan, NL80211_CHAN_NO_HT,
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300478 dur, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300479
480 return 0;
481}
482
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300483static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530484 u8 *datap, int len,
485 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300486{
487 struct wmi_cancel_remain_on_chnl_event *ev;
488 u32 freq;
489 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300490 struct ieee80211_channel *chan;
491 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen10522612011-10-27 16:00:13 +0300492 u32 id;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300493
494 if (len < sizeof(*ev))
495 return -EINVAL;
496
497 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
498 freq = le32_to_cpu(ev->freq);
499 dur = le32_to_cpu(ev->duration);
Kalle Valocdeb8602012-04-12 11:02:18 +0300500 ath6kl_dbg(ATH6KL_DBG_WMI,
501 "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
502 freq, dur, ev->status);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530503 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300504 if (!chan) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300505 ath6kl_dbg(ATH6KL_DBG_WMI,
506 "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
507 freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300508 return -EINVAL;
509 }
Jouni Malinen10522612011-10-27 16:00:13 +0300510 if (vif->last_cancel_roc_id &&
511 vif->last_cancel_roc_id + 1 == vif->last_roc_id)
512 id = vif->last_cancel_roc_id; /* event for cancel command */
513 else
514 id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
515 vif->last_cancel_roc_id = 0;
Johannes Berg71bbc992012-06-15 15:30:18 +0200516 cfg80211_remain_on_channel_expired(&vif->wdev, id, chan,
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300517 NL80211_CHAN_NO_HT, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300518
519 return 0;
520}
521
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530522static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
523 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300524{
525 struct wmi_tx_status_event *ev;
526 u32 id;
527
528 if (len < sizeof(*ev))
529 return -EINVAL;
530
531 ev = (struct wmi_tx_status_event *) datap;
532 id = le32_to_cpu(ev->id);
533 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
534 id, ev->ack_status);
Jouni Malinena0df5db2011-08-30 21:58:02 +0300535 if (wmi->last_mgmt_tx_frame) {
Johannes Berg71bbc992012-06-15 15:30:18 +0200536 cfg80211_mgmt_tx_status(&vif->wdev, id,
Jouni Malinena0df5db2011-08-30 21:58:02 +0300537 wmi->last_mgmt_tx_frame,
538 wmi->last_mgmt_tx_frame_len,
539 !!ev->ack_status, GFP_ATOMIC);
540 kfree(wmi->last_mgmt_tx_frame);
541 wmi->last_mgmt_tx_frame = NULL;
542 wmi->last_mgmt_tx_frame_len = 0;
543 }
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300544
545 return 0;
546}
547
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530548static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
549 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300550{
551 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300552 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300553 u16 dlen;
554
555 if (len < sizeof(*ev))
556 return -EINVAL;
557
558 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300559 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300560 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300561 if (datap + len < ev->data + dlen) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300562 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
563 len, dlen);
Jouni Malinenae32c302011-08-30 21:58:01 +0300564 return -EINVAL;
565 }
Kalle Valocdeb8602012-04-12 11:02:18 +0300566 ath6kl_dbg(ATH6KL_DBG_WMI,
567 "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530568 dlen, freq, vif->probe_req_report);
Jouni Malinenae32c302011-08-30 21:58:01 +0300569
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530570 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
Johannes Berg71bbc992012-06-15 15:30:18 +0200571 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
Johannes Berg804483e2012-03-05 22:18:41 +0100572 ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300573
574 return 0;
575}
576
577static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
578{
579 struct wmi_p2p_capabilities_event *ev;
580 u16 dlen;
581
582 if (len < sizeof(*ev))
583 return -EINVAL;
584
585 ev = (struct wmi_p2p_capabilities_event *) datap;
586 dlen = le16_to_cpu(ev->len);
587 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
588
589 return 0;
590}
591
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530592static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
593 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300594{
595 struct wmi_rx_action_event *ev;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300596 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300597 u16 dlen;
598
599 if (len < sizeof(*ev))
600 return -EINVAL;
601
602 ev = (struct wmi_rx_action_event *) datap;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300603 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300604 dlen = le16_to_cpu(ev->len);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300605 if (datap + len < ev->data + dlen) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300606 ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
607 len, dlen);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300608 return -EINVAL;
609 }
610 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
Johannes Berg71bbc992012-06-15 15:30:18 +0200611 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
Johannes Berg804483e2012-03-05 22:18:41 +0100612 ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300613
614 return 0;
615}
616
617static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
618{
619 struct wmi_p2p_info_event *ev;
620 u32 flags;
621 u16 dlen;
622
623 if (len < sizeof(*ev))
624 return -EINVAL;
625
626 ev = (struct wmi_p2p_info_event *) datap;
627 flags = le32_to_cpu(ev->info_req_flags);
628 dlen = le16_to_cpu(ev->len);
629 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
630
631 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
632 struct wmi_p2p_capabilities *cap;
633 if (dlen < sizeof(*cap))
634 return -EINVAL;
635 cap = (struct wmi_p2p_capabilities *) ev->data;
636 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
637 cap->go_power_save);
638 }
639
640 if (flags & P2P_FLAG_MACADDR_REQ) {
641 struct wmi_p2p_macaddr *mac;
642 if (dlen < sizeof(*mac))
643 return -EINVAL;
644 mac = (struct wmi_p2p_macaddr *) ev->data;
645 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
646 mac->mac_addr);
647 }
648
649 if (flags & P2P_FLAG_HMODEL_REQ) {
650 struct wmi_p2p_hmodel *mod;
651 if (dlen < sizeof(*mod))
652 return -EINVAL;
653 mod = (struct wmi_p2p_hmodel *) ev->data;
654 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
655 mod->p2p_model,
656 mod->p2p_model ? "host" : "firmware");
657 }
658 return 0;
659}
660
Kalle Valobdcd8172011-07-18 00:22:30 +0300661static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
662{
663 struct sk_buff *skb;
664
665 skb = ath6kl_buf_alloc(size);
666 if (!skb)
667 return NULL;
668
669 skb_put(skb, size);
670 if (size)
671 memset(skb->data, 0, size);
672
673 return skb;
674}
675
676/* Send a "simple" wmi command -- one with no arguments */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530677static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
678 enum wmi_cmd_id cmd_id)
Kalle Valobdcd8172011-07-18 00:22:30 +0300679{
680 struct sk_buff *skb;
681 int ret;
682
683 skb = ath6kl_wmi_get_new_buf(0);
684 if (!skb)
685 return -ENOMEM;
686
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530687 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +0300688
689 return ret;
690}
691
692static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
693{
694 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
695
696 if (len < sizeof(struct wmi_ready_event_2))
697 return -EINVAL;
698
Kalle Valobdcd8172011-07-18 00:22:30 +0300699 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
700 le32_to_cpu(ev->sw_version),
Thomas Pedersend92917e2012-04-19 15:31:56 -0700701 le32_to_cpu(ev->abi_version), ev->phy_cap);
Kalle Valobdcd8172011-07-18 00:22:30 +0300702
703 return 0;
704}
705
Vivek Natarajane5090442011-08-31 15:02:19 +0530706/*
707 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
708 * at which the station has to roam can be passed with
709 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
710 * in dBm.
711 */
712int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
713{
714 struct sk_buff *skb;
715 struct roam_ctrl_cmd *cmd;
716
717 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
718 if (!skb)
719 return -ENOMEM;
720
721 cmd = (struct roam_ctrl_cmd *) skb->data;
722
723 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
724 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
725 DEF_SCAN_FOR_ROAM_INTVL);
726 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
727 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
728 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
729
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530730 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
731 NO_SYNC_WMIFLAG);
Vivek Natarajane5090442011-08-31 15:02:19 +0530732
733 return 0;
734}
735
Jouni Malinen12618752011-10-11 17:31:55 +0300736int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
737{
738 struct sk_buff *skb;
739 struct roam_ctrl_cmd *cmd;
740
741 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
742 if (!skb)
743 return -ENOMEM;
744
745 cmd = (struct roam_ctrl_cmd *) skb->data;
Jouni Malinen12618752011-10-11 17:31:55 +0300746
747 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
748 cmd->roam_ctrl = WMI_FORCE_ROAM;
749
750 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530751 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300752 NO_SYNC_WMIFLAG);
753}
754
Etay Luzd154f322012-05-30 11:35:08 +0300755int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
756{
757 struct sk_buff *skb;
758 struct set_dtim_cmd *cmd;
759
760 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
761 if (!skb)
762 return -ENOMEM;
763
764 cmd = (struct set_dtim_cmd *) skb->data;
765
766 cmd->dtim_period = cpu_to_le32(dtim_period);
767 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
768 WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
769}
770
Jouni Malinen12618752011-10-11 17:31:55 +0300771int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
772{
773 struct sk_buff *skb;
774 struct roam_ctrl_cmd *cmd;
775
776 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
777 if (!skb)
778 return -ENOMEM;
779
780 cmd = (struct roam_ctrl_cmd *) skb->data;
Jouni Malinen12618752011-10-11 17:31:55 +0300781
782 cmd->info.roam_mode = mode;
783 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
784
785 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530786 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300787 NO_SYNC_WMIFLAG);
788}
789
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530790static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
791 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300792{
793 struct wmi_connect_event *ev;
794 u8 *pie, *peie;
795
796 if (len < sizeof(struct wmi_connect_event))
797 return -EINVAL;
798
799 ev = (struct wmi_connect_event *) datap;
800
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530801 if (vif->nw_type == AP_NETWORK) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300802 /* AP mode start/STA connected event */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530803 struct net_device *dev = vif->ndev;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300804 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300805 ath6kl_dbg(ATH6KL_DBG_WMI,
806 "%s: freq %d bssid %pM (AP started)\n",
Jouni Malinen572e27c2011-09-05 17:38:45 +0300807 __func__, le16_to_cpu(ev->u.ap_bss.ch),
808 ev->u.ap_bss.bssid);
809 ath6kl_connect_ap_mode_bss(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530810 vif, le16_to_cpu(ev->u.ap_bss.ch));
Jouni Malinen572e27c2011-09-05 17:38:45 +0300811 } else {
Kalle Valocdeb8602012-04-12 11:02:18 +0300812 ath6kl_dbg(ATH6KL_DBG_WMI,
813 "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
Jouni Malinen572e27c2011-09-05 17:38:45 +0300814 __func__, ev->u.ap_sta.aid,
815 ev->u.ap_sta.mac_addr,
816 ev->u.ap_sta.auth,
817 ev->u.ap_sta.keymgmt,
818 le16_to_cpu(ev->u.ap_sta.cipher),
819 ev->u.ap_sta.apsd_info);
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530820
Jouni Malinen572e27c2011-09-05 17:38:45 +0300821 ath6kl_connect_ap_mode_sta(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530822 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300823 ev->u.ap_sta.keymgmt,
824 le16_to_cpu(ev->u.ap_sta.cipher),
825 ev->u.ap_sta.auth, ev->assoc_req_len,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530826 ev->assoc_info + ev->beacon_ie_len,
827 ev->u.ap_sta.apsd_info);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300828 }
829 return 0;
830 }
831
832 /* STA/IBSS mode connection event */
833
Kalle Valob9b6ee62011-09-27 14:31:21 +0300834 ath6kl_dbg(ATH6KL_DBG_WMI,
835 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
836 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
837 le16_to_cpu(ev->u.sta.listen_intvl),
838 le16_to_cpu(ev->u.sta.beacon_intvl),
839 le32_to_cpu(ev->u.sta.nw_type));
Kalle Valobdcd8172011-07-18 00:22:30 +0300840
Kalle Valobdcd8172011-07-18 00:22:30 +0300841 /* Start of assoc rsp IEs */
842 pie = ev->assoc_info + ev->beacon_ie_len +
843 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
844
845 /* End of assoc rsp IEs */
846 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
847 ev->assoc_resp_len;
848
849 while (pie < peie) {
850 switch (*pie) {
851 case WLAN_EID_VENDOR_SPECIFIC:
852 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
853 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
854 /* WMM OUT (00:50:F2) */
Kalle Valoddc3d772012-03-07 20:03:58 +0200855 if (pie[1] > 5 &&
856 pie[6] == WMM_PARAM_OUI_SUBTYPE)
Kalle Valobdcd8172011-07-18 00:22:30 +0300857 wmi->is_wmm_enabled = true;
858 }
859 break;
860 }
861
862 if (wmi->is_wmm_enabled)
863 break;
864
865 pie += pie[1] + 2;
866 }
867
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530868 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
Jouni Malinen572e27c2011-09-05 17:38:45 +0300869 ev->u.sta.bssid,
870 le16_to_cpu(ev->u.sta.listen_intvl),
871 le16_to_cpu(ev->u.sta.beacon_intvl),
872 le32_to_cpu(ev->u.sta.nw_type),
Kalle Valobdcd8172011-07-18 00:22:30 +0300873 ev->beacon_ie_len, ev->assoc_req_len,
874 ev->assoc_resp_len, ev->assoc_info);
875
876 return 0;
877}
878
Vivek Natarajan06033762011-09-06 13:01:36 +0530879static struct country_code_to_enum_rd *
880ath6kl_regd_find_country(u16 countryCode)
881{
882 int i;
883
884 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
885 if (allCountries[i].countryCode == countryCode)
886 return &allCountries[i];
887 }
888
889 return NULL;
890}
891
892static struct reg_dmn_pair_mapping *
893ath6kl_get_regpair(u16 regdmn)
894{
895 int i;
896
897 if (regdmn == NO_ENUMRD)
898 return NULL;
899
900 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
901 if (regDomainPairs[i].regDmnEnum == regdmn)
902 return &regDomainPairs[i];
903 }
904
905 return NULL;
906}
907
908static struct country_code_to_enum_rd *
909ath6kl_regd_find_country_by_rd(u16 regdmn)
910{
911 int i;
912
913 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
914 if (allCountries[i].regDmnEnum == regdmn)
915 return &allCountries[i];
916 }
917
918 return NULL;
919}
920
921static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
922{
923
924 struct ath6kl_wmi_regdomain *ev;
925 struct country_code_to_enum_rd *country = NULL;
926 struct reg_dmn_pair_mapping *regpair = NULL;
927 char alpha2[2];
928 u32 reg_code;
929
930 ev = (struct ath6kl_wmi_regdomain *) datap;
931 reg_code = le32_to_cpu(ev->reg_code);
932
933 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
934 country = ath6kl_regd_find_country((u16) reg_code);
935 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
936
937 regpair = ath6kl_get_regpair((u16) reg_code);
938 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
Kalle Valob9b6ee62011-09-27 14:31:21 +0300939 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +0200940 regpair->regDmnEnum);
Vivek Natarajan06033762011-09-06 13:01:36 +0530941 }
942
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +0530943 if (country && wmi->parent_dev->wiphy_registered) {
Vivek Natarajan06033762011-09-06 13:01:36 +0530944 alpha2[0] = country->isoName[0];
945 alpha2[1] = country->isoName[1];
946
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530947 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
Vivek Natarajan06033762011-09-06 13:01:36 +0530948
Kalle Valob9b6ee62011-09-27 14:31:21 +0300949 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +0200950 alpha2[0], alpha2[1]);
Vivek Natarajan06033762011-09-06 13:01:36 +0530951 }
952}
953
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530954static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
955 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300956{
957 struct wmi_disconnect_event *ev;
958 wmi->traffic_class = 100;
959
960 if (len < sizeof(struct wmi_disconnect_event))
961 return -EINVAL;
962
963 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300964
Kalle Valob9b6ee62011-09-27 14:31:21 +0300965 ath6kl_dbg(ATH6KL_DBG_WMI,
966 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
967 le16_to_cpu(ev->proto_reason_status), ev->bssid,
968 ev->disconn_reason, ev->assoc_resp_len);
969
Kalle Valobdcd8172011-07-18 00:22:30 +0300970 wmi->is_wmm_enabled = false;
Kalle Valobdcd8172011-07-18 00:22:30 +0300971
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530972 ath6kl_disconnect_event(vif, ev->disconn_reason,
Kalle Valobdcd8172011-07-18 00:22:30 +0300973 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
974 le16_to_cpu(ev->proto_reason_status));
975
976 return 0;
977}
978
979static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
980{
981 struct wmi_peer_node_event *ev;
982
983 if (len < sizeof(struct wmi_peer_node_event))
984 return -EINVAL;
985
986 ev = (struct wmi_peer_node_event *) datap;
987
988 if (ev->event_code == PEER_NODE_JOIN_EVENT)
989 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
990 ev->peer_mac_addr);
991 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
992 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
993 ev->peer_mac_addr);
994
995 return 0;
996}
997
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530998static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
999 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001000{
1001 struct wmi_tkip_micerr_event *ev;
1002
1003 if (len < sizeof(struct wmi_tkip_micerr_event))
1004 return -EINVAL;
1005
1006 ev = (struct wmi_tkip_micerr_event *) datap;
1007
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301008 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
Kalle Valobdcd8172011-07-18 00:22:30 +03001009
1010 return 0;
1011}
1012
Kalle Valo10509f92011-12-13 14:52:07 +02001013void ath6kl_wmi_sscan_timer(unsigned long ptr)
1014{
1015 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
1016
1017 cfg80211_sched_scan_results(vif->ar->wiphy);
1018}
1019
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301020static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
1021 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001022{
Jouni Malinen82e14f52011-09-19 19:15:05 +03001023 struct wmi_bss_info_hdr2 *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001024 u8 *buf;
1025 struct ieee80211_channel *channel;
1026 struct ath6kl *ar = wmi->parent_dev;
1027 struct ieee80211_mgmt *mgmt;
1028 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +03001029
Jouni Malinen82e14f52011-09-19 19:15:05 +03001030 if (len <= sizeof(struct wmi_bss_info_hdr2))
Kalle Valobdcd8172011-07-18 00:22:30 +03001031 return -EINVAL;
1032
Jouni Malinen82e14f52011-09-19 19:15:05 +03001033 bih = (struct wmi_bss_info_hdr2 *) datap;
1034 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1035 len -= sizeof(struct wmi_bss_info_hdr2);
Kalle Valobdcd8172011-07-18 00:22:30 +03001036
1037 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001038 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1039 "frame_type=%d\n",
Jouni Malinen82e14f52011-09-19 19:15:05 +03001040 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001041 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +03001042
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001043 if (bih->frame_type != BEACON_FTYPE &&
1044 bih->frame_type != PROBERESP_FTYPE)
1045 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +03001046
Jouni Malinen551185c2011-09-19 19:15:06 +03001047 if (bih->frame_type == BEACON_FTYPE &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301048 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1049 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301050 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1051 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001052 }
1053
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301054 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001055 if (channel == NULL)
1056 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001057
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001058 if (len < 8 + 2 + 2)
1059 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001060
Kalle Valoddc3d772012-03-07 20:03:58 +02001061 if (bih->frame_type == BEACON_FTYPE &&
1062 test_bit(CONNECTED, &vif->flags) &&
1063 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001064 const u8 *tim;
1065 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1066 len - 8 - 2 - 2);
1067 if (tim && tim[1] >= 2) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301068 vif->assoc_bss_dtim_period = tim[3];
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301069 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +03001070 }
1071 }
1072
Kalle Valobdcd8172011-07-18 00:22:30 +03001073 /*
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001074 * In theory, use of cfg80211_inform_bss() would be more natural here
1075 * since we do not have the full frame. However, at least for now,
1076 * cfg80211 can only distinguish Beacon and Probe Response frames from
1077 * each other when using cfg80211_inform_bss_frame(), so let's build a
1078 * fake IEEE 802.11 header to be able to take benefit of this.
Kalle Valobdcd8172011-07-18 00:22:30 +03001079 */
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001080 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1081 if (mgmt == NULL)
1082 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001083
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001084 if (bih->frame_type == BEACON_FTYPE) {
1085 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1086 IEEE80211_STYPE_BEACON);
1087 memset(mgmt->da, 0xff, ETH_ALEN);
1088 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301089 struct net_device *dev = vif->ndev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001090
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001091 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1092 IEEE80211_STYPE_PROBE_RESP);
1093 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +03001094 }
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001095 mgmt->duration = cpu_to_le16(0);
1096 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1097 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1098 mgmt->seq_ctrl = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001099
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001100 memcpy(&mgmt->u.beacon, buf, len);
1101
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301102 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
Jouni Malinen82e14f52011-09-19 19:15:05 +03001103 24 + len, (bih->snr - 95) * 100,
1104 GFP_ATOMIC);
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001105 kfree(mgmt);
1106 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +03001107 return -ENOMEM;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001108 cfg80211_put_bss(bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001109
Kalle Valo10509f92011-12-13 14:52:07 +02001110 /*
1111 * Firmware doesn't return any event when scheduled scan has
1112 * finished, so we need to use a timer to find out when there are
1113 * no more results.
1114 *
1115 * The timer is started from the first bss info received, otherwise
1116 * the timer would not ever fire if the scan interval is short
1117 * enough.
1118 */
1119 if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
1120 !timer_pending(&vif->sched_scan_timer)) {
1121 mod_timer(&vif->sched_scan_timer, jiffies +
1122 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1123 }
1124
Kalle Valobdcd8172011-07-18 00:22:30 +03001125 return 0;
1126}
1127
Kalle Valobdcd8172011-07-18 00:22:30 +03001128/* Inactivity timeout of a fatpipe(pstream) at the target */
1129static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1130 int len)
1131{
1132 struct wmi_pstream_timeout_event *ev;
1133
1134 if (len < sizeof(struct wmi_pstream_timeout_event))
1135 return -EINVAL;
1136
1137 ev = (struct wmi_pstream_timeout_event *) datap;
1138
1139 /*
1140 * When the pstream (fat pipe == AC) timesout, it means there were
1141 * no thinStreams within this pstream & it got implicitly created
1142 * due to data flow on this AC. We start the inactivity timer only
1143 * for implicitly created pstream. Just reset the host state.
1144 */
1145 spin_lock_bh(&wmi->lock);
1146 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1147 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1148 spin_unlock_bh(&wmi->lock);
1149
1150 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1151 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1152
1153 return 0;
1154}
1155
1156static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1157{
1158 struct wmi_bit_rate_reply *reply;
1159 s32 rate;
1160 u32 sgi, index;
1161
1162 if (len < sizeof(struct wmi_bit_rate_reply))
1163 return -EINVAL;
1164
1165 reply = (struct wmi_bit_rate_reply *) datap;
1166
1167 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1168
1169 if (reply->rate_index == (s8) RATE_AUTO) {
1170 rate = RATE_AUTO;
1171 } else {
1172 index = reply->rate_index & 0x7f;
1173 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1174 rate = wmi_rate_tbl[index][sgi];
1175 }
1176
1177 ath6kl_wakeup_event(wmi->parent_dev);
1178
1179 return 0;
1180}
1181
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001182static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
Kalle Valo003353b0d2011-09-01 10:14:21 +03001183{
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001184 ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03001185
1186 return 0;
1187}
1188
Kalle Valobdcd8172011-07-18 00:22:30 +03001189static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1190{
1191 if (len < sizeof(struct wmi_fix_rates_reply))
1192 return -EINVAL;
1193
1194 ath6kl_wakeup_event(wmi->parent_dev);
1195
1196 return 0;
1197}
1198
1199static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1200{
1201 if (len < sizeof(struct wmi_channel_list_reply))
1202 return -EINVAL;
1203
1204 ath6kl_wakeup_event(wmi->parent_dev);
1205
1206 return 0;
1207}
1208
1209static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1210{
1211 struct wmi_tx_pwr_reply *reply;
1212
1213 if (len < sizeof(struct wmi_tx_pwr_reply))
1214 return -EINVAL;
1215
1216 reply = (struct wmi_tx_pwr_reply *) datap;
1217 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1218
1219 return 0;
1220}
1221
1222static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1223{
1224 if (len < sizeof(struct wmi_get_keepalive_cmd))
1225 return -EINVAL;
1226
1227 ath6kl_wakeup_event(wmi->parent_dev);
1228
1229 return 0;
1230}
1231
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301232static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1233 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001234{
1235 struct wmi_scan_complete_event *ev;
1236
1237 ev = (struct wmi_scan_complete_event *) datap;
1238
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301239 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
Kalle Valobdcd8172011-07-18 00:22:30 +03001240 wmi->is_probe_ssid = false;
1241
1242 return 0;
1243}
1244
Jouni Malinen86512132011-09-21 16:57:29 +03001245static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301246 int len, struct ath6kl_vif *vif)
Jouni Malinen86512132011-09-21 16:57:29 +03001247{
1248 struct wmi_neighbor_report_event *ev;
1249 u8 i;
1250
1251 if (len < sizeof(*ev))
1252 return -EINVAL;
1253 ev = (struct wmi_neighbor_report_event *) datap;
1254 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1255 > len) {
Kalle Valocdeb8602012-04-12 11:02:18 +03001256 ath6kl_dbg(ATH6KL_DBG_WMI,
1257 "truncated neighbor event (num=%d len=%d)\n",
1258 ev->num_neighbors, len);
Jouni Malinen86512132011-09-21 16:57:29 +03001259 return -EINVAL;
1260 }
1261 for (i = 0; i < ev->num_neighbors; i++) {
1262 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1263 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1264 ev->neighbor[i].bss_flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301265 cfg80211_pmksa_candidate_notify(vif->ndev, i,
Jouni Malinen86512132011-09-21 16:57:29 +03001266 ev->neighbor[i].bssid,
1267 !!(ev->neighbor[i].bss_flags &
1268 WMI_PREAUTH_CAPABLE_BSS),
1269 GFP_ATOMIC);
1270 }
1271
1272 return 0;
1273}
1274
Kalle Valobdcd8172011-07-18 00:22:30 +03001275/*
1276 * Target is reporting a programming error. This is for
1277 * developer aid only. Target only checks a few common violations
1278 * and it is responsibility of host to do all error checking.
1279 * Behavior of target after wmi error event is undefined.
1280 * A reset is recommended.
1281 */
1282static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1283{
1284 const char *type = "unknown error";
1285 struct wmi_cmd_error_event *ev;
1286 ev = (struct wmi_cmd_error_event *) datap;
1287
1288 switch (ev->err_code) {
1289 case INVALID_PARAM:
1290 type = "invalid parameter";
1291 break;
1292 case ILLEGAL_STATE:
1293 type = "invalid state";
1294 break;
1295 case INTERNAL_ERROR:
1296 type = "internal error";
1297 break;
1298 }
1299
1300 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1301 ev->cmd_id, type);
1302
1303 return 0;
1304}
1305
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301306static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1307 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001308{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301309 ath6kl_tgt_stats_event(vif, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001310
1311 return 0;
1312}
1313
1314static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1315 struct sq_threshold_params *sq_thresh,
1316 u32 size)
1317{
1318 u32 index;
1319 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1320
1321 /* The list is already in sorted order. Get the next lower value */
1322 for (index = 0; index < size; index++) {
1323 if (rssi < sq_thresh->upper_threshold[index]) {
1324 threshold = (u8) sq_thresh->upper_threshold[index];
1325 break;
1326 }
1327 }
1328
1329 return threshold;
1330}
1331
1332static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1333 struct sq_threshold_params *sq_thresh,
1334 u32 size)
1335{
1336 u32 index;
1337 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1338
1339 /* The list is already in sorted order. Get the next lower value */
1340 for (index = 0; index < size; index++) {
1341 if (rssi > sq_thresh->lower_threshold[index]) {
1342 threshold = (u8) sq_thresh->lower_threshold[index];
1343 break;
1344 }
1345 }
1346
1347 return threshold;
1348}
1349
1350static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1351 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1352{
1353 struct sk_buff *skb;
1354 struct wmi_rssi_threshold_params_cmd *cmd;
1355
1356 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1357 if (!skb)
1358 return -ENOMEM;
1359
1360 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1361 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1362
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301363 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001364 NO_SYNC_WMIFLAG);
1365}
1366
1367static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1368 int len)
1369{
1370 struct wmi_rssi_threshold_event *reply;
1371 struct wmi_rssi_threshold_params_cmd cmd;
1372 struct sq_threshold_params *sq_thresh;
1373 enum wmi_rssi_threshold_val new_threshold;
1374 u8 upper_rssi_threshold, lower_rssi_threshold;
1375 s16 rssi;
1376 int ret;
1377
1378 if (len < sizeof(struct wmi_rssi_threshold_event))
1379 return -EINVAL;
1380
1381 reply = (struct wmi_rssi_threshold_event *) datap;
1382 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1383 rssi = a_sle16_to_cpu(reply->rssi);
1384
1385 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1386
1387 /*
1388 * Identify the threshold breached and communicate that to the app.
1389 * After that install a new set of thresholds based on the signal
1390 * quality reported by the target
1391 */
1392 if (new_threshold) {
1393 /* Upper threshold breached */
1394 if (rssi < sq_thresh->upper_threshold[0]) {
1395 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001396 "spurious upper rssi threshold event: %d\n",
1397 rssi);
Kalle Valobdcd8172011-07-18 00:22:30 +03001398 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1399 (rssi >= sq_thresh->upper_threshold[0])) {
1400 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1401 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1402 (rssi >= sq_thresh->upper_threshold[1])) {
1403 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1404 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1405 (rssi >= sq_thresh->upper_threshold[2])) {
1406 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1407 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1408 (rssi >= sq_thresh->upper_threshold[3])) {
1409 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1410 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1411 (rssi >= sq_thresh->upper_threshold[4])) {
1412 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1413 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1414 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1415 }
1416 } else {
1417 /* Lower threshold breached */
1418 if (rssi > sq_thresh->lower_threshold[0]) {
1419 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001420 "spurious lower rssi threshold event: %d %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +03001421 rssi, sq_thresh->lower_threshold[0]);
1422 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1423 (rssi <= sq_thresh->lower_threshold[0])) {
1424 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1425 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1426 (rssi <= sq_thresh->lower_threshold[1])) {
1427 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1428 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1429 (rssi <= sq_thresh->lower_threshold[2])) {
1430 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1431 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1432 (rssi <= sq_thresh->lower_threshold[3])) {
1433 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1434 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1435 (rssi <= sq_thresh->lower_threshold[4])) {
1436 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1437 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1438 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1439 }
1440 }
1441
1442 /* Calculate and install the next set of thresholds */
1443 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1444 sq_thresh->lower_threshold_valid_count);
1445 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1446 sq_thresh->upper_threshold_valid_count);
1447
1448 /* Issue a wmi command to install the thresholds */
1449 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1450 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1451 cmd.weight = sq_thresh->weight;
1452 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1453
1454 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1455 if (ret) {
1456 ath6kl_err("unable to configure rssi thresholds\n");
1457 return -EIO;
1458 }
1459
1460 return 0;
1461}
1462
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301463static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1464 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001465{
1466 struct wmi_cac_event *reply;
1467 struct ieee80211_tspec_ie *ts;
1468 u16 active_tsids, tsinfo;
1469 u8 tsid, index;
1470 u8 ts_id;
1471
1472 if (len < sizeof(struct wmi_cac_event))
1473 return -EINVAL;
1474
1475 reply = (struct wmi_cac_event *) datap;
1476
1477 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1478 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1479
1480 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1481 tsinfo = le16_to_cpu(ts->tsinfo);
1482 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1483 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1484
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301485 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1486 reply->ac, tsid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001487 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1488 /*
1489 * Following assumes that there is only one outstanding
1490 * ADDTS request when this event is received
1491 */
1492 spin_lock_bh(&wmi->lock);
1493 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1494 spin_unlock_bh(&wmi->lock);
1495
1496 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1497 if ((active_tsids >> index) & 1)
1498 break;
1499 }
1500 if (index < (sizeof(active_tsids) * 8))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301501 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1502 reply->ac, index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001503 }
1504
1505 /*
1506 * Clear active tsids and Add missing handling
1507 * for delete qos stream from AP
1508 */
1509 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1510
1511 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1512 tsinfo = le16_to_cpu(ts->tsinfo);
1513 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1514 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1515
1516 spin_lock_bh(&wmi->lock);
1517 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1518 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1519 spin_unlock_bh(&wmi->lock);
1520
1521 /* Indicate stream inactivity to driver layer only if all tsids
1522 * within this AC are deleted.
1523 */
1524 if (!active_tsids) {
1525 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1526 false);
1527 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1528 }
1529 }
1530
1531 return 0;
1532}
1533
Thomas Pedersen279b2862012-07-17 19:39:55 -07001534static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
1535 struct ath6kl_vif *vif)
1536{
1537 struct wmi_txe_notify_event *ev;
1538 u32 rate, pkts;
1539
1540 if (len < sizeof(*ev))
1541 return -EINVAL;
1542
1543 if (vif->sme_state != SME_CONNECTED)
1544 return -ENOTCONN;
1545
1546 ev = (struct wmi_txe_notify_event *) datap;
1547 rate = le32_to_cpu(ev->rate);
1548 pkts = le32_to_cpu(ev->pkts);
1549
1550 ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d% pkts %d intvl %ds\n",
1551 vif->bssid, rate, pkts, vif->txe_intvl);
1552
1553 cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
1554 rate, vif->txe_intvl, GFP_KERNEL);
1555
1556 return 0;
1557}
1558
1559int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
1560 u32 rate, u32 pkts, u32 intvl)
1561{
1562 struct sk_buff *skb;
1563 struct wmi_txe_notify_cmd *cmd;
1564
1565 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1566 if (!skb)
1567 return -ENOMEM;
1568
1569 cmd = (struct wmi_txe_notify_cmd *) skb->data;
1570 cmd->rate = cpu_to_le32(rate);
1571 cmd->pkts = cpu_to_le32(pkts);
1572 cmd->intvl = cpu_to_le32(intvl);
1573
1574 return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
1575 NO_SYNC_WMIFLAG);
1576}
1577
Thomas Pedersen85b20fc2012-06-21 12:50:08 -07001578int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
1579{
1580 struct sk_buff *skb;
1581 struct wmi_set_rssi_filter_cmd *cmd;
1582 int ret;
1583
1584 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1585 if (!skb)
1586 return -ENOMEM;
1587
1588 cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
1589 cmd->rssi = rssi;
1590
1591 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
1592 NO_SYNC_WMIFLAG);
1593 return ret;
1594}
1595
Kalle Valobdcd8172011-07-18 00:22:30 +03001596static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1597 struct wmi_snr_threshold_params_cmd *snr_cmd)
1598{
1599 struct sk_buff *skb;
1600 struct wmi_snr_threshold_params_cmd *cmd;
1601
1602 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1603 if (!skb)
1604 return -ENOMEM;
1605
1606 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1607 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1608
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301609 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001610 NO_SYNC_WMIFLAG);
1611}
1612
1613static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1614 int len)
1615{
1616 struct wmi_snr_threshold_event *reply;
1617 struct sq_threshold_params *sq_thresh;
1618 struct wmi_snr_threshold_params_cmd cmd;
1619 enum wmi_snr_threshold_val new_threshold;
1620 u8 upper_snr_threshold, lower_snr_threshold;
1621 s16 snr;
1622 int ret;
1623
1624 if (len < sizeof(struct wmi_snr_threshold_event))
1625 return -EINVAL;
1626
1627 reply = (struct wmi_snr_threshold_event *) datap;
1628
1629 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1630 snr = reply->snr;
1631
1632 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1633
1634 /*
1635 * Identify the threshold breached and communicate that to the app.
1636 * After that install a new set of thresholds based on the signal
1637 * quality reported by the target.
1638 */
1639 if (new_threshold) {
1640 /* Upper threshold breached */
1641 if (snr < sq_thresh->upper_threshold[0]) {
1642 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001643 "spurious upper snr threshold event: %d\n",
1644 snr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001645 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1646 (snr >= sq_thresh->upper_threshold[0])) {
1647 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1648 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1649 (snr >= sq_thresh->upper_threshold[1])) {
1650 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1651 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1652 (snr >= sq_thresh->upper_threshold[2])) {
1653 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1654 } else if (snr >= sq_thresh->upper_threshold[3]) {
1655 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1656 }
1657 } else {
1658 /* Lower threshold breached */
1659 if (snr > sq_thresh->lower_threshold[0]) {
1660 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001661 "spurious lower snr threshold event: %d\n",
1662 sq_thresh->lower_threshold[0]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001663 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1664 (snr <= sq_thresh->lower_threshold[0])) {
1665 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1666 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1667 (snr <= sq_thresh->lower_threshold[1])) {
1668 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1669 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1670 (snr <= sq_thresh->lower_threshold[2])) {
1671 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1672 } else if (snr <= sq_thresh->lower_threshold[3]) {
1673 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1674 }
1675 }
1676
1677 /* Calculate and install the next set of thresholds */
1678 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1679 sq_thresh->lower_threshold_valid_count);
1680 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1681 sq_thresh->upper_threshold_valid_count);
1682
1683 /* Issue a wmi command to install the thresholds */
1684 cmd.thresh_above1_val = upper_snr_threshold;
1685 cmd.thresh_below1_val = lower_snr_threshold;
1686 cmd.weight = sq_thresh->weight;
1687 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1688
1689 ath6kl_dbg(ATH6KL_DBG_WMI,
1690 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1691 snr, new_threshold,
1692 lower_snr_threshold, upper_snr_threshold);
1693
1694 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1695 if (ret) {
1696 ath6kl_err("unable to configure snr threshold\n");
1697 return -EIO;
1698 }
1699
1700 return 0;
1701}
1702
1703static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1704{
1705 u16 ap_info_entry_size;
1706 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1707 struct wmi_ap_info_v1 *ap_info_v1;
1708 u8 index;
1709
1710 if (len < sizeof(struct wmi_aplist_event) ||
1711 ev->ap_list_ver != APLIST_VER1)
1712 return -EINVAL;
1713
1714 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1715 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1716
1717 ath6kl_dbg(ATH6KL_DBG_WMI,
1718 "number of APs in aplist event: %d\n", ev->num_ap);
1719
1720 if (len < (int) (sizeof(struct wmi_aplist_event) +
1721 (ev->num_ap - 1) * ap_info_entry_size))
1722 return -EINVAL;
1723
1724 /* AP list version 1 contents */
1725 for (index = 0; index < ev->num_ap; index++) {
1726 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1727 index, ap_info_v1->bssid, ap_info_v1->channel);
1728 ap_info_v1++;
1729 }
1730
1731 return 0;
1732}
1733
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301734int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +03001735 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1736{
1737 struct wmi_cmd_hdr *cmd_hdr;
1738 enum htc_endpoint_id ep_id = wmi->ep_id;
1739 int ret;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301740 u16 info1;
Kalle Valobdcd8172011-07-18 00:22:30 +03001741
Kalle Valo71f96ee2011-11-14 19:31:30 +02001742 if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1))))
Kalle Valobdcd8172011-07-18 00:22:30 +03001743 return -EINVAL;
1744
Kalle Valob9b6ee62011-09-27 14:31:21 +03001745 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1746 cmd_id, skb->len, sync_flag);
1747 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1748 skb->data, skb->len);
1749
Kalle Valobdcd8172011-07-18 00:22:30 +03001750 if (sync_flag >= END_WMIFLAG) {
1751 dev_kfree_skb(skb);
1752 return -EINVAL;
1753 }
1754
1755 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1756 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1757 /*
1758 * Make sure all data currently queued is transmitted before
1759 * the cmd execution. Establish a new sync point.
1760 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301761 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001762 }
1763
1764 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1765
1766 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1767 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301768 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1769 cmd_hdr->info1 = cpu_to_le16(info1);
Kalle Valobdcd8172011-07-18 00:22:30 +03001770
1771 /* Only for OPT_TX_CMD, use BE endpoint. */
1772 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1773 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301774 false, false, 0, NULL, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001775 if (ret) {
1776 dev_kfree_skb(skb);
1777 return ret;
1778 }
1779 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1780 }
1781
1782 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1783
1784 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1785 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1786 /*
1787 * Make sure all new data queued waits for the command to
1788 * execute. Establish a new sync point.
1789 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301790 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001791 }
1792
1793 return 0;
1794}
1795
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301796int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1797 enum network_type nw_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001798 enum dot11_auth_mode dot11_auth_mode,
1799 enum auth_mode auth_mode,
1800 enum crypto_type pairwise_crypto,
1801 u8 pairwise_crypto_len,
1802 enum crypto_type group_crypto,
1803 u8 group_crypto_len, int ssid_len, u8 *ssid,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001804 u8 *bssid, u16 channel, u32 ctrl_flags,
1805 u8 nw_subtype)
Kalle Valobdcd8172011-07-18 00:22:30 +03001806{
1807 struct sk_buff *skb;
1808 struct wmi_connect_cmd *cc;
1809 int ret;
1810
Kalle Valob9b6ee62011-09-27 14:31:21 +03001811 ath6kl_dbg(ATH6KL_DBG_WMI,
1812 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1813 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1814 bssid, channel, ctrl_flags, ssid_len, nw_type,
1815 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1816 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1817
Kalle Valobdcd8172011-07-18 00:22:30 +03001818 wmi->traffic_class = 100;
1819
1820 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1821 return -EINVAL;
1822
1823 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1824 return -EINVAL;
1825
1826 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1827 if (!skb)
1828 return -ENOMEM;
1829
1830 cc = (struct wmi_connect_cmd *) skb->data;
1831
1832 if (ssid_len)
1833 memcpy(cc->ssid, ssid, ssid_len);
1834
1835 cc->ssid_len = ssid_len;
1836 cc->nw_type = nw_type;
1837 cc->dot11_auth_mode = dot11_auth_mode;
1838 cc->auth_mode = auth_mode;
1839 cc->prwise_crypto_type = pairwise_crypto;
1840 cc->prwise_crypto_len = pairwise_crypto_len;
1841 cc->grp_crypto_type = group_crypto;
1842 cc->grp_crypto_len = group_crypto_len;
1843 cc->ch = cpu_to_le16(channel);
1844 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001845 cc->nw_subtype = nw_subtype;
Kalle Valobdcd8172011-07-18 00:22:30 +03001846
1847 if (bssid != NULL)
1848 memcpy(cc->bssid, bssid, ETH_ALEN);
1849
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301850 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1851 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001852
1853 return ret;
1854}
1855
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301856int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1857 u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +03001858{
1859 struct sk_buff *skb;
1860 struct wmi_reconnect_cmd *cc;
1861 int ret;
1862
Kalle Valob9b6ee62011-09-27 14:31:21 +03001863 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1864 bssid, channel);
1865
Kalle Valobdcd8172011-07-18 00:22:30 +03001866 wmi->traffic_class = 100;
1867
1868 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1869 if (!skb)
1870 return -ENOMEM;
1871
1872 cc = (struct wmi_reconnect_cmd *) skb->data;
1873 cc->channel = cpu_to_le16(channel);
1874
1875 if (bssid != NULL)
1876 memcpy(cc->bssid, bssid, ETH_ALEN);
1877
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301878 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001879 NO_SYNC_WMIFLAG);
1880
1881 return ret;
1882}
1883
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301884int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03001885{
1886 int ret;
1887
Kalle Valob9b6ee62011-09-27 14:31:21 +03001888 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1889
Kalle Valobdcd8172011-07-18 00:22:30 +03001890 wmi->traffic_class = 100;
1891
1892 /* Disconnect command does not need to do a SYNC before. */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301893 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03001894
1895 return ret;
1896}
1897
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001898int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
1899 enum wmi_scan_type scan_type,
1900 u32 force_fgscan, u32 is_legacy,
1901 u32 home_dwell_time, u32 force_scan_interval,
1902 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
1903{
Thomas Pedersen03e20842012-04-24 12:50:41 -07001904 struct ieee80211_supported_band *sband;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001905 struct sk_buff *skb;
1906 struct wmi_begin_scan_cmd *sc;
Thomas Pedersen03e20842012-04-24 12:50:41 -07001907 s8 size, *supp_rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001908 int i, band, ret;
1909 struct ath6kl *ar = wmi->parent_dev;
1910 int num_rates;
Thomas Pedersen03e20842012-04-24 12:50:41 -07001911 u32 ratemask;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001912
1913 size = sizeof(struct wmi_begin_scan_cmd);
1914
1915 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1916 return -EINVAL;
1917
1918 if (num_chan > WMI_MAX_CHANNELS)
1919 return -EINVAL;
1920
1921 if (num_chan)
1922 size += sizeof(u16) * (num_chan - 1);
1923
1924 skb = ath6kl_wmi_get_new_buf(size);
1925 if (!skb)
1926 return -ENOMEM;
1927
1928 sc = (struct wmi_begin_scan_cmd *) skb->data;
1929 sc->scan_type = scan_type;
1930 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1931 sc->is_legacy = cpu_to_le32(is_legacy);
1932 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1933 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1934 sc->no_cck = cpu_to_le32(no_cck);
1935 sc->num_ch = num_chan;
1936
1937 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
Thomas Pedersen03e20842012-04-24 12:50:41 -07001938 sband = ar->wiphy->bands[band];
1939
1940 if (!sband)
1941 continue;
1942
1943 ratemask = rates[band];
1944 supp_rates = sc->supp_rates[band].rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001945 num_rates = 0;
1946
1947 for (i = 0; i < sband->n_bitrates; i++) {
1948 if ((BIT(i) & ratemask) == 0)
1949 continue; /* skip rate */
1950 supp_rates[num_rates++] =
1951 (u8) (sband->bitrates[i].bitrate / 5);
1952 }
1953 sc->supp_rates[band].nrates = num_rates;
1954 }
1955
1956 for (i = 0; i < num_chan; i++)
1957 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1958
1959 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
1960 NO_SYNC_WMIFLAG);
1961
1962 return ret;
1963}
1964
1965/* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1966 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1967 * mgmt operations using station interface.
1968 */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301969int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1970 enum wmi_scan_type scan_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001971 u32 force_fgscan, u32 is_legacy,
1972 u32 home_dwell_time, u32 force_scan_interval,
1973 s8 num_chan, u16 *ch_list)
1974{
1975 struct sk_buff *skb;
1976 struct wmi_start_scan_cmd *sc;
1977 s8 size;
Edward Lu1276c9e2011-08-30 21:58:00 +03001978 int i, ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03001979
1980 size = sizeof(struct wmi_start_scan_cmd);
1981
1982 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1983 return -EINVAL;
1984
1985 if (num_chan > WMI_MAX_CHANNELS)
1986 return -EINVAL;
1987
1988 if (num_chan)
1989 size += sizeof(u16) * (num_chan - 1);
1990
1991 skb = ath6kl_wmi_get_new_buf(size);
1992 if (!skb)
1993 return -ENOMEM;
1994
1995 sc = (struct wmi_start_scan_cmd *) skb->data;
1996 sc->scan_type = scan_type;
1997 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1998 sc->is_legacy = cpu_to_le32(is_legacy);
1999 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
2000 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
2001 sc->num_ch = num_chan;
2002
Edward Lu1276c9e2011-08-30 21:58:00 +03002003 for (i = 0; i < num_chan; i++)
2004 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
Kalle Valobdcd8172011-07-18 00:22:30 +03002005
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302006 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002007 NO_SYNC_WMIFLAG);
2008
2009 return ret;
2010}
2011
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302012int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
2013 u16 fg_start_sec,
Kalle Valobdcd8172011-07-18 00:22:30 +03002014 u16 fg_end_sec, u16 bg_sec,
2015 u16 minact_chdw_msec, u16 maxact_chdw_msec,
2016 u16 pas_chdw_msec, u8 short_scan_ratio,
2017 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
2018 u16 maxact_scan_per_ssid)
2019{
2020 struct sk_buff *skb;
2021 struct wmi_scan_params_cmd *sc;
2022 int ret;
2023
2024 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2025 if (!skb)
2026 return -ENOMEM;
2027
2028 sc = (struct wmi_scan_params_cmd *) skb->data;
2029 sc->fg_start_period = cpu_to_le16(fg_start_sec);
2030 sc->fg_end_period = cpu_to_le16(fg_end_sec);
2031 sc->bg_period = cpu_to_le16(bg_sec);
2032 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
2033 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
2034 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
2035 sc->short_scan_ratio = short_scan_ratio;
2036 sc->scan_ctrl_flags = scan_ctrl_flag;
2037 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
2038 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
2039
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302040 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002041 NO_SYNC_WMIFLAG);
2042 return ret;
2043}
2044
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302045int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
Kalle Valobdcd8172011-07-18 00:22:30 +03002046{
2047 struct sk_buff *skb;
2048 struct wmi_bss_filter_cmd *cmd;
2049 int ret;
2050
2051 if (filter >= LAST_BSS_FILTER)
2052 return -EINVAL;
2053
2054 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2055 if (!skb)
2056 return -ENOMEM;
2057
2058 cmd = (struct wmi_bss_filter_cmd *) skb->data;
2059 cmd->bss_filter = filter;
2060 cmd->ie_mask = cpu_to_le32(ie_mask);
2061
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302062 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002063 NO_SYNC_WMIFLAG);
2064 return ret;
2065}
2066
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302067int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
Kalle Valobdcd8172011-07-18 00:22:30 +03002068 u8 ssid_len, u8 *ssid)
2069{
2070 struct sk_buff *skb;
2071 struct wmi_probed_ssid_cmd *cmd;
2072 int ret;
2073
Jouni Malinen8ab54152012-05-09 22:14:51 +03002074 if (index >= MAX_PROBED_SSIDS)
Kalle Valobdcd8172011-07-18 00:22:30 +03002075 return -EINVAL;
2076
2077 if (ssid_len > sizeof(cmd->ssid))
2078 return -EINVAL;
2079
2080 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
2081 return -EINVAL;
2082
2083 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
2084 return -EINVAL;
2085
2086 if (flag & SPECIFIC_SSID_FLAG)
2087 wmi->is_probe_ssid = true;
2088
2089 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2090 if (!skb)
2091 return -ENOMEM;
2092
2093 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2094 cmd->entry_index = index;
2095 cmd->flag = flag;
2096 cmd->ssid_len = ssid_len;
2097 memcpy(cmd->ssid, ssid, ssid_len);
2098
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302099 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002100 NO_SYNC_WMIFLAG);
2101 return ret;
2102}
2103
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302104int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2105 u16 listen_interval,
Kalle Valobdcd8172011-07-18 00:22:30 +03002106 u16 listen_beacons)
2107{
2108 struct sk_buff *skb;
2109 struct wmi_listen_int_cmd *cmd;
2110 int ret;
2111
2112 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2113 if (!skb)
2114 return -ENOMEM;
2115
2116 cmd = (struct wmi_listen_int_cmd *) skb->data;
2117 cmd->listen_intvl = cpu_to_le16(listen_interval);
2118 cmd->num_beacons = cpu_to_le16(listen_beacons);
2119
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302120 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002121 NO_SYNC_WMIFLAG);
2122 return ret;
2123}
2124
Raja Manice0dc0c2012-02-20 19:08:08 +05302125int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2126 u16 bmiss_time, u16 num_beacons)
2127{
2128 struct sk_buff *skb;
2129 struct wmi_bmiss_time_cmd *cmd;
2130 int ret;
2131
2132 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2133 if (!skb)
2134 return -ENOMEM;
2135
2136 cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2137 cmd->bmiss_time = cpu_to_le16(bmiss_time);
2138 cmd->num_beacons = cpu_to_le16(num_beacons);
2139
2140 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2141 NO_SYNC_WMIFLAG);
2142 return ret;
2143}
2144
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302145int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
Kalle Valobdcd8172011-07-18 00:22:30 +03002146{
2147 struct sk_buff *skb;
2148 struct wmi_power_mode_cmd *cmd;
2149 int ret;
2150
2151 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2152 if (!skb)
2153 return -ENOMEM;
2154
2155 cmd = (struct wmi_power_mode_cmd *) skb->data;
2156 cmd->pwr_mode = pwr_mode;
2157 wmi->pwr_mode = pwr_mode;
2158
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302159 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002160 NO_SYNC_WMIFLAG);
2161 return ret;
2162}
2163
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302164int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
Kalle Valobdcd8172011-07-18 00:22:30 +03002165 u16 ps_poll_num, u16 dtim_policy,
2166 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2167 u16 ps_fail_event_policy)
2168{
2169 struct sk_buff *skb;
2170 struct wmi_power_params_cmd *pm;
2171 int ret;
2172
2173 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2174 if (!skb)
2175 return -ENOMEM;
2176
2177 pm = (struct wmi_power_params_cmd *)skb->data;
2178 pm->idle_period = cpu_to_le16(idle_period);
2179 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2180 pm->dtim_policy = cpu_to_le16(dtim_policy);
2181 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2182 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2183 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2184
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302185 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002186 NO_SYNC_WMIFLAG);
2187 return ret;
2188}
2189
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302190int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
Kalle Valobdcd8172011-07-18 00:22:30 +03002191{
2192 struct sk_buff *skb;
2193 struct wmi_disc_timeout_cmd *cmd;
2194 int ret;
2195
2196 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2197 if (!skb)
2198 return -ENOMEM;
2199
2200 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2201 cmd->discon_timeout = timeout;
2202
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302203 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002204 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302205
Jouni Malinenff0b0072011-10-11 17:31:56 +03002206 if (ret == 0)
2207 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302208
Kalle Valobdcd8172011-07-18 00:22:30 +03002209 return ret;
2210}
2211
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302212int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
Kalle Valobdcd8172011-07-18 00:22:30 +03002213 enum crypto_type key_type,
2214 u8 key_usage, u8 key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002215 u8 *key_rsc, unsigned int key_rsc_len,
2216 u8 *key_material,
Kalle Valobdcd8172011-07-18 00:22:30 +03002217 u8 key_op_ctrl, u8 *mac_addr,
2218 enum wmi_sync_flag sync_flag)
2219{
2220 struct sk_buff *skb;
2221 struct wmi_add_cipher_key_cmd *cmd;
2222 int ret;
2223
Kalle Valocdeb8602012-04-12 11:02:18 +03002224 ath6kl_dbg(ATH6KL_DBG_WMI,
2225 "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
Jouni Malinen9a5b1312011-08-30 21:57:52 +03002226 key_index, key_type, key_usage, key_len, key_op_ctrl);
2227
Kalle Valobdcd8172011-07-18 00:22:30 +03002228 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002229 (key_material == NULL) || key_rsc_len > 8)
Kalle Valobdcd8172011-07-18 00:22:30 +03002230 return -EINVAL;
2231
2232 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2233 return -EINVAL;
2234
2235 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2236 if (!skb)
2237 return -ENOMEM;
2238
2239 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2240 cmd->key_index = key_index;
2241 cmd->key_type = key_type;
2242 cmd->key_usage = key_usage;
2243 cmd->key_len = key_len;
2244 memcpy(cmd->key, key_material, key_len);
2245
2246 if (key_rsc != NULL)
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002247 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002248
2249 cmd->key_op_ctrl = key_op_ctrl;
2250
2251 if (mac_addr)
2252 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2253
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302254 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002255 sync_flag);
2256
2257 return ret;
2258}
2259
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302260int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
Kalle Valobdcd8172011-07-18 00:22:30 +03002261{
2262 struct sk_buff *skb;
2263 struct wmi_add_krk_cmd *cmd;
2264 int ret;
2265
2266 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2267 if (!skb)
2268 return -ENOMEM;
2269
2270 cmd = (struct wmi_add_krk_cmd *) skb->data;
2271 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2272
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302273 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302274 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002275
2276 return ret;
2277}
2278
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302279int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
Kalle Valobdcd8172011-07-18 00:22:30 +03002280{
2281 struct sk_buff *skb;
2282 struct wmi_delete_cipher_key_cmd *cmd;
2283 int ret;
2284
2285 if (key_index > WMI_MAX_KEY_INDEX)
2286 return -EINVAL;
2287
2288 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2289 if (!skb)
2290 return -ENOMEM;
2291
2292 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2293 cmd->key_index = key_index;
2294
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302295 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002296 NO_SYNC_WMIFLAG);
2297
2298 return ret;
2299}
2300
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302301int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002302 const u8 *pmkid, bool set)
2303{
2304 struct sk_buff *skb;
2305 struct wmi_setpmkid_cmd *cmd;
2306 int ret;
2307
2308 if (bssid == NULL)
2309 return -EINVAL;
2310
2311 if (set && pmkid == NULL)
2312 return -EINVAL;
2313
2314 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2315 if (!skb)
2316 return -ENOMEM;
2317
2318 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2319 memcpy(cmd->bssid, bssid, ETH_ALEN);
2320 if (set) {
2321 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2322 cmd->enable = PMKID_ENABLE;
2323 } else {
2324 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2325 cmd->enable = PMKID_DISABLE;
2326 }
2327
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302328 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002329 NO_SYNC_WMIFLAG);
2330
2331 return ret;
2332}
2333
2334static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302335 enum htc_endpoint_id ep_id, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002336{
2337 struct wmi_data_hdr *data_hdr;
2338 int ret;
2339
2340 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2341 return -EINVAL;
2342
2343 skb_push(skb, sizeof(struct wmi_data_hdr));
2344
2345 data_hdr = (struct wmi_data_hdr *) skb->data;
2346 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302347 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +03002348
2349 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2350
2351 return ret;
2352}
2353
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302354static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002355{
2356 struct sk_buff *skb;
2357 struct wmi_sync_cmd *cmd;
2358 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2359 enum htc_endpoint_id ep_id;
2360 u8 index, num_pri_streams = 0;
2361 int ret = 0;
2362
2363 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2364
2365 spin_lock_bh(&wmi->lock);
2366
2367 for (index = 0; index < WMM_NUM_AC; index++) {
2368 if (wmi->fat_pipe_exist & (1 << index)) {
2369 num_pri_streams++;
2370 data_sync_bufs[num_pri_streams - 1].traffic_class =
2371 index;
2372 }
2373 }
2374
2375 spin_unlock_bh(&wmi->lock);
2376
2377 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2378 if (!skb) {
2379 ret = -ENOMEM;
2380 goto free_skb;
2381 }
2382
2383 cmd = (struct wmi_sync_cmd *) skb->data;
2384
2385 /*
2386 * In the SYNC cmd sent on the control Ep, send a bitmap
2387 * of the data eps on which the Data Sync will be sent
2388 */
2389 cmd->data_sync_map = wmi->fat_pipe_exist;
2390
2391 for (index = 0; index < num_pri_streams; index++) {
2392 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2393 if (data_sync_bufs[index].skb == NULL) {
2394 ret = -ENOMEM;
2395 break;
2396 }
2397 }
2398
2399 /*
2400 * If buffer allocation for any of the dataSync fails,
2401 * then do not send the Synchronize cmd on the control ep
2402 */
2403 if (ret)
2404 goto free_skb;
2405
2406 /*
2407 * Send sync cmd followed by sync data messages on all
2408 * endpoints being used
2409 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302410 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002411 NO_SYNC_WMIFLAG);
2412
2413 if (ret)
2414 goto free_skb;
2415
2416 /* cmd buffer sent, we no longer own it */
2417 skb = NULL;
2418
2419 for (index = 0; index < num_pri_streams; index++) {
2420
2421 if (WARN_ON(!data_sync_bufs[index].skb))
2422 break;
2423
2424 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2425 data_sync_bufs[index].
2426 traffic_class);
2427 ret =
2428 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302429 ep_id, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03002430
2431 if (ret)
2432 break;
2433
2434 data_sync_bufs[index].skb = NULL;
2435 }
2436
2437free_skb:
2438 /* free up any resources left over (possibly due to an error) */
2439 if (skb)
2440 dev_kfree_skb(skb);
2441
2442 for (index = 0; index < num_pri_streams; index++) {
2443 if (data_sync_bufs[index].skb != NULL) {
2444 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2445 skb);
2446 }
2447 }
2448
2449 return ret;
2450}
2451
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302452int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +03002453 struct wmi_create_pstream_cmd *params)
2454{
2455 struct sk_buff *skb;
2456 struct wmi_create_pstream_cmd *cmd;
2457 u8 fatpipe_exist_for_ac = 0;
2458 s32 min_phy = 0;
2459 s32 nominal_phy = 0;
2460 int ret;
2461
2462 if (!((params->user_pri < 8) &&
2463 (params->user_pri <= 0x7) &&
2464 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2465 (params->traffic_direc == UPLINK_TRAFFIC ||
2466 params->traffic_direc == DNLINK_TRAFFIC ||
2467 params->traffic_direc == BIDIR_TRAFFIC) &&
2468 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2469 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2470 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2471 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2472 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2473 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2474 params->tsid <= WMI_MAX_THINSTREAM))) {
2475 return -EINVAL;
2476 }
2477
2478 /*
2479 * Check nominal PHY rate is >= minimalPHY,
2480 * so that DUT can allow TSRS IE
2481 */
2482
2483 /* Get the physical rate (units of bps) */
2484 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2485
2486 /* Check minimal phy < nominal phy rate */
2487 if (params->nominal_phy >= min_phy) {
2488 /* unit of 500 kbps */
2489 nominal_phy = (params->nominal_phy * 1000) / 500;
2490 ath6kl_dbg(ATH6KL_DBG_WMI,
2491 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2492 min_phy, nominal_phy);
2493
2494 params->nominal_phy = nominal_phy;
2495 } else {
2496 params->nominal_phy = 0;
2497 }
2498
2499 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2500 if (!skb)
2501 return -ENOMEM;
2502
2503 ath6kl_dbg(ATH6KL_DBG_WMI,
2504 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2505 params->traffic_class, params->tsid);
2506
2507 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2508 memcpy(cmd, params, sizeof(*cmd));
2509
2510 /* This is an implicitly created Fat pipe */
2511 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2512 spin_lock_bh(&wmi->lock);
2513 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2514 (1 << params->traffic_class));
2515 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2516 spin_unlock_bh(&wmi->lock);
2517 } else {
2518 /* explicitly created thin stream within a fat pipe */
2519 spin_lock_bh(&wmi->lock);
2520 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2521 (1 << params->traffic_class));
2522 wmi->stream_exist_for_ac[params->traffic_class] |=
2523 (1 << params->tsid);
2524 /*
2525 * If a thinstream becomes active, the fat pipe automatically
2526 * becomes active
2527 */
2528 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2529 spin_unlock_bh(&wmi->lock);
2530 }
2531
2532 /*
2533 * Indicate activty change to driver layer only if this is the
2534 * first TSID to get created in this AC explicitly or an implicit
2535 * fat pipe is getting created.
2536 */
2537 if (!fatpipe_exist_for_ac)
2538 ath6kl_indicate_tx_activity(wmi->parent_dev,
2539 params->traffic_class, true);
2540
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302541 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002542 NO_SYNC_WMIFLAG);
2543 return ret;
2544}
2545
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302546int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2547 u8 tsid)
Kalle Valobdcd8172011-07-18 00:22:30 +03002548{
2549 struct sk_buff *skb;
2550 struct wmi_delete_pstream_cmd *cmd;
2551 u16 active_tsids = 0;
2552 int ret;
2553
2554 if (traffic_class > 3) {
2555 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2556 return -EINVAL;
2557 }
2558
2559 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2560 if (!skb)
2561 return -ENOMEM;
2562
2563 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2564 cmd->traffic_class = traffic_class;
2565 cmd->tsid = tsid;
2566
2567 spin_lock_bh(&wmi->lock);
2568 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2569 spin_unlock_bh(&wmi->lock);
2570
2571 if (!(active_tsids & (1 << tsid))) {
2572 dev_kfree_skb(skb);
2573 ath6kl_dbg(ATH6KL_DBG_WMI,
2574 "TSID %d doesn't exist for traffic class: %d\n",
2575 tsid, traffic_class);
2576 return -ENODATA;
2577 }
2578
2579 ath6kl_dbg(ATH6KL_DBG_WMI,
2580 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2581 traffic_class, tsid);
2582
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302583 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002584 SYNC_BEFORE_WMIFLAG);
2585
2586 spin_lock_bh(&wmi->lock);
2587 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2588 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2589 spin_unlock_bh(&wmi->lock);
2590
2591 /*
2592 * Indicate stream inactivity to driver layer only if all tsids
2593 * within this AC are deleted.
2594 */
2595 if (!active_tsids) {
2596 ath6kl_indicate_tx_activity(wmi->parent_dev,
2597 traffic_class, false);
2598 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2599 }
2600
2601 return ret;
2602}
2603
Raja Manica1d16a2011-12-16 14:24:23 +05302604int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2605 __be32 ips0, __be32 ips1)
Kalle Valobdcd8172011-07-18 00:22:30 +03002606{
2607 struct sk_buff *skb;
2608 struct wmi_set_ip_cmd *cmd;
2609 int ret;
2610
2611 /* Multicast address are not valid */
Raja Manica1d16a2011-12-16 14:24:23 +05302612 if (ipv4_is_multicast(ips0) ||
2613 ipv4_is_multicast(ips1))
Kalle Valobdcd8172011-07-18 00:22:30 +03002614 return -EINVAL;
2615
2616 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2617 if (!skb)
2618 return -ENOMEM;
2619
2620 cmd = (struct wmi_set_ip_cmd *) skb->data;
Raja Manica1d16a2011-12-16 14:24:23 +05302621 cmd->ips[0] = ips0;
2622 cmd->ips[1] = ips1;
Kalle Valobdcd8172011-07-18 00:22:30 +03002623
Raja Manica1d16a2011-12-16 14:24:23 +05302624 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302625 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002626 return ret;
2627}
2628
Raja Mani45cf1102011-11-07 22:52:45 +02002629static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2630{
2631 u16 active_tsids;
2632 u8 stream_exist;
2633 int i;
2634
2635 /*
2636 * Relinquish credits from all implicitly created pstreams
2637 * since when we go to sleep. If user created explicit
2638 * thinstreams exists with in a fatpipe leave them intact
2639 * for the user to delete.
2640 */
2641 spin_lock_bh(&wmi->lock);
2642 stream_exist = wmi->fat_pipe_exist;
2643 spin_unlock_bh(&wmi->lock);
2644
2645 for (i = 0; i < WMM_NUM_AC; i++) {
2646 if (stream_exist & (1 << i)) {
2647
2648 /*
2649 * FIXME: Is this lock & unlock inside
2650 * for loop correct? may need rework.
2651 */
2652 spin_lock_bh(&wmi->lock);
2653 active_tsids = wmi->stream_exist_for_ac[i];
2654 spin_unlock_bh(&wmi->lock);
2655
2656 /*
2657 * If there are no user created thin streams
2658 * delete the fatpipe
2659 */
2660 if (!active_tsids) {
2661 stream_exist &= ~(1 << i);
2662 /*
2663 * Indicate inactivity to driver layer for
2664 * this fatpipe (pstream)
2665 */
2666 ath6kl_indicate_tx_activity(wmi->parent_dev,
2667 i, false);
2668 }
2669 }
2670 }
2671
2672 /* FIXME: Can we do this assignment without locking ? */
2673 spin_lock_bh(&wmi->lock);
2674 wmi->fat_pipe_exist = stream_exist;
2675 spin_unlock_bh(&wmi->lock);
2676}
2677
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302678static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
2679 const struct cfg80211_bitrate_mask *mask)
2680{
2681 struct sk_buff *skb;
2682 int ret, mode, band;
2683 u64 mcsrate, ratemask[IEEE80211_NUM_BANDS];
2684 struct wmi_set_tx_select_rates64_cmd *cmd;
2685
2686 memset(&ratemask, 0, sizeof(ratemask));
2687 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2688 /* copy legacy rate mask */
2689 ratemask[band] = mask->control[band].legacy;
2690 if (band == IEEE80211_BAND_5GHZ)
2691 ratemask[band] =
2692 mask->control[band].legacy << 4;
2693
2694 /* copy mcs rate mask */
2695 mcsrate = mask->control[band].mcs[1];
2696 mcsrate <<= 8;
2697 mcsrate |= mask->control[band].mcs[0];
2698 ratemask[band] |= mcsrate << 12;
2699 ratemask[band] |= mcsrate << 28;
2700 }
2701
2702 ath6kl_dbg(ATH6KL_DBG_WMI,
2703 "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
2704 ratemask[0], ratemask[1]);
2705
2706 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2707 if (!skb)
2708 return -ENOMEM;
2709
2710 cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
2711 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2712 /* A mode operate in 5GHZ band */
2713 if (mode == WMI_RATES_MODE_11A ||
2714 mode == WMI_RATES_MODE_11A_HT20 ||
2715 mode == WMI_RATES_MODE_11A_HT40)
2716 band = IEEE80211_BAND_5GHZ;
2717 else
2718 band = IEEE80211_BAND_2GHZ;
2719 cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
2720 }
2721
2722 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2723 WMI_SET_TX_SELECT_RATES_CMDID,
2724 NO_SYNC_WMIFLAG);
2725 return ret;
2726}
2727
2728static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
2729 const struct cfg80211_bitrate_mask *mask)
2730{
2731 struct sk_buff *skb;
2732 int ret, mode, band;
2733 u32 mcsrate, ratemask[IEEE80211_NUM_BANDS];
2734 struct wmi_set_tx_select_rates32_cmd *cmd;
2735
2736 memset(&ratemask, 0, sizeof(ratemask));
2737 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2738 /* copy legacy rate mask */
2739 ratemask[band] = mask->control[band].legacy;
2740 if (band == IEEE80211_BAND_5GHZ)
2741 ratemask[band] =
2742 mask->control[band].legacy << 4;
2743
2744 /* copy mcs rate mask */
2745 mcsrate = mask->control[band].mcs[0];
2746 ratemask[band] |= mcsrate << 12;
2747 ratemask[band] |= mcsrate << 20;
2748 }
2749
2750 ath6kl_dbg(ATH6KL_DBG_WMI,
2751 "Ratemask 32 bit: 2.4:%x 5:%x\n",
2752 ratemask[0], ratemask[1]);
2753
2754 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2755 if (!skb)
2756 return -ENOMEM;
2757
2758 cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
2759 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2760 /* A mode operate in 5GHZ band */
2761 if (mode == WMI_RATES_MODE_11A ||
2762 mode == WMI_RATES_MODE_11A_HT20 ||
2763 mode == WMI_RATES_MODE_11A_HT40)
2764 band = IEEE80211_BAND_5GHZ;
2765 else
2766 band = IEEE80211_BAND_2GHZ;
2767 cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
2768 }
2769
2770 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2771 WMI_SET_TX_SELECT_RATES_CMDID,
2772 NO_SYNC_WMIFLAG);
2773 return ret;
2774}
2775
2776int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
2777 const struct cfg80211_bitrate_mask *mask)
2778{
2779 struct ath6kl *ar = wmi->parent_dev;
2780
2781 if (ar->hw.flags & ATH6KL_HW_FLAG_64BIT_RATES)
2782 return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
2783 else
2784 return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
2785}
2786
Raja Mani45cf1102011-11-07 22:52:45 +02002787int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2788 enum ath6kl_host_mode host_mode)
2789{
2790 struct sk_buff *skb;
2791 struct wmi_set_host_sleep_mode_cmd *cmd;
2792 int ret;
2793
2794 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2795 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2796 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2797 return -EINVAL;
2798 }
2799
2800 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2801 if (!skb)
2802 return -ENOMEM;
2803
2804 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2805
2806 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2807 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2808 cmd->asleep = cpu_to_le32(1);
2809 } else
2810 cmd->awake = cpu_to_le32(1);
2811
2812 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2813 WMI_SET_HOST_SLEEP_MODE_CMDID,
2814 NO_SYNC_WMIFLAG);
2815 return ret;
2816}
2817
Raja Mani081c7a82012-01-30 17:13:11 +05302818/* This command has zero length payload */
2819static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2820 struct ath6kl_vif *vif)
2821{
2822 struct ath6kl *ar = wmi->parent_dev;
2823
2824 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2825 wake_up(&ar->event_wq);
2826
2827 return 0;
2828}
2829
Raja Mani45cf1102011-11-07 22:52:45 +02002830int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2831 enum ath6kl_wow_mode wow_mode,
2832 u32 filter, u16 host_req_delay)
2833{
2834 struct sk_buff *skb;
2835 struct wmi_set_wow_mode_cmd *cmd;
2836 int ret;
2837
2838 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
Kalle Valo96f1fad2012-03-07 20:03:57 +02002839 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
Raja Mani45cf1102011-11-07 22:52:45 +02002840 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2841 return -EINVAL;
2842 }
2843
2844 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2845 if (!skb)
2846 return -ENOMEM;
2847
2848 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2849 cmd->enable_wow = cpu_to_le32(wow_mode);
2850 cmd->filter = cpu_to_le32(filter);
2851 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2852
2853 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2854 NO_SYNC_WMIFLAG);
2855 return ret;
2856}
2857
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002858int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2859 u8 list_id, u8 filter_size,
Raja Manid91e8ee2012-01-30 17:13:10 +05302860 u8 filter_offset, const u8 *filter,
2861 const u8 *mask)
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002862{
2863 struct sk_buff *skb;
2864 struct wmi_add_wow_pattern_cmd *cmd;
2865 u16 size;
2866 u8 *filter_mask;
2867 int ret;
2868
2869 /*
2870 * Allocate additional memory in the buffer to hold
2871 * filter and mask value, which is twice of filter_size.
2872 */
2873 size = sizeof(*cmd) + (2 * filter_size);
2874
2875 skb = ath6kl_wmi_get_new_buf(size);
2876 if (!skb)
2877 return -ENOMEM;
2878
2879 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2880 cmd->filter_list_id = list_id;
2881 cmd->filter_size = filter_size;
2882 cmd->filter_offset = filter_offset;
2883
2884 memcpy(cmd->filter, filter, filter_size);
2885
2886 filter_mask = (u8 *) (cmd->filter + filter_size);
2887 memcpy(filter_mask, mask, filter_size);
2888
2889 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2890 NO_SYNC_WMIFLAG);
2891
2892 return ret;
2893}
2894
2895int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2896 u16 list_id, u16 filter_id)
2897{
2898 struct sk_buff *skb;
2899 struct wmi_del_wow_pattern_cmd *cmd;
2900 int ret;
2901
2902 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2903 if (!skb)
2904 return -ENOMEM;
2905
2906 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
2907 cmd->filter_list_id = cpu_to_le16(list_id);
2908 cmd->filter_id = cpu_to_le16(filter_id);
2909
2910 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
2911 NO_SYNC_WMIFLAG);
2912 return ret;
2913}
2914
Kalle Valobdcd8172011-07-18 00:22:30 +03002915static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2916 enum wmix_command_id cmd_id,
2917 enum wmi_sync_flag sync_flag)
2918{
2919 struct wmix_cmd_hdr *cmd_hdr;
2920 int ret;
2921
2922 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2923
2924 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2925 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2926
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302927 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03002928
2929 return ret;
2930}
2931
2932int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2933{
2934 struct sk_buff *skb;
2935 struct wmix_hb_challenge_resp_cmd *cmd;
2936 int ret;
2937
2938 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2939 if (!skb)
2940 return -ENOMEM;
2941
2942 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2943 cmd->cookie = cpu_to_le32(cookie);
2944 cmd->source = cpu_to_le32(source);
2945
2946 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2947 NO_SYNC_WMIFLAG);
2948 return ret;
2949}
2950
Kalle Valo939f1cc2011-09-02 10:32:04 +03002951int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2952{
2953 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2954 struct sk_buff *skb;
2955 int ret;
2956
2957 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2958 if (!skb)
2959 return -ENOMEM;
2960
2961 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2962 cmd->valid = cpu_to_le32(valid);
2963 cmd->config = cpu_to_le32(config);
2964
2965 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2966 NO_SYNC_WMIFLAG);
2967 return ret;
2968}
2969
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302970int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002971{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302972 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002973}
2974
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302975int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
Kalle Valobdcd8172011-07-18 00:22:30 +03002976{
2977 struct sk_buff *skb;
2978 struct wmi_set_tx_pwr_cmd *cmd;
2979 int ret;
2980
2981 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2982 if (!skb)
2983 return -ENOMEM;
2984
2985 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2986 cmd->dbM = dbM;
2987
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302988 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002989 NO_SYNC_WMIFLAG);
2990
2991 return ret;
2992}
2993
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302994int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002995{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302996 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002997}
2998
Jouni Malinen4b28a802011-10-11 17:31:54 +03002999int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
3000{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303001 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
Jouni Malinen4b28a802011-10-11 17:31:54 +03003002}
3003
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303004int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
3005 u8 preamble_policy)
Kalle Valobdcd8172011-07-18 00:22:30 +03003006{
3007 struct sk_buff *skb;
3008 struct wmi_set_lpreamble_cmd *cmd;
3009 int ret;
3010
3011 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
3012 if (!skb)
3013 return -ENOMEM;
3014
3015 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
3016 cmd->status = status;
3017 cmd->preamble_policy = preamble_policy;
3018
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303019 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003020 NO_SYNC_WMIFLAG);
3021 return ret;
3022}
3023
3024int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
3025{
3026 struct sk_buff *skb;
3027 struct wmi_set_rts_cmd *cmd;
3028 int ret;
3029
3030 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
3031 if (!skb)
3032 return -ENOMEM;
3033
3034 cmd = (struct wmi_set_rts_cmd *) skb->data;
3035 cmd->threshold = cpu_to_le16(threshold);
3036
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303037 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
3038 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03003039 return ret;
3040}
3041
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303042int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
Kalle Valobdcd8172011-07-18 00:22:30 +03003043{
3044 struct sk_buff *skb;
3045 struct wmi_set_wmm_txop_cmd *cmd;
3046 int ret;
3047
3048 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
3049 return -EINVAL;
3050
3051 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
3052 if (!skb)
3053 return -ENOMEM;
3054
3055 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
3056 cmd->txop_enable = cfg;
3057
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303058 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003059 NO_SYNC_WMIFLAG);
3060 return ret;
3061}
3062
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303063int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
3064 u8 keep_alive_intvl)
Kalle Valobdcd8172011-07-18 00:22:30 +03003065{
3066 struct sk_buff *skb;
3067 struct wmi_set_keepalive_cmd *cmd;
3068 int ret;
3069
3070 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3071 if (!skb)
3072 return -ENOMEM;
3073
3074 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
3075 cmd->keep_alive_intvl = keep_alive_intvl;
Kalle Valobdcd8172011-07-18 00:22:30 +03003076
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303077 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003078 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303079
Jouni Malinenff0b0072011-10-11 17:31:56 +03003080 if (ret == 0)
3081 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303082
Kalle Valobdcd8172011-07-18 00:22:30 +03003083 return ret;
3084}
3085
Vasanthakumar Thiagarajandf90b362012-04-09 19:03:58 +05303086int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
3087 enum ieee80211_band band,
3088 struct ath6kl_htcap *htcap)
3089{
3090 struct sk_buff *skb;
3091 struct wmi_set_htcap_cmd *cmd;
3092
3093 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3094 if (!skb)
3095 return -ENOMEM;
3096
3097 cmd = (struct wmi_set_htcap_cmd *) skb->data;
3098
3099 /*
3100 * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely
3101 * this will be changed in firmware. If at all there is any change in
3102 * band value, the host needs to be fixed.
3103 */
3104 cmd->band = band;
3105 cmd->ht_enable = !!htcap->ht_enable;
3106 cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
3107 cmd->ht40_supported =
3108 !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
3109 cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
3110 cmd->intolerant_40mhz =
3111 !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
3112 cmd->max_ampdu_len_exp = htcap->ampdu_factor;
3113
3114 ath6kl_dbg(ATH6KL_DBG_WMI,
3115 "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
3116 cmd->band, cmd->ht_enable, cmd->ht40_supported,
3117 cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
3118 cmd->max_ampdu_len_exp);
3119 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
3120 NO_SYNC_WMIFLAG);
3121}
3122
Kalle Valo003353b0d2011-09-01 10:14:21 +03003123int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
3124{
3125 struct sk_buff *skb;
3126 int ret;
3127
3128 skb = ath6kl_wmi_get_new_buf(len);
3129 if (!skb)
3130 return -ENOMEM;
3131
3132 memcpy(skb->data, buf, len);
3133
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303134 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003135
3136 return ret;
3137}
3138
Vasanthakumar Thiagarajan3f3c4ee2012-01-03 14:41:59 +05303139int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
3140{
3141 struct sk_buff *skb;
3142 struct wmi_mcast_filter_cmd *cmd;
3143 int ret;
3144
3145 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3146 if (!skb)
3147 return -ENOMEM;
3148
3149 cmd = (struct wmi_mcast_filter_cmd *) skb->data;
3150 cmd->mcast_all_enable = mc_all_on;
3151
3152 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
3153 NO_SYNC_WMIFLAG);
3154 return ret;
3155}
Kalle Valo003353b0d2011-09-01 10:14:21 +03003156
Vasanthakumar Thiagarajanf914edd2012-01-03 14:42:00 +05303157int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
3158 u8 *filter, bool add_filter)
3159{
3160 struct sk_buff *skb;
3161 struct wmi_mcast_filter_add_del_cmd *cmd;
3162 int ret;
3163
3164 if ((filter[0] != 0x33 || filter[1] != 0x33) &&
3165 (filter[0] != 0x01 || filter[1] != 0x00 ||
3166 filter[2] != 0x5e || filter[3] > 0x7f)) {
3167 ath6kl_warn("invalid multicast filter address\n");
3168 return -EINVAL;
3169 }
3170
3171 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3172 if (!skb)
3173 return -ENOMEM;
3174
3175 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
3176 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
3177 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3178 add_filter ? WMI_SET_MCAST_FILTER_CMDID :
3179 WMI_DEL_MCAST_FILTER_CMDID,
3180 NO_SYNC_WMIFLAG);
3181
3182 return ret;
3183}
3184
Thomas Pedersenc422d52d2012-05-15 00:09:23 -07003185int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
3186{
3187 struct sk_buff *skb;
3188 struct wmi_sta_bmiss_enhance_cmd *cmd;
3189 int ret;
3190
3191 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3192 if (!skb)
3193 return -ENOMEM;
3194
3195 cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
3196 cmd->enable = enhance ? 1 : 0;
3197
3198 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3199 WMI_STA_BMISS_ENHANCE_CMDID,
3200 NO_SYNC_WMIFLAG);
3201 return ret;
3202}
3203
Kalle Valobdcd8172011-07-18 00:22:30 +03003204s32 ath6kl_wmi_get_rate(s8 rate_index)
3205{
3206 if (rate_index == RATE_AUTO)
3207 return 0;
3208
3209 return wmi_rate_tbl[(u32) rate_index][0];
3210}
3211
Kalle Valobdcd8172011-07-18 00:22:30 +03003212static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
3213 u32 len)
3214{
3215 struct wmi_pmkid_list_reply *reply;
3216 u32 expected_len;
3217
3218 if (len < sizeof(struct wmi_pmkid_list_reply))
3219 return -EINVAL;
3220
3221 reply = (struct wmi_pmkid_list_reply *)datap;
3222 expected_len = sizeof(reply->num_pmkid) +
3223 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
3224
3225 if (len < expected_len)
3226 return -EINVAL;
3227
3228 return 0;
3229}
3230
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303231static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3232 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003233{
3234 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
3235
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303236 aggr_recv_addba_req_evt(vif, cmd->tid,
Kalle Valobdcd8172011-07-18 00:22:30 +03003237 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
3238
3239 return 0;
3240}
3241
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303242static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3243 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003244{
3245 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
3246
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303247 aggr_recv_delba_req_evt(vif, cmd->tid);
Kalle Valobdcd8172011-07-18 00:22:30 +03003248
3249 return 0;
3250}
3251
3252/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003253
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303254int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
3255 struct wmi_connect_cmd *p)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003256{
3257 struct sk_buff *skb;
3258 struct wmi_connect_cmd *cm;
3259 int res;
3260
3261 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3262 if (!skb)
3263 return -ENOMEM;
3264
3265 cm = (struct wmi_connect_cmd *) skb->data;
3266 memcpy(cm, p, sizeof(*cm));
3267
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303268 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003269 NO_SYNC_WMIFLAG);
Kalle Valocdeb8602012-04-12 11:02:18 +03003270 ath6kl_dbg(ATH6KL_DBG_WMI,
3271 "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003272 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
3273 le32_to_cpu(p->ctrl_flags), res);
3274 return res;
3275}
3276
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303277int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3278 u16 reason)
Jouni Malinen23875132011-08-30 21:57:53 +03003279{
3280 struct sk_buff *skb;
3281 struct wmi_ap_set_mlme_cmd *cm;
3282
3283 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3284 if (!skb)
3285 return -ENOMEM;
3286
3287 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
3288 memcpy(cm->mac, mac, ETH_ALEN);
3289 cm->reason = cpu_to_le16(reason);
3290 cm->cmd = cmd;
3291
Aarthi Thiruvengadam7397dde2012-03-15 14:36:11 -07003292 ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
3293 cm->reason);
3294
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303295 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
Jouni Malinen23875132011-08-30 21:57:53 +03003296 NO_SYNC_WMIFLAG);
3297}
3298
Thomas Pedersen67cd22e2012-02-28 15:08:46 -08003299int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
3300{
3301 struct sk_buff *skb;
3302 struct wmi_ap_hidden_ssid_cmd *cmd;
3303
3304 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3305 if (!skb)
3306 return -ENOMEM;
3307
3308 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
3309 cmd->hidden_ssid = enable ? 1 : 0;
3310
3311 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
3312 NO_SYNC_WMIFLAG);
3313}
3314
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05303315/* This command will be used to enable/disable AP uAPSD feature */
3316int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3317{
3318 struct wmi_ap_set_apsd_cmd *cmd;
3319 struct sk_buff *skb;
3320
3321 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3322 if (!skb)
3323 return -ENOMEM;
3324
3325 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3326 cmd->enable = enable;
3327
3328 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3329 NO_SYNC_WMIFLAG);
3330}
3331
3332int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3333 u16 aid, u16 bitmap, u32 flags)
3334{
3335 struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3336 struct sk_buff *skb;
3337
3338 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3339 if (!skb)
3340 return -ENOMEM;
3341
3342 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3343 cmd->aid = cpu_to_le16(aid);
3344 cmd->bitmap = cpu_to_le16(bitmap);
3345 cmd->flags = cpu_to_le32(flags);
3346
3347 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3348 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3349 NO_SYNC_WMIFLAG);
3350}
3351
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303352static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3353 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003354{
3355 struct wmi_pspoll_event *ev;
3356
3357 if (len < sizeof(struct wmi_pspoll_event))
3358 return -EINVAL;
3359
3360 ev = (struct wmi_pspoll_event *) datap;
3361
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303362 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
Kalle Valobdcd8172011-07-18 00:22:30 +03003363
3364 return 0;
3365}
3366
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303367static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3368 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003369{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303370 ath6kl_dtimexpiry_event(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03003371
3372 return 0;
3373}
3374
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303375int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3376 bool flag)
Kalle Valobdcd8172011-07-18 00:22:30 +03003377{
3378 struct sk_buff *skb;
3379 struct wmi_ap_set_pvb_cmd *cmd;
3380 int ret;
3381
3382 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3383 if (!skb)
3384 return -ENOMEM;
3385
3386 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3387 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03003388 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03003389 cmd->flag = cpu_to_le32(flag);
3390
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303391 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003392 NO_SYNC_WMIFLAG);
3393
3394 return 0;
3395}
3396
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303397int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
3398 u8 rx_meta_ver,
Kalle Valobdcd8172011-07-18 00:22:30 +03003399 bool rx_dot11_hdr, bool defrag_on_host)
3400{
3401 struct sk_buff *skb;
3402 struct wmi_rx_frame_format_cmd *cmd;
3403 int ret;
3404
3405 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3406 if (!skb)
3407 return -ENOMEM;
3408
3409 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3410 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3411 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3412 cmd->meta_ver = rx_meta_ver;
3413
3414 /* Delete the local aggr state, on host */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303415 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003416 NO_SYNC_WMIFLAG);
3417
3418 return ret;
3419}
3420
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303421int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3422 const u8 *ie, u8 ie_len)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003423{
3424 struct sk_buff *skb;
3425 struct wmi_set_appie_cmd *p;
3426
3427 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3428 if (!skb)
3429 return -ENOMEM;
3430
Kalle Valocdeb8602012-04-12 11:02:18 +03003431 ath6kl_dbg(ATH6KL_DBG_WMI,
3432 "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
3433 mgmt_frm_type, ie_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003434 p = (struct wmi_set_appie_cmd *) skb->data;
3435 p->mgmt_frm_type = mgmt_frm_type;
3436 p->ie_len = ie_len;
Kalle Valo10509f92011-12-13 14:52:07 +02003437
3438 if (ie != NULL && ie_len > 0)
3439 memcpy(p->ie_info, ie, ie_len);
3440
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303441 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003442 NO_SYNC_WMIFLAG);
3443}
3444
Vasanthakumar Thiagarajand97c1212012-04-09 20:51:20 +05303445int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
3446 const u8 *ie_info, u8 ie_len)
3447{
3448 struct sk_buff *skb;
3449 struct wmi_set_ie_cmd *p;
3450
3451 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3452 if (!skb)
3453 return -ENOMEM;
3454
3455 ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
3456 ie_id, ie_field, ie_len);
3457 p = (struct wmi_set_ie_cmd *) skb->data;
3458 p->ie_id = ie_id;
3459 p->ie_field = ie_field;
3460 p->ie_len = ie_len;
3461 if (ie_info && ie_len > 0)
3462 memcpy(p->ie_info, ie_info, ie_len);
3463
3464 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
3465 NO_SYNC_WMIFLAG);
3466}
3467
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003468int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
3469{
3470 struct sk_buff *skb;
3471 struct wmi_disable_11b_rates_cmd *cmd;
3472
3473 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3474 if (!skb)
3475 return -ENOMEM;
3476
3477 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
3478 disable);
3479 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
3480 cmd->disable = disable ? 1 : 0;
3481
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303482 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003483 NO_SYNC_WMIFLAG);
3484}
3485
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303486int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003487{
3488 struct sk_buff *skb;
3489 struct wmi_remain_on_chnl_cmd *p;
3490
3491 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3492 if (!skb)
3493 return -ENOMEM;
3494
3495 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3496 freq, dur);
3497 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3498 p->freq = cpu_to_le32(freq);
3499 p->duration = cpu_to_le32(dur);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303500 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003501 NO_SYNC_WMIFLAG);
3502}
3503
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003504/* ath6kl_wmi_send_action_cmd is to be deprecated. Use
3505 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
3506 * mgmt operations using station interface.
3507 */
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003508static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3509 u32 freq, u32 wait, const u8 *data,
3510 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003511{
3512 struct sk_buff *skb;
3513 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03003514 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003515
3516 if (wait)
3517 return -EINVAL; /* Offload for wait not supported */
3518
Jouni Malinena0df5db2011-08-30 21:58:02 +03003519 buf = kmalloc(data_len, GFP_KERNEL);
3520 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003521 return -ENOMEM;
3522
Jouni Malinena0df5db2011-08-30 21:58:02 +03003523 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3524 if (!skb) {
3525 kfree(buf);
3526 return -ENOMEM;
3527 }
3528
3529 kfree(wmi->last_mgmt_tx_frame);
Aarthi Thiruvengadam3101ede2011-10-27 09:35:56 -07003530 memcpy(buf, data, data_len);
Jouni Malinena0df5db2011-08-30 21:58:02 +03003531 wmi->last_mgmt_tx_frame = buf;
3532 wmi->last_mgmt_tx_frame_len = data_len;
3533
Kalle Valocdeb8602012-04-12 11:02:18 +03003534 ath6kl_dbg(ATH6KL_DBG_WMI,
3535 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3536 id, freq, wait, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003537 p = (struct wmi_send_action_cmd *) skb->data;
3538 p->id = cpu_to_le32(id);
3539 p->freq = cpu_to_le32(freq);
3540 p->wait = cpu_to_le32(wait);
3541 p->len = cpu_to_le16(data_len);
3542 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303543 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003544 NO_SYNC_WMIFLAG);
3545}
3546
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003547static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3548 u32 freq, u32 wait, const u8 *data,
3549 u16 data_len, u32 no_cck)
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003550{
3551 struct sk_buff *skb;
3552 struct wmi_send_mgmt_cmd *p;
3553 u8 *buf;
3554
3555 if (wait)
3556 return -EINVAL; /* Offload for wait not supported */
3557
3558 buf = kmalloc(data_len, GFP_KERNEL);
3559 if (!buf)
3560 return -ENOMEM;
3561
3562 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3563 if (!skb) {
3564 kfree(buf);
3565 return -ENOMEM;
3566 }
3567
3568 kfree(wmi->last_mgmt_tx_frame);
3569 memcpy(buf, data, data_len);
3570 wmi->last_mgmt_tx_frame = buf;
3571 wmi->last_mgmt_tx_frame_len = data_len;
3572
Kalle Valocdeb8602012-04-12 11:02:18 +03003573 ath6kl_dbg(ATH6KL_DBG_WMI,
3574 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3575 id, freq, wait, data_len);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003576 p = (struct wmi_send_mgmt_cmd *) skb->data;
3577 p->id = cpu_to_le32(id);
3578 p->freq = cpu_to_le32(freq);
3579 p->wait = cpu_to_le32(wait);
3580 p->no_cck = cpu_to_le32(no_cck);
3581 p->len = cpu_to_le16(data_len);
3582 memcpy(p->data, data, data_len);
3583 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
3584 NO_SYNC_WMIFLAG);
3585}
3586
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003587int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3588 u32 wait, const u8 *data, u16 data_len,
3589 u32 no_cck)
3590{
3591 int status;
3592 struct ath6kl *ar = wmi->parent_dev;
3593
3594 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3595 ar->fw_capabilities)) {
3596 /*
3597 * If capable of doing P2P mgmt operations using
3598 * station interface, send additional information like
3599 * supported rates to advertise and xmit rates for
3600 * probe requests
3601 */
3602 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3603 wait, data, data_len,
3604 no_cck);
3605 } else {
3606 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3607 wait, data, data_len);
3608 }
3609
3610 return status;
3611}
3612
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303613int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3614 const u8 *dst, const u8 *data,
3615 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003616{
3617 struct sk_buff *skb;
3618 struct wmi_p2p_probe_response_cmd *p;
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003619 size_t cmd_len = sizeof(*p) + data_len;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003620
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003621 if (data_len == 0)
3622 cmd_len++; /* work around target minimum length requirement */
3623
3624 skb = ath6kl_wmi_get_new_buf(cmd_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003625 if (!skb)
3626 return -ENOMEM;
3627
Kalle Valocdeb8602012-04-12 11:02:18 +03003628 ath6kl_dbg(ATH6KL_DBG_WMI,
3629 "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
3630 freq, dst, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003631 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3632 p->freq = cpu_to_le32(freq);
3633 memcpy(p->destination_addr, dst, ETH_ALEN);
3634 p->len = cpu_to_le16(data_len);
3635 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303636 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3637 WMI_SEND_PROBE_RESPONSE_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003638 NO_SYNC_WMIFLAG);
3639}
3640
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303641int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003642{
3643 struct sk_buff *skb;
3644 struct wmi_probe_req_report_cmd *p;
3645
3646 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3647 if (!skb)
3648 return -ENOMEM;
3649
3650 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3651 enable);
3652 p = (struct wmi_probe_req_report_cmd *) skb->data;
3653 p->enable = enable ? 1 : 0;
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303654 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003655 NO_SYNC_WMIFLAG);
3656}
3657
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303658int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003659{
3660 struct sk_buff *skb;
3661 struct wmi_get_p2p_info *p;
3662
3663 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3664 if (!skb)
3665 return -ENOMEM;
3666
3667 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3668 info_req_flags);
3669 p = (struct wmi_get_p2p_info *) skb->data;
3670 p->info_req_flags = cpu_to_le32(info_req_flags);
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303671 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003672 NO_SYNC_WMIFLAG);
3673}
3674
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303675int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003676{
3677 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303678 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3679 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003680}
3681
Vasanthakumar Thiagarajan03bdeb02012-03-21 20:58:39 +05303682int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
3683{
3684 struct sk_buff *skb;
3685 struct wmi_set_inact_period_cmd *cmd;
3686
3687 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3688 if (!skb)
3689 return -ENOMEM;
3690
3691 cmd = (struct wmi_set_inact_period_cmd *) skb->data;
3692 cmd->inact_period = cpu_to_le32(inact_timeout);
3693 cmd->num_null_func = 0;
3694
3695 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
3696 NO_SYNC_WMIFLAG);
3697}
3698
Kalle Valobdcd8172011-07-18 00:22:30 +03003699static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3700{
3701 struct wmix_cmd_hdr *cmd;
3702 u32 len;
3703 u16 id;
3704 u8 *datap;
3705 int ret = 0;
3706
3707 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3708 ath6kl_err("bad packet 1\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003709 return -EINVAL;
3710 }
3711
3712 cmd = (struct wmix_cmd_hdr *) skb->data;
3713 id = le32_to_cpu(cmd->cmd_id);
3714
3715 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3716
3717 datap = skb->data;
3718 len = skb->len;
3719
3720 switch (id) {
3721 case WMIX_HB_CHALLENGE_RESP_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003722 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003723 break;
3724 case WMIX_DBGLOG_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003725 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
Kalle Valobdf53962011-09-02 10:32:04 +03003726 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003727 break;
3728 default:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003729 ath6kl_warn("unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03003730 ret = -EINVAL;
3731 break;
3732 }
3733
3734 return ret;
3735}
3736
Jouni Malinen4b28a802011-10-11 17:31:54 +03003737static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3738{
3739 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3740}
3741
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303742/* Process interface specific wmi events, caller would free the datap */
3743static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
3744 u8 *datap, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03003745{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303746 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03003747
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303748 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3749 if (!vif) {
3750 ath6kl_dbg(ATH6KL_DBG_WMI,
3751 "Wmi event for unavailable vif, vif_index:%d\n",
3752 if_idx);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303753 return -EINVAL;
3754 }
3755
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303756 switch (cmd_id) {
3757 case WMI_CONNECT_EVENTID:
3758 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3759 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3760 case WMI_DISCONNECT_EVENTID:
3761 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3762 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3763 case WMI_TKIP_MICERR_EVENTID:
3764 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3765 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3766 case WMI_BSSINFO_EVENTID:
3767 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3768 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3769 case WMI_NEIGHBOR_REPORT_EVENTID:
3770 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3771 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3772 vif);
3773 case WMI_SCAN_COMPLETE_EVENTID:
3774 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3775 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3776 case WMI_REPORT_STATISTICS_EVENTID:
3777 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3778 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3779 case WMI_CAC_EVENTID:
3780 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3781 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3782 case WMI_PSPOLL_EVENTID:
3783 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3784 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3785 case WMI_DTIMEXPIRY_EVENTID:
3786 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3787 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3788 case WMI_ADDBA_REQ_EVENTID:
3789 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3790 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3791 case WMI_DELBA_REQ_EVENTID:
3792 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3793 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3794 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
3795 ath6kl_dbg(ATH6KL_DBG_WMI,
3796 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
3797 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
3798 case WMI_REMAIN_ON_CHNL_EVENTID:
3799 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3800 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3801 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3802 ath6kl_dbg(ATH6KL_DBG_WMI,
3803 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3804 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3805 len, vif);
3806 case WMI_TX_STATUS_EVENTID:
3807 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3808 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3809 case WMI_RX_PROBE_REQ_EVENTID:
3810 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3811 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3812 case WMI_RX_ACTION_EVENTID:
3813 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3814 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
Thomas Pedersen279b2862012-07-17 19:39:55 -07003815 case WMI_TXE_NOTIFY_EVENTID:
3816 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
3817 return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303818 default:
3819 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
3820 return -EINVAL;
3821 }
3822
3823 return 0;
3824}
3825
3826static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
3827{
3828 struct wmi_cmd_hdr *cmd;
3829 int ret = 0;
3830 u32 len;
3831 u16 id;
3832 u8 if_idx;
3833 u8 *datap;
3834
3835 cmd = (struct wmi_cmd_hdr *) skb->data;
3836 id = le16_to_cpu(cmd->cmd_id);
3837 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
3838
3839 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3840 datap = skb->data;
3841 len = skb->len;
3842
3843 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3844 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3845 datap, len);
3846
Kalle Valobdcd8172011-07-18 00:22:30 +03003847 switch (id) {
3848 case WMI_GET_BITRATE_CMDID:
3849 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3850 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3851 break;
3852 case WMI_GET_CHANNEL_LIST_CMDID:
3853 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3854 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3855 break;
3856 case WMI_GET_TX_PWR_CMDID:
3857 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3858 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3859 break;
3860 case WMI_READY_EVENTID:
3861 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3862 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3863 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003864 case WMI_PEER_NODE_EVENTID:
3865 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3866 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3867 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003868 case WMI_REGDOMAIN_EVENTID:
3869 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05303870 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003871 break;
3872 case WMI_PSTREAM_TIMEOUT_EVENTID:
3873 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3874 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3875 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003876 case WMI_CMDERROR_EVENTID:
3877 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3878 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3879 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003880 case WMI_RSSI_THRESHOLD_EVENTID:
3881 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3882 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3883 break;
3884 case WMI_ERROR_REPORT_EVENTID:
3885 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3886 break;
3887 case WMI_OPT_RX_FRAME_EVENTID:
3888 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03003889 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03003890 break;
3891 case WMI_REPORT_ROAM_TBL_EVENTID:
3892 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
Jouni Malinen4b28a802011-10-11 17:31:54 +03003893 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003894 break;
3895 case WMI_EXTENSION_EVENTID:
3896 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3897 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3898 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003899 case WMI_CHANNEL_CHANGE_EVENTID:
3900 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3901 break;
3902 case WMI_REPORT_ROAM_DATA_EVENTID:
3903 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3904 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03003905 case WMI_TEST_EVENTID:
3906 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08003907 ret = ath6kl_wmi_test_rx(wmi, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003908 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003909 case WMI_GET_FIXRATES_CMDID:
3910 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3911 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3912 break;
3913 case WMI_TX_RETRY_ERR_EVENTID:
3914 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3915 break;
3916 case WMI_SNR_THRESHOLD_EVENTID:
3917 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3918 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3919 break;
3920 case WMI_LQ_THRESHOLD_EVENTID:
3921 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3922 break;
3923 case WMI_APLIST_EVENTID:
3924 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3925 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3926 break;
3927 case WMI_GET_KEEPALIVE_CMDID:
3928 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3929 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3930 break;
3931 case WMI_GET_WOW_LIST_EVENTID:
3932 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003933 break;
3934 case WMI_GET_PMKID_LIST_EVENTID:
3935 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3936 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3937 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003938 case WMI_SET_PARAMS_REPLY_EVENTID:
3939 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3940 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003941 case WMI_ADDBA_RESP_EVENTID:
3942 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3943 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003944 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3945 ath6kl_dbg(ATH6KL_DBG_WMI,
3946 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3947 break;
3948 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3949 ath6kl_dbg(ATH6KL_DBG_WMI,
3950 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3951 break;
3952 case WMI_TX_COMPLETE_EVENTID:
3953 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3954 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3955 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003956 case WMI_P2P_CAPABILITIES_EVENTID:
3957 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3958 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3959 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003960 case WMI_P2P_INFO_EVENTID:
3961 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3962 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3963 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003964 default:
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303965 /* may be the event is interface specific */
3966 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003967 break;
3968 }
3969
3970 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03003971 return ret;
3972}
3973
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303974/* Control Path */
3975int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
3976{
3977 if (WARN_ON(skb == NULL))
3978 return -EINVAL;
3979
3980 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
3981 ath6kl_err("bad packet 1\n");
3982 dev_kfree_skb(skb);
3983 return -EINVAL;
3984 }
3985
3986 return ath6kl_wmi_proc_events(wmi, skb);
3987}
3988
Kalle Valoc89c5912011-10-27 18:48:00 +03003989void ath6kl_wmi_reset(struct wmi *wmi)
Kalle Valobdcd8172011-07-18 00:22:30 +03003990{
Kalle Valobdcd8172011-07-18 00:22:30 +03003991 spin_lock_bh(&wmi->lock);
3992
3993 wmi->fat_pipe_exist = 0;
3994 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3995
3996 spin_unlock_bh(&wmi->lock);
3997}
3998
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05303999void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03004000{
4001 struct wmi *wmi;
4002
4003 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
4004 if (!wmi)
4005 return NULL;
4006
4007 spin_lock_init(&wmi->lock);
4008
4009 wmi->parent_dev = dev;
4010
Kalle Valobdcd8172011-07-18 00:22:30 +03004011 wmi->pwr_mode = REC_POWER;
Kalle Valobdcd8172011-07-18 00:22:30 +03004012
Kalle Valoc89c5912011-10-27 18:48:00 +03004013 ath6kl_wmi_reset(wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03004014
4015 return wmi;
4016}
4017
4018void ath6kl_wmi_shutdown(struct wmi *wmi)
4019{
4020 if (!wmi)
4021 return;
4022
Jouni Malinena0df5db2011-08-30 21:58:02 +03004023 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03004024 kfree(wmi);
4025}