blob: f4ef6a724e4c0e44ad0a0fbef55c05e1771c191b [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);
Raja Mani43a06b32012-09-21 15:08:53 +0530939 if (regpair)
940 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
941 regpair->regDmnEnum);
942 else
943 ath6kl_warn("Regpair not found reg_code 0x%0x\n",
944 reg_code);
Vivek Natarajan06033762011-09-06 13:01:36 +0530945 }
946
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +0530947 if (country && wmi->parent_dev->wiphy_registered) {
Vivek Natarajan06033762011-09-06 13:01:36 +0530948 alpha2[0] = country->isoName[0];
949 alpha2[1] = country->isoName[1];
950
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530951 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
Vivek Natarajan06033762011-09-06 13:01:36 +0530952
Kalle Valob9b6ee62011-09-27 14:31:21 +0300953 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +0200954 alpha2[0], alpha2[1]);
Vivek Natarajan06033762011-09-06 13:01:36 +0530955 }
956}
957
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530958static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
959 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300960{
961 struct wmi_disconnect_event *ev;
962 wmi->traffic_class = 100;
963
964 if (len < sizeof(struct wmi_disconnect_event))
965 return -EINVAL;
966
967 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300968
Kalle Valob9b6ee62011-09-27 14:31:21 +0300969 ath6kl_dbg(ATH6KL_DBG_WMI,
970 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
971 le16_to_cpu(ev->proto_reason_status), ev->bssid,
972 ev->disconn_reason, ev->assoc_resp_len);
973
Kalle Valobdcd8172011-07-18 00:22:30 +0300974 wmi->is_wmm_enabled = false;
Kalle Valobdcd8172011-07-18 00:22:30 +0300975
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530976 ath6kl_disconnect_event(vif, ev->disconn_reason,
Kalle Valobdcd8172011-07-18 00:22:30 +0300977 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
978 le16_to_cpu(ev->proto_reason_status));
979
980 return 0;
981}
982
983static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
984{
985 struct wmi_peer_node_event *ev;
986
987 if (len < sizeof(struct wmi_peer_node_event))
988 return -EINVAL;
989
990 ev = (struct wmi_peer_node_event *) datap;
991
992 if (ev->event_code == PEER_NODE_JOIN_EVENT)
993 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
994 ev->peer_mac_addr);
995 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
996 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
997 ev->peer_mac_addr);
998
999 return 0;
1000}
1001
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301002static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
1003 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001004{
1005 struct wmi_tkip_micerr_event *ev;
1006
1007 if (len < sizeof(struct wmi_tkip_micerr_event))
1008 return -EINVAL;
1009
1010 ev = (struct wmi_tkip_micerr_event *) datap;
1011
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301012 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
Kalle Valobdcd8172011-07-18 00:22:30 +03001013
1014 return 0;
1015}
1016
Kalle Valo10509f92011-12-13 14:52:07 +02001017void ath6kl_wmi_sscan_timer(unsigned long ptr)
1018{
1019 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
1020
1021 cfg80211_sched_scan_results(vif->ar->wiphy);
1022}
1023
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301024static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
1025 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001026{
Jouni Malinen82e14f52011-09-19 19:15:05 +03001027 struct wmi_bss_info_hdr2 *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001028 u8 *buf;
1029 struct ieee80211_channel *channel;
1030 struct ath6kl *ar = wmi->parent_dev;
1031 struct ieee80211_mgmt *mgmt;
1032 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +03001033
Jouni Malinen82e14f52011-09-19 19:15:05 +03001034 if (len <= sizeof(struct wmi_bss_info_hdr2))
Kalle Valobdcd8172011-07-18 00:22:30 +03001035 return -EINVAL;
1036
Jouni Malinen82e14f52011-09-19 19:15:05 +03001037 bih = (struct wmi_bss_info_hdr2 *) datap;
1038 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1039 len -= sizeof(struct wmi_bss_info_hdr2);
Kalle Valobdcd8172011-07-18 00:22:30 +03001040
1041 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001042 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1043 "frame_type=%d\n",
Jouni Malinen82e14f52011-09-19 19:15:05 +03001044 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001045 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +03001046
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001047 if (bih->frame_type != BEACON_FTYPE &&
1048 bih->frame_type != PROBERESP_FTYPE)
1049 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +03001050
Jouni Malinen551185c2011-09-19 19:15:06 +03001051 if (bih->frame_type == BEACON_FTYPE &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301052 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1053 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301054 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1055 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001056 }
1057
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301058 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001059 if (channel == NULL)
1060 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001061
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001062 if (len < 8 + 2 + 2)
1063 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001064
Kalle Valoddc3d772012-03-07 20:03:58 +02001065 if (bih->frame_type == BEACON_FTYPE &&
1066 test_bit(CONNECTED, &vif->flags) &&
1067 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001068 const u8 *tim;
1069 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1070 len - 8 - 2 - 2);
1071 if (tim && tim[1] >= 2) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301072 vif->assoc_bss_dtim_period = tim[3];
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301073 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +03001074 }
1075 }
1076
Kalle Valobdcd8172011-07-18 00:22:30 +03001077 /*
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001078 * In theory, use of cfg80211_inform_bss() would be more natural here
1079 * since we do not have the full frame. However, at least for now,
1080 * cfg80211 can only distinguish Beacon and Probe Response frames from
1081 * each other when using cfg80211_inform_bss_frame(), so let's build a
1082 * fake IEEE 802.11 header to be able to take benefit of this.
Kalle Valobdcd8172011-07-18 00:22:30 +03001083 */
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001084 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1085 if (mgmt == NULL)
1086 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001087
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001088 if (bih->frame_type == BEACON_FTYPE) {
1089 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1090 IEEE80211_STYPE_BEACON);
1091 memset(mgmt->da, 0xff, ETH_ALEN);
1092 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301093 struct net_device *dev = vif->ndev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001094
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001095 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1096 IEEE80211_STYPE_PROBE_RESP);
1097 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +03001098 }
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001099 mgmt->duration = cpu_to_le16(0);
1100 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1101 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1102 mgmt->seq_ctrl = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001103
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001104 memcpy(&mgmt->u.beacon, buf, len);
1105
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301106 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
Jouni Malinen82e14f52011-09-19 19:15:05 +03001107 24 + len, (bih->snr - 95) * 100,
1108 GFP_ATOMIC);
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001109 kfree(mgmt);
1110 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +03001111 return -ENOMEM;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001112 cfg80211_put_bss(bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001113
Kalle Valo10509f92011-12-13 14:52:07 +02001114 /*
1115 * Firmware doesn't return any event when scheduled scan has
1116 * finished, so we need to use a timer to find out when there are
1117 * no more results.
1118 *
1119 * The timer is started from the first bss info received, otherwise
1120 * the timer would not ever fire if the scan interval is short
1121 * enough.
1122 */
Thomas Pedersenb1f47e32012-08-15 16:51:24 -07001123 if (test_bit(SCHED_SCANNING, &vif->flags) &&
Kalle Valo10509f92011-12-13 14:52:07 +02001124 !timer_pending(&vif->sched_scan_timer)) {
1125 mod_timer(&vif->sched_scan_timer, jiffies +
1126 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1127 }
1128
Kalle Valobdcd8172011-07-18 00:22:30 +03001129 return 0;
1130}
1131
Kalle Valobdcd8172011-07-18 00:22:30 +03001132/* Inactivity timeout of a fatpipe(pstream) at the target */
1133static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1134 int len)
1135{
1136 struct wmi_pstream_timeout_event *ev;
1137
1138 if (len < sizeof(struct wmi_pstream_timeout_event))
1139 return -EINVAL;
1140
1141 ev = (struct wmi_pstream_timeout_event *) datap;
1142
1143 /*
1144 * When the pstream (fat pipe == AC) timesout, it means there were
1145 * no thinStreams within this pstream & it got implicitly created
1146 * due to data flow on this AC. We start the inactivity timer only
1147 * for implicitly created pstream. Just reset the host state.
1148 */
1149 spin_lock_bh(&wmi->lock);
1150 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1151 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1152 spin_unlock_bh(&wmi->lock);
1153
1154 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1155 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1156
1157 return 0;
1158}
1159
1160static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1161{
1162 struct wmi_bit_rate_reply *reply;
1163 s32 rate;
1164 u32 sgi, index;
1165
1166 if (len < sizeof(struct wmi_bit_rate_reply))
1167 return -EINVAL;
1168
1169 reply = (struct wmi_bit_rate_reply *) datap;
1170
1171 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1172
1173 if (reply->rate_index == (s8) RATE_AUTO) {
1174 rate = RATE_AUTO;
1175 } else {
1176 index = reply->rate_index & 0x7f;
Raja Manid54601b2012-09-21 15:08:54 +05301177 if (WARN_ON_ONCE(index > (RATE_MCS_7_40 + 1)))
1178 return -EINVAL;
1179
Kalle Valobdcd8172011-07-18 00:22:30 +03001180 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1181 rate = wmi_rate_tbl[index][sgi];
1182 }
1183
1184 ath6kl_wakeup_event(wmi->parent_dev);
1185
1186 return 0;
1187}
1188
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001189static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
Kalle Valo003353b0d2011-09-01 10:14:21 +03001190{
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001191 ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03001192
1193 return 0;
1194}
1195
Kalle Valobdcd8172011-07-18 00:22:30 +03001196static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1197{
1198 if (len < sizeof(struct wmi_fix_rates_reply))
1199 return -EINVAL;
1200
1201 ath6kl_wakeup_event(wmi->parent_dev);
1202
1203 return 0;
1204}
1205
1206static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1207{
1208 if (len < sizeof(struct wmi_channel_list_reply))
1209 return -EINVAL;
1210
1211 ath6kl_wakeup_event(wmi->parent_dev);
1212
1213 return 0;
1214}
1215
1216static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1217{
1218 struct wmi_tx_pwr_reply *reply;
1219
1220 if (len < sizeof(struct wmi_tx_pwr_reply))
1221 return -EINVAL;
1222
1223 reply = (struct wmi_tx_pwr_reply *) datap;
1224 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1225
1226 return 0;
1227}
1228
1229static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1230{
1231 if (len < sizeof(struct wmi_get_keepalive_cmd))
1232 return -EINVAL;
1233
1234 ath6kl_wakeup_event(wmi->parent_dev);
1235
1236 return 0;
1237}
1238
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301239static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1240 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001241{
1242 struct wmi_scan_complete_event *ev;
1243
1244 ev = (struct wmi_scan_complete_event *) datap;
1245
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301246 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
Kalle Valobdcd8172011-07-18 00:22:30 +03001247 wmi->is_probe_ssid = false;
1248
1249 return 0;
1250}
1251
Jouni Malinen86512132011-09-21 16:57:29 +03001252static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301253 int len, struct ath6kl_vif *vif)
Jouni Malinen86512132011-09-21 16:57:29 +03001254{
1255 struct wmi_neighbor_report_event *ev;
1256 u8 i;
1257
1258 if (len < sizeof(*ev))
1259 return -EINVAL;
1260 ev = (struct wmi_neighbor_report_event *) datap;
1261 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1262 > len) {
Kalle Valocdeb8602012-04-12 11:02:18 +03001263 ath6kl_dbg(ATH6KL_DBG_WMI,
1264 "truncated neighbor event (num=%d len=%d)\n",
1265 ev->num_neighbors, len);
Jouni Malinen86512132011-09-21 16:57:29 +03001266 return -EINVAL;
1267 }
1268 for (i = 0; i < ev->num_neighbors; i++) {
1269 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1270 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1271 ev->neighbor[i].bss_flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301272 cfg80211_pmksa_candidate_notify(vif->ndev, i,
Jouni Malinen86512132011-09-21 16:57:29 +03001273 ev->neighbor[i].bssid,
1274 !!(ev->neighbor[i].bss_flags &
1275 WMI_PREAUTH_CAPABLE_BSS),
1276 GFP_ATOMIC);
1277 }
1278
1279 return 0;
1280}
1281
Kalle Valobdcd8172011-07-18 00:22:30 +03001282/*
1283 * Target is reporting a programming error. This is for
1284 * developer aid only. Target only checks a few common violations
1285 * and it is responsibility of host to do all error checking.
1286 * Behavior of target after wmi error event is undefined.
1287 * A reset is recommended.
1288 */
1289static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1290{
1291 const char *type = "unknown error";
1292 struct wmi_cmd_error_event *ev;
1293 ev = (struct wmi_cmd_error_event *) datap;
1294
1295 switch (ev->err_code) {
1296 case INVALID_PARAM:
1297 type = "invalid parameter";
1298 break;
1299 case ILLEGAL_STATE:
1300 type = "invalid state";
1301 break;
1302 case INTERNAL_ERROR:
1303 type = "internal error";
1304 break;
1305 }
1306
1307 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1308 ev->cmd_id, type);
1309
1310 return 0;
1311}
1312
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301313static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1314 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001315{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301316 ath6kl_tgt_stats_event(vif, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001317
1318 return 0;
1319}
1320
1321static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1322 struct sq_threshold_params *sq_thresh,
1323 u32 size)
1324{
1325 u32 index;
1326 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1327
1328 /* The list is already in sorted order. Get the next lower value */
1329 for (index = 0; index < size; index++) {
1330 if (rssi < sq_thresh->upper_threshold[index]) {
1331 threshold = (u8) sq_thresh->upper_threshold[index];
1332 break;
1333 }
1334 }
1335
1336 return threshold;
1337}
1338
1339static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1340 struct sq_threshold_params *sq_thresh,
1341 u32 size)
1342{
1343 u32 index;
1344 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1345
1346 /* The list is already in sorted order. Get the next lower value */
1347 for (index = 0; index < size; index++) {
1348 if (rssi > sq_thresh->lower_threshold[index]) {
1349 threshold = (u8) sq_thresh->lower_threshold[index];
1350 break;
1351 }
1352 }
1353
1354 return threshold;
1355}
1356
1357static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1358 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1359{
1360 struct sk_buff *skb;
1361 struct wmi_rssi_threshold_params_cmd *cmd;
1362
1363 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1364 if (!skb)
1365 return -ENOMEM;
1366
1367 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1368 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1369
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301370 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001371 NO_SYNC_WMIFLAG);
1372}
1373
1374static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1375 int len)
1376{
1377 struct wmi_rssi_threshold_event *reply;
1378 struct wmi_rssi_threshold_params_cmd cmd;
1379 struct sq_threshold_params *sq_thresh;
1380 enum wmi_rssi_threshold_val new_threshold;
1381 u8 upper_rssi_threshold, lower_rssi_threshold;
1382 s16 rssi;
1383 int ret;
1384
1385 if (len < sizeof(struct wmi_rssi_threshold_event))
1386 return -EINVAL;
1387
1388 reply = (struct wmi_rssi_threshold_event *) datap;
1389 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1390 rssi = a_sle16_to_cpu(reply->rssi);
1391
1392 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1393
1394 /*
1395 * Identify the threshold breached and communicate that to the app.
1396 * After that install a new set of thresholds based on the signal
1397 * quality reported by the target
1398 */
1399 if (new_threshold) {
1400 /* Upper threshold breached */
1401 if (rssi < sq_thresh->upper_threshold[0]) {
1402 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001403 "spurious upper rssi threshold event: %d\n",
1404 rssi);
Kalle Valobdcd8172011-07-18 00:22:30 +03001405 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1406 (rssi >= sq_thresh->upper_threshold[0])) {
1407 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1408 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1409 (rssi >= sq_thresh->upper_threshold[1])) {
1410 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1411 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1412 (rssi >= sq_thresh->upper_threshold[2])) {
1413 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1414 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1415 (rssi >= sq_thresh->upper_threshold[3])) {
1416 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1417 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1418 (rssi >= sq_thresh->upper_threshold[4])) {
1419 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1420 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1421 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1422 }
1423 } else {
1424 /* Lower threshold breached */
1425 if (rssi > sq_thresh->lower_threshold[0]) {
1426 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001427 "spurious lower rssi threshold event: %d %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +03001428 rssi, sq_thresh->lower_threshold[0]);
1429 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1430 (rssi <= sq_thresh->lower_threshold[0])) {
1431 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1432 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1433 (rssi <= sq_thresh->lower_threshold[1])) {
1434 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1435 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1436 (rssi <= sq_thresh->lower_threshold[2])) {
1437 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1438 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1439 (rssi <= sq_thresh->lower_threshold[3])) {
1440 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1441 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1442 (rssi <= sq_thresh->lower_threshold[4])) {
1443 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1444 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1445 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1446 }
1447 }
1448
1449 /* Calculate and install the next set of thresholds */
1450 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1451 sq_thresh->lower_threshold_valid_count);
1452 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1453 sq_thresh->upper_threshold_valid_count);
1454
1455 /* Issue a wmi command to install the thresholds */
1456 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1457 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1458 cmd.weight = sq_thresh->weight;
1459 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1460
1461 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1462 if (ret) {
1463 ath6kl_err("unable to configure rssi thresholds\n");
1464 return -EIO;
1465 }
1466
1467 return 0;
1468}
1469
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301470static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1471 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001472{
1473 struct wmi_cac_event *reply;
1474 struct ieee80211_tspec_ie *ts;
1475 u16 active_tsids, tsinfo;
1476 u8 tsid, index;
1477 u8 ts_id;
1478
1479 if (len < sizeof(struct wmi_cac_event))
1480 return -EINVAL;
1481
1482 reply = (struct wmi_cac_event *) datap;
1483
1484 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1485 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1486
1487 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1488 tsinfo = le16_to_cpu(ts->tsinfo);
1489 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1490 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1491
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301492 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1493 reply->ac, tsid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001494 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1495 /*
1496 * Following assumes that there is only one outstanding
1497 * ADDTS request when this event is received
1498 */
1499 spin_lock_bh(&wmi->lock);
1500 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1501 spin_unlock_bh(&wmi->lock);
1502
1503 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1504 if ((active_tsids >> index) & 1)
1505 break;
1506 }
1507 if (index < (sizeof(active_tsids) * 8))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301508 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1509 reply->ac, index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001510 }
1511
1512 /*
1513 * Clear active tsids and Add missing handling
1514 * for delete qos stream from AP
1515 */
1516 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1517
1518 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1519 tsinfo = le16_to_cpu(ts->tsinfo);
1520 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1521 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1522
1523 spin_lock_bh(&wmi->lock);
1524 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1525 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1526 spin_unlock_bh(&wmi->lock);
1527
1528 /* Indicate stream inactivity to driver layer only if all tsids
1529 * within this AC are deleted.
1530 */
1531 if (!active_tsids) {
1532 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1533 false);
1534 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1535 }
1536 }
1537
1538 return 0;
1539}
1540
Thomas Pedersen279b2862012-07-17 19:39:55 -07001541static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
1542 struct ath6kl_vif *vif)
1543{
1544 struct wmi_txe_notify_event *ev;
1545 u32 rate, pkts;
1546
1547 if (len < sizeof(*ev))
1548 return -EINVAL;
1549
1550 if (vif->sme_state != SME_CONNECTED)
1551 return -ENOTCONN;
1552
1553 ev = (struct wmi_txe_notify_event *) datap;
1554 rate = le32_to_cpu(ev->rate);
1555 pkts = le32_to_cpu(ev->pkts);
1556
1557 ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d% pkts %d intvl %ds\n",
1558 vif->bssid, rate, pkts, vif->txe_intvl);
1559
1560 cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
1561 rate, vif->txe_intvl, GFP_KERNEL);
1562
1563 return 0;
1564}
1565
1566int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
1567 u32 rate, u32 pkts, u32 intvl)
1568{
1569 struct sk_buff *skb;
1570 struct wmi_txe_notify_cmd *cmd;
1571
1572 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1573 if (!skb)
1574 return -ENOMEM;
1575
1576 cmd = (struct wmi_txe_notify_cmd *) skb->data;
1577 cmd->rate = cpu_to_le32(rate);
1578 cmd->pkts = cpu_to_le32(pkts);
1579 cmd->intvl = cpu_to_le32(intvl);
1580
1581 return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
1582 NO_SYNC_WMIFLAG);
1583}
1584
Thomas Pedersen85b20fc2012-06-21 12:50:08 -07001585int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
1586{
1587 struct sk_buff *skb;
1588 struct wmi_set_rssi_filter_cmd *cmd;
1589 int ret;
1590
1591 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1592 if (!skb)
1593 return -ENOMEM;
1594
1595 cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
1596 cmd->rssi = rssi;
1597
1598 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
1599 NO_SYNC_WMIFLAG);
1600 return ret;
1601}
1602
Kalle Valobdcd8172011-07-18 00:22:30 +03001603static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1604 struct wmi_snr_threshold_params_cmd *snr_cmd)
1605{
1606 struct sk_buff *skb;
1607 struct wmi_snr_threshold_params_cmd *cmd;
1608
1609 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1610 if (!skb)
1611 return -ENOMEM;
1612
1613 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1614 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1615
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301616 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001617 NO_SYNC_WMIFLAG);
1618}
1619
1620static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1621 int len)
1622{
1623 struct wmi_snr_threshold_event *reply;
1624 struct sq_threshold_params *sq_thresh;
1625 struct wmi_snr_threshold_params_cmd cmd;
1626 enum wmi_snr_threshold_val new_threshold;
1627 u8 upper_snr_threshold, lower_snr_threshold;
1628 s16 snr;
1629 int ret;
1630
1631 if (len < sizeof(struct wmi_snr_threshold_event))
1632 return -EINVAL;
1633
1634 reply = (struct wmi_snr_threshold_event *) datap;
1635
1636 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1637 snr = reply->snr;
1638
1639 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1640
1641 /*
1642 * Identify the threshold breached and communicate that to the app.
1643 * After that install a new set of thresholds based on the signal
1644 * quality reported by the target.
1645 */
1646 if (new_threshold) {
1647 /* Upper threshold breached */
1648 if (snr < sq_thresh->upper_threshold[0]) {
1649 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001650 "spurious upper snr threshold event: %d\n",
1651 snr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001652 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1653 (snr >= sq_thresh->upper_threshold[0])) {
1654 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1655 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1656 (snr >= sq_thresh->upper_threshold[1])) {
1657 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1658 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1659 (snr >= sq_thresh->upper_threshold[2])) {
1660 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1661 } else if (snr >= sq_thresh->upper_threshold[3]) {
1662 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1663 }
1664 } else {
1665 /* Lower threshold breached */
1666 if (snr > sq_thresh->lower_threshold[0]) {
1667 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001668 "spurious lower snr threshold event: %d\n",
1669 sq_thresh->lower_threshold[0]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001670 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1671 (snr <= sq_thresh->lower_threshold[0])) {
1672 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1673 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1674 (snr <= sq_thresh->lower_threshold[1])) {
1675 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1676 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1677 (snr <= sq_thresh->lower_threshold[2])) {
1678 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1679 } else if (snr <= sq_thresh->lower_threshold[3]) {
1680 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1681 }
1682 }
1683
1684 /* Calculate and install the next set of thresholds */
1685 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1686 sq_thresh->lower_threshold_valid_count);
1687 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1688 sq_thresh->upper_threshold_valid_count);
1689
1690 /* Issue a wmi command to install the thresholds */
1691 cmd.thresh_above1_val = upper_snr_threshold;
1692 cmd.thresh_below1_val = lower_snr_threshold;
1693 cmd.weight = sq_thresh->weight;
1694 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1695
1696 ath6kl_dbg(ATH6KL_DBG_WMI,
1697 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1698 snr, new_threshold,
1699 lower_snr_threshold, upper_snr_threshold);
1700
1701 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1702 if (ret) {
1703 ath6kl_err("unable to configure snr threshold\n");
1704 return -EIO;
1705 }
1706
1707 return 0;
1708}
1709
1710static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1711{
1712 u16 ap_info_entry_size;
1713 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1714 struct wmi_ap_info_v1 *ap_info_v1;
1715 u8 index;
1716
1717 if (len < sizeof(struct wmi_aplist_event) ||
1718 ev->ap_list_ver != APLIST_VER1)
1719 return -EINVAL;
1720
1721 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1722 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1723
1724 ath6kl_dbg(ATH6KL_DBG_WMI,
1725 "number of APs in aplist event: %d\n", ev->num_ap);
1726
1727 if (len < (int) (sizeof(struct wmi_aplist_event) +
1728 (ev->num_ap - 1) * ap_info_entry_size))
1729 return -EINVAL;
1730
1731 /* AP list version 1 contents */
1732 for (index = 0; index < ev->num_ap; index++) {
1733 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1734 index, ap_info_v1->bssid, ap_info_v1->channel);
1735 ap_info_v1++;
1736 }
1737
1738 return 0;
1739}
1740
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301741int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +03001742 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1743{
1744 struct wmi_cmd_hdr *cmd_hdr;
1745 enum htc_endpoint_id ep_id = wmi->ep_id;
1746 int ret;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301747 u16 info1;
Kalle Valobdcd8172011-07-18 00:22:30 +03001748
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05301749 if (WARN_ON(skb == NULL ||
1750 (if_idx > (wmi->parent_dev->vif_max - 1)))) {
1751 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03001752 return -EINVAL;
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05301753 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001754
Kalle Valob9b6ee62011-09-27 14:31:21 +03001755 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1756 cmd_id, skb->len, sync_flag);
1757 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1758 skb->data, skb->len);
1759
Kalle Valobdcd8172011-07-18 00:22:30 +03001760 if (sync_flag >= END_WMIFLAG) {
1761 dev_kfree_skb(skb);
1762 return -EINVAL;
1763 }
1764
1765 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1766 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1767 /*
1768 * Make sure all data currently queued is transmitted before
1769 * the cmd execution. Establish a new sync point.
1770 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301771 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001772 }
1773
1774 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1775
1776 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1777 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301778 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1779 cmd_hdr->info1 = cpu_to_le16(info1);
Kalle Valobdcd8172011-07-18 00:22:30 +03001780
1781 /* Only for OPT_TX_CMD, use BE endpoint. */
1782 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1783 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301784 false, false, 0, NULL, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001785 if (ret) {
1786 dev_kfree_skb(skb);
1787 return ret;
1788 }
1789 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1790 }
1791
1792 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1793
1794 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1795 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1796 /*
1797 * Make sure all new data queued waits for the command to
1798 * execute. Establish a new sync point.
1799 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301800 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001801 }
1802
1803 return 0;
1804}
1805
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301806int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1807 enum network_type nw_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001808 enum dot11_auth_mode dot11_auth_mode,
1809 enum auth_mode auth_mode,
1810 enum crypto_type pairwise_crypto,
1811 u8 pairwise_crypto_len,
1812 enum crypto_type group_crypto,
1813 u8 group_crypto_len, int ssid_len, u8 *ssid,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001814 u8 *bssid, u16 channel, u32 ctrl_flags,
1815 u8 nw_subtype)
Kalle Valobdcd8172011-07-18 00:22:30 +03001816{
1817 struct sk_buff *skb;
1818 struct wmi_connect_cmd *cc;
1819 int ret;
1820
Kalle Valob9b6ee62011-09-27 14:31:21 +03001821 ath6kl_dbg(ATH6KL_DBG_WMI,
1822 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1823 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1824 bssid, channel, ctrl_flags, ssid_len, nw_type,
1825 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1826 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1827
Kalle Valobdcd8172011-07-18 00:22:30 +03001828 wmi->traffic_class = 100;
1829
1830 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1831 return -EINVAL;
1832
1833 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1834 return -EINVAL;
1835
1836 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1837 if (!skb)
1838 return -ENOMEM;
1839
1840 cc = (struct wmi_connect_cmd *) skb->data;
1841
1842 if (ssid_len)
1843 memcpy(cc->ssid, ssid, ssid_len);
1844
1845 cc->ssid_len = ssid_len;
1846 cc->nw_type = nw_type;
1847 cc->dot11_auth_mode = dot11_auth_mode;
1848 cc->auth_mode = auth_mode;
1849 cc->prwise_crypto_type = pairwise_crypto;
1850 cc->prwise_crypto_len = pairwise_crypto_len;
1851 cc->grp_crypto_type = group_crypto;
1852 cc->grp_crypto_len = group_crypto_len;
1853 cc->ch = cpu_to_le16(channel);
1854 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001855 cc->nw_subtype = nw_subtype;
Kalle Valobdcd8172011-07-18 00:22:30 +03001856
1857 if (bssid != NULL)
1858 memcpy(cc->bssid, bssid, ETH_ALEN);
1859
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301860 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1861 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001862
1863 return ret;
1864}
1865
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301866int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1867 u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +03001868{
1869 struct sk_buff *skb;
1870 struct wmi_reconnect_cmd *cc;
1871 int ret;
1872
Kalle Valob9b6ee62011-09-27 14:31:21 +03001873 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1874 bssid, channel);
1875
Kalle Valobdcd8172011-07-18 00:22:30 +03001876 wmi->traffic_class = 100;
1877
1878 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1879 if (!skb)
1880 return -ENOMEM;
1881
1882 cc = (struct wmi_reconnect_cmd *) skb->data;
1883 cc->channel = cpu_to_le16(channel);
1884
1885 if (bssid != NULL)
1886 memcpy(cc->bssid, bssid, ETH_ALEN);
1887
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301888 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001889 NO_SYNC_WMIFLAG);
1890
1891 return ret;
1892}
1893
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301894int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03001895{
1896 int ret;
1897
Kalle Valob9b6ee62011-09-27 14:31:21 +03001898 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1899
Kalle Valobdcd8172011-07-18 00:22:30 +03001900 wmi->traffic_class = 100;
1901
1902 /* Disconnect command does not need to do a SYNC before. */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301903 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03001904
1905 return ret;
1906}
1907
Kalle Valoc8c72b72012-07-19 16:00:40 +03001908/* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1909 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1910 * mgmt operations using station interface.
1911 */
Kalle Valo11f0bfc2012-07-19 16:00:48 +03001912static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1913 enum wmi_scan_type scan_type,
1914 u32 force_fgscan, u32 is_legacy,
1915 u32 home_dwell_time,
1916 u32 force_scan_interval,
1917 s8 num_chan, u16 *ch_list)
Kalle Valoc8c72b72012-07-19 16:00:40 +03001918{
1919 struct sk_buff *skb;
1920 struct wmi_start_scan_cmd *sc;
1921 s8 size;
1922 int i, ret;
1923
1924 size = sizeof(struct wmi_start_scan_cmd);
1925
1926 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1927 return -EINVAL;
1928
1929 if (num_chan > WMI_MAX_CHANNELS)
1930 return -EINVAL;
1931
1932 if (num_chan)
1933 size += sizeof(u16) * (num_chan - 1);
1934
1935 skb = ath6kl_wmi_get_new_buf(size);
1936 if (!skb)
1937 return -ENOMEM;
1938
1939 sc = (struct wmi_start_scan_cmd *) skb->data;
1940 sc->scan_type = scan_type;
1941 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1942 sc->is_legacy = cpu_to_le32(is_legacy);
1943 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1944 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1945 sc->num_ch = num_chan;
1946
1947 for (i = 0; i < num_chan; i++)
1948 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1949
1950 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
1951 NO_SYNC_WMIFLAG);
1952
1953 return ret;
1954}
1955
Kalle Valo11f0bfc2012-07-19 16:00:48 +03001956/*
1957 * beginscan supports (compared to old startscan) P2P mgmt operations using
1958 * station interface, send additional information like supported rates to
1959 * advertise and xmit rates for probe requests
1960 */
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001961int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
1962 enum wmi_scan_type scan_type,
1963 u32 force_fgscan, u32 is_legacy,
1964 u32 home_dwell_time, u32 force_scan_interval,
1965 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
1966{
Thomas Pedersen03e20842012-04-24 12:50:41 -07001967 struct ieee80211_supported_band *sband;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001968 struct sk_buff *skb;
1969 struct wmi_begin_scan_cmd *sc;
Thomas Pedersen03e20842012-04-24 12:50:41 -07001970 s8 size, *supp_rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001971 int i, band, ret;
1972 struct ath6kl *ar = wmi->parent_dev;
1973 int num_rates;
Thomas Pedersen03e20842012-04-24 12:50:41 -07001974 u32 ratemask;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001975
Kalle Valo11f0bfc2012-07-19 16:00:48 +03001976 if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
1977 ar->fw_capabilities)) {
1978 return ath6kl_wmi_startscan_cmd(wmi, if_idx,
1979 scan_type, force_fgscan,
1980 is_legacy, home_dwell_time,
1981 force_scan_interval,
1982 num_chan, ch_list);
1983 }
1984
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001985 size = sizeof(struct wmi_begin_scan_cmd);
1986
1987 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1988 return -EINVAL;
1989
1990 if (num_chan > WMI_MAX_CHANNELS)
1991 return -EINVAL;
1992
1993 if (num_chan)
1994 size += sizeof(u16) * (num_chan - 1);
1995
1996 skb = ath6kl_wmi_get_new_buf(size);
1997 if (!skb)
1998 return -ENOMEM;
1999
2000 sc = (struct wmi_begin_scan_cmd *) skb->data;
2001 sc->scan_type = scan_type;
2002 sc->force_fg_scan = cpu_to_le32(force_fgscan);
2003 sc->is_legacy = cpu_to_le32(is_legacy);
2004 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
2005 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
2006 sc->no_cck = cpu_to_le32(no_cck);
2007 sc->num_ch = num_chan;
2008
2009 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
Thomas Pedersen03e20842012-04-24 12:50:41 -07002010 sband = ar->wiphy->bands[band];
2011
2012 if (!sband)
2013 continue;
2014
2015 ratemask = rates[band];
2016 supp_rates = sc->supp_rates[band].rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08002017 num_rates = 0;
2018
2019 for (i = 0; i < sband->n_bitrates; i++) {
2020 if ((BIT(i) & ratemask) == 0)
2021 continue; /* skip rate */
2022 supp_rates[num_rates++] =
2023 (u8) (sband->bitrates[i].bitrate / 5);
2024 }
2025 sc->supp_rates[band].nrates = num_rates;
2026 }
2027
2028 for (i = 0; i < num_chan; i++)
2029 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
2030
2031 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
2032 NO_SYNC_WMIFLAG);
2033
2034 return ret;
2035}
2036
Thomas Pedersenb1f47e32012-08-15 16:51:24 -07002037int ath6kl_wmi_enable_sched_scan_cmd(struct wmi *wmi, u8 if_idx, bool enable)
2038{
2039 struct sk_buff *skb;
2040 struct wmi_enable_sched_scan_cmd *sc;
2041 int ret;
2042
2043 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2044 if (!skb)
2045 return -ENOMEM;
2046
2047 ath6kl_dbg(ATH6KL_DBG_WMI, "%s scheduled scan on vif %d\n",
2048 enable ? "enabling" : "disabling", if_idx);
2049 sc = (struct wmi_enable_sched_scan_cmd *) skb->data;
2050 sc->enable = enable ? 1 : 0;
2051
2052 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2053 WMI_ENABLE_SCHED_SCAN_CMDID,
2054 NO_SYNC_WMIFLAG);
2055 return ret;
2056}
2057
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302058int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
2059 u16 fg_start_sec,
Kalle Valobdcd8172011-07-18 00:22:30 +03002060 u16 fg_end_sec, u16 bg_sec,
2061 u16 minact_chdw_msec, u16 maxact_chdw_msec,
2062 u16 pas_chdw_msec, u8 short_scan_ratio,
2063 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
2064 u16 maxact_scan_per_ssid)
2065{
2066 struct sk_buff *skb;
2067 struct wmi_scan_params_cmd *sc;
2068 int ret;
2069
2070 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
2071 if (!skb)
2072 return -ENOMEM;
2073
2074 sc = (struct wmi_scan_params_cmd *) skb->data;
2075 sc->fg_start_period = cpu_to_le16(fg_start_sec);
2076 sc->fg_end_period = cpu_to_le16(fg_end_sec);
2077 sc->bg_period = cpu_to_le16(bg_sec);
2078 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
2079 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
2080 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
2081 sc->short_scan_ratio = short_scan_ratio;
2082 sc->scan_ctrl_flags = scan_ctrl_flag;
2083 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
2084 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
2085
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302086 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002087 NO_SYNC_WMIFLAG);
2088 return ret;
2089}
2090
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302091int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
Kalle Valobdcd8172011-07-18 00:22:30 +03002092{
2093 struct sk_buff *skb;
2094 struct wmi_bss_filter_cmd *cmd;
2095 int ret;
2096
2097 if (filter >= LAST_BSS_FILTER)
2098 return -EINVAL;
2099
2100 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2101 if (!skb)
2102 return -ENOMEM;
2103
2104 cmd = (struct wmi_bss_filter_cmd *) skb->data;
2105 cmd->bss_filter = filter;
2106 cmd->ie_mask = cpu_to_le32(ie_mask);
2107
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302108 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002109 NO_SYNC_WMIFLAG);
2110 return ret;
2111}
2112
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302113int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
Kalle Valobdcd8172011-07-18 00:22:30 +03002114 u8 ssid_len, u8 *ssid)
2115{
2116 struct sk_buff *skb;
2117 struct wmi_probed_ssid_cmd *cmd;
2118 int ret;
2119
Jouni Malinen8ab54152012-05-09 22:14:51 +03002120 if (index >= MAX_PROBED_SSIDS)
Kalle Valobdcd8172011-07-18 00:22:30 +03002121 return -EINVAL;
2122
2123 if (ssid_len > sizeof(cmd->ssid))
2124 return -EINVAL;
2125
2126 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
2127 return -EINVAL;
2128
2129 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
2130 return -EINVAL;
2131
2132 if (flag & SPECIFIC_SSID_FLAG)
2133 wmi->is_probe_ssid = true;
2134
2135 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2136 if (!skb)
2137 return -ENOMEM;
2138
2139 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2140 cmd->entry_index = index;
2141 cmd->flag = flag;
2142 cmd->ssid_len = ssid_len;
2143 memcpy(cmd->ssid, ssid, ssid_len);
2144
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302145 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002146 NO_SYNC_WMIFLAG);
2147 return ret;
2148}
2149
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302150int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2151 u16 listen_interval,
Kalle Valobdcd8172011-07-18 00:22:30 +03002152 u16 listen_beacons)
2153{
2154 struct sk_buff *skb;
2155 struct wmi_listen_int_cmd *cmd;
2156 int ret;
2157
2158 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2159 if (!skb)
2160 return -ENOMEM;
2161
2162 cmd = (struct wmi_listen_int_cmd *) skb->data;
2163 cmd->listen_intvl = cpu_to_le16(listen_interval);
2164 cmd->num_beacons = cpu_to_le16(listen_beacons);
2165
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302166 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002167 NO_SYNC_WMIFLAG);
2168 return ret;
2169}
2170
Raja Manice0dc0c2012-02-20 19:08:08 +05302171int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2172 u16 bmiss_time, u16 num_beacons)
2173{
2174 struct sk_buff *skb;
2175 struct wmi_bmiss_time_cmd *cmd;
2176 int ret;
2177
2178 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2179 if (!skb)
2180 return -ENOMEM;
2181
2182 cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2183 cmd->bmiss_time = cpu_to_le16(bmiss_time);
2184 cmd->num_beacons = cpu_to_le16(num_beacons);
2185
2186 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2187 NO_SYNC_WMIFLAG);
2188 return ret;
2189}
2190
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302191int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
Kalle Valobdcd8172011-07-18 00:22:30 +03002192{
2193 struct sk_buff *skb;
2194 struct wmi_power_mode_cmd *cmd;
2195 int ret;
2196
2197 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2198 if (!skb)
2199 return -ENOMEM;
2200
2201 cmd = (struct wmi_power_mode_cmd *) skb->data;
2202 cmd->pwr_mode = pwr_mode;
2203 wmi->pwr_mode = pwr_mode;
2204
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302205 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002206 NO_SYNC_WMIFLAG);
2207 return ret;
2208}
2209
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302210int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
Kalle Valobdcd8172011-07-18 00:22:30 +03002211 u16 ps_poll_num, u16 dtim_policy,
2212 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2213 u16 ps_fail_event_policy)
2214{
2215 struct sk_buff *skb;
2216 struct wmi_power_params_cmd *pm;
2217 int ret;
2218
2219 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2220 if (!skb)
2221 return -ENOMEM;
2222
2223 pm = (struct wmi_power_params_cmd *)skb->data;
2224 pm->idle_period = cpu_to_le16(idle_period);
2225 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2226 pm->dtim_policy = cpu_to_le16(dtim_policy);
2227 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2228 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2229 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2230
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302231 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002232 NO_SYNC_WMIFLAG);
2233 return ret;
2234}
2235
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302236int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
Kalle Valobdcd8172011-07-18 00:22:30 +03002237{
2238 struct sk_buff *skb;
2239 struct wmi_disc_timeout_cmd *cmd;
2240 int ret;
2241
2242 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2243 if (!skb)
2244 return -ENOMEM;
2245
2246 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2247 cmd->discon_timeout = timeout;
2248
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302249 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002250 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302251
Jouni Malinenff0b0072011-10-11 17:31:56 +03002252 if (ret == 0)
2253 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302254
Kalle Valobdcd8172011-07-18 00:22:30 +03002255 return ret;
2256}
2257
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302258int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
Kalle Valobdcd8172011-07-18 00:22:30 +03002259 enum crypto_type key_type,
2260 u8 key_usage, u8 key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002261 u8 *key_rsc, unsigned int key_rsc_len,
2262 u8 *key_material,
Kalle Valobdcd8172011-07-18 00:22:30 +03002263 u8 key_op_ctrl, u8 *mac_addr,
2264 enum wmi_sync_flag sync_flag)
2265{
2266 struct sk_buff *skb;
2267 struct wmi_add_cipher_key_cmd *cmd;
2268 int ret;
2269
Kalle Valocdeb8602012-04-12 11:02:18 +03002270 ath6kl_dbg(ATH6KL_DBG_WMI,
2271 "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 +03002272 key_index, key_type, key_usage, key_len, key_op_ctrl);
2273
Kalle Valobdcd8172011-07-18 00:22:30 +03002274 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002275 (key_material == NULL) || key_rsc_len > 8)
Kalle Valobdcd8172011-07-18 00:22:30 +03002276 return -EINVAL;
2277
2278 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2279 return -EINVAL;
2280
2281 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2282 if (!skb)
2283 return -ENOMEM;
2284
2285 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2286 cmd->key_index = key_index;
2287 cmd->key_type = key_type;
2288 cmd->key_usage = key_usage;
2289 cmd->key_len = key_len;
2290 memcpy(cmd->key, key_material, key_len);
2291
2292 if (key_rsc != NULL)
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002293 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002294
2295 cmd->key_op_ctrl = key_op_ctrl;
2296
2297 if (mac_addr)
2298 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2299
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302300 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002301 sync_flag);
2302
2303 return ret;
2304}
2305
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302306int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
Kalle Valobdcd8172011-07-18 00:22:30 +03002307{
2308 struct sk_buff *skb;
2309 struct wmi_add_krk_cmd *cmd;
2310 int ret;
2311
2312 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2313 if (!skb)
2314 return -ENOMEM;
2315
2316 cmd = (struct wmi_add_krk_cmd *) skb->data;
2317 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2318
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302319 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302320 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002321
2322 return ret;
2323}
2324
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302325int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
Kalle Valobdcd8172011-07-18 00:22:30 +03002326{
2327 struct sk_buff *skb;
2328 struct wmi_delete_cipher_key_cmd *cmd;
2329 int ret;
2330
2331 if (key_index > WMI_MAX_KEY_INDEX)
2332 return -EINVAL;
2333
2334 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2335 if (!skb)
2336 return -ENOMEM;
2337
2338 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2339 cmd->key_index = key_index;
2340
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302341 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002342 NO_SYNC_WMIFLAG);
2343
2344 return ret;
2345}
2346
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302347int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002348 const u8 *pmkid, bool set)
2349{
2350 struct sk_buff *skb;
2351 struct wmi_setpmkid_cmd *cmd;
2352 int ret;
2353
2354 if (bssid == NULL)
2355 return -EINVAL;
2356
2357 if (set && pmkid == NULL)
2358 return -EINVAL;
2359
2360 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2361 if (!skb)
2362 return -ENOMEM;
2363
2364 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2365 memcpy(cmd->bssid, bssid, ETH_ALEN);
2366 if (set) {
2367 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2368 cmd->enable = PMKID_ENABLE;
2369 } else {
2370 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2371 cmd->enable = PMKID_DISABLE;
2372 }
2373
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302374 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002375 NO_SYNC_WMIFLAG);
2376
2377 return ret;
2378}
2379
2380static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302381 enum htc_endpoint_id ep_id, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002382{
2383 struct wmi_data_hdr *data_hdr;
2384 int ret;
2385
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302386 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) {
2387 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002388 return -EINVAL;
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302389 }
Kalle Valobdcd8172011-07-18 00:22:30 +03002390
2391 skb_push(skb, sizeof(struct wmi_data_hdr));
2392
2393 data_hdr = (struct wmi_data_hdr *) skb->data;
2394 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302395 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +03002396
2397 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2398
2399 return ret;
2400}
2401
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302402static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002403{
2404 struct sk_buff *skb;
2405 struct wmi_sync_cmd *cmd;
2406 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2407 enum htc_endpoint_id ep_id;
2408 u8 index, num_pri_streams = 0;
2409 int ret = 0;
2410
2411 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2412
2413 spin_lock_bh(&wmi->lock);
2414
2415 for (index = 0; index < WMM_NUM_AC; index++) {
2416 if (wmi->fat_pipe_exist & (1 << index)) {
2417 num_pri_streams++;
2418 data_sync_bufs[num_pri_streams - 1].traffic_class =
2419 index;
2420 }
2421 }
2422
2423 spin_unlock_bh(&wmi->lock);
2424
2425 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302426 if (!skb)
2427 return -ENOMEM;
Kalle Valobdcd8172011-07-18 00:22:30 +03002428
2429 cmd = (struct wmi_sync_cmd *) skb->data;
2430
2431 /*
2432 * In the SYNC cmd sent on the control Ep, send a bitmap
2433 * of the data eps on which the Data Sync will be sent
2434 */
2435 cmd->data_sync_map = wmi->fat_pipe_exist;
2436
2437 for (index = 0; index < num_pri_streams; index++) {
2438 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2439 if (data_sync_bufs[index].skb == NULL) {
2440 ret = -ENOMEM;
2441 break;
2442 }
2443 }
2444
2445 /*
2446 * If buffer allocation for any of the dataSync fails,
2447 * then do not send the Synchronize cmd on the control ep
2448 */
2449 if (ret)
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302450 goto free_cmd_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002451
2452 /*
2453 * Send sync cmd followed by sync data messages on all
2454 * endpoints being used
2455 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302456 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002457 NO_SYNC_WMIFLAG);
2458
2459 if (ret)
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302460 goto free_data_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002461
2462 for (index = 0; index < num_pri_streams; index++) {
2463
2464 if (WARN_ON(!data_sync_bufs[index].skb))
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302465 goto free_data_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002466
2467 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2468 data_sync_bufs[index].
2469 traffic_class);
2470 ret =
2471 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302472 ep_id, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03002473
Kalle Valobdcd8172011-07-18 00:22:30 +03002474 data_sync_bufs[index].skb = NULL;
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302475
2476 if (ret)
2477 goto free_data_skb;
Kalle Valobdcd8172011-07-18 00:22:30 +03002478 }
2479
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302480 return 0;
2481
2482free_cmd_skb:
Kalle Valobdcd8172011-07-18 00:22:30 +03002483 /* free up any resources left over (possibly due to an error) */
Mohammed Shafi Shajakhane16ccfe2012-11-16 18:22:22 +05302484 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002485
Vasanthakumar Thiagarajan0616dc12012-08-14 10:10:33 +05302486free_data_skb:
Mohammed Shafi Shajakhane16ccfe2012-11-16 18:22:22 +05302487 for (index = 0; index < num_pri_streams; index++)
2488 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002489
2490 return ret;
2491}
2492
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302493int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +03002494 struct wmi_create_pstream_cmd *params)
2495{
2496 struct sk_buff *skb;
2497 struct wmi_create_pstream_cmd *cmd;
2498 u8 fatpipe_exist_for_ac = 0;
2499 s32 min_phy = 0;
2500 s32 nominal_phy = 0;
2501 int ret;
2502
2503 if (!((params->user_pri < 8) &&
2504 (params->user_pri <= 0x7) &&
2505 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2506 (params->traffic_direc == UPLINK_TRAFFIC ||
2507 params->traffic_direc == DNLINK_TRAFFIC ||
2508 params->traffic_direc == BIDIR_TRAFFIC) &&
2509 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2510 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2511 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2512 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2513 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2514 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2515 params->tsid <= WMI_MAX_THINSTREAM))) {
2516 return -EINVAL;
2517 }
2518
2519 /*
2520 * Check nominal PHY rate is >= minimalPHY,
2521 * so that DUT can allow TSRS IE
2522 */
2523
2524 /* Get the physical rate (units of bps) */
2525 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2526
2527 /* Check minimal phy < nominal phy rate */
2528 if (params->nominal_phy >= min_phy) {
2529 /* unit of 500 kbps */
2530 nominal_phy = (params->nominal_phy * 1000) / 500;
2531 ath6kl_dbg(ATH6KL_DBG_WMI,
2532 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2533 min_phy, nominal_phy);
2534
2535 params->nominal_phy = nominal_phy;
2536 } else {
2537 params->nominal_phy = 0;
2538 }
2539
2540 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2541 if (!skb)
2542 return -ENOMEM;
2543
2544 ath6kl_dbg(ATH6KL_DBG_WMI,
2545 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2546 params->traffic_class, params->tsid);
2547
2548 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2549 memcpy(cmd, params, sizeof(*cmd));
2550
2551 /* This is an implicitly created Fat pipe */
2552 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2553 spin_lock_bh(&wmi->lock);
2554 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2555 (1 << params->traffic_class));
2556 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2557 spin_unlock_bh(&wmi->lock);
2558 } else {
2559 /* explicitly created thin stream within a fat pipe */
2560 spin_lock_bh(&wmi->lock);
2561 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2562 (1 << params->traffic_class));
2563 wmi->stream_exist_for_ac[params->traffic_class] |=
2564 (1 << params->tsid);
2565 /*
2566 * If a thinstream becomes active, the fat pipe automatically
2567 * becomes active
2568 */
2569 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2570 spin_unlock_bh(&wmi->lock);
2571 }
2572
2573 /*
2574 * Indicate activty change to driver layer only if this is the
2575 * first TSID to get created in this AC explicitly or an implicit
2576 * fat pipe is getting created.
2577 */
2578 if (!fatpipe_exist_for_ac)
2579 ath6kl_indicate_tx_activity(wmi->parent_dev,
2580 params->traffic_class, true);
2581
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302582 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002583 NO_SYNC_WMIFLAG);
2584 return ret;
2585}
2586
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302587int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2588 u8 tsid)
Kalle Valobdcd8172011-07-18 00:22:30 +03002589{
2590 struct sk_buff *skb;
2591 struct wmi_delete_pstream_cmd *cmd;
2592 u16 active_tsids = 0;
2593 int ret;
2594
2595 if (traffic_class > 3) {
2596 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2597 return -EINVAL;
2598 }
2599
2600 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2601 if (!skb)
2602 return -ENOMEM;
2603
2604 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2605 cmd->traffic_class = traffic_class;
2606 cmd->tsid = tsid;
2607
2608 spin_lock_bh(&wmi->lock);
2609 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2610 spin_unlock_bh(&wmi->lock);
2611
2612 if (!(active_tsids & (1 << tsid))) {
2613 dev_kfree_skb(skb);
2614 ath6kl_dbg(ATH6KL_DBG_WMI,
2615 "TSID %d doesn't exist for traffic class: %d\n",
2616 tsid, traffic_class);
2617 return -ENODATA;
2618 }
2619
2620 ath6kl_dbg(ATH6KL_DBG_WMI,
2621 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2622 traffic_class, tsid);
2623
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302624 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002625 SYNC_BEFORE_WMIFLAG);
2626
2627 spin_lock_bh(&wmi->lock);
2628 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2629 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2630 spin_unlock_bh(&wmi->lock);
2631
2632 /*
2633 * Indicate stream inactivity to driver layer only if all tsids
2634 * within this AC are deleted.
2635 */
2636 if (!active_tsids) {
2637 ath6kl_indicate_tx_activity(wmi->parent_dev,
2638 traffic_class, false);
2639 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2640 }
2641
2642 return ret;
2643}
2644
Raja Manica1d16a2011-12-16 14:24:23 +05302645int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2646 __be32 ips0, __be32 ips1)
Kalle Valobdcd8172011-07-18 00:22:30 +03002647{
2648 struct sk_buff *skb;
2649 struct wmi_set_ip_cmd *cmd;
2650 int ret;
2651
2652 /* Multicast address are not valid */
Raja Manica1d16a2011-12-16 14:24:23 +05302653 if (ipv4_is_multicast(ips0) ||
2654 ipv4_is_multicast(ips1))
Kalle Valobdcd8172011-07-18 00:22:30 +03002655 return -EINVAL;
2656
2657 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2658 if (!skb)
2659 return -ENOMEM;
2660
2661 cmd = (struct wmi_set_ip_cmd *) skb->data;
Raja Manica1d16a2011-12-16 14:24:23 +05302662 cmd->ips[0] = ips0;
2663 cmd->ips[1] = ips1;
Kalle Valobdcd8172011-07-18 00:22:30 +03002664
Raja Manica1d16a2011-12-16 14:24:23 +05302665 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302666 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002667 return ret;
2668}
2669
Raja Mani45cf1102011-11-07 22:52:45 +02002670static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2671{
2672 u16 active_tsids;
2673 u8 stream_exist;
2674 int i;
2675
2676 /*
2677 * Relinquish credits from all implicitly created pstreams
2678 * since when we go to sleep. If user created explicit
2679 * thinstreams exists with in a fatpipe leave them intact
2680 * for the user to delete.
2681 */
2682 spin_lock_bh(&wmi->lock);
2683 stream_exist = wmi->fat_pipe_exist;
2684 spin_unlock_bh(&wmi->lock);
2685
2686 for (i = 0; i < WMM_NUM_AC; i++) {
2687 if (stream_exist & (1 << i)) {
2688
2689 /*
2690 * FIXME: Is this lock & unlock inside
2691 * for loop correct? may need rework.
2692 */
2693 spin_lock_bh(&wmi->lock);
2694 active_tsids = wmi->stream_exist_for_ac[i];
2695 spin_unlock_bh(&wmi->lock);
2696
2697 /*
2698 * If there are no user created thin streams
2699 * delete the fatpipe
2700 */
2701 if (!active_tsids) {
2702 stream_exist &= ~(1 << i);
2703 /*
2704 * Indicate inactivity to driver layer for
2705 * this fatpipe (pstream)
2706 */
2707 ath6kl_indicate_tx_activity(wmi->parent_dev,
2708 i, false);
2709 }
2710 }
2711 }
2712
2713 /* FIXME: Can we do this assignment without locking ? */
2714 spin_lock_bh(&wmi->lock);
2715 wmi->fat_pipe_exist = stream_exist;
2716 spin_unlock_bh(&wmi->lock);
2717}
2718
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302719static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
2720 const struct cfg80211_bitrate_mask *mask)
2721{
2722 struct sk_buff *skb;
2723 int ret, mode, band;
Kalle Valof8c03052012-07-12 12:13:12 +03002724 u64 mcsrate, ratemask[ATH6KL_NUM_BANDS];
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302725 struct wmi_set_tx_select_rates64_cmd *cmd;
2726
2727 memset(&ratemask, 0, sizeof(ratemask));
Kalle Valof8c03052012-07-12 12:13:12 +03002728
2729 /* only check 2.4 and 5 GHz bands, skip the rest */
2730 for (band = 0; band <= IEEE80211_BAND_5GHZ; band++) {
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302731 /* copy legacy rate mask */
2732 ratemask[band] = mask->control[band].legacy;
2733 if (band == IEEE80211_BAND_5GHZ)
2734 ratemask[band] =
2735 mask->control[band].legacy << 4;
2736
2737 /* copy mcs rate mask */
2738 mcsrate = mask->control[band].mcs[1];
2739 mcsrate <<= 8;
2740 mcsrate |= mask->control[band].mcs[0];
2741 ratemask[band] |= mcsrate << 12;
2742 ratemask[band] |= mcsrate << 28;
2743 }
2744
2745 ath6kl_dbg(ATH6KL_DBG_WMI,
2746 "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
2747 ratemask[0], ratemask[1]);
2748
2749 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2750 if (!skb)
2751 return -ENOMEM;
2752
2753 cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
2754 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2755 /* A mode operate in 5GHZ band */
2756 if (mode == WMI_RATES_MODE_11A ||
2757 mode == WMI_RATES_MODE_11A_HT20 ||
2758 mode == WMI_RATES_MODE_11A_HT40)
2759 band = IEEE80211_BAND_5GHZ;
2760 else
2761 band = IEEE80211_BAND_2GHZ;
2762 cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
2763 }
2764
2765 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2766 WMI_SET_TX_SELECT_RATES_CMDID,
2767 NO_SYNC_WMIFLAG);
2768 return ret;
2769}
2770
2771static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
2772 const struct cfg80211_bitrate_mask *mask)
2773{
2774 struct sk_buff *skb;
2775 int ret, mode, band;
Kalle Valof8c03052012-07-12 12:13:12 +03002776 u32 mcsrate, ratemask[ATH6KL_NUM_BANDS];
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302777 struct wmi_set_tx_select_rates32_cmd *cmd;
2778
2779 memset(&ratemask, 0, sizeof(ratemask));
Kalle Valof8c03052012-07-12 12:13:12 +03002780
2781 /* only check 2.4 and 5 GHz bands, skip the rest */
2782 for (band = 0; band <= IEEE80211_BAND_5GHZ; band++) {
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302783 /* copy legacy rate mask */
2784 ratemask[band] = mask->control[band].legacy;
2785 if (band == IEEE80211_BAND_5GHZ)
2786 ratemask[band] =
2787 mask->control[band].legacy << 4;
2788
2789 /* copy mcs rate mask */
2790 mcsrate = mask->control[band].mcs[0];
2791 ratemask[band] |= mcsrate << 12;
2792 ratemask[band] |= mcsrate << 20;
2793 }
2794
2795 ath6kl_dbg(ATH6KL_DBG_WMI,
2796 "Ratemask 32 bit: 2.4:%x 5:%x\n",
2797 ratemask[0], ratemask[1]);
2798
2799 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2800 if (!skb)
2801 return -ENOMEM;
2802
2803 cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
2804 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2805 /* A mode operate in 5GHZ band */
2806 if (mode == WMI_RATES_MODE_11A ||
2807 mode == WMI_RATES_MODE_11A_HT20 ||
2808 mode == WMI_RATES_MODE_11A_HT40)
2809 band = IEEE80211_BAND_5GHZ;
2810 else
2811 band = IEEE80211_BAND_2GHZ;
2812 cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
2813 }
2814
2815 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2816 WMI_SET_TX_SELECT_RATES_CMDID,
2817 NO_SYNC_WMIFLAG);
2818 return ret;
2819}
2820
2821int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
2822 const struct cfg80211_bitrate_mask *mask)
2823{
2824 struct ath6kl *ar = wmi->parent_dev;
2825
Mohammed Shafi Shajakhanc0b34e22012-09-27 18:19:50 +05302826 if (ar->hw.flags & ATH6KL_HW_64BIT_RATES)
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302827 return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
2828 else
2829 return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
2830}
2831
Raja Mani45cf1102011-11-07 22:52:45 +02002832int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2833 enum ath6kl_host_mode host_mode)
2834{
2835 struct sk_buff *skb;
2836 struct wmi_set_host_sleep_mode_cmd *cmd;
2837 int ret;
2838
2839 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2840 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2841 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2842 return -EINVAL;
2843 }
2844
2845 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2846 if (!skb)
2847 return -ENOMEM;
2848
2849 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2850
2851 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2852 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2853 cmd->asleep = cpu_to_le32(1);
2854 } else
2855 cmd->awake = cpu_to_le32(1);
2856
2857 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2858 WMI_SET_HOST_SLEEP_MODE_CMDID,
2859 NO_SYNC_WMIFLAG);
2860 return ret;
2861}
2862
Raja Mani081c7a82012-01-30 17:13:11 +05302863/* This command has zero length payload */
2864static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2865 struct ath6kl_vif *vif)
2866{
2867 struct ath6kl *ar = wmi->parent_dev;
2868
2869 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2870 wake_up(&ar->event_wq);
2871
2872 return 0;
2873}
2874
Raja Mani45cf1102011-11-07 22:52:45 +02002875int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2876 enum ath6kl_wow_mode wow_mode,
2877 u32 filter, u16 host_req_delay)
2878{
2879 struct sk_buff *skb;
2880 struct wmi_set_wow_mode_cmd *cmd;
2881 int ret;
2882
2883 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
Kalle Valo96f1fad2012-03-07 20:03:57 +02002884 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
Raja Mani45cf1102011-11-07 22:52:45 +02002885 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2886 return -EINVAL;
2887 }
2888
2889 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2890 if (!skb)
2891 return -ENOMEM;
2892
2893 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2894 cmd->enable_wow = cpu_to_le32(wow_mode);
2895 cmd->filter = cpu_to_le32(filter);
2896 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2897
2898 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2899 NO_SYNC_WMIFLAG);
2900 return ret;
2901}
2902
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002903int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2904 u8 list_id, u8 filter_size,
Raja Manid91e8ee2012-01-30 17:13:10 +05302905 u8 filter_offset, const u8 *filter,
2906 const u8 *mask)
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002907{
2908 struct sk_buff *skb;
2909 struct wmi_add_wow_pattern_cmd *cmd;
2910 u16 size;
2911 u8 *filter_mask;
2912 int ret;
2913
2914 /*
2915 * Allocate additional memory in the buffer to hold
2916 * filter and mask value, which is twice of filter_size.
2917 */
2918 size = sizeof(*cmd) + (2 * filter_size);
2919
2920 skb = ath6kl_wmi_get_new_buf(size);
2921 if (!skb)
2922 return -ENOMEM;
2923
2924 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2925 cmd->filter_list_id = list_id;
2926 cmd->filter_size = filter_size;
2927 cmd->filter_offset = filter_offset;
2928
2929 memcpy(cmd->filter, filter, filter_size);
2930
2931 filter_mask = (u8 *) (cmd->filter + filter_size);
2932 memcpy(filter_mask, mask, filter_size);
2933
2934 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2935 NO_SYNC_WMIFLAG);
2936
2937 return ret;
2938}
2939
2940int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2941 u16 list_id, u16 filter_id)
2942{
2943 struct sk_buff *skb;
2944 struct wmi_del_wow_pattern_cmd *cmd;
2945 int ret;
2946
2947 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2948 if (!skb)
2949 return -ENOMEM;
2950
2951 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
2952 cmd->filter_list_id = cpu_to_le16(list_id);
2953 cmd->filter_id = cpu_to_le16(filter_id);
2954
2955 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
2956 NO_SYNC_WMIFLAG);
2957 return ret;
2958}
2959
Kalle Valobdcd8172011-07-18 00:22:30 +03002960static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2961 enum wmix_command_id cmd_id,
2962 enum wmi_sync_flag sync_flag)
2963{
2964 struct wmix_cmd_hdr *cmd_hdr;
2965 int ret;
2966
2967 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2968
2969 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2970 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2971
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302972 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03002973
2974 return ret;
2975}
2976
2977int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2978{
2979 struct sk_buff *skb;
2980 struct wmix_hb_challenge_resp_cmd *cmd;
2981 int ret;
2982
2983 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2984 if (!skb)
2985 return -ENOMEM;
2986
2987 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2988 cmd->cookie = cpu_to_le32(cookie);
2989 cmd->source = cpu_to_le32(source);
2990
2991 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2992 NO_SYNC_WMIFLAG);
2993 return ret;
2994}
2995
Kalle Valo939f1cc2011-09-02 10:32:04 +03002996int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2997{
2998 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2999 struct sk_buff *skb;
3000 int ret;
3001
3002 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3003 if (!skb)
3004 return -ENOMEM;
3005
3006 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
3007 cmd->valid = cpu_to_le32(valid);
3008 cmd->config = cpu_to_le32(config);
3009
3010 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
3011 NO_SYNC_WMIFLAG);
3012 return ret;
3013}
3014
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303015int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03003016{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303017 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03003018}
3019
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303020int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
Kalle Valobdcd8172011-07-18 00:22:30 +03003021{
3022 struct sk_buff *skb;
3023 struct wmi_set_tx_pwr_cmd *cmd;
3024 int ret;
3025
3026 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
3027 if (!skb)
3028 return -ENOMEM;
3029
3030 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
3031 cmd->dbM = dbM;
3032
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303033 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003034 NO_SYNC_WMIFLAG);
3035
3036 return ret;
3037}
3038
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303039int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03003040{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05303041 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03003042}
3043
Jouni Malinen4b28a802011-10-11 17:31:54 +03003044int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
3045{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303046 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
Jouni Malinen4b28a802011-10-11 17:31:54 +03003047}
3048
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303049int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
3050 u8 preamble_policy)
Kalle Valobdcd8172011-07-18 00:22:30 +03003051{
3052 struct sk_buff *skb;
3053 struct wmi_set_lpreamble_cmd *cmd;
3054 int ret;
3055
3056 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
3057 if (!skb)
3058 return -ENOMEM;
3059
3060 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
3061 cmd->status = status;
3062 cmd->preamble_policy = preamble_policy;
3063
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303064 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003065 NO_SYNC_WMIFLAG);
3066 return ret;
3067}
3068
3069int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
3070{
3071 struct sk_buff *skb;
3072 struct wmi_set_rts_cmd *cmd;
3073 int ret;
3074
3075 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
3076 if (!skb)
3077 return -ENOMEM;
3078
3079 cmd = (struct wmi_set_rts_cmd *) skb->data;
3080 cmd->threshold = cpu_to_le16(threshold);
3081
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303082 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
3083 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03003084 return ret;
3085}
3086
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303087int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
Kalle Valobdcd8172011-07-18 00:22:30 +03003088{
3089 struct sk_buff *skb;
3090 struct wmi_set_wmm_txop_cmd *cmd;
3091 int ret;
3092
3093 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
3094 return -EINVAL;
3095
3096 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
3097 if (!skb)
3098 return -ENOMEM;
3099
3100 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
3101 cmd->txop_enable = cfg;
3102
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303103 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003104 NO_SYNC_WMIFLAG);
3105 return ret;
3106}
3107
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303108int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
3109 u8 keep_alive_intvl)
Kalle Valobdcd8172011-07-18 00:22:30 +03003110{
3111 struct sk_buff *skb;
3112 struct wmi_set_keepalive_cmd *cmd;
3113 int ret;
3114
3115 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3116 if (!skb)
3117 return -ENOMEM;
3118
3119 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
3120 cmd->keep_alive_intvl = keep_alive_intvl;
Kalle Valobdcd8172011-07-18 00:22:30 +03003121
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303122 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003123 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303124
Jouni Malinenff0b0072011-10-11 17:31:56 +03003125 if (ret == 0)
3126 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303127
Kalle Valobdcd8172011-07-18 00:22:30 +03003128 return ret;
3129}
3130
Vasanthakumar Thiagarajandf90b362012-04-09 19:03:58 +05303131int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
3132 enum ieee80211_band band,
3133 struct ath6kl_htcap *htcap)
3134{
3135 struct sk_buff *skb;
3136 struct wmi_set_htcap_cmd *cmd;
3137
3138 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3139 if (!skb)
3140 return -ENOMEM;
3141
3142 cmd = (struct wmi_set_htcap_cmd *) skb->data;
3143
3144 /*
3145 * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely
3146 * this will be changed in firmware. If at all there is any change in
3147 * band value, the host needs to be fixed.
3148 */
3149 cmd->band = band;
3150 cmd->ht_enable = !!htcap->ht_enable;
3151 cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
3152 cmd->ht40_supported =
3153 !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
3154 cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
3155 cmd->intolerant_40mhz =
3156 !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
3157 cmd->max_ampdu_len_exp = htcap->ampdu_factor;
3158
3159 ath6kl_dbg(ATH6KL_DBG_WMI,
3160 "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
3161 cmd->band, cmd->ht_enable, cmd->ht40_supported,
3162 cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
3163 cmd->max_ampdu_len_exp);
3164 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
3165 NO_SYNC_WMIFLAG);
3166}
3167
Kalle Valo003353b0d2011-09-01 10:14:21 +03003168int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
3169{
3170 struct sk_buff *skb;
3171 int ret;
3172
3173 skb = ath6kl_wmi_get_new_buf(len);
3174 if (!skb)
3175 return -ENOMEM;
3176
3177 memcpy(skb->data, buf, len);
3178
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303179 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003180
3181 return ret;
3182}
3183
Vasanthakumar Thiagarajan3f3c4ee2012-01-03 14:41:59 +05303184int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
3185{
3186 struct sk_buff *skb;
3187 struct wmi_mcast_filter_cmd *cmd;
3188 int ret;
3189
3190 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3191 if (!skb)
3192 return -ENOMEM;
3193
3194 cmd = (struct wmi_mcast_filter_cmd *) skb->data;
3195 cmd->mcast_all_enable = mc_all_on;
3196
3197 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
3198 NO_SYNC_WMIFLAG);
3199 return ret;
3200}
Kalle Valo003353b0d2011-09-01 10:14:21 +03003201
Vasanthakumar Thiagarajanf914edd2012-01-03 14:42:00 +05303202int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
3203 u8 *filter, bool add_filter)
3204{
3205 struct sk_buff *skb;
3206 struct wmi_mcast_filter_add_del_cmd *cmd;
3207 int ret;
3208
3209 if ((filter[0] != 0x33 || filter[1] != 0x33) &&
3210 (filter[0] != 0x01 || filter[1] != 0x00 ||
3211 filter[2] != 0x5e || filter[3] > 0x7f)) {
3212 ath6kl_warn("invalid multicast filter address\n");
3213 return -EINVAL;
3214 }
3215
3216 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3217 if (!skb)
3218 return -ENOMEM;
3219
3220 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
3221 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
3222 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3223 add_filter ? WMI_SET_MCAST_FILTER_CMDID :
3224 WMI_DEL_MCAST_FILTER_CMDID,
3225 NO_SYNC_WMIFLAG);
3226
3227 return ret;
3228}
3229
Thomas Pedersenc422d52d2012-05-15 00:09:23 -07003230int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
3231{
3232 struct sk_buff *skb;
3233 struct wmi_sta_bmiss_enhance_cmd *cmd;
3234 int ret;
3235
3236 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3237 if (!skb)
3238 return -ENOMEM;
3239
3240 cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
3241 cmd->enable = enhance ? 1 : 0;
3242
3243 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3244 WMI_STA_BMISS_ENHANCE_CMDID,
3245 NO_SYNC_WMIFLAG);
3246 return ret;
3247}
3248
Kalle Valo84841ba2012-07-19 16:00:56 +03003249int ath6kl_wmi_set_regdomain_cmd(struct wmi *wmi, const char *alpha2)
3250{
3251 struct sk_buff *skb;
3252 struct wmi_set_regdomain_cmd *cmd;
3253
3254 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3255 if (!skb)
3256 return -ENOMEM;
3257
3258 cmd = (struct wmi_set_regdomain_cmd *) skb->data;
3259 memcpy(cmd->iso_name, alpha2, 2);
3260
3261 return ath6kl_wmi_cmd_send(wmi, 0, skb,
3262 WMI_SET_REGDOMAIN_CMDID,
3263 NO_SYNC_WMIFLAG);
3264}
3265
Kalle Valobdcd8172011-07-18 00:22:30 +03003266s32 ath6kl_wmi_get_rate(s8 rate_index)
3267{
Dengke Qiu83685092012-08-28 15:33:42 +08003268 u8 sgi = 0;
3269
Kalle Valobdcd8172011-07-18 00:22:30 +03003270 if (rate_index == RATE_AUTO)
3271 return 0;
3272
Dengke Qiu83685092012-08-28 15:33:42 +08003273 /* SGI is stored as the MSB of the rate_index */
3274 if (rate_index & RATE_INDEX_MSB) {
3275 rate_index &= RATE_INDEX_WITHOUT_SGI_MASK;
3276 sgi = 1;
3277 }
3278
3279 if (WARN_ON(rate_index > RATE_MCS_7_40))
3280 rate_index = RATE_MCS_7_40;
3281
3282 return wmi_rate_tbl[(u32) rate_index][sgi];
Kalle Valobdcd8172011-07-18 00:22:30 +03003283}
3284
Kalle Valobdcd8172011-07-18 00:22:30 +03003285static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
3286 u32 len)
3287{
3288 struct wmi_pmkid_list_reply *reply;
3289 u32 expected_len;
3290
3291 if (len < sizeof(struct wmi_pmkid_list_reply))
3292 return -EINVAL;
3293
3294 reply = (struct wmi_pmkid_list_reply *)datap;
3295 expected_len = sizeof(reply->num_pmkid) +
3296 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
3297
3298 if (len < expected_len)
3299 return -EINVAL;
3300
3301 return 0;
3302}
3303
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303304static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3305 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003306{
3307 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
3308
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303309 aggr_recv_addba_req_evt(vif, cmd->tid,
Kalle Valobdcd8172011-07-18 00:22:30 +03003310 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
3311
3312 return 0;
3313}
3314
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303315static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3316 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003317{
3318 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
3319
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303320 aggr_recv_delba_req_evt(vif, cmd->tid);
Kalle Valobdcd8172011-07-18 00:22:30 +03003321
3322 return 0;
3323}
3324
3325/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003326
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303327int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
3328 struct wmi_connect_cmd *p)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003329{
3330 struct sk_buff *skb;
3331 struct wmi_connect_cmd *cm;
3332 int res;
3333
3334 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3335 if (!skb)
3336 return -ENOMEM;
3337
3338 cm = (struct wmi_connect_cmd *) skb->data;
3339 memcpy(cm, p, sizeof(*cm));
3340
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303341 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003342 NO_SYNC_WMIFLAG);
Kalle Valocdeb8602012-04-12 11:02:18 +03003343 ath6kl_dbg(ATH6KL_DBG_WMI,
3344 "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003345 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
3346 le32_to_cpu(p->ctrl_flags), res);
3347 return res;
3348}
3349
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303350int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3351 u16 reason)
Jouni Malinen23875132011-08-30 21:57:53 +03003352{
3353 struct sk_buff *skb;
3354 struct wmi_ap_set_mlme_cmd *cm;
3355
3356 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3357 if (!skb)
3358 return -ENOMEM;
3359
3360 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
3361 memcpy(cm->mac, mac, ETH_ALEN);
3362 cm->reason = cpu_to_le16(reason);
3363 cm->cmd = cmd;
3364
Aarthi Thiruvengadam7397dde2012-03-15 14:36:11 -07003365 ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
3366 cm->reason);
3367
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303368 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
Jouni Malinen23875132011-08-30 21:57:53 +03003369 NO_SYNC_WMIFLAG);
3370}
3371
Thomas Pedersen67cd22e2012-02-28 15:08:46 -08003372int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
3373{
3374 struct sk_buff *skb;
3375 struct wmi_ap_hidden_ssid_cmd *cmd;
3376
3377 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3378 if (!skb)
3379 return -ENOMEM;
3380
3381 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
3382 cmd->hidden_ssid = enable ? 1 : 0;
3383
3384 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
3385 NO_SYNC_WMIFLAG);
3386}
3387
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05303388/* This command will be used to enable/disable AP uAPSD feature */
3389int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3390{
3391 struct wmi_ap_set_apsd_cmd *cmd;
3392 struct sk_buff *skb;
3393
3394 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3395 if (!skb)
3396 return -ENOMEM;
3397
3398 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3399 cmd->enable = enable;
3400
3401 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3402 NO_SYNC_WMIFLAG);
3403}
3404
3405int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3406 u16 aid, u16 bitmap, u32 flags)
3407{
3408 struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3409 struct sk_buff *skb;
3410
3411 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3412 if (!skb)
3413 return -ENOMEM;
3414
3415 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3416 cmd->aid = cpu_to_le16(aid);
3417 cmd->bitmap = cpu_to_le16(bitmap);
3418 cmd->flags = cpu_to_le32(flags);
3419
3420 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3421 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3422 NO_SYNC_WMIFLAG);
3423}
3424
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303425static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3426 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003427{
3428 struct wmi_pspoll_event *ev;
3429
3430 if (len < sizeof(struct wmi_pspoll_event))
3431 return -EINVAL;
3432
3433 ev = (struct wmi_pspoll_event *) datap;
3434
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303435 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
Kalle Valobdcd8172011-07-18 00:22:30 +03003436
3437 return 0;
3438}
3439
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303440static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3441 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003442{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303443 ath6kl_dtimexpiry_event(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03003444
3445 return 0;
3446}
3447
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303448int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3449 bool flag)
Kalle Valobdcd8172011-07-18 00:22:30 +03003450{
3451 struct sk_buff *skb;
3452 struct wmi_ap_set_pvb_cmd *cmd;
3453 int ret;
3454
3455 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3456 if (!skb)
3457 return -ENOMEM;
3458
3459 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3460 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03003461 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03003462 cmd->flag = cpu_to_le32(flag);
3463
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303464 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003465 NO_SYNC_WMIFLAG);
3466
3467 return 0;
3468}
3469
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303470int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
3471 u8 rx_meta_ver,
Kalle Valobdcd8172011-07-18 00:22:30 +03003472 bool rx_dot11_hdr, bool defrag_on_host)
3473{
3474 struct sk_buff *skb;
3475 struct wmi_rx_frame_format_cmd *cmd;
3476 int ret;
3477
3478 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3479 if (!skb)
3480 return -ENOMEM;
3481
3482 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3483 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3484 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3485 cmd->meta_ver = rx_meta_ver;
3486
3487 /* Delete the local aggr state, on host */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303488 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003489 NO_SYNC_WMIFLAG);
3490
3491 return ret;
3492}
3493
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303494int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3495 const u8 *ie, u8 ie_len)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003496{
3497 struct sk_buff *skb;
3498 struct wmi_set_appie_cmd *p;
3499
3500 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3501 if (!skb)
3502 return -ENOMEM;
3503
Kalle Valocdeb8602012-04-12 11:02:18 +03003504 ath6kl_dbg(ATH6KL_DBG_WMI,
3505 "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
3506 mgmt_frm_type, ie_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003507 p = (struct wmi_set_appie_cmd *) skb->data;
3508 p->mgmt_frm_type = mgmt_frm_type;
3509 p->ie_len = ie_len;
Kalle Valo10509f92011-12-13 14:52:07 +02003510
3511 if (ie != NULL && ie_len > 0)
3512 memcpy(p->ie_info, ie, ie_len);
3513
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303514 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003515 NO_SYNC_WMIFLAG);
3516}
3517
Vasanthakumar Thiagarajand97c1212012-04-09 20:51:20 +05303518int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
3519 const u8 *ie_info, u8 ie_len)
3520{
3521 struct sk_buff *skb;
3522 struct wmi_set_ie_cmd *p;
3523
3524 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3525 if (!skb)
3526 return -ENOMEM;
3527
3528 ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
3529 ie_id, ie_field, ie_len);
3530 p = (struct wmi_set_ie_cmd *) skb->data;
3531 p->ie_id = ie_id;
3532 p->ie_field = ie_field;
3533 p->ie_len = ie_len;
3534 if (ie_info && ie_len > 0)
3535 memcpy(p->ie_info, ie_info, ie_len);
3536
3537 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
3538 NO_SYNC_WMIFLAG);
3539}
3540
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003541int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
3542{
3543 struct sk_buff *skb;
3544 struct wmi_disable_11b_rates_cmd *cmd;
3545
3546 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3547 if (!skb)
3548 return -ENOMEM;
3549
3550 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
3551 disable);
3552 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
3553 cmd->disable = disable ? 1 : 0;
3554
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303555 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003556 NO_SYNC_WMIFLAG);
3557}
3558
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303559int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003560{
3561 struct sk_buff *skb;
3562 struct wmi_remain_on_chnl_cmd *p;
3563
3564 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3565 if (!skb)
3566 return -ENOMEM;
3567
3568 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3569 freq, dur);
3570 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3571 p->freq = cpu_to_le32(freq);
3572 p->duration = cpu_to_le32(dur);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303573 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003574 NO_SYNC_WMIFLAG);
3575}
3576
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003577/* ath6kl_wmi_send_action_cmd is to be deprecated. Use
3578 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
3579 * mgmt operations using station interface.
3580 */
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003581static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3582 u32 freq, u32 wait, const u8 *data,
3583 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003584{
3585 struct sk_buff *skb;
3586 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03003587 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003588
3589 if (wait)
3590 return -EINVAL; /* Offload for wait not supported */
3591
Jouni Malinena0df5db2011-08-30 21:58:02 +03003592 buf = kmalloc(data_len, GFP_KERNEL);
3593 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003594 return -ENOMEM;
3595
Jouni Malinena0df5db2011-08-30 21:58:02 +03003596 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3597 if (!skb) {
3598 kfree(buf);
3599 return -ENOMEM;
3600 }
3601
3602 kfree(wmi->last_mgmt_tx_frame);
Aarthi Thiruvengadam3101ede2011-10-27 09:35:56 -07003603 memcpy(buf, data, data_len);
Jouni Malinena0df5db2011-08-30 21:58:02 +03003604 wmi->last_mgmt_tx_frame = buf;
3605 wmi->last_mgmt_tx_frame_len = data_len;
3606
Kalle Valocdeb8602012-04-12 11:02:18 +03003607 ath6kl_dbg(ATH6KL_DBG_WMI,
3608 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3609 id, freq, wait, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003610 p = (struct wmi_send_action_cmd *) skb->data;
3611 p->id = cpu_to_le32(id);
3612 p->freq = cpu_to_le32(freq);
3613 p->wait = cpu_to_le32(wait);
3614 p->len = cpu_to_le16(data_len);
3615 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303616 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003617 NO_SYNC_WMIFLAG);
3618}
3619
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003620static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3621 u32 freq, u32 wait, const u8 *data,
3622 u16 data_len, u32 no_cck)
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003623{
3624 struct sk_buff *skb;
3625 struct wmi_send_mgmt_cmd *p;
3626 u8 *buf;
3627
3628 if (wait)
3629 return -EINVAL; /* Offload for wait not supported */
3630
3631 buf = kmalloc(data_len, GFP_KERNEL);
3632 if (!buf)
3633 return -ENOMEM;
3634
3635 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3636 if (!skb) {
3637 kfree(buf);
3638 return -ENOMEM;
3639 }
3640
3641 kfree(wmi->last_mgmt_tx_frame);
3642 memcpy(buf, data, data_len);
3643 wmi->last_mgmt_tx_frame = buf;
3644 wmi->last_mgmt_tx_frame_len = data_len;
3645
Kalle Valocdeb8602012-04-12 11:02:18 +03003646 ath6kl_dbg(ATH6KL_DBG_WMI,
3647 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3648 id, freq, wait, data_len);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003649 p = (struct wmi_send_mgmt_cmd *) skb->data;
3650 p->id = cpu_to_le32(id);
3651 p->freq = cpu_to_le32(freq);
3652 p->wait = cpu_to_le32(wait);
3653 p->no_cck = cpu_to_le32(no_cck);
3654 p->len = cpu_to_le16(data_len);
3655 memcpy(p->data, data, data_len);
3656 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
3657 NO_SYNC_WMIFLAG);
3658}
3659
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003660int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3661 u32 wait, const u8 *data, u16 data_len,
3662 u32 no_cck)
3663{
3664 int status;
3665 struct ath6kl *ar = wmi->parent_dev;
3666
3667 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3668 ar->fw_capabilities)) {
3669 /*
3670 * If capable of doing P2P mgmt operations using
3671 * station interface, send additional information like
3672 * supported rates to advertise and xmit rates for
3673 * probe requests
3674 */
3675 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3676 wait, data, data_len,
3677 no_cck);
3678 } else {
3679 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3680 wait, data, data_len);
3681 }
3682
3683 return status;
3684}
3685
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303686int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3687 const u8 *dst, const u8 *data,
3688 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003689{
3690 struct sk_buff *skb;
3691 struct wmi_p2p_probe_response_cmd *p;
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003692 size_t cmd_len = sizeof(*p) + data_len;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003693
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003694 if (data_len == 0)
3695 cmd_len++; /* work around target minimum length requirement */
3696
3697 skb = ath6kl_wmi_get_new_buf(cmd_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003698 if (!skb)
3699 return -ENOMEM;
3700
Kalle Valocdeb8602012-04-12 11:02:18 +03003701 ath6kl_dbg(ATH6KL_DBG_WMI,
3702 "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
3703 freq, dst, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003704 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3705 p->freq = cpu_to_le32(freq);
3706 memcpy(p->destination_addr, dst, ETH_ALEN);
3707 p->len = cpu_to_le16(data_len);
3708 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303709 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3710 WMI_SEND_PROBE_RESPONSE_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003711 NO_SYNC_WMIFLAG);
3712}
3713
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303714int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003715{
3716 struct sk_buff *skb;
3717 struct wmi_probe_req_report_cmd *p;
3718
3719 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3720 if (!skb)
3721 return -ENOMEM;
3722
3723 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3724 enable);
3725 p = (struct wmi_probe_req_report_cmd *) skb->data;
3726 p->enable = enable ? 1 : 0;
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303727 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003728 NO_SYNC_WMIFLAG);
3729}
3730
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303731int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003732{
3733 struct sk_buff *skb;
3734 struct wmi_get_p2p_info *p;
3735
3736 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3737 if (!skb)
3738 return -ENOMEM;
3739
3740 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3741 info_req_flags);
3742 p = (struct wmi_get_p2p_info *) skb->data;
3743 p->info_req_flags = cpu_to_le32(info_req_flags);
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303744 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003745 NO_SYNC_WMIFLAG);
3746}
3747
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303748int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003749{
3750 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303751 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3752 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003753}
3754
Vasanthakumar Thiagarajan03bdeb02012-03-21 20:58:39 +05303755int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
3756{
3757 struct sk_buff *skb;
3758 struct wmi_set_inact_period_cmd *cmd;
3759
3760 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3761 if (!skb)
3762 return -ENOMEM;
3763
3764 cmd = (struct wmi_set_inact_period_cmd *) skb->data;
3765 cmd->inact_period = cpu_to_le32(inact_timeout);
3766 cmd->num_null_func = 0;
3767
3768 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
3769 NO_SYNC_WMIFLAG);
3770}
3771
Vasanthakumar Thiagarajan92332992012-08-29 19:40:27 +05303772static void ath6kl_wmi_hb_challenge_resp_event(struct wmi *wmi, u8 *datap,
3773 int len)
3774{
3775 struct wmix_hb_challenge_resp_cmd *cmd;
3776
3777 if (len < sizeof(struct wmix_hb_challenge_resp_cmd))
3778 return;
3779
3780 cmd = (struct wmix_hb_challenge_resp_cmd *) datap;
3781 ath6kl_recovery_hb_event(wmi->parent_dev,
3782 le32_to_cpu(cmd->cookie));
3783}
3784
Kalle Valobdcd8172011-07-18 00:22:30 +03003785static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3786{
3787 struct wmix_cmd_hdr *cmd;
3788 u32 len;
3789 u16 id;
3790 u8 *datap;
3791 int ret = 0;
3792
3793 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3794 ath6kl_err("bad packet 1\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003795 return -EINVAL;
3796 }
3797
3798 cmd = (struct wmix_cmd_hdr *) skb->data;
3799 id = le32_to_cpu(cmd->cmd_id);
3800
3801 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3802
3803 datap = skb->data;
3804 len = skb->len;
3805
3806 switch (id) {
3807 case WMIX_HB_CHALLENGE_RESP_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003808 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
Vasanthakumar Thiagarajan92332992012-08-29 19:40:27 +05303809 ath6kl_wmi_hb_challenge_resp_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003810 break;
3811 case WMIX_DBGLOG_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003812 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
Kalle Valobdf53962011-09-02 10:32:04 +03003813 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003814 break;
3815 default:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003816 ath6kl_warn("unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03003817 ret = -EINVAL;
3818 break;
3819 }
3820
3821 return ret;
3822}
3823
Jouni Malinen4b28a802011-10-11 17:31:54 +03003824static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3825{
3826 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3827}
3828
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303829/* Process interface specific wmi events, caller would free the datap */
3830static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
3831 u8 *datap, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03003832{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303833 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03003834
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303835 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3836 if (!vif) {
3837 ath6kl_dbg(ATH6KL_DBG_WMI,
3838 "Wmi event for unavailable vif, vif_index:%d\n",
3839 if_idx);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303840 return -EINVAL;
3841 }
3842
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303843 switch (cmd_id) {
3844 case WMI_CONNECT_EVENTID:
3845 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3846 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3847 case WMI_DISCONNECT_EVENTID:
3848 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3849 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3850 case WMI_TKIP_MICERR_EVENTID:
3851 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3852 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3853 case WMI_BSSINFO_EVENTID:
3854 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3855 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3856 case WMI_NEIGHBOR_REPORT_EVENTID:
3857 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3858 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3859 vif);
3860 case WMI_SCAN_COMPLETE_EVENTID:
3861 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3862 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3863 case WMI_REPORT_STATISTICS_EVENTID:
3864 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3865 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3866 case WMI_CAC_EVENTID:
3867 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3868 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3869 case WMI_PSPOLL_EVENTID:
3870 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3871 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3872 case WMI_DTIMEXPIRY_EVENTID:
3873 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3874 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3875 case WMI_ADDBA_REQ_EVENTID:
3876 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3877 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3878 case WMI_DELBA_REQ_EVENTID:
3879 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3880 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3881 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
3882 ath6kl_dbg(ATH6KL_DBG_WMI,
3883 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
3884 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
3885 case WMI_REMAIN_ON_CHNL_EVENTID:
3886 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3887 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3888 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3889 ath6kl_dbg(ATH6KL_DBG_WMI,
3890 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3891 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3892 len, vif);
3893 case WMI_TX_STATUS_EVENTID:
3894 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3895 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3896 case WMI_RX_PROBE_REQ_EVENTID:
3897 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3898 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3899 case WMI_RX_ACTION_EVENTID:
3900 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3901 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
Thomas Pedersen279b2862012-07-17 19:39:55 -07003902 case WMI_TXE_NOTIFY_EVENTID:
3903 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
3904 return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303905 default:
3906 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
3907 return -EINVAL;
3908 }
3909
3910 return 0;
3911}
3912
3913static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
3914{
3915 struct wmi_cmd_hdr *cmd;
3916 int ret = 0;
3917 u32 len;
3918 u16 id;
3919 u8 if_idx;
3920 u8 *datap;
3921
3922 cmd = (struct wmi_cmd_hdr *) skb->data;
3923 id = le16_to_cpu(cmd->cmd_id);
3924 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
3925
3926 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3927 datap = skb->data;
3928 len = skb->len;
3929
3930 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3931 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3932 datap, len);
3933
Kalle Valobdcd8172011-07-18 00:22:30 +03003934 switch (id) {
3935 case WMI_GET_BITRATE_CMDID:
3936 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3937 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3938 break;
3939 case WMI_GET_CHANNEL_LIST_CMDID:
3940 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3941 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3942 break;
3943 case WMI_GET_TX_PWR_CMDID:
3944 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3945 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3946 break;
3947 case WMI_READY_EVENTID:
3948 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3949 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3950 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003951 case WMI_PEER_NODE_EVENTID:
3952 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3953 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3954 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003955 case WMI_REGDOMAIN_EVENTID:
3956 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05303957 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003958 break;
3959 case WMI_PSTREAM_TIMEOUT_EVENTID:
3960 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3961 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3962 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003963 case WMI_CMDERROR_EVENTID:
3964 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3965 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3966 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003967 case WMI_RSSI_THRESHOLD_EVENTID:
3968 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3969 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3970 break;
3971 case WMI_ERROR_REPORT_EVENTID:
3972 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3973 break;
3974 case WMI_OPT_RX_FRAME_EVENTID:
3975 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03003976 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03003977 break;
3978 case WMI_REPORT_ROAM_TBL_EVENTID:
3979 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
Jouni Malinen4b28a802011-10-11 17:31:54 +03003980 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003981 break;
3982 case WMI_EXTENSION_EVENTID:
3983 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3984 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3985 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003986 case WMI_CHANNEL_CHANGE_EVENTID:
3987 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3988 break;
3989 case WMI_REPORT_ROAM_DATA_EVENTID:
3990 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3991 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03003992 case WMI_TEST_EVENTID:
3993 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08003994 ret = ath6kl_wmi_test_rx(wmi, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003995 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003996 case WMI_GET_FIXRATES_CMDID:
3997 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3998 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3999 break;
4000 case WMI_TX_RETRY_ERR_EVENTID:
4001 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
4002 break;
4003 case WMI_SNR_THRESHOLD_EVENTID:
4004 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
4005 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
4006 break;
4007 case WMI_LQ_THRESHOLD_EVENTID:
4008 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
4009 break;
4010 case WMI_APLIST_EVENTID:
4011 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
4012 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
4013 break;
4014 case WMI_GET_KEEPALIVE_CMDID:
4015 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
4016 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
4017 break;
4018 case WMI_GET_WOW_LIST_EVENTID:
4019 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03004020 break;
4021 case WMI_GET_PMKID_LIST_EVENTID:
4022 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
4023 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
4024 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004025 case WMI_SET_PARAMS_REPLY_EVENTID:
4026 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
4027 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004028 case WMI_ADDBA_RESP_EVENTID:
4029 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
4030 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004031 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
4032 ath6kl_dbg(ATH6KL_DBG_WMI,
4033 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
4034 break;
4035 case WMI_REPORT_BTCOEX_STATS_EVENTID:
4036 ath6kl_dbg(ATH6KL_DBG_WMI,
4037 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
4038 break;
4039 case WMI_TX_COMPLETE_EVENTID:
4040 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
4041 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
4042 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03004043 case WMI_P2P_CAPABILITIES_EVENTID:
4044 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
4045 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
4046 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03004047 case WMI_P2P_INFO_EVENTID:
4048 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
4049 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
4050 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03004051 default:
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05304052 /* may be the event is interface specific */
4053 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03004054 break;
4055 }
4056
4057 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03004058 return ret;
4059}
4060
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05304061/* Control Path */
4062int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
4063{
4064 if (WARN_ON(skb == NULL))
4065 return -EINVAL;
4066
4067 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
4068 ath6kl_err("bad packet 1\n");
4069 dev_kfree_skb(skb);
4070 return -EINVAL;
4071 }
4072
4073 return ath6kl_wmi_proc_events(wmi, skb);
4074}
4075
Kalle Valoc89c5912011-10-27 18:48:00 +03004076void ath6kl_wmi_reset(struct wmi *wmi)
Kalle Valobdcd8172011-07-18 00:22:30 +03004077{
Kalle Valobdcd8172011-07-18 00:22:30 +03004078 spin_lock_bh(&wmi->lock);
4079
4080 wmi->fat_pipe_exist = 0;
4081 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
4082
4083 spin_unlock_bh(&wmi->lock);
4084}
4085
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05304086void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03004087{
4088 struct wmi *wmi;
4089
4090 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
4091 if (!wmi)
4092 return NULL;
4093
4094 spin_lock_init(&wmi->lock);
4095
4096 wmi->parent_dev = dev;
4097
Kalle Valobdcd8172011-07-18 00:22:30 +03004098 wmi->pwr_mode = REC_POWER;
Kalle Valobdcd8172011-07-18 00:22:30 +03004099
Kalle Valoc89c5912011-10-27 18:48:00 +03004100 ath6kl_wmi_reset(wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03004101
4102 return wmi;
4103}
4104
4105void ath6kl_wmi_shutdown(struct wmi *wmi)
4106{
4107 if (!wmi)
4108 return;
4109
Jouni Malinena0df5db2011-08-30 21:58:02 +03004110 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03004111 kfree(wmi);
4112}