blob: 0e05c41cdcfc96edf3c96df5ed1d9b3c2fb22bff [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 Berg42d97a52012-11-08 18:31:02 +0100477 cfg80211_ready_on_channel(&vif->wdev, id, chan,
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 Berg42d97a52012-11-08 18:31:02 +0100516 cfg80211_remain_on_channel_expired(&vif->wdev, id, chan, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300517
518 return 0;
519}
520
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530521static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
522 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300523{
524 struct wmi_tx_status_event *ev;
525 u32 id;
526
527 if (len < sizeof(*ev))
528 return -EINVAL;
529
530 ev = (struct wmi_tx_status_event *) datap;
531 id = le32_to_cpu(ev->id);
532 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
533 id, ev->ack_status);
Jouni Malinena0df5db2011-08-30 21:58:02 +0300534 if (wmi->last_mgmt_tx_frame) {
Johannes Berg71bbc992012-06-15 15:30:18 +0200535 cfg80211_mgmt_tx_status(&vif->wdev, id,
Jouni Malinena0df5db2011-08-30 21:58:02 +0300536 wmi->last_mgmt_tx_frame,
537 wmi->last_mgmt_tx_frame_len,
538 !!ev->ack_status, GFP_ATOMIC);
539 kfree(wmi->last_mgmt_tx_frame);
540 wmi->last_mgmt_tx_frame = NULL;
541 wmi->last_mgmt_tx_frame_len = 0;
542 }
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300543
544 return 0;
545}
546
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530547static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
548 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300549{
550 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300551 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300552 u16 dlen;
553
554 if (len < sizeof(*ev))
555 return -EINVAL;
556
557 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300558 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300559 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300560 if (datap + len < ev->data + dlen) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300561 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
562 len, dlen);
Jouni Malinenae32c302011-08-30 21:58:01 +0300563 return -EINVAL;
564 }
Kalle Valocdeb8602012-04-12 11:02:18 +0300565 ath6kl_dbg(ATH6KL_DBG_WMI,
566 "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530567 dlen, freq, vif->probe_req_report);
Jouni Malinenae32c302011-08-30 21:58:01 +0300568
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530569 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
Johannes Berg71bbc992012-06-15 15:30:18 +0200570 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
Johannes Berg804483e2012-03-05 22:18:41 +0100571 ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300572
573 return 0;
574}
575
576static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
577{
578 struct wmi_p2p_capabilities_event *ev;
579 u16 dlen;
580
581 if (len < sizeof(*ev))
582 return -EINVAL;
583
584 ev = (struct wmi_p2p_capabilities_event *) datap;
585 dlen = le16_to_cpu(ev->len);
586 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
587
588 return 0;
589}
590
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530591static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
592 struct ath6kl_vif *vif)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300593{
594 struct wmi_rx_action_event *ev;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300595 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300596 u16 dlen;
597
598 if (len < sizeof(*ev))
599 return -EINVAL;
600
601 ev = (struct wmi_rx_action_event *) datap;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300602 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300603 dlen = le16_to_cpu(ev->len);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300604 if (datap + len < ev->data + dlen) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300605 ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
606 len, dlen);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300607 return -EINVAL;
608 }
609 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
Johannes Berg71bbc992012-06-15 15:30:18 +0200610 cfg80211_rx_mgmt(&vif->wdev, freq, 0,
Johannes Berg804483e2012-03-05 22:18:41 +0100611 ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300612
613 return 0;
614}
615
616static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
617{
618 struct wmi_p2p_info_event *ev;
619 u32 flags;
620 u16 dlen;
621
622 if (len < sizeof(*ev))
623 return -EINVAL;
624
625 ev = (struct wmi_p2p_info_event *) datap;
626 flags = le32_to_cpu(ev->info_req_flags);
627 dlen = le16_to_cpu(ev->len);
628 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
629
630 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
631 struct wmi_p2p_capabilities *cap;
632 if (dlen < sizeof(*cap))
633 return -EINVAL;
634 cap = (struct wmi_p2p_capabilities *) ev->data;
635 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
636 cap->go_power_save);
637 }
638
639 if (flags & P2P_FLAG_MACADDR_REQ) {
640 struct wmi_p2p_macaddr *mac;
641 if (dlen < sizeof(*mac))
642 return -EINVAL;
643 mac = (struct wmi_p2p_macaddr *) ev->data;
644 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
645 mac->mac_addr);
646 }
647
648 if (flags & P2P_FLAG_HMODEL_REQ) {
649 struct wmi_p2p_hmodel *mod;
650 if (dlen < sizeof(*mod))
651 return -EINVAL;
652 mod = (struct wmi_p2p_hmodel *) ev->data;
653 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
654 mod->p2p_model,
655 mod->p2p_model ? "host" : "firmware");
656 }
657 return 0;
658}
659
Kalle Valobdcd8172011-07-18 00:22:30 +0300660static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
661{
662 struct sk_buff *skb;
663
664 skb = ath6kl_buf_alloc(size);
665 if (!skb)
666 return NULL;
667
668 skb_put(skb, size);
669 if (size)
670 memset(skb->data, 0, size);
671
672 return skb;
673}
674
675/* Send a "simple" wmi command -- one with no arguments */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530676static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
677 enum wmi_cmd_id cmd_id)
Kalle Valobdcd8172011-07-18 00:22:30 +0300678{
679 struct sk_buff *skb;
680 int ret;
681
682 skb = ath6kl_wmi_get_new_buf(0);
683 if (!skb)
684 return -ENOMEM;
685
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530686 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +0300687
688 return ret;
689}
690
691static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
692{
693 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
694
695 if (len < sizeof(struct wmi_ready_event_2))
696 return -EINVAL;
697
Kalle Valobdcd8172011-07-18 00:22:30 +0300698 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
699 le32_to_cpu(ev->sw_version),
Thomas Pedersend92917e2012-04-19 15:31:56 -0700700 le32_to_cpu(ev->abi_version), ev->phy_cap);
Kalle Valobdcd8172011-07-18 00:22:30 +0300701
702 return 0;
703}
704
Vivek Natarajane5090442011-08-31 15:02:19 +0530705/*
706 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
707 * at which the station has to roam can be passed with
708 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
709 * in dBm.
710 */
711int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
712{
713 struct sk_buff *skb;
714 struct roam_ctrl_cmd *cmd;
715
716 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
717 if (!skb)
718 return -ENOMEM;
719
720 cmd = (struct roam_ctrl_cmd *) skb->data;
721
722 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
723 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
724 DEF_SCAN_FOR_ROAM_INTVL);
725 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
726 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
727 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
728
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530729 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
730 NO_SYNC_WMIFLAG);
Vivek Natarajane5090442011-08-31 15:02:19 +0530731
732 return 0;
733}
734
Jouni Malinen12618752011-10-11 17:31:55 +0300735int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
736{
737 struct sk_buff *skb;
738 struct roam_ctrl_cmd *cmd;
739
740 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
741 if (!skb)
742 return -ENOMEM;
743
744 cmd = (struct roam_ctrl_cmd *) skb->data;
Jouni Malinen12618752011-10-11 17:31:55 +0300745
746 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
747 cmd->roam_ctrl = WMI_FORCE_ROAM;
748
749 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530750 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300751 NO_SYNC_WMIFLAG);
752}
753
Etay Luzd154f322012-05-30 11:35:08 +0300754int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
755{
756 struct sk_buff *skb;
757 struct set_dtim_cmd *cmd;
758
759 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
760 if (!skb)
761 return -ENOMEM;
762
763 cmd = (struct set_dtim_cmd *) skb->data;
764
765 cmd->dtim_period = cpu_to_le32(dtim_period);
766 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
767 WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
768}
769
Jouni Malinen12618752011-10-11 17:31:55 +0300770int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
771{
772 struct sk_buff *skb;
773 struct roam_ctrl_cmd *cmd;
774
775 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
776 if (!skb)
777 return -ENOMEM;
778
779 cmd = (struct roam_ctrl_cmd *) skb->data;
Jouni Malinen12618752011-10-11 17:31:55 +0300780
781 cmd->info.roam_mode = mode;
782 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
783
784 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530785 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300786 NO_SYNC_WMIFLAG);
787}
788
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530789static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
790 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300791{
792 struct wmi_connect_event *ev;
793 u8 *pie, *peie;
794
795 if (len < sizeof(struct wmi_connect_event))
796 return -EINVAL;
797
798 ev = (struct wmi_connect_event *) datap;
799
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530800 if (vif->nw_type == AP_NETWORK) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300801 /* AP mode start/STA connected event */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530802 struct net_device *dev = vif->ndev;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300803 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
Kalle Valocdeb8602012-04-12 11:02:18 +0300804 ath6kl_dbg(ATH6KL_DBG_WMI,
805 "%s: freq %d bssid %pM (AP started)\n",
Jouni Malinen572e27c2011-09-05 17:38:45 +0300806 __func__, le16_to_cpu(ev->u.ap_bss.ch),
807 ev->u.ap_bss.bssid);
808 ath6kl_connect_ap_mode_bss(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530809 vif, le16_to_cpu(ev->u.ap_bss.ch));
Jouni Malinen572e27c2011-09-05 17:38:45 +0300810 } else {
Kalle Valocdeb8602012-04-12 11:02:18 +0300811 ath6kl_dbg(ATH6KL_DBG_WMI,
812 "%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 +0300813 __func__, ev->u.ap_sta.aid,
814 ev->u.ap_sta.mac_addr,
815 ev->u.ap_sta.auth,
816 ev->u.ap_sta.keymgmt,
817 le16_to_cpu(ev->u.ap_sta.cipher),
818 ev->u.ap_sta.apsd_info);
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530819
Jouni Malinen572e27c2011-09-05 17:38:45 +0300820 ath6kl_connect_ap_mode_sta(
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530821 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
Jouni Malinen572e27c2011-09-05 17:38:45 +0300822 ev->u.ap_sta.keymgmt,
823 le16_to_cpu(ev->u.ap_sta.cipher),
824 ev->u.ap_sta.auth, ev->assoc_req_len,
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +0530825 ev->assoc_info + ev->beacon_ie_len,
826 ev->u.ap_sta.apsd_info);
Jouni Malinen572e27c2011-09-05 17:38:45 +0300827 }
828 return 0;
829 }
830
831 /* STA/IBSS mode connection event */
832
Kalle Valob9b6ee62011-09-27 14:31:21 +0300833 ath6kl_dbg(ATH6KL_DBG_WMI,
834 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
835 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
836 le16_to_cpu(ev->u.sta.listen_intvl),
837 le16_to_cpu(ev->u.sta.beacon_intvl),
838 le32_to_cpu(ev->u.sta.nw_type));
Kalle Valobdcd8172011-07-18 00:22:30 +0300839
Kalle Valobdcd8172011-07-18 00:22:30 +0300840 /* Start of assoc rsp IEs */
841 pie = ev->assoc_info + ev->beacon_ie_len +
842 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
843
844 /* End of assoc rsp IEs */
845 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
846 ev->assoc_resp_len;
847
848 while (pie < peie) {
849 switch (*pie) {
850 case WLAN_EID_VENDOR_SPECIFIC:
851 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
852 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
853 /* WMM OUT (00:50:F2) */
Kalle Valoddc3d772012-03-07 20:03:58 +0200854 if (pie[1] > 5 &&
855 pie[6] == WMM_PARAM_OUI_SUBTYPE)
Kalle Valobdcd8172011-07-18 00:22:30 +0300856 wmi->is_wmm_enabled = true;
857 }
858 break;
859 }
860
861 if (wmi->is_wmm_enabled)
862 break;
863
864 pie += pie[1] + 2;
865 }
866
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530867 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
Jouni Malinen572e27c2011-09-05 17:38:45 +0300868 ev->u.sta.bssid,
869 le16_to_cpu(ev->u.sta.listen_intvl),
870 le16_to_cpu(ev->u.sta.beacon_intvl),
871 le32_to_cpu(ev->u.sta.nw_type),
Kalle Valobdcd8172011-07-18 00:22:30 +0300872 ev->beacon_ie_len, ev->assoc_req_len,
873 ev->assoc_resp_len, ev->assoc_info);
874
875 return 0;
876}
877
Vivek Natarajan06033762011-09-06 13:01:36 +0530878static struct country_code_to_enum_rd *
879ath6kl_regd_find_country(u16 countryCode)
880{
881 int i;
882
883 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
884 if (allCountries[i].countryCode == countryCode)
885 return &allCountries[i];
886 }
887
888 return NULL;
889}
890
891static struct reg_dmn_pair_mapping *
892ath6kl_get_regpair(u16 regdmn)
893{
894 int i;
895
896 if (regdmn == NO_ENUMRD)
897 return NULL;
898
899 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
900 if (regDomainPairs[i].regDmnEnum == regdmn)
901 return &regDomainPairs[i];
902 }
903
904 return NULL;
905}
906
907static struct country_code_to_enum_rd *
908ath6kl_regd_find_country_by_rd(u16 regdmn)
909{
910 int i;
911
912 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
913 if (allCountries[i].regDmnEnum == regdmn)
914 return &allCountries[i];
915 }
916
917 return NULL;
918}
919
920static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
921{
922
923 struct ath6kl_wmi_regdomain *ev;
924 struct country_code_to_enum_rd *country = NULL;
925 struct reg_dmn_pair_mapping *regpair = NULL;
926 char alpha2[2];
927 u32 reg_code;
928
929 ev = (struct ath6kl_wmi_regdomain *) datap;
930 reg_code = le32_to_cpu(ev->reg_code);
931
932 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
933 country = ath6kl_regd_find_country((u16) reg_code);
934 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
935
936 regpair = ath6kl_get_regpair((u16) reg_code);
937 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
Kalle Valob9b6ee62011-09-27 14:31:21 +0300938 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +0200939 regpair->regDmnEnum);
Vivek Natarajan06033762011-09-06 13:01:36 +0530940 }
941
Vasanthakumar Thiagarajane5348a12012-02-25 14:43:17 +0530942 if (country && wmi->parent_dev->wiphy_registered) {
Vivek Natarajan06033762011-09-06 13:01:36 +0530943 alpha2[0] = country->isoName[0];
944 alpha2[1] = country->isoName[1];
945
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530946 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
Vivek Natarajan06033762011-09-06 13:01:36 +0530947
Kalle Valob9b6ee62011-09-27 14:31:21 +0300948 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
Kalle Valo96f1fad2012-03-07 20:03:57 +0200949 alpha2[0], alpha2[1]);
Vivek Natarajan06033762011-09-06 13:01:36 +0530950 }
951}
952
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530953static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
954 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300955{
956 struct wmi_disconnect_event *ev;
957 wmi->traffic_class = 100;
958
959 if (len < sizeof(struct wmi_disconnect_event))
960 return -EINVAL;
961
962 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300963
Kalle Valob9b6ee62011-09-27 14:31:21 +0300964 ath6kl_dbg(ATH6KL_DBG_WMI,
965 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
966 le16_to_cpu(ev->proto_reason_status), ev->bssid,
967 ev->disconn_reason, ev->assoc_resp_len);
968
Kalle Valobdcd8172011-07-18 00:22:30 +0300969 wmi->is_wmm_enabled = false;
Kalle Valobdcd8172011-07-18 00:22:30 +0300970
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530971 ath6kl_disconnect_event(vif, ev->disconn_reason,
Kalle Valobdcd8172011-07-18 00:22:30 +0300972 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
973 le16_to_cpu(ev->proto_reason_status));
974
975 return 0;
976}
977
978static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
979{
980 struct wmi_peer_node_event *ev;
981
982 if (len < sizeof(struct wmi_peer_node_event))
983 return -EINVAL;
984
985 ev = (struct wmi_peer_node_event *) datap;
986
987 if (ev->event_code == PEER_NODE_JOIN_EVENT)
988 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
989 ev->peer_mac_addr);
990 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
991 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
992 ev->peer_mac_addr);
993
994 return 0;
995}
996
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +0530997static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
998 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300999{
1000 struct wmi_tkip_micerr_event *ev;
1001
1002 if (len < sizeof(struct wmi_tkip_micerr_event))
1003 return -EINVAL;
1004
1005 ev = (struct wmi_tkip_micerr_event *) datap;
1006
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301007 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
Kalle Valobdcd8172011-07-18 00:22:30 +03001008
1009 return 0;
1010}
1011
Kalle Valo10509f92011-12-13 14:52:07 +02001012void ath6kl_wmi_sscan_timer(unsigned long ptr)
1013{
1014 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr;
1015
1016 cfg80211_sched_scan_results(vif->ar->wiphy);
1017}
1018
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301019static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
1020 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001021{
Jouni Malinen82e14f52011-09-19 19:15:05 +03001022 struct wmi_bss_info_hdr2 *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001023 u8 *buf;
1024 struct ieee80211_channel *channel;
1025 struct ath6kl *ar = wmi->parent_dev;
1026 struct ieee80211_mgmt *mgmt;
1027 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +03001028
Jouni Malinen82e14f52011-09-19 19:15:05 +03001029 if (len <= sizeof(struct wmi_bss_info_hdr2))
Kalle Valobdcd8172011-07-18 00:22:30 +03001030 return -EINVAL;
1031
Jouni Malinen82e14f52011-09-19 19:15:05 +03001032 bih = (struct wmi_bss_info_hdr2 *) datap;
1033 buf = datap + sizeof(struct wmi_bss_info_hdr2);
1034 len -= sizeof(struct wmi_bss_info_hdr2);
Kalle Valobdcd8172011-07-18 00:22:30 +03001035
1036 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001037 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
1038 "frame_type=%d\n",
Jouni Malinen82e14f52011-09-19 19:15:05 +03001039 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001040 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +03001041
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001042 if (bih->frame_type != BEACON_FTYPE &&
1043 bih->frame_type != PROBERESP_FTYPE)
1044 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +03001045
Jouni Malinen551185c2011-09-19 19:15:06 +03001046 if (bih->frame_type == BEACON_FTYPE &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301047 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
1048 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301049 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1050 NONE_BSS_FILTER, 0);
Jouni Malinen551185c2011-09-19 19:15:06 +03001051 }
1052
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301053 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001054 if (channel == NULL)
1055 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001056
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001057 if (len < 8 + 2 + 2)
1058 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001059
Kalle Valoddc3d772012-03-07 20:03:58 +02001060 if (bih->frame_type == BEACON_FTYPE &&
1061 test_bit(CONNECTED, &vif->flags) &&
1062 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
Jouni Malinen32c10872011-09-19 19:15:07 +03001063 const u8 *tim;
1064 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
1065 len - 8 - 2 - 2);
1066 if (tim && tim[1] >= 2) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +05301067 vif->assoc_bss_dtim_period = tim[3];
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +05301068 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +03001069 }
1070 }
1071
Kalle Valobdcd8172011-07-18 00:22:30 +03001072 /*
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001073 * In theory, use of cfg80211_inform_bss() would be more natural here
1074 * since we do not have the full frame. However, at least for now,
1075 * cfg80211 can only distinguish Beacon and Probe Response frames from
1076 * each other when using cfg80211_inform_bss_frame(), so let's build a
1077 * fake IEEE 802.11 header to be able to take benefit of this.
Kalle Valobdcd8172011-07-18 00:22:30 +03001078 */
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001079 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1080 if (mgmt == NULL)
1081 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001082
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001083 if (bih->frame_type == BEACON_FTYPE) {
1084 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1085 IEEE80211_STYPE_BEACON);
1086 memset(mgmt->da, 0xff, ETH_ALEN);
1087 } else {
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301088 struct net_device *dev = vif->ndev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001089
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001090 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1091 IEEE80211_STYPE_PROBE_RESP);
1092 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +03001093 }
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001094 mgmt->duration = cpu_to_le16(0);
1095 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1096 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1097 mgmt->seq_ctrl = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001098
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001099 memcpy(&mgmt->u.beacon, buf, len);
1100
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301101 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
Jouni Malinen82e14f52011-09-19 19:15:05 +03001102 24 + len, (bih->snr - 95) * 100,
1103 GFP_ATOMIC);
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001104 kfree(mgmt);
1105 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +03001106 return -ENOMEM;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001107 cfg80211_put_bss(bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001108
Kalle Valo10509f92011-12-13 14:52:07 +02001109 /*
1110 * Firmware doesn't return any event when scheduled scan has
1111 * finished, so we need to use a timer to find out when there are
1112 * no more results.
1113 *
1114 * The timer is started from the first bss info received, otherwise
1115 * the timer would not ever fire if the scan interval is short
1116 * enough.
1117 */
1118 if (ar->state == ATH6KL_STATE_SCHED_SCAN &&
1119 !timer_pending(&vif->sched_scan_timer)) {
1120 mod_timer(&vif->sched_scan_timer, jiffies +
1121 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
1122 }
1123
Kalle Valobdcd8172011-07-18 00:22:30 +03001124 return 0;
1125}
1126
Kalle Valobdcd8172011-07-18 00:22:30 +03001127/* Inactivity timeout of a fatpipe(pstream) at the target */
1128static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1129 int len)
1130{
1131 struct wmi_pstream_timeout_event *ev;
1132
1133 if (len < sizeof(struct wmi_pstream_timeout_event))
1134 return -EINVAL;
1135
1136 ev = (struct wmi_pstream_timeout_event *) datap;
1137
1138 /*
1139 * When the pstream (fat pipe == AC) timesout, it means there were
1140 * no thinStreams within this pstream & it got implicitly created
1141 * due to data flow on this AC. We start the inactivity timer only
1142 * for implicitly created pstream. Just reset the host state.
1143 */
1144 spin_lock_bh(&wmi->lock);
1145 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1146 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1147 spin_unlock_bh(&wmi->lock);
1148
1149 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1150 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1151
1152 return 0;
1153}
1154
1155static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1156{
1157 struct wmi_bit_rate_reply *reply;
1158 s32 rate;
1159 u32 sgi, index;
1160
1161 if (len < sizeof(struct wmi_bit_rate_reply))
1162 return -EINVAL;
1163
1164 reply = (struct wmi_bit_rate_reply *) datap;
1165
1166 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1167
1168 if (reply->rate_index == (s8) RATE_AUTO) {
1169 rate = RATE_AUTO;
1170 } else {
1171 index = reply->rate_index & 0x7f;
1172 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1173 rate = wmi_rate_tbl[index][sgi];
1174 }
1175
1176 ath6kl_wakeup_event(wmi->parent_dev);
1177
1178 return 0;
1179}
1180
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001181static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
Kalle Valo003353b0d2011-09-01 10:14:21 +03001182{
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08001183 ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03001184
1185 return 0;
1186}
1187
Kalle Valobdcd8172011-07-18 00:22:30 +03001188static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1189{
1190 if (len < sizeof(struct wmi_fix_rates_reply))
1191 return -EINVAL;
1192
1193 ath6kl_wakeup_event(wmi->parent_dev);
1194
1195 return 0;
1196}
1197
1198static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1199{
1200 if (len < sizeof(struct wmi_channel_list_reply))
1201 return -EINVAL;
1202
1203 ath6kl_wakeup_event(wmi->parent_dev);
1204
1205 return 0;
1206}
1207
1208static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1209{
1210 struct wmi_tx_pwr_reply *reply;
1211
1212 if (len < sizeof(struct wmi_tx_pwr_reply))
1213 return -EINVAL;
1214
1215 reply = (struct wmi_tx_pwr_reply *) datap;
1216 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1217
1218 return 0;
1219}
1220
1221static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1222{
1223 if (len < sizeof(struct wmi_get_keepalive_cmd))
1224 return -EINVAL;
1225
1226 ath6kl_wakeup_event(wmi->parent_dev);
1227
1228 return 0;
1229}
1230
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301231static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
1232 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001233{
1234 struct wmi_scan_complete_event *ev;
1235
1236 ev = (struct wmi_scan_complete_event *) datap;
1237
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301238 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
Kalle Valobdcd8172011-07-18 00:22:30 +03001239 wmi->is_probe_ssid = false;
1240
1241 return 0;
1242}
1243
Jouni Malinen86512132011-09-21 16:57:29 +03001244static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301245 int len, struct ath6kl_vif *vif)
Jouni Malinen86512132011-09-21 16:57:29 +03001246{
1247 struct wmi_neighbor_report_event *ev;
1248 u8 i;
1249
1250 if (len < sizeof(*ev))
1251 return -EINVAL;
1252 ev = (struct wmi_neighbor_report_event *) datap;
1253 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1254 > len) {
Kalle Valocdeb8602012-04-12 11:02:18 +03001255 ath6kl_dbg(ATH6KL_DBG_WMI,
1256 "truncated neighbor event (num=%d len=%d)\n",
1257 ev->num_neighbors, len);
Jouni Malinen86512132011-09-21 16:57:29 +03001258 return -EINVAL;
1259 }
1260 for (i = 0; i < ev->num_neighbors; i++) {
1261 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1262 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1263 ev->neighbor[i].bss_flags);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301264 cfg80211_pmksa_candidate_notify(vif->ndev, i,
Jouni Malinen86512132011-09-21 16:57:29 +03001265 ev->neighbor[i].bssid,
1266 !!(ev->neighbor[i].bss_flags &
1267 WMI_PREAUTH_CAPABLE_BSS),
1268 GFP_ATOMIC);
1269 }
1270
1271 return 0;
1272}
1273
Kalle Valobdcd8172011-07-18 00:22:30 +03001274/*
1275 * Target is reporting a programming error. This is for
1276 * developer aid only. Target only checks a few common violations
1277 * and it is responsibility of host to do all error checking.
1278 * Behavior of target after wmi error event is undefined.
1279 * A reset is recommended.
1280 */
1281static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1282{
1283 const char *type = "unknown error";
1284 struct wmi_cmd_error_event *ev;
1285 ev = (struct wmi_cmd_error_event *) datap;
1286
1287 switch (ev->err_code) {
1288 case INVALID_PARAM:
1289 type = "invalid parameter";
1290 break;
1291 case ILLEGAL_STATE:
1292 type = "invalid state";
1293 break;
1294 case INTERNAL_ERROR:
1295 type = "internal error";
1296 break;
1297 }
1298
1299 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1300 ev->cmd_id, type);
1301
1302 return 0;
1303}
1304
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301305static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
1306 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001307{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301308 ath6kl_tgt_stats_event(vif, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03001309
1310 return 0;
1311}
1312
1313static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1314 struct sq_threshold_params *sq_thresh,
1315 u32 size)
1316{
1317 u32 index;
1318 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1319
1320 /* The list is already in sorted order. Get the next lower value */
1321 for (index = 0; index < size; index++) {
1322 if (rssi < sq_thresh->upper_threshold[index]) {
1323 threshold = (u8) sq_thresh->upper_threshold[index];
1324 break;
1325 }
1326 }
1327
1328 return threshold;
1329}
1330
1331static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1332 struct sq_threshold_params *sq_thresh,
1333 u32 size)
1334{
1335 u32 index;
1336 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1337
1338 /* The list is already in sorted order. Get the next lower value */
1339 for (index = 0; index < size; index++) {
1340 if (rssi > sq_thresh->lower_threshold[index]) {
1341 threshold = (u8) sq_thresh->lower_threshold[index];
1342 break;
1343 }
1344 }
1345
1346 return threshold;
1347}
1348
1349static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1350 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1351{
1352 struct sk_buff *skb;
1353 struct wmi_rssi_threshold_params_cmd *cmd;
1354
1355 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1356 if (!skb)
1357 return -ENOMEM;
1358
1359 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1360 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1361
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301362 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001363 NO_SYNC_WMIFLAG);
1364}
1365
1366static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1367 int len)
1368{
1369 struct wmi_rssi_threshold_event *reply;
1370 struct wmi_rssi_threshold_params_cmd cmd;
1371 struct sq_threshold_params *sq_thresh;
1372 enum wmi_rssi_threshold_val new_threshold;
1373 u8 upper_rssi_threshold, lower_rssi_threshold;
1374 s16 rssi;
1375 int ret;
1376
1377 if (len < sizeof(struct wmi_rssi_threshold_event))
1378 return -EINVAL;
1379
1380 reply = (struct wmi_rssi_threshold_event *) datap;
1381 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1382 rssi = a_sle16_to_cpu(reply->rssi);
1383
1384 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1385
1386 /*
1387 * Identify the threshold breached and communicate that to the app.
1388 * After that install a new set of thresholds based on the signal
1389 * quality reported by the target
1390 */
1391 if (new_threshold) {
1392 /* Upper threshold breached */
1393 if (rssi < sq_thresh->upper_threshold[0]) {
1394 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001395 "spurious upper rssi threshold event: %d\n",
1396 rssi);
Kalle Valobdcd8172011-07-18 00:22:30 +03001397 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1398 (rssi >= sq_thresh->upper_threshold[0])) {
1399 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1400 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1401 (rssi >= sq_thresh->upper_threshold[1])) {
1402 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1403 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1404 (rssi >= sq_thresh->upper_threshold[2])) {
1405 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1406 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1407 (rssi >= sq_thresh->upper_threshold[3])) {
1408 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1409 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1410 (rssi >= sq_thresh->upper_threshold[4])) {
1411 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1412 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1413 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1414 }
1415 } else {
1416 /* Lower threshold breached */
1417 if (rssi > sq_thresh->lower_threshold[0]) {
1418 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001419 "spurious lower rssi threshold event: %d %d\n",
Kalle Valobdcd8172011-07-18 00:22:30 +03001420 rssi, sq_thresh->lower_threshold[0]);
1421 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1422 (rssi <= sq_thresh->lower_threshold[0])) {
1423 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1424 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1425 (rssi <= sq_thresh->lower_threshold[1])) {
1426 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1427 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1428 (rssi <= sq_thresh->lower_threshold[2])) {
1429 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1430 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1431 (rssi <= sq_thresh->lower_threshold[3])) {
1432 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1433 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1434 (rssi <= sq_thresh->lower_threshold[4])) {
1435 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1436 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1437 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1438 }
1439 }
1440
1441 /* Calculate and install the next set of thresholds */
1442 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1443 sq_thresh->lower_threshold_valid_count);
1444 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1445 sq_thresh->upper_threshold_valid_count);
1446
1447 /* Issue a wmi command to install the thresholds */
1448 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1449 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1450 cmd.weight = sq_thresh->weight;
1451 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1452
1453 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1454 if (ret) {
1455 ath6kl_err("unable to configure rssi thresholds\n");
1456 return -EIO;
1457 }
1458
1459 return 0;
1460}
1461
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301462static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
1463 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03001464{
1465 struct wmi_cac_event *reply;
1466 struct ieee80211_tspec_ie *ts;
1467 u16 active_tsids, tsinfo;
1468 u8 tsid, index;
1469 u8 ts_id;
1470
1471 if (len < sizeof(struct wmi_cac_event))
1472 return -EINVAL;
1473
1474 reply = (struct wmi_cac_event *) datap;
1475
1476 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1477 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1478
1479 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1480 tsinfo = le16_to_cpu(ts->tsinfo);
1481 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1482 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1483
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301484 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1485 reply->ac, tsid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001486 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1487 /*
1488 * Following assumes that there is only one outstanding
1489 * ADDTS request when this event is received
1490 */
1491 spin_lock_bh(&wmi->lock);
1492 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1493 spin_unlock_bh(&wmi->lock);
1494
1495 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1496 if ((active_tsids >> index) & 1)
1497 break;
1498 }
1499 if (index < (sizeof(active_tsids) * 8))
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301500 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
1501 reply->ac, index);
Kalle Valobdcd8172011-07-18 00:22:30 +03001502 }
1503
1504 /*
1505 * Clear active tsids and Add missing handling
1506 * for delete qos stream from AP
1507 */
1508 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1509
1510 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1511 tsinfo = le16_to_cpu(ts->tsinfo);
1512 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1513 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1514
1515 spin_lock_bh(&wmi->lock);
1516 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1517 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1518 spin_unlock_bh(&wmi->lock);
1519
1520 /* Indicate stream inactivity to driver layer only if all tsids
1521 * within this AC are deleted.
1522 */
1523 if (!active_tsids) {
1524 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1525 false);
1526 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1527 }
1528 }
1529
1530 return 0;
1531}
1532
1533static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1534 struct wmi_snr_threshold_params_cmd *snr_cmd)
1535{
1536 struct sk_buff *skb;
1537 struct wmi_snr_threshold_params_cmd *cmd;
1538
1539 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1540 if (!skb)
1541 return -ENOMEM;
1542
1543 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1544 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1545
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301546 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001547 NO_SYNC_WMIFLAG);
1548}
1549
1550static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1551 int len)
1552{
1553 struct wmi_snr_threshold_event *reply;
1554 struct sq_threshold_params *sq_thresh;
1555 struct wmi_snr_threshold_params_cmd cmd;
1556 enum wmi_snr_threshold_val new_threshold;
1557 u8 upper_snr_threshold, lower_snr_threshold;
1558 s16 snr;
1559 int ret;
1560
1561 if (len < sizeof(struct wmi_snr_threshold_event))
1562 return -EINVAL;
1563
1564 reply = (struct wmi_snr_threshold_event *) datap;
1565
1566 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1567 snr = reply->snr;
1568
1569 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1570
1571 /*
1572 * Identify the threshold breached and communicate that to the app.
1573 * After that install a new set of thresholds based on the signal
1574 * quality reported by the target.
1575 */
1576 if (new_threshold) {
1577 /* Upper threshold breached */
1578 if (snr < sq_thresh->upper_threshold[0]) {
1579 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001580 "spurious upper snr threshold event: %d\n",
1581 snr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001582 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1583 (snr >= sq_thresh->upper_threshold[0])) {
1584 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1585 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1586 (snr >= sq_thresh->upper_threshold[1])) {
1587 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1588 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1589 (snr >= sq_thresh->upper_threshold[2])) {
1590 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1591 } else if (snr >= sq_thresh->upper_threshold[3]) {
1592 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1593 }
1594 } else {
1595 /* Lower threshold breached */
1596 if (snr > sq_thresh->lower_threshold[0]) {
1597 ath6kl_dbg(ATH6KL_DBG_WMI,
Kalle Valo96f1fad2012-03-07 20:03:57 +02001598 "spurious lower snr threshold event: %d\n",
1599 sq_thresh->lower_threshold[0]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001600 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1601 (snr <= sq_thresh->lower_threshold[0])) {
1602 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1603 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1604 (snr <= sq_thresh->lower_threshold[1])) {
1605 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1606 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1607 (snr <= sq_thresh->lower_threshold[2])) {
1608 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1609 } else if (snr <= sq_thresh->lower_threshold[3]) {
1610 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1611 }
1612 }
1613
1614 /* Calculate and install the next set of thresholds */
1615 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1616 sq_thresh->lower_threshold_valid_count);
1617 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1618 sq_thresh->upper_threshold_valid_count);
1619
1620 /* Issue a wmi command to install the thresholds */
1621 cmd.thresh_above1_val = upper_snr_threshold;
1622 cmd.thresh_below1_val = lower_snr_threshold;
1623 cmd.weight = sq_thresh->weight;
1624 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1625
1626 ath6kl_dbg(ATH6KL_DBG_WMI,
1627 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1628 snr, new_threshold,
1629 lower_snr_threshold, upper_snr_threshold);
1630
1631 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1632 if (ret) {
1633 ath6kl_err("unable to configure snr threshold\n");
1634 return -EIO;
1635 }
1636
1637 return 0;
1638}
1639
1640static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1641{
1642 u16 ap_info_entry_size;
1643 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1644 struct wmi_ap_info_v1 *ap_info_v1;
1645 u8 index;
1646
1647 if (len < sizeof(struct wmi_aplist_event) ||
1648 ev->ap_list_ver != APLIST_VER1)
1649 return -EINVAL;
1650
1651 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1652 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1653
1654 ath6kl_dbg(ATH6KL_DBG_WMI,
1655 "number of APs in aplist event: %d\n", ev->num_ap);
1656
1657 if (len < (int) (sizeof(struct wmi_aplist_event) +
1658 (ev->num_ap - 1) * ap_info_entry_size))
1659 return -EINVAL;
1660
1661 /* AP list version 1 contents */
1662 for (index = 0; index < ev->num_ap; index++) {
1663 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1664 index, ap_info_v1->bssid, ap_info_v1->channel);
1665 ap_info_v1++;
1666 }
1667
1668 return 0;
1669}
1670
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301671int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +03001672 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1673{
1674 struct wmi_cmd_hdr *cmd_hdr;
1675 enum htc_endpoint_id ep_id = wmi->ep_id;
1676 int ret;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301677 u16 info1;
Kalle Valobdcd8172011-07-18 00:22:30 +03001678
Kalle Valo71f96ee2011-11-14 19:31:30 +02001679 if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1))))
Kalle Valobdcd8172011-07-18 00:22:30 +03001680 return -EINVAL;
1681
Kalle Valob9b6ee62011-09-27 14:31:21 +03001682 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1683 cmd_id, skb->len, sync_flag);
1684 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1685 skb->data, skb->len);
1686
Kalle Valobdcd8172011-07-18 00:22:30 +03001687 if (sync_flag >= END_WMIFLAG) {
1688 dev_kfree_skb(skb);
1689 return -EINVAL;
1690 }
1691
1692 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1693 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1694 /*
1695 * Make sure all data currently queued is transmitted before
1696 * the cmd execution. Establish a new sync point.
1697 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301698 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001699 }
1700
1701 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1702
1703 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1704 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301705 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1706 cmd_hdr->info1 = cpu_to_le16(info1);
Kalle Valobdcd8172011-07-18 00:22:30 +03001707
1708 /* Only for OPT_TX_CMD, use BE endpoint. */
1709 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1710 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05301711 false, false, 0, NULL, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001712 if (ret) {
1713 dev_kfree_skb(skb);
1714 return ret;
1715 }
1716 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1717 }
1718
1719 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1720
1721 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1722 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1723 /*
1724 * Make sure all new data queued waits for the command to
1725 * execute. Establish a new sync point.
1726 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301727 ath6kl_wmi_sync_point(wmi, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03001728 }
1729
1730 return 0;
1731}
1732
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301733int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1734 enum network_type nw_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001735 enum dot11_auth_mode dot11_auth_mode,
1736 enum auth_mode auth_mode,
1737 enum crypto_type pairwise_crypto,
1738 u8 pairwise_crypto_len,
1739 enum crypto_type group_crypto,
1740 u8 group_crypto_len, int ssid_len, u8 *ssid,
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001741 u8 *bssid, u16 channel, u32 ctrl_flags,
1742 u8 nw_subtype)
Kalle Valobdcd8172011-07-18 00:22:30 +03001743{
1744 struct sk_buff *skb;
1745 struct wmi_connect_cmd *cc;
1746 int ret;
1747
Kalle Valob9b6ee62011-09-27 14:31:21 +03001748 ath6kl_dbg(ATH6KL_DBG_WMI,
1749 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1750 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1751 bssid, channel, ctrl_flags, ssid_len, nw_type,
1752 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1753 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1754
Kalle Valobdcd8172011-07-18 00:22:30 +03001755 wmi->traffic_class = 100;
1756
1757 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1758 return -EINVAL;
1759
1760 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1761 return -EINVAL;
1762
1763 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1764 if (!skb)
1765 return -ENOMEM;
1766
1767 cc = (struct wmi_connect_cmd *) skb->data;
1768
1769 if (ssid_len)
1770 memcpy(cc->ssid, ssid, ssid_len);
1771
1772 cc->ssid_len = ssid_len;
1773 cc->nw_type = nw_type;
1774 cc->dot11_auth_mode = dot11_auth_mode;
1775 cc->auth_mode = auth_mode;
1776 cc->prwise_crypto_type = pairwise_crypto;
1777 cc->prwise_crypto_len = pairwise_crypto_len;
1778 cc->grp_crypto_type = group_crypto;
1779 cc->grp_crypto_len = group_crypto_len;
1780 cc->ch = cpu_to_le16(channel);
1781 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001782 cc->nw_subtype = nw_subtype;
Kalle Valobdcd8172011-07-18 00:22:30 +03001783
1784 if (bssid != NULL)
1785 memcpy(cc->bssid, bssid, ETH_ALEN);
1786
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301787 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1788 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001789
1790 return ret;
1791}
1792
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301793int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1794 u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +03001795{
1796 struct sk_buff *skb;
1797 struct wmi_reconnect_cmd *cc;
1798 int ret;
1799
Kalle Valob9b6ee62011-09-27 14:31:21 +03001800 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1801 bssid, channel);
1802
Kalle Valobdcd8172011-07-18 00:22:30 +03001803 wmi->traffic_class = 100;
1804
1805 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1806 if (!skb)
1807 return -ENOMEM;
1808
1809 cc = (struct wmi_reconnect_cmd *) skb->data;
1810 cc->channel = cpu_to_le16(channel);
1811
1812 if (bssid != NULL)
1813 memcpy(cc->bssid, bssid, ETH_ALEN);
1814
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301815 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001816 NO_SYNC_WMIFLAG);
1817
1818 return ret;
1819}
1820
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301821int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03001822{
1823 int ret;
1824
Kalle Valob9b6ee62011-09-27 14:31:21 +03001825 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1826
Kalle Valobdcd8172011-07-18 00:22:30 +03001827 wmi->traffic_class = 100;
1828
1829 /* Disconnect command does not need to do a SYNC before. */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301830 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03001831
1832 return ret;
1833}
1834
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001835int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
1836 enum wmi_scan_type scan_type,
1837 u32 force_fgscan, u32 is_legacy,
1838 u32 home_dwell_time, u32 force_scan_interval,
1839 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
1840{
Thomas Pedersen03e20842012-04-24 12:50:41 -07001841 struct ieee80211_supported_band *sband;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001842 struct sk_buff *skb;
1843 struct wmi_begin_scan_cmd *sc;
Thomas Pedersen03e20842012-04-24 12:50:41 -07001844 s8 size, *supp_rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001845 int i, band, ret;
1846 struct ath6kl *ar = wmi->parent_dev;
1847 int num_rates;
Thomas Pedersen03e20842012-04-24 12:50:41 -07001848 u32 ratemask;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001849
1850 size = sizeof(struct wmi_begin_scan_cmd);
1851
1852 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1853 return -EINVAL;
1854
1855 if (num_chan > WMI_MAX_CHANNELS)
1856 return -EINVAL;
1857
1858 if (num_chan)
1859 size += sizeof(u16) * (num_chan - 1);
1860
1861 skb = ath6kl_wmi_get_new_buf(size);
1862 if (!skb)
1863 return -ENOMEM;
1864
1865 sc = (struct wmi_begin_scan_cmd *) skb->data;
1866 sc->scan_type = scan_type;
1867 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1868 sc->is_legacy = cpu_to_le32(is_legacy);
1869 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1870 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1871 sc->no_cck = cpu_to_le32(no_cck);
1872 sc->num_ch = num_chan;
1873
1874 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
Thomas Pedersen03e20842012-04-24 12:50:41 -07001875 sband = ar->wiphy->bands[band];
1876
1877 if (!sband)
1878 continue;
1879
1880 ratemask = rates[band];
1881 supp_rates = sc->supp_rates[band].rates;
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08001882 num_rates = 0;
1883
1884 for (i = 0; i < sband->n_bitrates; i++) {
1885 if ((BIT(i) & ratemask) == 0)
1886 continue; /* skip rate */
1887 supp_rates[num_rates++] =
1888 (u8) (sband->bitrates[i].bitrate / 5);
1889 }
1890 sc->supp_rates[band].nrates = num_rates;
1891 }
1892
1893 for (i = 0; i < num_chan; i++)
1894 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
1895
1896 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
1897 NO_SYNC_WMIFLAG);
1898
1899 return ret;
1900}
1901
1902/* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
1903 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
1904 * mgmt operations using station interface.
1905 */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301906int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1907 enum wmi_scan_type scan_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001908 u32 force_fgscan, u32 is_legacy,
1909 u32 home_dwell_time, u32 force_scan_interval,
1910 s8 num_chan, u16 *ch_list)
1911{
1912 struct sk_buff *skb;
1913 struct wmi_start_scan_cmd *sc;
1914 s8 size;
Edward Lu1276c9e2011-08-30 21:58:00 +03001915 int i, ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03001916
1917 size = sizeof(struct wmi_start_scan_cmd);
1918
1919 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1920 return -EINVAL;
1921
1922 if (num_chan > WMI_MAX_CHANNELS)
1923 return -EINVAL;
1924
1925 if (num_chan)
1926 size += sizeof(u16) * (num_chan - 1);
1927
1928 skb = ath6kl_wmi_get_new_buf(size);
1929 if (!skb)
1930 return -ENOMEM;
1931
1932 sc = (struct wmi_start_scan_cmd *) skb->data;
1933 sc->scan_type = scan_type;
1934 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1935 sc->is_legacy = cpu_to_le32(is_legacy);
1936 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1937 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1938 sc->num_ch = num_chan;
1939
Edward Lu1276c9e2011-08-30 21:58:00 +03001940 for (i = 0; i < num_chan; i++)
1941 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001942
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301943 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001944 NO_SYNC_WMIFLAG);
1945
1946 return ret;
1947}
1948
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301949int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
1950 u16 fg_start_sec,
Kalle Valobdcd8172011-07-18 00:22:30 +03001951 u16 fg_end_sec, u16 bg_sec,
1952 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1953 u16 pas_chdw_msec, u8 short_scan_ratio,
1954 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1955 u16 maxact_scan_per_ssid)
1956{
1957 struct sk_buff *skb;
1958 struct wmi_scan_params_cmd *sc;
1959 int ret;
1960
1961 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1962 if (!skb)
1963 return -ENOMEM;
1964
1965 sc = (struct wmi_scan_params_cmd *) skb->data;
1966 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1967 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1968 sc->bg_period = cpu_to_le16(bg_sec);
1969 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1970 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1971 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1972 sc->short_scan_ratio = short_scan_ratio;
1973 sc->scan_ctrl_flags = scan_ctrl_flag;
1974 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1975 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1976
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301977 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001978 NO_SYNC_WMIFLAG);
1979 return ret;
1980}
1981
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301982int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
Kalle Valobdcd8172011-07-18 00:22:30 +03001983{
1984 struct sk_buff *skb;
1985 struct wmi_bss_filter_cmd *cmd;
1986 int ret;
1987
1988 if (filter >= LAST_BSS_FILTER)
1989 return -EINVAL;
1990
1991 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1992 if (!skb)
1993 return -ENOMEM;
1994
1995 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1996 cmd->bss_filter = filter;
1997 cmd->ie_mask = cpu_to_le32(ie_mask);
1998
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05301999 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002000 NO_SYNC_WMIFLAG);
2001 return ret;
2002}
2003
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302004int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
Kalle Valobdcd8172011-07-18 00:22:30 +03002005 u8 ssid_len, u8 *ssid)
2006{
2007 struct sk_buff *skb;
2008 struct wmi_probed_ssid_cmd *cmd;
2009 int ret;
2010
Jouni Malinen8ab54152012-05-09 22:14:51 +03002011 if (index >= MAX_PROBED_SSIDS)
Kalle Valobdcd8172011-07-18 00:22:30 +03002012 return -EINVAL;
2013
2014 if (ssid_len > sizeof(cmd->ssid))
2015 return -EINVAL;
2016
2017 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
2018 return -EINVAL;
2019
2020 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
2021 return -EINVAL;
2022
2023 if (flag & SPECIFIC_SSID_FLAG)
2024 wmi->is_probe_ssid = true;
2025
2026 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2027 if (!skb)
2028 return -ENOMEM;
2029
2030 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
2031 cmd->entry_index = index;
2032 cmd->flag = flag;
2033 cmd->ssid_len = ssid_len;
2034 memcpy(cmd->ssid, ssid, ssid_len);
2035
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302036 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002037 NO_SYNC_WMIFLAG);
2038 return ret;
2039}
2040
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302041int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
2042 u16 listen_interval,
Kalle Valobdcd8172011-07-18 00:22:30 +03002043 u16 listen_beacons)
2044{
2045 struct sk_buff *skb;
2046 struct wmi_listen_int_cmd *cmd;
2047 int ret;
2048
2049 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2050 if (!skb)
2051 return -ENOMEM;
2052
2053 cmd = (struct wmi_listen_int_cmd *) skb->data;
2054 cmd->listen_intvl = cpu_to_le16(listen_interval);
2055 cmd->num_beacons = cpu_to_le16(listen_beacons);
2056
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302057 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002058 NO_SYNC_WMIFLAG);
2059 return ret;
2060}
2061
Raja Manice0dc0c2012-02-20 19:08:08 +05302062int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
2063 u16 bmiss_time, u16 num_beacons)
2064{
2065 struct sk_buff *skb;
2066 struct wmi_bmiss_time_cmd *cmd;
2067 int ret;
2068
2069 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2070 if (!skb)
2071 return -ENOMEM;
2072
2073 cmd = (struct wmi_bmiss_time_cmd *) skb->data;
2074 cmd->bmiss_time = cpu_to_le16(bmiss_time);
2075 cmd->num_beacons = cpu_to_le16(num_beacons);
2076
2077 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
2078 NO_SYNC_WMIFLAG);
2079 return ret;
2080}
2081
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302082int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
Kalle Valobdcd8172011-07-18 00:22:30 +03002083{
2084 struct sk_buff *skb;
2085 struct wmi_power_mode_cmd *cmd;
2086 int ret;
2087
2088 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2089 if (!skb)
2090 return -ENOMEM;
2091
2092 cmd = (struct wmi_power_mode_cmd *) skb->data;
2093 cmd->pwr_mode = pwr_mode;
2094 wmi->pwr_mode = pwr_mode;
2095
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302096 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002097 NO_SYNC_WMIFLAG);
2098 return ret;
2099}
2100
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302101int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
Kalle Valobdcd8172011-07-18 00:22:30 +03002102 u16 ps_poll_num, u16 dtim_policy,
2103 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
2104 u16 ps_fail_event_policy)
2105{
2106 struct sk_buff *skb;
2107 struct wmi_power_params_cmd *pm;
2108 int ret;
2109
2110 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
2111 if (!skb)
2112 return -ENOMEM;
2113
2114 pm = (struct wmi_power_params_cmd *)skb->data;
2115 pm->idle_period = cpu_to_le16(idle_period);
2116 pm->pspoll_number = cpu_to_le16(ps_poll_num);
2117 pm->dtim_policy = cpu_to_le16(dtim_policy);
2118 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
2119 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
2120 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
2121
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302122 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002123 NO_SYNC_WMIFLAG);
2124 return ret;
2125}
2126
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302127int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
Kalle Valobdcd8172011-07-18 00:22:30 +03002128{
2129 struct sk_buff *skb;
2130 struct wmi_disc_timeout_cmd *cmd;
2131 int ret;
2132
2133 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2134 if (!skb)
2135 return -ENOMEM;
2136
2137 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
2138 cmd->discon_timeout = timeout;
2139
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302140 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002141 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302142
Jouni Malinenff0b0072011-10-11 17:31:56 +03002143 if (ret == 0)
2144 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302145
Kalle Valobdcd8172011-07-18 00:22:30 +03002146 return ret;
2147}
2148
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302149int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
Kalle Valobdcd8172011-07-18 00:22:30 +03002150 enum crypto_type key_type,
2151 u8 key_usage, u8 key_len,
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002152 u8 *key_rsc, unsigned int key_rsc_len,
2153 u8 *key_material,
Kalle Valobdcd8172011-07-18 00:22:30 +03002154 u8 key_op_ctrl, u8 *mac_addr,
2155 enum wmi_sync_flag sync_flag)
2156{
2157 struct sk_buff *skb;
2158 struct wmi_add_cipher_key_cmd *cmd;
2159 int ret;
2160
Kalle Valocdeb8602012-04-12 11:02:18 +03002161 ath6kl_dbg(ATH6KL_DBG_WMI,
2162 "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 +03002163 key_index, key_type, key_usage, key_len, key_op_ctrl);
2164
Kalle Valobdcd8172011-07-18 00:22:30 +03002165 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002166 (key_material == NULL) || key_rsc_len > 8)
Kalle Valobdcd8172011-07-18 00:22:30 +03002167 return -EINVAL;
2168
2169 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
2170 return -EINVAL;
2171
2172 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2173 if (!skb)
2174 return -ENOMEM;
2175
2176 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
2177 cmd->key_index = key_index;
2178 cmd->key_type = key_type;
2179 cmd->key_usage = key_usage;
2180 cmd->key_len = key_len;
2181 memcpy(cmd->key, key_material, key_len);
2182
2183 if (key_rsc != NULL)
Jouni Malinenf4bb9a62011-11-02 23:45:55 +02002184 memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002185
2186 cmd->key_op_ctrl = key_op_ctrl;
2187
2188 if (mac_addr)
2189 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2190
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302191 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002192 sync_flag);
2193
2194 return ret;
2195}
2196
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302197int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk)
Kalle Valobdcd8172011-07-18 00:22:30 +03002198{
2199 struct sk_buff *skb;
2200 struct wmi_add_krk_cmd *cmd;
2201 int ret;
2202
2203 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2204 if (!skb)
2205 return -ENOMEM;
2206
2207 cmd = (struct wmi_add_krk_cmd *) skb->data;
2208 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2209
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302210 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302211 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002212
2213 return ret;
2214}
2215
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302216int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
Kalle Valobdcd8172011-07-18 00:22:30 +03002217{
2218 struct sk_buff *skb;
2219 struct wmi_delete_cipher_key_cmd *cmd;
2220 int ret;
2221
2222 if (key_index > WMI_MAX_KEY_INDEX)
2223 return -EINVAL;
2224
2225 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2226 if (!skb)
2227 return -ENOMEM;
2228
2229 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2230 cmd->key_index = key_index;
2231
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302232 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002233 NO_SYNC_WMIFLAG);
2234
2235 return ret;
2236}
2237
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302238int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002239 const u8 *pmkid, bool set)
2240{
2241 struct sk_buff *skb;
2242 struct wmi_setpmkid_cmd *cmd;
2243 int ret;
2244
2245 if (bssid == NULL)
2246 return -EINVAL;
2247
2248 if (set && pmkid == NULL)
2249 return -EINVAL;
2250
2251 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2252 if (!skb)
2253 return -ENOMEM;
2254
2255 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2256 memcpy(cmd->bssid, bssid, ETH_ALEN);
2257 if (set) {
2258 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2259 cmd->enable = PMKID_ENABLE;
2260 } else {
2261 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2262 cmd->enable = PMKID_DISABLE;
2263 }
2264
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302265 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002266 NO_SYNC_WMIFLAG);
2267
2268 return ret;
2269}
2270
2271static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302272 enum htc_endpoint_id ep_id, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002273{
2274 struct wmi_data_hdr *data_hdr;
2275 int ret;
2276
2277 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2278 return -EINVAL;
2279
2280 skb_push(skb, sizeof(struct wmi_data_hdr));
2281
2282 data_hdr = (struct wmi_data_hdr *) skb->data;
2283 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302284 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
Kalle Valobdcd8172011-07-18 00:22:30 +03002285
2286 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2287
2288 return ret;
2289}
2290
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302291static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002292{
2293 struct sk_buff *skb;
2294 struct wmi_sync_cmd *cmd;
2295 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2296 enum htc_endpoint_id ep_id;
2297 u8 index, num_pri_streams = 0;
2298 int ret = 0;
2299
2300 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2301
2302 spin_lock_bh(&wmi->lock);
2303
2304 for (index = 0; index < WMM_NUM_AC; index++) {
2305 if (wmi->fat_pipe_exist & (1 << index)) {
2306 num_pri_streams++;
2307 data_sync_bufs[num_pri_streams - 1].traffic_class =
2308 index;
2309 }
2310 }
2311
2312 spin_unlock_bh(&wmi->lock);
2313
2314 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2315 if (!skb) {
2316 ret = -ENOMEM;
2317 goto free_skb;
2318 }
2319
2320 cmd = (struct wmi_sync_cmd *) skb->data;
2321
2322 /*
2323 * In the SYNC cmd sent on the control Ep, send a bitmap
2324 * of the data eps on which the Data Sync will be sent
2325 */
2326 cmd->data_sync_map = wmi->fat_pipe_exist;
2327
2328 for (index = 0; index < num_pri_streams; index++) {
2329 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2330 if (data_sync_bufs[index].skb == NULL) {
2331 ret = -ENOMEM;
2332 break;
2333 }
2334 }
2335
2336 /*
2337 * If buffer allocation for any of the dataSync fails,
2338 * then do not send the Synchronize cmd on the control ep
2339 */
2340 if (ret)
2341 goto free_skb;
2342
2343 /*
2344 * Send sync cmd followed by sync data messages on all
2345 * endpoints being used
2346 */
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302347 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002348 NO_SYNC_WMIFLAG);
2349
2350 if (ret)
2351 goto free_skb;
2352
2353 /* cmd buffer sent, we no longer own it */
2354 skb = NULL;
2355
2356 for (index = 0; index < num_pri_streams; index++) {
2357
2358 if (WARN_ON(!data_sync_bufs[index].skb))
2359 break;
2360
2361 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2362 data_sync_bufs[index].
2363 traffic_class);
2364 ret =
2365 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
Vasanthakumar Thiagarajan6765d0a2011-10-25 19:34:17 +05302366 ep_id, if_idx);
Kalle Valobdcd8172011-07-18 00:22:30 +03002367
2368 if (ret)
2369 break;
2370
2371 data_sync_bufs[index].skb = NULL;
2372 }
2373
2374free_skb:
2375 /* free up any resources left over (possibly due to an error) */
2376 if (skb)
2377 dev_kfree_skb(skb);
2378
2379 for (index = 0; index < num_pri_streams; index++) {
2380 if (data_sync_bufs[index].skb != NULL) {
2381 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2382 skb);
2383 }
2384 }
2385
2386 return ret;
2387}
2388
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302389int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
Kalle Valobdcd8172011-07-18 00:22:30 +03002390 struct wmi_create_pstream_cmd *params)
2391{
2392 struct sk_buff *skb;
2393 struct wmi_create_pstream_cmd *cmd;
2394 u8 fatpipe_exist_for_ac = 0;
2395 s32 min_phy = 0;
2396 s32 nominal_phy = 0;
2397 int ret;
2398
2399 if (!((params->user_pri < 8) &&
2400 (params->user_pri <= 0x7) &&
2401 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2402 (params->traffic_direc == UPLINK_TRAFFIC ||
2403 params->traffic_direc == DNLINK_TRAFFIC ||
2404 params->traffic_direc == BIDIR_TRAFFIC) &&
2405 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2406 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2407 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2408 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2409 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2410 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2411 params->tsid <= WMI_MAX_THINSTREAM))) {
2412 return -EINVAL;
2413 }
2414
2415 /*
2416 * Check nominal PHY rate is >= minimalPHY,
2417 * so that DUT can allow TSRS IE
2418 */
2419
2420 /* Get the physical rate (units of bps) */
2421 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2422
2423 /* Check minimal phy < nominal phy rate */
2424 if (params->nominal_phy >= min_phy) {
2425 /* unit of 500 kbps */
2426 nominal_phy = (params->nominal_phy * 1000) / 500;
2427 ath6kl_dbg(ATH6KL_DBG_WMI,
2428 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2429 min_phy, nominal_phy);
2430
2431 params->nominal_phy = nominal_phy;
2432 } else {
2433 params->nominal_phy = 0;
2434 }
2435
2436 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2437 if (!skb)
2438 return -ENOMEM;
2439
2440 ath6kl_dbg(ATH6KL_DBG_WMI,
2441 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2442 params->traffic_class, params->tsid);
2443
2444 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2445 memcpy(cmd, params, sizeof(*cmd));
2446
2447 /* This is an implicitly created Fat pipe */
2448 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2449 spin_lock_bh(&wmi->lock);
2450 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2451 (1 << params->traffic_class));
2452 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2453 spin_unlock_bh(&wmi->lock);
2454 } else {
2455 /* explicitly created thin stream within a fat pipe */
2456 spin_lock_bh(&wmi->lock);
2457 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2458 (1 << params->traffic_class));
2459 wmi->stream_exist_for_ac[params->traffic_class] |=
2460 (1 << params->tsid);
2461 /*
2462 * If a thinstream becomes active, the fat pipe automatically
2463 * becomes active
2464 */
2465 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2466 spin_unlock_bh(&wmi->lock);
2467 }
2468
2469 /*
2470 * Indicate activty change to driver layer only if this is the
2471 * first TSID to get created in this AC explicitly or an implicit
2472 * fat pipe is getting created.
2473 */
2474 if (!fatpipe_exist_for_ac)
2475 ath6kl_indicate_tx_activity(wmi->parent_dev,
2476 params->traffic_class, true);
2477
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302478 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002479 NO_SYNC_WMIFLAG);
2480 return ret;
2481}
2482
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302483int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
2484 u8 tsid)
Kalle Valobdcd8172011-07-18 00:22:30 +03002485{
2486 struct sk_buff *skb;
2487 struct wmi_delete_pstream_cmd *cmd;
2488 u16 active_tsids = 0;
2489 int ret;
2490
2491 if (traffic_class > 3) {
2492 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2493 return -EINVAL;
2494 }
2495
2496 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2497 if (!skb)
2498 return -ENOMEM;
2499
2500 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2501 cmd->traffic_class = traffic_class;
2502 cmd->tsid = tsid;
2503
2504 spin_lock_bh(&wmi->lock);
2505 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2506 spin_unlock_bh(&wmi->lock);
2507
2508 if (!(active_tsids & (1 << tsid))) {
2509 dev_kfree_skb(skb);
2510 ath6kl_dbg(ATH6KL_DBG_WMI,
2511 "TSID %d doesn't exist for traffic class: %d\n",
2512 tsid, traffic_class);
2513 return -ENODATA;
2514 }
2515
2516 ath6kl_dbg(ATH6KL_DBG_WMI,
2517 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2518 traffic_class, tsid);
2519
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05302520 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002521 SYNC_BEFORE_WMIFLAG);
2522
2523 spin_lock_bh(&wmi->lock);
2524 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2525 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2526 spin_unlock_bh(&wmi->lock);
2527
2528 /*
2529 * Indicate stream inactivity to driver layer only if all tsids
2530 * within this AC are deleted.
2531 */
2532 if (!active_tsids) {
2533 ath6kl_indicate_tx_activity(wmi->parent_dev,
2534 traffic_class, false);
2535 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2536 }
2537
2538 return ret;
2539}
2540
Raja Manica1d16a2011-12-16 14:24:23 +05302541int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
2542 __be32 ips0, __be32 ips1)
Kalle Valobdcd8172011-07-18 00:22:30 +03002543{
2544 struct sk_buff *skb;
2545 struct wmi_set_ip_cmd *cmd;
2546 int ret;
2547
2548 /* Multicast address are not valid */
Raja Manica1d16a2011-12-16 14:24:23 +05302549 if (ipv4_is_multicast(ips0) ||
2550 ipv4_is_multicast(ips1))
Kalle Valobdcd8172011-07-18 00:22:30 +03002551 return -EINVAL;
2552
2553 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2554 if (!skb)
2555 return -ENOMEM;
2556
2557 cmd = (struct wmi_set_ip_cmd *) skb->data;
Raja Manica1d16a2011-12-16 14:24:23 +05302558 cmd->ips[0] = ips0;
2559 cmd->ips[1] = ips1;
Kalle Valobdcd8172011-07-18 00:22:30 +03002560
Raja Manica1d16a2011-12-16 14:24:23 +05302561 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302562 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002563 return ret;
2564}
2565
Raja Mani45cf1102011-11-07 22:52:45 +02002566static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
2567{
2568 u16 active_tsids;
2569 u8 stream_exist;
2570 int i;
2571
2572 /*
2573 * Relinquish credits from all implicitly created pstreams
2574 * since when we go to sleep. If user created explicit
2575 * thinstreams exists with in a fatpipe leave them intact
2576 * for the user to delete.
2577 */
2578 spin_lock_bh(&wmi->lock);
2579 stream_exist = wmi->fat_pipe_exist;
2580 spin_unlock_bh(&wmi->lock);
2581
2582 for (i = 0; i < WMM_NUM_AC; i++) {
2583 if (stream_exist & (1 << i)) {
2584
2585 /*
2586 * FIXME: Is this lock & unlock inside
2587 * for loop correct? may need rework.
2588 */
2589 spin_lock_bh(&wmi->lock);
2590 active_tsids = wmi->stream_exist_for_ac[i];
2591 spin_unlock_bh(&wmi->lock);
2592
2593 /*
2594 * If there are no user created thin streams
2595 * delete the fatpipe
2596 */
2597 if (!active_tsids) {
2598 stream_exist &= ~(1 << i);
2599 /*
2600 * Indicate inactivity to driver layer for
2601 * this fatpipe (pstream)
2602 */
2603 ath6kl_indicate_tx_activity(wmi->parent_dev,
2604 i, false);
2605 }
2606 }
2607 }
2608
2609 /* FIXME: Can we do this assignment without locking ? */
2610 spin_lock_bh(&wmi->lock);
2611 wmi->fat_pipe_exist = stream_exist;
2612 spin_unlock_bh(&wmi->lock);
2613}
2614
Bala Shanmugam06e360a2012-05-22 13:23:12 +05302615static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
2616 const struct cfg80211_bitrate_mask *mask)
2617{
2618 struct sk_buff *skb;
2619 int ret, mode, band;
2620 u64 mcsrate, ratemask[IEEE80211_NUM_BANDS];
2621 struct wmi_set_tx_select_rates64_cmd *cmd;
2622
2623 memset(&ratemask, 0, sizeof(ratemask));
2624 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2625 /* copy legacy rate mask */
2626 ratemask[band] = mask->control[band].legacy;
2627 if (band == IEEE80211_BAND_5GHZ)
2628 ratemask[band] =
2629 mask->control[band].legacy << 4;
2630
2631 /* copy mcs rate mask */
2632 mcsrate = mask->control[band].mcs[1];
2633 mcsrate <<= 8;
2634 mcsrate |= mask->control[band].mcs[0];
2635 ratemask[band] |= mcsrate << 12;
2636 ratemask[band] |= mcsrate << 28;
2637 }
2638
2639 ath6kl_dbg(ATH6KL_DBG_WMI,
2640 "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
2641 ratemask[0], ratemask[1]);
2642
2643 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2644 if (!skb)
2645 return -ENOMEM;
2646
2647 cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
2648 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2649 /* A mode operate in 5GHZ band */
2650 if (mode == WMI_RATES_MODE_11A ||
2651 mode == WMI_RATES_MODE_11A_HT20 ||
2652 mode == WMI_RATES_MODE_11A_HT40)
2653 band = IEEE80211_BAND_5GHZ;
2654 else
2655 band = IEEE80211_BAND_2GHZ;
2656 cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
2657 }
2658
2659 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2660 WMI_SET_TX_SELECT_RATES_CMDID,
2661 NO_SYNC_WMIFLAG);
2662 return ret;
2663}
2664
2665static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
2666 const struct cfg80211_bitrate_mask *mask)
2667{
2668 struct sk_buff *skb;
2669 int ret, mode, band;
2670 u32 mcsrate, ratemask[IEEE80211_NUM_BANDS];
2671 struct wmi_set_tx_select_rates32_cmd *cmd;
2672
2673 memset(&ratemask, 0, sizeof(ratemask));
2674 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2675 /* copy legacy rate mask */
2676 ratemask[band] = mask->control[band].legacy;
2677 if (band == IEEE80211_BAND_5GHZ)
2678 ratemask[band] =
2679 mask->control[band].legacy << 4;
2680
2681 /* copy mcs rate mask */
2682 mcsrate = mask->control[band].mcs[0];
2683 ratemask[band] |= mcsrate << 12;
2684 ratemask[band] |= mcsrate << 20;
2685 }
2686
2687 ath6kl_dbg(ATH6KL_DBG_WMI,
2688 "Ratemask 32 bit: 2.4:%x 5:%x\n",
2689 ratemask[0], ratemask[1]);
2690
2691 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
2692 if (!skb)
2693 return -ENOMEM;
2694
2695 cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
2696 for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
2697 /* A mode operate in 5GHZ band */
2698 if (mode == WMI_RATES_MODE_11A ||
2699 mode == WMI_RATES_MODE_11A_HT20 ||
2700 mode == WMI_RATES_MODE_11A_HT40)
2701 band = IEEE80211_BAND_5GHZ;
2702 else
2703 band = IEEE80211_BAND_2GHZ;
2704 cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
2705 }
2706
2707 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2708 WMI_SET_TX_SELECT_RATES_CMDID,
2709 NO_SYNC_WMIFLAG);
2710 return ret;
2711}
2712
2713int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
2714 const struct cfg80211_bitrate_mask *mask)
2715{
2716 struct ath6kl *ar = wmi->parent_dev;
2717
2718 if (ar->hw.flags & ATH6KL_HW_FLAG_64BIT_RATES)
2719 return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
2720 else
2721 return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
2722}
2723
Raja Mani45cf1102011-11-07 22:52:45 +02002724int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
2725 enum ath6kl_host_mode host_mode)
2726{
2727 struct sk_buff *skb;
2728 struct wmi_set_host_sleep_mode_cmd *cmd;
2729 int ret;
2730
2731 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
2732 (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
2733 ath6kl_err("invalid host sleep mode: %d\n", host_mode);
2734 return -EINVAL;
2735 }
2736
2737 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2738 if (!skb)
2739 return -ENOMEM;
2740
2741 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
2742
2743 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
2744 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
2745 cmd->asleep = cpu_to_le32(1);
2746 } else
2747 cmd->awake = cpu_to_le32(1);
2748
2749 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2750 WMI_SET_HOST_SLEEP_MODE_CMDID,
2751 NO_SYNC_WMIFLAG);
2752 return ret;
2753}
2754
Raja Mani081c7a82012-01-30 17:13:11 +05302755/* This command has zero length payload */
2756static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
2757 struct ath6kl_vif *vif)
2758{
2759 struct ath6kl *ar = wmi->parent_dev;
2760
2761 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
2762 wake_up(&ar->event_wq);
2763
2764 return 0;
2765}
2766
Raja Mani45cf1102011-11-07 22:52:45 +02002767int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
2768 enum ath6kl_wow_mode wow_mode,
2769 u32 filter, u16 host_req_delay)
2770{
2771 struct sk_buff *skb;
2772 struct wmi_set_wow_mode_cmd *cmd;
2773 int ret;
2774
2775 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
Kalle Valo96f1fad2012-03-07 20:03:57 +02002776 wow_mode != ATH6KL_WOW_MODE_DISABLE) {
Raja Mani45cf1102011-11-07 22:52:45 +02002777 ath6kl_err("invalid wow mode: %d\n", wow_mode);
2778 return -EINVAL;
2779 }
2780
2781 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2782 if (!skb)
2783 return -ENOMEM;
2784
2785 cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
2786 cmd->enable_wow = cpu_to_le32(wow_mode);
2787 cmd->filter = cpu_to_le32(filter);
2788 cmd->host_req_delay = cpu_to_le16(host_req_delay);
2789
2790 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
2791 NO_SYNC_WMIFLAG);
2792 return ret;
2793}
2794
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002795int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2796 u8 list_id, u8 filter_size,
Raja Manid91e8ee2012-01-30 17:13:10 +05302797 u8 filter_offset, const u8 *filter,
2798 const u8 *mask)
Raja Mani5c9b4fa2011-11-07 22:52:45 +02002799{
2800 struct sk_buff *skb;
2801 struct wmi_add_wow_pattern_cmd *cmd;
2802 u16 size;
2803 u8 *filter_mask;
2804 int ret;
2805
2806 /*
2807 * Allocate additional memory in the buffer to hold
2808 * filter and mask value, which is twice of filter_size.
2809 */
2810 size = sizeof(*cmd) + (2 * filter_size);
2811
2812 skb = ath6kl_wmi_get_new_buf(size);
2813 if (!skb)
2814 return -ENOMEM;
2815
2816 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
2817 cmd->filter_list_id = list_id;
2818 cmd->filter_size = filter_size;
2819 cmd->filter_offset = filter_offset;
2820
2821 memcpy(cmd->filter, filter, filter_size);
2822
2823 filter_mask = (u8 *) (cmd->filter + filter_size);
2824 memcpy(filter_mask, mask, filter_size);
2825
2826 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
2827 NO_SYNC_WMIFLAG);
2828
2829 return ret;
2830}
2831
2832int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
2833 u16 list_id, u16 filter_id)
2834{
2835 struct sk_buff *skb;
2836 struct wmi_del_wow_pattern_cmd *cmd;
2837 int ret;
2838
2839 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2840 if (!skb)
2841 return -ENOMEM;
2842
2843 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
2844 cmd->filter_list_id = cpu_to_le16(list_id);
2845 cmd->filter_id = cpu_to_le16(filter_id);
2846
2847 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
2848 NO_SYNC_WMIFLAG);
2849 return ret;
2850}
2851
Kalle Valobdcd8172011-07-18 00:22:30 +03002852static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2853 enum wmix_command_id cmd_id,
2854 enum wmi_sync_flag sync_flag)
2855{
2856 struct wmix_cmd_hdr *cmd_hdr;
2857 int ret;
2858
2859 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2860
2861 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2862 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2863
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302864 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03002865
2866 return ret;
2867}
2868
2869int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2870{
2871 struct sk_buff *skb;
2872 struct wmix_hb_challenge_resp_cmd *cmd;
2873 int ret;
2874
2875 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2876 if (!skb)
2877 return -ENOMEM;
2878
2879 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2880 cmd->cookie = cpu_to_le32(cookie);
2881 cmd->source = cpu_to_le32(source);
2882
2883 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2884 NO_SYNC_WMIFLAG);
2885 return ret;
2886}
2887
Kalle Valo939f1cc2011-09-02 10:32:04 +03002888int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2889{
2890 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2891 struct sk_buff *skb;
2892 int ret;
2893
2894 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2895 if (!skb)
2896 return -ENOMEM;
2897
2898 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2899 cmd->valid = cpu_to_le32(valid);
2900 cmd->config = cpu_to_le32(config);
2901
2902 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2903 NO_SYNC_WMIFLAG);
2904 return ret;
2905}
2906
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302907int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002908{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302909 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002910}
2911
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302912int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
Kalle Valobdcd8172011-07-18 00:22:30 +03002913{
2914 struct sk_buff *skb;
2915 struct wmi_set_tx_pwr_cmd *cmd;
2916 int ret;
2917
2918 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2919 if (!skb)
2920 return -ENOMEM;
2921
2922 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2923 cmd->dbM = dbM;
2924
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302925 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002926 NO_SYNC_WMIFLAG);
2927
2928 return ret;
2929}
2930
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302931int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002932{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05302933 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002934}
2935
Jouni Malinen4b28a802011-10-11 17:31:54 +03002936int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
2937{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302938 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
Jouni Malinen4b28a802011-10-11 17:31:54 +03002939}
2940
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302941int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
2942 u8 preamble_policy)
Kalle Valobdcd8172011-07-18 00:22:30 +03002943{
2944 struct sk_buff *skb;
2945 struct wmi_set_lpreamble_cmd *cmd;
2946 int ret;
2947
2948 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2949 if (!skb)
2950 return -ENOMEM;
2951
2952 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2953 cmd->status = status;
2954 cmd->preamble_policy = preamble_policy;
2955
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302956 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002957 NO_SYNC_WMIFLAG);
2958 return ret;
2959}
2960
2961int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2962{
2963 struct sk_buff *skb;
2964 struct wmi_set_rts_cmd *cmd;
2965 int ret;
2966
2967 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2968 if (!skb)
2969 return -ENOMEM;
2970
2971 cmd = (struct wmi_set_rts_cmd *) skb->data;
2972 cmd->threshold = cpu_to_le16(threshold);
2973
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302974 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
2975 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002976 return ret;
2977}
2978
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302979int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
Kalle Valobdcd8172011-07-18 00:22:30 +03002980{
2981 struct sk_buff *skb;
2982 struct wmi_set_wmm_txop_cmd *cmd;
2983 int ret;
2984
2985 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2986 return -EINVAL;
2987
2988 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2989 if (!skb)
2990 return -ENOMEM;
2991
2992 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2993 cmd->txop_enable = cfg;
2994
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05302995 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002996 NO_SYNC_WMIFLAG);
2997 return ret;
2998}
2999
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303000int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
3001 u8 keep_alive_intvl)
Kalle Valobdcd8172011-07-18 00:22:30 +03003002{
3003 struct sk_buff *skb;
3004 struct wmi_set_keepalive_cmd *cmd;
3005 int ret;
3006
3007 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3008 if (!skb)
3009 return -ENOMEM;
3010
3011 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
3012 cmd->keep_alive_intvl = keep_alive_intvl;
Kalle Valobdcd8172011-07-18 00:22:30 +03003013
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303014 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003015 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303016
Jouni Malinenff0b0072011-10-11 17:31:56 +03003017 if (ret == 0)
3018 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303019
Kalle Valobdcd8172011-07-18 00:22:30 +03003020 return ret;
3021}
3022
Vasanthakumar Thiagarajandf90b362012-04-09 19:03:58 +05303023int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
3024 enum ieee80211_band band,
3025 struct ath6kl_htcap *htcap)
3026{
3027 struct sk_buff *skb;
3028 struct wmi_set_htcap_cmd *cmd;
3029
3030 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3031 if (!skb)
3032 return -ENOMEM;
3033
3034 cmd = (struct wmi_set_htcap_cmd *) skb->data;
3035
3036 /*
3037 * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely
3038 * this will be changed in firmware. If at all there is any change in
3039 * band value, the host needs to be fixed.
3040 */
3041 cmd->band = band;
3042 cmd->ht_enable = !!htcap->ht_enable;
3043 cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
3044 cmd->ht40_supported =
3045 !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
3046 cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
3047 cmd->intolerant_40mhz =
3048 !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
3049 cmd->max_ampdu_len_exp = htcap->ampdu_factor;
3050
3051 ath6kl_dbg(ATH6KL_DBG_WMI,
3052 "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
3053 cmd->band, cmd->ht_enable, cmd->ht40_supported,
3054 cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
3055 cmd->max_ampdu_len_exp);
3056 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
3057 NO_SYNC_WMIFLAG);
3058}
3059
Kalle Valo003353b0d2011-09-01 10:14:21 +03003060int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
3061{
3062 struct sk_buff *skb;
3063 int ret;
3064
3065 skb = ath6kl_wmi_get_new_buf(len);
3066 if (!skb)
3067 return -ENOMEM;
3068
3069 memcpy(skb->data, buf, len);
3070
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303071 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003072
3073 return ret;
3074}
3075
Vasanthakumar Thiagarajan3f3c4ee2012-01-03 14:41:59 +05303076int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
3077{
3078 struct sk_buff *skb;
3079 struct wmi_mcast_filter_cmd *cmd;
3080 int ret;
3081
3082 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3083 if (!skb)
3084 return -ENOMEM;
3085
3086 cmd = (struct wmi_mcast_filter_cmd *) skb->data;
3087 cmd->mcast_all_enable = mc_all_on;
3088
3089 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
3090 NO_SYNC_WMIFLAG);
3091 return ret;
3092}
Kalle Valo003353b0d2011-09-01 10:14:21 +03003093
Vasanthakumar Thiagarajanf914edd2012-01-03 14:42:00 +05303094int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
3095 u8 *filter, bool add_filter)
3096{
3097 struct sk_buff *skb;
3098 struct wmi_mcast_filter_add_del_cmd *cmd;
3099 int ret;
3100
3101 if ((filter[0] != 0x33 || filter[1] != 0x33) &&
3102 (filter[0] != 0x01 || filter[1] != 0x00 ||
3103 filter[2] != 0x5e || filter[3] > 0x7f)) {
3104 ath6kl_warn("invalid multicast filter address\n");
3105 return -EINVAL;
3106 }
3107
3108 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3109 if (!skb)
3110 return -ENOMEM;
3111
3112 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
3113 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
3114 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3115 add_filter ? WMI_SET_MCAST_FILTER_CMDID :
3116 WMI_DEL_MCAST_FILTER_CMDID,
3117 NO_SYNC_WMIFLAG);
3118
3119 return ret;
3120}
3121
Thomas Pedersenc422d52d2012-05-15 00:09:23 -07003122int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
3123{
3124 struct sk_buff *skb;
3125 struct wmi_sta_bmiss_enhance_cmd *cmd;
3126 int ret;
3127
3128 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3129 if (!skb)
3130 return -ENOMEM;
3131
3132 cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
3133 cmd->enable = enhance ? 1 : 0;
3134
3135 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3136 WMI_STA_BMISS_ENHANCE_CMDID,
3137 NO_SYNC_WMIFLAG);
3138 return ret;
3139}
3140
Kalle Valobdcd8172011-07-18 00:22:30 +03003141s32 ath6kl_wmi_get_rate(s8 rate_index)
3142{
3143 if (rate_index == RATE_AUTO)
3144 return 0;
3145
3146 return wmi_rate_tbl[(u32) rate_index][0];
3147}
3148
Kalle Valobdcd8172011-07-18 00:22:30 +03003149static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
3150 u32 len)
3151{
3152 struct wmi_pmkid_list_reply *reply;
3153 u32 expected_len;
3154
3155 if (len < sizeof(struct wmi_pmkid_list_reply))
3156 return -EINVAL;
3157
3158 reply = (struct wmi_pmkid_list_reply *)datap;
3159 expected_len = sizeof(reply->num_pmkid) +
3160 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
3161
3162 if (len < expected_len)
3163 return -EINVAL;
3164
3165 return 0;
3166}
3167
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303168static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3169 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003170{
3171 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
3172
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303173 aggr_recv_addba_req_evt(vif, cmd->tid,
Kalle Valobdcd8172011-07-18 00:22:30 +03003174 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
3175
3176 return 0;
3177}
3178
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303179static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
3180 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003181{
3182 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
3183
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303184 aggr_recv_delba_req_evt(vif, cmd->tid);
Kalle Valobdcd8172011-07-18 00:22:30 +03003185
3186 return 0;
3187}
3188
3189/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003190
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303191int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
3192 struct wmi_connect_cmd *p)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003193{
3194 struct sk_buff *skb;
3195 struct wmi_connect_cmd *cm;
3196 int res;
3197
3198 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3199 if (!skb)
3200 return -ENOMEM;
3201
3202 cm = (struct wmi_connect_cmd *) skb->data;
3203 memcpy(cm, p, sizeof(*cm));
3204
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303205 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003206 NO_SYNC_WMIFLAG);
Kalle Valocdeb8602012-04-12 11:02:18 +03003207 ath6kl_dbg(ATH6KL_DBG_WMI,
3208 "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003209 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
3210 le32_to_cpu(p->ctrl_flags), res);
3211 return res;
3212}
3213
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303214int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
3215 u16 reason)
Jouni Malinen23875132011-08-30 21:57:53 +03003216{
3217 struct sk_buff *skb;
3218 struct wmi_ap_set_mlme_cmd *cm;
3219
3220 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
3221 if (!skb)
3222 return -ENOMEM;
3223
3224 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
3225 memcpy(cm->mac, mac, ETH_ALEN);
3226 cm->reason = cpu_to_le16(reason);
3227 cm->cmd = cmd;
3228
Aarthi Thiruvengadam7397dde2012-03-15 14:36:11 -07003229 ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
3230 cm->reason);
3231
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303232 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
Jouni Malinen23875132011-08-30 21:57:53 +03003233 NO_SYNC_WMIFLAG);
3234}
3235
Thomas Pedersen67cd22e2012-02-28 15:08:46 -08003236int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
3237{
3238 struct sk_buff *skb;
3239 struct wmi_ap_hidden_ssid_cmd *cmd;
3240
3241 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3242 if (!skb)
3243 return -ENOMEM;
3244
3245 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
3246 cmd->hidden_ssid = enable ? 1 : 0;
3247
3248 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
3249 NO_SYNC_WMIFLAG);
3250}
3251
Thirumalai Pachamuthuc1762a32012-01-12 18:21:39 +05303252/* This command will be used to enable/disable AP uAPSD feature */
3253int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
3254{
3255 struct wmi_ap_set_apsd_cmd *cmd;
3256 struct sk_buff *skb;
3257
3258 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3259 if (!skb)
3260 return -ENOMEM;
3261
3262 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
3263 cmd->enable = enable;
3264
3265 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
3266 NO_SYNC_WMIFLAG);
3267}
3268
3269int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
3270 u16 aid, u16 bitmap, u32 flags)
3271{
3272 struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
3273 struct sk_buff *skb;
3274
3275 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3276 if (!skb)
3277 return -ENOMEM;
3278
3279 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
3280 cmd->aid = cpu_to_le16(aid);
3281 cmd->bitmap = cpu_to_le16(bitmap);
3282 cmd->flags = cpu_to_le32(flags);
3283
3284 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3285 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
3286 NO_SYNC_WMIFLAG);
3287}
3288
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303289static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
3290 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003291{
3292 struct wmi_pspoll_event *ev;
3293
3294 if (len < sizeof(struct wmi_pspoll_event))
3295 return -EINVAL;
3296
3297 ev = (struct wmi_pspoll_event *) datap;
3298
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303299 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
Kalle Valobdcd8172011-07-18 00:22:30 +03003300
3301 return 0;
3302}
3303
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303304static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
3305 struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +03003306{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303307 ath6kl_dtimexpiry_event(vif);
Kalle Valobdcd8172011-07-18 00:22:30 +03003308
3309 return 0;
3310}
3311
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303312int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
3313 bool flag)
Kalle Valobdcd8172011-07-18 00:22:30 +03003314{
3315 struct sk_buff *skb;
3316 struct wmi_ap_set_pvb_cmd *cmd;
3317 int ret;
3318
3319 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
3320 if (!skb)
3321 return -ENOMEM;
3322
3323 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
3324 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03003325 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03003326 cmd->flag = cpu_to_le32(flag);
3327
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303328 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003329 NO_SYNC_WMIFLAG);
3330
3331 return 0;
3332}
3333
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303334int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
3335 u8 rx_meta_ver,
Kalle Valobdcd8172011-07-18 00:22:30 +03003336 bool rx_dot11_hdr, bool defrag_on_host)
3337{
3338 struct sk_buff *skb;
3339 struct wmi_rx_frame_format_cmd *cmd;
3340 int ret;
3341
3342 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3343 if (!skb)
3344 return -ENOMEM;
3345
3346 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
3347 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
3348 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
3349 cmd->meta_ver = rx_meta_ver;
3350
3351 /* Delete the local aggr state, on host */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303352 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03003353 NO_SYNC_WMIFLAG);
3354
3355 return ret;
3356}
3357
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303358int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
3359 const u8 *ie, u8 ie_len)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003360{
3361 struct sk_buff *skb;
3362 struct wmi_set_appie_cmd *p;
3363
3364 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3365 if (!skb)
3366 return -ENOMEM;
3367
Kalle Valocdeb8602012-04-12 11:02:18 +03003368 ath6kl_dbg(ATH6KL_DBG_WMI,
3369 "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
3370 mgmt_frm_type, ie_len);
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003371 p = (struct wmi_set_appie_cmd *) skb->data;
3372 p->mgmt_frm_type = mgmt_frm_type;
3373 p->ie_len = ie_len;
Kalle Valo10509f92011-12-13 14:52:07 +02003374
3375 if (ie != NULL && ie_len > 0)
3376 memcpy(p->ie_info, ie, ie_len);
3377
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303378 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03003379 NO_SYNC_WMIFLAG);
3380}
3381
Vasanthakumar Thiagarajand97c1212012-04-09 20:51:20 +05303382int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
3383 const u8 *ie_info, u8 ie_len)
3384{
3385 struct sk_buff *skb;
3386 struct wmi_set_ie_cmd *p;
3387
3388 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
3389 if (!skb)
3390 return -ENOMEM;
3391
3392 ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
3393 ie_id, ie_field, ie_len);
3394 p = (struct wmi_set_ie_cmd *) skb->data;
3395 p->ie_id = ie_id;
3396 p->ie_field = ie_field;
3397 p->ie_len = ie_len;
3398 if (ie_info && ie_len > 0)
3399 memcpy(p->ie_info, ie_info, ie_len);
3400
3401 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
3402 NO_SYNC_WMIFLAG);
3403}
3404
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003405int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
3406{
3407 struct sk_buff *skb;
3408 struct wmi_disable_11b_rates_cmd *cmd;
3409
3410 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3411 if (!skb)
3412 return -ENOMEM;
3413
3414 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
3415 disable);
3416 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
3417 cmd->disable = disable ? 1 : 0;
3418
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303419 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003420 NO_SYNC_WMIFLAG);
3421}
3422
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303423int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003424{
3425 struct sk_buff *skb;
3426 struct wmi_remain_on_chnl_cmd *p;
3427
3428 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3429 if (!skb)
3430 return -ENOMEM;
3431
3432 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
3433 freq, dur);
3434 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
3435 p->freq = cpu_to_le32(freq);
3436 p->duration = cpu_to_le32(dur);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303437 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003438 NO_SYNC_WMIFLAG);
3439}
3440
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003441/* ath6kl_wmi_send_action_cmd is to be deprecated. Use
3442 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
3443 * mgmt operations using station interface.
3444 */
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003445static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3446 u32 freq, u32 wait, const u8 *data,
3447 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003448{
3449 struct sk_buff *skb;
3450 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03003451 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003452
3453 if (wait)
3454 return -EINVAL; /* Offload for wait not supported */
3455
Jouni Malinena0df5db2011-08-30 21:58:02 +03003456 buf = kmalloc(data_len, GFP_KERNEL);
3457 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003458 return -ENOMEM;
3459
Jouni Malinena0df5db2011-08-30 21:58:02 +03003460 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3461 if (!skb) {
3462 kfree(buf);
3463 return -ENOMEM;
3464 }
3465
3466 kfree(wmi->last_mgmt_tx_frame);
Aarthi Thiruvengadam3101ede2011-10-27 09:35:56 -07003467 memcpy(buf, data, data_len);
Jouni Malinena0df5db2011-08-30 21:58:02 +03003468 wmi->last_mgmt_tx_frame = buf;
3469 wmi->last_mgmt_tx_frame_len = data_len;
3470
Kalle Valocdeb8602012-04-12 11:02:18 +03003471 ath6kl_dbg(ATH6KL_DBG_WMI,
3472 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3473 id, freq, wait, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003474 p = (struct wmi_send_action_cmd *) skb->data;
3475 p->id = cpu_to_le32(id);
3476 p->freq = cpu_to_le32(freq);
3477 p->wait = cpu_to_le32(wait);
3478 p->len = cpu_to_le16(data_len);
3479 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303480 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003481 NO_SYNC_WMIFLAG);
3482}
3483
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003484static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
3485 u32 freq, u32 wait, const u8 *data,
3486 u16 data_len, u32 no_cck)
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003487{
3488 struct sk_buff *skb;
3489 struct wmi_send_mgmt_cmd *p;
3490 u8 *buf;
3491
3492 if (wait)
3493 return -EINVAL; /* Offload for wait not supported */
3494
3495 buf = kmalloc(data_len, GFP_KERNEL);
3496 if (!buf)
3497 return -ENOMEM;
3498
3499 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
3500 if (!skb) {
3501 kfree(buf);
3502 return -ENOMEM;
3503 }
3504
3505 kfree(wmi->last_mgmt_tx_frame);
3506 memcpy(buf, data, data_len);
3507 wmi->last_mgmt_tx_frame = buf;
3508 wmi->last_mgmt_tx_frame_len = data_len;
3509
Kalle Valocdeb8602012-04-12 11:02:18 +03003510 ath6kl_dbg(ATH6KL_DBG_WMI,
3511 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
3512 id, freq, wait, data_len);
Aarthi Thiruvengadam3ca9d1f2011-12-13 13:32:12 -08003513 p = (struct wmi_send_mgmt_cmd *) skb->data;
3514 p->id = cpu_to_le32(id);
3515 p->freq = cpu_to_le32(freq);
3516 p->wait = cpu_to_le32(wait);
3517 p->no_cck = cpu_to_le32(no_cck);
3518 p->len = cpu_to_le16(data_len);
3519 memcpy(p->data, data, data_len);
3520 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
3521 NO_SYNC_WMIFLAG);
3522}
3523
Naveen Gangadharand0ff7382012-02-08 17:51:36 -08003524int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
3525 u32 wait, const u8 *data, u16 data_len,
3526 u32 no_cck)
3527{
3528 int status;
3529 struct ath6kl *ar = wmi->parent_dev;
3530
3531 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
3532 ar->fw_capabilities)) {
3533 /*
3534 * If capable of doing P2P mgmt operations using
3535 * station interface, send additional information like
3536 * supported rates to advertise and xmit rates for
3537 * probe requests
3538 */
3539 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
3540 wait, data, data_len,
3541 no_cck);
3542 } else {
3543 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
3544 wait, data, data_len);
3545 }
3546
3547 return status;
3548}
3549
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303550int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
3551 const u8 *dst, const u8 *data,
3552 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003553{
3554 struct sk_buff *skb;
3555 struct wmi_p2p_probe_response_cmd *p;
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003556 size_t cmd_len = sizeof(*p) + data_len;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003557
Aarthi Thiruvengadambd24a502011-11-09 10:05:56 -08003558 if (data_len == 0)
3559 cmd_len++; /* work around target minimum length requirement */
3560
3561 skb = ath6kl_wmi_get_new_buf(cmd_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003562 if (!skb)
3563 return -ENOMEM;
3564
Kalle Valocdeb8602012-04-12 11:02:18 +03003565 ath6kl_dbg(ATH6KL_DBG_WMI,
3566 "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
3567 freq, dst, data_len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003568 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
3569 p->freq = cpu_to_le32(freq);
3570 memcpy(p->destination_addr, dst, ETH_ALEN);
3571 p->len = cpu_to_le16(data_len);
3572 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303573 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
3574 WMI_SEND_PROBE_RESPONSE_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003575 NO_SYNC_WMIFLAG);
3576}
3577
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303578int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003579{
3580 struct sk_buff *skb;
3581 struct wmi_probe_req_report_cmd *p;
3582
3583 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3584 if (!skb)
3585 return -ENOMEM;
3586
3587 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
3588 enable);
3589 p = (struct wmi_probe_req_report_cmd *) skb->data;
3590 p->enable = enable ? 1 : 0;
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303591 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003592 NO_SYNC_WMIFLAG);
3593}
3594
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303595int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003596{
3597 struct sk_buff *skb;
3598 struct wmi_get_p2p_info *p;
3599
3600 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
3601 if (!skb)
3602 return -ENOMEM;
3603
3604 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
3605 info_req_flags);
3606 p = (struct wmi_get_p2p_info *) skb->data;
3607 p->info_req_flags = cpu_to_le32(info_req_flags);
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05303608 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003609 NO_SYNC_WMIFLAG);
3610}
3611
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303612int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003613{
3614 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05303615 return ath6kl_wmi_simple_cmd(wmi, if_idx,
3616 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003617}
3618
Vasanthakumar Thiagarajan03bdeb02012-03-21 20:58:39 +05303619int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
3620{
3621 struct sk_buff *skb;
3622 struct wmi_set_inact_period_cmd *cmd;
3623
3624 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
3625 if (!skb)
3626 return -ENOMEM;
3627
3628 cmd = (struct wmi_set_inact_period_cmd *) skb->data;
3629 cmd->inact_period = cpu_to_le32(inact_timeout);
3630 cmd->num_null_func = 0;
3631
3632 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
3633 NO_SYNC_WMIFLAG);
3634}
3635
Kalle Valobdcd8172011-07-18 00:22:30 +03003636static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
3637{
3638 struct wmix_cmd_hdr *cmd;
3639 u32 len;
3640 u16 id;
3641 u8 *datap;
3642 int ret = 0;
3643
3644 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
3645 ath6kl_err("bad packet 1\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003646 return -EINVAL;
3647 }
3648
3649 cmd = (struct wmix_cmd_hdr *) skb->data;
3650 id = le32_to_cpu(cmd->cmd_id);
3651
3652 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
3653
3654 datap = skb->data;
3655 len = skb->len;
3656
3657 switch (id) {
3658 case WMIX_HB_CHALLENGE_RESP_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003659 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003660 break;
3661 case WMIX_DBGLOG_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003662 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
Kalle Valobdf53962011-09-02 10:32:04 +03003663 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003664 break;
3665 default:
Kalle Valob9b6ee62011-09-27 14:31:21 +03003666 ath6kl_warn("unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03003667 ret = -EINVAL;
3668 break;
3669 }
3670
3671 return ret;
3672}
3673
Jouni Malinen4b28a802011-10-11 17:31:54 +03003674static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
3675{
3676 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
3677}
3678
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303679/* Process interface specific wmi events, caller would free the datap */
3680static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
3681 u8 *datap, u32 len)
Kalle Valobdcd8172011-07-18 00:22:30 +03003682{
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303683 struct ath6kl_vif *vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03003684
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303685 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
3686 if (!vif) {
3687 ath6kl_dbg(ATH6KL_DBG_WMI,
3688 "Wmi event for unavailable vif, vif_index:%d\n",
3689 if_idx);
Vasanthakumar Thiagarajan240d2792011-10-25 19:34:13 +05303690 return -EINVAL;
3691 }
3692
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303693 switch (cmd_id) {
3694 case WMI_CONNECT_EVENTID:
3695 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
3696 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
3697 case WMI_DISCONNECT_EVENTID:
3698 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
3699 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
3700 case WMI_TKIP_MICERR_EVENTID:
3701 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
3702 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
3703 case WMI_BSSINFO_EVENTID:
3704 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
3705 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
3706 case WMI_NEIGHBOR_REPORT_EVENTID:
3707 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
3708 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
3709 vif);
3710 case WMI_SCAN_COMPLETE_EVENTID:
3711 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3712 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
3713 case WMI_REPORT_STATISTICS_EVENTID:
3714 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3715 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
3716 case WMI_CAC_EVENTID:
3717 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3718 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
3719 case WMI_PSPOLL_EVENTID:
3720 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3721 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
3722 case WMI_DTIMEXPIRY_EVENTID:
3723 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3724 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
3725 case WMI_ADDBA_REQ_EVENTID:
3726 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3727 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
3728 case WMI_DELBA_REQ_EVENTID:
3729 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3730 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
3731 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
3732 ath6kl_dbg(ATH6KL_DBG_WMI,
3733 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
3734 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
3735 case WMI_REMAIN_ON_CHNL_EVENTID:
3736 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
3737 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
3738 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3739 ath6kl_dbg(ATH6KL_DBG_WMI,
3740 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
3741 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3742 len, vif);
3743 case WMI_TX_STATUS_EVENTID:
3744 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3745 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
3746 case WMI_RX_PROBE_REQ_EVENTID:
3747 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
3748 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
3749 case WMI_RX_ACTION_EVENTID:
3750 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3751 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
3752 default:
3753 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
3754 return -EINVAL;
3755 }
3756
3757 return 0;
3758}
3759
3760static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
3761{
3762 struct wmi_cmd_hdr *cmd;
3763 int ret = 0;
3764 u32 len;
3765 u16 id;
3766 u8 if_idx;
3767 u8 *datap;
3768
3769 cmd = (struct wmi_cmd_hdr *) skb->data;
3770 id = le16_to_cpu(cmd->cmd_id);
3771 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
3772
3773 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
3774 datap = skb->data;
3775 len = skb->len;
3776
3777 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
3778 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
3779 datap, len);
3780
Kalle Valobdcd8172011-07-18 00:22:30 +03003781 switch (id) {
3782 case WMI_GET_BITRATE_CMDID:
3783 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
3784 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
3785 break;
3786 case WMI_GET_CHANNEL_LIST_CMDID:
3787 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
3788 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
3789 break;
3790 case WMI_GET_TX_PWR_CMDID:
3791 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
3792 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
3793 break;
3794 case WMI_READY_EVENTID:
3795 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
3796 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
3797 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003798 case WMI_PEER_NODE_EVENTID:
3799 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
3800 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
3801 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003802 case WMI_REGDOMAIN_EVENTID:
3803 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05303804 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003805 break;
3806 case WMI_PSTREAM_TIMEOUT_EVENTID:
3807 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3808 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3809 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003810 case WMI_CMDERROR_EVENTID:
3811 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3812 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3813 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003814 case WMI_RSSI_THRESHOLD_EVENTID:
3815 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3816 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3817 break;
3818 case WMI_ERROR_REPORT_EVENTID:
3819 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3820 break;
3821 case WMI_OPT_RX_FRAME_EVENTID:
3822 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03003823 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03003824 break;
3825 case WMI_REPORT_ROAM_TBL_EVENTID:
3826 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
Jouni Malinen4b28a802011-10-11 17:31:54 +03003827 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003828 break;
3829 case WMI_EXTENSION_EVENTID:
3830 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3831 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3832 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003833 case WMI_CHANNEL_CHANGE_EVENTID:
3834 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3835 break;
3836 case WMI_REPORT_ROAM_DATA_EVENTID:
3837 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3838 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03003839 case WMI_TEST_EVENTID:
3840 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
Thomas Pedersen4f34dac2011-12-30 01:57:00 -08003841 ret = ath6kl_wmi_test_rx(wmi, datap, len);
Kalle Valo003353b0d2011-09-01 10:14:21 +03003842 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003843 case WMI_GET_FIXRATES_CMDID:
3844 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3845 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3846 break;
3847 case WMI_TX_RETRY_ERR_EVENTID:
3848 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3849 break;
3850 case WMI_SNR_THRESHOLD_EVENTID:
3851 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3852 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3853 break;
3854 case WMI_LQ_THRESHOLD_EVENTID:
3855 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3856 break;
3857 case WMI_APLIST_EVENTID:
3858 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3859 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3860 break;
3861 case WMI_GET_KEEPALIVE_CMDID:
3862 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3863 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3864 break;
3865 case WMI_GET_WOW_LIST_EVENTID:
3866 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03003867 break;
3868 case WMI_GET_PMKID_LIST_EVENTID:
3869 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3870 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3871 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003872 case WMI_SET_PARAMS_REPLY_EVENTID:
3873 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3874 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003875 case WMI_ADDBA_RESP_EVENTID:
3876 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3877 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003878 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3879 ath6kl_dbg(ATH6KL_DBG_WMI,
3880 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3881 break;
3882 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3883 ath6kl_dbg(ATH6KL_DBG_WMI,
3884 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3885 break;
3886 case WMI_TX_COMPLETE_EVENTID:
3887 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3888 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3889 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003890 case WMI_P2P_CAPABILITIES_EVENTID:
3891 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3892 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3893 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003894 case WMI_P2P_INFO_EVENTID:
3895 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3896 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3897 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003898 default:
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303899 /* may be the event is interface specific */
3900 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003901 break;
3902 }
3903
3904 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03003905 return ret;
3906}
3907
Vasanthakumar Thiagarajan5dbc8112012-02-28 20:20:21 +05303908/* Control Path */
3909int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
3910{
3911 if (WARN_ON(skb == NULL))
3912 return -EINVAL;
3913
3914 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
3915 ath6kl_err("bad packet 1\n");
3916 dev_kfree_skb(skb);
3917 return -EINVAL;
3918 }
3919
3920 return ath6kl_wmi_proc_events(wmi, skb);
3921}
3922
Kalle Valoc89c5912011-10-27 18:48:00 +03003923void ath6kl_wmi_reset(struct wmi *wmi)
Kalle Valobdcd8172011-07-18 00:22:30 +03003924{
Kalle Valobdcd8172011-07-18 00:22:30 +03003925 spin_lock_bh(&wmi->lock);
3926
3927 wmi->fat_pipe_exist = 0;
3928 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3929
3930 spin_unlock_bh(&wmi->lock);
3931}
3932
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05303933void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03003934{
3935 struct wmi *wmi;
3936
3937 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3938 if (!wmi)
3939 return NULL;
3940
3941 spin_lock_init(&wmi->lock);
3942
3943 wmi->parent_dev = dev;
3944
Kalle Valobdcd8172011-07-18 00:22:30 +03003945 wmi->pwr_mode = REC_POWER;
Kalle Valobdcd8172011-07-18 00:22:30 +03003946
Kalle Valoc89c5912011-10-27 18:48:00 +03003947 ath6kl_wmi_reset(wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03003948
3949 return wmi;
3950}
3951
3952void ath6kl_wmi_shutdown(struct wmi *wmi)
3953{
3954 if (!wmi)
3955 return;
3956
Jouni Malinena0df5db2011-08-30 21:58:02 +03003957 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03003958 kfree(wmi);
3959}