blob: d12ed13b0bb5c9c3ac4fdfe74f09305c4cae824c [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: functions for station ioctl
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27#include "cfg80211.h"
28
29/*
30 * Copies the multicast address list from device to driver.
31 *
32 * This function does not validate the destination memory for
33 * size, and the calling function must ensure enough memory is
34 * available.
35 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070036int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
37 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070038{
39 int i = 0;
40 struct netdev_hw_addr *ha;
41
42 netdev_for_each_mc_addr(ha, dev)
43 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
44
45 return i;
46}
47
48/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070049 * Wait queue completion handler.
50 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070051 * This function waits on a cmd wait queue. It also cancels the pending
52 * request after waking up, in case of errors.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070053 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070054int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070055{
56 bool cancel_flag = false;
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080057 int status;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080058 struct cmd_ctrl_node *cmd_queued;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080060 if (!adapter->cmd_queued)
61 return 0;
62
63 cmd_queued = adapter->cmd_queued;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -070064 adapter->cmd_queued = NULL;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080065
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070066 dev_dbg(adapter->dev, "cmd pending\n");
67 atomic_inc(&adapter->cmd_pending);
68
69 /* Status pending, wake up main process */
70 queue_work(adapter->workqueue, &adapter->main_work);
71
72 /* Wait for completion */
73 wait_event_interruptible(adapter->cmd_wait_q.wait,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -070074 *(cmd_queued->condition));
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -070075 if (!*(cmd_queued->condition))
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070076 cancel_flag = true;
77
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078 if (cancel_flag) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070079 mwifiex_cancel_pending_ioctl(adapter);
80 dev_dbg(adapter->dev, "cmd cancel\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070081 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080082
83 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070084 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070085
Bing Zhao5e6e3a92011-03-21 18:00:50 -070086 return status;
87}
88
89/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070090 * This function prepares the correct firmware command and
91 * issues it to set the multicast list.
92 *
93 * This function can be used to enable promiscuous mode, or enable all
94 * multicast packets, or to enable selective multicast.
95 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070096int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
97 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070098{
99 int ret = 0;
100 u16 old_pkt_filter;
101
102 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700103
104 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
105 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
106 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
107 priv->curr_pkt_filter &=
108 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
109 } else {
110 /* Multicast */
111 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
112 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
113 dev_dbg(priv->adapter->dev,
114 "info: Enabling All Multicast!\n");
115 priv->curr_pkt_filter |=
116 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
117 } else {
118 priv->curr_pkt_filter &=
119 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
120 if (mcast_list->num_multicast_addr) {
121 dev_dbg(priv->adapter->dev,
122 "info: Set multicast list=%d\n",
123 mcast_list->num_multicast_addr);
124 /* Set multicast addresses to firmware */
125 if (old_pkt_filter == priv->curr_pkt_filter) {
126 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700127 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700128 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700129 HostCmd_ACT_GEN_SET, 0,
130 mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131 } else {
132 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700133 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700134 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700135 HostCmd_ACT_GEN_SET, 0,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700136 mcast_list);
137 }
138 }
139 }
140 }
141 dev_dbg(priv->adapter->dev,
142 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
143 old_pkt_filter, priv->curr_pkt_filter);
144 if (old_pkt_filter != priv->curr_pkt_filter) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700145 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
146 HostCmd_ACT_GEN_SET,
147 0, &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700148 }
149
150 return ret;
151}
152
153/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700154 * This function fills bss descriptor structure using provided
155 * information.
156 */
157int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
158 u8 *bssid, s32 rssi, u8 *ie_buf,
159 size_t ie_len, u16 beacon_period,
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -0700160 u16 cap_info_bitmap, u8 band,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700161 struct mwifiex_bssdescriptor *bss_desc)
162{
163 int ret;
164
165 memcpy(bss_desc->mac_address, bssid, ETH_ALEN);
166 bss_desc->rssi = rssi;
167 bss_desc->beacon_buf = ie_buf;
168 bss_desc->beacon_buf_size = ie_len;
169 bss_desc->beacon_period = beacon_period;
170 bss_desc->cap_info_bitmap = cap_info_bitmap;
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -0700171 bss_desc->bss_band = band;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700172 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
173 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
174 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
175 } else {
176 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
177 }
178 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
179 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
180 else
181 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
182
183 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
184 ie_buf, ie_len);
185
186 return ret;
187}
188
189/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700190 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
191 * In both Ad-Hoc and infra mode, an deauthentication is performed
192 * first.
193 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700194int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800195 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700196{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700197 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700198 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700199 struct mwifiex_bssdescriptor *bss_desc = NULL;
200 u8 *beacon_ie = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700201
202 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700203
204 if (bss) {
205 /* Allocate and fill new bss descriptor */
206 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
207 GFP_KERNEL);
208 if (!bss_desc) {
209 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
210 return -ENOMEM;
211 }
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700212
213 beacon_ie = kmemdup(bss->information_elements,
214 bss->len_beacon_ies, GFP_KERNEL);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700215 if (!beacon_ie) {
Dan Carpenteraef0ba52011-09-21 10:13:29 +0300216 kfree(bss_desc);
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700217 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700218 return -ENOMEM;
219 }
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700220
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700221 ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
222 beacon_ie, bss->len_beacon_ies,
223 bss->beacon_interval,
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -0700224 bss->capability,
225 *(u8 *)bss->priv, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700226 if (ret)
227 goto done;
228 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700229
Bing Zhaoeecd8252011-03-28 17:55:41 -0700230 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700231 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700232 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700233 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700234 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700235
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700236 ret = mwifiex_check_network_compatibility(priv, bss_desc);
237 if (ret)
238 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700239
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700240 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
241 "associating...\n");
242
243 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800244 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800245 if (netif_carrier_ok(priv->netdev))
246 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700247
248 /* Clear any past association response stored for
249 * application retrieval */
250 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700251 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800252
253 /* If auth type is auto and association fails using open mode,
254 * try to connect using shared mode */
255 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
256 priv->sec_info.is_authtype_auto &&
257 priv->sec_info.wep_enabled) {
258 priv->sec_info.authentication_mode =
259 NL80211_AUTHTYPE_SHARED_KEY;
260 ret = mwifiex_associate(priv, bss_desc);
261 }
262
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700263 if (bss)
264 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700265 } else {
266 /* Adhoc mode */
267 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700268 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700269 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
270 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700271 kfree(bss_desc);
272 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700273 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700274 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700275
276 /* Exit Adhoc mode first */
277 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700278 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700279 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700280 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700281
282 priv->adhoc_is_link_sensed = false;
283
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700284 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700285
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700286 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800287 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800288 if (netif_carrier_ok(priv->netdev))
289 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700290
291 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700292 dev_dbg(adapter->dev, "info: network found in scan"
293 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700294 ret = mwifiex_adhoc_join(priv, bss_desc);
295 if (bss)
296 cfg80211_put_bss(bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700297 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700298 dev_dbg(adapter->dev, "info: Network not found in "
299 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700300 req_ssid->ssid);
301 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700302 }
303 }
304
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700305done:
306 kfree(bss_desc);
307 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700308 return ret;
309}
310
311/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700312 * IOCTL request handler to set host sleep configuration.
313 *
314 * This function prepares the correct firmware command and
315 * issues it.
316 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700317static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
318 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700319
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700320{
321 struct mwifiex_adapter *adapter = priv->adapter;
322 int status = 0;
323 u32 prev_cond = 0;
324
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700325 if (!hs_cfg)
326 return -ENOMEM;
327
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700328 switch (action) {
329 case HostCmd_ACT_GEN_SET:
330 if (adapter->pps_uapsd_mode) {
331 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
332 " is blocked in UAPSD/PPS mode\n");
333 status = -1;
334 break;
335 }
336 if (hs_cfg->is_invoke_hostcmd) {
337 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
338 if (!adapter->is_hs_configured)
339 /* Already cancelled */
340 break;
341 /* Save previous condition */
342 prev_cond = le32_to_cpu(adapter->hs_cfg
343 .conditions);
344 adapter->hs_cfg.conditions =
345 cpu_to_le32(hs_cfg->conditions);
346 } else if (hs_cfg->conditions) {
347 adapter->hs_cfg.conditions =
348 cpu_to_le32(hs_cfg->conditions);
349 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
350 if (hs_cfg->gap)
351 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700352 } else if (adapter->hs_cfg.conditions
353 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700354 /* Return failure if no parameters for HS
355 enable */
356 status = -1;
357 break;
358 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700359 if (cmd_type == MWIFIEX_SYNC_CMD)
360 status = mwifiex_send_cmd_sync(priv,
361 HostCmd_CMD_802_11_HS_CFG_ENH,
362 HostCmd_ACT_GEN_SET, 0,
363 &adapter->hs_cfg);
364 else
365 status = mwifiex_send_cmd_async(priv,
366 HostCmd_CMD_802_11_HS_CFG_ENH,
367 HostCmd_ACT_GEN_SET, 0,
368 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700369 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
370 /* Restore previous condition */
371 adapter->hs_cfg.conditions =
372 cpu_to_le32(prev_cond);
373 } else {
374 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700375 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
377 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
378 }
379 break;
380 case HostCmd_ACT_GEN_GET:
381 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
382 hs_cfg->gpio = adapter->hs_cfg.gpio;
383 hs_cfg->gap = adapter->hs_cfg.gap;
384 break;
385 default:
386 status = -1;
387 break;
388 }
389
390 return status;
391}
392
393/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700394 * Sends IOCTL request to cancel the existing Host Sleep configuration.
395 *
396 * This function allocates the IOCTL request buffer, fills it
397 * with requisite parameters and calls the IOCTL handler.
398 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700399int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700400{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700401 struct mwifiex_ds_hs_cfg hscfg;
402
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700403 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
404 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700405
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700406 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
407 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700408}
409EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
410
411/*
412 * Sends IOCTL request to cancel the existing Host Sleep configuration.
413 *
414 * This function allocates the IOCTL request buffer, fills it
415 * with requisite parameters and calls the IOCTL handler.
416 */
417int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
418{
419 struct mwifiex_ds_hs_cfg hscfg;
420
421 if (adapter->hs_activated) {
422 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
423 return true;
424 }
425
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700426 adapter->hs_activate_wait_q_woken = false;
427
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700428 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700429 hscfg.is_invoke_hostcmd = true;
430
431 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700432 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700433 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
434 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700435 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
436 return false;
437 }
438
439 wait_event_interruptible(adapter->hs_activate_wait_q,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700440 adapter->hs_activate_wait_q_woken);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700441
442 return true;
443}
444EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
445
446/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700447 * IOCTL request handler to get BSS information.
448 *
449 * This function collates the information from different driver structures
450 * to send to the user.
451 */
452int mwifiex_get_bss_info(struct mwifiex_private *priv,
453 struct mwifiex_bss_info *info)
454{
455 struct mwifiex_adapter *adapter = priv->adapter;
456 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700457
458 if (!info)
459 return -1;
460
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700461 bss_desc = &priv->curr_bss_params.bss_descriptor;
462
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 info->bss_mode = priv->bss_mode;
464
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800465 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700466
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700467 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
468
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 info->bss_chan = bss_desc->channel;
470
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700471 memcpy(info->country_code, priv->country_code,
472 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474 info->media_connected = priv->media_connected;
475
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476 info->max_power_level = priv->max_tx_power_level;
477 info->min_power_level = priv->min_tx_power_level;
478
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700479 info->adhoc_state = priv->adhoc_state;
480
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700481 info->bcn_nf_last = priv->bcn_nf_last;
482
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800483 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700484 info->wep_status = true;
485 else
486 info->wep_status = false;
487
488 info->is_hs_configured = adapter->is_hs_configured;
489 info->is_deep_sleep = adapter->is_deep_sleep;
490
491 return 0;
492}
493
494/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700495 * The function disables auto deep sleep mode.
496 */
497int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
498{
499 struct mwifiex_ds_auto_ds auto_ds;
500
501 auto_ds.auto_ds = DEEP_SLEEP_OFF;
502
503 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
504 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
505}
506EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
507
508/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700509 * IOCTL request handler to set/get active channel.
510 *
511 * This function performs validity checking on channel/frequency
512 * compatibility and returns failure if not valid.
513 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700514int mwifiex_bss_set_channel(struct mwifiex_private *priv,
515 struct mwifiex_chan_freq_power *chan)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700516{
517 struct mwifiex_adapter *adapter = priv->adapter;
518 struct mwifiex_chan_freq_power *cfp = NULL;
519
520 if (!chan)
521 return -1;
522
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523 if (!chan->channel && !chan->freq)
524 return -1;
525 if (adapter->adhoc_start_band & BAND_AN)
526 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
527 else if (adapter->adhoc_start_band & BAND_A)
528 adapter->adhoc_start_band = BAND_G | BAND_B;
529 if (chan->channel) {
530 if (chan->channel <= MAX_CHANNEL_BAND_BG)
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700531 cfp = mwifiex_get_cfp(priv, 0, (u16) chan->channel, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700532 if (!cfp) {
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700533 cfp = mwifiex_get_cfp(priv, BAND_A,
534 (u16) chan->channel, 0);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535 if (cfp) {
536 if (adapter->adhoc_11n_enabled)
537 adapter->adhoc_start_band = BAND_A
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700538 | BAND_AN;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700539 else
540 adapter->adhoc_start_band = BAND_A;
541 }
542 }
543 } else {
544 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700545 cfp = mwifiex_get_cfp(priv, 0, 0, chan->freq);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700546 if (!cfp) {
Yogesh Ashok Powar6685d102012-03-12 19:35:10 -0700547 cfp = mwifiex_get_cfp(priv, BAND_A, 0, chan->freq);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 if (cfp) {
549 if (adapter->adhoc_11n_enabled)
550 adapter->adhoc_start_band = BAND_A
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700551 | BAND_AN;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700552 else
553 adapter->adhoc_start_band = BAND_A;
554 }
555 }
556 }
557 if (!cfp || !cfp->channel) {
558 dev_err(adapter->dev, "invalid channel/freq\n");
559 return -1;
560 }
561 priv->adhoc_channel = (u8) cfp->channel;
562 chan->channel = cfp->channel;
563 chan->freq = cfp->freq;
564
565 return 0;
566}
567
568/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700569 * IOCTL request handler to set/get Ad-Hoc channel.
570 *
571 * This function prepares the correct firmware command and
572 * issues it to set or get the ad-hoc channel.
573 */
574static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700575 u16 action, u16 *channel)
576{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700577 if (action == HostCmd_ACT_GEN_GET) {
578 if (!priv->media_connected) {
579 *channel = priv->adhoc_channel;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700580 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700581 }
582 } else {
583 priv->adhoc_channel = (u8) *channel;
584 }
585
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700586 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700587 action, 0, channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588}
589
590/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700591 * IOCTL request handler to change Ad-Hoc channel.
592 *
593 * This function allocates the IOCTL request buffer, fills it
594 * with requisite parameters and calls the IOCTL handler.
595 *
596 * The function follows the following steps to perform the change -
597 * - Get current IBSS information
598 * - Get current channel
599 * - If no change is required, return
600 * - If not connected, change channel and return
601 * - If connected,
602 * - Disconnect
603 * - Change channel
604 * - Perform specific SSID scan with same SSID
605 * - Start/Join the IBSS
606 */
607int
Dan Carpenter380aeef2012-03-01 10:22:30 +0300608mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, u16 channel)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700609{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700610 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700611 struct mwifiex_bss_info bss_info;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612 struct mwifiex_ssid_bssid ssid_bssid;
613 u16 curr_chan = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700614 struct cfg80211_bss *bss = NULL;
615 struct ieee80211_channel *chan;
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700616 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700617
618 memset(&bss_info, 0, sizeof(bss_info));
619
620 /* Get BSS information */
621 if (mwifiex_get_bss_info(priv, &bss_info))
622 return -1;
623
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700624 /* Get current channel */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700625 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
626 &curr_chan);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700627
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700628 if (curr_chan == channel) {
629 ret = 0;
630 goto done;
631 }
632 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700633 curr_chan, channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700634
635 if (!bss_info.media_connected) {
636 ret = 0;
637 goto done;
638 }
639
640 /* Do disonnect */
641 memset(&ssid_bssid, 0, ETH_ALEN);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700642 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700643
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700644 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
Dan Carpenter380aeef2012-03-01 10:22:30 +0300645 &channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700646
647 /* Do specific SSID scanning */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700648 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649 ret = -1;
650 goto done;
651 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700652
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700653 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700654 chan = __ieee80211_get_channel(priv->wdev->wiphy,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700655 ieee80211_channel_to_frequency(channel,
656 band));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700657
658 /* Find the BSS we want using available scan results */
659 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
660 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
661 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
662 if (!bss)
663 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700664 bss_info.bssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700665
666 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700667done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700668 return ret;
669}
670
671/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700672 * IOCTL request handler to get rate.
673 *
674 * This function prepares the correct firmware command and
675 * issues it to get the current rate if it is connected,
676 * otherwise, the function returns the lowest supported rate
677 * for the band.
678 */
679static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700680 struct mwifiex_rate_cfg *rate_cfg)
681{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700682 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
Amitkumar Karwarcbaaf592011-09-26 20:37:24 -0700683 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
684 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700685}
686
687/*
688 * IOCTL request handler to set rate.
689 *
690 * This function prepares the correct firmware command and
691 * issues it to set the current rate.
692 *
693 * The function also performs validation checking on the supplied value.
694 */
695static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700696 struct mwifiex_rate_cfg *rate_cfg)
697{
698 u8 rates[MWIFIEX_SUPPORTED_RATES];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700699 u8 *rate;
700 int rate_index, ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700701 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700702 u32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700703 struct mwifiex_adapter *adapter = priv->adapter;
704
705 if (rate_cfg->is_rate_auto) {
706 memset(bitmap_rates, 0, sizeof(bitmap_rates));
707 /* Support all HR/DSSS rates */
708 bitmap_rates[0] = 0x000F;
709 /* Support all OFDM rates */
710 bitmap_rates[1] = 0x00FF;
711 /* Support all HT-MCSs rate */
712 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
713 bitmap_rates[i + 2] = 0xFFFF;
714 bitmap_rates[9] = 0x3FFF;
715 } else {
716 memset(rates, 0, sizeof(rates));
717 mwifiex_get_active_data_rates(priv, rates);
718 rate = rates;
719 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
720 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
721 rate[i], rate_cfg->rate);
722 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
723 break;
724 }
Yogesh Ashok Powar3d82de02011-10-05 14:58:24 -0700725 if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726 dev_err(adapter->dev, "fixed data rate %#x is out "
727 "of range\n", rate_cfg->rate);
728 return -1;
729 }
730 memset(bitmap_rates, 0, sizeof(bitmap_rates));
731
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700732 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700733
734 /* Only allow b/g rates to be set */
735 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
736 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
737 bitmap_rates[0] = 1 << rate_index;
738 } else {
739 rate_index -= 1; /* There is a 0x00 in the table */
740 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
741 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
742 bitmap_rates[1] = 1 << (rate_index -
743 MWIFIEX_RATE_INDEX_OFDM0);
744 }
745 }
746
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700747 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
748 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700749
750 return ret;
751}
752
753/*
754 * IOCTL request handler to set/get rate.
755 *
756 * This function can be used to set/get either the rate value or the
757 * rate index.
758 */
759static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700760 struct mwifiex_rate_cfg *rate_cfg)
761{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700762 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700763
764 if (!rate_cfg)
765 return -1;
766
767 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700768 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700769 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700770 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700771
772 return status;
773}
774
775/*
776 * Sends IOCTL request to get the data rate.
777 *
778 * This function allocates the IOCTL request buffer, fills it
779 * with requisite parameters and calls the IOCTL handler.
780 */
781int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
782 struct mwifiex_rate_cfg *rate)
783{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700784 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700785
786 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
787 rate->action = HostCmd_ACT_GEN_GET;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700788 ret = mwifiex_rate_ioctl_cfg(priv, rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700789
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700790 if (!ret) {
Dan Carpenter49753122011-09-21 10:13:56 +0300791 if (rate->is_rate_auto)
Bing Zhaoe3bea1c2011-11-16 20:40:35 -0800792 rate->rate = mwifiex_index_to_data_rate(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700793 priv->tx_rate,
794 priv->tx_htinfo
795 );
Dan Carpenter49753122011-09-21 10:13:56 +0300796 else
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700797 rate->rate = priv->data_rate;
798 } else {
799 ret = -1;
800 }
801
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700802 return ret;
803}
804
805/*
806 * IOCTL request handler to set tx power configuration.
807 *
808 * This function prepares the correct firmware command and
809 * issues it.
810 *
811 * For non-auto power mode, all the following power groups are set -
812 * - Modulation class HR/DSSS
813 * - Modulation class OFDM
814 * - Modulation class HTBW20
815 * - Modulation class HTBW40
816 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700817int mwifiex_set_tx_power(struct mwifiex_private *priv,
818 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700819{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700820 int ret;
821 struct host_cmd_ds_txpwr_cfg *txp_cfg;
822 struct mwifiex_types_power_group *pg_tlv;
823 struct mwifiex_power_group *pg;
824 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825 u16 dbm = 0;
826
827 if (!power_cfg->is_power_auto) {
828 dbm = (u16) power_cfg->power_level;
829 if ((dbm < priv->min_tx_power_level) ||
830 (dbm > priv->max_tx_power_level)) {
831 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700832 " is out of range (%d dBm-%d dBm)\n",
833 dbm, priv->min_tx_power_level,
834 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700835 return -1;
836 }
837 }
838 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
839 if (!buf) {
840 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700841 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200842 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700843 }
844
845 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
846 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
847 if (!power_cfg->is_power_auto) {
848 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700849 pg_tlv = (struct mwifiex_types_power_group *)
850 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700851 pg_tlv->type = TLV_TYPE_POWER_GROUP;
852 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700853 pg = (struct mwifiex_power_group *)
854 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
855 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700856 /* Power group for modulation class HR/DSSS */
857 pg->first_rate_code = 0x00;
858 pg->last_rate_code = 0x03;
859 pg->modulation_class = MOD_CLASS_HR_DSSS;
860 pg->power_step = 0;
861 pg->power_min = (s8) dbm;
862 pg->power_max = (s8) dbm;
863 pg++;
864 /* Power group for modulation class OFDM */
865 pg->first_rate_code = 0x00;
866 pg->last_rate_code = 0x07;
867 pg->modulation_class = MOD_CLASS_OFDM;
868 pg->power_step = 0;
869 pg->power_min = (s8) dbm;
870 pg->power_max = (s8) dbm;
871 pg++;
872 /* Power group for modulation class HTBW20 */
873 pg->first_rate_code = 0x00;
874 pg->last_rate_code = 0x20;
875 pg->modulation_class = MOD_CLASS_HT;
876 pg->power_step = 0;
877 pg->power_min = (s8) dbm;
878 pg->power_max = (s8) dbm;
879 pg->ht_bandwidth = HT_BW_20;
880 pg++;
881 /* Power group for modulation class HTBW40 */
882 pg->first_rate_code = 0x00;
883 pg->last_rate_code = 0x20;
884 pg->modulation_class = MOD_CLASS_HT;
885 pg->power_step = 0;
886 pg->power_min = (s8) dbm;
887 pg->power_max = (s8) dbm;
888 pg->ht_bandwidth = HT_BW_40;
889 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700890 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
891 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700892
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700893 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700894 return ret;
895}
896
897/*
898 * IOCTL request handler to get power save mode.
899 *
900 * This function prepares the correct firmware command and
901 * issues it.
902 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700903int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700904{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700905 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700906 struct mwifiex_adapter *adapter = priv->adapter;
907 u16 sub_cmd;
908
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700909 if (*ps_mode)
910 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
911 else
912 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
913 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
914 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
915 sub_cmd, BITMAP_STA_PS, NULL);
916 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
917 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700918 HostCmd_CMD_802_11_PS_MODE_ENH,
919 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700920
921 return ret;
922}
923
924/*
925 * IOCTL request handler to set/reset WPA IE.
926 *
927 * The supplied WPA IE is treated as a opaque buffer. Only the first field
928 * is checked to determine WPA version. If buffer length is zero, the existing
929 * WPA IE is reset.
930 */
931static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
932 u8 *ie_data_ptr, u16 ie_len)
933{
934 if (ie_len) {
935 if (ie_len > sizeof(priv->wpa_ie)) {
936 dev_err(priv->adapter->dev,
937 "failed to copy WPA IE, too big\n");
938 return -1;
939 }
940 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
941 priv->wpa_ie_len = (u8) ie_len;
942 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700943 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700944
945 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
946 priv->sec_info.wpa_enabled = true;
947 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
948 priv->sec_info.wpa2_enabled = true;
949 } else {
950 priv->sec_info.wpa_enabled = false;
951 priv->sec_info.wpa2_enabled = false;
952 }
953 } else {
954 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
955 priv->wpa_ie_len = 0;
956 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
957 priv->wpa_ie_len, priv->wpa_ie[0]);
958 priv->sec_info.wpa_enabled = false;
959 priv->sec_info.wpa2_enabled = false;
960 }
961
962 return 0;
963}
964
965/*
966 * IOCTL request handler to set/reset WAPI IE.
967 *
968 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
969 * is checked to internally enable WAPI. If buffer length is zero, the existing
970 * WAPI IE is reset.
971 */
972static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
973 u8 *ie_data_ptr, u16 ie_len)
974{
975 if (ie_len) {
976 if (ie_len > sizeof(priv->wapi_ie)) {
977 dev_dbg(priv->adapter->dev,
978 "info: failed to copy WAPI IE, too big\n");
979 return -1;
980 }
981 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
982 priv->wapi_ie_len = ie_len;
983 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700984 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700985
986 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
987 priv->sec_info.wapi_enabled = true;
988 } else {
989 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
990 priv->wapi_ie_len = ie_len;
991 dev_dbg(priv->adapter->dev,
992 "info: Reset wapi_ie_len=%d IE=%#x\n",
993 priv->wapi_ie_len, priv->wapi_ie[0]);
994 priv->sec_info.wapi_enabled = false;
995 }
996 return 0;
997}
998
999/*
Avinash Patil13d7ba782012-04-09 20:06:56 -07001000 * IOCTL request handler to set/reset WPS IE.
1001 *
1002 * The supplied WPS IE is treated as a opaque buffer. Only the first field
1003 * is checked to internally enable WPS. If buffer length is zero, the existing
1004 * WPS IE is reset.
1005 */
1006static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
1007 u8 *ie_data_ptr, u16 ie_len)
1008{
1009 if (ie_len) {
1010 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
1011 if (!priv->wps_ie)
1012 return -ENOMEM;
1013 if (ie_len > sizeof(priv->wps_ie)) {
1014 dev_dbg(priv->adapter->dev,
1015 "info: failed to copy WPS IE, too big\n");
1016 kfree(priv->wps_ie);
1017 return -1;
1018 }
1019 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
1020 priv->wps_ie_len = ie_len;
1021 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
1022 priv->wps_ie_len, priv->wps_ie[0]);
1023 } else {
1024 kfree(priv->wps_ie);
1025 priv->wps_ie_len = ie_len;
1026 dev_dbg(priv->adapter->dev,
1027 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
1028 }
1029 return 0;
1030}
1031
1032/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001033 * IOCTL request handler to set WAPI key.
1034 *
1035 * This function prepares the correct firmware command and
1036 * issues it.
1037 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001038static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039 struct mwifiex_ds_encrypt_key *encrypt_key)
1040{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001041
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001042 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001043 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1044 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001045}
1046
1047/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001048 * IOCTL request handler to set WEP network key.
1049 *
1050 * This function prepares the correct firmware command and
1051 * issues it, after validation checks.
1052 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001053static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054 struct mwifiex_ds_encrypt_key *encrypt_key)
1055{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001056 int ret;
1057 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058 int index;
1059
1060 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1061 priv->wep_key_curr_index = 0;
1062 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1063 index = encrypt_key->key_index;
1064 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001065 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001066 } else if (!encrypt_key->key_len) {
1067 /* Copy the required key as the current key */
1068 wep_key = &priv->wep_key[index];
1069 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001070 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001071 "key not set, so cannot enable it\n");
1072 return -1;
1073 }
1074 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001075 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001076 } else {
1077 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001078 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1079 /* Copy the key in the driver */
1080 memcpy(wep_key->key_material,
1081 encrypt_key->key_material,
1082 encrypt_key->key_len);
1083 wep_key->key_index = index;
1084 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001085 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001086 }
1087 if (wep_key->key_length) {
1088 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001089 ret = mwifiex_send_cmd_async(priv,
1090 HostCmd_CMD_802_11_KEY_MATERIAL,
1091 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001092 if (ret)
1093 return ret;
1094 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001095 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001096 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1097 else
1098 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1099
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001100 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1101 HostCmd_ACT_GEN_SET, 0,
1102 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103
1104 return ret;
1105}
1106
1107/*
1108 * IOCTL request handler to set WPA key.
1109 *
1110 * This function prepares the correct firmware command and
1111 * issues it, after validation checks.
1112 *
1113 * Current driver only supports key length of up to 32 bytes.
1114 *
1115 * This function can also be used to disable a currently set key.
1116 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001117static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001118 struct mwifiex_ds_encrypt_key *encrypt_key)
1119{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001120 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001121 u8 remove_key = false;
1122 struct host_cmd_ds_802_11_key_material *ibss_key;
1123
1124 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -07001125 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001126 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001127 return -1;
1128 }
1129
Bing Zhaoeecd8252011-03-28 17:55:41 -07001130 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001131 /*
1132 * IBSS/WPA-None uses only one key (Group) for both receiving
1133 * and sending unicast and multicast packets.
1134 */
1135 /* Send the key as PTK to firmware */
1136 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001137 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001138 HostCmd_CMD_802_11_KEY_MATERIAL,
1139 HostCmd_ACT_GEN_SET,
1140 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001141 if (ret)
1142 return ret;
1143
1144 ibss_key = &priv->aes_key;
1145 memset(ibss_key, 0,
1146 sizeof(struct host_cmd_ds_802_11_key_material));
1147 /* Copy the key in the driver */
1148 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1149 encrypt_key->key_len);
1150 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1151 sizeof(ibss_key->key_param_set.key_len));
1152 ibss_key->key_param_set.key_type_id
1153 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -07001154 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001155
1156 /* Send the key as GTK to firmware */
1157 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1158 }
1159
1160 if (!encrypt_key->key_index)
1161 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1162
1163 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001164 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001165 HostCmd_CMD_802_11_KEY_MATERIAL,
1166 HostCmd_ACT_GEN_SET,
1167 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001168 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001169 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001170 HostCmd_CMD_802_11_KEY_MATERIAL,
1171 HostCmd_ACT_GEN_SET,
1172 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001173
1174 return ret;
1175}
1176
1177/*
1178 * IOCTL request handler to set/get network keys.
1179 *
1180 * This is a generic key handling function which supports WEP, WPA
1181 * and WAPI.
1182 */
1183static int
1184mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001185 struct mwifiex_ds_encrypt_key *encrypt_key)
1186{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001187 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001188
1189 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001190 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001191 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001192 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001193 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001194 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001195 return status;
1196}
1197
1198/*
1199 * This function returns the driver version.
1200 */
1201int
1202mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1203 int max_len)
1204{
1205 union {
1206 u32 l;
1207 u8 c[4];
1208 } ver;
1209 char fw_ver[32];
1210
1211 ver.l = adapter->fw_release_number;
1212 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1213
1214 snprintf(version, max_len, driver_version, fw_ver);
1215
1216 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1217
1218 return 0;
1219}
1220
1221/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001222 * Sends IOCTL request to set encoding parameters.
1223 *
1224 * This function allocates the IOCTL request buffer, fills it
1225 * with requisite parameters and calls the IOCTL handler.
1226 */
1227int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1228 int key_len, u8 key_index, int disable)
1229{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001230 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001231
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1233 encrypt_key.key_len = key_len;
1234 if (!disable) {
1235 encrypt_key.key_index = key_index;
1236 if (key_len)
1237 memcpy(encrypt_key.key_material, key, key_len);
1238 } else {
1239 encrypt_key.key_disable = true;
1240 }
1241
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001242 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001243}
1244
1245/*
1246 * Sends IOCTL request to get extended version.
1247 *
1248 * This function allocates the IOCTL request buffer, fills it
1249 * with requisite parameters and calls the IOCTL handler.
1250 */
1251int
1252mwifiex_get_ver_ext(struct mwifiex_private *priv)
1253{
1254 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001256 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001257 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001258 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001259 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001260
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001261 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001262}
1263
1264/*
1265 * Sends IOCTL request to get statistics information.
1266 *
1267 * This function allocates the IOCTL request buffer, fills it
1268 * with requisite parameters and calls the IOCTL handler.
1269 */
1270int
1271mwifiex_get_stats_info(struct mwifiex_private *priv,
1272 struct mwifiex_ds_get_stats *log)
1273{
Bing Zhao67a50032011-07-13 18:38:34 -07001274 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001275 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001276}
1277
1278/*
1279 * IOCTL request handler to read/write register.
1280 *
1281 * This function prepares the correct firmware command and
1282 * issues it.
1283 *
1284 * Access to the following registers are supported -
1285 * - MAC
1286 * - BBP
1287 * - RF
1288 * - PMIC
1289 * - CAU
1290 */
1291static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001292 struct mwifiex_ds_reg_rw *reg_rw,
1293 u16 action)
1294{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001295 u16 cmd_no;
1296
1297 switch (le32_to_cpu(reg_rw->type)) {
1298 case MWIFIEX_REG_MAC:
1299 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1300 break;
1301 case MWIFIEX_REG_BBP:
1302 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1303 break;
1304 case MWIFIEX_REG_RF:
1305 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1306 break;
1307 case MWIFIEX_REG_PMIC:
1308 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1309 break;
1310 case MWIFIEX_REG_CAU:
1311 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1312 break;
1313 default:
1314 return -1;
1315 }
1316
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001317 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001318
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001319}
1320
1321/*
1322 * Sends IOCTL request to write to a register.
1323 *
1324 * This function allocates the IOCTL request buffer, fills it
1325 * with requisite parameters and calls the IOCTL handler.
1326 */
1327int
1328mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1329 u32 reg_offset, u32 reg_value)
1330{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001331 struct mwifiex_ds_reg_rw reg_rw;
1332
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001333 reg_rw.type = cpu_to_le32(reg_type);
1334 reg_rw.offset = cpu_to_le32(reg_offset);
1335 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001336
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001337 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001338}
1339
1340/*
1341 * Sends IOCTL request to read from a register.
1342 *
1343 * This function allocates the IOCTL request buffer, fills it
1344 * with requisite parameters and calls the IOCTL handler.
1345 */
1346int
1347mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1348 u32 reg_offset, u32 *value)
1349{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001350 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001351 struct mwifiex_ds_reg_rw reg_rw;
1352
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001353 reg_rw.type = cpu_to_le32(reg_type);
1354 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001355 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001356
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001357 if (ret)
1358 goto done;
1359
1360 *value = le32_to_cpu(reg_rw.value);
1361
1362done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001363 return ret;
1364}
1365
1366/*
1367 * Sends IOCTL request to read from EEPROM.
1368 *
1369 * This function allocates the IOCTL request buffer, fills it
1370 * with requisite parameters and calls the IOCTL handler.
1371 */
1372int
1373mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1374 u8 *value)
1375{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001376 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001377 struct mwifiex_ds_read_eeprom rd_eeprom;
1378
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001379 rd_eeprom.offset = cpu_to_le16((u16) offset);
1380 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001381
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001382 /* Send request to firmware */
1383 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1384 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001385
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001386 if (!ret)
1387 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001388 return ret;
1389}
1390
1391/*
1392 * This function sets a generic IE. In addition to generic IE, it can
1393 * also handle WPA, WPA2 and WAPI IEs.
1394 */
1395static int
1396mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1397 u16 ie_len)
1398{
1399 int ret = 0;
1400 struct ieee_types_vendor_header *pvendor_ie;
1401 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1402 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1403
1404 /* If the passed length is zero, reset the buffer */
1405 if (!ie_len) {
1406 priv->gen_ie_buf_len = 0;
1407 priv->wps.session_enable = false;
1408
1409 return 0;
1410 } else if (!ie_data_ptr) {
1411 return -1;
1412 }
1413 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1414 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001415 if (((pvendor_ie->element_id == WLAN_EID_WPA) &&
1416 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1417 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001418
1419 /* IE is a WPA/WPA2 IE so call set_wpa function */
1420 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1421 priv->wps.session_enable = false;
1422
1423 return ret;
1424 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1425 /* IE is a WAPI IE so call set_wapi function */
1426 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1427
1428 return ret;
1429 }
1430 /*
1431 * Verify that the passed length is not larger than the
1432 * available space remaining in the buffer
1433 */
1434 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1435
1436 /* Test to see if it is a WPS IE, if so, enable
1437 * wps session flag
1438 */
1439 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001440 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1441 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001442 priv->wps.session_enable = true;
1443 dev_dbg(priv->adapter->dev,
1444 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001445 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001446 }
1447
1448 /* Append the passed data to the end of the
1449 genIeBuffer */
1450 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001451 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001452 /* Increment the stored buffer length by the
1453 size passed */
1454 priv->gen_ie_buf_len += ie_len;
1455 } else {
1456 /* Passed data does not fit in the remaining
1457 buffer space */
1458 ret = -1;
1459 }
1460
1461 /* Return 0, or -1 for error case */
1462 return ret;
1463}
1464
1465/*
1466 * IOCTL request handler to set/get generic IE.
1467 *
1468 * In addition to various generic IEs, this function can also be
1469 * used to set the ARP filter.
1470 */
1471static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1472 struct mwifiex_ds_misc_gen_ie *gen_ie,
1473 u16 action)
1474{
1475 struct mwifiex_adapter *adapter = priv->adapter;
1476
1477 switch (gen_ie->type) {
1478 case MWIFIEX_IE_TYPE_GEN_IE:
1479 if (action == HostCmd_ACT_GEN_GET) {
1480 gen_ie->len = priv->wpa_ie_len;
1481 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1482 } else {
1483 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1484 (u16) gen_ie->len);
1485 }
1486 break;
1487 case MWIFIEX_IE_TYPE_ARP_FILTER:
1488 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1489 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1490 adapter->arp_filter_size = 0;
1491 dev_err(adapter->dev, "invalid ARP filter size\n");
1492 return -1;
1493 } else {
1494 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001495 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001496 adapter->arp_filter_size = gen_ie->len;
1497 }
1498 break;
1499 default:
1500 dev_err(adapter->dev, "invalid IE type\n");
1501 return -1;
1502 }
1503 return 0;
1504}
1505
1506/*
1507 * Sends IOCTL request to set a generic IE.
1508 *
1509 * This function allocates the IOCTL request buffer, fills it
1510 * with requisite parameters and calls the IOCTL handler.
1511 */
1512int
1513mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1514{
1515 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001516
Bing Zhao67a50032011-07-13 18:38:34 -07001517 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001518 return -EFAULT;
1519
1520 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1521 gen_ie.len = ie_len;
1522 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001523 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001524 return -EFAULT;
1525
1526 return 0;
1527}