blob: 9b2a1829776e56fd6745866330118585cd1a0f9e [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"
20
21static int ath6kl_wmi_sync_point(struct wmi *wmi);
22
23static const s32 wmi_rate_tbl[][2] = {
24 /* {W/O SGI, with SGI} */
25 {1000, 1000},
26 {2000, 2000},
27 {5500, 5500},
28 {11000, 11000},
29 {6000, 6000},
30 {9000, 9000},
31 {12000, 12000},
32 {18000, 18000},
33 {24000, 24000},
34 {36000, 36000},
35 {48000, 48000},
36 {54000, 54000},
37 {6500, 7200},
38 {13000, 14400},
39 {19500, 21700},
40 {26000, 28900},
41 {39000, 43300},
42 {52000, 57800},
43 {58500, 65000},
44 {65000, 72200},
45 {13500, 15000},
46 {27000, 30000},
47 {40500, 45000},
48 {54000, 60000},
49 {81000, 90000},
50 {108000, 120000},
51 {121500, 135000},
52 {135000, 150000},
53 {0, 0}
54};
55
56/* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
57static const u8 up_to_ac[] = {
58 WMM_AC_BE,
59 WMM_AC_BK,
60 WMM_AC_BK,
61 WMM_AC_BE,
62 WMM_AC_VI,
63 WMM_AC_VI,
64 WMM_AC_VO,
65 WMM_AC_VO,
66};
67
68void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
69{
70 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
71 return;
72
73 wmi->ep_id = ep_id;
74}
75
76enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
77{
78 return wmi->ep_id;
79}
80
81/* Performs DIX to 802.3 encapsulation for transmit packets.
82 * Assumes the entire DIX header is contigous and that there is
83 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
84 */
85int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
86{
87 struct ath6kl_llc_snap_hdr *llc_hdr;
88 struct ethhdr *eth_hdr;
89 size_t new_len;
90 __be16 type;
91 u8 *datap;
92 u16 size;
93
94 if (WARN_ON(skb == NULL))
95 return -EINVAL;
96
97 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
98 if (skb_headroom(skb) < size)
99 return -ENOMEM;
100
101 eth_hdr = (struct ethhdr *) skb->data;
102 type = eth_hdr->h_proto;
103
104 if (!is_ethertype(be16_to_cpu(type))) {
105 ath6kl_dbg(ATH6KL_DBG_WMI,
106 "%s: pkt is already in 802.3 format\n", __func__);
107 return 0;
108 }
109
110 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
111
112 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
113 datap = skb->data;
114
115 eth_hdr->h_proto = cpu_to_be16(new_len);
116
117 memcpy(datap, eth_hdr, sizeof(*eth_hdr));
118
119 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
120 llc_hdr->dsap = 0xAA;
121 llc_hdr->ssap = 0xAA;
122 llc_hdr->cntl = 0x03;
123 llc_hdr->org_code[0] = 0x0;
124 llc_hdr->org_code[1] = 0x0;
125 llc_hdr->org_code[2] = 0x0;
126 llc_hdr->eth_type = type;
127
128 return 0;
129}
130
131static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
132 u8 *version, void *tx_meta_info)
133{
134 struct wmi_tx_meta_v1 *v1;
135 struct wmi_tx_meta_v2 *v2;
136
137 if (WARN_ON(skb == NULL || version == NULL))
138 return -EINVAL;
139
140 switch (*version) {
141 case WMI_META_VERSION_1:
142 skb_push(skb, WMI_MAX_TX_META_SZ);
143 v1 = (struct wmi_tx_meta_v1 *) skb->data;
144 v1->pkt_id = 0;
145 v1->rate_plcy_id = 0;
146 *version = WMI_META_VERSION_1;
147 break;
148 case WMI_META_VERSION_2:
149 skb_push(skb, WMI_MAX_TX_META_SZ);
150 v2 = (struct wmi_tx_meta_v2 *) skb->data;
151 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
152 sizeof(struct wmi_tx_meta_v2));
153 break;
154 }
155
156 return 0;
157}
158
159int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
160 u8 msg_type, bool more_data,
161 enum wmi_data_hdr_data_type data_type,
162 u8 meta_ver, void *tx_meta_info)
163{
164 struct wmi_data_hdr *data_hdr;
165 int ret;
166
167 if (WARN_ON(skb == NULL))
168 return -EINVAL;
169
Vasanthakumar Thiagarajan3ce6ff52011-08-22 20:40:21 +0530170 if (tx_meta_info) {
171 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
172 if (ret)
173 return ret;
174 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300175
176 skb_push(skb, sizeof(struct wmi_data_hdr));
177
178 data_hdr = (struct wmi_data_hdr *)skb->data;
179 memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
180
181 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
182 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
183
184 if (more_data)
185 data_hdr->info |=
186 WMI_DATA_HDR_MORE_MASK << WMI_DATA_HDR_MORE_SHIFT;
187
188 data_hdr->info2 = cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
189 data_hdr->info3 = 0;
190
191 return 0;
192}
193
194static u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
195{
196 struct iphdr *ip_hdr = (struct iphdr *) pkt;
197 u8 ip_pri;
198
199 /*
200 * Determine IPTOS priority
201 *
202 * IP-TOS - 8bits
203 * : DSCP(6-bits) ECN(2-bits)
204 * : DSCP - P2 P1 P0 X X X
205 * where (P2 P1 P0) form 802.1D
206 */
207 ip_pri = ip_hdr->tos >> 5;
208 ip_pri &= 0x7;
209
210 if ((layer2_pri & 0x7) > ip_pri)
211 return (u8) layer2_pri & 0x7;
212 else
213 return ip_pri;
214}
215
216int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, struct sk_buff *skb,
217 u32 layer2_priority, bool wmm_enabled,
218 u8 *ac)
219{
220 struct wmi_data_hdr *data_hdr;
221 struct ath6kl_llc_snap_hdr *llc_hdr;
222 struct wmi_create_pstream_cmd cmd;
223 u32 meta_size, hdr_size;
224 u16 ip_type = IP_ETHERTYPE;
225 u8 stream_exist, usr_pri;
226 u8 traffic_class = WMM_AC_BE;
227 u8 *datap;
228
229 if (WARN_ON(skb == NULL))
230 return -EINVAL;
231
232 datap = skb->data;
233 data_hdr = (struct wmi_data_hdr *) datap;
234
235 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
236 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
237
238 if (!wmm_enabled) {
239 /* If WMM is disabled all traffic goes as BE traffic */
240 usr_pri = 0;
241 } else {
242 hdr_size = sizeof(struct ethhdr);
243
244 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
245 sizeof(struct
246 wmi_data_hdr) +
247 meta_size + hdr_size);
248
249 if (llc_hdr->eth_type == htons(ip_type)) {
250 /*
251 * Extract the endpoint info from the TOS field
252 * in the IP header.
253 */
254 usr_pri =
255 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
256 sizeof(struct ath6kl_llc_snap_hdr),
257 layer2_priority);
258 } else
259 usr_pri = layer2_priority & 0x7;
260 }
261
262 /* workaround for WMM S5 */
263 if ((wmi->traffic_class == WMM_AC_VI) &&
264 ((usr_pri == 5) || (usr_pri == 4)))
265 usr_pri = 1;
266
267 /* Convert user priority to traffic class */
268 traffic_class = up_to_ac[usr_pri & 0x7];
269
270 wmi_data_hdr_set_up(data_hdr, usr_pri);
271
272 spin_lock_bh(&wmi->lock);
273 stream_exist = wmi->fat_pipe_exist;
274 spin_unlock_bh(&wmi->lock);
275
276 if (!(stream_exist & (1 << traffic_class))) {
277 memset(&cmd, 0, sizeof(cmd));
278 cmd.traffic_class = traffic_class;
279 cmd.user_pri = usr_pri;
280 cmd.inactivity_int =
281 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
282 /* Implicit streams are created with TSID 0xFF */
283 cmd.tsid = WMI_IMPLICIT_PSTREAM;
284 ath6kl_wmi_create_pstream_cmd(wmi, &cmd);
285 }
286
287 *ac = traffic_class;
288
289 return 0;
290}
291
292int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
293{
294 struct ieee80211_hdr_3addr *pwh, wh;
295 struct ath6kl_llc_snap_hdr *llc_hdr;
296 struct ethhdr eth_hdr;
297 u32 hdr_size;
298 u8 *datap;
299 __le16 sub_type;
300
301 if (WARN_ON(skb == NULL))
302 return -EINVAL;
303
304 datap = skb->data;
305 pwh = (struct ieee80211_hdr_3addr *) datap;
306
307 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
308
309 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
310
311 /* Strip off the 802.11 header */
312 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
313 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
314 sizeof(u32));
315 skb_pull(skb, hdr_size);
316 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA))
317 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
318
319 datap = skb->data;
320 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
321
Raja Manic8790cba2011-07-19 19:27:32 +0530322 memset(&eth_hdr, 0, sizeof(eth_hdr));
Kalle Valobdcd8172011-07-18 00:22:30 +0300323 eth_hdr.h_proto = llc_hdr->eth_type;
Kalle Valobdcd8172011-07-18 00:22:30 +0300324
325 switch ((le16_to_cpu(wh.frame_control)) &
326 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
327 case 0:
328 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
329 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
330 break;
331 case IEEE80211_FCTL_TODS:
332 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
333 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
334 break;
335 case IEEE80211_FCTL_FROMDS:
336 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
337 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
338 break;
339 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
340 break;
341 }
342
343 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
344 skb_push(skb, sizeof(eth_hdr));
345
346 datap = skb->data;
347
348 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
349
350 return 0;
351}
352
353/*
354 * Performs 802.3 to DIX encapsulation for received packets.
355 * Assumes the entire 802.3 header is contigous.
356 */
357int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
358{
359 struct ath6kl_llc_snap_hdr *llc_hdr;
360 struct ethhdr eth_hdr;
361 u8 *datap;
362
363 if (WARN_ON(skb == NULL))
364 return -EINVAL;
365
366 datap = skb->data;
367
368 memcpy(&eth_hdr, datap, sizeof(eth_hdr));
369
370 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
371 eth_hdr.h_proto = llc_hdr->eth_type;
372
373 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
374 datap = skb->data;
375
376 memcpy(datap, &eth_hdr, sizeof(eth_hdr));
377
378 return 0;
379}
380
Kalle Valobdcd8172011-07-18 00:22:30 +0300381static void ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(struct sk_buff *skb,
382 u8 *datap)
383{
384 struct wmi_bss_info_hdr2 bih2;
385 struct wmi_bss_info_hdr *bih;
386
387 memcpy(&bih2, datap, sizeof(struct wmi_bss_info_hdr2));
388
389 skb_push(skb, 4);
390 bih = (struct wmi_bss_info_hdr *) skb->data;
391
392 bih->ch = bih2.ch;
393 bih->frame_type = bih2.frame_type;
394 bih->snr = bih2.snr;
395 bih->rssi = a_cpu_to_sle16(bih2.snr - 95);
396 bih->ie_mask = cpu_to_le32(le16_to_cpu(bih2.ie_mask));
397 memcpy(bih->bssid, bih2.bssid, ETH_ALEN);
398}
399
400static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
401{
402 struct tx_complete_msg_v1 *msg_v1;
403 struct wmi_tx_complete_event *evt;
404 int index;
405 u16 size;
406
407 evt = (struct wmi_tx_complete_event *) datap;
408
409 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
410 evt->num_msg, evt->msg_len, evt->msg_type);
411
412 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_WMI))
413 return 0;
414
415 for (index = 0; index < evt->num_msg; index++) {
416 size = sizeof(struct wmi_tx_complete_event) +
417 (index * sizeof(struct tx_complete_msg_v1));
418 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
419
420 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
421 msg_v1->status, msg_v1->pkt_id,
422 msg_v1->rate_idx, msg_v1->ack_failures);
423 }
424
425 return 0;
426}
427
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300428static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
429 int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300430{
431 struct wmi_remain_on_chnl_event *ev;
432 u32 freq;
433 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300434 struct ieee80211_channel *chan;
435 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300436
437 if (len < sizeof(*ev))
438 return -EINVAL;
439
440 ev = (struct wmi_remain_on_chnl_event *) datap;
441 freq = le32_to_cpu(ev->freq);
442 dur = le32_to_cpu(ev->duration);
443 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
444 freq, dur);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300445 chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
446 if (!chan) {
447 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: Unknown channel "
448 "(freq=%u)\n", freq);
449 return -EINVAL;
450 }
451 cfg80211_ready_on_channel(ar->net_dev, 1, chan, NL80211_CHAN_NO_HT,
452 dur, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300453
454 return 0;
455}
456
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300457static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
458 u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300459{
460 struct wmi_cancel_remain_on_chnl_event *ev;
461 u32 freq;
462 u32 dur;
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300463 struct ieee80211_channel *chan;
464 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300465
466 if (len < sizeof(*ev))
467 return -EINVAL;
468
469 ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
470 freq = le32_to_cpu(ev->freq);
471 dur = le32_to_cpu(ev->duration);
472 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: freq=%u dur=%u "
473 "status=%u\n", freq, dur, ev->status);
Jouni Malinenf9e5f052011-08-30 21:57:58 +0300474 chan = ieee80211_get_channel(ar->wdev->wiphy, freq);
475 if (!chan) {
476 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl: Unknown "
477 "channel (freq=%u)\n", freq);
478 return -EINVAL;
479 }
480 cfg80211_remain_on_channel_expired(ar->net_dev, 1, chan,
481 NL80211_CHAN_NO_HT, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300482
483 return 0;
484}
485
486static int ath6kl_wmi_tx_status_event_rx(u8 *datap, int len)
487{
488 struct wmi_tx_status_event *ev;
489 u32 id;
490
491 if (len < sizeof(*ev))
492 return -EINVAL;
493
494 ev = (struct wmi_tx_status_event *) datap;
495 id = le32_to_cpu(ev->id);
496 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
497 id, ev->ack_status);
498
499 return 0;
500}
501
Jouni Malinenae32c302011-08-30 21:58:01 +0300502static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len)
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300503{
504 struct wmi_p2p_rx_probe_req_event *ev;
Jouni Malinenae32c302011-08-30 21:58:01 +0300505 u32 freq;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300506 u16 dlen;
Jouni Malinenae32c302011-08-30 21:58:01 +0300507 struct ath6kl *ar = wmi->parent_dev;
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300508
509 if (len < sizeof(*ev))
510 return -EINVAL;
511
512 ev = (struct wmi_p2p_rx_probe_req_event *) datap;
Jouni Malinenae32c302011-08-30 21:58:01 +0300513 freq = le32_to_cpu(ev->freq);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300514 dlen = le16_to_cpu(ev->len);
Jouni Malinenae32c302011-08-30 21:58:01 +0300515 if (datap + len < ev->data + dlen) {
516 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: "
517 "len=%d dlen=%u\n", len, dlen);
518 return -EINVAL;
519 }
520 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_probe_req: len=%u freq=%u "
521 "probe_req_report=%d\n",
522 dlen, freq, ar->probe_req_report);
523
524 if (ar->probe_req_report || ar->nw_type == AP_NETWORK)
525 cfg80211_rx_mgmt(ar->net_dev, freq, ev->data, dlen, GFP_ATOMIC);
Jouni Malinen6465ddc2011-08-30 21:57:54 +0300526
527 return 0;
528}
529
530static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
531{
532 struct wmi_p2p_capabilities_event *ev;
533 u16 dlen;
534
535 if (len < sizeof(*ev))
536 return -EINVAL;
537
538 ev = (struct wmi_p2p_capabilities_event *) datap;
539 dlen = le16_to_cpu(ev->len);
540 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
541
542 return 0;
543}
544
545static int ath6kl_wmi_rx_action_event_rx(u8 *datap, int len)
546{
547 struct wmi_rx_action_event *ev;
548 u16 dlen;
549
550 if (len < sizeof(*ev))
551 return -EINVAL;
552
553 ev = (struct wmi_rx_action_event *) datap;
554 dlen = le16_to_cpu(ev->len);
555 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u\n", dlen);
556
557 return 0;
558}
559
560static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
561{
562 struct wmi_p2p_info_event *ev;
563 u32 flags;
564 u16 dlen;
565
566 if (len < sizeof(*ev))
567 return -EINVAL;
568
569 ev = (struct wmi_p2p_info_event *) datap;
570 flags = le32_to_cpu(ev->info_req_flags);
571 dlen = le16_to_cpu(ev->len);
572 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
573
574 if (flags & P2P_FLAG_CAPABILITIES_REQ) {
575 struct wmi_p2p_capabilities *cap;
576 if (dlen < sizeof(*cap))
577 return -EINVAL;
578 cap = (struct wmi_p2p_capabilities *) ev->data;
579 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
580 cap->go_power_save);
581 }
582
583 if (flags & P2P_FLAG_MACADDR_REQ) {
584 struct wmi_p2p_macaddr *mac;
585 if (dlen < sizeof(*mac))
586 return -EINVAL;
587 mac = (struct wmi_p2p_macaddr *) ev->data;
588 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
589 mac->mac_addr);
590 }
591
592 if (flags & P2P_FLAG_HMODEL_REQ) {
593 struct wmi_p2p_hmodel *mod;
594 if (dlen < sizeof(*mod))
595 return -EINVAL;
596 mod = (struct wmi_p2p_hmodel *) ev->data;
597 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
598 mod->p2p_model,
599 mod->p2p_model ? "host" : "firmware");
600 }
601 return 0;
602}
603
Kalle Valobdcd8172011-07-18 00:22:30 +0300604static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
605{
606 struct sk_buff *skb;
607
608 skb = ath6kl_buf_alloc(size);
609 if (!skb)
610 return NULL;
611
612 skb_put(skb, size);
613 if (size)
614 memset(skb->data, 0, size);
615
616 return skb;
617}
618
619/* Send a "simple" wmi command -- one with no arguments */
620static int ath6kl_wmi_simple_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id)
621{
622 struct sk_buff *skb;
623 int ret;
624
625 skb = ath6kl_wmi_get_new_buf(0);
626 if (!skb)
627 return -ENOMEM;
628
629 ret = ath6kl_wmi_cmd_send(wmi, skb, cmd_id, NO_SYNC_WMIFLAG);
630
631 return ret;
632}
633
634static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
635{
636 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
637
638 if (len < sizeof(struct wmi_ready_event_2))
639 return -EINVAL;
640
641 wmi->ready = true;
642 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
643 le32_to_cpu(ev->sw_version),
644 le32_to_cpu(ev->abi_version));
645
646 return 0;
647}
648
649static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len)
650{
651 struct wmi_connect_event *ev;
652 u8 *pie, *peie;
653
654 if (len < sizeof(struct wmi_connect_event))
655 return -EINVAL;
656
657 ev = (struct wmi_connect_event *) datap;
658
659 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: freq %d bssid %pM\n",
660 __func__, ev->ch, ev->bssid);
661
Kalle Valobdcd8172011-07-18 00:22:30 +0300662 /* Start of assoc rsp IEs */
663 pie = ev->assoc_info + ev->beacon_ie_len +
664 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
665
666 /* End of assoc rsp IEs */
667 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
668 ev->assoc_resp_len;
669
670 while (pie < peie) {
671 switch (*pie) {
672 case WLAN_EID_VENDOR_SPECIFIC:
673 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
674 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
675 /* WMM OUT (00:50:F2) */
676 if (pie[1] > 5
677 && pie[6] == WMM_PARAM_OUI_SUBTYPE)
678 wmi->is_wmm_enabled = true;
679 }
680 break;
681 }
682
683 if (wmi->is_wmm_enabled)
684 break;
685
686 pie += pie[1] + 2;
687 }
688
689 ath6kl_connect_event(wmi->parent_dev, le16_to_cpu(ev->ch), ev->bssid,
690 le16_to_cpu(ev->listen_intvl),
691 le16_to_cpu(ev->beacon_intvl),
692 le32_to_cpu(ev->nw_type),
693 ev->beacon_ie_len, ev->assoc_req_len,
694 ev->assoc_resp_len, ev->assoc_info);
695
696 return 0;
697}
698
699static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len)
700{
701 struct wmi_disconnect_event *ev;
702 wmi->traffic_class = 100;
703
704 if (len < sizeof(struct wmi_disconnect_event))
705 return -EINVAL;
706
707 ev = (struct wmi_disconnect_event *) datap;
Kalle Valobdcd8172011-07-18 00:22:30 +0300708
709 wmi->is_wmm_enabled = false;
710 wmi->pair_crypto_type = NONE_CRYPT;
711 wmi->grp_crypto_type = NONE_CRYPT;
712
713 ath6kl_disconnect_event(wmi->parent_dev, ev->disconn_reason,
714 ev->bssid, ev->assoc_resp_len, ev->assoc_info,
715 le16_to_cpu(ev->proto_reason_status));
716
717 return 0;
718}
719
720static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
721{
722 struct wmi_peer_node_event *ev;
723
724 if (len < sizeof(struct wmi_peer_node_event))
725 return -EINVAL;
726
727 ev = (struct wmi_peer_node_event *) datap;
728
729 if (ev->event_code == PEER_NODE_JOIN_EVENT)
730 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
731 ev->peer_mac_addr);
732 else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
733 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
734 ev->peer_mac_addr);
735
736 return 0;
737}
738
739static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len)
740{
741 struct wmi_tkip_micerr_event *ev;
742
743 if (len < sizeof(struct wmi_tkip_micerr_event))
744 return -EINVAL;
745
746 ev = (struct wmi_tkip_micerr_event *) datap;
747
748 ath6kl_tkip_micerr_event(wmi->parent_dev, ev->key_id, ev->is_mcast);
749
750 return 0;
751}
752
753static int ath6kl_wlan_parse_beacon(u8 *buf, int frame_len,
754 struct ath6kl_common_ie *cie)
755{
756 u8 *frm, *efrm;
757 u8 elemid_ssid = false;
758
759 frm = buf;
760 efrm = (u8 *) (frm + frame_len);
761
762 /*
763 * beacon/probe response frame format
764 * [8] time stamp
765 * [2] beacon interval
766 * [2] capability information
767 * [tlv] ssid
768 * [tlv] supported rates
769 * [tlv] country information
770 * [tlv] parameter set (FH/DS)
771 * [tlv] erp information
772 * [tlv] extended supported rates
773 * [tlv] WMM
774 * [tlv] WPA or RSN
775 * [tlv] Atheros Advanced Capabilities
776 */
777 if ((efrm - frm) < 12)
778 return -EINVAL;
779
780 memset(cie, 0, sizeof(*cie));
781
782 cie->ie_tstamp = frm;
783 frm += 8;
784 cie->ie_beaconInt = *(u16 *) frm;
785 frm += 2;
786 cie->ie_capInfo = *(u16 *) frm;
787 frm += 2;
788 cie->ie_chan = 0;
789
790 while (frm < efrm) {
791 switch (*frm) {
792 case WLAN_EID_SSID:
793 if (!elemid_ssid) {
794 cie->ie_ssid = frm;
795 elemid_ssid = true;
796 }
797 break;
798 case WLAN_EID_SUPP_RATES:
799 cie->ie_rates = frm;
800 break;
801 case WLAN_EID_COUNTRY:
802 cie->ie_country = frm;
803 break;
804 case WLAN_EID_FH_PARAMS:
805 break;
806 case WLAN_EID_DS_PARAMS:
807 cie->ie_chan = frm[2];
808 break;
809 case WLAN_EID_TIM:
810 cie->ie_tim = frm;
811 break;
812 case WLAN_EID_IBSS_PARAMS:
813 break;
814 case WLAN_EID_EXT_SUPP_RATES:
815 cie->ie_xrates = frm;
816 break;
817 case WLAN_EID_ERP_INFO:
818 if (frm[1] != 1)
819 return -EINVAL;
820
821 cie->ie_erp = frm[2];
822 break;
823 case WLAN_EID_RSN:
824 cie->ie_rsn = frm;
825 break;
826 case WLAN_EID_HT_CAPABILITY:
827 cie->ie_htcap = frm;
828 break;
829 case WLAN_EID_HT_INFORMATION:
830 cie->ie_htop = frm;
831 break;
832 case WLAN_EID_VENDOR_SPECIFIC:
833 if (frm[1] > 3 && frm[2] == 0x00 && frm[3] == 0x50 &&
834 frm[4] == 0xf2) {
835 /* OUT Type (00:50:F2) */
836
837 if (frm[5] == WPA_OUI_TYPE) {
838 /* WPA OUT */
839 cie->ie_wpa = frm;
840 } else if (frm[5] == WMM_OUI_TYPE) {
841 /* WMM OUT */
842 cie->ie_wmm = frm;
843 } else if (frm[5] == WSC_OUT_TYPE) {
844 /* WSC OUT */
845 cie->ie_wsc = frm;
846 }
847
848 } else if (frm[1] > 3 && frm[2] == 0x00
849 && frm[3] == 0x03 && frm[4] == 0x7f
850 && frm[5] == ATH_OUI_TYPE) {
851 /* Atheros OUI (00:03:7f) */
852 cie->ie_ath = frm;
853 }
854 break;
855 default:
856 break;
857 }
858 frm += frm[1] + 2;
859 }
860
861 if ((cie->ie_rates == NULL)
862 || (cie->ie_rates[1] > ATH6KL_RATE_MAXSIZE))
863 return -EINVAL;
864
865 if ((cie->ie_ssid == NULL)
866 || (cie->ie_ssid[1] > IEEE80211_MAX_SSID_LEN))
867 return -EINVAL;
868
869 return 0;
870}
871
872static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len)
873{
874 struct bss *bss = NULL;
875 struct wmi_bss_info_hdr *bih;
876 u8 cached_ssid_len = 0;
877 u8 cached_ssid[IEEE80211_MAX_SSID_LEN] = { 0 };
878 u8 beacon_ssid_len = 0;
879 u8 *buf, *ie_ssid;
880 u8 *ni_buf;
881 int buf_len;
882
883 int ret;
884
885 if (len <= sizeof(struct wmi_bss_info_hdr))
886 return -EINVAL;
887
888 bih = (struct wmi_bss_info_hdr *) datap;
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +0530889 bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
Kalle Valobdcd8172011-07-18 00:22:30 +0300890
891 if (a_sle16_to_cpu(bih->rssi) > 0) {
892 if (bss == NULL)
893 return 0;
894 else
895 bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
896 }
897
898 buf = datap + sizeof(struct wmi_bss_info_hdr);
899 len -= sizeof(struct wmi_bss_info_hdr);
900
901 ath6kl_dbg(ATH6KL_DBG_WMI,
902 "bss info evt - ch %u, rssi %02x, bssid \"%pM\"\n",
903 bih->ch, a_sle16_to_cpu(bih->rssi), bih->bssid);
904
905 if (bss != NULL) {
906 /*
907 * Free up the node. We are about to allocate a new node.
908 * In case of hidden AP, beacon will not have ssid,
909 * but a directed probe response will have it,
910 * so cache the probe-resp-ssid if already present.
911 */
912 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE)) {
913 ie_ssid = bss->ni_cie.ie_ssid;
914 if (ie_ssid && (ie_ssid[1] <= IEEE80211_MAX_SSID_LEN) &&
915 (ie_ssid[2] != 0)) {
916 cached_ssid_len = ie_ssid[1];
917 memcpy(cached_ssid, ie_ssid + 2,
918 cached_ssid_len);
919 }
920 }
921
922 /*
923 * Use the current average rssi of associated AP base on
924 * assumption
925 * 1. Most os with GUI will update RSSI by
926 * ath6kl_wmi_get_stats_cmd() periodically.
927 * 2. ath6kl_wmi_get_stats_cmd(..) will be called when calling
928 * ath6kl_wmi_startscan_cmd(...)
929 * The average value of RSSI give end-user better feeling for
930 * instance value of scan result. It also sync up RSSI info
931 * in GUI between scan result and RSSI signal icon.
932 */
Vasanthakumar Thiagarajan70df0512011-07-21 14:09:07 +0530933 if (memcmp(wmi->parent_dev->bssid, bih->bssid, ETH_ALEN) == 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300934 bih->rssi = a_cpu_to_sle16(bss->ni_rssi);
935 bih->snr = bss->ni_snr;
936 }
937
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +0530938 wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
Kalle Valobdcd8172011-07-18 00:22:30 +0300939 }
940
941 /*
942 * beacon/probe response frame format
943 * [8] time stamp
944 * [2] beacon interval
945 * [2] capability information
946 * [tlv] ssid
947 */
948 beacon_ssid_len = buf[SSID_IE_LEN_INDEX];
949
950 /*
951 * If ssid is cached for this hidden AP, then change
952 * buffer len accordingly.
953 */
954 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
955 (cached_ssid_len != 0) &&
956 (beacon_ssid_len == 0 || (cached_ssid_len > beacon_ssid_len &&
957 buf[SSID_IE_LEN_INDEX + 1] == 0))) {
958
959 len += (cached_ssid_len - beacon_ssid_len);
960 }
961
962 bss = wlan_node_alloc(len);
963 if (!bss)
964 return -ENOMEM;
965
966 bss->ni_snr = bih->snr;
967 bss->ni_rssi = a_sle16_to_cpu(bih->rssi);
968
969 if (WARN_ON(!bss->ni_buf))
970 return -EINVAL;
971
972 /*
973 * In case of hidden AP, beacon will not have ssid,
974 * but a directed probe response will have it,
975 * so place the cached-ssid(probe-resp) in the bss info.
976 */
977 if (wmi->is_probe_ssid && (bih->frame_type == BEACON_FTYPE) &&
978 (cached_ssid_len != 0) &&
979 (beacon_ssid_len == 0 || (beacon_ssid_len &&
980 buf[SSID_IE_LEN_INDEX + 1] == 0))) {
981 ni_buf = bss->ni_buf;
982 buf_len = len;
983
984 /*
985 * Copy the first 14 bytes:
986 * time-stamp(8), beacon-interval(2),
987 * cap-info(2), ssid-id(1), ssid-len(1).
988 */
989 memcpy(ni_buf, buf, SSID_IE_LEN_INDEX + 1);
990
991 ni_buf[SSID_IE_LEN_INDEX] = cached_ssid_len;
992 ni_buf += (SSID_IE_LEN_INDEX + 1);
993
994 buf += (SSID_IE_LEN_INDEX + 1);
995 buf_len -= (SSID_IE_LEN_INDEX + 1);
996
997 memcpy(ni_buf, cached_ssid, cached_ssid_len);
998 ni_buf += cached_ssid_len;
999
1000 buf += beacon_ssid_len;
1001 buf_len -= beacon_ssid_len;
1002
1003 if (cached_ssid_len > beacon_ssid_len)
1004 buf_len -= (cached_ssid_len - beacon_ssid_len);
1005
1006 memcpy(ni_buf, buf, buf_len);
1007 } else
1008 memcpy(bss->ni_buf, buf, len);
1009
1010 bss->ni_framelen = len;
1011
1012 ret = ath6kl_wlan_parse_beacon(bss->ni_buf, len, &bss->ni_cie);
1013 if (ret) {
1014 wlan_node_free(bss);
1015 return -EINVAL;
1016 }
1017
1018 /*
1019 * Update the frequency in ie_chan, overwriting of channel number
1020 * which is done in ath6kl_wlan_parse_beacon
1021 */
1022 bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05301023 wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001024
1025 return 0;
1026}
1027
1028static int ath6kl_wmi_opt_frame_event_rx(struct wmi *wmi, u8 *datap, int len)
1029{
1030 struct bss *bss;
1031 struct wmi_opt_rx_info_hdr *bih;
1032 u8 *buf;
1033
1034 if (len <= sizeof(struct wmi_opt_rx_info_hdr))
1035 return -EINVAL;
1036
1037 bih = (struct wmi_opt_rx_info_hdr *) datap;
1038 buf = datap + sizeof(struct wmi_opt_rx_info_hdr);
1039 len -= sizeof(struct wmi_opt_rx_info_hdr);
1040
1041 ath6kl_dbg(ATH6KL_DBG_WMI, "opt frame event %2.2x:%2.2x\n",
1042 bih->bssid[4], bih->bssid[5]);
1043
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05301044 bss = wlan_find_node(&wmi->parent_dev->scan_table, bih->bssid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001045 if (bss != NULL) {
1046 /* Free up the node. We are about to allocate a new node. */
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05301047 wlan_node_reclaim(&wmi->parent_dev->scan_table, bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03001048 }
1049
1050 bss = wlan_node_alloc(len);
1051 if (!bss)
1052 return -ENOMEM;
1053
1054 bss->ni_snr = bih->snr;
1055 bss->ni_cie.ie_chan = le16_to_cpu(bih->ch);
1056
1057 if (WARN_ON(!bss->ni_buf))
1058 return -EINVAL;
1059
1060 memcpy(bss->ni_buf, buf, len);
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05301061 wlan_setup_node(&wmi->parent_dev->scan_table, bss, bih->bssid);
Kalle Valobdcd8172011-07-18 00:22:30 +03001062
1063 return 0;
1064}
1065
1066/* Inactivity timeout of a fatpipe(pstream) at the target */
1067static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
1068 int len)
1069{
1070 struct wmi_pstream_timeout_event *ev;
1071
1072 if (len < sizeof(struct wmi_pstream_timeout_event))
1073 return -EINVAL;
1074
1075 ev = (struct wmi_pstream_timeout_event *) datap;
1076
1077 /*
1078 * When the pstream (fat pipe == AC) timesout, it means there were
1079 * no thinStreams within this pstream & it got implicitly created
1080 * due to data flow on this AC. We start the inactivity timer only
1081 * for implicitly created pstream. Just reset the host state.
1082 */
1083 spin_lock_bh(&wmi->lock);
1084 wmi->stream_exist_for_ac[ev->traffic_class] = 0;
1085 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
1086 spin_unlock_bh(&wmi->lock);
1087
1088 /* Indicate inactivity to driver layer for this fatpipe (pstream) */
1089 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
1090
1091 return 0;
1092}
1093
1094static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
1095{
1096 struct wmi_bit_rate_reply *reply;
1097 s32 rate;
1098 u32 sgi, index;
1099
1100 if (len < sizeof(struct wmi_bit_rate_reply))
1101 return -EINVAL;
1102
1103 reply = (struct wmi_bit_rate_reply *) datap;
1104
1105 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
1106
1107 if (reply->rate_index == (s8) RATE_AUTO) {
1108 rate = RATE_AUTO;
1109 } else {
1110 index = reply->rate_index & 0x7f;
1111 sgi = (reply->rate_index & 0x80) ? 1 : 0;
1112 rate = wmi_rate_tbl[index][sgi];
1113 }
1114
1115 ath6kl_wakeup_event(wmi->parent_dev);
1116
1117 return 0;
1118}
1119
1120static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
1121{
1122 if (len < sizeof(struct wmi_fix_rates_reply))
1123 return -EINVAL;
1124
1125 ath6kl_wakeup_event(wmi->parent_dev);
1126
1127 return 0;
1128}
1129
1130static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
1131{
1132 if (len < sizeof(struct wmi_channel_list_reply))
1133 return -EINVAL;
1134
1135 ath6kl_wakeup_event(wmi->parent_dev);
1136
1137 return 0;
1138}
1139
1140static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
1141{
1142 struct wmi_tx_pwr_reply *reply;
1143
1144 if (len < sizeof(struct wmi_tx_pwr_reply))
1145 return -EINVAL;
1146
1147 reply = (struct wmi_tx_pwr_reply *) datap;
1148 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
1149
1150 return 0;
1151}
1152
1153static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
1154{
1155 if (len < sizeof(struct wmi_get_keepalive_cmd))
1156 return -EINVAL;
1157
1158 ath6kl_wakeup_event(wmi->parent_dev);
1159
1160 return 0;
1161}
1162
1163static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len)
1164{
1165 struct wmi_scan_complete_event *ev;
1166
1167 ev = (struct wmi_scan_complete_event *) datap;
1168
1169 if (a_sle32_to_cpu(ev->status) == 0)
Vasanthakumar Thiagarajane4c7ffc2011-07-21 13:49:32 +05301170 wlan_refresh_inactive_nodes(wmi->parent_dev);
Kalle Valobdcd8172011-07-18 00:22:30 +03001171
1172 ath6kl_scan_complete_evt(wmi->parent_dev, a_sle32_to_cpu(ev->status));
1173 wmi->is_probe_ssid = false;
1174
1175 return 0;
1176}
1177
1178/*
1179 * Target is reporting a programming error. This is for
1180 * developer aid only. Target only checks a few common violations
1181 * and it is responsibility of host to do all error checking.
1182 * Behavior of target after wmi error event is undefined.
1183 * A reset is recommended.
1184 */
1185static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
1186{
1187 const char *type = "unknown error";
1188 struct wmi_cmd_error_event *ev;
1189 ev = (struct wmi_cmd_error_event *) datap;
1190
1191 switch (ev->err_code) {
1192 case INVALID_PARAM:
1193 type = "invalid parameter";
1194 break;
1195 case ILLEGAL_STATE:
1196 type = "invalid state";
1197 break;
1198 case INTERNAL_ERROR:
1199 type = "internal error";
1200 break;
1201 }
1202
1203 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
1204 ev->cmd_id, type);
1205
1206 return 0;
1207}
1208
1209static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len)
1210{
1211 ath6kl_tgt_stats_event(wmi->parent_dev, datap, len);
1212
1213 return 0;
1214}
1215
1216static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
1217 struct sq_threshold_params *sq_thresh,
1218 u32 size)
1219{
1220 u32 index;
1221 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
1222
1223 /* The list is already in sorted order. Get the next lower value */
1224 for (index = 0; index < size; index++) {
1225 if (rssi < sq_thresh->upper_threshold[index]) {
1226 threshold = (u8) sq_thresh->upper_threshold[index];
1227 break;
1228 }
1229 }
1230
1231 return threshold;
1232}
1233
1234static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
1235 struct sq_threshold_params *sq_thresh,
1236 u32 size)
1237{
1238 u32 index;
1239 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
1240
1241 /* The list is already in sorted order. Get the next lower value */
1242 for (index = 0; index < size; index++) {
1243 if (rssi > sq_thresh->lower_threshold[index]) {
1244 threshold = (u8) sq_thresh->lower_threshold[index];
1245 break;
1246 }
1247 }
1248
1249 return threshold;
1250}
1251
1252static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
1253 struct wmi_rssi_threshold_params_cmd *rssi_cmd)
1254{
1255 struct sk_buff *skb;
1256 struct wmi_rssi_threshold_params_cmd *cmd;
1257
1258 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1259 if (!skb)
1260 return -ENOMEM;
1261
1262 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
1263 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
1264
1265 return ath6kl_wmi_cmd_send(wmi, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
1266 NO_SYNC_WMIFLAG);
1267}
1268
1269static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
1270 int len)
1271{
1272 struct wmi_rssi_threshold_event *reply;
1273 struct wmi_rssi_threshold_params_cmd cmd;
1274 struct sq_threshold_params *sq_thresh;
1275 enum wmi_rssi_threshold_val new_threshold;
1276 u8 upper_rssi_threshold, lower_rssi_threshold;
1277 s16 rssi;
1278 int ret;
1279
1280 if (len < sizeof(struct wmi_rssi_threshold_event))
1281 return -EINVAL;
1282
1283 reply = (struct wmi_rssi_threshold_event *) datap;
1284 new_threshold = (enum wmi_rssi_threshold_val) reply->range;
1285 rssi = a_sle16_to_cpu(reply->rssi);
1286
1287 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
1288
1289 /*
1290 * Identify the threshold breached and communicate that to the app.
1291 * After that install a new set of thresholds based on the signal
1292 * quality reported by the target
1293 */
1294 if (new_threshold) {
1295 /* Upper threshold breached */
1296 if (rssi < sq_thresh->upper_threshold[0]) {
1297 ath6kl_dbg(ATH6KL_DBG_WMI,
1298 "spurious upper rssi threshold event: %d\n",
1299 rssi);
1300 } else if ((rssi < sq_thresh->upper_threshold[1]) &&
1301 (rssi >= sq_thresh->upper_threshold[0])) {
1302 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
1303 } else if ((rssi < sq_thresh->upper_threshold[2]) &&
1304 (rssi >= sq_thresh->upper_threshold[1])) {
1305 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
1306 } else if ((rssi < sq_thresh->upper_threshold[3]) &&
1307 (rssi >= sq_thresh->upper_threshold[2])) {
1308 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
1309 } else if ((rssi < sq_thresh->upper_threshold[4]) &&
1310 (rssi >= sq_thresh->upper_threshold[3])) {
1311 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
1312 } else if ((rssi < sq_thresh->upper_threshold[5]) &&
1313 (rssi >= sq_thresh->upper_threshold[4])) {
1314 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
1315 } else if (rssi >= sq_thresh->upper_threshold[5]) {
1316 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
1317 }
1318 } else {
1319 /* Lower threshold breached */
1320 if (rssi > sq_thresh->lower_threshold[0]) {
1321 ath6kl_dbg(ATH6KL_DBG_WMI,
1322 "spurious lower rssi threshold event: %d %d\n",
1323 rssi, sq_thresh->lower_threshold[0]);
1324 } else if ((rssi > sq_thresh->lower_threshold[1]) &&
1325 (rssi <= sq_thresh->lower_threshold[0])) {
1326 new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
1327 } else if ((rssi > sq_thresh->lower_threshold[2]) &&
1328 (rssi <= sq_thresh->lower_threshold[1])) {
1329 new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
1330 } else if ((rssi > sq_thresh->lower_threshold[3]) &&
1331 (rssi <= sq_thresh->lower_threshold[2])) {
1332 new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
1333 } else if ((rssi > sq_thresh->lower_threshold[4]) &&
1334 (rssi <= sq_thresh->lower_threshold[3])) {
1335 new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
1336 } else if ((rssi > sq_thresh->lower_threshold[5]) &&
1337 (rssi <= sq_thresh->lower_threshold[4])) {
1338 new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
1339 } else if (rssi <= sq_thresh->lower_threshold[5]) {
1340 new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
1341 }
1342 }
1343
1344 /* Calculate and install the next set of thresholds */
1345 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
1346 sq_thresh->lower_threshold_valid_count);
1347 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
1348 sq_thresh->upper_threshold_valid_count);
1349
1350 /* Issue a wmi command to install the thresholds */
1351 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
1352 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
1353 cmd.weight = sq_thresh->weight;
1354 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1355
1356 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
1357 if (ret) {
1358 ath6kl_err("unable to configure rssi thresholds\n");
1359 return -EIO;
1360 }
1361
1362 return 0;
1363}
1364
1365static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len)
1366{
1367 struct wmi_cac_event *reply;
1368 struct ieee80211_tspec_ie *ts;
1369 u16 active_tsids, tsinfo;
1370 u8 tsid, index;
1371 u8 ts_id;
1372
1373 if (len < sizeof(struct wmi_cac_event))
1374 return -EINVAL;
1375
1376 reply = (struct wmi_cac_event *) datap;
1377
1378 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
1379 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
1380
1381 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1382 tsinfo = le16_to_cpu(ts->tsinfo);
1383 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1384 IEEE80211_WMM_IE_TSPEC_TID_MASK;
1385
1386 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, tsid);
1387 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
1388 /*
1389 * Following assumes that there is only one outstanding
1390 * ADDTS request when this event is received
1391 */
1392 spin_lock_bh(&wmi->lock);
1393 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1394 spin_unlock_bh(&wmi->lock);
1395
1396 for (index = 0; index < sizeof(active_tsids) * 8; index++) {
1397 if ((active_tsids >> index) & 1)
1398 break;
1399 }
1400 if (index < (sizeof(active_tsids) * 8))
1401 ath6kl_wmi_delete_pstream_cmd(wmi, reply->ac, index);
1402 }
1403
1404 /*
1405 * Clear active tsids and Add missing handling
1406 * for delete qos stream from AP
1407 */
1408 else if (reply->cac_indication == CAC_INDICATION_DELETE) {
1409
1410 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
1411 tsinfo = le16_to_cpu(ts->tsinfo);
1412 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
1413 IEEE80211_WMM_IE_TSPEC_TID_MASK);
1414
1415 spin_lock_bh(&wmi->lock);
1416 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
1417 active_tsids = wmi->stream_exist_for_ac[reply->ac];
1418 spin_unlock_bh(&wmi->lock);
1419
1420 /* Indicate stream inactivity to driver layer only if all tsids
1421 * within this AC are deleted.
1422 */
1423 if (!active_tsids) {
1424 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
1425 false);
1426 wmi->fat_pipe_exist &= ~(1 << reply->ac);
1427 }
1428 }
1429
1430 return 0;
1431}
1432
1433static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
1434 struct wmi_snr_threshold_params_cmd *snr_cmd)
1435{
1436 struct sk_buff *skb;
1437 struct wmi_snr_threshold_params_cmd *cmd;
1438
1439 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1440 if (!skb)
1441 return -ENOMEM;
1442
1443 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
1444 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
1445
1446 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
1447 NO_SYNC_WMIFLAG);
1448}
1449
1450static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
1451 int len)
1452{
1453 struct wmi_snr_threshold_event *reply;
1454 struct sq_threshold_params *sq_thresh;
1455 struct wmi_snr_threshold_params_cmd cmd;
1456 enum wmi_snr_threshold_val new_threshold;
1457 u8 upper_snr_threshold, lower_snr_threshold;
1458 s16 snr;
1459 int ret;
1460
1461 if (len < sizeof(struct wmi_snr_threshold_event))
1462 return -EINVAL;
1463
1464 reply = (struct wmi_snr_threshold_event *) datap;
1465
1466 new_threshold = (enum wmi_snr_threshold_val) reply->range;
1467 snr = reply->snr;
1468
1469 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
1470
1471 /*
1472 * Identify the threshold breached and communicate that to the app.
1473 * After that install a new set of thresholds based on the signal
1474 * quality reported by the target.
1475 */
1476 if (new_threshold) {
1477 /* Upper threshold breached */
1478 if (snr < sq_thresh->upper_threshold[0]) {
1479 ath6kl_dbg(ATH6KL_DBG_WMI,
1480 "spurious upper snr threshold event: %d\n",
1481 snr);
1482 } else if ((snr < sq_thresh->upper_threshold[1]) &&
1483 (snr >= sq_thresh->upper_threshold[0])) {
1484 new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
1485 } else if ((snr < sq_thresh->upper_threshold[2]) &&
1486 (snr >= sq_thresh->upper_threshold[1])) {
1487 new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
1488 } else if ((snr < sq_thresh->upper_threshold[3]) &&
1489 (snr >= sq_thresh->upper_threshold[2])) {
1490 new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
1491 } else if (snr >= sq_thresh->upper_threshold[3]) {
1492 new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
1493 }
1494 } else {
1495 /* Lower threshold breached */
1496 if (snr > sq_thresh->lower_threshold[0]) {
1497 ath6kl_dbg(ATH6KL_DBG_WMI,
1498 "spurious lower snr threshold event: %d\n",
1499 sq_thresh->lower_threshold[0]);
1500 } else if ((snr > sq_thresh->lower_threshold[1]) &&
1501 (snr <= sq_thresh->lower_threshold[0])) {
1502 new_threshold = WMI_SNR_THRESHOLD4_BELOW;
1503 } else if ((snr > sq_thresh->lower_threshold[2]) &&
1504 (snr <= sq_thresh->lower_threshold[1])) {
1505 new_threshold = WMI_SNR_THRESHOLD3_BELOW;
1506 } else if ((snr > sq_thresh->lower_threshold[3]) &&
1507 (snr <= sq_thresh->lower_threshold[2])) {
1508 new_threshold = WMI_SNR_THRESHOLD2_BELOW;
1509 } else if (snr <= sq_thresh->lower_threshold[3]) {
1510 new_threshold = WMI_SNR_THRESHOLD1_BELOW;
1511 }
1512 }
1513
1514 /* Calculate and install the next set of thresholds */
1515 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
1516 sq_thresh->lower_threshold_valid_count);
1517 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
1518 sq_thresh->upper_threshold_valid_count);
1519
1520 /* Issue a wmi command to install the thresholds */
1521 cmd.thresh_above1_val = upper_snr_threshold;
1522 cmd.thresh_below1_val = lower_snr_threshold;
1523 cmd.weight = sq_thresh->weight;
1524 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
1525
1526 ath6kl_dbg(ATH6KL_DBG_WMI,
1527 "snr: %d, threshold: %d, lower: %d, upper: %d\n",
1528 snr, new_threshold,
1529 lower_snr_threshold, upper_snr_threshold);
1530
1531 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
1532 if (ret) {
1533 ath6kl_err("unable to configure snr threshold\n");
1534 return -EIO;
1535 }
1536
1537 return 0;
1538}
1539
1540static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
1541{
1542 u16 ap_info_entry_size;
1543 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
1544 struct wmi_ap_info_v1 *ap_info_v1;
1545 u8 index;
1546
1547 if (len < sizeof(struct wmi_aplist_event) ||
1548 ev->ap_list_ver != APLIST_VER1)
1549 return -EINVAL;
1550
1551 ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
1552 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
1553
1554 ath6kl_dbg(ATH6KL_DBG_WMI,
1555 "number of APs in aplist event: %d\n", ev->num_ap);
1556
1557 if (len < (int) (sizeof(struct wmi_aplist_event) +
1558 (ev->num_ap - 1) * ap_info_entry_size))
1559 return -EINVAL;
1560
1561 /* AP list version 1 contents */
1562 for (index = 0; index < ev->num_ap; index++) {
1563 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
1564 index, ap_info_v1->bssid, ap_info_v1->channel);
1565 ap_info_v1++;
1566 }
1567
1568 return 0;
1569}
1570
1571int ath6kl_wmi_cmd_send(struct wmi *wmi, struct sk_buff *skb,
1572 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
1573{
1574 struct wmi_cmd_hdr *cmd_hdr;
1575 enum htc_endpoint_id ep_id = wmi->ep_id;
1576 int ret;
1577
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03001578 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: cmd_id=%d\n", __func__, cmd_id);
1579
Kalle Valobdcd8172011-07-18 00:22:30 +03001580 if (WARN_ON(skb == NULL))
1581 return -EINVAL;
1582
1583 if (sync_flag >= END_WMIFLAG) {
1584 dev_kfree_skb(skb);
1585 return -EINVAL;
1586 }
1587
1588 if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
1589 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1590 /*
1591 * Make sure all data currently queued is transmitted before
1592 * the cmd execution. Establish a new sync point.
1593 */
1594 ath6kl_wmi_sync_point(wmi);
1595 }
1596
1597 skb_push(skb, sizeof(struct wmi_cmd_hdr));
1598
1599 cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
1600 cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
1601 cmd_hdr->info1 = 0; /* added for virtual interface */
1602
1603 /* Only for OPT_TX_CMD, use BE endpoint. */
1604 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
1605 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
1606 false, false, 0, NULL);
1607 if (ret) {
1608 dev_kfree_skb(skb);
1609 return ret;
1610 }
1611 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
1612 }
1613
1614 ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
1615
1616 if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
1617 (sync_flag == SYNC_BOTH_WMIFLAG)) {
1618 /*
1619 * Make sure all new data queued waits for the command to
1620 * execute. Establish a new sync point.
1621 */
1622 ath6kl_wmi_sync_point(wmi);
1623 }
1624
1625 return 0;
1626}
1627
1628int ath6kl_wmi_connect_cmd(struct wmi *wmi, enum network_type nw_type,
1629 enum dot11_auth_mode dot11_auth_mode,
1630 enum auth_mode auth_mode,
1631 enum crypto_type pairwise_crypto,
1632 u8 pairwise_crypto_len,
1633 enum crypto_type group_crypto,
1634 u8 group_crypto_len, int ssid_len, u8 *ssid,
1635 u8 *bssid, u16 channel, u32 ctrl_flags)
1636{
1637 struct sk_buff *skb;
1638 struct wmi_connect_cmd *cc;
1639 int ret;
1640
1641 wmi->traffic_class = 100;
1642
1643 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
1644 return -EINVAL;
1645
1646 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
1647 return -EINVAL;
1648
1649 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
1650 if (!skb)
1651 return -ENOMEM;
1652
1653 cc = (struct wmi_connect_cmd *) skb->data;
1654
1655 if (ssid_len)
1656 memcpy(cc->ssid, ssid, ssid_len);
1657
1658 cc->ssid_len = ssid_len;
1659 cc->nw_type = nw_type;
1660 cc->dot11_auth_mode = dot11_auth_mode;
1661 cc->auth_mode = auth_mode;
1662 cc->prwise_crypto_type = pairwise_crypto;
1663 cc->prwise_crypto_len = pairwise_crypto_len;
1664 cc->grp_crypto_type = group_crypto;
1665 cc->grp_crypto_len = group_crypto_len;
1666 cc->ch = cpu_to_le16(channel);
1667 cc->ctrl_flags = cpu_to_le32(ctrl_flags);
1668
1669 if (bssid != NULL)
1670 memcpy(cc->bssid, bssid, ETH_ALEN);
1671
1672 wmi->pair_crypto_type = pairwise_crypto;
1673 wmi->grp_crypto_type = group_crypto;
1674
1675 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CONNECT_CMDID, NO_SYNC_WMIFLAG);
1676
1677 return ret;
1678}
1679
1680int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 *bssid, u16 channel)
1681{
1682 struct sk_buff *skb;
1683 struct wmi_reconnect_cmd *cc;
1684 int ret;
1685
1686 wmi->traffic_class = 100;
1687
1688 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
1689 if (!skb)
1690 return -ENOMEM;
1691
1692 cc = (struct wmi_reconnect_cmd *) skb->data;
1693 cc->channel = cpu_to_le16(channel);
1694
1695 if (bssid != NULL)
1696 memcpy(cc->bssid, bssid, ETH_ALEN);
1697
1698 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RECONNECT_CMDID,
1699 NO_SYNC_WMIFLAG);
1700
1701 return ret;
1702}
1703
1704int ath6kl_wmi_disconnect_cmd(struct wmi *wmi)
1705{
1706 int ret;
1707
1708 wmi->traffic_class = 100;
1709
1710 /* Disconnect command does not need to do a SYNC before. */
1711 ret = ath6kl_wmi_simple_cmd(wmi, WMI_DISCONNECT_CMDID);
1712
1713 return ret;
1714}
1715
1716int ath6kl_wmi_startscan_cmd(struct wmi *wmi, enum wmi_scan_type scan_type,
1717 u32 force_fgscan, u32 is_legacy,
1718 u32 home_dwell_time, u32 force_scan_interval,
1719 s8 num_chan, u16 *ch_list)
1720{
1721 struct sk_buff *skb;
1722 struct wmi_start_scan_cmd *sc;
1723 s8 size;
Edward Lu1276c9e2011-08-30 21:58:00 +03001724 int i, ret;
Kalle Valobdcd8172011-07-18 00:22:30 +03001725
1726 size = sizeof(struct wmi_start_scan_cmd);
1727
1728 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
1729 return -EINVAL;
1730
1731 if (num_chan > WMI_MAX_CHANNELS)
1732 return -EINVAL;
1733
1734 if (num_chan)
1735 size += sizeof(u16) * (num_chan - 1);
1736
1737 skb = ath6kl_wmi_get_new_buf(size);
1738 if (!skb)
1739 return -ENOMEM;
1740
1741 sc = (struct wmi_start_scan_cmd *) skb->data;
1742 sc->scan_type = scan_type;
1743 sc->force_fg_scan = cpu_to_le32(force_fgscan);
1744 sc->is_legacy = cpu_to_le32(is_legacy);
1745 sc->home_dwell_time = cpu_to_le32(home_dwell_time);
1746 sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
1747 sc->num_ch = num_chan;
1748
Edward Lu1276c9e2011-08-30 21:58:00 +03001749 for (i = 0; i < num_chan; i++)
1750 sc->ch_list[i] = cpu_to_le16(ch_list[i]);
Kalle Valobdcd8172011-07-18 00:22:30 +03001751
1752 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_START_SCAN_CMDID,
1753 NO_SYNC_WMIFLAG);
1754
1755 return ret;
1756}
1757
1758int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u16 fg_start_sec,
1759 u16 fg_end_sec, u16 bg_sec,
1760 u16 minact_chdw_msec, u16 maxact_chdw_msec,
1761 u16 pas_chdw_msec, u8 short_scan_ratio,
1762 u8 scan_ctrl_flag, u32 max_dfsch_act_time,
1763 u16 maxact_scan_per_ssid)
1764{
1765 struct sk_buff *skb;
1766 struct wmi_scan_params_cmd *sc;
1767 int ret;
1768
1769 skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
1770 if (!skb)
1771 return -ENOMEM;
1772
1773 sc = (struct wmi_scan_params_cmd *) skb->data;
1774 sc->fg_start_period = cpu_to_le16(fg_start_sec);
1775 sc->fg_end_period = cpu_to_le16(fg_end_sec);
1776 sc->bg_period = cpu_to_le16(bg_sec);
1777 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
1778 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
1779 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
1780 sc->short_scan_ratio = short_scan_ratio;
1781 sc->scan_ctrl_flags = scan_ctrl_flag;
1782 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
1783 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
1784
1785 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_SCAN_PARAMS_CMDID,
1786 NO_SYNC_WMIFLAG);
1787 return ret;
1788}
1789
1790int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 filter, u32 ie_mask)
1791{
1792 struct sk_buff *skb;
1793 struct wmi_bss_filter_cmd *cmd;
1794 int ret;
1795
1796 if (filter >= LAST_BSS_FILTER)
1797 return -EINVAL;
1798
1799 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1800 if (!skb)
1801 return -ENOMEM;
1802
1803 cmd = (struct wmi_bss_filter_cmd *) skb->data;
1804 cmd->bss_filter = filter;
1805 cmd->ie_mask = cpu_to_le32(ie_mask);
1806
1807 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_BSS_FILTER_CMDID,
1808 NO_SYNC_WMIFLAG);
1809 return ret;
1810}
1811
1812int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 index, u8 flag,
1813 u8 ssid_len, u8 *ssid)
1814{
1815 struct sk_buff *skb;
1816 struct wmi_probed_ssid_cmd *cmd;
1817 int ret;
1818
1819 if (index > MAX_PROBED_SSID_INDEX)
1820 return -EINVAL;
1821
1822 if (ssid_len > sizeof(cmd->ssid))
1823 return -EINVAL;
1824
1825 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
1826 return -EINVAL;
1827
1828 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
1829 return -EINVAL;
1830
1831 if (flag & SPECIFIC_SSID_FLAG)
1832 wmi->is_probe_ssid = true;
1833
1834 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1835 if (!skb)
1836 return -ENOMEM;
1837
1838 cmd = (struct wmi_probed_ssid_cmd *) skb->data;
1839 cmd->entry_index = index;
1840 cmd->flag = flag;
1841 cmd->ssid_len = ssid_len;
1842 memcpy(cmd->ssid, ssid, ssid_len);
1843
1844 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PROBED_SSID_CMDID,
1845 NO_SYNC_WMIFLAG);
1846 return ret;
1847}
1848
1849int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u16 listen_interval,
1850 u16 listen_beacons)
1851{
1852 struct sk_buff *skb;
1853 struct wmi_listen_int_cmd *cmd;
1854 int ret;
1855
1856 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1857 if (!skb)
1858 return -ENOMEM;
1859
1860 cmd = (struct wmi_listen_int_cmd *) skb->data;
1861 cmd->listen_intvl = cpu_to_le16(listen_interval);
1862 cmd->num_beacons = cpu_to_le16(listen_beacons);
1863
1864 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LISTEN_INT_CMDID,
1865 NO_SYNC_WMIFLAG);
1866 return ret;
1867}
1868
1869int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 pwr_mode)
1870{
1871 struct sk_buff *skb;
1872 struct wmi_power_mode_cmd *cmd;
1873 int ret;
1874
1875 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1876 if (!skb)
1877 return -ENOMEM;
1878
1879 cmd = (struct wmi_power_mode_cmd *) skb->data;
1880 cmd->pwr_mode = pwr_mode;
1881 wmi->pwr_mode = pwr_mode;
1882
1883 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_MODE_CMDID,
1884 NO_SYNC_WMIFLAG);
1885 return ret;
1886}
1887
1888int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u16 idle_period,
1889 u16 ps_poll_num, u16 dtim_policy,
1890 u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
1891 u16 ps_fail_event_policy)
1892{
1893 struct sk_buff *skb;
1894 struct wmi_power_params_cmd *pm;
1895 int ret;
1896
1897 skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
1898 if (!skb)
1899 return -ENOMEM;
1900
1901 pm = (struct wmi_power_params_cmd *)skb->data;
1902 pm->idle_period = cpu_to_le16(idle_period);
1903 pm->pspoll_number = cpu_to_le16(ps_poll_num);
1904 pm->dtim_policy = cpu_to_le16(dtim_policy);
1905 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
1906 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
1907 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
1908
1909 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_POWER_PARAMS_CMDID,
1910 NO_SYNC_WMIFLAG);
1911 return ret;
1912}
1913
1914int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 timeout)
1915{
1916 struct sk_buff *skb;
1917 struct wmi_disc_timeout_cmd *cmd;
1918 int ret;
1919
1920 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1921 if (!skb)
1922 return -ENOMEM;
1923
1924 cmd = (struct wmi_disc_timeout_cmd *) skb->data;
1925 cmd->discon_timeout = timeout;
1926
1927 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_DISC_TIMEOUT_CMDID,
1928 NO_SYNC_WMIFLAG);
1929 return ret;
1930}
1931
1932int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 key_index,
1933 enum crypto_type key_type,
1934 u8 key_usage, u8 key_len,
1935 u8 *key_rsc, u8 *key_material,
1936 u8 key_op_ctrl, u8 *mac_addr,
1937 enum wmi_sync_flag sync_flag)
1938{
1939 struct sk_buff *skb;
1940 struct wmi_add_cipher_key_cmd *cmd;
1941 int ret;
1942
Jouni Malinen9a5b1312011-08-30 21:57:52 +03001943 ath6kl_dbg(ATH6KL_DBG_WMI, "addkey cmd: key_index=%u key_type=%d "
1944 "key_usage=%d key_len=%d key_op_ctrl=%d\n",
1945 key_index, key_type, key_usage, key_len, key_op_ctrl);
1946
Kalle Valobdcd8172011-07-18 00:22:30 +03001947 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
1948 (key_material == NULL))
1949 return -EINVAL;
1950
1951 if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
1952 return -EINVAL;
1953
1954 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1955 if (!skb)
1956 return -ENOMEM;
1957
1958 cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
1959 cmd->key_index = key_index;
1960 cmd->key_type = key_type;
1961 cmd->key_usage = key_usage;
1962 cmd->key_len = key_len;
1963 memcpy(cmd->key, key_material, key_len);
1964
1965 if (key_rsc != NULL)
1966 memcpy(cmd->key_rsc, key_rsc, sizeof(cmd->key_rsc));
1967
1968 cmd->key_op_ctrl = key_op_ctrl;
1969
1970 if (mac_addr)
1971 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
1972
1973 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_CIPHER_KEY_CMDID,
1974 sync_flag);
1975
1976 return ret;
1977}
1978
1979int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 *krk)
1980{
1981 struct sk_buff *skb;
1982 struct wmi_add_krk_cmd *cmd;
1983 int ret;
1984
1985 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
1986 if (!skb)
1987 return -ENOMEM;
1988
1989 cmd = (struct wmi_add_krk_cmd *) skb->data;
1990 memcpy(cmd->krk, krk, WMI_KRK_LEN);
1991
1992 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_ADD_KRK_CMDID, NO_SYNC_WMIFLAG);
1993
1994 return ret;
1995}
1996
1997int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 key_index)
1998{
1999 struct sk_buff *skb;
2000 struct wmi_delete_cipher_key_cmd *cmd;
2001 int ret;
2002
2003 if (key_index > WMI_MAX_KEY_INDEX)
2004 return -EINVAL;
2005
2006 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2007 if (!skb)
2008 return -ENOMEM;
2009
2010 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
2011 cmd->key_index = key_index;
2012
2013 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_CIPHER_KEY_CMDID,
2014 NO_SYNC_WMIFLAG);
2015
2016 return ret;
2017}
2018
2019int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, const u8 *bssid,
2020 const u8 *pmkid, bool set)
2021{
2022 struct sk_buff *skb;
2023 struct wmi_setpmkid_cmd *cmd;
2024 int ret;
2025
2026 if (bssid == NULL)
2027 return -EINVAL;
2028
2029 if (set && pmkid == NULL)
2030 return -EINVAL;
2031
2032 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2033 if (!skb)
2034 return -ENOMEM;
2035
2036 cmd = (struct wmi_setpmkid_cmd *) skb->data;
2037 memcpy(cmd->bssid, bssid, ETH_ALEN);
2038 if (set) {
2039 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
2040 cmd->enable = PMKID_ENABLE;
2041 } else {
2042 memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
2043 cmd->enable = PMKID_DISABLE;
2044 }
2045
2046 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_PMKID_CMDID,
2047 NO_SYNC_WMIFLAG);
2048
2049 return ret;
2050}
2051
2052static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
2053 enum htc_endpoint_id ep_id)
2054{
2055 struct wmi_data_hdr *data_hdr;
2056 int ret;
2057
2058 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id))
2059 return -EINVAL;
2060
2061 skb_push(skb, sizeof(struct wmi_data_hdr));
2062
2063 data_hdr = (struct wmi_data_hdr *) skb->data;
2064 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
2065 data_hdr->info3 = 0;
2066
2067 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
2068
2069 return ret;
2070}
2071
2072static int ath6kl_wmi_sync_point(struct wmi *wmi)
2073{
2074 struct sk_buff *skb;
2075 struct wmi_sync_cmd *cmd;
2076 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
2077 enum htc_endpoint_id ep_id;
2078 u8 index, num_pri_streams = 0;
2079 int ret = 0;
2080
2081 memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
2082
2083 spin_lock_bh(&wmi->lock);
2084
2085 for (index = 0; index < WMM_NUM_AC; index++) {
2086 if (wmi->fat_pipe_exist & (1 << index)) {
2087 num_pri_streams++;
2088 data_sync_bufs[num_pri_streams - 1].traffic_class =
2089 index;
2090 }
2091 }
2092
2093 spin_unlock_bh(&wmi->lock);
2094
2095 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2096 if (!skb) {
2097 ret = -ENOMEM;
2098 goto free_skb;
2099 }
2100
2101 cmd = (struct wmi_sync_cmd *) skb->data;
2102
2103 /*
2104 * In the SYNC cmd sent on the control Ep, send a bitmap
2105 * of the data eps on which the Data Sync will be sent
2106 */
2107 cmd->data_sync_map = wmi->fat_pipe_exist;
2108
2109 for (index = 0; index < num_pri_streams; index++) {
2110 data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
2111 if (data_sync_bufs[index].skb == NULL) {
2112 ret = -ENOMEM;
2113 break;
2114 }
2115 }
2116
2117 /*
2118 * If buffer allocation for any of the dataSync fails,
2119 * then do not send the Synchronize cmd on the control ep
2120 */
2121 if (ret)
2122 goto free_skb;
2123
2124 /*
2125 * Send sync cmd followed by sync data messages on all
2126 * endpoints being used
2127 */
2128 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SYNCHRONIZE_CMDID,
2129 NO_SYNC_WMIFLAG);
2130
2131 if (ret)
2132 goto free_skb;
2133
2134 /* cmd buffer sent, we no longer own it */
2135 skb = NULL;
2136
2137 for (index = 0; index < num_pri_streams; index++) {
2138
2139 if (WARN_ON(!data_sync_bufs[index].skb))
2140 break;
2141
2142 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
2143 data_sync_bufs[index].
2144 traffic_class);
2145 ret =
2146 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
2147 ep_id);
2148
2149 if (ret)
2150 break;
2151
2152 data_sync_bufs[index].skb = NULL;
2153 }
2154
2155free_skb:
2156 /* free up any resources left over (possibly due to an error) */
2157 if (skb)
2158 dev_kfree_skb(skb);
2159
2160 for (index = 0; index < num_pri_streams; index++) {
2161 if (data_sync_bufs[index].skb != NULL) {
2162 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].
2163 skb);
2164 }
2165 }
2166
2167 return ret;
2168}
2169
2170int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi,
2171 struct wmi_create_pstream_cmd *params)
2172{
2173 struct sk_buff *skb;
2174 struct wmi_create_pstream_cmd *cmd;
2175 u8 fatpipe_exist_for_ac = 0;
2176 s32 min_phy = 0;
2177 s32 nominal_phy = 0;
2178 int ret;
2179
2180 if (!((params->user_pri < 8) &&
2181 (params->user_pri <= 0x7) &&
2182 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
2183 (params->traffic_direc == UPLINK_TRAFFIC ||
2184 params->traffic_direc == DNLINK_TRAFFIC ||
2185 params->traffic_direc == BIDIR_TRAFFIC) &&
2186 (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
2187 params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
2188 (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
2189 params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
2190 params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
2191 (params->tsid == WMI_IMPLICIT_PSTREAM ||
2192 params->tsid <= WMI_MAX_THINSTREAM))) {
2193 return -EINVAL;
2194 }
2195
2196 /*
2197 * Check nominal PHY rate is >= minimalPHY,
2198 * so that DUT can allow TSRS IE
2199 */
2200
2201 /* Get the physical rate (units of bps) */
2202 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
2203
2204 /* Check minimal phy < nominal phy rate */
2205 if (params->nominal_phy >= min_phy) {
2206 /* unit of 500 kbps */
2207 nominal_phy = (params->nominal_phy * 1000) / 500;
2208 ath6kl_dbg(ATH6KL_DBG_WMI,
2209 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
2210 min_phy, nominal_phy);
2211
2212 params->nominal_phy = nominal_phy;
2213 } else {
2214 params->nominal_phy = 0;
2215 }
2216
2217 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2218 if (!skb)
2219 return -ENOMEM;
2220
2221 ath6kl_dbg(ATH6KL_DBG_WMI,
2222 "sending create_pstream_cmd: ac=%d tsid:%d\n",
2223 params->traffic_class, params->tsid);
2224
2225 cmd = (struct wmi_create_pstream_cmd *) skb->data;
2226 memcpy(cmd, params, sizeof(*cmd));
2227
2228 /* This is an implicitly created Fat pipe */
2229 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
2230 spin_lock_bh(&wmi->lock);
2231 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2232 (1 << params->traffic_class));
2233 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2234 spin_unlock_bh(&wmi->lock);
2235 } else {
2236 /* explicitly created thin stream within a fat pipe */
2237 spin_lock_bh(&wmi->lock);
2238 fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
2239 (1 << params->traffic_class));
2240 wmi->stream_exist_for_ac[params->traffic_class] |=
2241 (1 << params->tsid);
2242 /*
2243 * If a thinstream becomes active, the fat pipe automatically
2244 * becomes active
2245 */
2246 wmi->fat_pipe_exist |= (1 << params->traffic_class);
2247 spin_unlock_bh(&wmi->lock);
2248 }
2249
2250 /*
2251 * Indicate activty change to driver layer only if this is the
2252 * first TSID to get created in this AC explicitly or an implicit
2253 * fat pipe is getting created.
2254 */
2255 if (!fatpipe_exist_for_ac)
2256 ath6kl_indicate_tx_activity(wmi->parent_dev,
2257 params->traffic_class, true);
2258
2259 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_CREATE_PSTREAM_CMDID,
2260 NO_SYNC_WMIFLAG);
2261 return ret;
2262}
2263
2264int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 traffic_class, u8 tsid)
2265{
2266 struct sk_buff *skb;
2267 struct wmi_delete_pstream_cmd *cmd;
2268 u16 active_tsids = 0;
2269 int ret;
2270
2271 if (traffic_class > 3) {
2272 ath6kl_err("invalid traffic class: %d\n", traffic_class);
2273 return -EINVAL;
2274 }
2275
2276 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2277 if (!skb)
2278 return -ENOMEM;
2279
2280 cmd = (struct wmi_delete_pstream_cmd *) skb->data;
2281 cmd->traffic_class = traffic_class;
2282 cmd->tsid = tsid;
2283
2284 spin_lock_bh(&wmi->lock);
2285 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2286 spin_unlock_bh(&wmi->lock);
2287
2288 if (!(active_tsids & (1 << tsid))) {
2289 dev_kfree_skb(skb);
2290 ath6kl_dbg(ATH6KL_DBG_WMI,
2291 "TSID %d doesn't exist for traffic class: %d\n",
2292 tsid, traffic_class);
2293 return -ENODATA;
2294 }
2295
2296 ath6kl_dbg(ATH6KL_DBG_WMI,
2297 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
2298 traffic_class, tsid);
2299
2300 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_DELETE_PSTREAM_CMDID,
2301 SYNC_BEFORE_WMIFLAG);
2302
2303 spin_lock_bh(&wmi->lock);
2304 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
2305 active_tsids = wmi->stream_exist_for_ac[traffic_class];
2306 spin_unlock_bh(&wmi->lock);
2307
2308 /*
2309 * Indicate stream inactivity to driver layer only if all tsids
2310 * within this AC are deleted.
2311 */
2312 if (!active_tsids) {
2313 ath6kl_indicate_tx_activity(wmi->parent_dev,
2314 traffic_class, false);
2315 wmi->fat_pipe_exist &= ~(1 << traffic_class);
2316 }
2317
2318 return ret;
2319}
2320
2321int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, struct wmi_set_ip_cmd *ip_cmd)
2322{
2323 struct sk_buff *skb;
2324 struct wmi_set_ip_cmd *cmd;
2325 int ret;
2326
2327 /* Multicast address are not valid */
2328 if ((*((u8 *) &ip_cmd->ips[0]) >= 0xE0) ||
2329 (*((u8 *) &ip_cmd->ips[1]) >= 0xE0))
2330 return -EINVAL;
2331
2332 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
2333 if (!skb)
2334 return -ENOMEM;
2335
2336 cmd = (struct wmi_set_ip_cmd *) skb->data;
2337 memcpy(cmd, ip_cmd, sizeof(struct wmi_set_ip_cmd));
2338
2339 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_IP_CMDID, NO_SYNC_WMIFLAG);
2340 return ret;
2341}
2342
2343static int ath6kl_wmi_get_wow_list_event_rx(struct wmi *wmi, u8 * datap,
2344 int len)
2345{
2346 if (len < sizeof(struct wmi_get_wow_list_reply))
2347 return -EINVAL;
2348
2349 return 0;
2350}
2351
2352static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
2353 enum wmix_command_id cmd_id,
2354 enum wmi_sync_flag sync_flag)
2355{
2356 struct wmix_cmd_hdr *cmd_hdr;
2357 int ret;
2358
2359 skb_push(skb, sizeof(struct wmix_cmd_hdr));
2360
2361 cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
2362 cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
2363
2364 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_EXTENSION_CMDID, sync_flag);
2365
2366 return ret;
2367}
2368
2369int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
2370{
2371 struct sk_buff *skb;
2372 struct wmix_hb_challenge_resp_cmd *cmd;
2373 int ret;
2374
2375 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2376 if (!skb)
2377 return -ENOMEM;
2378
2379 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
2380 cmd->cookie = cpu_to_le32(cookie);
2381 cmd->source = cpu_to_le32(source);
2382
2383 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
2384 NO_SYNC_WMIFLAG);
2385 return ret;
2386}
2387
2388int ath6kl_wmi_get_stats_cmd(struct wmi *wmi)
2389{
2390 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_STATISTICS_CMDID);
2391}
2392
2393int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 dbM)
2394{
2395 struct sk_buff *skb;
2396 struct wmi_set_tx_pwr_cmd *cmd;
2397 int ret;
2398
2399 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
2400 if (!skb)
2401 return -ENOMEM;
2402
2403 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
2404 cmd->dbM = dbM;
2405
2406 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_TX_PWR_CMDID,
2407 NO_SYNC_WMIFLAG);
2408
2409 return ret;
2410}
2411
2412int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi)
2413{
2414 return ath6kl_wmi_simple_cmd(wmi, WMI_GET_TX_PWR_CMDID);
2415}
2416
Kalle Valobdcd8172011-07-18 00:22:30 +03002417int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 status, u8 preamble_policy)
2418{
2419 struct sk_buff *skb;
2420 struct wmi_set_lpreamble_cmd *cmd;
2421 int ret;
2422
2423 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
2424 if (!skb)
2425 return -ENOMEM;
2426
2427 cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
2428 cmd->status = status;
2429 cmd->preamble_policy = preamble_policy;
2430
2431 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_LPREAMBLE_CMDID,
2432 NO_SYNC_WMIFLAG);
2433 return ret;
2434}
2435
2436int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
2437{
2438 struct sk_buff *skb;
2439 struct wmi_set_rts_cmd *cmd;
2440 int ret;
2441
2442 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
2443 if (!skb)
2444 return -ENOMEM;
2445
2446 cmd = (struct wmi_set_rts_cmd *) skb->data;
2447 cmd->threshold = cpu_to_le16(threshold);
2448
2449 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_RTS_CMDID, NO_SYNC_WMIFLAG);
2450 return ret;
2451}
2452
2453int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, enum wmi_txop_cfg cfg)
2454{
2455 struct sk_buff *skb;
2456 struct wmi_set_wmm_txop_cmd *cmd;
2457 int ret;
2458
2459 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
2460 return -EINVAL;
2461
2462 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
2463 if (!skb)
2464 return -ENOMEM;
2465
2466 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
2467 cmd->txop_enable = cfg;
2468
2469 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_WMM_TXOP_CMDID,
2470 NO_SYNC_WMIFLAG);
2471 return ret;
2472}
2473
2474int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 keep_alive_intvl)
2475{
2476 struct sk_buff *skb;
2477 struct wmi_set_keepalive_cmd *cmd;
2478 int ret;
2479
2480 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2481 if (!skb)
2482 return -ENOMEM;
2483
2484 cmd = (struct wmi_set_keepalive_cmd *) skb->data;
2485 cmd->keep_alive_intvl = keep_alive_intvl;
2486 wmi->keep_alive_intvl = keep_alive_intvl;
2487
2488 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_KEEPALIVE_CMDID,
2489 NO_SYNC_WMIFLAG);
2490 return ret;
2491}
2492
2493s32 ath6kl_wmi_get_rate(s8 rate_index)
2494{
2495 if (rate_index == RATE_AUTO)
2496 return 0;
2497
2498 return wmi_rate_tbl[(u32) rate_index][0];
2499}
2500
2501void ath6kl_wmi_node_return(struct wmi *wmi, struct bss *bss)
2502{
2503 if (bss)
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05302504 wlan_node_return(&wmi->parent_dev->scan_table, bss);
Kalle Valobdcd8172011-07-18 00:22:30 +03002505}
2506
2507struct bss *ath6kl_wmi_find_ssid_node(struct wmi *wmi, u8 * ssid,
2508 u32 ssid_len, bool is_wpa2,
2509 bool match_ssid)
2510{
2511 struct bss *node = NULL;
2512
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05302513 node = wlan_find_ssid_node(&wmi->parent_dev->scan_table, ssid,
Kalle Valobdcd8172011-07-18 00:22:30 +03002514 ssid_len, is_wpa2, match_ssid);
2515 return node;
2516}
2517
2518struct bss *ath6kl_wmi_find_node(struct wmi *wmi, const u8 * mac_addr)
2519{
2520 struct bss *ni = NULL;
2521
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05302522 ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
Kalle Valobdcd8172011-07-18 00:22:30 +03002523
2524 return ni;
2525}
2526
2527void ath6kl_wmi_node_free(struct wmi *wmi, const u8 * mac_addr)
2528{
2529 struct bss *ni = NULL;
2530
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05302531 ni = wlan_find_node(&wmi->parent_dev->scan_table, mac_addr);
Kalle Valobdcd8172011-07-18 00:22:30 +03002532 if (ni != NULL)
Vasanthakumar Thiagarajan7c3075e2011-07-21 13:38:33 +05302533 wlan_node_reclaim(&wmi->parent_dev->scan_table, ni);
Kalle Valobdcd8172011-07-18 00:22:30 +03002534
2535 return;
2536}
2537
2538static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
2539 u32 len)
2540{
2541 struct wmi_pmkid_list_reply *reply;
2542 u32 expected_len;
2543
2544 if (len < sizeof(struct wmi_pmkid_list_reply))
2545 return -EINVAL;
2546
2547 reply = (struct wmi_pmkid_list_reply *)datap;
2548 expected_len = sizeof(reply->num_pmkid) +
2549 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
2550
2551 if (len < expected_len)
2552 return -EINVAL;
2553
2554 return 0;
2555}
2556
2557static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2558{
2559 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
2560
2561 aggr_recv_addba_req_evt(wmi->parent_dev, cmd->tid,
2562 le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
2563
2564 return 0;
2565}
2566
2567static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len)
2568{
2569 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
2570
2571 aggr_recv_delba_req_evt(wmi->parent_dev, cmd->tid);
2572
2573 return 0;
2574}
2575
2576/* AP mode functions */
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002577
2578int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, struct wmi_connect_cmd *p)
2579{
2580 struct sk_buff *skb;
2581 struct wmi_connect_cmd *cm;
2582 int res;
2583
2584 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2585 if (!skb)
2586 return -ENOMEM;
2587
2588 cm = (struct wmi_connect_cmd *) skb->data;
2589 memcpy(cm, p, sizeof(*cm));
2590
2591 res = ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_CONFIG_COMMIT_CMDID,
2592 NO_SYNC_WMIFLAG);
2593 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: nw_type=%u auth_mode=%u ch=%u "
2594 "ctrl_flags=0x%x-> res=%d\n",
2595 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
2596 le32_to_cpu(p->ctrl_flags), res);
2597 return res;
2598}
2599
Jouni Malinen23875132011-08-30 21:57:53 +03002600int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 cmd, const u8 *mac, u16 reason)
2601{
2602 struct sk_buff *skb;
2603 struct wmi_ap_set_mlme_cmd *cm;
2604
2605 skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
2606 if (!skb)
2607 return -ENOMEM;
2608
2609 cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
2610 memcpy(cm->mac, mac, ETH_ALEN);
2611 cm->reason = cpu_to_le16(reason);
2612 cm->cmd = cmd;
2613
2614 return ath6kl_wmi_cmd_send(wmip, skb, WMI_AP_SET_MLME_CMDID,
2615 NO_SYNC_WMIFLAG);
2616}
2617
Kalle Valobdcd8172011-07-18 00:22:30 +03002618static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len)
2619{
2620 struct wmi_pspoll_event *ev;
2621
2622 if (len < sizeof(struct wmi_pspoll_event))
2623 return -EINVAL;
2624
2625 ev = (struct wmi_pspoll_event *) datap;
2626
2627 ath6kl_pspoll_event(wmi->parent_dev, le16_to_cpu(ev->aid));
2628
2629 return 0;
2630}
2631
2632static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len)
2633{
2634 ath6kl_dtimexpiry_event(wmi->parent_dev);
2635
2636 return 0;
2637}
2638
2639int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u16 aid, bool flag)
2640{
2641 struct sk_buff *skb;
2642 struct wmi_ap_set_pvb_cmd *cmd;
2643 int ret;
2644
2645 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
2646 if (!skb)
2647 return -ENOMEM;
2648
2649 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
2650 cmd->aid = cpu_to_le16(aid);
2651 cmd->flag = cpu_to_le32(flag);
2652
2653 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_AP_SET_PVB_CMDID,
2654 NO_SYNC_WMIFLAG);
2655
2656 return 0;
2657}
2658
2659int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 rx_meta_ver,
2660 bool rx_dot11_hdr, bool defrag_on_host)
2661{
2662 struct sk_buff *skb;
2663 struct wmi_rx_frame_format_cmd *cmd;
2664 int ret;
2665
2666 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2667 if (!skb)
2668 return -ENOMEM;
2669
2670 cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
2671 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
2672 cmd->defrag_on_host = defrag_on_host ? 1 : 0;
2673 cmd->meta_ver = rx_meta_ver;
2674
2675 /* Delete the local aggr state, on host */
2676 ret = ath6kl_wmi_cmd_send(wmi, skb, WMI_RX_FRAME_FORMAT_CMDID,
2677 NO_SYNC_WMIFLAG);
2678
2679 return ret;
2680}
2681
Jouni Malinen6a7c9ba2011-08-30 21:57:50 +03002682int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 mgmt_frm_type, const u8 *ie,
2683 u8 ie_len)
2684{
2685 struct sk_buff *skb;
2686 struct wmi_set_appie_cmd *p;
2687
2688 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
2689 if (!skb)
2690 return -ENOMEM;
2691
2692 ath6kl_dbg(ATH6KL_DBG_WMI, "set_appie_cmd: mgmt_frm_type=%u "
2693 "ie_len=%u\n", mgmt_frm_type, ie_len);
2694 p = (struct wmi_set_appie_cmd *) skb->data;
2695 p->mgmt_frm_type = mgmt_frm_type;
2696 p->ie_len = ie_len;
2697 memcpy(p->ie_info, ie, ie_len);
2698 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SET_APPIE_CMDID,
2699 NO_SYNC_WMIFLAG);
2700}
2701
Jouni Malinen6465ddc2011-08-30 21:57:54 +03002702int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
2703{
2704 struct sk_buff *skb;
2705 struct wmi_disable_11b_rates_cmd *cmd;
2706
2707 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
2708 if (!skb)
2709 return -ENOMEM;
2710
2711 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
2712 disable);
2713 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
2714 cmd->disable = disable ? 1 : 0;
2715
2716 return ath6kl_wmi_cmd_send(wmi, skb, WMI_DISABLE_11B_RATES_CMDID,
2717 NO_SYNC_WMIFLAG);
2718}
2719
2720int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u32 freq, u32 dur)
2721{
2722 struct sk_buff *skb;
2723 struct wmi_remain_on_chnl_cmd *p;
2724
2725 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2726 if (!skb)
2727 return -ENOMEM;
2728
2729 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
2730 freq, dur);
2731 p = (struct wmi_remain_on_chnl_cmd *) skb->data;
2732 p->freq = cpu_to_le32(freq);
2733 p->duration = cpu_to_le32(dur);
2734 return ath6kl_wmi_cmd_send(wmi, skb, WMI_REMAIN_ON_CHNL_CMDID,
2735 NO_SYNC_WMIFLAG);
2736}
2737
2738int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u32 id, u32 freq, u32 wait,
2739 const u8 *data, u16 data_len)
2740{
2741 struct sk_buff *skb;
2742 struct wmi_send_action_cmd *p;
2743
2744 if (wait)
2745 return -EINVAL; /* Offload for wait not supported */
2746
2747 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2748 if (!skb)
2749 return -ENOMEM;
2750
2751 ath6kl_dbg(ATH6KL_DBG_WMI, "send_action_cmd: id=%u freq=%u wait=%u "
2752 "len=%u\n", id, freq, wait, data_len);
2753 p = (struct wmi_send_action_cmd *) skb->data;
2754 p->id = cpu_to_le32(id);
2755 p->freq = cpu_to_le32(freq);
2756 p->wait = cpu_to_le32(wait);
2757 p->len = cpu_to_le16(data_len);
2758 memcpy(p->data, data, data_len);
2759 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_ACTION_CMDID,
2760 NO_SYNC_WMIFLAG);
2761}
2762
2763int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u32 freq,
2764 const u8 *dst,
2765 const u8 *data, u16 data_len)
2766{
2767 struct sk_buff *skb;
2768 struct wmi_p2p_probe_response_cmd *p;
2769
2770 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
2771 if (!skb)
2772 return -ENOMEM;
2773
2774 ath6kl_dbg(ATH6KL_DBG_WMI, "send_probe_response_cmd: freq=%u dst=%pM "
2775 "len=%u\n", freq, dst, data_len);
2776 p = (struct wmi_p2p_probe_response_cmd *) skb->data;
2777 p->freq = cpu_to_le32(freq);
2778 memcpy(p->destination_addr, dst, ETH_ALEN);
2779 p->len = cpu_to_le16(data_len);
2780 memcpy(p->data, data, data_len);
2781 return ath6kl_wmi_cmd_send(wmi, skb, WMI_SEND_PROBE_RESPONSE_CMDID,
2782 NO_SYNC_WMIFLAG);
2783}
2784
2785int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, bool enable)
2786{
2787 struct sk_buff *skb;
2788 struct wmi_probe_req_report_cmd *p;
2789
2790 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2791 if (!skb)
2792 return -ENOMEM;
2793
2794 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
2795 enable);
2796 p = (struct wmi_probe_req_report_cmd *) skb->data;
2797 p->enable = enable ? 1 : 0;
2798 return ath6kl_wmi_cmd_send(wmi, skb, WMI_PROBE_REQ_REPORT_CMDID,
2799 NO_SYNC_WMIFLAG);
2800}
2801
2802int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u32 info_req_flags)
2803{
2804 struct sk_buff *skb;
2805 struct wmi_get_p2p_info *p;
2806
2807 skb = ath6kl_wmi_get_new_buf(sizeof(*p));
2808 if (!skb)
2809 return -ENOMEM;
2810
2811 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
2812 info_req_flags);
2813 p = (struct wmi_get_p2p_info *) skb->data;
2814 p->info_req_flags = cpu_to_le32(info_req_flags);
2815 return ath6kl_wmi_cmd_send(wmi, skb, WMI_GET_P2P_INFO_CMDID,
2816 NO_SYNC_WMIFLAG);
2817}
2818
2819int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi)
2820{
2821 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
2822 return ath6kl_wmi_simple_cmd(wmi, WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
2823}
2824
Kalle Valobdcd8172011-07-18 00:22:30 +03002825static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
2826{
2827 struct wmix_cmd_hdr *cmd;
2828 u32 len;
2829 u16 id;
2830 u8 *datap;
2831 int ret = 0;
2832
2833 if (skb->len < sizeof(struct wmix_cmd_hdr)) {
2834 ath6kl_err("bad packet 1\n");
2835 wmi->stat.cmd_len_err++;
2836 return -EINVAL;
2837 }
2838
2839 cmd = (struct wmix_cmd_hdr *) skb->data;
2840 id = le32_to_cpu(cmd->cmd_id);
2841
2842 skb_pull(skb, sizeof(struct wmix_cmd_hdr));
2843
2844 datap = skb->data;
2845 len = skb->len;
2846
2847 switch (id) {
2848 case WMIX_HB_CHALLENGE_RESP_EVENTID:
2849 break;
2850 case WMIX_DBGLOG_EVENTID:
2851 break;
2852 default:
2853 ath6kl_err("unknown cmd id 0x%x\n", id);
2854 wmi->stat.cmd_id_err++;
2855 ret = -EINVAL;
2856 break;
2857 }
2858
2859 return ret;
2860}
2861
2862/* Control Path */
2863int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
2864{
2865 struct wmi_cmd_hdr *cmd;
2866 u32 len;
2867 u16 id;
2868 u8 *datap;
2869 int ret = 0;
2870
2871 if (WARN_ON(skb == NULL))
2872 return -EINVAL;
2873
2874 if (skb->len < sizeof(struct wmi_cmd_hdr)) {
2875 ath6kl_err("bad packet 1\n");
2876 dev_kfree_skb(skb);
2877 wmi->stat.cmd_len_err++;
2878 return -EINVAL;
2879 }
2880
2881 cmd = (struct wmi_cmd_hdr *) skb->data;
2882 id = le16_to_cpu(cmd->cmd_id);
2883
2884 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
2885
2886 datap = skb->data;
2887 len = skb->len;
2888
2889 ath6kl_dbg(ATH6KL_DBG_WMI, "%s: wmi id: %d\n", __func__, id);
2890 ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, "msg payload ", datap, len);
2891
2892 switch (id) {
2893 case WMI_GET_BITRATE_CMDID:
2894 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
2895 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
2896 break;
2897 case WMI_GET_CHANNEL_LIST_CMDID:
2898 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
2899 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
2900 break;
2901 case WMI_GET_TX_PWR_CMDID:
2902 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
2903 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
2904 break;
2905 case WMI_READY_EVENTID:
2906 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
2907 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
2908 break;
2909 case WMI_CONNECT_EVENTID:
2910 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
2911 ret = ath6kl_wmi_connect_event_rx(wmi, datap, len);
2912 break;
2913 case WMI_DISCONNECT_EVENTID:
2914 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
2915 ret = ath6kl_wmi_disconnect_event_rx(wmi, datap, len);
2916 break;
2917 case WMI_PEER_NODE_EVENTID:
2918 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
2919 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
2920 break;
2921 case WMI_TKIP_MICERR_EVENTID:
2922 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
2923 ret = ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len);
2924 break;
2925 case WMI_BSSINFO_EVENTID:
2926 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
2927 ath6kl_wmi_convert_bssinfo_hdr2_to_hdr(skb, datap);
2928 ret = ath6kl_wmi_bssinfo_event_rx(wmi, skb->data, skb->len);
2929 break;
2930 case WMI_REGDOMAIN_EVENTID:
2931 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
2932 break;
2933 case WMI_PSTREAM_TIMEOUT_EVENTID:
2934 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
2935 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
2936 break;
2937 case WMI_NEIGHBOR_REPORT_EVENTID:
2938 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
2939 break;
2940 case WMI_SCAN_COMPLETE_EVENTID:
2941 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
2942 ret = ath6kl_wmi_scan_complete_rx(wmi, datap, len);
2943 break;
2944 case WMI_CMDERROR_EVENTID:
2945 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
2946 ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
2947 break;
2948 case WMI_REPORT_STATISTICS_EVENTID:
2949 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
2950 ret = ath6kl_wmi_stats_event_rx(wmi, datap, len);
2951 break;
2952 case WMI_RSSI_THRESHOLD_EVENTID:
2953 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
2954 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
2955 break;
2956 case WMI_ERROR_REPORT_EVENTID:
2957 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
2958 break;
2959 case WMI_OPT_RX_FRAME_EVENTID:
2960 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
2961 ret = ath6kl_wmi_opt_frame_event_rx(wmi, datap, len);
2962 break;
2963 case WMI_REPORT_ROAM_TBL_EVENTID:
2964 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
2965 break;
2966 case WMI_EXTENSION_EVENTID:
2967 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
2968 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
2969 break;
2970 case WMI_CAC_EVENTID:
2971 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
2972 ret = ath6kl_wmi_cac_event_rx(wmi, datap, len);
2973 break;
2974 case WMI_CHANNEL_CHANGE_EVENTID:
2975 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
2976 break;
2977 case WMI_REPORT_ROAM_DATA_EVENTID:
2978 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
2979 break;
2980 case WMI_GET_FIXRATES_CMDID:
2981 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
2982 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
2983 break;
2984 case WMI_TX_RETRY_ERR_EVENTID:
2985 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
2986 break;
2987 case WMI_SNR_THRESHOLD_EVENTID:
2988 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
2989 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
2990 break;
2991 case WMI_LQ_THRESHOLD_EVENTID:
2992 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
2993 break;
2994 case WMI_APLIST_EVENTID:
2995 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
2996 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
2997 break;
2998 case WMI_GET_KEEPALIVE_CMDID:
2999 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
3000 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
3001 break;
3002 case WMI_GET_WOW_LIST_EVENTID:
3003 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
3004 ret = ath6kl_wmi_get_wow_list_event_rx(wmi, datap, len);
3005 break;
3006 case WMI_GET_PMKID_LIST_EVENTID:
3007 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
3008 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
3009 break;
3010 case WMI_PSPOLL_EVENTID:
3011 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
3012 ret = ath6kl_wmi_pspoll_event_rx(wmi, datap, len);
3013 break;
3014 case WMI_DTIMEXPIRY_EVENTID:
3015 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
3016 ret = ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len);
3017 break;
3018 case WMI_SET_PARAMS_REPLY_EVENTID:
3019 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
3020 break;
3021 case WMI_ADDBA_REQ_EVENTID:
3022 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
3023 ret = ath6kl_wmi_addba_req_event_rx(wmi, datap, len);
3024 break;
3025 case WMI_ADDBA_RESP_EVENTID:
3026 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
3027 break;
3028 case WMI_DELBA_REQ_EVENTID:
3029 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
3030 ret = ath6kl_wmi_delba_req_event_rx(wmi, datap, len);
3031 break;
3032 case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
3033 ath6kl_dbg(ATH6KL_DBG_WMI,
3034 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
3035 break;
3036 case WMI_REPORT_BTCOEX_STATS_EVENTID:
3037 ath6kl_dbg(ATH6KL_DBG_WMI,
3038 "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
3039 break;
3040 case WMI_TX_COMPLETE_EVENTID:
3041 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
3042 ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
3043 break;
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003044 case WMI_REMAIN_ON_CHNL_EVENTID:
3045 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03003046 ret = ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003047 break;
3048 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
3049 ath6kl_dbg(ATH6KL_DBG_WMI,
3050 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
Jouni Malinenf9e5f052011-08-30 21:57:58 +03003051 ret = ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
3052 len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003053 break;
3054 case WMI_TX_STATUS_EVENTID:
3055 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
3056 ret = ath6kl_wmi_tx_status_event_rx(datap, len);
3057 break;
3058 case WMI_RX_PROBE_REQ_EVENTID:
3059 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
Jouni Malinenae32c302011-08-30 21:58:01 +03003060 ret = ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len);
Jouni Malinen6465ddc2011-08-30 21:57:54 +03003061 break;
3062 case WMI_P2P_CAPABILITIES_EVENTID:
3063 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
3064 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
3065 break;
3066 case WMI_RX_ACTION_EVENTID:
3067 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
3068 ret = ath6kl_wmi_rx_action_event_rx(datap, len);
3069 break;
3070 case WMI_P2P_INFO_EVENTID:
3071 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
3072 ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
3073 break;
Kalle Valobdcd8172011-07-18 00:22:30 +03003074 default:
3075 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", id);
3076 wmi->stat.cmd_id_err++;
3077 ret = -EINVAL;
3078 break;
3079 }
3080
3081 dev_kfree_skb(skb);
3082
3083 return ret;
3084}
3085
3086static void ath6kl_wmi_qos_state_init(struct wmi *wmi)
3087{
3088 if (!wmi)
3089 return;
3090
3091 spin_lock_bh(&wmi->lock);
3092
3093 wmi->fat_pipe_exist = 0;
3094 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
3095
3096 spin_unlock_bh(&wmi->lock);
3097}
3098
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05303099void *ath6kl_wmi_init(struct ath6kl *dev)
Kalle Valobdcd8172011-07-18 00:22:30 +03003100{
3101 struct wmi *wmi;
3102
3103 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
3104 if (!wmi)
3105 return NULL;
3106
3107 spin_lock_init(&wmi->lock);
3108
3109 wmi->parent_dev = dev;
3110
Kalle Valobdcd8172011-07-18 00:22:30 +03003111 ath6kl_wmi_qos_state_init(wmi);
3112
3113 wmi->pwr_mode = REC_POWER;
3114 wmi->phy_mode = WMI_11G_MODE;
3115
3116 wmi->pair_crypto_type = NONE_CRYPT;
3117 wmi->grp_crypto_type = NONE_CRYPT;
3118
3119 wmi->ht_allowed[A_BAND_24GHZ] = 1;
3120 wmi->ht_allowed[A_BAND_5GHZ] = 1;
3121
3122 return wmi;
3123}
3124
3125void ath6kl_wmi_shutdown(struct wmi *wmi)
3126{
3127 if (!wmi)
3128 return;
3129
Kalle Valobdcd8172011-07-18 00:22:30 +03003130 kfree(wmi);
3131}