blob: a4ad7cbd5eb0c859e44b387dbee0ee7afbac9239 [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001/*
2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/ip.h>
18#include "core.h"
19#include "debug.h"
Kalle Valo003353b0d2011-09-01 10:14:21 +030020#include "testmode.h"
Vivek Natarajan06033762011-09-06 13:01:36 +053021#include "../regd.h"
22#include "../regd_common.h"
Kalle Valobdcd8172011-07-18 00:22:30 +030023
24static int ath6kl_wmi_sync_point(struct wmi *wmi);
25
26static const s32 wmi_rate_tbl[][2] = {
27 /* {W/O SGI, with SGI} */
28 {1000, 1000},
29 {2000, 2000},
30 {5500, 5500},
31 {11000, 11000},
32 {6000, 6000},
33 {9000, 9000},
34 {12000, 12000},
35 {18000, 18000},
36 {24000, 24000},
37 {36000, 36000},
38 {48000, 48000},
39 {54000, 54000},
40 {6500, 7200},
41 {13000, 14400},
42 {19500, 21700},
43 {26000, 28900},
44 {39000, 43300},
45 {52000, 57800},
46 {58500, 65000},
47 {65000, 72200},
48 {13500, 15000},
49 {27000, 30000},
50 {40500, 45000},
51 {54000, 60000},
52 {81000, 90000},
53 {108000, 120000},
54 {121500, 135000},
55 {135000, 150000},
56 {0, 0}
57};
58
59/* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
60static const u8 up_to_ac[] = {
61 WMM_AC_BE,
62 WMM_AC_BK,
63 WMM_AC_BK,
64 WMM_AC_BE,
65 WMM_AC_VI,
66 WMM_AC_VI,
67 WMM_AC_VO,
68 WMM_AC_VO,
69};
70
71void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
72{
73 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
74 return;
75
76 wmi->ep_id = ep_id;
77}
78
79enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
80{
81 return wmi->ep_id;
82}
83
84/* Performs DIX to 802.3 encapsulation for transmit packets.
85 * Assumes the entire DIX header is contigous and that there is
86 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
87 */
88int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
89{
90 struct ath6kl_llc_snap_hdr *llc_hdr;
91 struct ethhdr *eth_hdr;
92 size_t new_len;
93 __be16 type;
94 u8 *datap;
95 u16 size;
96
97 if (WARN_ON(skb == NULL))
98 return -EINVAL;
99
100 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
101 if (skb_headroom(skb) < size)
102 return -ENOMEM;
103
104 eth_hdr = (struct ethhdr *) skb->data;
105 type = eth_hdr->h_proto;
106
107 if (!is_ethertype(be16_to_cpu(type))) {
108 ath6kl_dbg(ATH6KL_DBG_WMI,
109 "%s: pkt is already in 802.3 format\n", __func__);
110 return 0;
111 }
112
113 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
114
115 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
116 datap = skb->data;
117
118 eth_hdr->h_proto = cpu_to_be16(new_len);
119
120 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
121
122 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
123 llc_hdr->dsap = 0xAA;
124 llc_hdr->ssap = 0xAA;
125 llc_hdr->cntl = 0x03;
126 llc_hdr->org_code[0] = 0x0;
127 llc_hdr->org_code[1] = 0x0;
128 llc_hdr->org_code[2] = 0x0;
129 llc_hdr->eth_type = type;
130
131 return 0;
132}
133
134static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
135 u8 *version, void *tx_meta_info)
136{
137 struct wmi_tx_meta_v1 *v1;
138 struct wmi_tx_meta_v2 *v2;
139
140 if (WARN_ON(skb == NULL || version == NULL))
141 return -EINVAL;
142
143 switch (*version) {
144 case WMI_META_VERSION_1:
145 skb_push(skb, WMI_MAX_TX_META_SZ);
146 v1 = (struct wmi_tx_meta_v1 *) skb->data;
147 v1->pkt_id = 0;
148 v1->rate_plcy_id = 0;
149 *version = WMI_META_VERSION_1;
150 break;
151 case WMI_META_VERSION_2:
152 skb_push(skb, WMI_MAX_TX_META_SZ);
153 v2 = (struct wmi_tx_meta_v2 *) skb->data;
154 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
155 sizeof(struct wmi_tx_meta_v2));
156 break;
157 }
158
159 return 0;
160}
161
162int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
163 u8 msg_type, bool more_data,
164 enum wmi_data_hdr_data_type data_type,
165 u8 meta_ver, void *tx_meta_info)
166{
167 struct wmi_data_hdr *data_hdr;
168 int ret;
169
170 if (WARN_ON(skb == NULL))
171 return -EINVAL;
172
Vasanthakumar Thiagarajan3ce6ff52011-08-22 20:40:21 +0530173 if (tx_meta_info) {
174 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
175 if (ret)
176 return ret;
177 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300178
179 skb_push(skb, sizeof(struct wmi_data_hdr));
180
181 data_hdr = (struct wmi_data_hdr *)skb->data;
182 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
183
184 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
185 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
186
187 if (more_data)
188 data_hdr->info |=
189 WMI_DATA_HDR_MORE_MASK << WMI_DATA_HDR_MORE_SHIFT;
190
191 data_hdr->info2 = cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
192 data_hdr->info3 = 0;
193
194 return 0;
195}
196
197static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
198{
199 struct iphdr *ip_hdr = (struct iphdr *) pkt;
200 u8 ip_pri;
201
202 /*
203 * Determine IPTOS priority
204 *
205 * IP-TOS - 8bits
206 * : DSCP(6-bits) ECN(2-bits)
207 * : DSCP - P2 P1 P0 X X X
208 * where (P2 P1 P0) form 802.1D
209 */
210 ip_pri = ip_hdr->tos >> 5;
211 ip_pri &= 0x7;
212
213 if ((layer2_pri & 0x7) > ip_pri)
214 return (u8) layer2_pri & 0x7;
215 else
216 return ip_pri;
217}
218
219int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
220 u32 layer2_priority, bool wmm_enabled,
221 u8 *ac)
222{
223 struct wmi_data_hdr *data_hdr;
224 struct ath6kl_llc_snap_hdr *llc_hdr;
225 struct wmi_create_pstream_cmd cmd;
226 u32 meta_size, hdr_size;
227 u16 ip_type = IP_ETHERTYPE;
228 u8 stream_exist, usr_pri;
229 u8 traffic_class = WMM_AC_BE;
230 u8 *datap;
231
232 if (WARN_ON(skb == NULL))
233 return -EINVAL;
234
235 datap = skb->data;
236 data_hdr = (struct wmi_data_hdr *) datap;
237
238 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
239 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
240
241 if (!wmm_enabled) {
242 /* If WMM is disabled all traffic goes as BE traffic */
243 usr_pri = 0;
244 } else {
245 hdr_size = sizeof(struct ethhdr);
246
247 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
248 sizeof(struct
249 wmi_data_hdr) +
250 meta_size + hdr_size);
251
252 if (llc_hdr->eth_type == htons(ip_type)) {
253 /*
254 * Extract the endpoint info from the TOS field
255 * in the IP header.
256 */
257 usr_pri =
258 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
259 sizeof(struct ath6kl_llc_snap_hdr),
260 layer2_priority);
261 } else
262 usr_pri = layer2_priority & 0x7;
263 }
264
Kalle Valoa7f0c582011-10-05 12:23:05 +0300265 /*
266 * workaround for WMM S5
267 *
268 * FIXME: wmi->traffic_class is always 100 so this test doesn't
269 * make sense
270 */
Kalle Valobdcd8172011-07-18 00:22:30 +0300271 if ((wmi->traffic_class == WMM_AC_VI) &&
272 ((usr_pri == 5) || (usr_pri == 4)))
273 usr_pri = 1;
274
275 /* Convert user priority to traffic class */
276 traffic_class = up_to_ac[usr_pri & 0x7];
277
278 wmi_data_hdr_set_up(data_hdr, usr_pri);
279
280 spin_lock_bh(&wmi->lock);
281 stream_exist = wmi->fat_pipe_exist;
282 spin_unlock_bh(&wmi->lock);
283
284 if (!(stream_exist & (1 << traffic_class))) {
285 memset(&cmd, 0, sizeof(cmd));
286 cmd.traffic_class = traffic_class;
287 cmd.user_pri = usr_pri;
288 cmd.inactivity_int =
289 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
290 /* Implicit streams are created with TSID 0xFF */
291 cmd.tsid = WMI_IMPLICIT_PSTREAM;
292 ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
293 }
294
295 *ac = traffic_class;
296
297 return 0;
298}
299
300int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
301{
302 struct ieee80211_hdr_3addr *pwh, wh;
303 struct ath6kl_llc_snap_hdr *llc_hdr;
304 struct ethhdr eth_hdr;
305 u32 hdr_size;
306 u8 *datap;
307 __le16 sub_type;
308
309 if (WARN_ON(skb == NULL))
310 return -EINVAL;
311
312 datap = skb->data;
313 pwh = (struct ieee80211_hdr_3addr *) datap;
314
315 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
316
317 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
318
319 /* Strip off the 802.11 header */
320 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
321 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
322 sizeof(u32));
323 skb_pull(skb, hdr_size);
324 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
325 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
326
327 datap = skb->data;
328 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
329
Raja Manic8790cba2011-07-19 19:27:32 +0530330 memset(&eth_hdr, 0, sizeof(eth_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +0300331 eth_hdr.h_proto = llc_hdr->eth_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300332
333 switch ((le16_to_cpu(wh.frame_control)) &
334 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
335 case 0:
336 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
337 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
338 break;
339 case IEEE80211_FCTL_TODS:
340 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
341 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
342 break;
343 case IEEE80211_FCTL_FROMDS:
344 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
345 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
346 break;
347 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
348 break;
349 }
350
351 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
352 skb_push(skb, sizeof(eth_hdr));
353
354 datap = skb->data;
355
356 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
357
358 return 0;
359}
360
361/*
362 * Performs 802.3 to DIX encapsulation for received packets.
363 * Assumes the entire 802.3 header is contigous.
364 */
365int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
366{
367 struct ath6kl_llc_snap_hdr *llc_hdr;
368 struct ethhdr eth_hdr;
369 u8 *datap;
370
371 if (WARN_ON(skb == NULL))
372 return -EINVAL;
373
374 datap = skb->data;
375
376 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
377
378 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
379 eth_hdr.h_proto = llc_hdr->eth_type;
380
381 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
382 datap = skb->data;
383
384 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
385
386 return 0;
387}
388
Kalle Valobdcd8172011-07-18 00:22:30 +0300389static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
390{
391 struct tx_complete_msg_v1 *msg_v1;
392 struct wmi_tx_complete_event *evt;
393 int index;
394 u16 size;
395
396 evt = (struct wmi_tx_complete_event *) datap;
397
398 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
399 evt->num_msg, evt->msg_len, evt->msg_type);
400
401 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
402 return 0;
403
404 for (index = 0; index < evt->num_msg; index++) {
405 size = sizeof(struct wmi_tx_complete_event) +
406 (index * sizeof(struct tx_complete_msg_v1));
407 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
408
409 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
410 msg_v1->status, msg_v1->pkt_id,
411 msg_v1->rate_idx, msg_v1->ack_failures);
412 }
413
414 return 0;
415}
416
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300417static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
418 int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300419{
420 struct wmi_remain_on_chnl_event *ev;
421 u32 freq;
422 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300423 struct ieee80211_channel *chan;
424 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300425
426 if (len < sizeof(*ev))
427 return -EINVAL;
428
429 ev = (struct wmi_remain_on_chnl_event *) datap;
430 freq = le32_to_cpu(ev->freq);
431 dur = le32_to_cpu(ev->duration);
432 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
433 freq, dur);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530434 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300435 if (!chan) {
436 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
437 "(freq=%u)\n", freq);
438 return -EINVAL;
439 }
440 cfg80211_ready_on_channel(ar->net_dev, 1, chan, NL80211_CHAN_NO_HT,
441 dur, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300442
443 return 0;
444}
445
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300446static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
447 u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300448{
449 struct wmi_cancel_remain_on_chnl_event *ev;
450 u32 freq;
451 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300452 struct ieee80211_channel *chan;
453 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300454
455 if (len < sizeof(*ev))
456 return -EINVAL;
457
458 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
459 freq = le32_to_cpu(ev->freq);
460 dur = le32_to_cpu(ev->duration);
461 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
462 "status=%u\n", freq, dur, ev->status);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530463 chan = ieee80211_get_channel(ar->wiphy, freq);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300464 if (!chan) {
465 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
466 "channel (freq=%u)\n", freq);
467 return -EINVAL;
468 }
469 cfg80211_remain_on_channel_expired(ar->net_dev, 1, chan,
470 NL80211_CHAN_NO_HT, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300471
472 return 0;
473}
474
Jouni Malinena0df5db2011-08-30 21:58:02 +0300475static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300476{
477 struct wmi_tx_status_event *ev;
478 u32 id;
Jouni Malinena0df5db2011-08-30 21:58:02 +0300479 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300480
481 if (len < sizeof(*ev))
482 return -EINVAL;
483
484 ev = (struct wmi_tx_status_event *) datap;
485 id = le32_to_cpu(ev->id);
486 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
487 id, ev->ack_status);
Jouni Malinena0df5db2011-08-30 21:58:02 +0300488 if (wmi->last_mgmt_tx_frame) {
489 cfg80211_mgmt_tx_status(ar->net_dev, id,
490 wmi->last_mgmt_tx_frame,
491 wmi->last_mgmt_tx_frame_len,
492 !!ev->ack_status, GFP_ATOMIC);
493 kfree(wmi->last_mgmt_tx_frame);
494 wmi->last_mgmt_tx_frame = NULL;
495 wmi->last_mgmt_tx_frame_len = 0;
496 }
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300497
498 return 0;
499}
500
Jouni Malinenae32c302011-08-30 21:58:01 +0300501static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300502{
503 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300504 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300505 u16 dlen;
Jouni Malinenae32c302011-08-30 21:58:01 +0300506 struct ath6kl *ar = wmi->parent_dev;
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530507 /* TODO: Findout vif */
508 struct ath6kl_vif *vif = ar->vif;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300509
510 if (len < sizeof(*ev))
511 return -EINVAL;
512
513 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300514 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300515 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300516 if (datap + len < ev->data + dlen) {
517 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
518 "len=%d dlen=%u\n", len, dlen);
519 return -EINVAL;
520 }
521 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
522 "probe_req_report=%d\n",
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530523 dlen, freq, vif->probe_req_report);
Jouni Malinenae32c302011-08-30 21:58:01 +0300524
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530525 if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
Jouni Malinenae32c302011-08-30 21:58:01 +0300526 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300527
528 return 0;
529}
530
531static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
532{
533 struct wmi_p2p_capabilities_event *ev;
534 u16 dlen;
535
536 if (len < sizeof(*ev))
537 return -EINVAL;
538
539 ev = (struct wmi_p2p_capabilities_event *) datap;
540 dlen = le16_to_cpu(ev->len);
541 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
542
543 return 0;
544}
545
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300546static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300547{
548 struct wmi_rx_action_event *ev;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300549 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300550 u16 dlen;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300551 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300552
553 if (len < sizeof(*ev))
554 return -EINVAL;
555
556 ev = (struct wmi_rx_action_event *) datap;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300557 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300558 dlen = le16_to_cpu(ev->len);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300559 if (datap + len < ev->data + dlen) {
560 ath6kl_err("invalid wmi_rx_action_event: "
561 "len=%d dlen=%u\n", len, dlen);
562 return -EINVAL;
563 }
564 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
565 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300566
567 return 0;
568}
569
570static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
571{
572 struct wmi_p2p_info_event *ev;
573 u32 flags;
574 u16 dlen;
575
576 if (len < sizeof(*ev))
577 return -EINVAL;
578
579 ev = (struct wmi_p2p_info_event *) datap;
580 flags = le32_to_cpu(ev->info_req_flags);
581 dlen = le16_to_cpu(ev->len);
582 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
583
584 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
585 struct wmi_p2p_capabilities *cap;
586 if (dlen < sizeof(*cap))
587 return -EINVAL;
588 cap = (struct wmi_p2p_capabilities *) ev->data;
589 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
590 cap->go_power_save);
591 }
592
593 if (flags & P2P_FLAG_MACADDR_REQ) {
594 struct wmi_p2p_macaddr *mac;
595 if (dlen < sizeof(*mac))
596 return -EINVAL;
597 mac = (struct wmi_p2p_macaddr *) ev->data;
598 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
599 mac->mac_addr);
600 }
601
602 if (flags & P2P_FLAG_HMODEL_REQ) {
603 struct wmi_p2p_hmodel *mod;
604 if (dlen < sizeof(*mod))
605 return -EINVAL;
606 mod = (struct wmi_p2p_hmodel *) ev->data;
607 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
608 mod->p2p_model,
609 mod->p2p_model ? "host" : "firmware");
610 }
611 return 0;
612}
613
Kalle Valobdcd8172011-07-18 00:22:30 +0300614static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
615{
616 struct sk_buff *skb;
617
618 skb = ath6kl_buf_alloc(size);
619 if (!skb)
620 return NULL;
621
622 skb_put(skb, size);
623 if (size)
624 memset(skb->data, 0, size);
625
626 return skb;
627}
628
629/* Send a "simple" wmi command -- one with no arguments */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530630static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
631 enum wmi_cmd_id cmd_id)
Kalle Valobdcd8172011-07-18 00:22:30 +0300632{
633 struct sk_buff *skb;
634 int ret;
635
636 skb = ath6kl_wmi_get_new_buf(0);
637 if (!skb)
638 return -ENOMEM;
639
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530640 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +0300641
642 return ret;
643}
644
645static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
646{
647 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
648
649 if (len < sizeof(struct wmi_ready_event_2))
650 return -EINVAL;
651
Kalle Valobdcd8172011-07-18 00:22:30 +0300652 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
653 le32_to_cpu(ev->sw_version),
654 le32_to_cpu(ev->abi_version));
655
656 return 0;
657}
658
Vivek Natarajane5090442011-08-31 15:02:19 +0530659/*
660 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
661 * at which the station has to roam can be passed with
662 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
663 * in dBm.
664 */
665int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
666{
667 struct sk_buff *skb;
668 struct roam_ctrl_cmd *cmd;
669
670 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
671 if (!skb)
672 return -ENOMEM;
673
674 cmd = (struct roam_ctrl_cmd *) skb->data;
675
676 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
677 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
678 DEF_SCAN_FOR_ROAM_INTVL);
679 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
680 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
681 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
682
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530683 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
684 NO_SYNC_WMIFLAG);
Vivek Natarajane5090442011-08-31 15:02:19 +0530685
686 return 0;
687}
688
Jouni Malinen12618752011-10-11 17:31:55 +0300689int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
690{
691 struct sk_buff *skb;
692 struct roam_ctrl_cmd *cmd;
693
694 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
695 if (!skb)
696 return -ENOMEM;
697
698 cmd = (struct roam_ctrl_cmd *) skb->data;
699 memset(cmd, 0, sizeof(*cmd));
700
701 memcpy(cmd->info.bssid, bssid, ETH_ALEN);
702 cmd->roam_ctrl = WMI_FORCE_ROAM;
703
704 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530705 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300706 NO_SYNC_WMIFLAG);
707}
708
709int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
710{
711 struct sk_buff *skb;
712 struct roam_ctrl_cmd *cmd;
713
714 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
715 if (!skb)
716 return -ENOMEM;
717
718 cmd = (struct roam_ctrl_cmd *) skb->data;
719 memset(cmd, 0, sizeof(*cmd));
720
721 cmd->info.roam_mode = mode;
722 cmd->roam_ctrl = WMI_SET_ROAM_MODE;
723
724 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +0530725 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
Jouni Malinen12618752011-10-11 17:31:55 +0300726 NO_SYNC_WMIFLAG);
727}
728
Kalle Valobdcd8172011-07-18 00:22:30 +0300729static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
730{
731 struct wmi_connect_event *ev;
732 u8 *pie, *peie;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300733 struct ath6kl *ar = wmi->parent_dev;
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530734 /* TODO: Findout vif */
735 struct ath6kl_vif *vif = ar->vif;
Kalle Valobdcd8172011-07-18 00:22:30 +0300736
737 if (len < sizeof(struct wmi_connect_event))
738 return -EINVAL;
739
740 ev = (struct wmi_connect_event *) datap;
741
Vasanthakumar Thiagarajanf5938f22011-10-25 19:34:03 +0530742 if (vif->nw_type == AP_NETWORK) {
Jouni Malinen572e27c2011-09-05 17:38:45 +0300743 /* AP mode start/STA connected event */
744 struct net_device *dev = ar->net_dev;
745 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
746 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
747 "(AP started)\n",
748 __func__, le16_to_cpu(ev->u.ap_bss.ch),
749 ev->u.ap_bss.bssid);
750 ath6kl_connect_ap_mode_bss(
751 ar, le16_to_cpu(ev->u.ap_bss.ch));
752 } else {
753 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
754 "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
755 "(STA connected)\n",
756 __func__, ev->u.ap_sta.aid,
757 ev->u.ap_sta.mac_addr,
758 ev->u.ap_sta.auth,
759 ev->u.ap_sta.keymgmt,
760 le16_to_cpu(ev->u.ap_sta.cipher),
761 ev->u.ap_sta.apsd_info);
762 ath6kl_connect_ap_mode_sta(
763 ar, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
764 ev->u.ap_sta.keymgmt,
765 le16_to_cpu(ev->u.ap_sta.cipher),
766 ev->u.ap_sta.auth, ev->assoc_req_len,
767 ev->assoc_info + ev->beacon_ie_len);
768 }
769 return 0;
770 }
771
772 /* STA/IBSS mode connection event */
773
Kalle Valob9b6ee62011-09-27 14:31:21 +0300774 ath6kl_dbg(ATH6KL_DBG_WMI,
775 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
776 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
777 le16_to_cpu(ev->u.sta.listen_intvl),
778 le16_to_cpu(ev->u.sta.beacon_intvl),
779 le32_to_cpu(ev->u.sta.nw_type));
Kalle Valobdcd8172011-07-18 00:22:30 +0300780
Kalle Valobdcd8172011-07-18 00:22:30 +0300781 /* Start of assoc rsp IEs */
782 pie = ev->assoc_info + ev->beacon_ie_len +
783 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
784
785 /* End of assoc rsp IEs */
786 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
787 ev->assoc_resp_len;
788
789 while (pie < peie) {
790 switch (*pie) {
791 case WLAN_EID_VENDOR_SPECIFIC:
792 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
793 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
794 /* WMM OUT (00:50:F2) */
795 if (pie[1] > 5
796 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
797 wmi->is_wmm_enabled = true;
798 }
799 break;
800 }
801
802 if (wmi->is_wmm_enabled)
803 break;
804
805 pie += pie[1] + 2;
806 }
807
Jouni Malinen572e27c2011-09-05 17:38:45 +0300808 ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->u.sta.ch),
809 ev->u.sta.bssid,
810 le16_to_cpu(ev->u.sta.listen_intvl),
811 le16_to_cpu(ev->u.sta.beacon_intvl),
812 le32_to_cpu(ev->u.sta.nw_type),
Kalle Valobdcd8172011-07-18 00:22:30 +0300813 ev->beacon_ie_len, ev->assoc_req_len,
814 ev->assoc_resp_len, ev->assoc_info);
815
816 return 0;
817}
818
Vivek Natarajan06033762011-09-06 13:01:36 +0530819static struct country_code_to_enum_rd *
820ath6kl_regd_find_country(u16 countryCode)
821{
822 int i;
823
824 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
825 if (allCountries[i].countryCode == countryCode)
826 return &allCountries[i];
827 }
828
829 return NULL;
830}
831
832static struct reg_dmn_pair_mapping *
833ath6kl_get_regpair(u16 regdmn)
834{
835 int i;
836
837 if (regdmn == NO_ENUMRD)
838 return NULL;
839
840 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
841 if (regDomainPairs[i].regDmnEnum == regdmn)
842 return &regDomainPairs[i];
843 }
844
845 return NULL;
846}
847
848static struct country_code_to_enum_rd *
849ath6kl_regd_find_country_by_rd(u16 regdmn)
850{
851 int i;
852
853 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
854 if (allCountries[i].regDmnEnum == regdmn)
855 return &allCountries[i];
856 }
857
858 return NULL;
859}
860
861static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
862{
863
864 struct ath6kl_wmi_regdomain *ev;
865 struct country_code_to_enum_rd *country = NULL;
866 struct reg_dmn_pair_mapping *regpair = NULL;
867 char alpha2[2];
868 u32 reg_code;
869
870 ev = (struct ath6kl_wmi_regdomain *) datap;
871 reg_code = le32_to_cpu(ev->reg_code);
872
873 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
874 country = ath6kl_regd_find_country((u16) reg_code);
875 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
876
877 regpair = ath6kl_get_regpair((u16) reg_code);
878 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
Kalle Valob9b6ee62011-09-27 14:31:21 +0300879 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
Vivek Natarajan06033762011-09-06 13:01:36 +0530880 regpair->regDmnEnum);
881 }
882
883 if (country) {
884 alpha2[0] = country->isoName[0];
885 alpha2[1] = country->isoName[1];
886
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530887 regulatory_hint(wmi->parent_dev->wiphy, alpha2);
Vivek Natarajan06033762011-09-06 13:01:36 +0530888
Kalle Valob9b6ee62011-09-27 14:31:21 +0300889 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
Vivek Natarajan06033762011-09-06 13:01:36 +0530890 alpha2[0], alpha2[1]);
891 }
892}
893
Kalle Valobdcd8172011-07-18 00:22:30 +0300894static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
895{
896 struct wmi_disconnect_event *ev;
897 wmi->traffic_class = 100;
898
899 if (len < sizeof(struct wmi_disconnect_event))
900 return -EINVAL;
901
902 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300903
Kalle Valob9b6ee62011-09-27 14:31:21 +0300904 ath6kl_dbg(ATH6KL_DBG_WMI,
905 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
906 le16_to_cpu(ev->proto_reason_status), ev->bssid,
907 ev->disconn_reason, ev->assoc_resp_len);
908
Kalle Valobdcd8172011-07-18 00:22:30 +0300909 wmi->is_wmm_enabled = false;
Kalle Valobdcd8172011-07-18 00:22:30 +0300910
911 ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
912 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
913 le16_to_cpu(ev->proto_reason_status));
914
915 return 0;
916}
917
918static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
919{
920 struct wmi_peer_node_event *ev;
921
922 if (len < sizeof(struct wmi_peer_node_event))
923 return -EINVAL;
924
925 ev = (struct wmi_peer_node_event *) datap;
926
927 if (ev->event_code == PEER_NODE_JOIN_EVENT)
928 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
929 ev->peer_mac_addr);
930 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
931 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
932 ev->peer_mac_addr);
933
934 return 0;
935}
936
937static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
938{
939 struct wmi_tkip_micerr_event *ev;
940
941 if (len < sizeof(struct wmi_tkip_micerr_event))
942 return -EINVAL;
943
944 ev = (struct wmi_tkip_micerr_event *) datap;
945
946 ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
947
948 return 0;
949}
950
Kalle Valobdcd8172011-07-18 00:22:30 +0300951static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
952{
Jouni Malinen82e14f52011-09-19 19:15:05 +0300953 struct wmi_bss_info_hdr2 *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300954 u8 *buf;
955 struct ieee80211_channel *channel;
956 struct ath6kl *ar = wmi->parent_dev;
957 struct ieee80211_mgmt *mgmt;
958 struct cfg80211_bss *bss;
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530959 /*TODO: Findout vif properly */
960 struct ath6kl_vif *vif = ar->vif;
Kalle Valobdcd8172011-07-18 00:22:30 +0300961
Jouni Malinen82e14f52011-09-19 19:15:05 +0300962 if (len <= sizeof(struct wmi_bss_info_hdr2))
Kalle Valobdcd8172011-07-18 00:22:30 +0300963 return -EINVAL;
964
Jouni Malinen82e14f52011-09-19 19:15:05 +0300965 bih = (struct wmi_bss_info_hdr2 *) datap;
966 buf = datap + sizeof(struct wmi_bss_info_hdr2);
967 len -= sizeof(struct wmi_bss_info_hdr2);
Kalle Valobdcd8172011-07-18 00:22:30 +0300968
969 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300970 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
971 "frame_type=%d\n",
Jouni Malinen82e14f52011-09-19 19:15:05 +0300972 bih->ch, bih->snr, bih->snr - 95, bih->bssid,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300973 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +0300974
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300975 if (bih->frame_type != BEACON_FTYPE &&
976 bih->frame_type != PROBERESP_FTYPE)
977 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +0300978
Jouni Malinen551185c2011-09-19 19:15:06 +0300979 if (bih->frame_type == BEACON_FTYPE &&
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530980 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
981 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
Jouni Malinen551185c2011-09-19 19:15:06 +0300982 ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0);
983 }
984
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +0530985 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300986 if (channel == NULL)
987 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300988
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300989 if (len < 8 + 2 + 2)
990 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300991
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530992 if (bih->frame_type == BEACON_FTYPE && test_bit(CONNECTED, &vif->flags)
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530993 && memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
Jouni Malinen32c10872011-09-19 19:15:07 +0300994 const u8 *tim;
995 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
996 len - 8 - 2 - 2);
997 if (tim && tim[1] >= 2) {
Vasanthakumar Thiagarajancf5333d2011-10-25 19:34:10 +0530998 vif->assoc_bss_dtim_period = tim[3];
Vasanthakumar Thiagarajan59c98442011-10-25 19:34:01 +0530999 set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
Jouni Malinen32c10872011-09-19 19:15:07 +03001000 }
1001 }
1002
Kalle Valobdcd8172011-07-18 00:22:30 +03001003 /*
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001004 * In theory, use of cfg80211_inform_bss() would be more natural here
1005 * since we do not have the full frame. However, at least for now,
1006 * cfg80211 can only distinguish Beacon and Probe Response frames from
1007 * each other when using cfg80211_inform_bss_frame(), so let's build a
1008 * fake IEEE 802.11 header to be able to take benefit of this.
Kalle Valobdcd8172011-07-18 00:22:30 +03001009 */
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001010 mgmt = kmalloc(24 + len, GFP_ATOMIC);
1011 if (mgmt == NULL)
1012 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001013
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001014 if (bih->frame_type == BEACON_FTYPE) {
1015 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1016 IEEE80211_STYPE_BEACON);
1017 memset(mgmt->da, 0xff, ETH_ALEN);
1018 } else {
1019 struct net_device *dev = ar->net_dev;
Kalle Valobdcd8172011-07-18 00:22:30 +03001020
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001021 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1022 IEEE80211_STYPE_PROBE_RESP);
1023 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +03001024 }
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001025 mgmt->duration = cpu_to_le16(0);
1026 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
1027 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
1028 mgmt->seq_ctrl = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03001029
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001030 memcpy(&mgmt->u.beacon, buf, len);
1031
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301032 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt,
Jouni Malinen82e14f52011-09-19 19:15:05 +03001033 24 + len, (bih->snr - 95) * 100,
1034 GFP_ATOMIC);
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001035 kfree(mgmt);
1036 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +03001037 return -ENOMEM;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +03001038 cfg80211_put_bss(bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001039
1040 return 0;
1041}
1042
Kalle Valobdcd8172011-07-18 00:22:30 +03001043/* Inactivity timeout of a fatpipe(pstream) at the target */
1044static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1045 int len)
1046{
1047 struct wmi_pstream_timeout_event *ev;
1048
1049 if (len < sizeof(struct wmi_pstream_timeout_event))
1050 return -EINVAL;
1051
1052 ev = (struct wmi_pstream_timeout_event *) datap;
1053
1054 /*
1055 * When the pstream (fat pipe == AC) timesout, it means there were
1056 * no thinStreams within this pstream & it got implicitly created
1057 * due to data flow on this AC. We start the inactivity timer only
1058 * for implicitly created pstream. Just reset the host state.
1059 */
1060 spin_lock_bh(&wmi->lock);
1061 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1062 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1063 spin_unlock_bh(&wmi->lock);
1064
1065 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1066 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1067
1068 return 0;
1069}
1070
1071static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1072{
1073 struct wmi_bit_rate_reply *reply;
1074 s32 rate;
1075 u32 sgi, index;
1076
1077 if (len < sizeof(struct wmi_bit_rate_reply))
1078 return -EINVAL;
1079
1080 reply = (struct wmi_bit_rate_reply *) datap;
1081
1082 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1083
1084 if (reply->rate_index == (s8) RATE_AUTO) {
1085 rate = RATE_AUTO;
1086 } else {
1087 index = reply->rate_index & 0x7f;
1088 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1089 rate = wmi_rate_tbl[index][sgi];
1090 }
1091
1092 ath6kl_wakeup_event(wmi->parent_dev);
1093
1094 return 0;
1095}
1096
Kalle Valo003353b0d2011-09-01 10:14:21 +03001097static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
1098{
1099 ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
1100
1101 return 0;
1102}
1103
Kalle Valobdcd8172011-07-18 00:22:30 +03001104static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1105{
1106 if (len < sizeof(struct wmi_fix_rates_reply))
1107 return -EINVAL;
1108
1109 ath6kl_wakeup_event(wmi->parent_dev);
1110
1111 return 0;
1112}
1113
1114static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1115{
1116 if (len < sizeof(struct wmi_channel_list_reply))
1117 return -EINVAL;
1118
1119 ath6kl_wakeup_event(wmi->parent_dev);
1120
1121 return 0;
1122}
1123
1124static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1125{
1126 struct wmi_tx_pwr_reply *reply;
1127
1128 if (len < sizeof(struct wmi_tx_pwr_reply))
1129 return -EINVAL;
1130
1131 reply = (struct wmi_tx_pwr_reply *) datap;
1132 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1133
1134 return 0;
1135}
1136
1137static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1138{
1139 if (len < sizeof(struct wmi_get_keepalive_cmd))
1140 return -EINVAL;
1141
1142 ath6kl_wakeup_event(wmi->parent_dev);
1143
1144 return 0;
1145}
1146
1147static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
1148{
1149 struct wmi_scan_complete_event *ev;
1150
1151 ev = (struct wmi_scan_complete_event *) datap;
1152
Kalle Valobdcd8172011-07-18 00:22:30 +03001153 ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
1154 wmi->is_probe_ssid = false;
1155
1156 return 0;
1157}
1158
Jouni Malinen86512132011-09-21 16:57:29 +03001159static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
1160 int len)
1161{
1162 struct wmi_neighbor_report_event *ev;
1163 u8 i;
1164
1165 if (len < sizeof(*ev))
1166 return -EINVAL;
1167 ev = (struct wmi_neighbor_report_event *) datap;
1168 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info)
1169 > len) {
1170 ath6kl_dbg(ATH6KL_DBG_WMI, "truncated neighbor event "
1171 "(num=%d len=%d)\n", ev->num_neighbors, len);
1172 return -EINVAL;
1173 }
1174 for (i = 0; i < ev->num_neighbors; i++) {
1175 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
1176 i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
1177 ev->neighbor[i].bss_flags);
1178 cfg80211_pmksa_candidate_notify(wmi->parent_dev->net_dev, i,
1179 ev->neighbor[i].bssid,
1180 !!(ev->neighbor[i].bss_flags &
1181 WMI_PREAUTH_CAPABLE_BSS),
1182 GFP_ATOMIC);
1183 }
1184
1185 return 0;
1186}
1187
Kalle Valobdcd8172011-07-18 00:22:30 +03001188/*
1189 * Target is reporting a programming error. This is for
1190 * developer aid only. Target only checks a few common violations
1191 * and it is responsibility of host to do all error checking.
1192 * Behavior of target after wmi error event is undefined.
1193 * A reset is recommended.
1194 */
1195static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1196{
1197 const char *type = "unknown error";
1198 struct wmi_cmd_error_event *ev;
1199 ev = (struct wmi_cmd_error_event *) datap;
1200
1201 switch (ev->err_code) {
1202 case INVALID_PARAM:
1203 type = "invalid parameter";
1204 break;
1205 case ILLEGAL_STATE:
1206 type = "invalid state";
1207 break;
1208 case INTERNAL_ERROR:
1209 type = "internal error";
1210 break;
1211 }
1212
1213 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1214 ev->cmd_id, type);
1215
1216 return 0;
1217}
1218
1219static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
1220{
1221 ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
1222
1223 return 0;
1224}
1225
1226static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1227 struct sq_threshold_params *sq_thresh,
1228 u32 size)
1229{
1230 u32 index;
1231 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1232
1233 /* The list is already in sorted order. Get the next lower value */
1234 for (index = 0; index < size; index++) {
1235 if (rssi < sq_thresh->upper_threshold[index]) {
1236 threshold = (u8) sq_thresh->upper_threshold[index];
1237 break;
1238 }
1239 }
1240
1241 return threshold;
1242}
1243
1244static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1245 struct sq_threshold_params *sq_thresh,
1246 u32 size)
1247{
1248 u32 index;
1249 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1250
1251 /* The list is already in sorted order. Get the next lower value */
1252 for (index = 0; index < size; index++) {
1253 if (rssi > sq_thresh->lower_threshold[index]) {
1254 threshold = (u8) sq_thresh->lower_threshold[index];
1255 break;
1256 }
1257 }
1258
1259 return threshold;
1260}
1261
1262static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1263 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1264{
1265 struct sk_buff *skb;
1266 struct wmi_rssi_threshold_params_cmd *cmd;
1267
1268 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1269 if (!skb)
1270 return -ENOMEM;
1271
1272 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1273 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1274
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301275 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001276 NO_SYNC_WMIFLAG);
1277}
1278
1279static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1280 int len)
1281{
1282 struct wmi_rssi_threshold_event *reply;
1283 struct wmi_rssi_threshold_params_cmd cmd;
1284 struct sq_threshold_params *sq_thresh;
1285 enum wmi_rssi_threshold_val new_threshold;
1286 u8 upper_rssi_threshold, lower_rssi_threshold;
1287 s16 rssi;
1288 int ret;
1289
1290 if (len < sizeof(struct wmi_rssi_threshold_event))
1291 return -EINVAL;
1292
1293 reply = (struct wmi_rssi_threshold_event *) datap;
1294 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1295 rssi = a_sle16_to_cpu(reply->rssi);
1296
1297 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1298
1299 /*
1300 * Identify the threshold breached and communicate that to the app.
1301 * After that install a new set of thresholds based on the signal
1302 * quality reported by the target
1303 */
1304 if (new_threshold) {
1305 /* Upper threshold breached */
1306 if (rssi < sq_thresh->upper_threshold[0]) {
1307 ath6kl_dbg(ATH6KL_DBG_WMI,
1308 "spurious upper rssi threshold event: %d\n",
1309 rssi);
1310 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1311 (rssi >= sq_thresh->upper_threshold[0])) {
1312 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1313 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1314 (rssi >= sq_thresh->upper_threshold[1])) {
1315 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1316 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1317 (rssi >= sq_thresh->upper_threshold[2])) {
1318 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1319 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1320 (rssi >= sq_thresh->upper_threshold[3])) {
1321 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1322 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1323 (rssi >= sq_thresh->upper_threshold[4])) {
1324 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1325 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1326 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1327 }
1328 } else {
1329 /* Lower threshold breached */
1330 if (rssi > sq_thresh->lower_threshold[0]) {
1331 ath6kl_dbg(ATH6KL_DBG_WMI,
1332 "spurious lower rssi threshold event: %d %d\n",
1333 rssi, sq_thresh->lower_threshold[0]);
1334 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1335 (rssi <= sq_thresh->lower_threshold[0])) {
1336 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1337 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1338 (rssi <= sq_thresh->lower_threshold[1])) {
1339 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1340 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1341 (rssi <= sq_thresh->lower_threshold[2])) {
1342 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1343 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1344 (rssi <= sq_thresh->lower_threshold[3])) {
1345 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1346 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1347 (rssi <= sq_thresh->lower_threshold[4])) {
1348 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1349 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1350 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1351 }
1352 }
1353
1354 /* Calculate and install the next set of thresholds */
1355 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1356 sq_thresh->lower_threshold_valid_count);
1357 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1358 sq_thresh->upper_threshold_valid_count);
1359
1360 /* Issue a wmi command to install the thresholds */
1361 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1362 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1363 cmd.weight = sq_thresh->weight;
1364 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1365
1366 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1367 if (ret) {
1368 ath6kl_err("unable to configure rssi thresholds\n");
1369 return -EIO;
1370 }
1371
1372 return 0;
1373}
1374
1375static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
1376{
1377 struct wmi_cac_event *reply;
1378 struct ieee80211_tspec_ie *ts;
1379 u16 active_tsids, tsinfo;
1380 u8 tsid, index;
1381 u8 ts_id;
1382
1383 if (len < sizeof(struct wmi_cac_event))
1384 return -EINVAL;
1385
1386 reply = (struct wmi_cac_event *) datap;
1387
1388 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1389 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1390
1391 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1392 tsinfo = le16_to_cpu(ts->tsinfo);
1393 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1394 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1395
1396 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
1397 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1398 /*
1399 * Following assumes that there is only one outstanding
1400 * ADDTS request when this event is received
1401 */
1402 spin_lock_bh(&wmi->lock);
1403 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1404 spin_unlock_bh(&wmi->lock);
1405
1406 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1407 if ((active_tsids >> index) & 1)
1408 break;
1409 }
1410 if (index < (sizeof(active_tsids) * 8))
1411 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
1412 }
1413
1414 /*
1415 * Clear active tsids and Add missing handling
1416 * for delete qos stream from AP
1417 */
1418 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1419
1420 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1421 tsinfo = le16_to_cpu(ts->tsinfo);
1422 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1423 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1424
1425 spin_lock_bh(&wmi->lock);
1426 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1427 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1428 spin_unlock_bh(&wmi->lock);
1429
1430 /* Indicate stream inactivity to driver layer only if all tsids
1431 * within this AC are deleted.
1432 */
1433 if (!active_tsids) {
1434 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1435 false);
1436 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1437 }
1438 }
1439
1440 return 0;
1441}
1442
1443static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1444 struct wmi_snr_threshold_params_cmd *snr_cmd)
1445{
1446 struct sk_buff *skb;
1447 struct wmi_snr_threshold_params_cmd *cmd;
1448
1449 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1450 if (!skb)
1451 return -ENOMEM;
1452
1453 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1454 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1455
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301456 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001457 NO_SYNC_WMIFLAG);
1458}
1459
1460static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1461 int len)
1462{
1463 struct wmi_snr_threshold_event *reply;
1464 struct sq_threshold_params *sq_thresh;
1465 struct wmi_snr_threshold_params_cmd cmd;
1466 enum wmi_snr_threshold_val new_threshold;
1467 u8 upper_snr_threshold, lower_snr_threshold;
1468 s16 snr;
1469 int ret;
1470
1471 if (len < sizeof(struct wmi_snr_threshold_event))
1472 return -EINVAL;
1473
1474 reply = (struct wmi_snr_threshold_event *) datap;
1475
1476 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1477 snr = reply->snr;
1478
1479 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1480
1481 /*
1482 * Identify the threshold breached and communicate that to the app.
1483 * After that install a new set of thresholds based on the signal
1484 * quality reported by the target.
1485 */
1486 if (new_threshold) {
1487 /* Upper threshold breached */
1488 if (snr < sq_thresh->upper_threshold[0]) {
1489 ath6kl_dbg(ATH6KL_DBG_WMI,
1490 "spurious upper snr threshold event: %d\n",
1491 snr);
1492 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1493 (snr >= sq_thresh->upper_threshold[0])) {
1494 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1495 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1496 (snr >= sq_thresh->upper_threshold[1])) {
1497 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1498 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1499 (snr >= sq_thresh->upper_threshold[2])) {
1500 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1501 } else if (snr >= sq_thresh->upper_threshold[3]) {
1502 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1503 }
1504 } else {
1505 /* Lower threshold breached */
1506 if (snr > sq_thresh->lower_threshold[0]) {
1507 ath6kl_dbg(ATH6KL_DBG_WMI,
1508 "spurious lower snr threshold event: %d\n",
1509 sq_thresh->lower_threshold[0]);
1510 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1511 (snr <= sq_thresh->lower_threshold[0])) {
1512 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1513 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1514 (snr <= sq_thresh->lower_threshold[1])) {
1515 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1516 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1517 (snr <= sq_thresh->lower_threshold[2])) {
1518 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1519 } else if (snr <= sq_thresh->lower_threshold[3]) {
1520 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1521 }
1522 }
1523
1524 /* Calculate and install the next set of thresholds */
1525 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1526 sq_thresh->lower_threshold_valid_count);
1527 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1528 sq_thresh->upper_threshold_valid_count);
1529
1530 /* Issue a wmi command to install the thresholds */
1531 cmd.thresh_above1_val = upper_snr_threshold;
1532 cmd.thresh_below1_val = lower_snr_threshold;
1533 cmd.weight = sq_thresh->weight;
1534 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1535
1536 ath6kl_dbg(ATH6KL_DBG_WMI,
1537 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1538 snr, new_threshold,
1539 lower_snr_threshold, upper_snr_threshold);
1540
1541 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1542 if (ret) {
1543 ath6kl_err("unable to configure snr threshold\n");
1544 return -EIO;
1545 }
1546
1547 return 0;
1548}
1549
1550static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1551{
1552 u16 ap_info_entry_size;
1553 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1554 struct wmi_ap_info_v1 *ap_info_v1;
1555 u8 index;
1556
1557 if (len < sizeof(struct wmi_aplist_event) ||
1558 ev->ap_list_ver != APLIST_VER1)
1559 return -EINVAL;
1560
1561 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1562 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1563
1564 ath6kl_dbg(ATH6KL_DBG_WMI,
1565 "number of APs in aplist event: %d\n", ev->num_ap);
1566
1567 if (len < (int) (sizeof(struct wmi_aplist_event) +
1568 (ev->num_ap - 1) * ap_info_entry_size))
1569 return -EINVAL;
1570
1571 /* AP list version 1 contents */
1572 for (index = 0; index < ev->num_ap; index++) {
1573 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1574 index, ap_info_v1->bssid, ap_info_v1->channel);
1575 ap_info_v1++;
1576 }
1577
1578 return 0;
1579}
1580
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301581int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
Kalle Valobdcd8172011-07-18 00:22:30 +03001582 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1583{
1584 struct wmi_cmd_hdr *cmd_hdr;
1585 enum htc_endpoint_id ep_id = wmi->ep_id;
1586 int ret;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301587 u16 info1;
Kalle Valobdcd8172011-07-18 00:22:30 +03001588
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301589 if (WARN_ON(skb == NULL || (if_idx > (MAX_NUM_VIF - 1))))
Kalle Valobdcd8172011-07-18 00:22:30 +03001590 return -EINVAL;
1591
Kalle Valob9b6ee62011-09-27 14:31:21 +03001592 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
1593 cmd_id, skb->len, sync_flag);
1594 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
1595 skb->data, skb->len);
1596
Kalle Valobdcd8172011-07-18 00:22:30 +03001597 if (sync_flag >= END_WMIFLAG) {
1598 dev_kfree_skb(skb);
1599 return -EINVAL;
1600 }
1601
1602 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1603 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1604 /*
1605 * Make sure all data currently queued is transmitted before
1606 * the cmd execution. Establish a new sync point.
1607 */
1608 ath6kl_wmi_sync_point(wmi);
1609 }
1610
1611 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1612
1613 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1614 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301615 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
1616 cmd_hdr->info1 = cpu_to_le16(info1);
Kalle Valobdcd8172011-07-18 00:22:30 +03001617
1618 /* Only for OPT_TX_CMD, use BE endpoint. */
1619 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1620 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1621 false, false, 0, NULL);
1622 if (ret) {
1623 dev_kfree_skb(skb);
1624 return ret;
1625 }
1626 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1627 }
1628
1629 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1630
1631 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1632 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1633 /*
1634 * Make sure all new data queued waits for the command to
1635 * execute. Establish a new sync point.
1636 */
1637 ath6kl_wmi_sync_point(wmi);
1638 }
1639
1640 return 0;
1641}
1642
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301643int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
1644 enum network_type nw_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001645 enum dot11_auth_mode dot11_auth_mode,
1646 enum auth_mode auth_mode,
1647 enum crypto_type pairwise_crypto,
1648 u8 pairwise_crypto_len,
1649 enum crypto_type group_crypto,
1650 u8 group_crypto_len, int ssid_len, u8 *ssid,
1651 u8 *bssid, u16 channel, u32 ctrl_flags)
1652{
1653 struct sk_buff *skb;
1654 struct wmi_connect_cmd *cc;
1655 int ret;
1656
Kalle Valob9b6ee62011-09-27 14:31:21 +03001657 ath6kl_dbg(ATH6KL_DBG_WMI,
1658 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
1659 "type %d dot11_auth %d auth %d pairwise %d group %d\n",
1660 bssid, channel, ctrl_flags, ssid_len, nw_type,
1661 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
1662 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
1663
Kalle Valobdcd8172011-07-18 00:22:30 +03001664 wmi->traffic_class = 100;
1665
1666 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1667 return -EINVAL;
1668
1669 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1670 return -EINVAL;
1671
1672 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1673 if (!skb)
1674 return -ENOMEM;
1675
1676 cc = (struct wmi_connect_cmd *) skb->data;
1677
1678 if (ssid_len)
1679 memcpy(cc->ssid, ssid, ssid_len);
1680
1681 cc->ssid_len = ssid_len;
1682 cc->nw_type = nw_type;
1683 cc->dot11_auth_mode = dot11_auth_mode;
1684 cc->auth_mode = auth_mode;
1685 cc->prwise_crypto_type = pairwise_crypto;
1686 cc->prwise_crypto_len = pairwise_crypto_len;
1687 cc->grp_crypto_type = group_crypto;
1688 cc->grp_crypto_len = group_crypto_len;
1689 cc->ch = cpu_to_le16(channel);
1690 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1691
1692 if (bssid != NULL)
1693 memcpy(cc->bssid, bssid, ETH_ALEN);
1694
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301695 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
1696 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03001697
1698 return ret;
1699}
1700
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301701int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
1702 u16 channel)
Kalle Valobdcd8172011-07-18 00:22:30 +03001703{
1704 struct sk_buff *skb;
1705 struct wmi_reconnect_cmd *cc;
1706 int ret;
1707
Kalle Valob9b6ee62011-09-27 14:31:21 +03001708 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
1709 bssid, channel);
1710
Kalle Valobdcd8172011-07-18 00:22:30 +03001711 wmi->traffic_class = 100;
1712
1713 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1714 if (!skb)
1715 return -ENOMEM;
1716
1717 cc = (struct wmi_reconnect_cmd *) skb->data;
1718 cc->channel = cpu_to_le16(channel);
1719
1720 if (bssid != NULL)
1721 memcpy(cc->bssid, bssid, ETH_ALEN);
1722
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301723 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001724 NO_SYNC_WMIFLAG);
1725
1726 return ret;
1727}
1728
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301729int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03001730{
1731 int ret;
1732
Kalle Valob9b6ee62011-09-27 14:31:21 +03001733 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
1734
Kalle Valobdcd8172011-07-18 00:22:30 +03001735 wmi->traffic_class = 100;
1736
1737 /* Disconnect command does not need to do a SYNC before. */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301738 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03001739
1740 return ret;
1741}
1742
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301743int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
1744 enum wmi_scan_type scan_type,
Kalle Valobdcd8172011-07-18 00:22:30 +03001745 u32 force_fgscan, u32 is_legacy,
1746 u32 home_dwell_time, u32 force_scan_interval,
1747 s8 num_chan, u16 *ch_list)
1748{
1749 struct sk_buff *skb;
1750 struct wmi_start_scan_cmd *sc;
1751 s8 size;
Edward Lu1276c9e2011-08-30 21:58:00 +03001752 int i, ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03001753
1754 size = sizeof(struct wmi_start_scan_cmd);
1755
1756 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1757 return -EINVAL;
1758
1759 if (num_chan > WMI_MAX_CHANNELS)
1760 return -EINVAL;
1761
1762 if (num_chan)
1763 size += sizeof(u16) * (num_chan - 1);
1764
1765 skb = ath6kl_wmi_get_new_buf(size);
1766 if (!skb)
1767 return -ENOMEM;
1768
1769 sc = (struct wmi_start_scan_cmd *) skb->data;
1770 sc->scan_type = scan_type;
1771 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1772 sc->is_legacy = cpu_to_le32(is_legacy);
1773 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1774 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1775 sc->num_ch = num_chan;
1776
Edward Lu1276c9e2011-08-30 21:58:00 +03001777 for (i = 0; i < num_chan; i++)
1778 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001779
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301780 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001781 NO_SYNC_WMIFLAG);
1782
1783 return ret;
1784}
1785
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301786int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
1787 u16 fg_start_sec,
Kalle Valobdcd8172011-07-18 00:22:30 +03001788 u16 fg_end_sec, u16 bg_sec,
1789 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1790 u16 pas_chdw_msec, u8 short_scan_ratio,
1791 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1792 u16 maxact_scan_per_ssid)
1793{
1794 struct sk_buff *skb;
1795 struct wmi_scan_params_cmd *sc;
1796 int ret;
1797
1798 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1799 if (!skb)
1800 return -ENOMEM;
1801
1802 sc = (struct wmi_scan_params_cmd *) skb->data;
1803 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1804 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1805 sc->bg_period = cpu_to_le16(bg_sec);
1806 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1807 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1808 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1809 sc->short_scan_ratio = short_scan_ratio;
1810 sc->scan_ctrl_flags = scan_ctrl_flag;
1811 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1812 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1813
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301814 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001815 NO_SYNC_WMIFLAG);
1816 return ret;
1817}
1818
1819int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
1820{
1821 struct sk_buff *skb;
1822 struct wmi_bss_filter_cmd *cmd;
1823 int ret;
1824
1825 if (filter >= LAST_BSS_FILTER)
1826 return -EINVAL;
1827
1828 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1829 if (!skb)
1830 return -ENOMEM;
1831
1832 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1833 cmd->bss_filter = filter;
1834 cmd->ie_mask = cpu_to_le32(ie_mask);
1835
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301836 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_BSS_FILTER_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001837 NO_SYNC_WMIFLAG);
1838 return ret;
1839}
1840
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301841int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
Kalle Valobdcd8172011-07-18 00:22:30 +03001842 u8 ssid_len, u8 *ssid)
1843{
1844 struct sk_buff *skb;
1845 struct wmi_probed_ssid_cmd *cmd;
1846 int ret;
1847
1848 if (index > MAX_PROBED_SSID_INDEX)
1849 return -EINVAL;
1850
1851 if (ssid_len > sizeof(cmd->ssid))
1852 return -EINVAL;
1853
1854 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1855 return -EINVAL;
1856
1857 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1858 return -EINVAL;
1859
1860 if (flag & SPECIFIC_SSID_FLAG)
1861 wmi->is_probe_ssid = true;
1862
1863 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1864 if (!skb)
1865 return -ENOMEM;
1866
1867 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1868 cmd->entry_index = index;
1869 cmd->flag = flag;
1870 cmd->ssid_len = ssid_len;
1871 memcpy(cmd->ssid, ssid, ssid_len);
1872
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301873 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001874 NO_SYNC_WMIFLAG);
1875 return ret;
1876}
1877
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301878int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
1879 u16 listen_interval,
Kalle Valobdcd8172011-07-18 00:22:30 +03001880 u16 listen_beacons)
1881{
1882 struct sk_buff *skb;
1883 struct wmi_listen_int_cmd *cmd;
1884 int ret;
1885
1886 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1887 if (!skb)
1888 return -ENOMEM;
1889
1890 cmd = (struct wmi_listen_int_cmd *) skb->data;
1891 cmd->listen_intvl = cpu_to_le16(listen_interval);
1892 cmd->num_beacons = cpu_to_le16(listen_beacons);
1893
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301894 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001895 NO_SYNC_WMIFLAG);
1896 return ret;
1897}
1898
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301899int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
Kalle Valobdcd8172011-07-18 00:22:30 +03001900{
1901 struct sk_buff *skb;
1902 struct wmi_power_mode_cmd *cmd;
1903 int ret;
1904
1905 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1906 if (!skb)
1907 return -ENOMEM;
1908
1909 cmd = (struct wmi_power_mode_cmd *) skb->data;
1910 cmd->pwr_mode = pwr_mode;
1911 wmi->pwr_mode = pwr_mode;
1912
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301913 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001914 NO_SYNC_WMIFLAG);
1915 return ret;
1916}
1917
1918int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
1919 u16 ps_poll_num, u16 dtim_policy,
1920 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1921 u16 ps_fail_event_policy)
1922{
1923 struct sk_buff *skb;
1924 struct wmi_power_params_cmd *pm;
1925 int ret;
1926
1927 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1928 if (!skb)
1929 return -ENOMEM;
1930
1931 pm = (struct wmi_power_params_cmd *)skb->data;
1932 pm->idle_period = cpu_to_le16(idle_period);
1933 pm->pspoll_number = cpu_to_le16(ps_poll_num);
1934 pm->dtim_policy = cpu_to_le16(dtim_policy);
1935 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1936 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1937 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1938
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301939 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_POWER_PARAMS_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001940 NO_SYNC_WMIFLAG);
1941 return ret;
1942}
1943
1944int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
1945{
1946 struct sk_buff *skb;
1947 struct wmi_disc_timeout_cmd *cmd;
1948 int ret;
1949
1950 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1951 if (!skb)
1952 return -ENOMEM;
1953
1954 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
1955 cmd->discon_timeout = timeout;
1956
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301957 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_DISC_TIMEOUT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03001958 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301959
Jouni Malinenff0b0072011-10-11 17:31:56 +03001960 if (ret == 0)
1961 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301962
Kalle Valobdcd8172011-07-18 00:22:30 +03001963 return ret;
1964}
1965
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05301966int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
Kalle Valobdcd8172011-07-18 00:22:30 +03001967 enum crypto_type key_type,
1968 u8 key_usage, u8 key_len,
1969 u8 *key_rsc, u8 *key_material,
1970 u8 key_op_ctrl, u8 *mac_addr,
1971 enum wmi_sync_flag sync_flag)
1972{
1973 struct sk_buff *skb;
1974 struct wmi_add_cipher_key_cmd *cmd;
1975 int ret;
1976
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001977 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
1978 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
1979 key_index, key_type, key_usage, key_len, key_op_ctrl);
1980
Kalle Valobdcd8172011-07-18 00:22:30 +03001981 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
1982 (key_material == NULL))
1983 return -EINVAL;
1984
1985 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
1986 return -EINVAL;
1987
1988 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1989 if (!skb)
1990 return -ENOMEM;
1991
1992 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
1993 cmd->key_index = key_index;
1994 cmd->key_type = key_type;
1995 cmd->key_usage = key_usage;
1996 cmd->key_len = key_len;
1997 memcpy(cmd->key, key_material, key_len);
1998
1999 if (key_rsc != NULL)
2000 memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
2001
2002 cmd->key_op_ctrl = key_op_ctrl;
2003
2004 if (mac_addr)
2005 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
2006
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302007 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002008 sync_flag);
2009
2010 return ret;
2011}
2012
2013int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
2014{
2015 struct sk_buff *skb;
2016 struct wmi_add_krk_cmd *cmd;
2017 int ret;
2018
2019 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2020 if (!skb)
2021 return -ENOMEM;
2022
2023 cmd = (struct wmi_add_krk_cmd *) skb->data;
2024 memcpy(cmd->krk, krk, WMI_KRK_LEN);
2025
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302026 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_ADD_KRK_CMDID,
2027 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002028
2029 return ret;
2030}
2031
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302032int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
Kalle Valobdcd8172011-07-18 00:22:30 +03002033{
2034 struct sk_buff *skb;
2035 struct wmi_delete_cipher_key_cmd *cmd;
2036 int ret;
2037
2038 if (key_index > WMI_MAX_KEY_INDEX)
2039 return -EINVAL;
2040
2041 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2042 if (!skb)
2043 return -ENOMEM;
2044
2045 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2046 cmd->key_index = key_index;
2047
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302048 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002049 NO_SYNC_WMIFLAG);
2050
2051 return ret;
2052}
2053
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302054int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002055 const u8 *pmkid, bool set)
2056{
2057 struct sk_buff *skb;
2058 struct wmi_setpmkid_cmd *cmd;
2059 int ret;
2060
2061 if (bssid == NULL)
2062 return -EINVAL;
2063
2064 if (set && pmkid == NULL)
2065 return -EINVAL;
2066
2067 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2068 if (!skb)
2069 return -ENOMEM;
2070
2071 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2072 memcpy(cmd->bssid, bssid, ETH_ALEN);
2073 if (set) {
2074 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2075 cmd->enable = PMKID_ENABLE;
2076 } else {
2077 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2078 cmd->enable = PMKID_DISABLE;
2079 }
2080
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302081 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002082 NO_SYNC_WMIFLAG);
2083
2084 return ret;
2085}
2086
2087static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2088 enum htc_endpoint_id ep_id)
2089{
2090 struct wmi_data_hdr *data_hdr;
2091 int ret;
2092
2093 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2094 return -EINVAL;
2095
2096 skb_push(skb, sizeof(struct wmi_data_hdr));
2097
2098 data_hdr = (struct wmi_data_hdr *) skb->data;
2099 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2100 data_hdr->info3 = 0;
2101
2102 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2103
2104 return ret;
2105}
2106
2107static int ath6kl_wmi_sync_point(struct wmi *wmi)
2108{
2109 struct sk_buff *skb;
2110 struct wmi_sync_cmd *cmd;
2111 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2112 enum htc_endpoint_id ep_id;
2113 u8 index, num_pri_streams = 0;
2114 int ret = 0;
2115
2116 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2117
2118 spin_lock_bh(&wmi->lock);
2119
2120 for (index = 0; index < WMM_NUM_AC; index++) {
2121 if (wmi->fat_pipe_exist & (1 << index)) {
2122 num_pri_streams++;
2123 data_sync_bufs[num_pri_streams - 1].traffic_class =
2124 index;
2125 }
2126 }
2127
2128 spin_unlock_bh(&wmi->lock);
2129
2130 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2131 if (!skb) {
2132 ret = -ENOMEM;
2133 goto free_skb;
2134 }
2135
2136 cmd = (struct wmi_sync_cmd *) skb->data;
2137
2138 /*
2139 * In the SYNC cmd sent on the control Ep, send a bitmap
2140 * of the data eps on which the Data Sync will be sent
2141 */
2142 cmd->data_sync_map = wmi->fat_pipe_exist;
2143
2144 for (index = 0; index < num_pri_streams; index++) {
2145 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2146 if (data_sync_bufs[index].skb == NULL) {
2147 ret = -ENOMEM;
2148 break;
2149 }
2150 }
2151
2152 /*
2153 * If buffer allocation for any of the dataSync fails,
2154 * then do not send the Synchronize cmd on the control ep
2155 */
2156 if (ret)
2157 goto free_skb;
2158
2159 /*
2160 * Send sync cmd followed by sync data messages on all
2161 * endpoints being used
2162 */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302163 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SYNCHRONIZE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002164 NO_SYNC_WMIFLAG);
2165
2166 if (ret)
2167 goto free_skb;
2168
2169 /* cmd buffer sent, we no longer own it */
2170 skb = NULL;
2171
2172 for (index = 0; index < num_pri_streams; index++) {
2173
2174 if (WARN_ON(!data_sync_bufs[index].skb))
2175 break;
2176
2177 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2178 data_sync_bufs[index].
2179 traffic_class);
2180 ret =
2181 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2182 ep_id);
2183
2184 if (ret)
2185 break;
2186
2187 data_sync_bufs[index].skb = NULL;
2188 }
2189
2190free_skb:
2191 /* free up any resources left over (possibly due to an error) */
2192 if (skb)
2193 dev_kfree_skb(skb);
2194
2195 for (index = 0; index < num_pri_streams; index++) {
2196 if (data_sync_bufs[index].skb != NULL) {
2197 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2198 skb);
2199 }
2200 }
2201
2202 return ret;
2203}
2204
2205int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
2206 struct wmi_create_pstream_cmd *params)
2207{
2208 struct sk_buff *skb;
2209 struct wmi_create_pstream_cmd *cmd;
2210 u8 fatpipe_exist_for_ac = 0;
2211 s32 min_phy = 0;
2212 s32 nominal_phy = 0;
2213 int ret;
2214
2215 if (!((params->user_pri < 8) &&
2216 (params->user_pri <= 0x7) &&
2217 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2218 (params->traffic_direc == UPLINK_TRAFFIC ||
2219 params->traffic_direc == DNLINK_TRAFFIC ||
2220 params->traffic_direc == BIDIR_TRAFFIC) &&
2221 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2222 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2223 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2224 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2225 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2226 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2227 params->tsid <= WMI_MAX_THINSTREAM))) {
2228 return -EINVAL;
2229 }
2230
2231 /*
2232 * Check nominal PHY rate is >= minimalPHY,
2233 * so that DUT can allow TSRS IE
2234 */
2235
2236 /* Get the physical rate (units of bps) */
2237 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2238
2239 /* Check minimal phy < nominal phy rate */
2240 if (params->nominal_phy >= min_phy) {
2241 /* unit of 500 kbps */
2242 nominal_phy = (params->nominal_phy * 1000) / 500;
2243 ath6kl_dbg(ATH6KL_DBG_WMI,
2244 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2245 min_phy, nominal_phy);
2246
2247 params->nominal_phy = nominal_phy;
2248 } else {
2249 params->nominal_phy = 0;
2250 }
2251
2252 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2253 if (!skb)
2254 return -ENOMEM;
2255
2256 ath6kl_dbg(ATH6KL_DBG_WMI,
2257 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2258 params->traffic_class, params->tsid);
2259
2260 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2261 memcpy(cmd, params, sizeof(*cmd));
2262
2263 /* This is an implicitly created Fat pipe */
2264 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2265 spin_lock_bh(&wmi->lock);
2266 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2267 (1 << params->traffic_class));
2268 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2269 spin_unlock_bh(&wmi->lock);
2270 } else {
2271 /* explicitly created thin stream within a fat pipe */
2272 spin_lock_bh(&wmi->lock);
2273 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2274 (1 << params->traffic_class));
2275 wmi->stream_exist_for_ac[params->traffic_class] |=
2276 (1 << params->tsid);
2277 /*
2278 * If a thinstream becomes active, the fat pipe automatically
2279 * becomes active
2280 */
2281 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2282 spin_unlock_bh(&wmi->lock);
2283 }
2284
2285 /*
2286 * Indicate activty change to driver layer only if this is the
2287 * first TSID to get created in this AC explicitly or an implicit
2288 * fat pipe is getting created.
2289 */
2290 if (!fatpipe_exist_for_ac)
2291 ath6kl_indicate_tx_activity(wmi->parent_dev,
2292 params->traffic_class, true);
2293
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302294 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_CREATE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002295 NO_SYNC_WMIFLAG);
2296 return ret;
2297}
2298
2299int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
2300{
2301 struct sk_buff *skb;
2302 struct wmi_delete_pstream_cmd *cmd;
2303 u16 active_tsids = 0;
2304 int ret;
2305
2306 if (traffic_class > 3) {
2307 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2308 return -EINVAL;
2309 }
2310
2311 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2312 if (!skb)
2313 return -ENOMEM;
2314
2315 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2316 cmd->traffic_class = traffic_class;
2317 cmd->tsid = tsid;
2318
2319 spin_lock_bh(&wmi->lock);
2320 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2321 spin_unlock_bh(&wmi->lock);
2322
2323 if (!(active_tsids & (1 << tsid))) {
2324 dev_kfree_skb(skb);
2325 ath6kl_dbg(ATH6KL_DBG_WMI,
2326 "TSID %d doesn't exist for traffic class: %d\n",
2327 tsid, traffic_class);
2328 return -ENODATA;
2329 }
2330
2331 ath6kl_dbg(ATH6KL_DBG_WMI,
2332 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2333 traffic_class, tsid);
2334
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302335 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DELETE_PSTREAM_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002336 SYNC_BEFORE_WMIFLAG);
2337
2338 spin_lock_bh(&wmi->lock);
2339 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2340 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2341 spin_unlock_bh(&wmi->lock);
2342
2343 /*
2344 * Indicate stream inactivity to driver layer only if all tsids
2345 * within this AC are deleted.
2346 */
2347 if (!active_tsids) {
2348 ath6kl_indicate_tx_activity(wmi->parent_dev,
2349 traffic_class, false);
2350 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2351 }
2352
2353 return ret;
2354}
2355
2356int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2357{
2358 struct sk_buff *skb;
2359 struct wmi_set_ip_cmd *cmd;
2360 int ret;
2361
2362 /* Multicast address are not valid */
2363 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2364 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2365 return -EINVAL;
2366
2367 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2368 if (!skb)
2369 return -ENOMEM;
2370
2371 cmd = (struct wmi_set_ip_cmd *) skb->data;
2372 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2373
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302374 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_IP_CMDID,
2375 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002376 return ret;
2377}
2378
2379static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2380 int len)
2381{
2382 if (len < sizeof(struct wmi_get_wow_list_reply))
2383 return -EINVAL;
2384
2385 return 0;
2386}
2387
2388static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2389 enum wmix_command_id cmd_id,
2390 enum wmi_sync_flag sync_flag)
2391{
2392 struct wmix_cmd_hdr *cmd_hdr;
2393 int ret;
2394
2395 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2396
2397 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2398 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2399
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302400 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03002401
2402 return ret;
2403}
2404
2405int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2406{
2407 struct sk_buff *skb;
2408 struct wmix_hb_challenge_resp_cmd *cmd;
2409 int ret;
2410
2411 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2412 if (!skb)
2413 return -ENOMEM;
2414
2415 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2416 cmd->cookie = cpu_to_le32(cookie);
2417 cmd->source = cpu_to_le32(source);
2418
2419 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2420 NO_SYNC_WMIFLAG);
2421 return ret;
2422}
2423
Kalle Valo939f1cc2011-09-02 10:32:04 +03002424int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2425{
2426 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2427 struct sk_buff *skb;
2428 int ret;
2429
2430 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2431 if (!skb)
2432 return -ENOMEM;
2433
2434 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2435 cmd->valid = cpu_to_le32(valid);
2436 cmd->config = cpu_to_le32(config);
2437
2438 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2439 NO_SYNC_WMIFLAG);
2440 return ret;
2441}
2442
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302443int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
Kalle Valobdcd8172011-07-18 00:22:30 +03002444{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302445 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002446}
2447
2448int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
2449{
2450 struct sk_buff *skb;
2451 struct wmi_set_tx_pwr_cmd *cmd;
2452 int ret;
2453
2454 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2455 if (!skb)
2456 return -ENOMEM;
2457
2458 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2459 cmd->dbM = dbM;
2460
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302461 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_TX_PWR_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002462 NO_SYNC_WMIFLAG);
2463
2464 return ret;
2465}
2466
2467int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
2468{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302469 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_TX_PWR_CMDID);
Kalle Valobdcd8172011-07-18 00:22:30 +03002470}
2471
Jouni Malinen4b28a802011-10-11 17:31:54 +03002472int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
2473{
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302474 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
Jouni Malinen4b28a802011-10-11 17:31:54 +03002475}
2476
Kalle Valobdcd8172011-07-18 00:22:30 +03002477int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
2478{
2479 struct sk_buff *skb;
2480 struct wmi_set_lpreamble_cmd *cmd;
2481 int ret;
2482
2483 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2484 if (!skb)
2485 return -ENOMEM;
2486
2487 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2488 cmd->status = status;
2489 cmd->preamble_policy = preamble_policy;
2490
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302491 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_LPREAMBLE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002492 NO_SYNC_WMIFLAG);
2493 return ret;
2494}
2495
2496int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2497{
2498 struct sk_buff *skb;
2499 struct wmi_set_rts_cmd *cmd;
2500 int ret;
2501
2502 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2503 if (!skb)
2504 return -ENOMEM;
2505
2506 cmd = (struct wmi_set_rts_cmd *) skb->data;
2507 cmd->threshold = cpu_to_le16(threshold);
2508
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302509 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
2510 NO_SYNC_WMIFLAG);
Kalle Valobdcd8172011-07-18 00:22:30 +03002511 return ret;
2512}
2513
2514int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
2515{
2516 struct sk_buff *skb;
2517 struct wmi_set_wmm_txop_cmd *cmd;
2518 int ret;
2519
2520 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2521 return -EINVAL;
2522
2523 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2524 if (!skb)
2525 return -ENOMEM;
2526
2527 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2528 cmd->txop_enable = cfg;
2529
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302530 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_WMM_TXOP_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002531 NO_SYNC_WMIFLAG);
2532 return ret;
2533}
2534
2535int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
2536{
2537 struct sk_buff *skb;
2538 struct wmi_set_keepalive_cmd *cmd;
2539 int ret;
2540
2541 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2542 if (!skb)
2543 return -ENOMEM;
2544
2545 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2546 cmd->keep_alive_intvl = keep_alive_intvl;
Kalle Valobdcd8172011-07-18 00:22:30 +03002547
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302548 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_KEEPALIVE_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002549 NO_SYNC_WMIFLAG);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302550
Jouni Malinenff0b0072011-10-11 17:31:56 +03002551 if (ret == 0)
2552 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302553
Kalle Valobdcd8172011-07-18 00:22:30 +03002554 return ret;
2555}
2556
Kalle Valo003353b0d2011-09-01 10:14:21 +03002557int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2558{
2559 struct sk_buff *skb;
2560 int ret;
2561
2562 skb = ath6kl_wmi_get_new_buf(len);
2563 if (!skb)
2564 return -ENOMEM;
2565
2566 memcpy(skb->data, buf, len);
2567
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302568 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
Kalle Valo003353b0d2011-09-01 10:14:21 +03002569
2570 return ret;
2571}
2572
2573
Kalle Valobdcd8172011-07-18 00:22:30 +03002574s32 ath6kl_wmi_get_rate(s8 rate_index)
2575{
2576 if (rate_index == RATE_AUTO)
2577 return 0;
2578
2579 return wmi_rate_tbl[(u32) rate_index][0];
2580}
2581
Kalle Valobdcd8172011-07-18 00:22:30 +03002582static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2583 u32 len)
2584{
2585 struct wmi_pmkid_list_reply *reply;
2586 u32 expected_len;
2587
2588 if (len < sizeof(struct wmi_pmkid_list_reply))
2589 return -EINVAL;
2590
2591 reply = (struct wmi_pmkid_list_reply *)datap;
2592 expected_len = sizeof(reply->num_pmkid) +
2593 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2594
2595 if (len < expected_len)
2596 return -EINVAL;
2597
2598 return 0;
2599}
2600
2601static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2602{
2603 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2604
2605 aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
2606 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2607
2608 return 0;
2609}
2610
2611static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2612{
2613 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2614
2615 aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
2616
2617 return 0;
2618}
2619
2620/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002621
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302622int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
2623 struct wmi_connect_cmd *p)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002624{
2625 struct sk_buff *skb;
2626 struct wmi_connect_cmd *cm;
2627 int res;
2628
2629 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2630 if (!skb)
2631 return -ENOMEM;
2632
2633 cm = (struct wmi_connect_cmd *) skb->data;
2634 memcpy(cm, p, sizeof(*cm));
2635
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302636 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002637 NO_SYNC_WMIFLAG);
2638 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2639 "ctrl_flags=0x%x-> res=%d\n",
2640 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2641 le32_to_cpu(p->ctrl_flags), res);
2642 return res;
2643}
2644
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302645int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
2646 u16 reason)
Jouni Malinen23875132011-08-30 21:57:53 +03002647{
2648 struct sk_buff *skb;
2649 struct wmi_ap_set_mlme_cmd *cm;
2650
2651 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2652 if (!skb)
2653 return -ENOMEM;
2654
2655 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2656 memcpy(cm->mac, mac, ETH_ALEN);
2657 cm->reason = cpu_to_le16(reason);
2658 cm->cmd = cmd;
2659
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302660 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
Jouni Malinen23875132011-08-30 21:57:53 +03002661 NO_SYNC_WMIFLAG);
2662}
2663
Kalle Valobdcd8172011-07-18 00:22:30 +03002664static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
2665{
2666 struct wmi_pspoll_event *ev;
2667
2668 if (len < sizeof(struct wmi_pspoll_event))
2669 return -EINVAL;
2670
2671 ev = (struct wmi_pspoll_event *) datap;
2672
2673 ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
2674
2675 return 0;
2676}
2677
2678static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
2679{
2680 ath6kl_dtimexpiry_event(wmi->parent_dev);
2681
2682 return 0;
2683}
2684
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302685int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
2686 bool flag)
Kalle Valobdcd8172011-07-18 00:22:30 +03002687{
2688 struct sk_buff *skb;
2689 struct wmi_ap_set_pvb_cmd *cmd;
2690 int ret;
2691
2692 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2693 if (!skb)
2694 return -ENOMEM;
2695
2696 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2697 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03002698 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03002699 cmd->flag = cpu_to_le32(flag);
2700
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302701 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002702 NO_SYNC_WMIFLAG);
2703
2704 return 0;
2705}
2706
2707int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
2708 bool rx_dot11_hdr, bool defrag_on_host)
2709{
2710 struct sk_buff *skb;
2711 struct wmi_rx_frame_format_cmd *cmd;
2712 int ret;
2713
2714 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2715 if (!skb)
2716 return -ENOMEM;
2717
2718 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2719 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2720 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2721 cmd->meta_ver = rx_meta_ver;
2722
2723 /* Delete the local aggr state, on host */
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302724 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RX_FRAME_FORMAT_CMDID,
Kalle Valobdcd8172011-07-18 00:22:30 +03002725 NO_SYNC_WMIFLAG);
2726
2727 return ret;
2728}
2729
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302730int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
2731 const u8 *ie, u8 ie_len)
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002732{
2733 struct sk_buff *skb;
2734 struct wmi_set_appie_cmd *p;
2735
2736 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2737 if (!skb)
2738 return -ENOMEM;
2739
2740 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2741 "ie_len=%u\n", mgmt_frm_type, ie_len);
2742 p = (struct wmi_set_appie_cmd *) skb->data;
2743 p->mgmt_frm_type = mgmt_frm_type;
2744 p->ie_len = ie_len;
2745 memcpy(p->ie_info, ie, ie_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302746 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002747 NO_SYNC_WMIFLAG);
2748}
2749
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002750int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2751{
2752 struct sk_buff *skb;
2753 struct wmi_disable_11b_rates_cmd *cmd;
2754
2755 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2756 if (!skb)
2757 return -ENOMEM;
2758
2759 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2760 disable);
2761 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2762 cmd->disable = disable ? 1 : 0;
2763
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302764 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002765 NO_SYNC_WMIFLAG);
2766}
2767
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302768int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002769{
2770 struct sk_buff *skb;
2771 struct wmi_remain_on_chnl_cmd *p;
2772
2773 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2774 if (!skb)
2775 return -ENOMEM;
2776
2777 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
2778 freq, dur);
2779 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
2780 p->freq = cpu_to_le32(freq);
2781 p->duration = cpu_to_le32(dur);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302782 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002783 NO_SYNC_WMIFLAG);
2784}
2785
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302786int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
2787 u32 wait, const u8 *data, u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002788{
2789 struct sk_buff *skb;
2790 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03002791 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002792
2793 if (wait)
2794 return -EINVAL; /* Offload for wait not supported */
2795
Jouni Malinena0df5db2011-08-30 21:58:02 +03002796 buf = kmalloc(data_len, GFP_KERNEL);
2797 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002798 return -ENOMEM;
2799
Jouni Malinena0df5db2011-08-30 21:58:02 +03002800 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2801 if (!skb) {
2802 kfree(buf);
2803 return -ENOMEM;
2804 }
2805
2806 kfree(wmi->last_mgmt_tx_frame);
2807 wmi->last_mgmt_tx_frame = buf;
2808 wmi->last_mgmt_tx_frame_len = data_len;
2809
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002810 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
2811 "len=%u\n", id, freq, wait, data_len);
2812 p = (struct wmi_send_action_cmd *) skb->data;
2813 p->id = cpu_to_le32(id);
2814 p->freq = cpu_to_le32(freq);
2815 p->wait = cpu_to_le32(wait);
2816 p->len = cpu_to_le16(data_len);
2817 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302818 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002819 NO_SYNC_WMIFLAG);
2820}
2821
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302822int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
2823 const u8 *dst, const u8 *data,
2824 u16 data_len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002825{
2826 struct sk_buff *skb;
2827 struct wmi_p2p_probe_response_cmd *p;
2828
2829 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2830 if (!skb)
2831 return -ENOMEM;
2832
2833 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
2834 "len=%u\n", freq, dst, data_len);
2835 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
2836 p->freq = cpu_to_le32(freq);
2837 memcpy(p->destination_addr, dst, ETH_ALEN);
2838 p->len = cpu_to_le16(data_len);
2839 memcpy(p->data, data, data_len);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302840 return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
2841 WMI_SEND_PROBE_RESPONSE_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002842 NO_SYNC_WMIFLAG);
2843}
2844
2845int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
2846{
2847 struct sk_buff *skb;
2848 struct wmi_probe_req_report_cmd *p;
2849
2850 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2851 if (!skb)
2852 return -ENOMEM;
2853
2854 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
2855 enable);
2856 p = (struct wmi_probe_req_report_cmd *) skb->data;
2857 p->enable = enable ? 1 : 0;
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302858 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_PROBE_REQ_REPORT_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002859 NO_SYNC_WMIFLAG);
2860}
2861
2862int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
2863{
2864 struct sk_buff *skb;
2865 struct wmi_get_p2p_info *p;
2866
2867 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2868 if (!skb)
2869 return -ENOMEM;
2870
2871 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
2872 info_req_flags);
2873 p = (struct wmi_get_p2p_info *) skb->data;
2874 p->info_req_flags = cpu_to_le32(info_req_flags);
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302875 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_GET_P2P_INFO_CMDID,
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002876 NO_SYNC_WMIFLAG);
2877}
2878
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302879int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002880{
2881 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
Vasanthakumar Thiagarajan334234b2011-10-25 19:34:12 +05302882 return ath6kl_wmi_simple_cmd(wmi, if_idx,
2883 WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002884}
2885
Kalle Valobdcd8172011-07-18 00:22:30 +03002886static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
2887{
2888 struct wmix_cmd_hdr *cmd;
2889 u32 len;
2890 u16 id;
2891 u8 *datap;
2892 int ret = 0;
2893
2894 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
2895 ath6kl_err("bad packet 1\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03002896 return -EINVAL;
2897 }
2898
2899 cmd = (struct wmix_cmd_hdr *) skb->data;
2900 id = le32_to_cpu(cmd->cmd_id);
2901
2902 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
2903
2904 datap = skb->data;
2905 len = skb->len;
2906
2907 switch (id) {
2908 case WMIX_HB_CHALLENGE_RESP_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03002909 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
Kalle Valobdcd8172011-07-18 00:22:30 +03002910 break;
2911 case WMIX_DBGLOG_EVENTID:
Kalle Valob9b6ee62011-09-27 14:31:21 +03002912 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
Kalle Valobdf53962011-09-02 10:32:04 +03002913 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002914 break;
2915 default:
Kalle Valob9b6ee62011-09-27 14:31:21 +03002916 ath6kl_warn("unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03002917 ret = -EINVAL;
2918 break;
2919 }
2920
2921 return ret;
2922}
2923
Jouni Malinen4b28a802011-10-11 17:31:54 +03002924static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
2925{
2926 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
2927}
2928
Kalle Valobdcd8172011-07-18 00:22:30 +03002929/* Control Path */
2930int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
2931{
2932 struct wmi_cmd_hdr *cmd;
2933 u32 len;
2934 u16 id;
2935 u8 *datap;
2936 int ret = 0;
2937
2938 if (WARN_ON(skb == NULL))
2939 return -EINVAL;
2940
2941 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
2942 ath6kl_err("bad packet 1\n");
2943 dev_kfree_skb(skb);
Kalle Valobdcd8172011-07-18 00:22:30 +03002944 return -EINVAL;
2945 }
2946
2947 cmd = (struct wmi_cmd_hdr *) skb->data;
2948 id = le16_to_cpu(cmd->cmd_id);
2949
2950 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
2951
2952 datap = skb->data;
2953 len = skb->len;
2954
Kalle Valob9b6ee62011-09-27 14:31:21 +03002955 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
2956 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
Kalle Valoef094102011-09-27 14:30:45 +03002957 datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002958
2959 switch (id) {
2960 case WMI_GET_BITRATE_CMDID:
2961 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
2962 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
2963 break;
2964 case WMI_GET_CHANNEL_LIST_CMDID:
2965 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
2966 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
2967 break;
2968 case WMI_GET_TX_PWR_CMDID:
2969 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
2970 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
2971 break;
2972 case WMI_READY_EVENTID:
2973 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
2974 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
2975 break;
2976 case WMI_CONNECT_EVENTID:
2977 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
2978 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
2979 break;
2980 case WMI_DISCONNECT_EVENTID:
2981 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
2982 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
2983 break;
2984 case WMI_PEER_NODE_EVENTID:
2985 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
2986 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
2987 break;
2988 case WMI_TKIP_MICERR_EVENTID:
2989 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
2990 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
2991 break;
2992 case WMI_BSSINFO_EVENTID:
2993 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
Jouni Malinen82e14f52011-09-19 19:15:05 +03002994 ret = ath6kl_wmi_bssinfo_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002995 break;
2996 case WMI_REGDOMAIN_EVENTID:
2997 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05302998 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002999 break;
3000 case WMI_PSTREAM_TIMEOUT_EVENTID:
3001 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
3002 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
3003 break;
3004 case WMI_NEIGHBOR_REPORT_EVENTID:
3005 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
Jouni Malinen86512132011-09-21 16:57:29 +03003006 ret = ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003007 break;
3008 case WMI_SCAN_COMPLETE_EVENTID:
3009 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
3010 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
3011 break;
3012 case WMI_CMDERROR_EVENTID:
3013 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
3014 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
3015 break;
3016 case WMI_REPORT_STATISTICS_EVENTID:
3017 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
3018 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
3019 break;
3020 case WMI_RSSI_THRESHOLD_EVENTID:
3021 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
3022 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
3023 break;
3024 case WMI_ERROR_REPORT_EVENTID:
3025 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
3026 break;
3027 case WMI_OPT_RX_FRAME_EVENTID:
3028 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03003029 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03003030 break;
3031 case WMI_REPORT_ROAM_TBL_EVENTID:
3032 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
Jouni Malinen4b28a802011-10-11 17:31:54 +03003033 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03003034 break;
3035 case WMI_EXTENSION_EVENTID:
3036 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
3037 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
3038 break;
3039 case WMI_CAC_EVENTID:
3040 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
3041 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
3042 break;
3043 case WMI_CHANNEL_CHANGE_EVENTID:
3044 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
3045 break;
3046 case WMI_REPORT_ROAM_DATA_EVENTID:
3047 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
3048 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03003049 case WMI_TEST_EVENTID:
3050 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
3051 ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
3052 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003053 case WMI_GET_FIXRATES_CMDID:
3054 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
3055 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
3056 break;
3057 case WMI_TX_RETRY_ERR_EVENTID:
3058 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
3059 break;
3060 case WMI_SNR_THRESHOLD_EVENTID:
3061 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
3062 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
3063 break;
3064 case WMI_LQ_THRESHOLD_EVENTID:
3065 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
3066 break;
3067 case WMI_APLIST_EVENTID:
3068 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
3069 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
3070 break;
3071 case WMI_GET_KEEPALIVE_CMDID:
3072 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3073 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3074 break;
3075 case WMI_GET_WOW_LIST_EVENTID:
3076 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
3077 ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
3078 break;
3079 case WMI_GET_PMKID_LIST_EVENTID:
3080 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3081 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3082 break;
3083 case WMI_PSPOLL_EVENTID:
3084 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3085 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
3086 break;
3087 case WMI_DTIMEXPIRY_EVENTID:
3088 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3089 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
3090 break;
3091 case WMI_SET_PARAMS_REPLY_EVENTID:
3092 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3093 break;
3094 case WMI_ADDBA_REQ_EVENTID:
3095 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3096 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
3097 break;
3098 case WMI_ADDBA_RESP_EVENTID:
3099 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3100 break;
3101 case WMI_DELBA_REQ_EVENTID:
3102 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3103 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
3104 break;
3105 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3106 ath6kl_dbg(ATH6KL_DBG_WMI,
3107 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3108 break;
3109 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3110 ath6kl_dbg(ATH6KL_DBG_WMI,
3111 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3112 break;
3113 case WMI_TX_COMPLETE_EVENTID:
3114 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3115 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3116 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003117 case WMI_REMAIN_ON_CHNL_EVENTID:
3118 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03003119 ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003120 break;
3121 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3122 ath6kl_dbg(ATH6KL_DBG_WMI,
3123 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03003124 ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3125 len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003126 break;
3127 case WMI_TX_STATUS_EVENTID:
3128 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
Jouni Malinena0df5db2011-08-30 21:58:02 +03003129 ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003130 break;
3131 case WMI_RX_PROBE_REQ_EVENTID:
3132 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
Jouni Malinenae32c302011-08-30 21:58:01 +03003133 ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003134 break;
3135 case WMI_P2P_CAPABILITIES_EVENTID:
3136 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3137 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3138 break;
3139 case WMI_RX_ACTION_EVENTID:
3140 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
Jouni Malinen9809d8e2011-08-30 21:58:03 +03003141 ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003142 break;
3143 case WMI_P2P_INFO_EVENTID:
3144 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3145 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3146 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003147 default:
3148 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
Kalle Valobdcd8172011-07-18 00:22:30 +03003149 ret = -EINVAL;
3150 break;
3151 }
3152
3153 dev_kfree_skb(skb);
3154
3155 return ret;
3156}
3157
3158static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
3159{
3160 if (!wmi)
3161 return;
3162
3163 spin_lock_bh(&wmi->lock);
3164
3165 wmi->fat_pipe_exist = 0;
3166 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3167
3168 spin_unlock_bh(&wmi->lock);
3169}
3170
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05303171void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03003172{
3173 struct wmi *wmi;
3174
3175 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3176 if (!wmi)
3177 return NULL;
3178
3179 spin_lock_init(&wmi->lock);
3180
3181 wmi->parent_dev = dev;
3182
Kalle Valobdcd8172011-07-18 00:22:30 +03003183 wmi->pwr_mode = REC_POWER;
Kalle Valobdcd8172011-07-18 00:22:30 +03003184
Kalle Valoa7f0c582011-10-05 12:23:05 +03003185 ath6kl_wmi_qos_state_init(wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03003186
3187 return wmi;
3188}
3189
3190void ath6kl_wmi_shutdown(struct wmi *wmi)
3191{
3192 if (!wmi)
3193 return;
3194
Jouni Malinena0df5db2011-08-30 21:58:02 +03003195 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03003196 kfree(wmi);
3197}