blob: 3ade9a17c0eb048fb89fdb753dd1290496c111b7 [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
265 /* workaround for WMM S5 */
266 if ((wmi->traffic_class == WMM_AC_VI) &&
267 ((usr_pri == 5) || (usr_pri == 4)))
268 usr_pri = 1;
269
270 /* Convert user priority to traffic class */
271 traffic_class = up_to_ac[usr_pri & 0x7];
272
273 wmi_data_hdr_set_up(data_hdr, usr_pri);
274
275 spin_lock_bh(&wmi->lock);
276 stream_exist = wmi->fat_pipe_exist;
277 spin_unlock_bh(&wmi->lock);
278
279 if (!(stream_exist & (1 << traffic_class))) {
280 memset(&cmd, 0, sizeof(cmd));
281 cmd.traffic_class = traffic_class;
282 cmd.user_pri = usr_pri;
283 cmd.inactivity_int =
284 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
285 /* Implicit streams are created with TSID 0xFF */
286 cmd.tsid = WMI_IMPLICIT_PSTREAM;
287 ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
288 }
289
290 *ac = traffic_class;
291
292 return 0;
293}
294
295int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
296{
297 struct ieee80211_hdr_3addr *pwh, wh;
298 struct ath6kl_llc_snap_hdr *llc_hdr;
299 struct ethhdr eth_hdr;
300 u32 hdr_size;
301 u8 *datap;
302 __le16 sub_type;
303
304 if (WARN_ON(skb == NULL))
305 return -EINVAL;
306
307 datap = skb->data;
308 pwh = (struct ieee80211_hdr_3addr *) datap;
309
310 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
311
312 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
313
314 /* Strip off the 802.11 header */
315 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
316 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
317 sizeof(u32));
318 skb_pull(skb, hdr_size);
319 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
320 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
321
322 datap = skb->data;
323 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
324
Raja Manic8790cba2011-07-19 19:27:32 +0530325 memset(&eth_hdr, 0, sizeof(eth_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +0300326 eth_hdr.h_proto = llc_hdr->eth_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300327
328 switch ((le16_to_cpu(wh.frame_control)) &
329 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
330 case 0:
331 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
332 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
333 break;
334 case IEEE80211_FCTL_TODS:
335 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
336 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
337 break;
338 case IEEE80211_FCTL_FROMDS:
339 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
340 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
341 break;
342 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
343 break;
344 }
345
346 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
347 skb_push(skb, sizeof(eth_hdr));
348
349 datap = skb->data;
350
351 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
352
353 return 0;
354}
355
356/*
357 * Performs 802.3 to DIX encapsulation for received packets.
358 * Assumes the entire 802.3 header is contigous.
359 */
360int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
361{
362 struct ath6kl_llc_snap_hdr *llc_hdr;
363 struct ethhdr eth_hdr;
364 u8 *datap;
365
366 if (WARN_ON(skb == NULL))
367 return -EINVAL;
368
369 datap = skb->data;
370
371 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
372
373 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
374 eth_hdr.h_proto = llc_hdr->eth_type;
375
376 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
377 datap = skb->data;
378
379 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
380
381 return 0;
382}
383
Kalle Valobdcd8172011-07-18 00:22:30 +0300384static void ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(struct sk_buff *skb,
385 u8 *datap)
386{
387 struct wmi_bss_info_hdr2 bih2;
388 struct wmi_bss_info_hdr *bih;
389
390 memcpy(&bih2, datap, sizeof(struct wmi_bss_info_hdr2));
391
392 skb_push(skb, 4);
393 bih = (struct wmi_bss_info_hdr *) skb->data;
394
395 bih->ch = bih2.ch;
396 bih->frame_type = bih2.frame_type;
397 bih->snr = bih2.snr;
398 bih->rssi = a_cpu_to_sle16(bih2.snr - 95);
399 bih->ie_mask = cpu_to_le32(le16_to_cpu(bih2.ie_mask));
400 memcpy(bih->bssid, bih2.bssid, ETH_ALEN);
401}
402
403static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
404{
405 struct tx_complete_msg_v1 *msg_v1;
406 struct wmi_tx_complete_event *evt;
407 int index;
408 u16 size;
409
410 evt = (struct wmi_tx_complete_event *) datap;
411
412 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
413 evt->num_msg, evt->msg_len, evt->msg_type);
414
415 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
416 return 0;
417
418 for (index = 0; index < evt->num_msg; index++) {
419 size = sizeof(struct wmi_tx_complete_event) +
420 (index * sizeof(struct tx_complete_msg_v1));
421 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
422
423 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
424 msg_v1->status, msg_v1->pkt_id,
425 msg_v1->rate_idx, msg_v1->ack_failures);
426 }
427
428 return 0;
429}
430
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300431static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
432 int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300433{
434 struct wmi_remain_on_chnl_event *ev;
435 u32 freq;
436 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300437 struct ieee80211_channel *chan;
438 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300439
440 if (len < sizeof(*ev))
441 return -EINVAL;
442
443 ev = (struct wmi_remain_on_chnl_event *) datap;
444 freq = le32_to_cpu(ev->freq);
445 dur = le32_to_cpu(ev->duration);
446 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
447 freq, dur);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300448 chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
449 if (!chan) {
450 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
451 "(freq=%u)\n", freq);
452 return -EINVAL;
453 }
454 cfg80211_ready_on_channel(ar->net_dev, 1, chan, NL80211_CHAN_NO_HT,
455 dur, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300456
457 return 0;
458}
459
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300460static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
461 u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300462{
463 struct wmi_cancel_remain_on_chnl_event *ev;
464 u32 freq;
465 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300466 struct ieee80211_channel *chan;
467 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300468
469 if (len < sizeof(*ev))
470 return -EINVAL;
471
472 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
473 freq = le32_to_cpu(ev->freq);
474 dur = le32_to_cpu(ev->duration);
475 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
476 "status=%u\n", freq, dur, ev->status);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300477 chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
478 if (!chan) {
479 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
480 "channel (freq=%u)\n", freq);
481 return -EINVAL;
482 }
483 cfg80211_remain_on_channel_expired(ar->net_dev, 1, chan,
484 NL80211_CHAN_NO_HT, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300485
486 return 0;
487}
488
Jouni Malinena0df5db2011-08-30 21:58:02 +0300489static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300490{
491 struct wmi_tx_status_event *ev;
492 u32 id;
Jouni Malinena0df5db2011-08-30 21:58:02 +0300493 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300494
495 if (len < sizeof(*ev))
496 return -EINVAL;
497
498 ev = (struct wmi_tx_status_event *) datap;
499 id = le32_to_cpu(ev->id);
500 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
501 id, ev->ack_status);
Jouni Malinena0df5db2011-08-30 21:58:02 +0300502 if (wmi->last_mgmt_tx_frame) {
503 cfg80211_mgmt_tx_status(ar->net_dev, id,
504 wmi->last_mgmt_tx_frame,
505 wmi->last_mgmt_tx_frame_len,
506 !!ev->ack_status, GFP_ATOMIC);
507 kfree(wmi->last_mgmt_tx_frame);
508 wmi->last_mgmt_tx_frame = NULL;
509 wmi->last_mgmt_tx_frame_len = 0;
510 }
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300511
512 return 0;
513}
514
Jouni Malinenae32c302011-08-30 21:58:01 +0300515static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300516{
517 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300518 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300519 u16 dlen;
Jouni Malinenae32c302011-08-30 21:58:01 +0300520 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300521
522 if (len < sizeof(*ev))
523 return -EINVAL;
524
525 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300526 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300527 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300528 if (datap + len < ev->data + dlen) {
529 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
530 "len=%d dlen=%u\n", len, dlen);
531 return -EINVAL;
532 }
533 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
534 "probe_req_report=%d\n",
535 dlen, freq, ar->probe_req_report);
536
537 if (ar->probe_req_report || ar->nw_type == AP_NETWORK)
538 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300539
540 return 0;
541}
542
543static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
544{
545 struct wmi_p2p_capabilities_event *ev;
546 u16 dlen;
547
548 if (len < sizeof(*ev))
549 return -EINVAL;
550
551 ev = (struct wmi_p2p_capabilities_event *) datap;
552 dlen = le16_to_cpu(ev->len);
553 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
554
555 return 0;
556}
557
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300558static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300559{
560 struct wmi_rx_action_event *ev;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300561 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300562 u16 dlen;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300563 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300564
565 if (len < sizeof(*ev))
566 return -EINVAL;
567
568 ev = (struct wmi_rx_action_event *) datap;
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300569 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300570 dlen = le16_to_cpu(ev->len);
Jouni Malinen9809d8e2011-08-30 21:58:03 +0300571 if (datap + len < ev->data + dlen) {
572 ath6kl_err("invalid wmi_rx_action_event: "
573 "len=%d dlen=%u\n", len, dlen);
574 return -EINVAL;
575 }
576 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
577 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300578
579 return 0;
580}
581
582static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
583{
584 struct wmi_p2p_info_event *ev;
585 u32 flags;
586 u16 dlen;
587
588 if (len < sizeof(*ev))
589 return -EINVAL;
590
591 ev = (struct wmi_p2p_info_event *) datap;
592 flags = le32_to_cpu(ev->info_req_flags);
593 dlen = le16_to_cpu(ev->len);
594 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
595
596 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
597 struct wmi_p2p_capabilities *cap;
598 if (dlen < sizeof(*cap))
599 return -EINVAL;
600 cap = (struct wmi_p2p_capabilities *) ev->data;
601 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
602 cap->go_power_save);
603 }
604
605 if (flags & P2P_FLAG_MACADDR_REQ) {
606 struct wmi_p2p_macaddr *mac;
607 if (dlen < sizeof(*mac))
608 return -EINVAL;
609 mac = (struct wmi_p2p_macaddr *) ev->data;
610 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
611 mac->mac_addr);
612 }
613
614 if (flags & P2P_FLAG_HMODEL_REQ) {
615 struct wmi_p2p_hmodel *mod;
616 if (dlen < sizeof(*mod))
617 return -EINVAL;
618 mod = (struct wmi_p2p_hmodel *) ev->data;
619 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
620 mod->p2p_model,
621 mod->p2p_model ? "host" : "firmware");
622 }
623 return 0;
624}
625
Kalle Valobdcd8172011-07-18 00:22:30 +0300626static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
627{
628 struct sk_buff *skb;
629
630 skb = ath6kl_buf_alloc(size);
631 if (!skb)
632 return NULL;
633
634 skb_put(skb, size);
635 if (size)
636 memset(skb->data, 0, size);
637
638 return skb;
639}
640
641/* Send a "simple" wmi command -- one with no arguments */
642static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
643{
644 struct sk_buff *skb;
645 int ret;
646
647 skb = ath6kl_wmi_get_new_buf(0);
648 if (!skb)
649 return -ENOMEM;
650
651 ret = ath6kl_wmi_cmd_send(wmi, skb, cmd_id, NO_SYNC_WMIFLAG);
652
653 return ret;
654}
655
656static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
657{
658 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
659
660 if (len < sizeof(struct wmi_ready_event_2))
661 return -EINVAL;
662
663 wmi->ready = true;
664 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
665 le32_to_cpu(ev->sw_version),
666 le32_to_cpu(ev->abi_version));
667
668 return 0;
669}
670
Vivek Natarajane5090442011-08-31 15:02:19 +0530671/*
672 * Mechanism to modify the roaming behavior in the firmware. The lower rssi
673 * at which the station has to roam can be passed with
674 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
675 * in dBm.
676 */
677int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
678{
679 struct sk_buff *skb;
680 struct roam_ctrl_cmd *cmd;
681
682 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
683 if (!skb)
684 return -ENOMEM;
685
686 cmd = (struct roam_ctrl_cmd *) skb->data;
687
688 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
689 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
690 DEF_SCAN_FOR_ROAM_INTVL);
691 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
692 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
693 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
694
695 ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_ROAM_CTRL_CMDID, NO_SYNC_WMIFLAG);
696
697 return 0;
698}
699
Kalle Valobdcd8172011-07-18 00:22:30 +0300700static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
701{
702 struct wmi_connect_event *ev;
703 u8 *pie, *peie;
Jouni Malinen572e27c2011-09-05 17:38:45 +0300704 struct ath6kl *ar = wmi->parent_dev;
Kalle Valobdcd8172011-07-18 00:22:30 +0300705
706 if (len < sizeof(struct wmi_connect_event))
707 return -EINVAL;
708
709 ev = (struct wmi_connect_event *) datap;
710
Jouni Malinen572e27c2011-09-05 17:38:45 +0300711 if (ar->nw_type == AP_NETWORK) {
712 /* AP mode start/STA connected event */
713 struct net_device *dev = ar->net_dev;
714 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
715 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM "
716 "(AP started)\n",
717 __func__, le16_to_cpu(ev->u.ap_bss.ch),
718 ev->u.ap_bss.bssid);
719 ath6kl_connect_ap_mode_bss(
720 ar, le16_to_cpu(ev->u.ap_bss.ch));
721 } else {
722 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: aid %u mac_addr %pM "
723 "auth=%u keymgmt=%u cipher=%u apsd_info=%u "
724 "(STA connected)\n",
725 __func__, ev->u.ap_sta.aid,
726 ev->u.ap_sta.mac_addr,
727 ev->u.ap_sta.auth,
728 ev->u.ap_sta.keymgmt,
729 le16_to_cpu(ev->u.ap_sta.cipher),
730 ev->u.ap_sta.apsd_info);
731 ath6kl_connect_ap_mode_sta(
732 ar, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
733 ev->u.ap_sta.keymgmt,
734 le16_to_cpu(ev->u.ap_sta.cipher),
735 ev->u.ap_sta.auth, ev->assoc_req_len,
736 ev->assoc_info + ev->beacon_ie_len);
737 }
738 return 0;
739 }
740
741 /* STA/IBSS mode connection event */
742
Kalle Valobdcd8172011-07-18 00:22:30 +0300743 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM\n",
Jouni Malinen572e27c2011-09-05 17:38:45 +0300744 __func__, le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid);
Kalle Valobdcd8172011-07-18 00:22:30 +0300745
Kalle Valobdcd8172011-07-18 00:22:30 +0300746 /* Start of assoc rsp IEs */
747 pie = ev->assoc_info + ev->beacon_ie_len +
748 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
749
750 /* End of assoc rsp IEs */
751 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
752 ev->assoc_resp_len;
753
754 while (pie < peie) {
755 switch (*pie) {
756 case WLAN_EID_VENDOR_SPECIFIC:
757 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
758 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
759 /* WMM OUT (00:50:F2) */
760 if (pie[1] > 5
761 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
762 wmi->is_wmm_enabled = true;
763 }
764 break;
765 }
766
767 if (wmi->is_wmm_enabled)
768 break;
769
770 pie += pie[1] + 2;
771 }
772
Jouni Malinen572e27c2011-09-05 17:38:45 +0300773 ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->u.sta.ch),
774 ev->u.sta.bssid,
775 le16_to_cpu(ev->u.sta.listen_intvl),
776 le16_to_cpu(ev->u.sta.beacon_intvl),
777 le32_to_cpu(ev->u.sta.nw_type),
Kalle Valobdcd8172011-07-18 00:22:30 +0300778 ev->beacon_ie_len, ev->assoc_req_len,
779 ev->assoc_resp_len, ev->assoc_info);
780
781 return 0;
782}
783
Vivek Natarajan06033762011-09-06 13:01:36 +0530784static struct country_code_to_enum_rd *
785ath6kl_regd_find_country(u16 countryCode)
786{
787 int i;
788
789 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
790 if (allCountries[i].countryCode == countryCode)
791 return &allCountries[i];
792 }
793
794 return NULL;
795}
796
797static struct reg_dmn_pair_mapping *
798ath6kl_get_regpair(u16 regdmn)
799{
800 int i;
801
802 if (regdmn == NO_ENUMRD)
803 return NULL;
804
805 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
806 if (regDomainPairs[i].regDmnEnum == regdmn)
807 return &regDomainPairs[i];
808 }
809
810 return NULL;
811}
812
813static struct country_code_to_enum_rd *
814ath6kl_regd_find_country_by_rd(u16 regdmn)
815{
816 int i;
817
818 for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
819 if (allCountries[i].regDmnEnum == regdmn)
820 return &allCountries[i];
821 }
822
823 return NULL;
824}
825
826static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
827{
828
829 struct ath6kl_wmi_regdomain *ev;
830 struct country_code_to_enum_rd *country = NULL;
831 struct reg_dmn_pair_mapping *regpair = NULL;
832 char alpha2[2];
833 u32 reg_code;
834
835 ev = (struct ath6kl_wmi_regdomain *) datap;
836 reg_code = le32_to_cpu(ev->reg_code);
837
838 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG)
839 country = ath6kl_regd_find_country((u16) reg_code);
840 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
841
842 regpair = ath6kl_get_regpair((u16) reg_code);
843 country = ath6kl_regd_find_country_by_rd((u16) reg_code);
844 ath6kl_dbg(ATH6KL_DBG_WMI, "ath6kl: Regpair used: 0x%0x\n",
845 regpair->regDmnEnum);
846 }
847
848 if (country) {
849 alpha2[0] = country->isoName[0];
850 alpha2[1] = country->isoName[1];
851
852 regulatory_hint(wmi->parent_dev->wdev->wiphy, alpha2);
853
854 ath6kl_dbg(ATH6KL_DBG_WMI, "ath6kl: Country alpha2 being used: %c%c\n",
855 alpha2[0], alpha2[1]);
856 }
857}
858
Kalle Valobdcd8172011-07-18 00:22:30 +0300859static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
860{
861 struct wmi_disconnect_event *ev;
862 wmi->traffic_class = 100;
863
864 if (len < sizeof(struct wmi_disconnect_event))
865 return -EINVAL;
866
867 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300868
869 wmi->is_wmm_enabled = false;
870 wmi->pair_crypto_type = NONE_CRYPT;
871 wmi->grp_crypto_type = NONE_CRYPT;
872
873 ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
874 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
875 le16_to_cpu(ev->proto_reason_status));
876
877 return 0;
878}
879
880static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
881{
882 struct wmi_peer_node_event *ev;
883
884 if (len < sizeof(struct wmi_peer_node_event))
885 return -EINVAL;
886
887 ev = (struct wmi_peer_node_event *) datap;
888
889 if (ev->event_code == PEER_NODE_JOIN_EVENT)
890 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
891 ev->peer_mac_addr);
892 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
893 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
894 ev->peer_mac_addr);
895
896 return 0;
897}
898
899static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
900{
901 struct wmi_tkip_micerr_event *ev;
902
903 if (len < sizeof(struct wmi_tkip_micerr_event))
904 return -EINVAL;
905
906 ev = (struct wmi_tkip_micerr_event *) datap;
907
908 ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
909
910 return 0;
911}
912
Kalle Valobdcd8172011-07-18 00:22:30 +0300913static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
914{
Kalle Valobdcd8172011-07-18 00:22:30 +0300915 struct wmi_bss_info_hdr *bih;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300916 u8 *buf;
917 struct ieee80211_channel *channel;
918 struct ath6kl *ar = wmi->parent_dev;
919 struct ieee80211_mgmt *mgmt;
920 struct cfg80211_bss *bss;
Kalle Valobdcd8172011-07-18 00:22:30 +0300921
922 if (len <= sizeof(struct wmi_bss_info_hdr))
923 return -EINVAL;
924
925 bih = (struct wmi_bss_info_hdr *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300926 buf = datap + sizeof(struct wmi_bss_info_hdr);
927 len -= sizeof(struct wmi_bss_info_hdr);
928
929 ath6kl_dbg(ATH6KL_DBG_WMI,
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300930 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
931 "frame_type=%d\n",
932 bih->ch, bih->snr, a_sle16_to_cpu(bih->rssi), bih->bssid,
933 bih->frame_type);
Kalle Valobdcd8172011-07-18 00:22:30 +0300934
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300935 if (bih->frame_type != BEACON_FTYPE &&
936 bih->frame_type != PROBERESP_FTYPE)
937 return 0; /* Only update BSS table for now */
Kalle Valobdcd8172011-07-18 00:22:30 +0300938
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300939 channel = ieee80211_get_channel(ar->wdev->wiphy, le16_to_cpu(bih->ch));
940 if (channel == NULL)
941 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300942
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300943 if (len < 8 + 2 + 2)
944 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300945
946 /*
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300947 * In theory, use of cfg80211_inform_bss() would be more natural here
948 * since we do not have the full frame. However, at least for now,
949 * cfg80211 can only distinguish Beacon and Probe Response frames from
950 * each other when using cfg80211_inform_bss_frame(), so let's build a
951 * fake IEEE 802.11 header to be able to take benefit of this.
Kalle Valobdcd8172011-07-18 00:22:30 +0300952 */
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300953 mgmt = kmalloc(24 + len, GFP_ATOMIC);
954 if (mgmt == NULL)
955 return -EINVAL;
Kalle Valobdcd8172011-07-18 00:22:30 +0300956
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300957 if (bih->frame_type == BEACON_FTYPE) {
958 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
959 IEEE80211_STYPE_BEACON);
960 memset(mgmt->da, 0xff, ETH_ALEN);
961 } else {
962 struct net_device *dev = ar->net_dev;
Kalle Valobdcd8172011-07-18 00:22:30 +0300963
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300964 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
965 IEEE80211_STYPE_PROBE_RESP);
966 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +0300967 }
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300968 mgmt->duration = cpu_to_le16(0);
969 memcpy(mgmt->sa, bih->bssid, ETH_ALEN);
970 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN);
971 mgmt->seq_ctrl = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +0300972
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300973 memcpy(&mgmt->u.beacon, buf, len);
974
975 bss = cfg80211_inform_bss_frame(ar->wdev->wiphy, channel, mgmt,
976 24 + len, bih->snr * 100, GFP_ATOMIC);
977 kfree(mgmt);
978 if (bss == NULL)
Kalle Valobdcd8172011-07-18 00:22:30 +0300979 return -ENOMEM;
Jouni Malinen1aaa8c72011-09-19 19:15:03 +0300980 cfg80211_put_bss(bss);
Kalle Valobdcd8172011-07-18 00:22:30 +0300981
982 return 0;
983}
984
Kalle Valobdcd8172011-07-18 00:22:30 +0300985/* Inactivity timeout of a fatpipe(pstream) at the target */
986static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
987 int len)
988{
989 struct wmi_pstream_timeout_event *ev;
990
991 if (len < sizeof(struct wmi_pstream_timeout_event))
992 return -EINVAL;
993
994 ev = (struct wmi_pstream_timeout_event *) datap;
995
996 /*
997 * When the pstream (fat pipe == AC) timesout, it means there were
998 * no thinStreams within this pstream & it got implicitly created
999 * due to data flow on this AC. We start the inactivity timer only
1000 * for implicitly created pstream. Just reset the host state.
1001 */
1002 spin_lock_bh(&wmi->lock);
1003 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1004 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1005 spin_unlock_bh(&wmi->lock);
1006
1007 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1008 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1009
1010 return 0;
1011}
1012
1013static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1014{
1015 struct wmi_bit_rate_reply *reply;
1016 s32 rate;
1017 u32 sgi, index;
1018
1019 if (len < sizeof(struct wmi_bit_rate_reply))
1020 return -EINVAL;
1021
1022 reply = (struct wmi_bit_rate_reply *) datap;
1023
1024 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1025
1026 if (reply->rate_index == (s8) RATE_AUTO) {
1027 rate = RATE_AUTO;
1028 } else {
1029 index = reply->rate_index & 0x7f;
1030 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1031 rate = wmi_rate_tbl[index][sgi];
1032 }
1033
1034 ath6kl_wakeup_event(wmi->parent_dev);
1035
1036 return 0;
1037}
1038
Kalle Valo003353b0d2011-09-01 10:14:21 +03001039static int ath6kl_wmi_tcmd_test_report_rx(struct wmi *wmi, u8 *datap, int len)
1040{
1041 ath6kl_tm_rx_report_event(wmi->parent_dev, datap, len);
1042
1043 return 0;
1044}
1045
Kalle Valobdcd8172011-07-18 00:22:30 +03001046static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1047{
1048 if (len < sizeof(struct wmi_fix_rates_reply))
1049 return -EINVAL;
1050
1051 ath6kl_wakeup_event(wmi->parent_dev);
1052
1053 return 0;
1054}
1055
1056static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1057{
1058 if (len < sizeof(struct wmi_channel_list_reply))
1059 return -EINVAL;
1060
1061 ath6kl_wakeup_event(wmi->parent_dev);
1062
1063 return 0;
1064}
1065
1066static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1067{
1068 struct wmi_tx_pwr_reply *reply;
1069
1070 if (len < sizeof(struct wmi_tx_pwr_reply))
1071 return -EINVAL;
1072
1073 reply = (struct wmi_tx_pwr_reply *) datap;
1074 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1075
1076 return 0;
1077}
1078
1079static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1080{
1081 if (len < sizeof(struct wmi_get_keepalive_cmd))
1082 return -EINVAL;
1083
1084 ath6kl_wakeup_event(wmi->parent_dev);
1085
1086 return 0;
1087}
1088
1089static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
1090{
1091 struct wmi_scan_complete_event *ev;
1092
1093 ev = (struct wmi_scan_complete_event *) datap;
1094
Kalle Valobdcd8172011-07-18 00:22:30 +03001095 ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
1096 wmi->is_probe_ssid = false;
1097
1098 return 0;
1099}
1100
1101/*
1102 * Target is reporting a programming error. This is for
1103 * developer aid only. Target only checks a few common violations
1104 * and it is responsibility of host to do all error checking.
1105 * Behavior of target after wmi error event is undefined.
1106 * A reset is recommended.
1107 */
1108static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1109{
1110 const char *type = "unknown error";
1111 struct wmi_cmd_error_event *ev;
1112 ev = (struct wmi_cmd_error_event *) datap;
1113
1114 switch (ev->err_code) {
1115 case INVALID_PARAM:
1116 type = "invalid parameter";
1117 break;
1118 case ILLEGAL_STATE:
1119 type = "invalid state";
1120 break;
1121 case INTERNAL_ERROR:
1122 type = "internal error";
1123 break;
1124 }
1125
1126 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1127 ev->cmd_id, type);
1128
1129 return 0;
1130}
1131
1132static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
1133{
1134 ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
1135
1136 return 0;
1137}
1138
1139static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1140 struct sq_threshold_params *sq_thresh,
1141 u32 size)
1142{
1143 u32 index;
1144 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1145
1146 /* The list is already in sorted order. Get the next lower value */
1147 for (index = 0; index < size; index++) {
1148 if (rssi < sq_thresh->upper_threshold[index]) {
1149 threshold = (u8) sq_thresh->upper_threshold[index];
1150 break;
1151 }
1152 }
1153
1154 return threshold;
1155}
1156
1157static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1158 struct sq_threshold_params *sq_thresh,
1159 u32 size)
1160{
1161 u32 index;
1162 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1163
1164 /* The list is already in sorted order. Get the next lower value */
1165 for (index = 0; index < size; index++) {
1166 if (rssi > sq_thresh->lower_threshold[index]) {
1167 threshold = (u8) sq_thresh->lower_threshold[index];
1168 break;
1169 }
1170 }
1171
1172 return threshold;
1173}
1174
1175static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1176 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1177{
1178 struct sk_buff *skb;
1179 struct wmi_rssi_threshold_params_cmd *cmd;
1180
1181 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1182 if (!skb)
1183 return -ENOMEM;
1184
1185 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1186 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1187
1188 return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1189 NO_SYNC_WMIFLAG);
1190}
1191
1192static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1193 int len)
1194{
1195 struct wmi_rssi_threshold_event *reply;
1196 struct wmi_rssi_threshold_params_cmd cmd;
1197 struct sq_threshold_params *sq_thresh;
1198 enum wmi_rssi_threshold_val new_threshold;
1199 u8 upper_rssi_threshold, lower_rssi_threshold;
1200 s16 rssi;
1201 int ret;
1202
1203 if (len < sizeof(struct wmi_rssi_threshold_event))
1204 return -EINVAL;
1205
1206 reply = (struct wmi_rssi_threshold_event *) datap;
1207 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1208 rssi = a_sle16_to_cpu(reply->rssi);
1209
1210 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1211
1212 /*
1213 * Identify the threshold breached and communicate that to the app.
1214 * After that install a new set of thresholds based on the signal
1215 * quality reported by the target
1216 */
1217 if (new_threshold) {
1218 /* Upper threshold breached */
1219 if (rssi < sq_thresh->upper_threshold[0]) {
1220 ath6kl_dbg(ATH6KL_DBG_WMI,
1221 "spurious upper rssi threshold event: %d\n",
1222 rssi);
1223 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1224 (rssi >= sq_thresh->upper_threshold[0])) {
1225 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1226 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1227 (rssi >= sq_thresh->upper_threshold[1])) {
1228 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1229 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1230 (rssi >= sq_thresh->upper_threshold[2])) {
1231 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1232 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1233 (rssi >= sq_thresh->upper_threshold[3])) {
1234 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1235 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1236 (rssi >= sq_thresh->upper_threshold[4])) {
1237 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1238 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1239 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1240 }
1241 } else {
1242 /* Lower threshold breached */
1243 if (rssi > sq_thresh->lower_threshold[0]) {
1244 ath6kl_dbg(ATH6KL_DBG_WMI,
1245 "spurious lower rssi threshold event: %d %d\n",
1246 rssi, sq_thresh->lower_threshold[0]);
1247 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1248 (rssi <= sq_thresh->lower_threshold[0])) {
1249 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1250 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1251 (rssi <= sq_thresh->lower_threshold[1])) {
1252 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1253 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1254 (rssi <= sq_thresh->lower_threshold[2])) {
1255 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1256 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1257 (rssi <= sq_thresh->lower_threshold[3])) {
1258 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1259 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1260 (rssi <= sq_thresh->lower_threshold[4])) {
1261 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1262 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1263 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1264 }
1265 }
1266
1267 /* Calculate and install the next set of thresholds */
1268 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1269 sq_thresh->lower_threshold_valid_count);
1270 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1271 sq_thresh->upper_threshold_valid_count);
1272
1273 /* Issue a wmi command to install the thresholds */
1274 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1275 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1276 cmd.weight = sq_thresh->weight;
1277 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1278
1279 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1280 if (ret) {
1281 ath6kl_err("unable to configure rssi thresholds\n");
1282 return -EIO;
1283 }
1284
1285 return 0;
1286}
1287
1288static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
1289{
1290 struct wmi_cac_event *reply;
1291 struct ieee80211_tspec_ie *ts;
1292 u16 active_tsids, tsinfo;
1293 u8 tsid, index;
1294 u8 ts_id;
1295
1296 if (len < sizeof(struct wmi_cac_event))
1297 return -EINVAL;
1298
1299 reply = (struct wmi_cac_event *) datap;
1300
1301 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1302 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1303
1304 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1305 tsinfo = le16_to_cpu(ts->tsinfo);
1306 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1307 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1308
1309 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
1310 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1311 /*
1312 * Following assumes that there is only one outstanding
1313 * ADDTS request when this event is received
1314 */
1315 spin_lock_bh(&wmi->lock);
1316 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1317 spin_unlock_bh(&wmi->lock);
1318
1319 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1320 if ((active_tsids >> index) & 1)
1321 break;
1322 }
1323 if (index < (sizeof(active_tsids) * 8))
1324 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
1325 }
1326
1327 /*
1328 * Clear active tsids and Add missing handling
1329 * for delete qos stream from AP
1330 */
1331 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1332
1333 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1334 tsinfo = le16_to_cpu(ts->tsinfo);
1335 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1336 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1337
1338 spin_lock_bh(&wmi->lock);
1339 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1340 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1341 spin_unlock_bh(&wmi->lock);
1342
1343 /* Indicate stream inactivity to driver layer only if all tsids
1344 * within this AC are deleted.
1345 */
1346 if (!active_tsids) {
1347 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1348 false);
1349 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1350 }
1351 }
1352
1353 return 0;
1354}
1355
1356static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1357 struct wmi_snr_threshold_params_cmd *snr_cmd)
1358{
1359 struct sk_buff *skb;
1360 struct wmi_snr_threshold_params_cmd *cmd;
1361
1362 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1363 if (!skb)
1364 return -ENOMEM;
1365
1366 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1367 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1368
1369 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1370 NO_SYNC_WMIFLAG);
1371}
1372
1373static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1374 int len)
1375{
1376 struct wmi_snr_threshold_event *reply;
1377 struct sq_threshold_params *sq_thresh;
1378 struct wmi_snr_threshold_params_cmd cmd;
1379 enum wmi_snr_threshold_val new_threshold;
1380 u8 upper_snr_threshold, lower_snr_threshold;
1381 s16 snr;
1382 int ret;
1383
1384 if (len < sizeof(struct wmi_snr_threshold_event))
1385 return -EINVAL;
1386
1387 reply = (struct wmi_snr_threshold_event *) datap;
1388
1389 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1390 snr = reply->snr;
1391
1392 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1393
1394 /*
1395 * Identify the threshold breached and communicate that to the app.
1396 * After that install a new set of thresholds based on the signal
1397 * quality reported by the target.
1398 */
1399 if (new_threshold) {
1400 /* Upper threshold breached */
1401 if (snr < sq_thresh->upper_threshold[0]) {
1402 ath6kl_dbg(ATH6KL_DBG_WMI,
1403 "spurious upper snr threshold event: %d\n",
1404 snr);
1405 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1406 (snr >= sq_thresh->upper_threshold[0])) {
1407 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1408 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1409 (snr >= sq_thresh->upper_threshold[1])) {
1410 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1411 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1412 (snr >= sq_thresh->upper_threshold[2])) {
1413 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1414 } else if (snr >= sq_thresh->upper_threshold[3]) {
1415 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1416 }
1417 } else {
1418 /* Lower threshold breached */
1419 if (snr > sq_thresh->lower_threshold[0]) {
1420 ath6kl_dbg(ATH6KL_DBG_WMI,
1421 "spurious lower snr threshold event: %d\n",
1422 sq_thresh->lower_threshold[0]);
1423 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1424 (snr <= sq_thresh->lower_threshold[0])) {
1425 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1426 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1427 (snr <= sq_thresh->lower_threshold[1])) {
1428 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1429 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1430 (snr <= sq_thresh->lower_threshold[2])) {
1431 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1432 } else if (snr <= sq_thresh->lower_threshold[3]) {
1433 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1434 }
1435 }
1436
1437 /* Calculate and install the next set of thresholds */
1438 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1439 sq_thresh->lower_threshold_valid_count);
1440 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1441 sq_thresh->upper_threshold_valid_count);
1442
1443 /* Issue a wmi command to install the thresholds */
1444 cmd.thresh_above1_val = upper_snr_threshold;
1445 cmd.thresh_below1_val = lower_snr_threshold;
1446 cmd.weight = sq_thresh->weight;
1447 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1448
1449 ath6kl_dbg(ATH6KL_DBG_WMI,
1450 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1451 snr, new_threshold,
1452 lower_snr_threshold, upper_snr_threshold);
1453
1454 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1455 if (ret) {
1456 ath6kl_err("unable to configure snr threshold\n");
1457 return -EIO;
1458 }
1459
1460 return 0;
1461}
1462
1463static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1464{
1465 u16 ap_info_entry_size;
1466 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1467 struct wmi_ap_info_v1 *ap_info_v1;
1468 u8 index;
1469
1470 if (len < sizeof(struct wmi_aplist_event) ||
1471 ev->ap_list_ver != APLIST_VER1)
1472 return -EINVAL;
1473
1474 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1475 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1476
1477 ath6kl_dbg(ATH6KL_DBG_WMI,
1478 "number of APs in aplist event: %d\n", ev->num_ap);
1479
1480 if (len < (int) (sizeof(struct wmi_aplist_event) +
1481 (ev->num_ap - 1) * ap_info_entry_size))
1482 return -EINVAL;
1483
1484 /* AP list version 1 contents */
1485 for (index = 0; index < ev->num_ap; index++) {
1486 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1487 index, ap_info_v1->bssid, ap_info_v1->channel);
1488 ap_info_v1++;
1489 }
1490
1491 return 0;
1492}
1493
1494int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
1495 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1496{
1497 struct wmi_cmd_hdr *cmd_hdr;
1498 enum htc_endpoint_id ep_id = wmi->ep_id;
1499 int ret;
1500
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001501 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: cmd_id=%d\n", __func__, cmd_id);
1502
Kalle Valobdcd8172011-07-18 00:22:30 +03001503 if (WARN_ON(skb == NULL))
1504 return -EINVAL;
1505
1506 if (sync_flag >= END_WMIFLAG) {
1507 dev_kfree_skb(skb);
1508 return -EINVAL;
1509 }
1510
1511 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1512 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1513 /*
1514 * Make sure all data currently queued is transmitted before
1515 * the cmd execution. Establish a new sync point.
1516 */
1517 ath6kl_wmi_sync_point(wmi);
1518 }
1519
1520 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1521
1522 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1523 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1524 cmd_hdr->info1 = 0; /* added for virtual interface */
1525
1526 /* Only for OPT_TX_CMD, use BE endpoint. */
1527 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1528 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1529 false, false, 0, NULL);
1530 if (ret) {
1531 dev_kfree_skb(skb);
1532 return ret;
1533 }
1534 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1535 }
1536
1537 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1538
1539 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1540 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1541 /*
1542 * Make sure all new data queued waits for the command to
1543 * execute. Establish a new sync point.
1544 */
1545 ath6kl_wmi_sync_point(wmi);
1546 }
1547
1548 return 0;
1549}
1550
1551int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
1552 enum dot11_auth_mode dot11_auth_mode,
1553 enum auth_mode auth_mode,
1554 enum crypto_type pairwise_crypto,
1555 u8 pairwise_crypto_len,
1556 enum crypto_type group_crypto,
1557 u8 group_crypto_len, int ssid_len, u8 *ssid,
1558 u8 *bssid, u16 channel, u32 ctrl_flags)
1559{
1560 struct sk_buff *skb;
1561 struct wmi_connect_cmd *cc;
1562 int ret;
1563
1564 wmi->traffic_class = 100;
1565
1566 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1567 return -EINVAL;
1568
1569 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1570 return -EINVAL;
1571
1572 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1573 if (!skb)
1574 return -ENOMEM;
1575
1576 cc = (struct wmi_connect_cmd *) skb->data;
1577
1578 if (ssid_len)
1579 memcpy(cc->ssid, ssid, ssid_len);
1580
1581 cc->ssid_len = ssid_len;
1582 cc->nw_type = nw_type;
1583 cc->dot11_auth_mode = dot11_auth_mode;
1584 cc->auth_mode = auth_mode;
1585 cc->prwise_crypto_type = pairwise_crypto;
1586 cc->prwise_crypto_len = pairwise_crypto_len;
1587 cc->grp_crypto_type = group_crypto;
1588 cc->grp_crypto_len = group_crypto_len;
1589 cc->ch = cpu_to_le16(channel);
1590 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1591
1592 if (bssid != NULL)
1593 memcpy(cc->bssid, bssid, ETH_ALEN);
1594
1595 wmi->pair_crypto_type = pairwise_crypto;
1596 wmi->grp_crypto_type = group_crypto;
1597
1598 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
1599
1600 return ret;
1601}
1602
1603int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
1604{
1605 struct sk_buff *skb;
1606 struct wmi_reconnect_cmd *cc;
1607 int ret;
1608
1609 wmi->traffic_class = 100;
1610
1611 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1612 if (!skb)
1613 return -ENOMEM;
1614
1615 cc = (struct wmi_reconnect_cmd *) skb->data;
1616 cc->channel = cpu_to_le16(channel);
1617
1618 if (bssid != NULL)
1619 memcpy(cc->bssid, bssid, ETH_ALEN);
1620
1621 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
1622 NO_SYNC_WMIFLAG);
1623
1624 return ret;
1625}
1626
1627int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
1628{
1629 int ret;
1630
1631 wmi->traffic_class = 100;
1632
1633 /* Disconnect command does not need to do a SYNC before. */
1634 ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
1635
1636 return ret;
1637}
1638
1639int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
1640 u32 force_fgscan, u32 is_legacy,
1641 u32 home_dwell_time, u32 force_scan_interval,
1642 s8 num_chan, u16 *ch_list)
1643{
1644 struct sk_buff *skb;
1645 struct wmi_start_scan_cmd *sc;
1646 s8 size;
Edward Lu1276c9e2011-08-30 21:58:00 +03001647 int i, ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03001648
1649 size = sizeof(struct wmi_start_scan_cmd);
1650
1651 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1652 return -EINVAL;
1653
1654 if (num_chan > WMI_MAX_CHANNELS)
1655 return -EINVAL;
1656
1657 if (num_chan)
1658 size += sizeof(u16) * (num_chan - 1);
1659
1660 skb = ath6kl_wmi_get_new_buf(size);
1661 if (!skb)
1662 return -ENOMEM;
1663
1664 sc = (struct wmi_start_scan_cmd *) skb->data;
1665 sc->scan_type = scan_type;
1666 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1667 sc->is_legacy = cpu_to_le32(is_legacy);
1668 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1669 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1670 sc->num_ch = num_chan;
1671
Edward Lu1276c9e2011-08-30 21:58:00 +03001672 for (i = 0; i < num_chan; i++)
1673 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001674
1675 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
1676 NO_SYNC_WMIFLAG);
1677
1678 return ret;
1679}
1680
1681int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
1682 u16 fg_end_sec, u16 bg_sec,
1683 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1684 u16 pas_chdw_msec, u8 short_scan_ratio,
1685 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1686 u16 maxact_scan_per_ssid)
1687{
1688 struct sk_buff *skb;
1689 struct wmi_scan_params_cmd *sc;
1690 int ret;
1691
1692 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1693 if (!skb)
1694 return -ENOMEM;
1695
1696 sc = (struct wmi_scan_params_cmd *) skb->data;
1697 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1698 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1699 sc->bg_period = cpu_to_le16(bg_sec);
1700 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1701 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1702 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1703 sc->short_scan_ratio = short_scan_ratio;
1704 sc->scan_ctrl_flags = scan_ctrl_flag;
1705 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1706 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1707
1708 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
1709 NO_SYNC_WMIFLAG);
1710 return ret;
1711}
1712
1713int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
1714{
1715 struct sk_buff *skb;
1716 struct wmi_bss_filter_cmd *cmd;
1717 int ret;
1718
1719 if (filter >= LAST_BSS_FILTER)
1720 return -EINVAL;
1721
1722 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1723 if (!skb)
1724 return -ENOMEM;
1725
1726 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1727 cmd->bss_filter = filter;
1728 cmd->ie_mask = cpu_to_le32(ie_mask);
1729
1730 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
1731 NO_SYNC_WMIFLAG);
1732 return ret;
1733}
1734
1735int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
1736 u8 ssid_len, u8 *ssid)
1737{
1738 struct sk_buff *skb;
1739 struct wmi_probed_ssid_cmd *cmd;
1740 int ret;
1741
1742 if (index > MAX_PROBED_SSID_INDEX)
1743 return -EINVAL;
1744
1745 if (ssid_len > sizeof(cmd->ssid))
1746 return -EINVAL;
1747
1748 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1749 return -EINVAL;
1750
1751 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1752 return -EINVAL;
1753
1754 if (flag & SPECIFIC_SSID_FLAG)
1755 wmi->is_probe_ssid = true;
1756
1757 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1758 if (!skb)
1759 return -ENOMEM;
1760
1761 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1762 cmd->entry_index = index;
1763 cmd->flag = flag;
1764 cmd->ssid_len = ssid_len;
1765 memcpy(cmd->ssid, ssid, ssid_len);
1766
1767 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
1768 NO_SYNC_WMIFLAG);
1769 return ret;
1770}
1771
1772int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
1773 u16 listen_beacons)
1774{
1775 struct sk_buff *skb;
1776 struct wmi_listen_int_cmd *cmd;
1777 int ret;
1778
1779 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1780 if (!skb)
1781 return -ENOMEM;
1782
1783 cmd = (struct wmi_listen_int_cmd *) skb->data;
1784 cmd->listen_intvl = cpu_to_le16(listen_interval);
1785 cmd->num_beacons = cpu_to_le16(listen_beacons);
1786
1787 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
1788 NO_SYNC_WMIFLAG);
1789 return ret;
1790}
1791
1792int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
1793{
1794 struct sk_buff *skb;
1795 struct wmi_power_mode_cmd *cmd;
1796 int ret;
1797
1798 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1799 if (!skb)
1800 return -ENOMEM;
1801
1802 cmd = (struct wmi_power_mode_cmd *) skb->data;
1803 cmd->pwr_mode = pwr_mode;
1804 wmi->pwr_mode = pwr_mode;
1805
1806 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
1807 NO_SYNC_WMIFLAG);
1808 return ret;
1809}
1810
1811int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
1812 u16 ps_poll_num, u16 dtim_policy,
1813 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1814 u16 ps_fail_event_policy)
1815{
1816 struct sk_buff *skb;
1817 struct wmi_power_params_cmd *pm;
1818 int ret;
1819
1820 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1821 if (!skb)
1822 return -ENOMEM;
1823
1824 pm = (struct wmi_power_params_cmd *)skb->data;
1825 pm->idle_period = cpu_to_le16(idle_period);
1826 pm->pspoll_number = cpu_to_le16(ps_poll_num);
1827 pm->dtim_policy = cpu_to_le16(dtim_policy);
1828 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1829 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1830 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1831
1832 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
1833 NO_SYNC_WMIFLAG);
1834 return ret;
1835}
1836
1837int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
1838{
1839 struct sk_buff *skb;
1840 struct wmi_disc_timeout_cmd *cmd;
1841 int ret;
1842
1843 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1844 if (!skb)
1845 return -ENOMEM;
1846
1847 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
1848 cmd->discon_timeout = timeout;
1849
1850 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
1851 NO_SYNC_WMIFLAG);
1852 return ret;
1853}
1854
1855int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
1856 enum crypto_type key_type,
1857 u8 key_usage, u8 key_len,
1858 u8 *key_rsc, u8 *key_material,
1859 u8 key_op_ctrl, u8 *mac_addr,
1860 enum wmi_sync_flag sync_flag)
1861{
1862 struct sk_buff *skb;
1863 struct wmi_add_cipher_key_cmd *cmd;
1864 int ret;
1865
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001866 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
1867 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
1868 key_index, key_type, key_usage, key_len, key_op_ctrl);
1869
Kalle Valobdcd8172011-07-18 00:22:30 +03001870 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
1871 (key_material == NULL))
1872 return -EINVAL;
1873
1874 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
1875 return -EINVAL;
1876
1877 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1878 if (!skb)
1879 return -ENOMEM;
1880
1881 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
1882 cmd->key_index = key_index;
1883 cmd->key_type = key_type;
1884 cmd->key_usage = key_usage;
1885 cmd->key_len = key_len;
1886 memcpy(cmd->key, key_material, key_len);
1887
1888 if (key_rsc != NULL)
1889 memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
1890
1891 cmd->key_op_ctrl = key_op_ctrl;
1892
1893 if (mac_addr)
1894 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
1895
1896 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
1897 sync_flag);
1898
1899 return ret;
1900}
1901
1902int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
1903{
1904 struct sk_buff *skb;
1905 struct wmi_add_krk_cmd *cmd;
1906 int ret;
1907
1908 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1909 if (!skb)
1910 return -ENOMEM;
1911
1912 cmd = (struct wmi_add_krk_cmd *) skb->data;
1913 memcpy(cmd->krk, krk, WMI_KRK_LEN);
1914
1915 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
1916
1917 return ret;
1918}
1919
1920int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
1921{
1922 struct sk_buff *skb;
1923 struct wmi_delete_cipher_key_cmd *cmd;
1924 int ret;
1925
1926 if (key_index > WMI_MAX_KEY_INDEX)
1927 return -EINVAL;
1928
1929 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1930 if (!skb)
1931 return -ENOMEM;
1932
1933 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
1934 cmd->key_index = key_index;
1935
1936 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
1937 NO_SYNC_WMIFLAG);
1938
1939 return ret;
1940}
1941
1942int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
1943 const u8 *pmkid, bool set)
1944{
1945 struct sk_buff *skb;
1946 struct wmi_setpmkid_cmd *cmd;
1947 int ret;
1948
1949 if (bssid == NULL)
1950 return -EINVAL;
1951
1952 if (set && pmkid == NULL)
1953 return -EINVAL;
1954
1955 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1956 if (!skb)
1957 return -ENOMEM;
1958
1959 cmd = (struct wmi_setpmkid_cmd *) skb->data;
1960 memcpy(cmd->bssid, bssid, ETH_ALEN);
1961 if (set) {
1962 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
1963 cmd->enable = PMKID_ENABLE;
1964 } else {
1965 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
1966 cmd->enable = PMKID_DISABLE;
1967 }
1968
1969 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
1970 NO_SYNC_WMIFLAG);
1971
1972 return ret;
1973}
1974
1975static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
1976 enum htc_endpoint_id ep_id)
1977{
1978 struct wmi_data_hdr *data_hdr;
1979 int ret;
1980
1981 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
1982 return -EINVAL;
1983
1984 skb_push(skb, sizeof(struct wmi_data_hdr));
1985
1986 data_hdr = (struct wmi_data_hdr *) skb->data;
1987 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
1988 data_hdr->info3 = 0;
1989
1990 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1991
1992 return ret;
1993}
1994
1995static int ath6kl_wmi_sync_point(struct wmi *wmi)
1996{
1997 struct sk_buff *skb;
1998 struct wmi_sync_cmd *cmd;
1999 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2000 enum htc_endpoint_id ep_id;
2001 u8 index, num_pri_streams = 0;
2002 int ret = 0;
2003
2004 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2005
2006 spin_lock_bh(&wmi->lock);
2007
2008 for (index = 0; index < WMM_NUM_AC; index++) {
2009 if (wmi->fat_pipe_exist & (1 << index)) {
2010 num_pri_streams++;
2011 data_sync_bufs[num_pri_streams - 1].traffic_class =
2012 index;
2013 }
2014 }
2015
2016 spin_unlock_bh(&wmi->lock);
2017
2018 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2019 if (!skb) {
2020 ret = -ENOMEM;
2021 goto free_skb;
2022 }
2023
2024 cmd = (struct wmi_sync_cmd *) skb->data;
2025
2026 /*
2027 * In the SYNC cmd sent on the control Ep, send a bitmap
2028 * of the data eps on which the Data Sync will be sent
2029 */
2030 cmd->data_sync_map = wmi->fat_pipe_exist;
2031
2032 for (index = 0; index < num_pri_streams; index++) {
2033 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2034 if (data_sync_bufs[index].skb == NULL) {
2035 ret = -ENOMEM;
2036 break;
2037 }
2038 }
2039
2040 /*
2041 * If buffer allocation for any of the dataSync fails,
2042 * then do not send the Synchronize cmd on the control ep
2043 */
2044 if (ret)
2045 goto free_skb;
2046
2047 /*
2048 * Send sync cmd followed by sync data messages on all
2049 * endpoints being used
2050 */
2051 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
2052 NO_SYNC_WMIFLAG);
2053
2054 if (ret)
2055 goto free_skb;
2056
2057 /* cmd buffer sent, we no longer own it */
2058 skb = NULL;
2059
2060 for (index = 0; index < num_pri_streams; index++) {
2061
2062 if (WARN_ON(!data_sync_bufs[index].skb))
2063 break;
2064
2065 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2066 data_sync_bufs[index].
2067 traffic_class);
2068 ret =
2069 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2070 ep_id);
2071
2072 if (ret)
2073 break;
2074
2075 data_sync_bufs[index].skb = NULL;
2076 }
2077
2078free_skb:
2079 /* free up any resources left over (possibly due to an error) */
2080 if (skb)
2081 dev_kfree_skb(skb);
2082
2083 for (index = 0; index < num_pri_streams; index++) {
2084 if (data_sync_bufs[index].skb != NULL) {
2085 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2086 skb);
2087 }
2088 }
2089
2090 return ret;
2091}
2092
2093int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
2094 struct wmi_create_pstream_cmd *params)
2095{
2096 struct sk_buff *skb;
2097 struct wmi_create_pstream_cmd *cmd;
2098 u8 fatpipe_exist_for_ac = 0;
2099 s32 min_phy = 0;
2100 s32 nominal_phy = 0;
2101 int ret;
2102
2103 if (!((params->user_pri < 8) &&
2104 (params->user_pri <= 0x7) &&
2105 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2106 (params->traffic_direc == UPLINK_TRAFFIC ||
2107 params->traffic_direc == DNLINK_TRAFFIC ||
2108 params->traffic_direc == BIDIR_TRAFFIC) &&
2109 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2110 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2111 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2112 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2113 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2114 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2115 params->tsid <= WMI_MAX_THINSTREAM))) {
2116 return -EINVAL;
2117 }
2118
2119 /*
2120 * Check nominal PHY rate is >= minimalPHY,
2121 * so that DUT can allow TSRS IE
2122 */
2123
2124 /* Get the physical rate (units of bps) */
2125 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2126
2127 /* Check minimal phy < nominal phy rate */
2128 if (params->nominal_phy >= min_phy) {
2129 /* unit of 500 kbps */
2130 nominal_phy = (params->nominal_phy * 1000) / 500;
2131 ath6kl_dbg(ATH6KL_DBG_WMI,
2132 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2133 min_phy, nominal_phy);
2134
2135 params->nominal_phy = nominal_phy;
2136 } else {
2137 params->nominal_phy = 0;
2138 }
2139
2140 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2141 if (!skb)
2142 return -ENOMEM;
2143
2144 ath6kl_dbg(ATH6KL_DBG_WMI,
2145 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2146 params->traffic_class, params->tsid);
2147
2148 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2149 memcpy(cmd, params, sizeof(*cmd));
2150
2151 /* This is an implicitly created Fat pipe */
2152 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2153 spin_lock_bh(&wmi->lock);
2154 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2155 (1 << params->traffic_class));
2156 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2157 spin_unlock_bh(&wmi->lock);
2158 } else {
2159 /* explicitly created thin stream within a fat pipe */
2160 spin_lock_bh(&wmi->lock);
2161 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2162 (1 << params->traffic_class));
2163 wmi->stream_exist_for_ac[params->traffic_class] |=
2164 (1 << params->tsid);
2165 /*
2166 * If a thinstream becomes active, the fat pipe automatically
2167 * becomes active
2168 */
2169 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2170 spin_unlock_bh(&wmi->lock);
2171 }
2172
2173 /*
2174 * Indicate activty change to driver layer only if this is the
2175 * first TSID to get created in this AC explicitly or an implicit
2176 * fat pipe is getting created.
2177 */
2178 if (!fatpipe_exist_for_ac)
2179 ath6kl_indicate_tx_activity(wmi->parent_dev,
2180 params->traffic_class, true);
2181
2182 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
2183 NO_SYNC_WMIFLAG);
2184 return ret;
2185}
2186
2187int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
2188{
2189 struct sk_buff *skb;
2190 struct wmi_delete_pstream_cmd *cmd;
2191 u16 active_tsids = 0;
2192 int ret;
2193
2194 if (traffic_class > 3) {
2195 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2196 return -EINVAL;
2197 }
2198
2199 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2200 if (!skb)
2201 return -ENOMEM;
2202
2203 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2204 cmd->traffic_class = traffic_class;
2205 cmd->tsid = tsid;
2206
2207 spin_lock_bh(&wmi->lock);
2208 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2209 spin_unlock_bh(&wmi->lock);
2210
2211 if (!(active_tsids & (1 << tsid))) {
2212 dev_kfree_skb(skb);
2213 ath6kl_dbg(ATH6KL_DBG_WMI,
2214 "TSID %d doesn't exist for traffic class: %d\n",
2215 tsid, traffic_class);
2216 return -ENODATA;
2217 }
2218
2219 ath6kl_dbg(ATH6KL_DBG_WMI,
2220 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2221 traffic_class, tsid);
2222
2223 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
2224 SYNC_BEFORE_WMIFLAG);
2225
2226 spin_lock_bh(&wmi->lock);
2227 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2228 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2229 spin_unlock_bh(&wmi->lock);
2230
2231 /*
2232 * Indicate stream inactivity to driver layer only if all tsids
2233 * within this AC are deleted.
2234 */
2235 if (!active_tsids) {
2236 ath6kl_indicate_tx_activity(wmi->parent_dev,
2237 traffic_class, false);
2238 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2239 }
2240
2241 return ret;
2242}
2243
2244int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2245{
2246 struct sk_buff *skb;
2247 struct wmi_set_ip_cmd *cmd;
2248 int ret;
2249
2250 /* Multicast address are not valid */
2251 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2252 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2253 return -EINVAL;
2254
2255 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2256 if (!skb)
2257 return -ENOMEM;
2258
2259 cmd = (struct wmi_set_ip_cmd *) skb->data;
2260 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2261
2262 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
2263 return ret;
2264}
2265
2266static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2267 int len)
2268{
2269 if (len < sizeof(struct wmi_get_wow_list_reply))
2270 return -EINVAL;
2271
2272 return 0;
2273}
2274
2275static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2276 enum wmix_command_id cmd_id,
2277 enum wmi_sync_flag sync_flag)
2278{
2279 struct wmix_cmd_hdr *cmd_hdr;
2280 int ret;
2281
2282 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2283
2284 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2285 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2286
2287 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
2288
2289 return ret;
2290}
2291
2292int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2293{
2294 struct sk_buff *skb;
2295 struct wmix_hb_challenge_resp_cmd *cmd;
2296 int ret;
2297
2298 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2299 if (!skb)
2300 return -ENOMEM;
2301
2302 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2303 cmd->cookie = cpu_to_le32(cookie);
2304 cmd->source = cpu_to_le32(source);
2305
2306 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2307 NO_SYNC_WMIFLAG);
2308 return ret;
2309}
2310
Kalle Valo939f1cc2011-09-02 10:32:04 +03002311int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
2312{
2313 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
2314 struct sk_buff *skb;
2315 int ret;
2316
2317 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2318 if (!skb)
2319 return -ENOMEM;
2320
2321 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
2322 cmd->valid = cpu_to_le32(valid);
2323 cmd->config = cpu_to_le32(config);
2324
2325 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
2326 NO_SYNC_WMIFLAG);
2327 return ret;
2328}
2329
Kalle Valobdcd8172011-07-18 00:22:30 +03002330int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
2331{
2332 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
2333}
2334
2335int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
2336{
2337 struct sk_buff *skb;
2338 struct wmi_set_tx_pwr_cmd *cmd;
2339 int ret;
2340
2341 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2342 if (!skb)
2343 return -ENOMEM;
2344
2345 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2346 cmd->dbM = dbM;
2347
2348 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
2349 NO_SYNC_WMIFLAG);
2350
2351 return ret;
2352}
2353
2354int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
2355{
2356 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
2357}
2358
Kalle Valobdcd8172011-07-18 00:22:30 +03002359int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
2360{
2361 struct sk_buff *skb;
2362 struct wmi_set_lpreamble_cmd *cmd;
2363 int ret;
2364
2365 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2366 if (!skb)
2367 return -ENOMEM;
2368
2369 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2370 cmd->status = status;
2371 cmd->preamble_policy = preamble_policy;
2372
2373 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
2374 NO_SYNC_WMIFLAG);
2375 return ret;
2376}
2377
2378int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2379{
2380 struct sk_buff *skb;
2381 struct wmi_set_rts_cmd *cmd;
2382 int ret;
2383
2384 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2385 if (!skb)
2386 return -ENOMEM;
2387
2388 cmd = (struct wmi_set_rts_cmd *) skb->data;
2389 cmd->threshold = cpu_to_le16(threshold);
2390
2391 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
2392 return ret;
2393}
2394
2395int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
2396{
2397 struct sk_buff *skb;
2398 struct wmi_set_wmm_txop_cmd *cmd;
2399 int ret;
2400
2401 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2402 return -EINVAL;
2403
2404 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2405 if (!skb)
2406 return -ENOMEM;
2407
2408 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2409 cmd->txop_enable = cfg;
2410
2411 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
2412 NO_SYNC_WMIFLAG);
2413 return ret;
2414}
2415
2416int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
2417{
2418 struct sk_buff *skb;
2419 struct wmi_set_keepalive_cmd *cmd;
2420 int ret;
2421
2422 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2423 if (!skb)
2424 return -ENOMEM;
2425
2426 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2427 cmd->keep_alive_intvl = keep_alive_intvl;
2428 wmi->keep_alive_intvl = keep_alive_intvl;
2429
2430 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
2431 NO_SYNC_WMIFLAG);
2432 return ret;
2433}
2434
Kalle Valo003353b0d2011-09-01 10:14:21 +03002435int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
2436{
2437 struct sk_buff *skb;
2438 int ret;
2439
2440 skb = ath6kl_wmi_get_new_buf(len);
2441 if (!skb)
2442 return -ENOMEM;
2443
2444 memcpy(skb->data, buf, len);
2445
2446 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
2447
2448 return ret;
2449}
2450
2451
Kalle Valobdcd8172011-07-18 00:22:30 +03002452s32 ath6kl_wmi_get_rate(s8 rate_index)
2453{
2454 if (rate_index == RATE_AUTO)
2455 return 0;
2456
2457 return wmi_rate_tbl[(u32) rate_index][0];
2458}
2459
Kalle Valobdcd8172011-07-18 00:22:30 +03002460static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2461 u32 len)
2462{
2463 struct wmi_pmkid_list_reply *reply;
2464 u32 expected_len;
2465
2466 if (len < sizeof(struct wmi_pmkid_list_reply))
2467 return -EINVAL;
2468
2469 reply = (struct wmi_pmkid_list_reply *)datap;
2470 expected_len = sizeof(reply->num_pmkid) +
2471 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2472
2473 if (len < expected_len)
2474 return -EINVAL;
2475
2476 return 0;
2477}
2478
2479static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2480{
2481 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2482
2483 aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
2484 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2485
2486 return 0;
2487}
2488
2489static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2490{
2491 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2492
2493 aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
2494
2495 return 0;
2496}
2497
2498/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002499
2500int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
2501{
2502 struct sk_buff *skb;
2503 struct wmi_connect_cmd *cm;
2504 int res;
2505
2506 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2507 if (!skb)
2508 return -ENOMEM;
2509
2510 cm = (struct wmi_connect_cmd *) skb->data;
2511 memcpy(cm, p, sizeof(*cm));
2512
2513 res = ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_CONFIG_COMMIT_CMDID,
2514 NO_SYNC_WMIFLAG);
2515 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2516 "ctrl_flags=0x%x-> res=%d\n",
2517 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2518 le32_to_cpu(p->ctrl_flags), res);
2519 return res;
2520}
2521
Jouni Malinen23875132011-08-30 21:57:53 +03002522int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
2523{
2524 struct sk_buff *skb;
2525 struct wmi_ap_set_mlme_cmd *cm;
2526
2527 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2528 if (!skb)
2529 return -ENOMEM;
2530
2531 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2532 memcpy(cm->mac, mac, ETH_ALEN);
2533 cm->reason = cpu_to_le16(reason);
2534 cm->cmd = cmd;
2535
2536 return ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_SET_MLME_CMDID,
2537 NO_SYNC_WMIFLAG);
2538}
2539
Kalle Valobdcd8172011-07-18 00:22:30 +03002540static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
2541{
2542 struct wmi_pspoll_event *ev;
2543
2544 if (len < sizeof(struct wmi_pspoll_event))
2545 return -EINVAL;
2546
2547 ev = (struct wmi_pspoll_event *) datap;
2548
2549 ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
2550
2551 return 0;
2552}
2553
2554static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
2555{
2556 ath6kl_dtimexpiry_event(wmi->parent_dev);
2557
2558 return 0;
2559}
2560
2561int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
2562{
2563 struct sk_buff *skb;
2564 struct wmi_ap_set_pvb_cmd *cmd;
2565 int ret;
2566
2567 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2568 if (!skb)
2569 return -ENOMEM;
2570
2571 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2572 cmd->aid = cpu_to_le16(aid);
Jouni Malinend6e51e62011-09-05 17:38:44 +03002573 cmd->rsvd = cpu_to_le16(0);
Kalle Valobdcd8172011-07-18 00:22:30 +03002574 cmd->flag = cpu_to_le32(flag);
2575
2576 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
2577 NO_SYNC_WMIFLAG);
2578
2579 return 0;
2580}
2581
2582int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
2583 bool rx_dot11_hdr, bool defrag_on_host)
2584{
2585 struct sk_buff *skb;
2586 struct wmi_rx_frame_format_cmd *cmd;
2587 int ret;
2588
2589 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2590 if (!skb)
2591 return -ENOMEM;
2592
2593 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2594 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2595 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2596 cmd->meta_ver = rx_meta_ver;
2597
2598 /* Delete the local aggr state, on host */
2599 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
2600 NO_SYNC_WMIFLAG);
2601
2602 return ret;
2603}
2604
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002605int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
2606 u8 ie_len)
2607{
2608 struct sk_buff *skb;
2609 struct wmi_set_appie_cmd *p;
2610
2611 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2612 if (!skb)
2613 return -ENOMEM;
2614
2615 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2616 "ie_len=%u\n", mgmt_frm_type, ie_len);
2617 p = (struct wmi_set_appie_cmd *) skb->data;
2618 p->mgmt_frm_type = mgmt_frm_type;
2619 p->ie_len = ie_len;
2620 memcpy(p->ie_info, ie, ie_len);
2621 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_APPIE_CMDID,
2622 NO_SYNC_WMIFLAG);
2623}
2624
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002625int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2626{
2627 struct sk_buff *skb;
2628 struct wmi_disable_11b_rates_cmd *cmd;
2629
2630 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2631 if (!skb)
2632 return -ENOMEM;
2633
2634 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2635 disable);
2636 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2637 cmd->disable = disable ? 1 : 0;
2638
2639 return ath6kl_wmi_cmd_send(wmi, skb, WMI_DISABLE_11B_RATES_CMDID,
2640 NO_SYNC_WMIFLAG);
2641}
2642
2643int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
2644{
2645 struct sk_buff *skb;
2646 struct wmi_remain_on_chnl_cmd *p;
2647
2648 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2649 if (!skb)
2650 return -ENOMEM;
2651
2652 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
2653 freq, dur);
2654 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
2655 p->freq = cpu_to_le32(freq);
2656 p->duration = cpu_to_le32(dur);
2657 return ath6kl_wmi_cmd_send(wmi, skb, WMI_REMAIN_ON_CHNL_CMDID,
2658 NO_SYNC_WMIFLAG);
2659}
2660
2661int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
2662 const u8 *data, u16 data_len)
2663{
2664 struct sk_buff *skb;
2665 struct wmi_send_action_cmd *p;
Jouni Malinena0df5db2011-08-30 21:58:02 +03002666 u8 *buf;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002667
2668 if (wait)
2669 return -EINVAL; /* Offload for wait not supported */
2670
Jouni Malinena0df5db2011-08-30 21:58:02 +03002671 buf = kmalloc(data_len, GFP_KERNEL);
2672 if (!buf)
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002673 return -ENOMEM;
2674
Jouni Malinena0df5db2011-08-30 21:58:02 +03002675 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2676 if (!skb) {
2677 kfree(buf);
2678 return -ENOMEM;
2679 }
2680
2681 kfree(wmi->last_mgmt_tx_frame);
2682 wmi->last_mgmt_tx_frame = buf;
2683 wmi->last_mgmt_tx_frame_len = data_len;
2684
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002685 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
2686 "len=%u\n", id, freq, wait, data_len);
2687 p = (struct wmi_send_action_cmd *) skb->data;
2688 p->id = cpu_to_le32(id);
2689 p->freq = cpu_to_le32(freq);
2690 p->wait = cpu_to_le32(wait);
2691 p->len = cpu_to_le16(data_len);
2692 memcpy(p->data, data, data_len);
2693 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_ACTION_CMDID,
2694 NO_SYNC_WMIFLAG);
2695}
2696
2697int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
2698 const u8 *dst,
2699 const u8 *data, u16 data_len)
2700{
2701 struct sk_buff *skb;
2702 struct wmi_p2p_probe_response_cmd *p;
2703
2704 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2705 if (!skb)
2706 return -ENOMEM;
2707
2708 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
2709 "len=%u\n", freq, dst, data_len);
2710 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
2711 p->freq = cpu_to_le32(freq);
2712 memcpy(p->destination_addr, dst, ETH_ALEN);
2713 p->len = cpu_to_le16(data_len);
2714 memcpy(p->data, data, data_len);
2715 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_PROBE_RESPONSE_CMDID,
2716 NO_SYNC_WMIFLAG);
2717}
2718
2719int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
2720{
2721 struct sk_buff *skb;
2722 struct wmi_probe_req_report_cmd *p;
2723
2724 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2725 if (!skb)
2726 return -ENOMEM;
2727
2728 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
2729 enable);
2730 p = (struct wmi_probe_req_report_cmd *) skb->data;
2731 p->enable = enable ? 1 : 0;
2732 return ath6kl_wmi_cmd_send(wmi, skb, WMI_PROBE_REQ_REPORT_CMDID,
2733 NO_SYNC_WMIFLAG);
2734}
2735
2736int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
2737{
2738 struct sk_buff *skb;
2739 struct wmi_get_p2p_info *p;
2740
2741 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2742 if (!skb)
2743 return -ENOMEM;
2744
2745 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
2746 info_req_flags);
2747 p = (struct wmi_get_p2p_info *) skb->data;
2748 p->info_req_flags = cpu_to_le32(info_req_flags);
2749 return ath6kl_wmi_cmd_send(wmi, skb, WMI_GET_P2P_INFO_CMDID,
2750 NO_SYNC_WMIFLAG);
2751}
2752
2753int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi)
2754{
2755 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
2756 return ath6kl_wmi_simple_cmd(wmi, WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
2757}
2758
Kalle Valobdcd8172011-07-18 00:22:30 +03002759static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
2760{
2761 struct wmix_cmd_hdr *cmd;
2762 u32 len;
2763 u16 id;
2764 u8 *datap;
2765 int ret = 0;
2766
2767 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
2768 ath6kl_err("bad packet 1\n");
2769 wmi->stat.cmd_len_err++;
2770 return -EINVAL;
2771 }
2772
2773 cmd = (struct wmix_cmd_hdr *) skb->data;
2774 id = le32_to_cpu(cmd->cmd_id);
2775
2776 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
2777
2778 datap = skb->data;
2779 len = skb->len;
2780
2781 switch (id) {
2782 case WMIX_HB_CHALLENGE_RESP_EVENTID:
2783 break;
2784 case WMIX_DBGLOG_EVENTID:
Kalle Valobdf53962011-09-02 10:32:04 +03002785 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002786 break;
2787 default:
2788 ath6kl_err("unknown cmd id 0x%x\n", id);
2789 wmi->stat.cmd_id_err++;
2790 ret = -EINVAL;
2791 break;
2792 }
2793
2794 return ret;
2795}
2796
2797/* Control Path */
2798int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
2799{
2800 struct wmi_cmd_hdr *cmd;
2801 u32 len;
2802 u16 id;
2803 u8 *datap;
2804 int ret = 0;
2805
2806 if (WARN_ON(skb == NULL))
2807 return -EINVAL;
2808
2809 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
2810 ath6kl_err("bad packet 1\n");
2811 dev_kfree_skb(skb);
2812 wmi->stat.cmd_len_err++;
2813 return -EINVAL;
2814 }
2815
2816 cmd = (struct wmi_cmd_hdr *) skb->data;
2817 id = le16_to_cpu(cmd->cmd_id);
2818
2819 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
2820
2821 datap = skb->data;
2822 len = skb->len;
2823
2824 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: wmi id: %d\n", __func__, id);
2825 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "msg payload ", datap, len);
2826
2827 switch (id) {
2828 case WMI_GET_BITRATE_CMDID:
2829 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
2830 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
2831 break;
2832 case WMI_GET_CHANNEL_LIST_CMDID:
2833 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
2834 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
2835 break;
2836 case WMI_GET_TX_PWR_CMDID:
2837 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
2838 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
2839 break;
2840 case WMI_READY_EVENTID:
2841 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
2842 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
2843 break;
2844 case WMI_CONNECT_EVENTID:
2845 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
2846 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
2847 break;
2848 case WMI_DISCONNECT_EVENTID:
2849 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
2850 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
2851 break;
2852 case WMI_PEER_NODE_EVENTID:
2853 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
2854 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
2855 break;
2856 case WMI_TKIP_MICERR_EVENTID:
2857 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
2858 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
2859 break;
2860 case WMI_BSSINFO_EVENTID:
2861 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
2862 ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(skb, datap);
2863 ret = ath6kl_wmi_bssinfo_event_rx(wmi, skb->data, skb->len);
2864 break;
2865 case WMI_REGDOMAIN_EVENTID:
2866 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
Vivek Natarajan06033762011-09-06 13:01:36 +05302867 ath6kl_wmi_regdomain_event(wmi, datap, len);
Kalle Valobdcd8172011-07-18 00:22:30 +03002868 break;
2869 case WMI_PSTREAM_TIMEOUT_EVENTID:
2870 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
2871 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
2872 break;
2873 case WMI_NEIGHBOR_REPORT_EVENTID:
2874 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
2875 break;
2876 case WMI_SCAN_COMPLETE_EVENTID:
2877 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
2878 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
2879 break;
2880 case WMI_CMDERROR_EVENTID:
2881 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
2882 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
2883 break;
2884 case WMI_REPORT_STATISTICS_EVENTID:
2885 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
2886 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
2887 break;
2888 case WMI_RSSI_THRESHOLD_EVENTID:
2889 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
2890 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
2891 break;
2892 case WMI_ERROR_REPORT_EVENTID:
2893 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
2894 break;
2895 case WMI_OPT_RX_FRAME_EVENTID:
2896 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
Jouni Malinenf195d502011-09-19 19:15:00 +03002897 /* this event has been deprecated */
Kalle Valobdcd8172011-07-18 00:22:30 +03002898 break;
2899 case WMI_REPORT_ROAM_TBL_EVENTID:
2900 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
2901 break;
2902 case WMI_EXTENSION_EVENTID:
2903 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
2904 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
2905 break;
2906 case WMI_CAC_EVENTID:
2907 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
2908 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
2909 break;
2910 case WMI_CHANNEL_CHANGE_EVENTID:
2911 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
2912 break;
2913 case WMI_REPORT_ROAM_DATA_EVENTID:
2914 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
2915 break;
Kalle Valo003353b0d2011-09-01 10:14:21 +03002916 case WMI_TEST_EVENTID:
2917 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
2918 ret = ath6kl_wmi_tcmd_test_report_rx(wmi, datap, len);
2919 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03002920 case WMI_GET_FIXRATES_CMDID:
2921 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
2922 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
2923 break;
2924 case WMI_TX_RETRY_ERR_EVENTID:
2925 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
2926 break;
2927 case WMI_SNR_THRESHOLD_EVENTID:
2928 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
2929 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
2930 break;
2931 case WMI_LQ_THRESHOLD_EVENTID:
2932 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
2933 break;
2934 case WMI_APLIST_EVENTID:
2935 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
2936 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
2937 break;
2938 case WMI_GET_KEEPALIVE_CMDID:
2939 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
2940 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
2941 break;
2942 case WMI_GET_WOW_LIST_EVENTID:
2943 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
2944 ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
2945 break;
2946 case WMI_GET_PMKID_LIST_EVENTID:
2947 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
2948 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
2949 break;
2950 case WMI_PSPOLL_EVENTID:
2951 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
2952 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
2953 break;
2954 case WMI_DTIMEXPIRY_EVENTID:
2955 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
2956 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
2957 break;
2958 case WMI_SET_PARAMS_REPLY_EVENTID:
2959 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
2960 break;
2961 case WMI_ADDBA_REQ_EVENTID:
2962 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
2963 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
2964 break;
2965 case WMI_ADDBA_RESP_EVENTID:
2966 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
2967 break;
2968 case WMI_DELBA_REQ_EVENTID:
2969 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
2970 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
2971 break;
2972 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
2973 ath6kl_dbg(ATH6KL_DBG_WMI,
2974 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
2975 break;
2976 case WMI_REPORT_BTCOEX_STATS_EVENTID:
2977 ath6kl_dbg(ATH6KL_DBG_WMI,
2978 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
2979 break;
2980 case WMI_TX_COMPLETE_EVENTID:
2981 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
2982 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
2983 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002984 case WMI_REMAIN_ON_CHNL_EVENTID:
2985 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03002986 ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002987 break;
2988 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
2989 ath6kl_dbg(ATH6KL_DBG_WMI,
2990 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03002991 ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
2992 len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002993 break;
2994 case WMI_TX_STATUS_EVENTID:
2995 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
Jouni Malinena0df5db2011-08-30 21:58:02 +03002996 ret = ath6kl_wmi_tx_status_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002997 break;
2998 case WMI_RX_PROBE_REQ_EVENTID:
2999 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
Jouni Malinenae32c302011-08-30 21:58:01 +03003000 ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003001 break;
3002 case WMI_P2P_CAPABILITIES_EVENTID:
3003 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3004 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3005 break;
3006 case WMI_RX_ACTION_EVENTID:
3007 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
Jouni Malinen9809d8e2011-08-30 21:58:03 +03003008 ret = ath6kl_wmi_rx_action_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003009 break;
3010 case WMI_P2P_INFO_EVENTID:
3011 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3012 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3013 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003014 default:
3015 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
3016 wmi->stat.cmd_id_err++;
3017 ret = -EINVAL;
3018 break;
3019 }
3020
3021 dev_kfree_skb(skb);
3022
3023 return ret;
3024}
3025
3026static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
3027{
3028 if (!wmi)
3029 return;
3030
3031 spin_lock_bh(&wmi->lock);
3032
3033 wmi->fat_pipe_exist = 0;
3034 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3035
3036 spin_unlock_bh(&wmi->lock);
3037}
3038
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05303039void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03003040{
3041 struct wmi *wmi;
3042
3043 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3044 if (!wmi)
3045 return NULL;
3046
3047 spin_lock_init(&wmi->lock);
3048
3049 wmi->parent_dev = dev;
3050
Kalle Valobdcd8172011-07-18 00:22:30 +03003051 ath6kl_wmi_qos_state_init(wmi);
3052
3053 wmi->pwr_mode = REC_POWER;
3054 wmi->phy_mode = WMI_11G_MODE;
3055
3056 wmi->pair_crypto_type = NONE_CRYPT;
3057 wmi->grp_crypto_type = NONE_CRYPT;
3058
3059 wmi->ht_allowed[A_BAND_24GHZ] = 1;
3060 wmi->ht_allowed[A_BAND_5GHZ] = 1;
3061
3062 return wmi;
3063}
3064
3065void ath6kl_wmi_shutdown(struct wmi *wmi)
3066{
3067 if (!wmi)
3068 return;
3069
Jouni Malinena0df5db2011-08-30 21:58:02 +03003070 kfree(wmi->last_mgmt_tx_frame);
Kalle Valobdcd8172011-07-18 00:22:30 +03003071 kfree(wmi);
3072}