blob: f20550a7c525cc2898b390bb25a23c1547a01e84 [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 Karwar600f5d92011-04-13 17:27:06 -070057 int status = adapter->cmd_wait_q.status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070058
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070059 dev_dbg(adapter->dev, "cmd pending\n");
60 atomic_inc(&adapter->cmd_pending);
61
62 /* Status pending, wake up main process */
63 queue_work(adapter->workqueue, &adapter->main_work);
64
65 /* Wait for completion */
66 wait_event_interruptible(adapter->cmd_wait_q.wait,
67 adapter->cmd_wait_q.condition);
68 if (!adapter->cmd_wait_q.condition)
69 cancel_flag = true;
70
Bing Zhao5e6e3a92011-03-21 18:00:50 -070071 if (cancel_flag) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070072 mwifiex_cancel_pending_ioctl(adapter);
73 dev_dbg(adapter->dev, "cmd cancel\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070074 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070075 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070076
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077 return status;
78}
79
80/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070081 * This function prepares the correct firmware command and
82 * issues it to set the multicast list.
83 *
84 * This function can be used to enable promiscuous mode, or enable all
85 * multicast packets, or to enable selective multicast.
86 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070087int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
88 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070089{
90 int ret = 0;
91 u16 old_pkt_filter;
92
93 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070094
95 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
96 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
97 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
98 priv->curr_pkt_filter &=
99 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
100 } else {
101 /* Multicast */
102 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
103 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
104 dev_dbg(priv->adapter->dev,
105 "info: Enabling All Multicast!\n");
106 priv->curr_pkt_filter |=
107 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
108 } else {
109 priv->curr_pkt_filter &=
110 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
111 if (mcast_list->num_multicast_addr) {
112 dev_dbg(priv->adapter->dev,
113 "info: Set multicast list=%d\n",
114 mcast_list->num_multicast_addr);
115 /* Set multicast addresses to firmware */
116 if (old_pkt_filter == priv->curr_pkt_filter) {
117 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700118 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700119 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700120 HostCmd_ACT_GEN_SET, 0,
121 mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700122 } else {
123 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700124 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700125 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700126 HostCmd_ACT_GEN_SET, 0,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700127 mcast_list);
128 }
129 }
130 }
131 }
132 dev_dbg(priv->adapter->dev,
133 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
134 old_pkt_filter, priv->curr_pkt_filter);
135 if (old_pkt_filter != priv->curr_pkt_filter) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700136 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
137 HostCmd_ACT_GEN_SET,
138 0, &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700139 }
140
141 return ret;
142}
143
144/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700145 * This function fills bss descriptor structure using provided
146 * information.
147 */
148int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
149 u8 *bssid, s32 rssi, u8 *ie_buf,
150 size_t ie_len, u16 beacon_period,
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -0700151 u16 cap_info_bitmap, u8 band,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700152 struct mwifiex_bssdescriptor *bss_desc)
153{
154 int ret;
155
156 memcpy(bss_desc->mac_address, bssid, ETH_ALEN);
157 bss_desc->rssi = rssi;
158 bss_desc->beacon_buf = ie_buf;
159 bss_desc->beacon_buf_size = ie_len;
160 bss_desc->beacon_period = beacon_period;
161 bss_desc->cap_info_bitmap = cap_info_bitmap;
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -0700162 bss_desc->bss_band = band;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700163 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
164 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
165 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
166 } else {
167 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
168 }
169 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
170 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
171 else
172 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
173
174 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
175 ie_buf, ie_len);
176
177 return ret;
178}
179
180/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700181 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
182 * In both Ad-Hoc and infra mode, an deauthentication is performed
183 * first.
184 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700185int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
186 struct mwifiex_802_11_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700187{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700188 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700189 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700190 struct mwifiex_bssdescriptor *bss_desc = NULL;
191 u8 *beacon_ie = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700192
193 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700194
195 if (bss) {
196 /* Allocate and fill new bss descriptor */
197 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
198 GFP_KERNEL);
199 if (!bss_desc) {
200 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
201 return -ENOMEM;
202 }
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700203
204 beacon_ie = kmemdup(bss->information_elements,
205 bss->len_beacon_ies, GFP_KERNEL);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700206 if (!beacon_ie) {
Dan Carpenteraef0ba52011-09-21 10:13:29 +0300207 kfree(bss_desc);
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700208 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700209 return -ENOMEM;
210 }
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700211
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700212 ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
213 beacon_ie, bss->len_beacon_ies,
214 bss->beacon_interval,
Amitkumar Karwar5116f3c2011-09-21 21:43:23 -0700215 bss->capability,
216 *(u8 *)bss->priv, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700217 if (ret)
218 goto done;
219 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700220
Bing Zhaoeecd8252011-03-28 17:55:41 -0700221 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700222 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700223 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700224 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700225 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700226
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700227 ret = mwifiex_check_network_compatibility(priv, bss_desc);
228 if (ret)
229 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700230
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700231 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
232 "associating...\n");
233
234 if (!netif_queue_stopped(priv->netdev))
235 netif_stop_queue(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700236
237 /* Clear any past association response stored for
238 * application retrieval */
239 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700240 ret = mwifiex_associate(priv, bss_desc);
241 if (bss)
242 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700243 } else {
244 /* Adhoc mode */
245 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700246 if (bss_desc && bss_desc->ssid.ssid_len &&
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700247 (!mwifiex_ssid_cmp
248 (&priv->curr_bss_params.bss_descriptor.ssid,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700249 &bss_desc->ssid))) {
250 kfree(bss_desc);
251 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700252 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700253 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700254
255 /* Exit Adhoc mode first */
256 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700257 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700258 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700259 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700260
261 priv->adhoc_is_link_sensed = false;
262
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700263 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700264
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700265 if (!netif_queue_stopped(priv->netdev))
266 netif_stop_queue(priv->netdev);
267
268 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 dev_dbg(adapter->dev, "info: network found in scan"
270 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700271 ret = mwifiex_adhoc_join(priv, bss_desc);
272 if (bss)
273 cfg80211_put_bss(bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700274 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700275 dev_dbg(adapter->dev, "info: Network not found in "
276 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700277 req_ssid->ssid);
278 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700279 }
280 }
281
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700282done:
283 kfree(bss_desc);
284 kfree(beacon_ie);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700285 return ret;
286}
287
288/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700289 * IOCTL request handler to set host sleep configuration.
290 *
291 * This function prepares the correct firmware command and
292 * issues it.
293 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700294int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
295 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
296
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700297{
298 struct mwifiex_adapter *adapter = priv->adapter;
299 int status = 0;
300 u32 prev_cond = 0;
301
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700302 if (!hs_cfg)
303 return -ENOMEM;
304
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700305 switch (action) {
306 case HostCmd_ACT_GEN_SET:
307 if (adapter->pps_uapsd_mode) {
308 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
309 " is blocked in UAPSD/PPS mode\n");
310 status = -1;
311 break;
312 }
313 if (hs_cfg->is_invoke_hostcmd) {
314 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
315 if (!adapter->is_hs_configured)
316 /* Already cancelled */
317 break;
318 /* Save previous condition */
319 prev_cond = le32_to_cpu(adapter->hs_cfg
320 .conditions);
321 adapter->hs_cfg.conditions =
322 cpu_to_le32(hs_cfg->conditions);
323 } else if (hs_cfg->conditions) {
324 adapter->hs_cfg.conditions =
325 cpu_to_le32(hs_cfg->conditions);
326 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
327 if (hs_cfg->gap)
328 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
329 } else if (adapter->hs_cfg.conditions ==
330 cpu_to_le32(
331 HOST_SLEEP_CFG_CANCEL)) {
332 /* Return failure if no parameters for HS
333 enable */
334 status = -1;
335 break;
336 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700337 if (cmd_type == MWIFIEX_SYNC_CMD)
338 status = mwifiex_send_cmd_sync(priv,
339 HostCmd_CMD_802_11_HS_CFG_ENH,
340 HostCmd_ACT_GEN_SET, 0,
341 &adapter->hs_cfg);
342 else
343 status = mwifiex_send_cmd_async(priv,
344 HostCmd_CMD_802_11_HS_CFG_ENH,
345 HostCmd_ACT_GEN_SET, 0,
346 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
348 /* Restore previous condition */
349 adapter->hs_cfg.conditions =
350 cpu_to_le32(prev_cond);
351 } else {
352 adapter->hs_cfg.conditions =
353 cpu_to_le32(hs_cfg->conditions);
354 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
355 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
356 }
357 break;
358 case HostCmd_ACT_GEN_GET:
359 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
360 hs_cfg->gpio = adapter->hs_cfg.gpio;
361 hs_cfg->gap = adapter->hs_cfg.gap;
362 break;
363 default:
364 status = -1;
365 break;
366 }
367
368 return status;
369}
370
371/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700372 * Sends IOCTL request to cancel the existing Host Sleep configuration.
373 *
374 * This function allocates the IOCTL request buffer, fills it
375 * with requisite parameters and calls the IOCTL handler.
376 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700377int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700378{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700379 struct mwifiex_ds_hs_cfg hscfg;
380
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700381 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
382 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700383
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700384 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
385 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700386}
387EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
388
389/*
390 * Sends IOCTL request to cancel the existing Host Sleep configuration.
391 *
392 * This function allocates the IOCTL request buffer, fills it
393 * with requisite parameters and calls the IOCTL handler.
394 */
395int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
396{
397 struct mwifiex_ds_hs_cfg hscfg;
398
399 if (adapter->hs_activated) {
400 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
401 return true;
402 }
403
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700404 adapter->hs_activate_wait_q_woken = false;
405
406 memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param));
407 hscfg.is_invoke_hostcmd = true;
408
409 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
410 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700411 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
412 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700413 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
414 return false;
415 }
416
417 wait_event_interruptible(adapter->hs_activate_wait_q,
418 adapter->hs_activate_wait_q_woken);
419
420 return true;
421}
422EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
423
424/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700425 * IOCTL request handler to get BSS information.
426 *
427 * This function collates the information from different driver structures
428 * to send to the user.
429 */
430int mwifiex_get_bss_info(struct mwifiex_private *priv,
431 struct mwifiex_bss_info *info)
432{
433 struct mwifiex_adapter *adapter = priv->adapter;
434 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700435
436 if (!info)
437 return -1;
438
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700439 bss_desc = &priv->curr_bss_params.bss_descriptor;
440
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700441 info->bss_mode = priv->bss_mode;
442
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700443 memcpy(&info->ssid, &bss_desc->ssid,
444 sizeof(struct mwifiex_802_11_ssid));
445
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700446 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
447
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448 info->bss_chan = bss_desc->channel;
449
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700450 info->region_code = adapter->region_code;
451
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700452 info->media_connected = priv->media_connected;
453
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700454 info->max_power_level = priv->max_tx_power_level;
455 info->min_power_level = priv->min_tx_power_level;
456
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700457 info->adhoc_state = priv->adhoc_state;
458
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700459 info->bcn_nf_last = priv->bcn_nf_last;
460
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700461 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
462 info->wep_status = true;
463 else
464 info->wep_status = false;
465
466 info->is_hs_configured = adapter->is_hs_configured;
467 info->is_deep_sleep = adapter->is_deep_sleep;
468
469 return 0;
470}
471
472/*
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700473 * The function sets band configurations.
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700475 * it performs extra checks to make sure the Ad-Hoc
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476 * band and channel are compatible. Otherwise it returns an error.
477 *
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700478 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700479int mwifiex_set_radio_band_cfg(struct mwifiex_private *priv,
480 struct mwifiex_ds_band_cfg *radio_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700481{
482 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700483 u8 infra_band, adhoc_band;
484 u32 adhoc_channel;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700485
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700486 infra_band = (u8) radio_cfg->config_bands;
487 adhoc_band = (u8) radio_cfg->adhoc_start_band;
488 adhoc_channel = radio_cfg->adhoc_channel;
489
490 /* SET Infra band */
491 if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands)
492 return -1;
493
494 adapter->config_bands = infra_band;
495
496 /* SET Ad-hoc Band */
497 if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands)
498 return -1;
499
500 if (adhoc_band)
501 adapter->adhoc_start_band = adhoc_band;
502 adapter->chan_offset = (u8) radio_cfg->sec_chan_offset;
503 /*
504 * If no adhoc_channel is supplied verify if the existing adhoc
505 * channel compiles with new adhoc_band
506 */
507 if (!adhoc_channel) {
508 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
509 (priv, adapter->adhoc_start_band,
510 priv->adhoc_channel)) {
511 /* Pass back the default channel */
512 radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL;
513 if ((adapter->adhoc_start_band & BAND_A)
514 || (adapter->adhoc_start_band & BAND_AN))
515 radio_cfg->adhoc_channel =
516 DEFAULT_AD_HOC_CHANNEL_A;
517 }
518 } else { /* Retrurn error if adhoc_band and
519 adhoc_channel combination is invalid */
520 if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211
521 (priv, adapter->adhoc_start_band, (u16) adhoc_channel))
522 return -1;
523 priv->adhoc_channel = (u8) adhoc_channel;
524 }
525 if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN))
526 adapter->adhoc_11n_enabled = true;
527 else
528 adapter->adhoc_11n_enabled = false;
529
530 return 0;
531}
532
533/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700534 * The function disables auto deep sleep mode.
535 */
536int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
537{
538 struct mwifiex_ds_auto_ds auto_ds;
539
540 auto_ds.auto_ds = DEEP_SLEEP_OFF;
541
542 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
543 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
544}
545EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
546
547/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 * IOCTL request handler to set/get active channel.
549 *
550 * This function performs validity checking on channel/frequency
551 * compatibility and returns failure if not valid.
552 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700553int mwifiex_bss_set_channel(struct mwifiex_private *priv,
554 struct mwifiex_chan_freq_power *chan)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555{
556 struct mwifiex_adapter *adapter = priv->adapter;
557 struct mwifiex_chan_freq_power *cfp = NULL;
558
559 if (!chan)
560 return -1;
561
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562 if (!chan->channel && !chan->freq)
563 return -1;
564 if (adapter->adhoc_start_band & BAND_AN)
565 adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN;
566 else if (adapter->adhoc_start_band & BAND_A)
567 adapter->adhoc_start_band = BAND_G | BAND_B;
568 if (chan->channel) {
569 if (chan->channel <= MAX_CHANNEL_BAND_BG)
570 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
571 (priv, 0, (u16) chan->channel);
572 if (!cfp) {
573 cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211
574 (priv, BAND_A, (u16) chan->channel);
575 if (cfp) {
576 if (adapter->adhoc_11n_enabled)
577 adapter->adhoc_start_band = BAND_A
578 | BAND_AN;
579 else
580 adapter->adhoc_start_band = BAND_A;
581 }
582 }
583 } else {
584 if (chan->freq <= MAX_FREQUENCY_BAND_BG)
585 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
586 priv, 0, chan->freq);
587 if (!cfp) {
588 cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211
589 (priv, BAND_A, chan->freq);
590 if (cfp) {
591 if (adapter->adhoc_11n_enabled)
592 adapter->adhoc_start_band = BAND_A
593 | BAND_AN;
594 else
595 adapter->adhoc_start_band = BAND_A;
596 }
597 }
598 }
599 if (!cfp || !cfp->channel) {
600 dev_err(adapter->dev, "invalid channel/freq\n");
601 return -1;
602 }
603 priv->adhoc_channel = (u8) cfp->channel;
604 chan->channel = cfp->channel;
605 chan->freq = cfp->freq;
606
607 return 0;
608}
609
610/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700611 * IOCTL request handler to set/get Ad-Hoc channel.
612 *
613 * This function prepares the correct firmware command and
614 * issues it to set or get the ad-hoc channel.
615 */
616static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700617 u16 action, u16 *channel)
618{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700619 if (action == HostCmd_ACT_GEN_GET) {
620 if (!priv->media_connected) {
621 *channel = priv->adhoc_channel;
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700622 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700623 }
624 } else {
625 priv->adhoc_channel = (u8) *channel;
626 }
627
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700628 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700629 action, 0, channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700630}
631
632/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633 * IOCTL request handler to change Ad-Hoc channel.
634 *
635 * This function allocates the IOCTL request buffer, fills it
636 * with requisite parameters and calls the IOCTL handler.
637 *
638 * The function follows the following steps to perform the change -
639 * - Get current IBSS information
640 * - Get current channel
641 * - If no change is required, return
642 * - If not connected, change channel and return
643 * - If connected,
644 * - Disconnect
645 * - Change channel
646 * - Perform specific SSID scan with same SSID
647 * - Start/Join the IBSS
648 */
649int
650mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel)
651{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700652 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700653 struct mwifiex_bss_info bss_info;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700654 struct mwifiex_ssid_bssid ssid_bssid;
655 u16 curr_chan = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700656 struct cfg80211_bss *bss = NULL;
657 struct ieee80211_channel *chan;
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700658 enum ieee80211_band band;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700659
660 memset(&bss_info, 0, sizeof(bss_info));
661
662 /* Get BSS information */
663 if (mwifiex_get_bss_info(priv, &bss_info))
664 return -1;
665
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700666 /* Get current channel */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700667 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET,
668 &curr_chan);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700669
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700670 if (curr_chan == channel) {
671 ret = 0;
672 goto done;
673 }
674 dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n",
675 curr_chan, channel);
676
677 if (!bss_info.media_connected) {
678 ret = 0;
679 goto done;
680 }
681
682 /* Do disonnect */
683 memset(&ssid_bssid, 0, ETH_ALEN);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700684 ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700685
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700686 ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET,
687 (u16 *) &channel);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700688
689 /* Do specific SSID scanning */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700690 if (mwifiex_request_scan(priv, &bss_info.ssid)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700691 ret = -1;
692 goto done;
693 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700694
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700695 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700696 chan = __ieee80211_get_channel(priv->wdev->wiphy,
Amitkumar Karwar4ed5d522011-09-21 21:43:24 -0700697 ieee80211_channel_to_frequency(channel, band));
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700698
699 /* Find the BSS we want using available scan results */
700 bss = cfg80211_get_bss(priv->wdev->wiphy, chan, bss_info.bssid,
701 bss_info.ssid.ssid, bss_info.ssid.ssid_len,
702 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
703 if (!bss)
704 wiphy_warn(priv->wdev->wiphy, "assoc: bss %pM not in scan results\n",
705 bss_info.bssid);
706
707 ret = mwifiex_bss_start(priv, bss, &bss_info.ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700708done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700709 return ret;
710}
711
712/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700713 * IOCTL request handler to get rate.
714 *
715 * This function prepares the correct firmware command and
716 * issues it to get the current rate if it is connected,
717 * otherwise, the function returns the lowest supported rate
718 * for the band.
719 */
720static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700721 struct mwifiex_rate_cfg *rate_cfg)
722{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700723 rate_cfg->is_rate_auto = priv->is_data_rate_auto;
Amitkumar Karwarcbaaf592011-09-26 20:37:24 -0700724 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
725 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726}
727
728/*
729 * IOCTL request handler to set rate.
730 *
731 * This function prepares the correct firmware command and
732 * issues it to set the current rate.
733 *
734 * The function also performs validation checking on the supplied value.
735 */
736static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700737 struct mwifiex_rate_cfg *rate_cfg)
738{
739 u8 rates[MWIFIEX_SUPPORTED_RATES];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700740 u8 *rate;
741 int rate_index, ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700742 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700743 u32 i;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700744 struct mwifiex_adapter *adapter = priv->adapter;
745
746 if (rate_cfg->is_rate_auto) {
747 memset(bitmap_rates, 0, sizeof(bitmap_rates));
748 /* Support all HR/DSSS rates */
749 bitmap_rates[0] = 0x000F;
750 /* Support all OFDM rates */
751 bitmap_rates[1] = 0x00FF;
752 /* Support all HT-MCSs rate */
753 for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++)
754 bitmap_rates[i + 2] = 0xFFFF;
755 bitmap_rates[9] = 0x3FFF;
756 } else {
757 memset(rates, 0, sizeof(rates));
758 mwifiex_get_active_data_rates(priv, rates);
759 rate = rates;
760 for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) {
761 dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n",
762 rate[i], rate_cfg->rate);
763 if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f))
764 break;
765 }
Yogesh Ashok Powar3d82de02011-10-05 14:58:24 -0700766 if ((i == MWIFIEX_SUPPORTED_RATES) || !rate[i]) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700767 dev_err(adapter->dev, "fixed data rate %#x is out "
768 "of range\n", rate_cfg->rate);
769 return -1;
770 }
771 memset(bitmap_rates, 0, sizeof(bitmap_rates));
772
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700773 rate_index = mwifiex_data_rate_to_index(rate_cfg->rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700774
775 /* Only allow b/g rates to be set */
776 if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 &&
777 rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) {
778 bitmap_rates[0] = 1 << rate_index;
779 } else {
780 rate_index -= 1; /* There is a 0x00 in the table */
781 if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 &&
782 rate_index <= MWIFIEX_RATE_INDEX_OFDM7)
783 bitmap_rates[1] = 1 << (rate_index -
784 MWIFIEX_RATE_INDEX_OFDM0);
785 }
786 }
787
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700788 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG,
789 HostCmd_ACT_GEN_SET, 0, bitmap_rates);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700790
791 return ret;
792}
793
794/*
795 * IOCTL request handler to set/get rate.
796 *
797 * This function can be used to set/get either the rate value or the
798 * rate index.
799 */
800static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700801 struct mwifiex_rate_cfg *rate_cfg)
802{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700803 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700804
805 if (!rate_cfg)
806 return -1;
807
808 if (rate_cfg->action == HostCmd_ACT_GEN_GET)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700809 status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700810 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700811 status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700812
813 return status;
814}
815
816/*
817 * Sends IOCTL request to get the data rate.
818 *
819 * This function allocates the IOCTL request buffer, fills it
820 * with requisite parameters and calls the IOCTL handler.
821 */
822int mwifiex_drv_get_data_rate(struct mwifiex_private *priv,
823 struct mwifiex_rate_cfg *rate)
824{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700825 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700826
827 memset(rate, 0, sizeof(struct mwifiex_rate_cfg));
828 rate->action = HostCmd_ACT_GEN_GET;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700829 ret = mwifiex_rate_ioctl_cfg(priv, rate);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700830
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700831 if (!ret) {
Dan Carpenter49753122011-09-21 10:13:56 +0300832 if (rate->is_rate_auto)
Amitkumar Karwar572e8f32011-04-13 17:27:08 -0700833 rate->rate = mwifiex_index_to_data_rate(priv->tx_rate,
834 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300835 else
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700836 rate->rate = priv->data_rate;
837 } else {
838 ret = -1;
839 }
840
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700841 return ret;
842}
843
844/*
845 * IOCTL request handler to set tx power configuration.
846 *
847 * This function prepares the correct firmware command and
848 * issues it.
849 *
850 * For non-auto power mode, all the following power groups are set -
851 * - Modulation class HR/DSSS
852 * - Modulation class OFDM
853 * - Modulation class HTBW20
854 * - Modulation class HTBW40
855 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700856int mwifiex_set_tx_power(struct mwifiex_private *priv,
857 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700858{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700859 int ret;
860 struct host_cmd_ds_txpwr_cfg *txp_cfg;
861 struct mwifiex_types_power_group *pg_tlv;
862 struct mwifiex_power_group *pg;
863 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700864 u16 dbm = 0;
865
866 if (!power_cfg->is_power_auto) {
867 dbm = (u16) power_cfg->power_level;
868 if ((dbm < priv->min_tx_power_level) ||
869 (dbm > priv->max_tx_power_level)) {
870 dev_err(priv->adapter->dev, "txpower value %d dBm"
871 " is out of range (%d dBm-%d dBm)\n",
872 dbm, priv->min_tx_power_level,
873 priv->max_tx_power_level);
874 return -1;
875 }
876 }
877 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
878 if (!buf) {
879 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
880 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200881 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700882 }
883
884 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
885 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
886 if (!power_cfg->is_power_auto) {
887 txp_cfg->mode = cpu_to_le32(1);
888 pg_tlv = (struct mwifiex_types_power_group *) (buf +
889 sizeof(struct host_cmd_ds_txpwr_cfg));
890 pg_tlv->type = TLV_TYPE_POWER_GROUP;
891 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
892 pg = (struct mwifiex_power_group *) (buf +
893 sizeof(struct host_cmd_ds_txpwr_cfg) +
894 sizeof(struct mwifiex_types_power_group));
895 /* Power group for modulation class HR/DSSS */
896 pg->first_rate_code = 0x00;
897 pg->last_rate_code = 0x03;
898 pg->modulation_class = MOD_CLASS_HR_DSSS;
899 pg->power_step = 0;
900 pg->power_min = (s8) dbm;
901 pg->power_max = (s8) dbm;
902 pg++;
903 /* Power group for modulation class OFDM */
904 pg->first_rate_code = 0x00;
905 pg->last_rate_code = 0x07;
906 pg->modulation_class = MOD_CLASS_OFDM;
907 pg->power_step = 0;
908 pg->power_min = (s8) dbm;
909 pg->power_max = (s8) dbm;
910 pg++;
911 /* Power group for modulation class HTBW20 */
912 pg->first_rate_code = 0x00;
913 pg->last_rate_code = 0x20;
914 pg->modulation_class = MOD_CLASS_HT;
915 pg->power_step = 0;
916 pg->power_min = (s8) dbm;
917 pg->power_max = (s8) dbm;
918 pg->ht_bandwidth = HT_BW_20;
919 pg++;
920 /* Power group for modulation class HTBW40 */
921 pg->first_rate_code = 0x00;
922 pg->last_rate_code = 0x20;
923 pg->modulation_class = MOD_CLASS_HT;
924 pg->power_step = 0;
925 pg->power_min = (s8) dbm;
926 pg->power_max = (s8) dbm;
927 pg->ht_bandwidth = HT_BW_40;
928 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700929 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
930 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700931
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700932 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700933 return ret;
934}
935
936/*
937 * IOCTL request handler to get power save mode.
938 *
939 * This function prepares the correct firmware command and
940 * issues it.
941 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700942int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700943{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700944 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700945 struct mwifiex_adapter *adapter = priv->adapter;
946 u16 sub_cmd;
947
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700948 if (*ps_mode)
949 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
950 else
951 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
952 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
953 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
954 sub_cmd, BITMAP_STA_PS, NULL);
955 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
956 ret = mwifiex_send_cmd_async(priv,
957 HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS,
958 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700959
960 return ret;
961}
962
963/*
964 * IOCTL request handler to set/reset WPA IE.
965 *
966 * The supplied WPA IE is treated as a opaque buffer. Only the first field
967 * is checked to determine WPA version. If buffer length is zero, the existing
968 * WPA IE is reset.
969 */
970static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
971 u8 *ie_data_ptr, u16 ie_len)
972{
973 if (ie_len) {
974 if (ie_len > sizeof(priv->wpa_ie)) {
975 dev_err(priv->adapter->dev,
976 "failed to copy WPA IE, too big\n");
977 return -1;
978 }
979 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
980 priv->wpa_ie_len = (u8) ie_len;
981 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
982 priv->wpa_ie_len, priv->wpa_ie[0]);
983
984 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
985 priv->sec_info.wpa_enabled = true;
986 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
987 priv->sec_info.wpa2_enabled = true;
988 } else {
989 priv->sec_info.wpa_enabled = false;
990 priv->sec_info.wpa2_enabled = false;
991 }
992 } else {
993 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
994 priv->wpa_ie_len = 0;
995 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
996 priv->wpa_ie_len, priv->wpa_ie[0]);
997 priv->sec_info.wpa_enabled = false;
998 priv->sec_info.wpa2_enabled = false;
999 }
1000
1001 return 0;
1002}
1003
1004/*
1005 * IOCTL request handler to set/reset WAPI IE.
1006 *
1007 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
1008 * is checked to internally enable WAPI. If buffer length is zero, the existing
1009 * WAPI IE is reset.
1010 */
1011static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
1012 u8 *ie_data_ptr, u16 ie_len)
1013{
1014 if (ie_len) {
1015 if (ie_len > sizeof(priv->wapi_ie)) {
1016 dev_dbg(priv->adapter->dev,
1017 "info: failed to copy WAPI IE, too big\n");
1018 return -1;
1019 }
1020 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
1021 priv->wapi_ie_len = ie_len;
1022 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
1023 priv->wapi_ie_len, priv->wapi_ie[0]);
1024
1025 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
1026 priv->sec_info.wapi_enabled = true;
1027 } else {
1028 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
1029 priv->wapi_ie_len = ie_len;
1030 dev_dbg(priv->adapter->dev,
1031 "info: Reset wapi_ie_len=%d IE=%#x\n",
1032 priv->wapi_ie_len, priv->wapi_ie[0]);
1033 priv->sec_info.wapi_enabled = false;
1034 }
1035 return 0;
1036}
1037
1038/*
1039 * IOCTL request handler to set WAPI key.
1040 *
1041 * This function prepares the correct firmware command and
1042 * issues it.
1043 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001044static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001045 struct mwifiex_ds_encrypt_key *encrypt_key)
1046{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001047
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001048 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001049 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1050 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001051}
1052
1053/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054 * IOCTL request handler to set WEP network key.
1055 *
1056 * This function prepares the correct firmware command and
1057 * issues it, after validation checks.
1058 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001059static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001060 struct mwifiex_ds_encrypt_key *encrypt_key)
1061{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001062 int ret;
1063 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001064 int index;
1065
1066 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
1067 priv->wep_key_curr_index = 0;
1068 wep_key = &priv->wep_key[priv->wep_key_curr_index];
1069 index = encrypt_key->key_index;
1070 if (encrypt_key->key_disable) {
1071 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED;
1072 } else if (!encrypt_key->key_len) {
1073 /* Copy the required key as the current key */
1074 wep_key = &priv->wep_key[index];
1075 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001076 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001077 "key not set, so cannot enable it\n");
1078 return -1;
1079 }
1080 priv->wep_key_curr_index = (u16) index;
1081 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1082 } else {
1083 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001084 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
1085 /* Copy the key in the driver */
1086 memcpy(wep_key->key_material,
1087 encrypt_key->key_material,
1088 encrypt_key->key_len);
1089 wep_key->key_index = index;
1090 wep_key->key_length = encrypt_key->key_len;
1091 priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED;
1092 }
1093 if (wep_key->key_length) {
1094 /* Send request to firmware */
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, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001098 if (ret)
1099 return ret;
1100 }
1101 if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED)
1102 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
1103 else
1104 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
1105
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001106 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
1107 HostCmd_ACT_GEN_SET, 0,
1108 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001109
1110 return ret;
1111}
1112
1113/*
1114 * IOCTL request handler to set WPA key.
1115 *
1116 * This function prepares the correct firmware command and
1117 * issues it, after validation checks.
1118 *
1119 * Current driver only supports key length of up to 32 bytes.
1120 *
1121 * This function can also be used to disable a currently set key.
1122 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001123static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001124 struct mwifiex_ds_encrypt_key *encrypt_key)
1125{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001126 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001127 u8 remove_key = false;
1128 struct host_cmd_ds_802_11_key_material *ibss_key;
1129
1130 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -07001131 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001132 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001133 return -1;
1134 }
1135
Bing Zhaoeecd8252011-03-28 17:55:41 -07001136 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001137 /*
1138 * IBSS/WPA-None uses only one key (Group) for both receiving
1139 * and sending unicast and multicast packets.
1140 */
1141 /* Send the key as PTK to firmware */
1142 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001143 ret = mwifiex_send_cmd_async(priv,
1144 HostCmd_CMD_802_11_KEY_MATERIAL,
1145 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1146 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001147 if (ret)
1148 return ret;
1149
1150 ibss_key = &priv->aes_key;
1151 memset(ibss_key, 0,
1152 sizeof(struct host_cmd_ds_802_11_key_material));
1153 /* Copy the key in the driver */
1154 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
1155 encrypt_key->key_len);
1156 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
1157 sizeof(ibss_key->key_param_set.key_len));
1158 ibss_key->key_param_set.key_type_id
1159 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -07001160 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001161
1162 /* Send the key as GTK to firmware */
1163 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1164 }
1165
1166 if (!encrypt_key->key_index)
1167 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1168
1169 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001170 ret = mwifiex_send_cmd_sync(priv,
1171 HostCmd_CMD_802_11_KEY_MATERIAL,
1172 HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED),
1173 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001174 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001175 ret = mwifiex_send_cmd_sync(priv,
1176 HostCmd_CMD_802_11_KEY_MATERIAL,
1177 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
1178 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001179
1180 return ret;
1181}
1182
1183/*
1184 * IOCTL request handler to set/get network keys.
1185 *
1186 * This is a generic key handling function which supports WEP, WPA
1187 * and WAPI.
1188 */
1189static int
1190mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001191 struct mwifiex_ds_encrypt_key *encrypt_key)
1192{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001193 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001194
1195 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001196 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001198 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001200 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001201 return status;
1202}
1203
1204/*
1205 * This function returns the driver version.
1206 */
1207int
1208mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1209 int max_len)
1210{
1211 union {
1212 u32 l;
1213 u8 c[4];
1214 } ver;
1215 char fw_ver[32];
1216
1217 ver.l = adapter->fw_release_number;
1218 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1219
1220 snprintf(version, max_len, driver_version, fw_ver);
1221
1222 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1223
1224 return 0;
1225}
1226
1227/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001228 * Sends IOCTL request to get signal information.
1229 *
1230 * This function allocates the IOCTL request buffer, fills it
1231 * with requisite parameters and calls the IOCTL handler.
1232 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001233int mwifiex_get_signal_info(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001234 struct mwifiex_ds_get_signal *signal)
1235{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001236 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001237
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001238 signal->selector = ALL_RSSI_INFO_MASK;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001240 /* Signal info can be obtained only if connected */
1241 if (!priv->media_connected) {
1242 dev_dbg(priv->adapter->dev,
1243 "info: Can not get signal in disconnected state\n");
1244 return -1;
1245 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001246
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001247 status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO,
1248 HostCmd_ACT_GEN_GET, 0, signal);
1249
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001250 if (!status) {
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001251 if (signal->selector & BCN_RSSI_AVG_MASK)
Bing Zhao67a50032011-07-13 18:38:34 -07001252 priv->qual_level = signal->bcn_rssi_avg;
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001253 if (signal->selector & BCN_NF_AVG_MASK)
Bing Zhao67a50032011-07-13 18:38:34 -07001254 priv->qual_noise = signal->bcn_nf_avg;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255 }
1256
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 return status;
1258}
1259
1260/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261 * Sends IOCTL request to set encoding parameters.
1262 *
1263 * This function allocates the IOCTL request buffer, fills it
1264 * with requisite parameters and calls the IOCTL handler.
1265 */
1266int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key,
1267 int key_len, u8 key_index, int disable)
1268{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001269 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001270
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001271 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1272 encrypt_key.key_len = key_len;
1273 if (!disable) {
1274 encrypt_key.key_index = key_index;
1275 if (key_len)
1276 memcpy(encrypt_key.key_material, key, key_len);
1277 } else {
1278 encrypt_key.key_disable = true;
1279 }
1280
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001281 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001282}
1283
1284/*
1285 * Sends IOCTL request to get extended version.
1286 *
1287 * This function allocates the IOCTL request buffer, fills it
1288 * with requisite parameters and calls the IOCTL handler.
1289 */
1290int
1291mwifiex_get_ver_ext(struct mwifiex_private *priv)
1292{
1293 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001294
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001295 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001296 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
1297 HostCmd_ACT_GEN_GET, 0, &ver_ext))
1298 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001299
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001300 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001301}
1302
1303/*
1304 * Sends IOCTL request to get statistics information.
1305 *
1306 * This function allocates the IOCTL request buffer, fills it
1307 * with requisite parameters and calls the IOCTL handler.
1308 */
1309int
1310mwifiex_get_stats_info(struct mwifiex_private *priv,
1311 struct mwifiex_ds_get_stats *log)
1312{
Bing Zhao67a50032011-07-13 18:38:34 -07001313 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Amitkumar Karwarc4859fb2011-05-10 20:47:35 -07001314 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001315}
1316
1317/*
1318 * IOCTL request handler to read/write register.
1319 *
1320 * This function prepares the correct firmware command and
1321 * issues it.
1322 *
1323 * Access to the following registers are supported -
1324 * - MAC
1325 * - BBP
1326 * - RF
1327 * - PMIC
1328 * - CAU
1329 */
1330static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001331 struct mwifiex_ds_reg_rw *reg_rw,
1332 u16 action)
1333{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001334 u16 cmd_no;
1335
1336 switch (le32_to_cpu(reg_rw->type)) {
1337 case MWIFIEX_REG_MAC:
1338 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1339 break;
1340 case MWIFIEX_REG_BBP:
1341 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1342 break;
1343 case MWIFIEX_REG_RF:
1344 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1345 break;
1346 case MWIFIEX_REG_PMIC:
1347 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1348 break;
1349 case MWIFIEX_REG_CAU:
1350 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1351 break;
1352 default:
1353 return -1;
1354 }
1355
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001356 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001357
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001358}
1359
1360/*
1361 * Sends IOCTL request to write to a register.
1362 *
1363 * This function allocates the IOCTL request buffer, fills it
1364 * with requisite parameters and calls the IOCTL handler.
1365 */
1366int
1367mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1368 u32 reg_offset, u32 reg_value)
1369{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001370 struct mwifiex_ds_reg_rw reg_rw;
1371
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001372 reg_rw.type = cpu_to_le32(reg_type);
1373 reg_rw.offset = cpu_to_le32(reg_offset);
1374 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001375
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001376 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001377}
1378
1379/*
1380 * Sends IOCTL request to read from a register.
1381 *
1382 * This function allocates the IOCTL request buffer, fills it
1383 * with requisite parameters and calls the IOCTL handler.
1384 */
1385int
1386mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1387 u32 reg_offset, u32 *value)
1388{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001389 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001390 struct mwifiex_ds_reg_rw reg_rw;
1391
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001392 reg_rw.type = cpu_to_le32(reg_type);
1393 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001394 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001395
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001396 if (ret)
1397 goto done;
1398
1399 *value = le32_to_cpu(reg_rw.value);
1400
1401done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001402 return ret;
1403}
1404
1405/*
1406 * Sends IOCTL request to read from EEPROM.
1407 *
1408 * This function allocates the IOCTL request buffer, fills it
1409 * with requisite parameters and calls the IOCTL handler.
1410 */
1411int
1412mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1413 u8 *value)
1414{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001415 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001416 struct mwifiex_ds_read_eeprom rd_eeprom;
1417
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001418 rd_eeprom.offset = cpu_to_le16((u16) offset);
1419 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001421 /* Send request to firmware */
1422 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1423 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001424
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001425 if (!ret)
1426 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001427 return ret;
1428}
1429
1430/*
1431 * This function sets a generic IE. In addition to generic IE, it can
1432 * also handle WPA, WPA2 and WAPI IEs.
1433 */
1434static int
1435mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1436 u16 ie_len)
1437{
1438 int ret = 0;
1439 struct ieee_types_vendor_header *pvendor_ie;
1440 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1441 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1442
1443 /* If the passed length is zero, reset the buffer */
1444 if (!ie_len) {
1445 priv->gen_ie_buf_len = 0;
1446 priv->wps.session_enable = false;
1447
1448 return 0;
1449 } else if (!ie_data_ptr) {
1450 return -1;
1451 }
1452 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1453 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
1454 if (((pvendor_ie->element_id == WLAN_EID_WPA)
1455 && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui))))
1456 || (pvendor_ie->element_id == WLAN_EID_RSN)) {
1457
1458 /* IE is a WPA/WPA2 IE so call set_wpa function */
1459 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1460 priv->wps.session_enable = false;
1461
1462 return ret;
1463 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1464 /* IE is a WAPI IE so call set_wapi function */
1465 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1466
1467 return ret;
1468 }
1469 /*
1470 * Verify that the passed length is not larger than the
1471 * available space remaining in the buffer
1472 */
1473 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1474
1475 /* Test to see if it is a WPS IE, if so, enable
1476 * wps session flag
1477 */
1478 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1479 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC)
1480 && (!memcmp(pvendor_ie->oui, wps_oui,
1481 sizeof(wps_oui)))) {
1482 priv->wps.session_enable = true;
1483 dev_dbg(priv->adapter->dev,
1484 "info: WPS Session Enabled.\n");
1485 }
1486
1487 /* Append the passed data to the end of the
1488 genIeBuffer */
1489 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
1490 ie_len);
1491 /* Increment the stored buffer length by the
1492 size passed */
1493 priv->gen_ie_buf_len += ie_len;
1494 } else {
1495 /* Passed data does not fit in the remaining
1496 buffer space */
1497 ret = -1;
1498 }
1499
1500 /* Return 0, or -1 for error case */
1501 return ret;
1502}
1503
1504/*
1505 * IOCTL request handler to set/get generic IE.
1506 *
1507 * In addition to various generic IEs, this function can also be
1508 * used to set the ARP filter.
1509 */
1510static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1511 struct mwifiex_ds_misc_gen_ie *gen_ie,
1512 u16 action)
1513{
1514 struct mwifiex_adapter *adapter = priv->adapter;
1515
1516 switch (gen_ie->type) {
1517 case MWIFIEX_IE_TYPE_GEN_IE:
1518 if (action == HostCmd_ACT_GEN_GET) {
1519 gen_ie->len = priv->wpa_ie_len;
1520 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1521 } else {
1522 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1523 (u16) gen_ie->len);
1524 }
1525 break;
1526 case MWIFIEX_IE_TYPE_ARP_FILTER:
1527 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1528 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1529 adapter->arp_filter_size = 0;
1530 dev_err(adapter->dev, "invalid ARP filter size\n");
1531 return -1;
1532 } else {
1533 memcpy(adapter->arp_filter, gen_ie->ie_data,
1534 gen_ie->len);
1535 adapter->arp_filter_size = gen_ie->len;
1536 }
1537 break;
1538 default:
1539 dev_err(adapter->dev, "invalid IE type\n");
1540 return -1;
1541 }
1542 return 0;
1543}
1544
1545/*
1546 * Sends IOCTL request to set a generic IE.
1547 *
1548 * This function allocates the IOCTL request buffer, fills it
1549 * with requisite parameters and calls the IOCTL handler.
1550 */
1551int
1552mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1553{
1554 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001555
Bing Zhao67a50032011-07-13 18:38:34 -07001556 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001557 return -EFAULT;
1558
1559 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1560 gen_ie.len = ie_len;
1561 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001562 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001563 return -EFAULT;
1564
1565 return 0;
1566}