blob: 536c14aa71f39cb0e4f73417429fca55258af5ed [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 Karwar00d7ea12013-03-15 18:47:05 -070057int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
58 struct cmd_ctrl_node *cmd_queued)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059{
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080060 int status;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080061
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070062 /* Wait for completion */
Amitkumar Karwarf8d2b922014-04-14 15:31:06 -070063 status = wait_event_interruptible_timeout(adapter->cmd_wait_q.wait,
64 *(cmd_queued->condition),
65 (12 * HZ));
66 if (status <= 0) {
Bing Zhao9c969d82013-01-02 16:07:35 -080067 dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status);
Amitkumar Karwar3d026d02014-03-20 16:23:49 -070068 mwifiex_cancel_all_pending_cmd(adapter);
Bing Zhao9c969d82013-01-02 16:07:35 -080069 return status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070070 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080071
72 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070073 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070074
Bing Zhao5e6e3a92011-03-21 18:00:50 -070075 return status;
76}
77
78/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070079 * This function prepares the correct firmware command and
80 * issues it to set the multicast list.
81 *
82 * This function can be used to enable promiscuous mode, or enable all
83 * multicast packets, or to enable selective multicast.
84 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070085int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
86 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070087{
88 int ret = 0;
89 u16 old_pkt_filter;
90
91 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070092
93 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
94 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
95 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
96 priv->curr_pkt_filter &=
97 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
98 } else {
99 /* Multicast */
100 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
Daniel Drakeccd384b2013-05-08 15:37:19 -0400101 if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700102 dev_dbg(priv->adapter->dev,
103 "info: Enabling All Multicast!\n");
104 priv->curr_pkt_filter |=
105 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
106 } else {
107 priv->curr_pkt_filter &=
108 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
Daniel Drake6390d882013-06-14 15:24:24 -0400109 dev_dbg(priv->adapter->dev,
110 "info: Set multicast list=%d\n",
111 mcast_list->num_multicast_addr);
112 /* Send multicast addresses to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800113 ret = mwifiex_send_cmd(priv,
114 HostCmd_CMD_MAC_MULTICAST_ADR,
115 HostCmd_ACT_GEN_SET, 0,
116 mcast_list, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700117 }
118 }
119 dev_dbg(priv->adapter->dev,
120 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
121 old_pkt_filter, priv->curr_pkt_filter);
122 if (old_pkt_filter != priv->curr_pkt_filter) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800123 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
124 HostCmd_ACT_GEN_SET,
125 0, &priv->curr_pkt_filter, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126 }
127
128 return ret;
129}
130
131/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700132 * This function fills bss descriptor structure using provided
133 * information.
Bing Zhaod837a2a2013-04-12 10:34:17 -0700134 * beacon_ie buffer is allocated in this function. It is caller's
135 * responsibility to free the memory.
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700136 */
137int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700138 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700139 struct mwifiex_bssdescriptor *bss_desc)
140{
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700141 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500142 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700143 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100144 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700145
Johannes Berg9caf0362012-11-29 01:25:20 +0100146 rcu_read_lock();
147 ies = rcu_dereference(bss->ies);
Johannes Berg9caf0362012-11-29 01:25:20 +0100148 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
149 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100150 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100151 rcu_read_unlock();
152
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700153 if (!beacon_ie) {
154 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
155 return -ENOMEM;
156 }
157
158 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
159 bss_desc->rssi = bss->signal;
Bing Zhaod837a2a2013-04-12 10:34:17 -0700160 /* The caller of this function will free beacon_ie */
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700161 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100162 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700163 bss_desc->beacon_period = bss->beacon_interval;
164 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700165 bss_desc->bss_band = bss_priv->band;
166 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700167 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
168 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
169 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
170 } else {
171 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
172 }
173 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
174 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
175 else
176 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
177
Bing Zhaoc43933e2013-04-12 10:34:18 -0700178 /* Disable 11ac by default. Enable it only where there
179 * exist VHT_CAP IE in AP beacon
180 */
181 bss_desc->disable_11ac = true;
182
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700183 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
184 bss_desc->sensed_11h = true;
185
Bing Zhaod837a2a2013-04-12 10:34:17 -0700186 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700187}
188
Bing Zhaob58df442014-01-08 15:45:57 -0800189void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv)
190{
191 if (priv->adapter->dt_node) {
192 char txpwr[] = {"marvell,00_txpwrlimit"};
193
194 memcpy(&txpwr[8], priv->adapter->country_code, 2);
195 mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
196 }
197}
198
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700199static int mwifiex_process_country_ie(struct mwifiex_private *priv,
200 struct cfg80211_bss *bss)
201{
Johannes Berg9caf0362012-11-29 01:25:20 +0100202 const u8 *country_ie;
203 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700204 struct mwifiex_802_11d_domain_reg *domain_info =
205 &priv->adapter->domain_reg;
206
Johannes Berg9caf0362012-11-29 01:25:20 +0100207 rcu_read_lock();
208 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
209 if (!country_ie) {
210 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700211 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100212 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700213
214 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100215 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
216 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700217 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100218 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700219
Bing Zhaodd4a9ac2013-12-13 18:32:59 -0800220 if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
221 rcu_read_unlock();
222 wiphy_dbg(priv->wdev->wiphy,
223 "11D: skip setting domain info in FW\n");
224 return 0;
225 }
226 memcpy(priv->adapter->country_code, &country_ie[2], 2);
227
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700228 domain_info->country_code[0] = country_ie[2];
229 domain_info->country_code[1] = country_ie[3];
230 domain_info->country_code[2] = ' ';
231
232 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
233
234 domain_info->no_of_triplet =
235 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
236
237 memcpy((u8 *)domain_info->triplet,
238 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
239
Johannes Berg9caf0362012-11-29 01:25:20 +0100240 rcu_read_unlock();
241
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800242 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
243 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700244 wiphy_err(priv->adapter->wiphy,
245 "11D: setting domain info in FW\n");
246 return -1;
247 }
248
Bing Zhaob58df442014-01-08 15:45:57 -0800249 mwifiex_dnld_txpwr_table(priv);
Bing Zhao82efa162013-12-13 18:33:02 -0800250
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700251 return 0;
252}
253
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700254/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700255 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
256 * In both Ad-Hoc and infra mode, an deauthentication is performed
257 * first.
258 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700259int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800260 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700261{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700262 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700263 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700264 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700265
266 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700267
268 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700269 mwifiex_process_country_ie(priv, bss);
270
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700271 /* Allocate and fill new bss descriptor */
272 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000273 GFP_KERNEL);
274 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700275 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700276
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700277 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700278 if (ret)
279 goto done;
280 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700281
Stone Piao6621fe12013-07-29 16:32:39 -0700282 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
283 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700284 u8 config_bands;
285
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700286 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700287 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700288 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700289
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700290 if (!bss_desc)
291 return -1;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800292
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700293 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
294 HostCmd_SCAN_RADIO_TYPE_BG)
Bing Zhaof25b1432014-02-07 16:21:01 -0800295 config_bands = BAND_B | BAND_G | BAND_GN;
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700296 else
297 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800298
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700299 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
300 adapter->config_bands = config_bands;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800301
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700302 ret = mwifiex_check_network_compatibility(priv, bss_desc);
303 if (ret)
304 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700305
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700306 if (mwifiex_11h_get_csa_closed_channel(priv) ==
307 (u8)bss_desc->channel) {
308 dev_err(adapter->dev,
309 "Attempt to reconnect on csa closed chan(%d)\n",
310 bss_desc->channel);
311 goto done;
312 }
313
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700314 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
315 "associating...\n");
316
Avinash Patil47411a02012-11-01 18:44:16 -0700317 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800318 if (netif_carrier_ok(priv->netdev))
319 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700320
321 /* Clear any past association response stored for
322 * application retrieval */
323 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700324 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800325
326 /* If auth type is auto and association fails using open mode,
327 * try to connect using shared mode */
328 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
329 priv->sec_info.is_authtype_auto &&
330 priv->sec_info.wep_enabled) {
331 priv->sec_info.authentication_mode =
332 NL80211_AUTHTYPE_SHARED_KEY;
333 ret = mwifiex_associate(priv, bss_desc);
334 }
335
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700336 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100337 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700338 } else {
339 /* Adhoc mode */
340 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700341 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700342 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
343 ssid, &bss_desc->ssid))) {
Ujjal Roy517543f2013-11-21 11:08:56 -0800344 ret = 0;
345 goto done;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700346 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347
348 /* Exit Adhoc mode first */
349 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700350 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700351 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700352 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700353
354 priv->adhoc_is_link_sensed = false;
355
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700356 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700357
Avinash Patil47411a02012-11-01 18:44:16 -0700358 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800359 if (netif_carrier_ok(priv->netdev))
360 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700361
362 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700363 dev_dbg(adapter->dev, "info: network found in scan"
364 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700365 ret = mwifiex_adhoc_join(priv, bss_desc);
366 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100367 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700368 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700369 dev_dbg(adapter->dev, "info: Network not found in "
370 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700371 req_ssid->ssid);
372 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700373 }
374 }
375
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700376done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700377 /* beacon_ie buffer was allocated in function
378 * mwifiex_fill_new_bss_desc(). Free it now.
379 */
380 if (bss_desc)
381 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700382 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700383 return ret;
384}
385
386/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700387 * IOCTL request handler to set host sleep configuration.
388 *
389 * This function prepares the correct firmware command and
390 * issues it.
391 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700392static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
393 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700394
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700395{
396 struct mwifiex_adapter *adapter = priv->adapter;
397 int status = 0;
398 u32 prev_cond = 0;
399
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700400 if (!hs_cfg)
401 return -ENOMEM;
402
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700403 switch (action) {
404 case HostCmd_ACT_GEN_SET:
405 if (adapter->pps_uapsd_mode) {
406 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
407 " is blocked in UAPSD/PPS mode\n");
408 status = -1;
409 break;
410 }
411 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800412 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700413 if (!adapter->is_hs_configured)
414 /* Already cancelled */
415 break;
416 /* Save previous condition */
417 prev_cond = le32_to_cpu(adapter->hs_cfg
418 .conditions);
419 adapter->hs_cfg.conditions =
420 cpu_to_le32(hs_cfg->conditions);
421 } else if (hs_cfg->conditions) {
422 adapter->hs_cfg.conditions =
423 cpu_to_le32(hs_cfg->conditions);
424 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
425 if (hs_cfg->gap)
426 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800427 } else if (adapter->hs_cfg.conditions ==
428 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700429 /* Return failure if no parameters for HS
430 enable */
431 status = -1;
432 break;
433 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800434
435 status = mwifiex_send_cmd(priv,
436 HostCmd_CMD_802_11_HS_CFG_ENH,
437 HostCmd_ACT_GEN_SET, 0,
438 &adapter->hs_cfg,
439 cmd_type == MWIFIEX_SYNC_CMD);
440
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800441 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700442 /* Restore previous condition */
443 adapter->hs_cfg.conditions =
444 cpu_to_le32(prev_cond);
445 } else {
446 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700447 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700448 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
449 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
450 }
451 break;
452 case HostCmd_ACT_GEN_GET:
453 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
454 hs_cfg->gpio = adapter->hs_cfg.gpio;
455 hs_cfg->gap = adapter->hs_cfg.gap;
456 break;
457 default:
458 status = -1;
459 break;
460 }
461
462 return status;
463}
464
465/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700466 * Sends IOCTL request to cancel the existing Host Sleep configuration.
467 *
468 * This function allocates the IOCTL request buffer, fills it
469 * with requisite parameters and calls the IOCTL handler.
470 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700471int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700472{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473 struct mwifiex_ds_hs_cfg hscfg;
474
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800475 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700477
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700478 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
479 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700480}
481EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
482
483/*
484 * Sends IOCTL request to cancel the existing Host Sleep configuration.
485 *
486 * This function allocates the IOCTL request buffer, fills it
487 * with requisite parameters and calls the IOCTL handler.
488 */
489int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
490{
491 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700492 struct mwifiex_private *priv;
493 int i;
494
495 if (disconnect_on_suspend) {
496 for (i = 0; i < adapter->priv_num; i++) {
497 priv = adapter->priv[i];
498 if (priv)
499 mwifiex_deauthenticate(priv, NULL);
500 }
501 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700502
503 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900504 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700505 return true;
506 }
507
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700508 adapter->hs_activate_wait_q_woken = false;
509
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700510 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700511 hscfg.is_invoke_hostcmd = true;
512
Amitkumar Karwarc0dbba62014-03-25 19:01:20 -0700513 adapter->hs_enabling = true;
514 mwifiex_cancel_all_pending_cmd(adapter);
515
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700516 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700517 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700518 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
519 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700520 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
521 return false;
522 }
523
Amitkumar Karwar52250cb2014-03-20 16:23:50 -0700524 if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
525 adapter->hs_activate_wait_q_woken,
526 (10 * HZ)) <= 0) {
Bing Zhao9c969d82013-01-02 16:07:35 -0800527 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
528 return false;
529 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700530
531 return true;
532}
533EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
534
535/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700536 * IOCTL request handler to get BSS information.
537 *
538 * This function collates the information from different driver structures
539 * to send to the user.
540 */
541int mwifiex_get_bss_info(struct mwifiex_private *priv,
542 struct mwifiex_bss_info *info)
543{
544 struct mwifiex_adapter *adapter = priv->adapter;
545 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700546
547 if (!info)
548 return -1;
549
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700550 bss_desc = &priv->curr_bss_params.bss_descriptor;
551
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700552 info->bss_mode = priv->bss_mode;
553
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800554 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700556 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
557
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700558 info->bss_chan = bss_desc->channel;
559
Avinash Patil67fdf392012-05-08 18:30:17 -0700560 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700561 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 info->media_connected = priv->media_connected;
564
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 info->max_power_level = priv->max_tx_power_level;
566 info->min_power_level = priv->min_tx_power_level;
567
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700568 info->adhoc_state = priv->adhoc_state;
569
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700570 info->bcn_nf_last = priv->bcn_nf_last;
571
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800572 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700573 info->wep_status = true;
574 else
575 info->wep_status = false;
576
577 info->is_hs_configured = adapter->is_hs_configured;
578 info->is_deep_sleep = adapter->is_deep_sleep;
579
580 return 0;
581}
582
583/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700584 * The function disables auto deep sleep mode.
585 */
586int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
587{
588 struct mwifiex_ds_auto_ds auto_ds;
589
590 auto_ds.auto_ds = DEEP_SLEEP_OFF;
591
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800592 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
593 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
Amitkumar Karwara0490932011-07-13 20:51:59 -0700594}
595EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
596
597/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700598 * Sends IOCTL request to get the data rate.
599 *
600 * This function allocates the IOCTL request buffer, fills it
601 * with requisite parameters and calls the IOCTL handler.
602 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700603int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700604{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700605 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700606
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800607 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
608 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700609
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700610 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700611 if (priv->is_data_rate_auto)
612 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
613 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300614 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700615 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700616 }
617
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700618 return ret;
619}
620
621/*
622 * IOCTL request handler to set tx power configuration.
623 *
624 * This function prepares the correct firmware command and
625 * issues it.
626 *
627 * For non-auto power mode, all the following power groups are set -
628 * - Modulation class HR/DSSS
629 * - Modulation class OFDM
630 * - Modulation class HTBW20
631 * - Modulation class HTBW40
632 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700633int mwifiex_set_tx_power(struct mwifiex_private *priv,
634 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700635{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700636 int ret;
637 struct host_cmd_ds_txpwr_cfg *txp_cfg;
638 struct mwifiex_types_power_group *pg_tlv;
639 struct mwifiex_power_group *pg;
640 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700641 u16 dbm = 0;
642
643 if (!power_cfg->is_power_auto) {
644 dbm = (u16) power_cfg->power_level;
645 if ((dbm < priv->min_tx_power_level) ||
646 (dbm > priv->max_tx_power_level)) {
647 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700648 " is out of range (%d dBm-%d dBm)\n",
649 dbm, priv->min_tx_power_level,
650 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700651 return -1;
652 }
653 }
654 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000655 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200656 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700657
658 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
659 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
660 if (!power_cfg->is_power_auto) {
661 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700662 pg_tlv = (struct mwifiex_types_power_group *)
663 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700664 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
665 pg_tlv->length =
666 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700667 pg = (struct mwifiex_power_group *)
668 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
669 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700670 /* Power group for modulation class HR/DSSS */
671 pg->first_rate_code = 0x00;
672 pg->last_rate_code = 0x03;
673 pg->modulation_class = MOD_CLASS_HR_DSSS;
674 pg->power_step = 0;
675 pg->power_min = (s8) dbm;
676 pg->power_max = (s8) dbm;
677 pg++;
678 /* Power group for modulation class OFDM */
679 pg->first_rate_code = 0x00;
680 pg->last_rate_code = 0x07;
681 pg->modulation_class = MOD_CLASS_OFDM;
682 pg->power_step = 0;
683 pg->power_min = (s8) dbm;
684 pg->power_max = (s8) dbm;
685 pg++;
686 /* Power group for modulation class HTBW20 */
687 pg->first_rate_code = 0x00;
688 pg->last_rate_code = 0x20;
689 pg->modulation_class = MOD_CLASS_HT;
690 pg->power_step = 0;
691 pg->power_min = (s8) dbm;
692 pg->power_max = (s8) dbm;
693 pg->ht_bandwidth = HT_BW_20;
694 pg++;
695 /* Power group for modulation class HTBW40 */
696 pg->first_rate_code = 0x00;
697 pg->last_rate_code = 0x20;
698 pg->modulation_class = MOD_CLASS_HT;
699 pg->power_step = 0;
700 pg->power_min = (s8) dbm;
701 pg->power_max = (s8) dbm;
702 pg->ht_bandwidth = HT_BW_40;
703 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800704 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
705 HostCmd_ACT_GEN_SET, 0, buf, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700706
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700707 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700708 return ret;
709}
710
711/*
712 * IOCTL request handler to get power save mode.
713 *
714 * This function prepares the correct firmware command and
715 * issues it.
716 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700717int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700718{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700719 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700720 struct mwifiex_adapter *adapter = priv->adapter;
721 u16 sub_cmd;
722
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700723 if (*ps_mode)
724 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
725 else
726 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
727 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800728 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
729 sub_cmd, BITMAP_STA_PS, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700730 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800731 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
732 GET_PS, 0, NULL, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700733
734 return ret;
735}
736
737/*
738 * IOCTL request handler to set/reset WPA IE.
739 *
740 * The supplied WPA IE is treated as a opaque buffer. Only the first field
741 * is checked to determine WPA version. If buffer length is zero, the existing
742 * WPA IE is reset.
743 */
744static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
745 u8 *ie_data_ptr, u16 ie_len)
746{
747 if (ie_len) {
748 if (ie_len > sizeof(priv->wpa_ie)) {
749 dev_err(priv->adapter->dev,
750 "failed to copy WPA IE, too big\n");
751 return -1;
752 }
753 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
754 priv->wpa_ie_len = (u8) ie_len;
755 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700756 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700757
Arend van Spriel04b23122012-10-12 12:28:14 +0200758 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700759 priv->sec_info.wpa_enabled = true;
760 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
761 priv->sec_info.wpa2_enabled = true;
762 } else {
763 priv->sec_info.wpa_enabled = false;
764 priv->sec_info.wpa2_enabled = false;
765 }
766 } else {
767 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
768 priv->wpa_ie_len = 0;
769 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
770 priv->wpa_ie_len, priv->wpa_ie[0]);
771 priv->sec_info.wpa_enabled = false;
772 priv->sec_info.wpa2_enabled = false;
773 }
774
775 return 0;
776}
777
778/*
779 * IOCTL request handler to set/reset WAPI IE.
780 *
781 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
782 * is checked to internally enable WAPI. If buffer length is zero, the existing
783 * WAPI IE is reset.
784 */
785static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
786 u8 *ie_data_ptr, u16 ie_len)
787{
788 if (ie_len) {
789 if (ie_len > sizeof(priv->wapi_ie)) {
790 dev_dbg(priv->adapter->dev,
791 "info: failed to copy WAPI IE, too big\n");
792 return -1;
793 }
794 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
795 priv->wapi_ie_len = ie_len;
796 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700797 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700798
799 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
800 priv->sec_info.wapi_enabled = true;
801 } else {
802 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
803 priv->wapi_ie_len = ie_len;
804 dev_dbg(priv->adapter->dev,
805 "info: Reset wapi_ie_len=%d IE=%#x\n",
806 priv->wapi_ie_len, priv->wapi_ie[0]);
807 priv->sec_info.wapi_enabled = false;
808 }
809 return 0;
810}
811
812/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700813 * IOCTL request handler to set/reset WPS IE.
814 *
815 * The supplied WPS IE is treated as a opaque buffer. Only the first field
816 * is checked to internally enable WPS. If buffer length is zero, the existing
817 * WPS IE is reset.
818 */
819static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
820 u8 *ie_data_ptr, u16 ie_len)
821{
822 if (ie_len) {
Avinash Patil8795ca62013-07-22 19:17:46 -0700823 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
824 dev_dbg(priv->adapter->dev,
825 "info: failed to copy WPS IE, too big\n");
826 return -1;
827 }
828
Avinash Patil13d7ba782012-04-09 20:06:56 -0700829 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
830 if (!priv->wps_ie)
831 return -ENOMEM;
Avinash Patil8795ca62013-07-22 19:17:46 -0700832
Avinash Patil13d7ba782012-04-09 20:06:56 -0700833 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
834 priv->wps_ie_len = ie_len;
835 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
836 priv->wps_ie_len, priv->wps_ie[0]);
837 } else {
838 kfree(priv->wps_ie);
839 priv->wps_ie_len = ie_len;
840 dev_dbg(priv->adapter->dev,
841 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
842 }
843 return 0;
844}
845
846/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700847 * IOCTL request handler to set WAPI key.
848 *
849 * This function prepares the correct firmware command and
850 * issues it.
851 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700852static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700853 struct mwifiex_ds_encrypt_key *encrypt_key)
854{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700855
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800856 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
857 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
858 encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700859}
860
861/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700862 * IOCTL request handler to set WEP network key.
863 *
864 * This function prepares the correct firmware command and
865 * issues it, after validation checks.
866 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700867static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700868 struct mwifiex_ds_encrypt_key *encrypt_key)
869{
Avinash Patile57f1732014-02-07 16:32:35 -0800870 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700871 int ret;
872 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700873 int index;
874
875 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
876 priv->wep_key_curr_index = 0;
877 wep_key = &priv->wep_key[priv->wep_key_curr_index];
878 index = encrypt_key->key_index;
879 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800880 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700881 } else if (!encrypt_key->key_len) {
882 /* Copy the required key as the current key */
883 wep_key = &priv->wep_key[index];
884 if (!wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800885 dev_err(adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700886 "key not set, so cannot enable it\n");
887 return -1;
888 }
Avinash Patile57f1732014-02-07 16:32:35 -0800889
890 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2) {
891 memcpy(encrypt_key->key_material,
892 wep_key->key_material, wep_key->key_length);
893 encrypt_key->key_len = wep_key->key_length;
894 }
895
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700896 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800897 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898 } else {
899 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700900 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
901 /* Copy the key in the driver */
902 memcpy(wep_key->key_material,
903 encrypt_key->key_material,
904 encrypt_key->key_len);
905 wep_key->key_index = index;
906 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800907 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700908 }
909 if (wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800910 void *enc_key;
911
912 if (encrypt_key->key_disable)
913 memset(&priv->wep_key[index], 0,
914 sizeof(struct mwifiex_wep_key));
915
916 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2)
917 enc_key = encrypt_key;
918 else
919 enc_key = NULL;
920
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700921 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800922 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
923 HostCmd_ACT_GEN_SET, 0, enc_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700924 if (ret)
925 return ret;
926 }
Avinash Patile57f1732014-02-07 16:32:35 -0800927
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800928 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700929 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
930 else
931 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
932
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800933 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
934 HostCmd_ACT_GEN_SET, 0,
935 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700936
937 return ret;
938}
939
940/*
941 * IOCTL request handler to set WPA key.
942 *
943 * This function prepares the correct firmware command and
944 * issues it, after validation checks.
945 *
946 * Current driver only supports key length of up to 32 bytes.
947 *
948 * This function can also be used to disable a currently set key.
949 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700950static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700951 struct mwifiex_ds_encrypt_key *encrypt_key)
952{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700953 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700954 u8 remove_key = false;
955 struct host_cmd_ds_802_11_key_material *ibss_key;
956
957 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700958 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700959 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700960 return -1;
961 }
962
Bing Zhaoeecd8252011-03-28 17:55:41 -0700963 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700964 /*
965 * IBSS/WPA-None uses only one key (Group) for both receiving
966 * and sending unicast and multicast packets.
967 */
968 /* Send the key as PTK to firmware */
969 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800970 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
971 HostCmd_ACT_GEN_SET,
972 KEY_INFO_ENABLED, encrypt_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700973 if (ret)
974 return ret;
975
976 ibss_key = &priv->aes_key;
977 memset(ibss_key, 0,
978 sizeof(struct host_cmd_ds_802_11_key_material));
979 /* Copy the key in the driver */
980 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
981 encrypt_key->key_len);
982 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
983 sizeof(ibss_key->key_param_set.key_len));
984 ibss_key->key_param_set.key_type_id
985 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700986 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700987
988 /* Send the key as GTK to firmware */
989 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
990 }
991
992 if (!encrypt_key->key_index)
993 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
994
995 if (remove_key)
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800996 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
997 HostCmd_ACT_GEN_SET,
998 !KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700999 else
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001000 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1001 HostCmd_ACT_GEN_SET,
1002 KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001003
1004 return ret;
1005}
1006
1007/*
1008 * IOCTL request handler to set/get network keys.
1009 *
1010 * This is a generic key handling function which supports WEP, WPA
1011 * and WAPI.
1012 */
1013static int
1014mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015 struct mwifiex_ds_encrypt_key *encrypt_key)
1016{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001017 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001018
1019 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001020 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001021 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001022 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001023 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001024 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001025 return status;
1026}
1027
1028/*
1029 * This function returns the driver version.
1030 */
1031int
1032mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1033 int max_len)
1034{
1035 union {
1036 u32 l;
1037 u8 c[4];
1038 } ver;
1039 char fw_ver[32];
1040
1041 ver.l = adapter->fw_release_number;
1042 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1043
1044 snprintf(version, max_len, driver_version, fw_ver);
1045
1046 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1047
1048 return 0;
1049}
1050
1051/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001052 * Sends IOCTL request to set encoding parameters.
1053 *
1054 * This function allocates the IOCTL request buffer, fills it
1055 * with requisite parameters and calls the IOCTL handler.
1056 */
Ying Luo53b11232012-08-03 18:06:13 -07001057int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1058 const u8 *key, int key_len, u8 key_index,
1059 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001060{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001061 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001062
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001063 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1064 encrypt_key.key_len = key_len;
Avinash Patile57f1732014-02-07 16:32:35 -08001065 encrypt_key.key_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -07001066
1067 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1068 encrypt_key.is_igtk_key = true;
1069
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001070 if (!disable) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001071 if (key_len)
1072 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001073 else
1074 encrypt_key.is_current_wep_key = true;
1075
Avinash Patil75edd2c2012-05-08 18:30:18 -07001076 if (mac_addr)
1077 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Avinash Patile57f1732014-02-07 16:32:35 -08001078 if (kp && kp->seq && kp->seq_len) {
Ying Luo53b11232012-08-03 18:06:13 -07001079 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001080 encrypt_key.pn_len = kp->seq_len;
1081 encrypt_key.is_rx_seq_valid = true;
1082 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001083 } else {
Avinash Patile57f1732014-02-07 16:32:35 -08001084 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
1085 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001086 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001087 if (mac_addr)
1088 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001089 }
1090
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001091 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001092}
1093
1094/*
1095 * Sends IOCTL request to get extended version.
1096 *
1097 * This function allocates the IOCTL request buffer, fills it
1098 * with requisite parameters and calls the IOCTL handler.
1099 */
1100int
1101mwifiex_get_ver_ext(struct mwifiex_private *priv)
1102{
1103 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001104
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001105 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001106 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1107 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001108 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001109
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001110 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001111}
1112
Stone Piao7feb4c42012-09-25 20:23:36 -07001113int
1114mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1115 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001116 unsigned int duration)
1117{
1118 struct host_cmd_ds_remain_on_chan roc_cfg;
1119 u8 sc;
1120
1121 memset(&roc_cfg, 0, sizeof(roc_cfg));
1122 roc_cfg.action = cpu_to_le16(action);
1123 if (action == HostCmd_ACT_GEN_SET) {
1124 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001125 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001126 roc_cfg.band_cfg |= (sc << 2);
1127
1128 roc_cfg.channel =
1129 ieee80211_frequency_to_channel(chan->center_freq);
1130 roc_cfg.duration = cpu_to_le32(duration);
1131 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001132 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1133 action, 0, &roc_cfg, true)) {
Stone Piao7feb4c42012-09-25 20:23:36 -07001134 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1135 return -1;
1136 }
1137
1138 return roc_cfg.status;
1139}
1140
Stone Piao9197ab92012-09-25 20:23:42 -07001141int
1142mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1143{
1144 if (GET_BSS_ROLE(priv) == bss_role) {
1145 dev_dbg(priv->adapter->dev,
1146 "info: already in the desired role.\n");
1147 return 0;
1148 }
1149
1150 mwifiex_free_priv(priv);
1151 mwifiex_init_priv(priv);
1152
1153 priv->bss_role = bss_role;
1154 switch (bss_role) {
1155 case MWIFIEX_BSS_ROLE_UAP:
1156 priv->bss_mode = NL80211_IFTYPE_AP;
1157 break;
1158 case MWIFIEX_BSS_ROLE_STA:
1159 case MWIFIEX_BSS_ROLE_ANY:
1160 default:
1161 priv->bss_mode = NL80211_IFTYPE_STATION;
1162 break;
1163 }
1164
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001165 mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1166 HostCmd_ACT_GEN_SET, 0, NULL, true);
Stone Piao9197ab92012-09-25 20:23:42 -07001167
1168 return mwifiex_sta_init_cmd(priv, false);
1169}
1170
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001171/*
1172 * Sends IOCTL request to get statistics information.
1173 *
1174 * This function allocates the IOCTL request buffer, fills it
1175 * with requisite parameters and calls the IOCTL handler.
1176 */
1177int
1178mwifiex_get_stats_info(struct mwifiex_private *priv,
1179 struct mwifiex_ds_get_stats *log)
1180{
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001181 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1182 HostCmd_ACT_GEN_GET, 0, log, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001183}
1184
1185/*
1186 * IOCTL request handler to read/write register.
1187 *
1188 * This function prepares the correct firmware command and
1189 * issues it.
1190 *
1191 * Access to the following registers are supported -
1192 * - MAC
1193 * - BBP
1194 * - RF
1195 * - PMIC
1196 * - CAU
1197 */
1198static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199 struct mwifiex_ds_reg_rw *reg_rw,
1200 u16 action)
1201{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001202 u16 cmd_no;
1203
1204 switch (le32_to_cpu(reg_rw->type)) {
1205 case MWIFIEX_REG_MAC:
1206 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1207 break;
1208 case MWIFIEX_REG_BBP:
1209 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1210 break;
1211 case MWIFIEX_REG_RF:
1212 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1213 break;
1214 case MWIFIEX_REG_PMIC:
1215 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1216 break;
1217 case MWIFIEX_REG_CAU:
1218 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1219 break;
1220 default:
1221 return -1;
1222 }
1223
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001224 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001225}
1226
1227/*
1228 * Sends IOCTL request to write to a register.
1229 *
1230 * This function allocates the IOCTL request buffer, fills it
1231 * with requisite parameters and calls the IOCTL handler.
1232 */
1233int
1234mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1235 u32 reg_offset, u32 reg_value)
1236{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001237 struct mwifiex_ds_reg_rw reg_rw;
1238
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239 reg_rw.type = cpu_to_le32(reg_type);
1240 reg_rw.offset = cpu_to_le32(reg_offset);
1241 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001242
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001243 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001244}
1245
1246/*
1247 * Sends IOCTL request to read from a register.
1248 *
1249 * This function allocates the IOCTL request buffer, fills it
1250 * with requisite parameters and calls the IOCTL handler.
1251 */
1252int
1253mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1254 u32 reg_offset, u32 *value)
1255{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001256 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 struct mwifiex_ds_reg_rw reg_rw;
1258
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001259 reg_rw.type = cpu_to_le32(reg_type);
1260 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001261 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001262
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001263 if (ret)
1264 goto done;
1265
1266 *value = le32_to_cpu(reg_rw.value);
1267
1268done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001269 return ret;
1270}
1271
1272/*
1273 * Sends IOCTL request to read from EEPROM.
1274 *
1275 * This function allocates the IOCTL request buffer, fills it
1276 * with requisite parameters and calls the IOCTL handler.
1277 */
1278int
1279mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1280 u8 *value)
1281{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001282 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001283 struct mwifiex_ds_read_eeprom rd_eeprom;
1284
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001285 rd_eeprom.offset = cpu_to_le16((u16) offset);
1286 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001287
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001288 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001289 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1290 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001291
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001292 if (!ret)
1293 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001294 return ret;
1295}
1296
1297/*
1298 * This function sets a generic IE. In addition to generic IE, it can
1299 * also handle WPA, WPA2 and WAPI IEs.
1300 */
1301static int
1302mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1303 u16 ie_len)
1304{
1305 int ret = 0;
1306 struct ieee_types_vendor_header *pvendor_ie;
1307 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1308 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1309
1310 /* If the passed length is zero, reset the buffer */
1311 if (!ie_len) {
1312 priv->gen_ie_buf_len = 0;
1313 priv->wps.session_enable = false;
1314
1315 return 0;
1316 } else if (!ie_data_ptr) {
1317 return -1;
1318 }
1319 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1320 /* 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 +02001321 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001322 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1323 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001324
1325 /* IE is a WPA/WPA2 IE so call set_wpa function */
1326 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1327 priv->wps.session_enable = false;
1328
1329 return ret;
1330 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1331 /* IE is a WAPI IE so call set_wapi function */
1332 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1333
1334 return ret;
1335 }
1336 /*
1337 * Verify that the passed length is not larger than the
1338 * available space remaining in the buffer
1339 */
1340 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1341
1342 /* Test to see if it is a WPS IE, if so, enable
1343 * wps session flag
1344 */
1345 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001346 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1347 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001348 priv->wps.session_enable = true;
1349 dev_dbg(priv->adapter->dev,
1350 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001351 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001352 }
1353
1354 /* Append the passed data to the end of the
1355 genIeBuffer */
1356 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001357 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001358 /* Increment the stored buffer length by the
1359 size passed */
1360 priv->gen_ie_buf_len += ie_len;
1361 } else {
1362 /* Passed data does not fit in the remaining
1363 buffer space */
1364 ret = -1;
1365 }
1366
1367 /* Return 0, or -1 for error case */
1368 return ret;
1369}
1370
1371/*
1372 * IOCTL request handler to set/get generic IE.
1373 *
1374 * In addition to various generic IEs, this function can also be
1375 * used to set the ARP filter.
1376 */
1377static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1378 struct mwifiex_ds_misc_gen_ie *gen_ie,
1379 u16 action)
1380{
1381 struct mwifiex_adapter *adapter = priv->adapter;
1382
1383 switch (gen_ie->type) {
1384 case MWIFIEX_IE_TYPE_GEN_IE:
1385 if (action == HostCmd_ACT_GEN_GET) {
1386 gen_ie->len = priv->wpa_ie_len;
1387 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1388 } else {
1389 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1390 (u16) gen_ie->len);
1391 }
1392 break;
1393 case MWIFIEX_IE_TYPE_ARP_FILTER:
1394 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1395 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1396 adapter->arp_filter_size = 0;
1397 dev_err(adapter->dev, "invalid ARP filter size\n");
1398 return -1;
1399 } else {
1400 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001401 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001402 adapter->arp_filter_size = gen_ie->len;
1403 }
1404 break;
1405 default:
1406 dev_err(adapter->dev, "invalid IE type\n");
1407 return -1;
1408 }
1409 return 0;
1410}
1411
1412/*
1413 * Sends IOCTL request to set a generic IE.
1414 *
1415 * This function allocates the IOCTL request buffer, fills it
1416 * with requisite parameters and calls the IOCTL handler.
1417 */
1418int
Johannes Berg4b5800f2014-01-15 14:55:59 +01001419mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420{
1421 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001422
Bing Zhao67a50032011-07-13 18:38:34 -07001423 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001424 return -EFAULT;
1425
1426 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1427 gen_ie.len = ie_len;
1428 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001429 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001430 return -EFAULT;
1431
1432 return 0;
1433}