blob: c8b50c70a03d7aa196dd80d182638d1f60da7a27 [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
Avinash Patil47411a02012-11-01 18:44:16 -0700279 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800280 if (netif_carrier_ok(priv->netdev))
281 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700282
283 /* Clear any past association response stored for
284 * application retrieval */
285 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700286 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800287
288 /* If auth type is auto and association fails using open mode,
289 * try to connect using shared mode */
290 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
291 priv->sec_info.is_authtype_auto &&
292 priv->sec_info.wep_enabled) {
293 priv->sec_info.authentication_mode =
294 NL80211_AUTHTYPE_SHARED_KEY;
295 ret = mwifiex_associate(priv, bss_desc);
296 }
297
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700298 if (bss)
299 cfg80211_put_bss(bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700300 } else {
301 /* Adhoc mode */
302 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700303 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700304 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
305 ssid, &bss_desc->ssid))) {
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700306 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700307 return 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700308 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700309
310 /* Exit Adhoc mode first */
311 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700312 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700313 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700314 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700315
316 priv->adhoc_is_link_sensed = false;
317
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700318 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700319
Avinash Patil47411a02012-11-01 18:44:16 -0700320 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800321 if (netif_carrier_ok(priv->netdev))
322 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700323
324 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700325 dev_dbg(adapter->dev, "info: network found in scan"
326 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700327 ret = mwifiex_adhoc_join(priv, bss_desc);
328 if (bss)
329 cfg80211_put_bss(bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700330 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700331 dev_dbg(adapter->dev, "info: Network not found in "
332 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700333 req_ssid->ssid);
334 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700335 }
336 }
337
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700338done:
339 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700340 return ret;
341}
342
343/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700344 * IOCTL request handler to set host sleep configuration.
345 *
346 * This function prepares the correct firmware command and
347 * issues it.
348 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700349static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
350 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700351
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700352{
353 struct mwifiex_adapter *adapter = priv->adapter;
354 int status = 0;
355 u32 prev_cond = 0;
356
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700357 if (!hs_cfg)
358 return -ENOMEM;
359
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700360 switch (action) {
361 case HostCmd_ACT_GEN_SET:
362 if (adapter->pps_uapsd_mode) {
363 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
364 " is blocked in UAPSD/PPS mode\n");
365 status = -1;
366 break;
367 }
368 if (hs_cfg->is_invoke_hostcmd) {
369 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) {
370 if (!adapter->is_hs_configured)
371 /* Already cancelled */
372 break;
373 /* Save previous condition */
374 prev_cond = le32_to_cpu(adapter->hs_cfg
375 .conditions);
376 adapter->hs_cfg.conditions =
377 cpu_to_le32(hs_cfg->conditions);
378 } else if (hs_cfg->conditions) {
379 adapter->hs_cfg.conditions =
380 cpu_to_le32(hs_cfg->conditions);
381 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
382 if (hs_cfg->gap)
383 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700384 } else if (adapter->hs_cfg.conditions
385 == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700386 /* Return failure if no parameters for HS
387 enable */
388 status = -1;
389 break;
390 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700391 if (cmd_type == MWIFIEX_SYNC_CMD)
392 status = mwifiex_send_cmd_sync(priv,
393 HostCmd_CMD_802_11_HS_CFG_ENH,
394 HostCmd_ACT_GEN_SET, 0,
395 &adapter->hs_cfg);
396 else
397 status = mwifiex_send_cmd_async(priv,
398 HostCmd_CMD_802_11_HS_CFG_ENH,
399 HostCmd_ACT_GEN_SET, 0,
400 &adapter->hs_cfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700401 if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL)
402 /* Restore previous condition */
403 adapter->hs_cfg.conditions =
404 cpu_to_le32(prev_cond);
405 } else {
406 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700407 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700408 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
409 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
410 }
411 break;
412 case HostCmd_ACT_GEN_GET:
413 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
414 hs_cfg->gpio = adapter->hs_cfg.gpio;
415 hs_cfg->gap = adapter->hs_cfg.gap;
416 break;
417 default:
418 status = -1;
419 break;
420 }
421
422 return status;
423}
424
425/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700426 * Sends IOCTL request to cancel the existing Host Sleep configuration.
427 *
428 * This function allocates the IOCTL request buffer, fills it
429 * with requisite parameters and calls the IOCTL handler.
430 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700431int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700432{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700433 struct mwifiex_ds_hs_cfg hscfg;
434
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700435 hscfg.conditions = HOST_SLEEP_CFG_CANCEL;
436 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700437
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700438 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
439 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700440}
441EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
442
443/*
444 * Sends IOCTL request to cancel the existing Host Sleep configuration.
445 *
446 * This function allocates the IOCTL request buffer, fills it
447 * with requisite parameters and calls the IOCTL handler.
448 */
449int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
450{
451 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700452 struct mwifiex_private *priv;
453 int i;
454
455 if (disconnect_on_suspend) {
456 for (i = 0; i < adapter->priv_num; i++) {
457 priv = adapter->priv[i];
458 if (priv)
459 mwifiex_deauthenticate(priv, NULL);
460 }
461 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700462
463 if (adapter->hs_activated) {
464 dev_dbg(adapter->dev, "cmd: HS Already actived\n");
465 return true;
466 }
467
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700468 adapter->hs_activate_wait_q_woken = false;
469
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700470 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700471 hscfg.is_invoke_hostcmd = true;
472
473 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700474 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700475 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
476 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700477 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
478 return false;
479 }
480
481 wait_event_interruptible(adapter->hs_activate_wait_q,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700482 adapter->hs_activate_wait_q_woken);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700483
484 return true;
485}
486EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
487
488/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700489 * IOCTL request handler to get BSS information.
490 *
491 * This function collates the information from different driver structures
492 * to send to the user.
493 */
494int mwifiex_get_bss_info(struct mwifiex_private *priv,
495 struct mwifiex_bss_info *info)
496{
497 struct mwifiex_adapter *adapter = priv->adapter;
498 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700499
500 if (!info)
501 return -1;
502
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700503 bss_desc = &priv->curr_bss_params.bss_descriptor;
504
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 info->bss_mode = priv->bss_mode;
506
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800507 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700508
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700509 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
510
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700511 info->bss_chan = bss_desc->channel;
512
Avinash Patil67fdf392012-05-08 18:30:17 -0700513 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700514 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700515
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700516 info->media_connected = priv->media_connected;
517
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 info->max_power_level = priv->max_tx_power_level;
519 info->min_power_level = priv->min_tx_power_level;
520
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700521 info->adhoc_state = priv->adhoc_state;
522
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523 info->bcn_nf_last = priv->bcn_nf_last;
524
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800525 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700526 info->wep_status = true;
527 else
528 info->wep_status = false;
529
530 info->is_hs_configured = adapter->is_hs_configured;
531 info->is_deep_sleep = adapter->is_deep_sleep;
532
533 return 0;
534}
535
536/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700537 * The function disables auto deep sleep mode.
538 */
539int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
540{
541 struct mwifiex_ds_auto_ds auto_ds;
542
543 auto_ds.auto_ds = DEEP_SLEEP_OFF;
544
545 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
546 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds);
547}
548EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
549
550/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700551 * Sends IOCTL request to get the data rate.
552 *
553 * This function allocates the IOCTL request buffer, fills it
554 * with requisite parameters and calls the IOCTL handler.
555 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700556int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700557{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700558 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700559
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700560 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
561 HostCmd_ACT_GEN_GET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700564 if (priv->is_data_rate_auto)
565 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
566 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300567 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700568 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700569 }
570
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700571 return ret;
572}
573
574/*
575 * IOCTL request handler to set tx power configuration.
576 *
577 * This function prepares the correct firmware command and
578 * issues it.
579 *
580 * For non-auto power mode, all the following power groups are set -
581 * - Modulation class HR/DSSS
582 * - Modulation class OFDM
583 * - Modulation class HTBW20
584 * - Modulation class HTBW40
585 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700586int mwifiex_set_tx_power(struct mwifiex_private *priv,
587 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700588{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700589 int ret;
590 struct host_cmd_ds_txpwr_cfg *txp_cfg;
591 struct mwifiex_types_power_group *pg_tlv;
592 struct mwifiex_power_group *pg;
593 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700594 u16 dbm = 0;
595
596 if (!power_cfg->is_power_auto) {
597 dbm = (u16) power_cfg->power_level;
598 if ((dbm < priv->min_tx_power_level) ||
599 (dbm > priv->max_tx_power_level)) {
600 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700601 " is out of range (%d dBm-%d dBm)\n",
602 dbm, priv->min_tx_power_level,
603 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700604 return -1;
605 }
606 }
607 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
608 if (!buf) {
609 dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700610 __func__);
Christoph Fritzb53575e2011-05-08 22:50:09 +0200611 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700612 }
613
614 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
615 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
616 if (!power_cfg->is_power_auto) {
617 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700618 pg_tlv = (struct mwifiex_types_power_group *)
619 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700620 pg_tlv->type = TLV_TYPE_POWER_GROUP;
621 pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700622 pg = (struct mwifiex_power_group *)
623 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
624 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700625 /* Power group for modulation class HR/DSSS */
626 pg->first_rate_code = 0x00;
627 pg->last_rate_code = 0x03;
628 pg->modulation_class = MOD_CLASS_HR_DSSS;
629 pg->power_step = 0;
630 pg->power_min = (s8) dbm;
631 pg->power_max = (s8) dbm;
632 pg++;
633 /* Power group for modulation class OFDM */
634 pg->first_rate_code = 0x00;
635 pg->last_rate_code = 0x07;
636 pg->modulation_class = MOD_CLASS_OFDM;
637 pg->power_step = 0;
638 pg->power_min = (s8) dbm;
639 pg->power_max = (s8) dbm;
640 pg++;
641 /* Power group for modulation class HTBW20 */
642 pg->first_rate_code = 0x00;
643 pg->last_rate_code = 0x20;
644 pg->modulation_class = MOD_CLASS_HT;
645 pg->power_step = 0;
646 pg->power_min = (s8) dbm;
647 pg->power_max = (s8) dbm;
648 pg->ht_bandwidth = HT_BW_20;
649 pg++;
650 /* Power group for modulation class HTBW40 */
651 pg->first_rate_code = 0x00;
652 pg->last_rate_code = 0x20;
653 pg->modulation_class = MOD_CLASS_HT;
654 pg->power_step = 0;
655 pg->power_min = (s8) dbm;
656 pg->power_max = (s8) dbm;
657 pg->ht_bandwidth = HT_BW_40;
658 }
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700659 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG,
660 HostCmd_ACT_GEN_SET, 0, buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700661
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700662 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700663 return ret;
664}
665
666/*
667 * IOCTL request handler to get power save mode.
668 *
669 * This function prepares the correct firmware command and
670 * issues it.
671 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700672int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700673{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700674 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700675 struct mwifiex_adapter *adapter = priv->adapter;
676 u16 sub_cmd;
677
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700678 if (*ps_mode)
679 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
680 else
681 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
682 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
683 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
684 sub_cmd, BITMAP_STA_PS, NULL);
685 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
686 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700687 HostCmd_CMD_802_11_PS_MODE_ENH,
688 GET_PS, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700689
690 return ret;
691}
692
693/*
694 * IOCTL request handler to set/reset WPA IE.
695 *
696 * The supplied WPA IE is treated as a opaque buffer. Only the first field
697 * is checked to determine WPA version. If buffer length is zero, the existing
698 * WPA IE is reset.
699 */
700static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
701 u8 *ie_data_ptr, u16 ie_len)
702{
703 if (ie_len) {
704 if (ie_len > sizeof(priv->wpa_ie)) {
705 dev_err(priv->adapter->dev,
706 "failed to copy WPA IE, too big\n");
707 return -1;
708 }
709 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
710 priv->wpa_ie_len = (u8) ie_len;
711 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700712 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700713
Arend van Spriel04b23122012-10-12 12:28:14 +0200714 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700715 priv->sec_info.wpa_enabled = true;
716 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
717 priv->sec_info.wpa2_enabled = true;
718 } else {
719 priv->sec_info.wpa_enabled = false;
720 priv->sec_info.wpa2_enabled = false;
721 }
722 } else {
723 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
724 priv->wpa_ie_len = 0;
725 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
726 priv->wpa_ie_len, priv->wpa_ie[0]);
727 priv->sec_info.wpa_enabled = false;
728 priv->sec_info.wpa2_enabled = false;
729 }
730
731 return 0;
732}
733
734/*
735 * IOCTL request handler to set/reset WAPI IE.
736 *
737 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
738 * is checked to internally enable WAPI. If buffer length is zero, the existing
739 * WAPI IE is reset.
740 */
741static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
742 u8 *ie_data_ptr, u16 ie_len)
743{
744 if (ie_len) {
745 if (ie_len > sizeof(priv->wapi_ie)) {
746 dev_dbg(priv->adapter->dev,
747 "info: failed to copy WAPI IE, too big\n");
748 return -1;
749 }
750 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
751 priv->wapi_ie_len = ie_len;
752 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700753 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700754
755 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
756 priv->sec_info.wapi_enabled = true;
757 } else {
758 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
759 priv->wapi_ie_len = ie_len;
760 dev_dbg(priv->adapter->dev,
761 "info: Reset wapi_ie_len=%d IE=%#x\n",
762 priv->wapi_ie_len, priv->wapi_ie[0]);
763 priv->sec_info.wapi_enabled = false;
764 }
765 return 0;
766}
767
768/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700769 * IOCTL request handler to set/reset WPS IE.
770 *
771 * The supplied WPS IE is treated as a opaque buffer. Only the first field
772 * is checked to internally enable WPS. If buffer length is zero, the existing
773 * WPS IE is reset.
774 */
775static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
776 u8 *ie_data_ptr, u16 ie_len)
777{
778 if (ie_len) {
779 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
780 if (!priv->wps_ie)
781 return -ENOMEM;
782 if (ie_len > sizeof(priv->wps_ie)) {
783 dev_dbg(priv->adapter->dev,
784 "info: failed to copy WPS IE, too big\n");
785 kfree(priv->wps_ie);
786 return -1;
787 }
788 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
789 priv->wps_ie_len = ie_len;
790 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
791 priv->wps_ie_len, priv->wps_ie[0]);
792 } else {
793 kfree(priv->wps_ie);
794 priv->wps_ie_len = ie_len;
795 dev_dbg(priv->adapter->dev,
796 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
797 }
798 return 0;
799}
800
801/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700802 * IOCTL request handler to set WAPI key.
803 *
804 * This function prepares the correct firmware command and
805 * issues it.
806 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700807static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700808 struct mwifiex_ds_encrypt_key *encrypt_key)
809{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700810
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700811 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700812 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
813 encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700814}
815
816/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700817 * IOCTL request handler to set WEP network key.
818 *
819 * This function prepares the correct firmware command and
820 * issues it, after validation checks.
821 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700822static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700823 struct mwifiex_ds_encrypt_key *encrypt_key)
824{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700825 int ret;
826 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700827 int index;
828
829 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
830 priv->wep_key_curr_index = 0;
831 wep_key = &priv->wep_key[priv->wep_key_curr_index];
832 index = encrypt_key->key_index;
833 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800834 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700835 } else if (!encrypt_key->key_len) {
836 /* Copy the required key as the current key */
837 wep_key = &priv->wep_key[index];
838 if (!wep_key->key_length) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700839 dev_err(priv->adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700840 "key not set, so cannot enable it\n");
841 return -1;
842 }
843 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800844 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700845 } else {
846 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700847 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
848 /* Copy the key in the driver */
849 memcpy(wep_key->key_material,
850 encrypt_key->key_material,
851 encrypt_key->key_len);
852 wep_key->key_index = index;
853 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800854 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700855 }
856 if (wep_key->key_length) {
857 /* Send request to firmware */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700858 ret = mwifiex_send_cmd_async(priv,
859 HostCmd_CMD_802_11_KEY_MATERIAL,
860 HostCmd_ACT_GEN_SET, 0, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 if (ret)
862 return ret;
863 }
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800864 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700865 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
866 else
867 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
868
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700869 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL,
870 HostCmd_ACT_GEN_SET, 0,
871 &priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872
873 return ret;
874}
875
876/*
877 * IOCTL request handler to set WPA key.
878 *
879 * This function prepares the correct firmware command and
880 * issues it, after validation checks.
881 *
882 * Current driver only supports key length of up to 32 bytes.
883 *
884 * This function can also be used to disable a currently set key.
885 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700886static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700887 struct mwifiex_ds_encrypt_key *encrypt_key)
888{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700889 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700890 u8 remove_key = false;
891 struct host_cmd_ds_802_11_key_material *ibss_key;
892
893 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700894 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700895 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700896 return -1;
897 }
898
Bing Zhaoeecd8252011-03-28 17:55:41 -0700899 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700900 /*
901 * IBSS/WPA-None uses only one key (Group) for both receiving
902 * and sending unicast and multicast packets.
903 */
904 /* Send the key as PTK to firmware */
905 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700906 ret = mwifiex_send_cmd_async(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700907 HostCmd_CMD_802_11_KEY_MATERIAL,
908 HostCmd_ACT_GEN_SET,
909 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700910 if (ret)
911 return ret;
912
913 ibss_key = &priv->aes_key;
914 memset(ibss_key, 0,
915 sizeof(struct host_cmd_ds_802_11_key_material));
916 /* Copy the key in the driver */
917 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
918 encrypt_key->key_len);
919 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
920 sizeof(ibss_key->key_param_set.key_len));
921 ibss_key->key_param_set.key_type_id
922 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700923 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700924
925 /* Send the key as GTK to firmware */
926 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
927 }
928
929 if (!encrypt_key->key_index)
930 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
931
932 if (remove_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700933 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700934 HostCmd_CMD_802_11_KEY_MATERIAL,
935 HostCmd_ACT_GEN_SET,
936 !KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700937 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700938 ret = mwifiex_send_cmd_sync(priv,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700939 HostCmd_CMD_802_11_KEY_MATERIAL,
940 HostCmd_ACT_GEN_SET,
941 KEY_INFO_ENABLED, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700942
943 return ret;
944}
945
946/*
947 * IOCTL request handler to set/get network keys.
948 *
949 * This is a generic key handling function which supports WEP, WPA
950 * and WAPI.
951 */
952static int
953mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700954 struct mwifiex_ds_encrypt_key *encrypt_key)
955{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700956 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700957
958 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700959 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700960 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700961 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700962 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700963 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700964 return status;
965}
966
967/*
968 * This function returns the driver version.
969 */
970int
971mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
972 int max_len)
973{
974 union {
975 u32 l;
976 u8 c[4];
977 } ver;
978 char fw_ver[32];
979
980 ver.l = adapter->fw_release_number;
981 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
982
983 snprintf(version, max_len, driver_version, fw_ver);
984
985 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
986
987 return 0;
988}
989
990/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700991 * Sends IOCTL request to set encoding parameters.
992 *
993 * This function allocates the IOCTL request buffer, fills it
994 * with requisite parameters and calls the IOCTL handler.
995 */
Ying Luo53b11232012-08-03 18:06:13 -0700996int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
997 const u8 *key, int key_len, u8 key_index,
998 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700999{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001000 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001001
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001002 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1003 encrypt_key.key_len = key_len;
Ying Luo53b11232012-08-03 18:06:13 -07001004
1005 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1006 encrypt_key.is_igtk_key = true;
1007
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001008 if (!disable) {
1009 encrypt_key.key_index = key_index;
1010 if (key_len)
1011 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patil75edd2c2012-05-08 18:30:18 -07001012 if (mac_addr)
1013 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Ying Luo53b11232012-08-03 18:06:13 -07001014 if (kp && kp->seq && kp->seq_len)
1015 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016 } else {
1017 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001018 if (mac_addr)
1019 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001020 }
1021
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001022 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001023}
1024
1025/*
1026 * Sends IOCTL request to get extended version.
1027 *
1028 * This function allocates the IOCTL request buffer, fills it
1029 * with requisite parameters and calls the IOCTL handler.
1030 */
1031int
1032mwifiex_get_ver_ext(struct mwifiex_private *priv)
1033{
1034 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001036 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001037 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001038 HostCmd_ACT_GEN_GET, 0, &ver_ext))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001039 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001040
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001041 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001042}
1043
Stone Piao7feb4c42012-09-25 20:23:36 -07001044int
1045mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1046 struct ieee80211_channel *chan,
1047 enum nl80211_channel_type *ct,
1048 unsigned int duration)
1049{
1050 struct host_cmd_ds_remain_on_chan roc_cfg;
1051 u8 sc;
1052
1053 memset(&roc_cfg, 0, sizeof(roc_cfg));
1054 roc_cfg.action = cpu_to_le16(action);
1055 if (action == HostCmd_ACT_GEN_SET) {
1056 roc_cfg.band_cfg = chan->band;
1057 sc = mwifiex_chan_type_to_sec_chan_offset(*ct);
1058 roc_cfg.band_cfg |= (sc << 2);
1059
1060 roc_cfg.channel =
1061 ieee80211_frequency_to_channel(chan->center_freq);
1062 roc_cfg.duration = cpu_to_le32(duration);
1063 }
1064 if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1065 action, 0, &roc_cfg)) {
1066 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1067 return -1;
1068 }
1069
1070 return roc_cfg.status;
1071}
1072
Stone Piao9197ab92012-09-25 20:23:42 -07001073int
1074mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1075{
1076 if (GET_BSS_ROLE(priv) == bss_role) {
1077 dev_dbg(priv->adapter->dev,
1078 "info: already in the desired role.\n");
1079 return 0;
1080 }
1081
1082 mwifiex_free_priv(priv);
1083 mwifiex_init_priv(priv);
1084
1085 priv->bss_role = bss_role;
1086 switch (bss_role) {
1087 case MWIFIEX_BSS_ROLE_UAP:
1088 priv->bss_mode = NL80211_IFTYPE_AP;
1089 break;
1090 case MWIFIEX_BSS_ROLE_STA:
1091 case MWIFIEX_BSS_ROLE_ANY:
1092 default:
1093 priv->bss_mode = NL80211_IFTYPE_STATION;
1094 break;
1095 }
1096
1097 mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE,
1098 HostCmd_ACT_GEN_SET, 0, NULL);
1099
1100 return mwifiex_sta_init_cmd(priv, false);
1101}
1102
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103/*
1104 * Sends IOCTL request to get statistics information.
1105 *
1106 * This function allocates the IOCTL request buffer, fills it
1107 * with requisite parameters and calls the IOCTL handler.
1108 */
1109int
1110mwifiex_get_stats_info(struct mwifiex_private *priv,
1111 struct mwifiex_ds_get_stats *log)
1112{
Bing Zhao67a50032011-07-13 18:38:34 -07001113 return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001114 HostCmd_ACT_GEN_GET, 0, log);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001115}
1116
1117/*
1118 * IOCTL request handler to read/write register.
1119 *
1120 * This function prepares the correct firmware command and
1121 * issues it.
1122 *
1123 * Access to the following registers are supported -
1124 * - MAC
1125 * - BBP
1126 * - RF
1127 * - PMIC
1128 * - CAU
1129 */
1130static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001131 struct mwifiex_ds_reg_rw *reg_rw,
1132 u16 action)
1133{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001134 u16 cmd_no;
1135
1136 switch (le32_to_cpu(reg_rw->type)) {
1137 case MWIFIEX_REG_MAC:
1138 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1139 break;
1140 case MWIFIEX_REG_BBP:
1141 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1142 break;
1143 case MWIFIEX_REG_RF:
1144 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1145 break;
1146 case MWIFIEX_REG_PMIC:
1147 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1148 break;
1149 case MWIFIEX_REG_CAU:
1150 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1151 break;
1152 default:
1153 return -1;
1154 }
1155
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001156 return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001157
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001158}
1159
1160/*
1161 * Sends IOCTL request to write to a register.
1162 *
1163 * This function allocates the IOCTL request buffer, fills it
1164 * with requisite parameters and calls the IOCTL handler.
1165 */
1166int
1167mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1168 u32 reg_offset, u32 reg_value)
1169{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001170 struct mwifiex_ds_reg_rw reg_rw;
1171
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001172 reg_rw.type = cpu_to_le32(reg_type);
1173 reg_rw.offset = cpu_to_le32(reg_offset);
1174 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001175
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001176 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001177}
1178
1179/*
1180 * Sends IOCTL request to read from a register.
1181 *
1182 * This function allocates the IOCTL request buffer, fills it
1183 * with requisite parameters and calls the IOCTL handler.
1184 */
1185int
1186mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1187 u32 reg_offset, u32 *value)
1188{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001189 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001190 struct mwifiex_ds_reg_rw reg_rw;
1191
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001192 reg_rw.type = cpu_to_le32(reg_type);
1193 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001194 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001195
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196 if (ret)
1197 goto done;
1198
1199 *value = le32_to_cpu(reg_rw.value);
1200
1201done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 return ret;
1203}
1204
1205/*
1206 * Sends IOCTL request to read from EEPROM.
1207 *
1208 * This function allocates the IOCTL request buffer, fills it
1209 * with requisite parameters and calls the IOCTL handler.
1210 */
1211int
1212mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1213 u8 *value)
1214{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001215 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001216 struct mwifiex_ds_read_eeprom rd_eeprom;
1217
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001218 rd_eeprom.offset = cpu_to_le16((u16) offset);
1219 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001220
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001221 /* Send request to firmware */
1222 ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1223 HostCmd_ACT_GEN_GET, 0, &rd_eeprom);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001224
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001225 if (!ret)
1226 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001227 return ret;
1228}
1229
1230/*
1231 * This function sets a generic IE. In addition to generic IE, it can
1232 * also handle WPA, WPA2 and WAPI IEs.
1233 */
1234static int
1235mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1236 u16 ie_len)
1237{
1238 int ret = 0;
1239 struct ieee_types_vendor_header *pvendor_ie;
1240 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1241 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1242
1243 /* If the passed length is zero, reset the buffer */
1244 if (!ie_len) {
1245 priv->gen_ie_buf_len = 0;
1246 priv->wps.session_enable = false;
1247
1248 return 0;
1249 } else if (!ie_data_ptr) {
1250 return -1;
1251 }
1252 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1253 /* Test to see if it is a WPA IE, if not, then it is a gen IE */
Arend van Spriel04b23122012-10-12 12:28:14 +02001254 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001255 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1256 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257
1258 /* IE is a WPA/WPA2 IE so call set_wpa function */
1259 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1260 priv->wps.session_enable = false;
1261
1262 return ret;
1263 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1264 /* IE is a WAPI IE so call set_wapi function */
1265 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1266
1267 return ret;
1268 }
1269 /*
1270 * Verify that the passed length is not larger than the
1271 * available space remaining in the buffer
1272 */
1273 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1274
1275 /* Test to see if it is a WPS IE, if so, enable
1276 * wps session flag
1277 */
1278 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001279 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1280 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001281 priv->wps.session_enable = true;
1282 dev_dbg(priv->adapter->dev,
1283 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001284 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001285 }
1286
1287 /* Append the passed data to the end of the
1288 genIeBuffer */
1289 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001290 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001291 /* Increment the stored buffer length by the
1292 size passed */
1293 priv->gen_ie_buf_len += ie_len;
1294 } else {
1295 /* Passed data does not fit in the remaining
1296 buffer space */
1297 ret = -1;
1298 }
1299
1300 /* Return 0, or -1 for error case */
1301 return ret;
1302}
1303
1304/*
1305 * IOCTL request handler to set/get generic IE.
1306 *
1307 * In addition to various generic IEs, this function can also be
1308 * used to set the ARP filter.
1309 */
1310static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1311 struct mwifiex_ds_misc_gen_ie *gen_ie,
1312 u16 action)
1313{
1314 struct mwifiex_adapter *adapter = priv->adapter;
1315
1316 switch (gen_ie->type) {
1317 case MWIFIEX_IE_TYPE_GEN_IE:
1318 if (action == HostCmd_ACT_GEN_GET) {
1319 gen_ie->len = priv->wpa_ie_len;
1320 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1321 } else {
1322 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1323 (u16) gen_ie->len);
1324 }
1325 break;
1326 case MWIFIEX_IE_TYPE_ARP_FILTER:
1327 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1328 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1329 adapter->arp_filter_size = 0;
1330 dev_err(adapter->dev, "invalid ARP filter size\n");
1331 return -1;
1332 } else {
1333 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001334 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001335 adapter->arp_filter_size = gen_ie->len;
1336 }
1337 break;
1338 default:
1339 dev_err(adapter->dev, "invalid IE type\n");
1340 return -1;
1341 }
1342 return 0;
1343}
1344
1345/*
1346 * Sends IOCTL request to set a generic IE.
1347 *
1348 * This function allocates the IOCTL request buffer, fills it
1349 * with requisite parameters and calls the IOCTL handler.
1350 */
1351int
1352mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len)
1353{
1354 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001355
Bing Zhao67a50032011-07-13 18:38:34 -07001356 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001357 return -EFAULT;
1358
1359 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1360 gen_ie.len = ie_len;
1361 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001362 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001363 return -EFAULT;
1364
1365 return 0;
1366}