blob: 0ae1209646c14859e76cc311f3cfdff585b501d8 [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,
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 &&
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 (!mwifiex_ssid_cmp
270 (&priv->curr_bss_params.bss_descriptor.ssid,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700271 &bss_desc->ssid))) {
272 kfree(bss_desc);
273 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700274 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700275 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700276
277 /* Exit Adhoc mode first */
278 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700279 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700281 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700282
283 priv->adhoc_is_link_sensed = false;
284
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700285 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700286
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700287 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800288 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800289 if (netif_carrier_ok(priv->netdev))
290 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700291
292 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700293 dev_dbg(adapter->dev, "info: network found in scan"
294 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700295 ret = mwifiex_adhoc_join(priv, bss_desc);
296 if (bss)
297 cfg80211_put_bss(bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700298 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700299 dev_dbg(adapter->dev, "info: Network not found in "
300 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700301 req_ssid->ssid);
302 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700303 }
304 }
305
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700306done:
307 kfree(bss_desc);
308 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700309 return ret;
310}
311
312/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700313 * IOCTL request handler to set host sleep configuration.
314 *
315 * This function prepares the correct firmware command and
316 * issues it.
317 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700318static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
319 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700320
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700321{
322 struct mwifiex_adapter *adapter = priv->adapter;
323 int status = 0;
324 u32 prev_cond = 0;
325
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700326 if (!hs_cfg)
327 return -ENOMEM;
328
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700329 switch (action) {
330 case HostCmd_ACT_GEN_SET:
331 if (adapter->pps_uapsd_mode) {
332 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
333 " is blocked in UAPSD/PPS mode\n");
334 status = -1;
335 break;
336 }
337 if (hs_cfg->is_invoke_hostcmd) {
338 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
339 if (!adapter->is_hs_configured)
340 /* Already cancelled */
341 break;
342 /* Save previous condition */
343 prev_cond = le32_to_cpu(adapter->hs_cfg
344 .conditions);
345 adapter->hs_cfg.conditions =
346 cpu_to_le32(hs_cfg->conditions);
347 } else if (hs_cfg->conditions) {
348 adapter->hs_cfg.conditions =
349 cpu_to_le32(hs_cfg->conditions);
350 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
351 if (hs_cfg->gap)
352 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
353 } else if (adapter->hs_cfg.conditions ==
354 cpu_to_le32(
355 HOST_SLEEP_CFG_CANCEL)) {
356 /* Return failure if no parameters for HS
357 enable */
358 status = -1;
359 break;
360 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700361 if (cmd_type == MWIFIEX_SYNC_CMD)
362 status = mwifiex_send_cmd_sync(priv,
363 HostCmd_CMD_802_11_HS_CFG_ENH,
364 HostCmd_ACT_GEN_SET, 0,
365 &adapter->hs_cfg);
366 else
367 status = mwifiex_send_cmd_async(priv,
368 HostCmd_CMD_802_11_HS_CFG_ENH,
369 HostCmd_ACT_GEN_SET, 0,
370 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
372 /* Restore previous condition */
373 adapter->hs_cfg.conditions =
374 cpu_to_le32(prev_cond);
375 } else {
376 adapter->hs_cfg.conditions =
377 cpu_to_le32(hs_cfg->conditions);
378 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
379 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
380 }
381 break;
382 case HostCmd_ACT_GEN_GET:
383 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
384 hs_cfg->gpio = adapter->hs_cfg.gpio;
385 hs_cfg->gap = adapter->hs_cfg.gap;
386 break;
387 default:
388 status = -1;
389 break;
390 }
391
392 return status;
393}
394
395/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700396 * Sends IOCTL request to cancel the existing Host Sleep configuration.
397 *
398 * This function allocates the IOCTL request buffer, fills it
399 * with requisite parameters and calls the IOCTL handler.
400 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700401int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700402{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700403 struct mwifiex_ds_hs_cfg hscfg;
404
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700405 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
406 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700407
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700408 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
409 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700410}
411EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
412
413/*
414 * Sends IOCTL request to cancel the existing Host Sleep configuration.
415 *
416 * This function allocates the IOCTL request buffer, fills it
417 * with requisite parameters and calls the IOCTL handler.
418 */
419int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
420{
421 struct mwifiex_ds_hs_cfg hscfg;
422
423 if (adapter->hs_activated) {
424 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
425 return true;
426 }
427
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700428 adapter->hs_activate_wait_q_woken = false;
429
430 memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
431 hscfg.is_invoke_hostcmd = true;
432
433 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
434 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700435 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
436 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700437 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
438 return false;
439 }
440
441 wait_event_interruptible(adapter->hs_activate_wait_q,
442 adapter->hs_activate_wait_q_woken);
443
444 return true;
445}
446EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
447
448/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700449 * IOCTL request handler to get BSS information.
450 *
451 * This function collates the information from different driver structures
452 * to send to the user.
453 */
454int mwifiex_get_bss_info(struct mwifiex_private *priv,
455 struct mwifiex_bss_info *info)
456{
457 struct mwifiex_adapter *adapter = priv->adapter;
458 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700459
460 if (!info)
461 return -1;
462
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700463 bss_desc = &priv->curr_bss_params.bss_descriptor;
464
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700465 info->bss_mode = priv->bss_mode;
466
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800467 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700468
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
470
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700471 info->bss_chan = bss_desc->channel;
472
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473 info->region_code = adapter->region_code;
474
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475 info->media_connected = priv->media_connected;
476
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700477 info->max_power_level = priv->max_tx_power_level;
478 info->min_power_level = priv->min_tx_power_level;
479
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700480 info->adhoc_state = priv->adhoc_state;
481
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700482 info->bcn_nf_last = priv->bcn_nf_last;
483
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800484 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700485 info->wep_status = true;
486 else
487 info->wep_status = false;
488
489 info->is_hs_configured = adapter->is_hs_configured;
490 info->is_deep_sleep = adapter->is_deep_sleep;
491
492 return 0;
493}
494
495/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700496 * The function disables auto deep sleep mode.
497 */
498int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
499{
500 struct mwifiex_ds_auto_ds auto_ds;
501
502 auto_ds.auto_ds = DEEP_SLEEP_OFF;
503
504 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
505 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
506}
507EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
508
509/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510 * IOCTL request handler to set/get active channel.
511 *
512 * This function performs validity checking on channel/frequency
513 * compatibility and returns failure if not valid.
514 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700515int mwifiex_bss_set_channel(struct mwifiex_private *priv,
516 struct mwifiex_chan_freq_power *chan)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700517{
518 struct mwifiex_adapter *adapter = priv->adapter;
519 struct mwifiex_chan_freq_power *cfp = NULL;
520
521 if (!chan)
522 return -1;
523
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700524 if (!chan->channel && !chan->freq)
525 return -1;
526 if (adapter->adhoc_start_band & BAND_AN)
527 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
528 else if (adapter->adhoc_start_band & BAND_A)
529 adapter->adhoc_start_band = BAND_G | BAND_B;
530 if (chan->channel) {
531 if (chan->channel <= MAX_CHANNEL_BAND_BG)
532 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
533 (priv, 0, (u16) chan->channel);
534 if (!cfp) {
535 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
536 (priv, BAND_A, (u16) chan->channel);
537 if (cfp) {
538 if (adapter->adhoc_11n_enabled)
539 adapter->adhoc_start_band = BAND_A
540 | BAND_AN;
541 else
542 adapter->adhoc_start_band = BAND_A;
543 }
544 }
545 } else {
546 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
547 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
548 priv, 0, chan->freq);
549 if (!cfp) {
550 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
551 (priv, BAND_A, chan->freq);
552 if (cfp) {
553 if (adapter->adhoc_11n_enabled)
554 adapter->adhoc_start_band = BAND_A
555 | BAND_AN;
556 else
557 adapter->adhoc_start_band = BAND_A;
558 }
559 }
560 }
561 if (!cfp || !cfp->channel) {
562 dev_err(adapter->dev, "invalid channel/freq\n");
563 return -1;
564 }
565 priv->adhoc_channel = (u8) cfp->channel;
566 chan->channel = cfp->channel;
567 chan->freq = cfp->freq;
568
569 return 0;
570}
571
572/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700573 * IOCTL request handler to set/get Ad-Hoc channel.
574 *
575 * This function prepares the correct firmware command and
576 * issues it to set or get the ad-hoc channel.
577 */
578static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700579 u16 action, u16 *channel)
580{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700581 if (action == HostCmd_ACT_GEN_GET) {
582 if (!priv->media_connected) {
583 *channel = priv->adhoc_channel;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700584 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700585 }
586 } else {
587 priv->adhoc_channel = (u8) *channel;
588 }
589
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700590 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700591 action, 0, channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700592}
593
594/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700595 * IOCTL request handler to change Ad-Hoc channel.
596 *
597 * This function allocates the IOCTL request buffer, fills it
598 * with requisite parameters and calls the IOCTL handler.
599 *
600 * The function follows the following steps to perform the change -
601 * - Get current IBSS information
602 * - Get current channel
603 * - If no change is required, return
604 * - If not connected, change channel and return
605 * - If connected,
606 * - Disconnect
607 * - Change channel
608 * - Perform specific SSID scan with same SSID
609 * - Start/Join the IBSS
610 */
611int
Dan Carpenter380aeef2012-03-01 10:22:30 +0300612mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, u16 channel)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700613{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700614 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700615 struct mwifiex_bss_info bss_info;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700616 struct mwifiex_ssid_bssid ssid_bssid;
617 u16 curr_chan = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700618 struct cfg80211_bss *bss = NULL;
619 struct ieee80211_channel *chan;
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700620 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700621
622 memset(&bss_info, 0, sizeof(bss_info));
623
624 /* Get BSS information */
625 if (mwifiex_get_bss_info(priv, &bss_info))
626 return -1;
627
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700628 /* Get current channel */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700629 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
630 &curr_chan);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700631
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700632 if (curr_chan == channel) {
633 ret = 0;
634 goto done;
635 }
636 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
637 curr_chan, channel);
638
639 if (!bss_info.media_connected) {
640 ret = 0;
641 goto done;
642 }
643
644 /* Do disonnect */
645 memset(&ssid_bssid, 0, ETH_ALEN);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700646 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700647
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700648 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
Dan Carpenter380aeef2012-03-01 10:22:30 +0300649 &channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700650
651 /* Do specific SSID scanning */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700652 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700653 ret = -1;
654 goto done;
655 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700656
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700657 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700658 chan = __ieee80211_get_channel(priv->wdev->wiphy,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700659 ieee80211_channel_to_frequency(channel, band));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700660
661 /* Find the BSS we want using available scan results */
662 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
663 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
664 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
665 if (!bss)
666 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
667 bss_info.bssid);
668
669 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700670done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700671 return ret;
672}
673
674/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700675 * IOCTL request handler to get rate.
676 *
677 * This function prepares the correct firmware command and
678 * issues it to get the current rate if it is connected,
679 * otherwise, the function returns the lowest supported rate
680 * for the band.
681 */
682static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700683 struct mwifiex_rate_cfg *rate_cfg)
684{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700685 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
Amitkumar Karwarcbaaf592011-09-26 20:37:24 -0700686 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
687 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700688}
689
690/*
691 * IOCTL request handler to set rate.
692 *
693 * This function prepares the correct firmware command and
694 * issues it to set the current rate.
695 *
696 * The function also performs validation checking on the supplied value.
697 */
698static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700699 struct mwifiex_rate_cfg *rate_cfg)
700{
701 u8 rates[MWIFIEX_SUPPORTED_RATES];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700702 u8 *rate;
703 int rate_index, ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700704 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700705 u32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700706 struct mwifiex_adapter *adapter = priv->adapter;
707
708 if (rate_cfg->is_rate_auto) {
709 memset(bitmap_rates, 0, sizeof(bitmap_rates));
710 /* Support all HR/DSSS rates */
711 bitmap_rates[0] = 0x000F;
712 /* Support all OFDM rates */
713 bitmap_rates[1] = 0x00FF;
714 /* Support all HT-MCSs rate */
715 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
716 bitmap_rates[i + 2] = 0xFFFF;
717 bitmap_rates[9] = 0x3FFF;
718 } else {
719 memset(rates, 0, sizeof(rates));
720 mwifiex_get_active_data_rates(priv, rates);
721 rate = rates;
722 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
723 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
724 rate[i], rate_cfg->rate);
725 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
726 break;
727 }
Yogesh Ashok Powar3d82de02011-10-05 14:58:24 -0700728 if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700729 dev_err(adapter->dev, "fixed data rate %#x is out "
730 "of range\n", rate_cfg->rate);
731 return -1;
732 }
733 memset(bitmap_rates, 0, sizeof(bitmap_rates));
734
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700735 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700736
737 /* Only allow b/g rates to be set */
738 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
739 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
740 bitmap_rates[0] = 1 << rate_index;
741 } else {
742 rate_index -= 1; /* There is a 0x00 in the table */
743 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
744 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
745 bitmap_rates[1] = 1 << (rate_index -
746 MWIFIEX_RATE_INDEX_OFDM0);
747 }
748 }
749
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700750 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
751 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700752
753 return ret;
754}
755
756/*
757 * IOCTL request handler to set/get rate.
758 *
759 * This function can be used to set/get either the rate value or the
760 * rate index.
761 */
762static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700763 struct mwifiex_rate_cfg *rate_cfg)
764{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700765 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700766
767 if (!rate_cfg)
768 return -1;
769
770 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700771 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700772 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700773 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700774
775 return status;
776}
777
778/*
779 * Sends IOCTL request to get the data rate.
780 *
781 * This function allocates the IOCTL request buffer, fills it
782 * with requisite parameters and calls the IOCTL handler.
783 */
784int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
785 struct mwifiex_rate_cfg *rate)
786{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700787 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700788
789 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
790 rate->action = HostCmd_ACT_GEN_GET;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700791 ret = mwifiex_rate_ioctl_cfg(priv, rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700792
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700793 if (!ret) {
Dan Carpenter49753122011-09-21 10:13:56 +0300794 if (rate->is_rate_auto)
Bing Zhaoe3bea1c2011-11-16 20:40:35 -0800795 rate->rate = mwifiex_index_to_data_rate(priv,
796 priv->tx_rate, priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300797 else
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700798 rate->rate = priv->data_rate;
799 } else {
800 ret = -1;
801 }
802
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700803 return ret;
804}
805
806/*
807 * IOCTL request handler to set tx power configuration.
808 *
809 * This function prepares the correct firmware command and
810 * issues it.
811 *
812 * For non-auto power mode, all the following power groups are set -
813 * - Modulation class HR/DSSS
814 * - Modulation class OFDM
815 * - Modulation class HTBW20
816 * - Modulation class HTBW40
817 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700818int mwifiex_set_tx_power(struct mwifiex_private *priv,
819 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700820{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700821 int ret;
822 struct host_cmd_ds_txpwr_cfg *txp_cfg;
823 struct mwifiex_types_power_group *pg_tlv;
824 struct mwifiex_power_group *pg;
825 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700826 u16 dbm = 0;
827
828 if (!power_cfg->is_power_auto) {
829 dbm = (u16) power_cfg->power_level;
830 if ((dbm < priv->min_tx_power_level) ||
831 (dbm > priv->max_tx_power_level)) {
832 dev_err(priv->adapter->dev, "txpower value %d dBm"
833 " is out of range (%d dBm-%d dBm)\n",
834 dbm, priv->min_tx_power_level,
835 priv->max_tx_power_level);
836 return -1;
837 }
838 }
839 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
840 if (!buf) {
841 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
842 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200843 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700844 }
845
846 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
847 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
848 if (!power_cfg->is_power_auto) {
849 txp_cfg->mode = cpu_to_le32(1);
850 pg_tlv = (struct mwifiex_types_power_group *) (buf +
851 sizeof(struct host_cmd_ds_txpwr_cfg));
852 pg_tlv->type = TLV_TYPE_POWER_GROUP;
853 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
854 pg = (struct mwifiex_power_group *) (buf +
855 sizeof(struct host_cmd_ds_txpwr_cfg) +
856 sizeof(struct mwifiex_types_power_group));
857 /* Power group for modulation class HR/DSSS */
858 pg->first_rate_code = 0x00;
859 pg->last_rate_code = 0x03;
860 pg->modulation_class = MOD_CLASS_HR_DSSS;
861 pg->power_step = 0;
862 pg->power_min = (s8) dbm;
863 pg->power_max = (s8) dbm;
864 pg++;
865 /* Power group for modulation class OFDM */
866 pg->first_rate_code = 0x00;
867 pg->last_rate_code = 0x07;
868 pg->modulation_class = MOD_CLASS_OFDM;
869 pg->power_step = 0;
870 pg->power_min = (s8) dbm;
871 pg->power_max = (s8) dbm;
872 pg++;
873 /* Power group for modulation class HTBW20 */
874 pg->first_rate_code = 0x00;
875 pg->last_rate_code = 0x20;
876 pg->modulation_class = MOD_CLASS_HT;
877 pg->power_step = 0;
878 pg->power_min = (s8) dbm;
879 pg->power_max = (s8) dbm;
880 pg->ht_bandwidth = HT_BW_20;
881 pg++;
882 /* Power group for modulation class HTBW40 */
883 pg->first_rate_code = 0x00;
884 pg->last_rate_code = 0x20;
885 pg->modulation_class = MOD_CLASS_HT;
886 pg->power_step = 0;
887 pg->power_min = (s8) dbm;
888 pg->power_max = (s8) dbm;
889 pg->ht_bandwidth = HT_BW_40;
890 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700891 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
892 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700893
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700894 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700895 return ret;
896}
897
898/*
899 * IOCTL request handler to get power save mode.
900 *
901 * This function prepares the correct firmware command and
902 * issues it.
903 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700904int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700905{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700906 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700907 struct mwifiex_adapter *adapter = priv->adapter;
908 u16 sub_cmd;
909
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700910 if (*ps_mode)
911 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
912 else
913 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
914 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
915 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
916 sub_cmd, BITMAP_STA_PS, NULL);
917 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
918 ret = mwifiex_send_cmd_async(priv,
919 HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
920 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700921
922 return ret;
923}
924
925/*
926 * IOCTL request handler to set/reset WPA IE.
927 *
928 * The supplied WPA IE is treated as a opaque buffer. Only the first field
929 * is checked to determine WPA version. If buffer length is zero, the existing
930 * WPA IE is reset.
931 */
932static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
933 u8 *ie_data_ptr, u16 ie_len)
934{
935 if (ie_len) {
936 if (ie_len > sizeof(priv->wpa_ie)) {
937 dev_err(priv->adapter->dev,
938 "failed to copy WPA IE, too big\n");
939 return -1;
940 }
941 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
942 priv->wpa_ie_len = (u8) ie_len;
943 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
944 priv->wpa_ie_len, priv->wpa_ie[0]);
945
946 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
947 priv->sec_info.wpa_enabled = true;
948 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
949 priv->sec_info.wpa2_enabled = true;
950 } else {
951 priv->sec_info.wpa_enabled = false;
952 priv->sec_info.wpa2_enabled = false;
953 }
954 } else {
955 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
956 priv->wpa_ie_len = 0;
957 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
958 priv->wpa_ie_len, priv->wpa_ie[0]);
959 priv->sec_info.wpa_enabled = false;
960 priv->sec_info.wpa2_enabled = false;
961 }
962
963 return 0;
964}
965
966/*
967 * IOCTL request handler to set/reset WAPI IE.
968 *
969 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
970 * is checked to internally enable WAPI. If buffer length is zero, the existing
971 * WAPI IE is reset.
972 */
973static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
974 u8 *ie_data_ptr, u16 ie_len)
975{
976 if (ie_len) {
977 if (ie_len > sizeof(priv->wapi_ie)) {
978 dev_dbg(priv->adapter->dev,
979 "info: failed to copy WAPI IE, too big\n");
980 return -1;
981 }
982 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
983 priv->wapi_ie_len = ie_len;
984 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
985 priv->wapi_ie_len, priv->wapi_ie[0]);
986
987 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
988 priv->sec_info.wapi_enabled = true;
989 } else {
990 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
991 priv->wapi_ie_len = ie_len;
992 dev_dbg(priv->adapter->dev,
993 "info: Reset wapi_ie_len=%d IE=%#x\n",
994 priv->wapi_ie_len, priv->wapi_ie[0]);
995 priv->sec_info.wapi_enabled = false;
996 }
997 return 0;
998}
999
1000/*
1001 * IOCTL request handler to set WAPI key.
1002 *
1003 * This function prepares the correct firmware command and
1004 * issues it.
1005 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001006static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001007 struct mwifiex_ds_encrypt_key *encrypt_key)
1008{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001009
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001010 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001011 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1012 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001013}
1014
1015/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016 * IOCTL request handler to set WEP network key.
1017 *
1018 * This function prepares the correct firmware command and
1019 * issues it, after validation checks.
1020 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001021static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022 struct mwifiex_ds_encrypt_key *encrypt_key)
1023{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001024 int ret;
1025 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001026 int index;
1027
1028 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1029 priv->wep_key_curr_index = 0;
1030 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1031 index = encrypt_key->key_index;
1032 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001033 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001034 } else if (!encrypt_key->key_len) {
1035 /* Copy the required key as the current key */
1036 wep_key = &priv->wep_key[index];
1037 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001038 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039 "key not set, so cannot enable it\n");
1040 return -1;
1041 }
1042 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001043 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001044 } else {
1045 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001046 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1047 /* Copy the key in the driver */
1048 memcpy(wep_key->key_material,
1049 encrypt_key->key_material,
1050 encrypt_key->key_len);
1051 wep_key->key_index = index;
1052 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001053 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054 }
1055 if (wep_key->key_length) {
1056 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001057 ret = mwifiex_send_cmd_async(priv,
1058 HostCmd_CMD_802_11_KEY_MATERIAL,
1059 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001060 if (ret)
1061 return ret;
1062 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -08001063 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001064 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1065 else
1066 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1067
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001068 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1069 HostCmd_ACT_GEN_SET, 0,
1070 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001071
1072 return ret;
1073}
1074
1075/*
1076 * IOCTL request handler to set WPA key.
1077 *
1078 * This function prepares the correct firmware command and
1079 * issues it, after validation checks.
1080 *
1081 * Current driver only supports key length of up to 32 bytes.
1082 *
1083 * This function can also be used to disable a currently set key.
1084 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001085static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001086 struct mwifiex_ds_encrypt_key *encrypt_key)
1087{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001088 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001089 u8 remove_key = false;
1090 struct host_cmd_ds_802_11_key_material *ibss_key;
1091
1092 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -07001093 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001094 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001095 return -1;
1096 }
1097
Bing Zhaoeecd8252011-03-28 17:55:41 -07001098 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001099 /*
1100 * IBSS/WPA-None uses only one key (Group) for both receiving
1101 * and sending unicast and multicast packets.
1102 */
1103 /* Send the key as PTK to firmware */
1104 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001105 ret = mwifiex_send_cmd_async(priv,
1106 HostCmd_CMD_802_11_KEY_MATERIAL,
1107 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1108 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001109 if (ret)
1110 return ret;
1111
1112 ibss_key = &priv->aes_key;
1113 memset(ibss_key, 0,
1114 sizeof(struct host_cmd_ds_802_11_key_material));
1115 /* Copy the key in the driver */
1116 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1117 encrypt_key->key_len);
1118 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1119 sizeof(ibss_key->key_param_set.key_len));
1120 ibss_key->key_param_set.key_type_id
1121 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -07001122 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001123
1124 /* Send the key as GTK to firmware */
1125 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1126 }
1127
1128 if (!encrypt_key->key_index)
1129 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1130
1131 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001132 ret = mwifiex_send_cmd_sync(priv,
1133 HostCmd_CMD_802_11_KEY_MATERIAL,
1134 HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
1135 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001136 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001137 ret = mwifiex_send_cmd_sync(priv,
1138 HostCmd_CMD_802_11_KEY_MATERIAL,
1139 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1140 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001141
1142 return ret;
1143}
1144
1145/*
1146 * IOCTL request handler to set/get network keys.
1147 *
1148 * This is a generic key handling function which supports WEP, WPA
1149 * and WAPI.
1150 */
1151static int
1152mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001153 struct mwifiex_ds_encrypt_key *encrypt_key)
1154{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001155 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001156
1157 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001158 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001159 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001160 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001162 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001163 return status;
1164}
1165
1166/*
1167 * This function returns the driver version.
1168 */
1169int
1170mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1171 int max_len)
1172{
1173 union {
1174 u32 l;
1175 u8 c[4];
1176 } ver;
1177 char fw_ver[32];
1178
1179 ver.l = adapter->fw_release_number;
1180 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1181
1182 snprintf(version, max_len, driver_version, fw_ver);
1183
1184 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1185
1186 return 0;
1187}
1188
1189/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001190 * Sends IOCTL request to get signal information.
1191 *
1192 * This function allocates the IOCTL request buffer, fills it
1193 * with requisite parameters and calls the IOCTL handler.
1194 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001195int mwifiex_get_signal_info(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196 struct mwifiex_ds_get_signal *signal)
1197{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001198 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001200 signal->selector = ALL_RSSI_INFO_MASK;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001201
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001202 /* Signal info can be obtained only if connected */
1203 if (!priv->media_connected) {
1204 dev_dbg(priv->adapter->dev,
1205 "info: Can not get signal in disconnected state\n");
1206 return -1;
1207 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001208
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001209 status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
1210 HostCmd_ACT_GEN_GET, 0, signal);
1211
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001212 if (!status) {
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001213 if (signal->selector & BCN_RSSI_AVG_MASK)
Bing Zhao67a50032011-07-13 18:38:34 -07001214 priv->qual_level = signal->bcn_rssi_avg;
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001215 if (signal->selector & BCN_NF_AVG_MASK)
Bing Zhao67a50032011-07-13 18:38:34 -07001216 priv->qual_noise = signal->bcn_nf_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001217 }
1218
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001219 return status;
1220}
1221
1222/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001223 * Sends IOCTL request to set encoding parameters.
1224 *
1225 * This function allocates the IOCTL request buffer, fills it
1226 * with requisite parameters and calls the IOCTL handler.
1227 */
1228int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1229 int key_len, u8 key_index, int disable)
1230{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001231 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001233 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1234 encrypt_key.key_len = key_len;
1235 if (!disable) {
1236 encrypt_key.key_index = key_index;
1237 if (key_len)
1238 memcpy(encrypt_key.key_material, key, key_len);
1239 } else {
1240 encrypt_key.key_disable = true;
1241 }
1242
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001243 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001244}
1245
1246/*
1247 * Sends IOCTL request to get extended version.
1248 *
1249 * This function allocates the IOCTL request buffer, fills it
1250 * with requisite parameters and calls the IOCTL handler.
1251 */
1252int
1253mwifiex_get_ver_ext(struct mwifiex_private *priv)
1254{
1255 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001256
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001258 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1259 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1260 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001262 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001263}
1264
1265/*
1266 * Sends IOCTL request to get statistics information.
1267 *
1268 * This function allocates the IOCTL request buffer, fills it
1269 * with requisite parameters and calls the IOCTL handler.
1270 */
1271int
1272mwifiex_get_stats_info(struct mwifiex_private *priv,
1273 struct mwifiex_ds_get_stats *log)
1274{
Bing Zhao67a50032011-07-13 18:38:34 -07001275 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001276 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001277}
1278
1279/*
1280 * IOCTL request handler to read/write register.
1281 *
1282 * This function prepares the correct firmware command and
1283 * issues it.
1284 *
1285 * Access to the following registers are supported -
1286 * - MAC
1287 * - BBP
1288 * - RF
1289 * - PMIC
1290 * - CAU
1291 */
1292static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001293 struct mwifiex_ds_reg_rw *reg_rw,
1294 u16 action)
1295{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001296 u16 cmd_no;
1297
1298 switch (le32_to_cpu(reg_rw->type)) {
1299 case MWIFIEX_REG_MAC:
1300 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1301 break;
1302 case MWIFIEX_REG_BBP:
1303 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1304 break;
1305 case MWIFIEX_REG_RF:
1306 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1307 break;
1308 case MWIFIEX_REG_PMIC:
1309 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1310 break;
1311 case MWIFIEX_REG_CAU:
1312 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1313 break;
1314 default:
1315 return -1;
1316 }
1317
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001318 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001319
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001320}
1321
1322/*
1323 * Sends IOCTL request to write to a register.
1324 *
1325 * This function allocates the IOCTL request buffer, fills it
1326 * with requisite parameters and calls the IOCTL handler.
1327 */
1328int
1329mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1330 u32 reg_offset, u32 reg_value)
1331{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001332 struct mwifiex_ds_reg_rw reg_rw;
1333
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001334 reg_rw.type = cpu_to_le32(reg_type);
1335 reg_rw.offset = cpu_to_le32(reg_offset);
1336 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001337
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001338 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001339}
1340
1341/*
1342 * Sends IOCTL request to read from a register.
1343 *
1344 * This function allocates the IOCTL request buffer, fills it
1345 * with requisite parameters and calls the IOCTL handler.
1346 */
1347int
1348mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1349 u32 reg_offset, u32 *value)
1350{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001351 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001352 struct mwifiex_ds_reg_rw reg_rw;
1353
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001354 reg_rw.type = cpu_to_le32(reg_type);
1355 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001356 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001357
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001358 if (ret)
1359 goto done;
1360
1361 *value = le32_to_cpu(reg_rw.value);
1362
1363done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001364 return ret;
1365}
1366
1367/*
1368 * Sends IOCTL request to read from EEPROM.
1369 *
1370 * This function allocates the IOCTL request buffer, fills it
1371 * with requisite parameters and calls the IOCTL handler.
1372 */
1373int
1374mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1375 u8 *value)
1376{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001377 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001378 struct mwifiex_ds_read_eeprom rd_eeprom;
1379
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001380 rd_eeprom.offset = cpu_to_le16((u16) offset);
1381 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001382
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001383 /* Send request to firmware */
1384 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1385 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001386
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001387 if (!ret)
1388 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001389 return ret;
1390}
1391
1392/*
1393 * This function sets a generic IE. In addition to generic IE, it can
1394 * also handle WPA, WPA2 and WAPI IEs.
1395 */
1396static int
1397mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1398 u16 ie_len)
1399{
1400 int ret = 0;
1401 struct ieee_types_vendor_header *pvendor_ie;
1402 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1403 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1404
1405 /* If the passed length is zero, reset the buffer */
1406 if (!ie_len) {
1407 priv->gen_ie_buf_len = 0;
1408 priv->wps.session_enable = false;
1409
1410 return 0;
1411 } else if (!ie_data_ptr) {
1412 return -1;
1413 }
1414 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1415 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1416 if (((pvendor_ie->element_id == WLAN_EID_WPA)
1417 && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
1418 || (pvendor_ie->element_id == WLAN_EID_RSN)) {
1419
1420 /* IE is a WPA/WPA2 IE so call set_wpa function */
1421 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1422 priv->wps.session_enable = false;
1423
1424 return ret;
1425 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1426 /* IE is a WAPI IE so call set_wapi function */
1427 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1428
1429 return ret;
1430 }
1431 /*
1432 * Verify that the passed length is not larger than the
1433 * available space remaining in the buffer
1434 */
1435 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1436
1437 /* Test to see if it is a WPS IE, if so, enable
1438 * wps session flag
1439 */
1440 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1441 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
1442 && (!memcmp(pvendor_ie->oui, wps_oui,
1443 sizeof(wps_oui)))) {
1444 priv->wps.session_enable = true;
1445 dev_dbg(priv->adapter->dev,
1446 "info: WPS Session Enabled.\n");
1447 }
1448
1449 /* Append the passed data to the end of the
1450 genIeBuffer */
1451 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1452 ie_len);
1453 /* Increment the stored buffer length by the
1454 size passed */
1455 priv->gen_ie_buf_len += ie_len;
1456 } else {
1457 /* Passed data does not fit in the remaining
1458 buffer space */
1459 ret = -1;
1460 }
1461
1462 /* Return 0, or -1 for error case */
1463 return ret;
1464}
1465
1466/*
1467 * IOCTL request handler to set/get generic IE.
1468 *
1469 * In addition to various generic IEs, this function can also be
1470 * used to set the ARP filter.
1471 */
1472static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1473 struct mwifiex_ds_misc_gen_ie *gen_ie,
1474 u16 action)
1475{
1476 struct mwifiex_adapter *adapter = priv->adapter;
1477
1478 switch (gen_ie->type) {
1479 case MWIFIEX_IE_TYPE_GEN_IE:
1480 if (action == HostCmd_ACT_GEN_GET) {
1481 gen_ie->len = priv->wpa_ie_len;
1482 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1483 } else {
1484 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1485 (u16) gen_ie->len);
1486 }
1487 break;
1488 case MWIFIEX_IE_TYPE_ARP_FILTER:
1489 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1490 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1491 adapter->arp_filter_size = 0;
1492 dev_err(adapter->dev, "invalid ARP filter size\n");
1493 return -1;
1494 } else {
1495 memcpy(adapter->arp_filter, gen_ie->ie_data,
1496 gen_ie->len);
1497 adapter->arp_filter_size = gen_ie->len;
1498 }
1499 break;
1500 default:
1501 dev_err(adapter->dev, "invalid IE type\n");
1502 return -1;
1503 }
1504 return 0;
1505}
1506
1507/*
1508 * Sends IOCTL request to set a generic IE.
1509 *
1510 * This function allocates the IOCTL request buffer, fills it
1511 * with requisite parameters and calls the IOCTL handler.
1512 */
1513int
1514mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1515{
1516 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001517
Bing Zhao67a50032011-07-13 18:38:34 -07001518 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001519 return -EFAULT;
1520
1521 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1522 gen_ie.len = ie_len;
1523 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001524 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001525 return -EFAULT;
1526
1527 return 0;
1528}