blob: fd09a21b8824f57a88ea13c02089a0804c69f93d [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
Amitkumar Karwar22c22d22012-09-20 20:23:17 -070029static int disconnect_on_suspend = 1;
30module_param(disconnect_on_suspend, int, 0644);
31
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032/*
33 * Copies the multicast address list from device to driver.
34 *
35 * This function does not validate the destination memory for
36 * size, and the calling function must ensure enough memory is
37 * available.
38 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070039int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
40 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070041{
42 int i = 0;
43 struct netdev_hw_addr *ha;
44
45 netdev_for_each_mc_addr(ha, dev)
46 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
47
48 return i;
49}
50
51/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052 * Wait queue completion handler.
53 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070054 * This function waits on a cmd wait queue. It also cancels the pending
55 * request after waking up, in case of errors.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070057int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070058{
59 bool cancel_flag = false;
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080060 int status;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080061 struct cmd_ctrl_node *cmd_queued;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070062
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080063 if (!adapter->cmd_queued)
64 return 0;
65
66 cmd_queued = adapter->cmd_queued;
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -070067 adapter->cmd_queued = NULL;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080068
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070069 dev_dbg(adapter->dev, "cmd pending\n");
70 atomic_inc(&adapter->cmd_pending);
71
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070072 /* Wait for completion */
73 wait_event_interruptible(adapter->cmd_wait_q.wait,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -070074 *(cmd_queued->condition));
Amitkumar Karwarefaaa8b2011-10-12 20:28:06 -070075 if (!*(cmd_queued->condition))
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070076 cancel_flag = true;
77
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078 if (cancel_flag) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070079 mwifiex_cancel_pending_ioctl(adapter);
80 dev_dbg(adapter->dev, "cmd cancel\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070081 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080082
83 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070084 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070085
Bing Zhao5e6e3a92011-03-21 18:00:50 -070086 return status;
87}
88
89/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070090 * This function prepares the correct firmware command and
91 * issues it to set the multicast list.
92 *
93 * This function can be used to enable promiscuous mode, or enable all
94 * multicast packets, or to enable selective multicast.
95 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070096int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
97 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070098{
99 int ret = 0;
100 u16 old_pkt_filter;
101
102 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700103
104 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
105 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
106 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
107 priv->curr_pkt_filter &=
108 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
109 } else {
110 /* Multicast */
111 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
112 if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) {
113 dev_dbg(priv->adapter->dev,
114 "info: Enabling All Multicast!\n");
115 priv->curr_pkt_filter |=
116 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
117 } else {
118 priv->curr_pkt_filter &=
119 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
120 if (mcast_list->num_multicast_addr) {
121 dev_dbg(priv->adapter->dev,
122 "info: Set multicast list=%d\n",
123 mcast_list->num_multicast_addr);
124 /* Set multicast addresses to firmware */
125 if (old_pkt_filter == priv->curr_pkt_filter) {
126 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700127 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700128 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700129 HostCmd_ACT_GEN_SET, 0,
130 mcast_list);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700131 } else {
132 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700133 ret = mwifiex_send_cmd_async(priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700134 HostCmd_CMD_MAC_MULTICAST_ADR,
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700135 HostCmd_ACT_GEN_SET, 0,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700136 mcast_list);
137 }
138 }
139 }
140 }
141 dev_dbg(priv->adapter->dev,
142 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
143 old_pkt_filter, priv->curr_pkt_filter);
144 if (old_pkt_filter != priv->curr_pkt_filter) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700145 ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL,
146 HostCmd_ACT_GEN_SET,
147 0, &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700148 }
149
150 return ret;
151}
152
153/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700154 * This function fills bss descriptor structure using provided
155 * information.
156 */
157int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700158 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700159 struct mwifiex_bssdescriptor *bss_desc)
160{
161 int ret;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700162 u8 *beacon_ie;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700163 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700164
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700165 beacon_ie = kmemdup(bss->information_elements, bss->len_beacon_ies,
166 GFP_KERNEL);
167 if (!beacon_ie) {
168 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
169 return -ENOMEM;
170 }
171
172 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
173 bss_desc->rssi = bss->signal;
174 bss_desc->beacon_buf = beacon_ie;
175 bss_desc->beacon_buf_size = bss->len_beacon_ies;
176 bss_desc->beacon_period = bss->beacon_interval;
177 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700178 bss_desc->bss_band = bss_priv->band;
179 bss_desc->fw_tsf = bss_priv->fw_tsf;
180 bss_desc->timestamp = bss->tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700181 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
182 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
183 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
184 } else {
185 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
186 }
187 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
188 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
189 else
190 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
191
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700192 ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700193
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700194 kfree(beacon_ie);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700195 return ret;
196}
197
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700198static int mwifiex_process_country_ie(struct mwifiex_private *priv,
199 struct cfg80211_bss *bss)
200{
201 u8 *country_ie, country_ie_len;
202 struct mwifiex_802_11d_domain_reg *domain_info =
203 &priv->adapter->domain_reg;
204
205 country_ie = (u8 *)ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
206
207 if (!country_ie)
208 return 0;
209
210 country_ie_len = country_ie[1];
211 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
212 return 0;
213
214 domain_info->country_code[0] = country_ie[2];
215 domain_info->country_code[1] = country_ie[3];
216 domain_info->country_code[2] = ' ';
217
218 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
219
220 domain_info->no_of_triplet =
221 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
222
223 memcpy((u8 *)domain_info->triplet,
224 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
225
226 if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
227 HostCmd_ACT_GEN_SET, 0, NULL)) {
228 wiphy_err(priv->adapter->wiphy,
229 "11D: setting domain info in FW\n");
230 return -1;
231 }
232
233 return 0;
234}
235
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700236/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700237 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
238 * In both Ad-Hoc and infra mode, an deauthentication is performed
239 * first.
240 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700241int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800242 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700243{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700244 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700245 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700246 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700247
248 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700249
250 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700251 mwifiex_process_country_ie(priv, bss);
252
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700253 /* Allocate and fill new bss descriptor */
254 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
255 GFP_KERNEL);
256 if (!bss_desc) {
257 dev_err(priv->adapter->dev, " failed to alloc bss_desc\n");
258 return -ENOMEM;
259 }
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700260
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700261 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700262 if (ret)
263 goto done;
264 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700265
Bing Zhaoeecd8252011-03-28 17:55:41 -0700266 if (priv->bss_mode == NL80211_IFTYPE_STATION) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700267 /* Infra mode */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700268 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700270 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700271
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700272 ret = mwifiex_check_network_compatibility(priv, bss_desc);
273 if (ret)
274 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700275
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700276 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
277 "associating...\n");
278
279 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800280 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800281 if (netif_carrier_ok(priv->netdev))
282 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700283
284 /* Clear any past association response stored for
285 * application retrieval */
286 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700287 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800288
289 /* If auth type is auto and association fails using open mode,
290 * try to connect using shared mode */
291 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
292 priv->sec_info.is_authtype_auto &&
293 priv->sec_info.wep_enabled) {
294 priv->sec_info.authentication_mode =
295 NL80211_AUTHTYPE_SHARED_KEY;
296 ret = mwifiex_associate(priv, bss_desc);
297 }
298
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700299 if (bss)
300 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700301 } else {
302 /* Adhoc mode */
303 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700304 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700305 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
306 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700307 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700308 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700309 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700310
311 /* Exit Adhoc mode first */
312 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700313 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700314 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700315 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700316
317 priv->adhoc_is_link_sensed = false;
318
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700319 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700320
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700321 if (!netif_queue_stopped(priv->netdev))
Avinash Patilbbea3bc2011-12-08 20:41:05 -0800322 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800323 if (netif_carrier_ok(priv->netdev))
324 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700325
326 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700327 dev_dbg(adapter->dev, "info: network found in scan"
328 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700329 ret = mwifiex_adhoc_join(priv, bss_desc);
330 if (bss)
331 cfg80211_put_bss(bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700332 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700333 dev_dbg(adapter->dev, "info: Network not found in "
334 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700335 req_ssid->ssid);
336 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337 }
338 }
339
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700340done:
341 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700342 return ret;
343}
344
345/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700346 * IOCTL request handler to set host sleep configuration.
347 *
348 * This function prepares the correct firmware command and
349 * issues it.
350 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700351static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
352 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700353
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700354{
355 struct mwifiex_adapter *adapter = priv->adapter;
356 int status = 0;
357 u32 prev_cond = 0;
358
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700359 if (!hs_cfg)
360 return -ENOMEM;
361
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 switch (action) {
363 case HostCmd_ACT_GEN_SET:
364 if (adapter->pps_uapsd_mode) {
365 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
366 " is blocked in UAPSD/PPS mode\n");
367 status = -1;
368 break;
369 }
370 if (hs_cfg->is_invoke_hostcmd) {
371 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
372 if (!adapter->is_hs_configured)
373 /* Already cancelled */
374 break;
375 /* Save previous condition */
376 prev_cond = le32_to_cpu(adapter->hs_cfg
377 .conditions);
378 adapter->hs_cfg.conditions =
379 cpu_to_le32(hs_cfg->conditions);
380 } else if (hs_cfg->conditions) {
381 adapter->hs_cfg.conditions =
382 cpu_to_le32(hs_cfg->conditions);
383 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
384 if (hs_cfg->gap)
385 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700386 } else if (adapter->hs_cfg.conditions
387 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700388 /* Return failure if no parameters for HS
389 enable */
390 status = -1;
391 break;
392 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700393 if (cmd_type == MWIFIEX_SYNC_CMD)
394 status = mwifiex_send_cmd_sync(priv,
395 HostCmd_CMD_802_11_HS_CFG_ENH,
396 HostCmd_ACT_GEN_SET, 0,
397 &adapter->hs_cfg);
398 else
399 status = mwifiex_send_cmd_async(priv,
400 HostCmd_CMD_802_11_HS_CFG_ENH,
401 HostCmd_ACT_GEN_SET, 0,
402 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700403 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
404 /* Restore previous condition */
405 adapter->hs_cfg.conditions =
406 cpu_to_le32(prev_cond);
407 } else {
408 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700409 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700410 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
411 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
412 }
413 break;
414 case HostCmd_ACT_GEN_GET:
415 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
416 hs_cfg->gpio = adapter->hs_cfg.gpio;
417 hs_cfg->gap = adapter->hs_cfg.gap;
418 break;
419 default:
420 status = -1;
421 break;
422 }
423
424 return status;
425}
426
427/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700428 * Sends IOCTL request to cancel the existing Host Sleep configuration.
429 *
430 * This function allocates the IOCTL request buffer, fills it
431 * with requisite parameters and calls the IOCTL handler.
432 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700433int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700434{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700435 struct mwifiex_ds_hs_cfg hscfg;
436
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700437 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
438 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700439
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700440 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
441 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700442}
443EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
444
445/*
446 * Sends IOCTL request to cancel the existing Host Sleep configuration.
447 *
448 * This function allocates the IOCTL request buffer, fills it
449 * with requisite parameters and calls the IOCTL handler.
450 */
451int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
452{
453 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700454 struct mwifiex_private *priv;
455 int i;
456
457 if (disconnect_on_suspend) {
458 for (i = 0; i < adapter->priv_num; i++) {
459 priv = adapter->priv[i];
460 if (priv)
461 mwifiex_deauthenticate(priv, NULL);
462 }
463 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700464
465 if (adapter->hs_activated) {
466 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
467 return true;
468 }
469
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470 adapter->hs_activate_wait_q_woken = false;
471
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700472 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473 hscfg.is_invoke_hostcmd = true;
474
475 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700476 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700477 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
478 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700479 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
480 return false;
481 }
482
483 wait_event_interruptible(adapter->hs_activate_wait_q,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700484 adapter->hs_activate_wait_q_woken);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700485
486 return true;
487}
488EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
489
490/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700491 * IOCTL request handler to get BSS information.
492 *
493 * This function collates the information from different driver structures
494 * to send to the user.
495 */
496int mwifiex_get_bss_info(struct mwifiex_private *priv,
497 struct mwifiex_bss_info *info)
498{
499 struct mwifiex_adapter *adapter = priv->adapter;
500 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700501
502 if (!info)
503 return -1;
504
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 bss_desc = &priv->curr_bss_params.bss_descriptor;
506
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700507 info->bss_mode = priv->bss_mode;
508
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800509 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700511 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
512
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700513 info->bss_chan = bss_desc->channel;
514
Avinash Patil67fdf392012-05-08 18:30:17 -0700515 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700516 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700517
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 info->media_connected = priv->media_connected;
519
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700520 info->max_power_level = priv->max_tx_power_level;
521 info->min_power_level = priv->min_tx_power_level;
522
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523 info->adhoc_state = priv->adhoc_state;
524
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700525 info->bcn_nf_last = priv->bcn_nf_last;
526
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800527 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700528 info->wep_status = true;
529 else
530 info->wep_status = false;
531
532 info->is_hs_configured = adapter->is_hs_configured;
533 info->is_deep_sleep = adapter->is_deep_sleep;
534
535 return 0;
536}
537
538/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700539 * The function disables auto deep sleep mode.
540 */
541int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
542{
543 struct mwifiex_ds_auto_ds auto_ds;
544
545 auto_ds.auto_ds = DEEP_SLEEP_OFF;
546
547 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
548 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
549}
550EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
551
552/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553 * Sends IOCTL request to get the data rate.
554 *
555 * This function allocates the IOCTL request buffer, fills it
556 * with requisite parameters and calls the IOCTL handler.
557 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700558int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700559{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700560 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700561
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700562 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
563 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700564
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700566 if (priv->is_data_rate_auto)
567 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
568 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300569 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700570 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700571 }
572
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700573 return ret;
574}
575
576/*
577 * IOCTL request handler to set tx power configuration.
578 *
579 * This function prepares the correct firmware command and
580 * issues it.
581 *
582 * For non-auto power mode, all the following power groups are set -
583 * - Modulation class HR/DSSS
584 * - Modulation class OFDM
585 * - Modulation class HTBW20
586 * - Modulation class HTBW40
587 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700588int mwifiex_set_tx_power(struct mwifiex_private *priv,
589 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700590{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700591 int ret;
592 struct host_cmd_ds_txpwr_cfg *txp_cfg;
593 struct mwifiex_types_power_group *pg_tlv;
594 struct mwifiex_power_group *pg;
595 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 u16 dbm = 0;
597
598 if (!power_cfg->is_power_auto) {
599 dbm = (u16) power_cfg->power_level;
600 if ((dbm < priv->min_tx_power_level) ||
601 (dbm > priv->max_tx_power_level)) {
602 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700603 " is out of range (%d dBm-%d dBm)\n",
604 dbm, priv->min_tx_power_level,
605 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700606 return -1;
607 }
608 }
609 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
610 if (!buf) {
611 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700612 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200613 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700614 }
615
616 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
617 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
618 if (!power_cfg->is_power_auto) {
619 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700620 pg_tlv = (struct mwifiex_types_power_group *)
621 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700622 pg_tlv->type = TLV_TYPE_POWER_GROUP;
623 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700624 pg = (struct mwifiex_power_group *)
625 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
626 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700627 /* Power group for modulation class HR/DSSS */
628 pg->first_rate_code = 0x00;
629 pg->last_rate_code = 0x03;
630 pg->modulation_class = MOD_CLASS_HR_DSSS;
631 pg->power_step = 0;
632 pg->power_min = (s8) dbm;
633 pg->power_max = (s8) dbm;
634 pg++;
635 /* Power group for modulation class OFDM */
636 pg->first_rate_code = 0x00;
637 pg->last_rate_code = 0x07;
638 pg->modulation_class = MOD_CLASS_OFDM;
639 pg->power_step = 0;
640 pg->power_min = (s8) dbm;
641 pg->power_max = (s8) dbm;
642 pg++;
643 /* Power group for modulation class HTBW20 */
644 pg->first_rate_code = 0x00;
645 pg->last_rate_code = 0x20;
646 pg->modulation_class = MOD_CLASS_HT;
647 pg->power_step = 0;
648 pg->power_min = (s8) dbm;
649 pg->power_max = (s8) dbm;
650 pg->ht_bandwidth = HT_BW_20;
651 pg++;
652 /* Power group for modulation class HTBW40 */
653 pg->first_rate_code = 0x00;
654 pg->last_rate_code = 0x20;
655 pg->modulation_class = MOD_CLASS_HT;
656 pg->power_step = 0;
657 pg->power_min = (s8) dbm;
658 pg->power_max = (s8) dbm;
659 pg->ht_bandwidth = HT_BW_40;
660 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700661 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
662 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700663
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700664 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700665 return ret;
666}
667
668/*
669 * IOCTL request handler to get power save mode.
670 *
671 * This function prepares the correct firmware command and
672 * issues it.
673 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700674int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700675{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700676 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700677 struct mwifiex_adapter *adapter = priv->adapter;
678 u16 sub_cmd;
679
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700680 if (*ps_mode)
681 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
682 else
683 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
684 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
685 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
686 sub_cmd, BITMAP_STA_PS, NULL);
687 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
688 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700689 HostCmd_CMD_802_11_PS_MODE_ENH,
690 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700691
692 return ret;
693}
694
695/*
696 * IOCTL request handler to set/reset WPA IE.
697 *
698 * The supplied WPA IE is treated as a opaque buffer. Only the first field
699 * is checked to determine WPA version. If buffer length is zero, the existing
700 * WPA IE is reset.
701 */
702static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
703 u8 *ie_data_ptr, u16 ie_len)
704{
705 if (ie_len) {
706 if (ie_len > sizeof(priv->wpa_ie)) {
707 dev_err(priv->adapter->dev,
708 "failed to copy WPA IE, too big\n");
709 return -1;
710 }
711 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
712 priv->wpa_ie_len = (u8) ie_len;
713 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700714 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700715
716 if (priv->wpa_ie[0] == WLAN_EID_WPA) {
717 priv->sec_info.wpa_enabled = true;
718 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
719 priv->sec_info.wpa2_enabled = true;
720 } else {
721 priv->sec_info.wpa_enabled = false;
722 priv->sec_info.wpa2_enabled = false;
723 }
724 } else {
725 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
726 priv->wpa_ie_len = 0;
727 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
728 priv->wpa_ie_len, priv->wpa_ie[0]);
729 priv->sec_info.wpa_enabled = false;
730 priv->sec_info.wpa2_enabled = false;
731 }
732
733 return 0;
734}
735
736/*
737 * IOCTL request handler to set/reset WAPI IE.
738 *
739 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
740 * is checked to internally enable WAPI. If buffer length is zero, the existing
741 * WAPI IE is reset.
742 */
743static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
744 u8 *ie_data_ptr, u16 ie_len)
745{
746 if (ie_len) {
747 if (ie_len > sizeof(priv->wapi_ie)) {
748 dev_dbg(priv->adapter->dev,
749 "info: failed to copy WAPI IE, too big\n");
750 return -1;
751 }
752 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
753 priv->wapi_ie_len = ie_len;
754 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700755 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700756
757 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
758 priv->sec_info.wapi_enabled = true;
759 } else {
760 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
761 priv->wapi_ie_len = ie_len;
762 dev_dbg(priv->adapter->dev,
763 "info: Reset wapi_ie_len=%d IE=%#x\n",
764 priv->wapi_ie_len, priv->wapi_ie[0]);
765 priv->sec_info.wapi_enabled = false;
766 }
767 return 0;
768}
769
770/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700771 * IOCTL request handler to set/reset WPS IE.
772 *
773 * The supplied WPS IE is treated as a opaque buffer. Only the first field
774 * is checked to internally enable WPS. If buffer length is zero, the existing
775 * WPS IE is reset.
776 */
777static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
778 u8 *ie_data_ptr, u16 ie_len)
779{
780 if (ie_len) {
781 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
782 if (!priv->wps_ie)
783 return -ENOMEM;
784 if (ie_len > sizeof(priv->wps_ie)) {
785 dev_dbg(priv->adapter->dev,
786 "info: failed to copy WPS IE, too big\n");
787 kfree(priv->wps_ie);
788 return -1;
789 }
790 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
791 priv->wps_ie_len = ie_len;
792 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
793 priv->wps_ie_len, priv->wps_ie[0]);
794 } else {
795 kfree(priv->wps_ie);
796 priv->wps_ie_len = ie_len;
797 dev_dbg(priv->adapter->dev,
798 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
799 }
800 return 0;
801}
802
803/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700804 * IOCTL request handler to set WAPI key.
805 *
806 * This function prepares the correct firmware command and
807 * issues it.
808 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700809static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700810 struct mwifiex_ds_encrypt_key *encrypt_key)
811{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700812
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700813 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700814 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
815 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700816}
817
818/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700819 * IOCTL request handler to set WEP network key.
820 *
821 * This function prepares the correct firmware command and
822 * issues it, after validation checks.
823 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700824static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700825 struct mwifiex_ds_encrypt_key *encrypt_key)
826{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700827 int ret;
828 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700829 int index;
830
831 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
832 priv->wep_key_curr_index = 0;
833 wep_key = &priv->wep_key[priv->wep_key_curr_index];
834 index = encrypt_key->key_index;
835 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800836 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700837 } else if (!encrypt_key->key_len) {
838 /* Copy the required key as the current key */
839 wep_key = &priv->wep_key[index];
840 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700841 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700842 "key not set, so cannot enable it\n");
843 return -1;
844 }
845 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800846 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700847 } else {
848 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700849 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
850 /* Copy the key in the driver */
851 memcpy(wep_key->key_material,
852 encrypt_key->key_material,
853 encrypt_key->key_len);
854 wep_key->key_index = index;
855 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800856 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700857 }
858 if (wep_key->key_length) {
859 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700860 ret = mwifiex_send_cmd_async(priv,
861 HostCmd_CMD_802_11_KEY_MATERIAL,
862 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700863 if (ret)
864 return ret;
865 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800866 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
868 else
869 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
870
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700871 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
872 HostCmd_ACT_GEN_SET, 0,
873 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874
875 return ret;
876}
877
878/*
879 * IOCTL request handler to set WPA key.
880 *
881 * This function prepares the correct firmware command and
882 * issues it, after validation checks.
883 *
884 * Current driver only supports key length of up to 32 bytes.
885 *
886 * This function can also be used to disable a currently set key.
887 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700888static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700889 struct mwifiex_ds_encrypt_key *encrypt_key)
890{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700891 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700892 u8 remove_key = false;
893 struct host_cmd_ds_802_11_key_material *ibss_key;
894
895 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700896 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700897 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898 return -1;
899 }
900
Bing Zhaoeecd8252011-03-28 17:55:41 -0700901 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700902 /*
903 * IBSS/WPA-None uses only one key (Group) for both receiving
904 * and sending unicast and multicast packets.
905 */
906 /* Send the key as PTK to firmware */
907 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700908 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700909 HostCmd_CMD_802_11_KEY_MATERIAL,
910 HostCmd_ACT_GEN_SET,
911 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700912 if (ret)
913 return ret;
914
915 ibss_key = &priv->aes_key;
916 memset(ibss_key, 0,
917 sizeof(struct host_cmd_ds_802_11_key_material));
918 /* Copy the key in the driver */
919 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
920 encrypt_key->key_len);
921 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
922 sizeof(ibss_key->key_param_set.key_len));
923 ibss_key->key_param_set.key_type_id
924 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700925 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700926
927 /* Send the key as GTK to firmware */
928 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
929 }
930
931 if (!encrypt_key->key_index)
932 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
933
934 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700935 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700936 HostCmd_CMD_802_11_KEY_MATERIAL,
937 HostCmd_ACT_GEN_SET,
938 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700939 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700940 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700941 HostCmd_CMD_802_11_KEY_MATERIAL,
942 HostCmd_ACT_GEN_SET,
943 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700944
945 return ret;
946}
947
948/*
949 * IOCTL request handler to set/get network keys.
950 *
951 * This is a generic key handling function which supports WEP, WPA
952 * and WAPI.
953 */
954static int
955mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700956 struct mwifiex_ds_encrypt_key *encrypt_key)
957{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700958 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700959
960 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700961 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700962 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700963 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700964 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700965 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700966 return status;
967}
968
969/*
970 * This function returns the driver version.
971 */
972int
973mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
974 int max_len)
975{
976 union {
977 u32 l;
978 u8 c[4];
979 } ver;
980 char fw_ver[32];
981
982 ver.l = adapter->fw_release_number;
983 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
984
985 snprintf(version, max_len, driver_version, fw_ver);
986
987 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
988
989 return 0;
990}
991
992/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700993 * Sends IOCTL request to set encoding parameters.
994 *
995 * This function allocates the IOCTL request buffer, fills it
996 * with requisite parameters and calls the IOCTL handler.
997 */
Ying Luo53b11232012-08-03 18:06:13 -0700998int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
999 const u8 *key, int key_len, u8 key_index,
1000 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001001{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001002 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001003
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001004 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1005 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001006
1007 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1008 encrypt_key.is_igtk_key = true;
1009
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001010 if (!disable) {
1011 encrypt_key.key_index = key_index;
1012 if (key_len)
1013 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001014 if (mac_addr)
1015 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001016 if (kp && kp->seq && kp->seq_len)
1017 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001018 } else {
1019 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001020 if (mac_addr)
1021 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022 }
1023
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001024 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001025}
1026
1027/*
1028 * Sends IOCTL request to get extended version.
1029 *
1030 * This function allocates the IOCTL request buffer, fills it
1031 * with requisite parameters and calls the IOCTL handler.
1032 */
1033int
1034mwifiex_get_ver_ext(struct mwifiex_private *priv)
1035{
1036 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001037
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001038 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001039 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001040 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001041 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001043 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001044}
1045
Stone Piao7feb4c42012-09-25 20:23:36 -07001046int
1047mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1048 struct ieee80211_channel *chan,
1049 enum nl80211_channel_type *ct,
1050 unsigned int duration)
1051{
1052 struct host_cmd_ds_remain_on_chan roc_cfg;
1053 u8 sc;
1054
1055 memset(&roc_cfg, 0, sizeof(roc_cfg));
1056 roc_cfg.action = cpu_to_le16(action);
1057 if (action == HostCmd_ACT_GEN_SET) {
1058 roc_cfg.band_cfg = chan->band;
1059 sc = mwifiex_chan_type_to_sec_chan_offset(*ct);
1060 roc_cfg.band_cfg |= (sc << 2);
1061
1062 roc_cfg.channel =
1063 ieee80211_frequency_to_channel(chan->center_freq);
1064 roc_cfg.duration = cpu_to_le32(duration);
1065 }
1066 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1067 action, 0, &roc_cfg)) {
1068 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1069 return -1;
1070 }
1071
1072 return roc_cfg.status;
1073}
1074
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001075/*
1076 * Sends IOCTL request to get statistics information.
1077 *
1078 * This function allocates the IOCTL request buffer, fills it
1079 * with requisite parameters and calls the IOCTL handler.
1080 */
1081int
1082mwifiex_get_stats_info(struct mwifiex_private *priv,
1083 struct mwifiex_ds_get_stats *log)
1084{
Bing Zhao67a50032011-07-13 18:38:34 -07001085 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001086 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001087}
1088
1089/*
1090 * IOCTL request handler to read/write register.
1091 *
1092 * This function prepares the correct firmware command and
1093 * issues it.
1094 *
1095 * Access to the following registers are supported -
1096 * - MAC
1097 * - BBP
1098 * - RF
1099 * - PMIC
1100 * - CAU
1101 */
1102static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103 struct mwifiex_ds_reg_rw *reg_rw,
1104 u16 action)
1105{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106 u16 cmd_no;
1107
1108 switch (le32_to_cpu(reg_rw->type)) {
1109 case MWIFIEX_REG_MAC:
1110 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1111 break;
1112 case MWIFIEX_REG_BBP:
1113 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1114 break;
1115 case MWIFIEX_REG_RF:
1116 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1117 break;
1118 case MWIFIEX_REG_PMIC:
1119 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1120 break;
1121 case MWIFIEX_REG_CAU:
1122 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1123 break;
1124 default:
1125 return -1;
1126 }
1127
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001128 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001129
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001130}
1131
1132/*
1133 * Sends IOCTL request to write to a register.
1134 *
1135 * This function allocates the IOCTL request buffer, fills it
1136 * with requisite parameters and calls the IOCTL handler.
1137 */
1138int
1139mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1140 u32 reg_offset, u32 reg_value)
1141{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001142 struct mwifiex_ds_reg_rw reg_rw;
1143
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001144 reg_rw.type = cpu_to_le32(reg_type);
1145 reg_rw.offset = cpu_to_le32(reg_offset);
1146 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001147
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001148 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001149}
1150
1151/*
1152 * Sends IOCTL request to read from a register.
1153 *
1154 * This function allocates the IOCTL request buffer, fills it
1155 * with requisite parameters and calls the IOCTL handler.
1156 */
1157int
1158mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1159 u32 reg_offset, u32 *value)
1160{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001161 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001162 struct mwifiex_ds_reg_rw reg_rw;
1163
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001164 reg_rw.type = cpu_to_le32(reg_type);
1165 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001166 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001167
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001168 if (ret)
1169 goto done;
1170
1171 *value = le32_to_cpu(reg_rw.value);
1172
1173done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001174 return ret;
1175}
1176
1177/*
1178 * Sends IOCTL request to read from EEPROM.
1179 *
1180 * This function allocates the IOCTL request buffer, fills it
1181 * with requisite parameters and calls the IOCTL handler.
1182 */
1183int
1184mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1185 u8 *value)
1186{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001187 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001188 struct mwifiex_ds_read_eeprom rd_eeprom;
1189
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001190 rd_eeprom.offset = cpu_to_le16((u16) offset);
1191 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001192
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001193 /* Send request to firmware */
1194 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1195 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001197 if (!ret)
1198 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199 return ret;
1200}
1201
1202/*
1203 * This function sets a generic IE. In addition to generic IE, it can
1204 * also handle WPA, WPA2 and WAPI IEs.
1205 */
1206static int
1207mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1208 u16 ie_len)
1209{
1210 int ret = 0;
1211 struct ieee_types_vendor_header *pvendor_ie;
1212 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1213 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1214
1215 /* If the passed length is zero, reset the buffer */
1216 if (!ie_len) {
1217 priv->gen_ie_buf_len = 0;
1218 priv->wps.session_enable = false;
1219
1220 return 0;
1221 } else if (!ie_data_ptr) {
1222 return -1;
1223 }
1224 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1225 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001226 if (((pvendor_ie->element_id == WLAN_EID_WPA) &&
1227 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1228 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001229
1230 /* IE is a WPA/WPA2 IE so call set_wpa function */
1231 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1232 priv->wps.session_enable = false;
1233
1234 return ret;
1235 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1236 /* IE is a WAPI IE so call set_wapi function */
1237 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1238
1239 return ret;
1240 }
1241 /*
1242 * Verify that the passed length is not larger than the
1243 * available space remaining in the buffer
1244 */
1245 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1246
1247 /* Test to see if it is a WPS IE, if so, enable
1248 * wps session flag
1249 */
1250 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001251 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1252 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001253 priv->wps.session_enable = true;
1254 dev_dbg(priv->adapter->dev,
1255 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001256 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 }
1258
1259 /* Append the passed data to the end of the
1260 genIeBuffer */
1261 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001262 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001263 /* Increment the stored buffer length by the
1264 size passed */
1265 priv->gen_ie_buf_len += ie_len;
1266 } else {
1267 /* Passed data does not fit in the remaining
1268 buffer space */
1269 ret = -1;
1270 }
1271
1272 /* Return 0, or -1 for error case */
1273 return ret;
1274}
1275
1276/*
1277 * IOCTL request handler to set/get generic IE.
1278 *
1279 * In addition to various generic IEs, this function can also be
1280 * used to set the ARP filter.
1281 */
1282static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1283 struct mwifiex_ds_misc_gen_ie *gen_ie,
1284 u16 action)
1285{
1286 struct mwifiex_adapter *adapter = priv->adapter;
1287
1288 switch (gen_ie->type) {
1289 case MWIFIEX_IE_TYPE_GEN_IE:
1290 if (action == HostCmd_ACT_GEN_GET) {
1291 gen_ie->len = priv->wpa_ie_len;
1292 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1293 } else {
1294 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1295 (u16) gen_ie->len);
1296 }
1297 break;
1298 case MWIFIEX_IE_TYPE_ARP_FILTER:
1299 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1300 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1301 adapter->arp_filter_size = 0;
1302 dev_err(adapter->dev, "invalid ARP filter size\n");
1303 return -1;
1304 } else {
1305 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001306 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001307 adapter->arp_filter_size = gen_ie->len;
1308 }
1309 break;
1310 default:
1311 dev_err(adapter->dev, "invalid IE type\n");
1312 return -1;
1313 }
1314 return 0;
1315}
1316
1317/*
1318 * Sends IOCTL request to set a generic IE.
1319 *
1320 * This function allocates the IOCTL request buffer, fills it
1321 * with requisite parameters and calls the IOCTL handler.
1322 */
1323int
1324mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1325{
1326 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001327
Bing Zhao67a50032011-07-13 18:38:34 -07001328 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001329 return -EFAULT;
1330
1331 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1332 gen_ie.len = ie_len;
1333 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001334 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001335 return -EFAULT;
1336
1337 return 0;
1338}