blob: b0fbf5d4fea0bd6fbc9b8b340339f1db145059ee [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,
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -070074 *(cmd_queued->condition));
75 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,
195 struct mwifiex_802_11_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);
252 if (bss)
253 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700254 } else {
255 /* Adhoc mode */
256 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700257 if (bss_desc && bss_desc->ssid.ssid_len &&
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258 (!mwifiex_ssid_cmp
259 (&priv->curr_bss_params.bss_descriptor.ssid,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700260 &bss_desc->ssid))) {
261 kfree(bss_desc);
262 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700263 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700264 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700265
266 /* Exit Adhoc mode first */
267 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700268 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700270 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700271
272 priv->adhoc_is_link_sensed = false;
273
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700274 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700275
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700276 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800277 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800278 if (netif_carrier_ok(priv->netdev))
279 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700280
281 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700282 dev_dbg(adapter->dev, "info: network found in scan"
283 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700284 ret = mwifiex_adhoc_join(priv, bss_desc);
285 if (bss)
286 cfg80211_put_bss(bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700287 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700288 dev_dbg(adapter->dev, "info: Network not found in "
289 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700290 req_ssid->ssid);
291 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700292 }
293 }
294
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700295done:
296 kfree(bss_desc);
297 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700298 return ret;
299}
300
301/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700302 * IOCTL request handler to set host sleep configuration.
303 *
304 * This function prepares the correct firmware command and
305 * issues it.
306 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700307static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
308 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700309
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700310{
311 struct mwifiex_adapter *adapter = priv->adapter;
312 int status = 0;
313 u32 prev_cond = 0;
314
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700315 if (!hs_cfg)
316 return -ENOMEM;
317
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700318 switch (action) {
319 case HostCmd_ACT_GEN_SET:
320 if (adapter->pps_uapsd_mode) {
321 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
322 " is blocked in UAPSD/PPS mode\n");
323 status = -1;
324 break;
325 }
326 if (hs_cfg->is_invoke_hostcmd) {
327 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
328 if (!adapter->is_hs_configured)
329 /* Already cancelled */
330 break;
331 /* Save previous condition */
332 prev_cond = le32_to_cpu(adapter->hs_cfg
333 .conditions);
334 adapter->hs_cfg.conditions =
335 cpu_to_le32(hs_cfg->conditions);
336 } else if (hs_cfg->conditions) {
337 adapter->hs_cfg.conditions =
338 cpu_to_le32(hs_cfg->conditions);
339 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
340 if (hs_cfg->gap)
341 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
342 } else if (adapter->hs_cfg.conditions ==
343 cpu_to_le32(
344 HOST_SLEEP_CFG_CANCEL)) {
345 /* Return failure if no parameters for HS
346 enable */
347 status = -1;
348 break;
349 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700350 if (cmd_type == MWIFIEX_SYNC_CMD)
351 status = mwifiex_send_cmd_sync(priv,
352 HostCmd_CMD_802_11_HS_CFG_ENH,
353 HostCmd_ACT_GEN_SET, 0,
354 &adapter->hs_cfg);
355 else
356 status = mwifiex_send_cmd_async(priv,
357 HostCmd_CMD_802_11_HS_CFG_ENH,
358 HostCmd_ACT_GEN_SET, 0,
359 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700360 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
361 /* Restore previous condition */
362 adapter->hs_cfg.conditions =
363 cpu_to_le32(prev_cond);
364 } else {
365 adapter->hs_cfg.conditions =
366 cpu_to_le32(hs_cfg->conditions);
367 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
368 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
369 }
370 break;
371 case HostCmd_ACT_GEN_GET:
372 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
373 hs_cfg->gpio = adapter->hs_cfg.gpio;
374 hs_cfg->gap = adapter->hs_cfg.gap;
375 break;
376 default:
377 status = -1;
378 break;
379 }
380
381 return status;
382}
383
384/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700385 * Sends IOCTL request to cancel the existing Host Sleep configuration.
386 *
387 * This function allocates the IOCTL request buffer, fills it
388 * with requisite parameters and calls the IOCTL handler.
389 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700390int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700391{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700392 struct mwifiex_ds_hs_cfg hscfg;
393
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700394 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
395 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700396
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700397 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
398 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700399}
400EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
401
402/*
403 * Sends IOCTL request to cancel the existing Host Sleep configuration.
404 *
405 * This function allocates the IOCTL request buffer, fills it
406 * with requisite parameters and calls the IOCTL handler.
407 */
408int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
409{
410 struct mwifiex_ds_hs_cfg hscfg;
411
412 if (adapter->hs_activated) {
413 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
414 return true;
415 }
416
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700417 adapter->hs_activate_wait_q_woken = false;
418
419 memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
420 hscfg.is_invoke_hostcmd = true;
421
422 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
423 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700424 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
425 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700426 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
427 return false;
428 }
429
430 wait_event_interruptible(adapter->hs_activate_wait_q,
431 adapter->hs_activate_wait_q_woken);
432
433 return true;
434}
435EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
436
437/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700438 * IOCTL request handler to get BSS information.
439 *
440 * This function collates the information from different driver structures
441 * to send to the user.
442 */
443int mwifiex_get_bss_info(struct mwifiex_private *priv,
444 struct mwifiex_bss_info *info)
445{
446 struct mwifiex_adapter *adapter = priv->adapter;
447 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448
449 if (!info)
450 return -1;
451
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700452 bss_desc = &priv->curr_bss_params.bss_descriptor;
453
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700454 info->bss_mode = priv->bss_mode;
455
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700456 memcpy(&info->ssid, &bss_desc->ssid,
457 sizeof(struct mwifiex_802_11_ssid));
458
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700459 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
460
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700461 info->bss_chan = bss_desc->channel;
462
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 info->region_code = adapter->region_code;
464
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700465 info->media_connected = priv->media_connected;
466
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700467 info->max_power_level = priv->max_tx_power_level;
468 info->min_power_level = priv->min_tx_power_level;
469
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470 info->adhoc_state = priv->adhoc_state;
471
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700472 info->bcn_nf_last = priv->bcn_nf_last;
473
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
475 info->wep_status = true;
476 else
477 info->wep_status = false;
478
479 info->is_hs_configured = adapter->is_hs_configured;
480 info->is_deep_sleep = adapter->is_deep_sleep;
481
482 return 0;
483}
484
485/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700486 * The function disables auto deep sleep mode.
487 */
488int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
489{
490 struct mwifiex_ds_auto_ds auto_ds;
491
492 auto_ds.auto_ds = DEEP_SLEEP_OFF;
493
494 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
495 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
496}
497EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
498
499/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700500 * IOCTL request handler to set/get active channel.
501 *
502 * This function performs validity checking on channel/frequency
503 * compatibility and returns failure if not valid.
504 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700505int mwifiex_bss_set_channel(struct mwifiex_private *priv,
506 struct mwifiex_chan_freq_power *chan)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700507{
508 struct mwifiex_adapter *adapter = priv->adapter;
509 struct mwifiex_chan_freq_power *cfp = NULL;
510
511 if (!chan)
512 return -1;
513
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514 if (!chan->channel && !chan->freq)
515 return -1;
516 if (adapter->adhoc_start_band & BAND_AN)
517 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
518 else if (adapter->adhoc_start_band & BAND_A)
519 adapter->adhoc_start_band = BAND_G | BAND_B;
520 if (chan->channel) {
521 if (chan->channel <= MAX_CHANNEL_BAND_BG)
522 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
523 (priv, 0, (u16) chan->channel);
524 if (!cfp) {
525 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
526 (priv, BAND_A, (u16) chan->channel);
527 if (cfp) {
528 if (adapter->adhoc_11n_enabled)
529 adapter->adhoc_start_band = BAND_A
530 | BAND_AN;
531 else
532 adapter->adhoc_start_band = BAND_A;
533 }
534 }
535 } else {
536 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
537 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
538 priv, 0, chan->freq);
539 if (!cfp) {
540 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
541 (priv, BAND_A, chan->freq);
542 if (cfp) {
543 if (adapter->adhoc_11n_enabled)
544 adapter->adhoc_start_band = BAND_A
545 | BAND_AN;
546 else
547 adapter->adhoc_start_band = BAND_A;
548 }
549 }
550 }
551 if (!cfp || !cfp->channel) {
552 dev_err(adapter->dev, "invalid channel/freq\n");
553 return -1;
554 }
555 priv->adhoc_channel = (u8) cfp->channel;
556 chan->channel = cfp->channel;
557 chan->freq = cfp->freq;
558
559 return 0;
560}
561
562/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 * IOCTL request handler to set/get Ad-Hoc channel.
564 *
565 * This function prepares the correct firmware command and
566 * issues it to set or get the ad-hoc channel.
567 */
568static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700569 u16 action, u16 *channel)
570{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700571 if (action == HostCmd_ACT_GEN_GET) {
572 if (!priv->media_connected) {
573 *channel = priv->adhoc_channel;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700574 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700575 }
576 } else {
577 priv->adhoc_channel = (u8) *channel;
578 }
579
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700580 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700581 action, 0, channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700582}
583
584/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700585 * IOCTL request handler to change Ad-Hoc channel.
586 *
587 * This function allocates the IOCTL request buffer, fills it
588 * with requisite parameters and calls the IOCTL handler.
589 *
590 * The function follows the following steps to perform the change -
591 * - Get current IBSS information
592 * - Get current channel
593 * - If no change is required, return
594 * - If not connected, change channel and return
595 * - If connected,
596 * - Disconnect
597 * - Change channel
598 * - Perform specific SSID scan with same SSID
599 * - Start/Join the IBSS
600 */
601int
602mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
603{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700604 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700605 struct mwifiex_bss_info bss_info;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700606 struct mwifiex_ssid_bssid ssid_bssid;
607 u16 curr_chan = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700608 struct cfg80211_bss *bss = NULL;
609 struct ieee80211_channel *chan;
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700610 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700611
612 memset(&bss_info, 0, sizeof(bss_info));
613
614 /* Get BSS information */
615 if (mwifiex_get_bss_info(priv, &bss_info))
616 return -1;
617
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700618 /* Get current channel */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700619 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
620 &curr_chan);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700622 if (curr_chan == channel) {
623 ret = 0;
624 goto done;
625 }
626 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
627 curr_chan, channel);
628
629 if (!bss_info.media_connected) {
630 ret = 0;
631 goto done;
632 }
633
634 /* Do disonnect */
635 memset(&ssid_bssid, 0, ETH_ALEN);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700636 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700637
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700638 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
639 (u16 *) &channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700640
641 /* Do specific SSID scanning */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700642 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700643 ret = -1;
644 goto done;
645 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700646
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700647 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700648 chan = __ieee80211_get_channel(priv->wdev->wiphy,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700649 ieee80211_channel_to_frequency(channel, band));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700650
651 /* Find the BSS we want using available scan results */
652 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
653 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
654 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
655 if (!bss)
656 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
657 bss_info.bssid);
658
659 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700660done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700661 return ret;
662}
663
664/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700665 * IOCTL request handler to get rate.
666 *
667 * This function prepares the correct firmware command and
668 * issues it to get the current rate if it is connected,
669 * otherwise, the function returns the lowest supported rate
670 * for the band.
671 */
672static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700673 struct mwifiex_rate_cfg *rate_cfg)
674{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700675 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
Amitkumar Karwarcbaaf592011-09-26 20:37:24 -0700676 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
677 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700678}
679
680/*
681 * IOCTL request handler to set rate.
682 *
683 * This function prepares the correct firmware command and
684 * issues it to set the current rate.
685 *
686 * The function also performs validation checking on the supplied value.
687 */
688static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700689 struct mwifiex_rate_cfg *rate_cfg)
690{
691 u8 rates[MWIFIEX_SUPPORTED_RATES];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700692 u8 *rate;
693 int rate_index, ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700694 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700695 u32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700696 struct mwifiex_adapter *adapter = priv->adapter;
697
698 if (rate_cfg->is_rate_auto) {
699 memset(bitmap_rates, 0, sizeof(bitmap_rates));
700 /* Support all HR/DSSS rates */
701 bitmap_rates[0] = 0x000F;
702 /* Support all OFDM rates */
703 bitmap_rates[1] = 0x00FF;
704 /* Support all HT-MCSs rate */
705 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
706 bitmap_rates[i + 2] = 0xFFFF;
707 bitmap_rates[9] = 0x3FFF;
708 } else {
709 memset(rates, 0, sizeof(rates));
710 mwifiex_get_active_data_rates(priv, rates);
711 rate = rates;
712 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
713 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
714 rate[i], rate_cfg->rate);
715 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
716 break;
717 }
Yogesh Ashok Powar3d82de02011-10-05 14:58:24 -0700718 if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700719 dev_err(adapter->dev, "fixed data rate %#x is out "
720 "of range\n", rate_cfg->rate);
721 return -1;
722 }
723 memset(bitmap_rates, 0, sizeof(bitmap_rates));
724
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700725 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726
727 /* Only allow b/g rates to be set */
728 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
729 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
730 bitmap_rates[0] = 1 << rate_index;
731 } else {
732 rate_index -= 1; /* There is a 0x00 in the table */
733 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
734 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
735 bitmap_rates[1] = 1 << (rate_index -
736 MWIFIEX_RATE_INDEX_OFDM0);
737 }
738 }
739
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700740 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
741 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700742
743 return ret;
744}
745
746/*
747 * IOCTL request handler to set/get rate.
748 *
749 * This function can be used to set/get either the rate value or the
750 * rate index.
751 */
752static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700753 struct mwifiex_rate_cfg *rate_cfg)
754{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700755 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700756
757 if (!rate_cfg)
758 return -1;
759
760 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700761 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700762 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700763 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700764
765 return status;
766}
767
768/*
769 * Sends IOCTL request to get the data rate.
770 *
771 * This function allocates the IOCTL request buffer, fills it
772 * with requisite parameters and calls the IOCTL handler.
773 */
774int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
775 struct mwifiex_rate_cfg *rate)
776{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700777 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700778
779 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
780 rate->action = HostCmd_ACT_GEN_GET;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700781 ret = mwifiex_rate_ioctl_cfg(priv, rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700782
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700783 if (!ret) {
Dan Carpenter49753122011-09-21 10:13:56 +0300784 if (rate->is_rate_auto)
Bing Zhaoe3bea1c2011-11-16 20:40:35 -0800785 rate->rate = mwifiex_index_to_data_rate(priv,
786 priv->tx_rate, priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300787 else
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700788 rate->rate = priv->data_rate;
789 } else {
790 ret = -1;
791 }
792
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700793 return ret;
794}
795
796/*
797 * IOCTL request handler to set tx power configuration.
798 *
799 * This function prepares the correct firmware command and
800 * issues it.
801 *
802 * For non-auto power mode, all the following power groups are set -
803 * - Modulation class HR/DSSS
804 * - Modulation class OFDM
805 * - Modulation class HTBW20
806 * - Modulation class HTBW40
807 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700808int mwifiex_set_tx_power(struct mwifiex_private *priv,
809 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700810{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700811 int ret;
812 struct host_cmd_ds_txpwr_cfg *txp_cfg;
813 struct mwifiex_types_power_group *pg_tlv;
814 struct mwifiex_power_group *pg;
815 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700816 u16 dbm = 0;
817
818 if (!power_cfg->is_power_auto) {
819 dbm = (u16) power_cfg->power_level;
820 if ((dbm < priv->min_tx_power_level) ||
821 (dbm > priv->max_tx_power_level)) {
822 dev_err(priv->adapter->dev, "txpower value %d dBm"
823 " is out of range (%d dBm-%d dBm)\n",
824 dbm, priv->min_tx_power_level,
825 priv->max_tx_power_level);
826 return -1;
827 }
828 }
829 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
830 if (!buf) {
831 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
832 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200833 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700834 }
835
836 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
837 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
838 if (!power_cfg->is_power_auto) {
839 txp_cfg->mode = cpu_to_le32(1);
840 pg_tlv = (struct mwifiex_types_power_group *) (buf +
841 sizeof(struct host_cmd_ds_txpwr_cfg));
842 pg_tlv->type = TLV_TYPE_POWER_GROUP;
843 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
844 pg = (struct mwifiex_power_group *) (buf +
845 sizeof(struct host_cmd_ds_txpwr_cfg) +
846 sizeof(struct mwifiex_types_power_group));
847 /* Power group for modulation class HR/DSSS */
848 pg->first_rate_code = 0x00;
849 pg->last_rate_code = 0x03;
850 pg->modulation_class = MOD_CLASS_HR_DSSS;
851 pg->power_step = 0;
852 pg->power_min = (s8) dbm;
853 pg->power_max = (s8) dbm;
854 pg++;
855 /* Power group for modulation class OFDM */
856 pg->first_rate_code = 0x00;
857 pg->last_rate_code = 0x07;
858 pg->modulation_class = MOD_CLASS_OFDM;
859 pg->power_step = 0;
860 pg->power_min = (s8) dbm;
861 pg->power_max = (s8) dbm;
862 pg++;
863 /* Power group for modulation class HTBW20 */
864 pg->first_rate_code = 0x00;
865 pg->last_rate_code = 0x20;
866 pg->modulation_class = MOD_CLASS_HT;
867 pg->power_step = 0;
868 pg->power_min = (s8) dbm;
869 pg->power_max = (s8) dbm;
870 pg->ht_bandwidth = HT_BW_20;
871 pg++;
872 /* Power group for modulation class HTBW40 */
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_40;
880 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700881 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
882 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700883
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700884 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885 return ret;
886}
887
888/*
889 * IOCTL request handler to get power save mode.
890 *
891 * This function prepares the correct firmware command and
892 * issues it.
893 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700894int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700895{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700896 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700897 struct mwifiex_adapter *adapter = priv->adapter;
898 u16 sub_cmd;
899
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700900 if (*ps_mode)
901 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
902 else
903 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
904 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
905 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
906 sub_cmd, BITMAP_STA_PS, NULL);
907 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
908 ret = mwifiex_send_cmd_async(priv,
909 HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
910 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700911
912 return ret;
913}
914
915/*
916 * IOCTL request handler to set/reset WPA IE.
917 *
918 * The supplied WPA IE is treated as a opaque buffer. Only the first field
919 * is checked to determine WPA version. If buffer length is zero, the existing
920 * WPA IE is reset.
921 */
922static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
923 u8 *ie_data_ptr, u16 ie_len)
924{
925 if (ie_len) {
926 if (ie_len > sizeof(priv->wpa_ie)) {
927 dev_err(priv->adapter->dev,
928 "failed to copy WPA IE, too big\n");
929 return -1;
930 }
931 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
932 priv->wpa_ie_len = (u8) ie_len;
933 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
934 priv->wpa_ie_len, priv->wpa_ie[0]);
935
936 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
937 priv->sec_info.wpa_enabled = true;
938 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
939 priv->sec_info.wpa2_enabled = true;
940 } else {
941 priv->sec_info.wpa_enabled = false;
942 priv->sec_info.wpa2_enabled = false;
943 }
944 } else {
945 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
946 priv->wpa_ie_len = 0;
947 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
948 priv->wpa_ie_len, priv->wpa_ie[0]);
949 priv->sec_info.wpa_enabled = false;
950 priv->sec_info.wpa2_enabled = false;
951 }
952
953 return 0;
954}
955
956/*
957 * IOCTL request handler to set/reset WAPI IE.
958 *
959 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
960 * is checked to internally enable WAPI. If buffer length is zero, the existing
961 * WAPI IE is reset.
962 */
963static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
964 u8 *ie_data_ptr, u16 ie_len)
965{
966 if (ie_len) {
967 if (ie_len > sizeof(priv->wapi_ie)) {
968 dev_dbg(priv->adapter->dev,
969 "info: failed to copy WAPI IE, too big\n");
970 return -1;
971 }
972 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
973 priv->wapi_ie_len = ie_len;
974 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
975 priv->wapi_ie_len, priv->wapi_ie[0]);
976
977 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
978 priv->sec_info.wapi_enabled = true;
979 } else {
980 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
981 priv->wapi_ie_len = ie_len;
982 dev_dbg(priv->adapter->dev,
983 "info: Reset wapi_ie_len=%d IE=%#x\n",
984 priv->wapi_ie_len, priv->wapi_ie[0]);
985 priv->sec_info.wapi_enabled = false;
986 }
987 return 0;
988}
989
990/*
991 * IOCTL request handler to set WAPI key.
992 *
993 * This function prepares the correct firmware command and
994 * issues it.
995 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700996static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700997 struct mwifiex_ds_encrypt_key *encrypt_key)
998{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700999
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001000 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001001 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1002 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001003}
1004
1005/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001006 * IOCTL request handler to set WEP network key.
1007 *
1008 * This function prepares the correct firmware command and
1009 * issues it, after validation checks.
1010 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001011static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001012 struct mwifiex_ds_encrypt_key *encrypt_key)
1013{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001014 int ret;
1015 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016 int index;
1017
1018 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1019 priv->wep_key_curr_index = 0;
1020 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1021 index = encrypt_key->key_index;
1022 if (encrypt_key->key_disable) {
1023 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
1024 } else if (!encrypt_key->key_len) {
1025 /* Copy the required key as the current key */
1026 wep_key = &priv->wep_key[index];
1027 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001028 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001029 "key not set, so cannot enable it\n");
1030 return -1;
1031 }
1032 priv->wep_key_curr_index = (u16) index;
1033 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1034 } else {
1035 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001036 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1037 /* Copy the key in the driver */
1038 memcpy(wep_key->key_material,
1039 encrypt_key->key_material,
1040 encrypt_key->key_len);
1041 wep_key->key_index = index;
1042 wep_key->key_length = encrypt_key->key_len;
1043 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1044 }
1045 if (wep_key->key_length) {
1046 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001047 ret = mwifiex_send_cmd_async(priv,
1048 HostCmd_CMD_802_11_KEY_MATERIAL,
1049 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001050 if (ret)
1051 return ret;
1052 }
1053 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
1054 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1055 else
1056 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1057
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001058 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1059 HostCmd_ACT_GEN_SET, 0,
1060 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001061
1062 return ret;
1063}
1064
1065/*
1066 * IOCTL request handler to set WPA key.
1067 *
1068 * This function prepares the correct firmware command and
1069 * issues it, after validation checks.
1070 *
1071 * Current driver only supports key length of up to 32 bytes.
1072 *
1073 * This function can also be used to disable a currently set key.
1074 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001075static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001076 struct mwifiex_ds_encrypt_key *encrypt_key)
1077{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001078 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001079 u8 remove_key = false;
1080 struct host_cmd_ds_802_11_key_material *ibss_key;
1081
1082 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -07001083 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001084 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001085 return -1;
1086 }
1087
Bing Zhaoeecd8252011-03-28 17:55:41 -07001088 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001089 /*
1090 * IBSS/WPA-None uses only one key (Group) for both receiving
1091 * and sending unicast and multicast packets.
1092 */
1093 /* Send the key as PTK to firmware */
1094 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001095 ret = mwifiex_send_cmd_async(priv,
1096 HostCmd_CMD_802_11_KEY_MATERIAL,
1097 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1098 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001099 if (ret)
1100 return ret;
1101
1102 ibss_key = &priv->aes_key;
1103 memset(ibss_key, 0,
1104 sizeof(struct host_cmd_ds_802_11_key_material));
1105 /* Copy the key in the driver */
1106 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1107 encrypt_key->key_len);
1108 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1109 sizeof(ibss_key->key_param_set.key_len));
1110 ibss_key->key_param_set.key_type_id
1111 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -07001112 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001113
1114 /* Send the key as GTK to firmware */
1115 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1116 }
1117
1118 if (!encrypt_key->key_index)
1119 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1120
1121 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001122 ret = mwifiex_send_cmd_sync(priv,
1123 HostCmd_CMD_802_11_KEY_MATERIAL,
1124 HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
1125 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001126 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001127 ret = mwifiex_send_cmd_sync(priv,
1128 HostCmd_CMD_802_11_KEY_MATERIAL,
1129 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1130 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001131
1132 return ret;
1133}
1134
1135/*
1136 * IOCTL request handler to set/get network keys.
1137 *
1138 * This is a generic key handling function which supports WEP, WPA
1139 * and WAPI.
1140 */
1141static int
1142mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001143 struct mwifiex_ds_encrypt_key *encrypt_key)
1144{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001145 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001146
1147 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001148 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001150 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001151 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001152 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001153 return status;
1154}
1155
1156/*
1157 * This function returns the driver version.
1158 */
1159int
1160mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1161 int max_len)
1162{
1163 union {
1164 u32 l;
1165 u8 c[4];
1166 } ver;
1167 char fw_ver[32];
1168
1169 ver.l = adapter->fw_release_number;
1170 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1171
1172 snprintf(version, max_len, driver_version, fw_ver);
1173
1174 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1175
1176 return 0;
1177}
1178
1179/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001180 * Sends IOCTL request to get signal information.
1181 *
1182 * This function allocates the IOCTL request buffer, fills it
1183 * with requisite parameters and calls the IOCTL handler.
1184 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001185int mwifiex_get_signal_info(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001186 struct mwifiex_ds_get_signal *signal)
1187{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001188 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001189
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001190 signal->selector = ALL_RSSI_INFO_MASK;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001191
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001192 /* Signal info can be obtained only if connected */
1193 if (!priv->media_connected) {
1194 dev_dbg(priv->adapter->dev,
1195 "info: Can not get signal in disconnected state\n");
1196 return -1;
1197 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001198
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001199 status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
1200 HostCmd_ACT_GEN_GET, 0, signal);
1201
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 if (!status) {
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001203 if (signal->selector & BCN_RSSI_AVG_MASK)
Bing Zhao67a50032011-07-13 18:38:34 -07001204 priv->qual_level = signal->bcn_rssi_avg;
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001205 if (signal->selector & BCN_NF_AVG_MASK)
Bing Zhao67a50032011-07-13 18:38:34 -07001206 priv->qual_noise = signal->bcn_nf_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001207 }
1208
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001209 return status;
1210}
1211
1212/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001213 * Sends IOCTL request to set encoding parameters.
1214 *
1215 * This function allocates the IOCTL request buffer, fills it
1216 * with requisite parameters and calls the IOCTL handler.
1217 */
1218int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1219 int key_len, u8 key_index, int disable)
1220{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001221 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001222
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001223 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1224 encrypt_key.key_len = key_len;
1225 if (!disable) {
1226 encrypt_key.key_index = key_index;
1227 if (key_len)
1228 memcpy(encrypt_key.key_material, key, key_len);
1229 } else {
1230 encrypt_key.key_disable = true;
1231 }
1232
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001233 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001234}
1235
1236/*
1237 * Sends IOCTL request to get extended version.
1238 *
1239 * This function allocates the IOCTL request buffer, fills it
1240 * with requisite parameters and calls the IOCTL handler.
1241 */
1242int
1243mwifiex_get_ver_ext(struct mwifiex_private *priv)
1244{
1245 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001246
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001247 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001248 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1249 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1250 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001251
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001252 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001253}
1254
1255/*
1256 * Sends IOCTL request to get statistics information.
1257 *
1258 * This function allocates the IOCTL request buffer, fills it
1259 * with requisite parameters and calls the IOCTL handler.
1260 */
1261int
1262mwifiex_get_stats_info(struct mwifiex_private *priv,
1263 struct mwifiex_ds_get_stats *log)
1264{
Bing Zhao67a50032011-07-13 18:38:34 -07001265 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001266 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001267}
1268
1269/*
1270 * IOCTL request handler to read/write register.
1271 *
1272 * This function prepares the correct firmware command and
1273 * issues it.
1274 *
1275 * Access to the following registers are supported -
1276 * - MAC
1277 * - BBP
1278 * - RF
1279 * - PMIC
1280 * - CAU
1281 */
1282static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001283 struct mwifiex_ds_reg_rw *reg_rw,
1284 u16 action)
1285{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001286 u16 cmd_no;
1287
1288 switch (le32_to_cpu(reg_rw->type)) {
1289 case MWIFIEX_REG_MAC:
1290 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1291 break;
1292 case MWIFIEX_REG_BBP:
1293 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1294 break;
1295 case MWIFIEX_REG_RF:
1296 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1297 break;
1298 case MWIFIEX_REG_PMIC:
1299 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1300 break;
1301 case MWIFIEX_REG_CAU:
1302 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1303 break;
1304 default:
1305 return -1;
1306 }
1307
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001308 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001309
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001310}
1311
1312/*
1313 * Sends IOCTL request to write to a register.
1314 *
1315 * This function allocates the IOCTL request buffer, fills it
1316 * with requisite parameters and calls the IOCTL handler.
1317 */
1318int
1319mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1320 u32 reg_offset, u32 reg_value)
1321{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001322 struct mwifiex_ds_reg_rw reg_rw;
1323
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001324 reg_rw.type = cpu_to_le32(reg_type);
1325 reg_rw.offset = cpu_to_le32(reg_offset);
1326 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001327
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001328 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001329}
1330
1331/*
1332 * Sends IOCTL request to read from a register.
1333 *
1334 * This function allocates the IOCTL request buffer, fills it
1335 * with requisite parameters and calls the IOCTL handler.
1336 */
1337int
1338mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1339 u32 reg_offset, u32 *value)
1340{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001341 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001342 struct mwifiex_ds_reg_rw reg_rw;
1343
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001344 reg_rw.type = cpu_to_le32(reg_type);
1345 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001346 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001347
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001348 if (ret)
1349 goto done;
1350
1351 *value = le32_to_cpu(reg_rw.value);
1352
1353done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001354 return ret;
1355}
1356
1357/*
1358 * Sends IOCTL request to read from EEPROM.
1359 *
1360 * This function allocates the IOCTL request buffer, fills it
1361 * with requisite parameters and calls the IOCTL handler.
1362 */
1363int
1364mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1365 u8 *value)
1366{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001367 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001368 struct mwifiex_ds_read_eeprom rd_eeprom;
1369
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001370 rd_eeprom.offset = cpu_to_le16((u16) offset);
1371 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001372
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001373 /* Send request to firmware */
1374 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1375 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001376
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001377 if (!ret)
1378 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001379 return ret;
1380}
1381
1382/*
1383 * This function sets a generic IE. In addition to generic IE, it can
1384 * also handle WPA, WPA2 and WAPI IEs.
1385 */
1386static int
1387mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1388 u16 ie_len)
1389{
1390 int ret = 0;
1391 struct ieee_types_vendor_header *pvendor_ie;
1392 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1393 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1394
1395 /* If the passed length is zero, reset the buffer */
1396 if (!ie_len) {
1397 priv->gen_ie_buf_len = 0;
1398 priv->wps.session_enable = false;
1399
1400 return 0;
1401 } else if (!ie_data_ptr) {
1402 return -1;
1403 }
1404 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1405 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1406 if (((pvendor_ie->element_id == WLAN_EID_WPA)
1407 && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
1408 || (pvendor_ie->element_id == WLAN_EID_RSN)) {
1409
1410 /* IE is a WPA/WPA2 IE so call set_wpa function */
1411 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1412 priv->wps.session_enable = false;
1413
1414 return ret;
1415 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1416 /* IE is a WAPI IE so call set_wapi function */
1417 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1418
1419 return ret;
1420 }
1421 /*
1422 * Verify that the passed length is not larger than the
1423 * available space remaining in the buffer
1424 */
1425 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1426
1427 /* Test to see if it is a WPS IE, if so, enable
1428 * wps session flag
1429 */
1430 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1431 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
1432 && (!memcmp(pvendor_ie->oui, wps_oui,
1433 sizeof(wps_oui)))) {
1434 priv->wps.session_enable = true;
1435 dev_dbg(priv->adapter->dev,
1436 "info: WPS Session Enabled.\n");
1437 }
1438
1439 /* Append the passed data to the end of the
1440 genIeBuffer */
1441 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1442 ie_len);
1443 /* Increment the stored buffer length by the
1444 size passed */
1445 priv->gen_ie_buf_len += ie_len;
1446 } else {
1447 /* Passed data does not fit in the remaining
1448 buffer space */
1449 ret = -1;
1450 }
1451
1452 /* Return 0, or -1 for error case */
1453 return ret;
1454}
1455
1456/*
1457 * IOCTL request handler to set/get generic IE.
1458 *
1459 * In addition to various generic IEs, this function can also be
1460 * used to set the ARP filter.
1461 */
1462static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1463 struct mwifiex_ds_misc_gen_ie *gen_ie,
1464 u16 action)
1465{
1466 struct mwifiex_adapter *adapter = priv->adapter;
1467
1468 switch (gen_ie->type) {
1469 case MWIFIEX_IE_TYPE_GEN_IE:
1470 if (action == HostCmd_ACT_GEN_GET) {
1471 gen_ie->len = priv->wpa_ie_len;
1472 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1473 } else {
1474 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1475 (u16) gen_ie->len);
1476 }
1477 break;
1478 case MWIFIEX_IE_TYPE_ARP_FILTER:
1479 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1480 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1481 adapter->arp_filter_size = 0;
1482 dev_err(adapter->dev, "invalid ARP filter size\n");
1483 return -1;
1484 } else {
1485 memcpy(adapter->arp_filter, gen_ie->ie_data,
1486 gen_ie->len);
1487 adapter->arp_filter_size = gen_ie->len;
1488 }
1489 break;
1490 default:
1491 dev_err(adapter->dev, "invalid IE type\n");
1492 return -1;
1493 }
1494 return 0;
1495}
1496
1497/*
1498 * Sends IOCTL request to set a generic IE.
1499 *
1500 * This function allocates the IOCTL request buffer, fills it
1501 * with requisite parameters and calls the IOCTL handler.
1502 */
1503int
1504mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1505{
1506 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001507
Bing Zhao67a50032011-07-13 18:38:34 -07001508 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001509 return -EFAULT;
1510
1511 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1512 gen_ie.len = ie_len;
1513 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001514 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001515 return -EFAULT;
1516
1517 return 0;
1518}