blob: 1626868a4b5ce7935af22b31c8e506f1db923d06 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: functions for station ioctl
3 *
Xinming Hu65da33f2014-06-19 21:38:57 -07004 * Copyright (C) 2011-2014, Marvell International Ltd.
Bing Zhao5e6e3a92011-03-21 18:00:50 -07005 *
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
Bing Zhaoef0a68a2014-06-06 19:47:44 -070029static int disconnect_on_suspend;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -070030module_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 Karwarf2bbb072013-06-18 16:36:56 -0700286 if (!bss_desc)
287 return -1;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800288
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700289 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
Xinming Hua659c432014-09-12 20:08:50 +0530290 HostCmd_SCAN_RADIO_TYPE_BG) {
Bing Zhaof25b1432014-02-07 16:21:01 -0800291 config_bands = BAND_B | BAND_G | BAND_GN;
Xinming Hua659c432014-09-12 20:08:50 +0530292 } else {
293 config_bands = BAND_A | BAND_AN;
294 if (adapter->fw_bands & BAND_AAC)
295 config_bands |= BAND_AAC;
296 }
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800297
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700298 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
299 adapter->config_bands = config_bands;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800300
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700301 ret = mwifiex_check_network_compatibility(priv, bss_desc);
302 if (ret)
303 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700304
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700305 if (mwifiex_11h_get_csa_closed_channel(priv) ==
306 (u8)bss_desc->channel) {
307 dev_err(adapter->dev,
308 "Attempt to reconnect on csa closed chan(%d)\n",
309 bss_desc->channel);
310 goto done;
311 }
312
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700313 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
314 "associating...\n");
315
Avinash Patil47411a02012-11-01 18:44:16 -0700316 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800317 if (netif_carrier_ok(priv->netdev))
318 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700319
320 /* Clear any past association response stored for
321 * application retrieval */
322 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700323 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800324
325 /* If auth type is auto and association fails using open mode,
326 * try to connect using shared mode */
327 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
328 priv->sec_info.is_authtype_auto &&
329 priv->sec_info.wep_enabled) {
330 priv->sec_info.authentication_mode =
331 NL80211_AUTHTYPE_SHARED_KEY;
332 ret = mwifiex_associate(priv, bss_desc);
333 }
334
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700335 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100336 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700337 } else {
338 /* Adhoc mode */
339 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700340 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700341 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
342 ssid, &bss_desc->ssid))) {
Ujjal Roy517543f2013-11-21 11:08:56 -0800343 ret = 0;
344 goto done;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700345 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700346
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700347 priv->adhoc_is_link_sensed = false;
348
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700349 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700350
Avinash Patil47411a02012-11-01 18:44:16 -0700351 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800352 if (netif_carrier_ok(priv->netdev))
353 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700354
355 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700356 dev_dbg(adapter->dev, "info: network found in scan"
357 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700358 ret = mwifiex_adhoc_join(priv, bss_desc);
359 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100360 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700361 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 dev_dbg(adapter->dev, "info: Network not found in "
363 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700364 req_ssid->ssid);
365 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700366 }
367 }
368
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700369done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700370 /* beacon_ie buffer was allocated in function
371 * mwifiex_fill_new_bss_desc(). Free it now.
372 */
373 if (bss_desc)
374 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700375 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 return ret;
377}
378
379/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700380 * IOCTL request handler to set host sleep configuration.
381 *
382 * This function prepares the correct firmware command and
383 * issues it.
384 */
Xinming Hu937a5042014-06-19 21:38:56 -0700385int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
386 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700387
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700388{
389 struct mwifiex_adapter *adapter = priv->adapter;
390 int status = 0;
391 u32 prev_cond = 0;
392
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700393 if (!hs_cfg)
394 return -ENOMEM;
395
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700396 switch (action) {
397 case HostCmd_ACT_GEN_SET:
398 if (adapter->pps_uapsd_mode) {
399 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
400 " is blocked in UAPSD/PPS mode\n");
401 status = -1;
402 break;
403 }
404 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800405 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700406 if (!adapter->is_hs_configured)
407 /* Already cancelled */
408 break;
409 /* Save previous condition */
410 prev_cond = le32_to_cpu(adapter->hs_cfg
411 .conditions);
412 adapter->hs_cfg.conditions =
413 cpu_to_le32(hs_cfg->conditions);
414 } else if (hs_cfg->conditions) {
415 adapter->hs_cfg.conditions =
416 cpu_to_le32(hs_cfg->conditions);
417 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
418 if (hs_cfg->gap)
419 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800420 } else if (adapter->hs_cfg.conditions ==
421 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700422 /* Return failure if no parameters for HS
423 enable */
424 status = -1;
425 break;
426 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800427
428 status = mwifiex_send_cmd(priv,
429 HostCmd_CMD_802_11_HS_CFG_ENH,
430 HostCmd_ACT_GEN_SET, 0,
431 &adapter->hs_cfg,
432 cmd_type == MWIFIEX_SYNC_CMD);
433
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800434 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700435 /* Restore previous condition */
436 adapter->hs_cfg.conditions =
437 cpu_to_le32(prev_cond);
438 } else {
439 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700440 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700441 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
442 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
443 }
444 break;
445 case HostCmd_ACT_GEN_GET:
446 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
447 hs_cfg->gpio = adapter->hs_cfg.gpio;
448 hs_cfg->gap = adapter->hs_cfg.gap;
449 break;
450 default:
451 status = -1;
452 break;
453 }
454
455 return status;
456}
457
458/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700459 * Sends IOCTL request to cancel the existing Host Sleep configuration.
460 *
461 * This function allocates the IOCTL request buffer, fills it
462 * with requisite parameters and calls the IOCTL handler.
463 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700464int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700465{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700466 struct mwifiex_ds_hs_cfg hscfg;
467
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800468 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700469 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700471 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
472 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700473}
474EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
475
476/*
477 * Sends IOCTL request to cancel the existing Host Sleep configuration.
478 *
479 * This function allocates the IOCTL request buffer, fills it
480 * with requisite parameters and calls the IOCTL handler.
481 */
482int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
483{
484 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700485 struct mwifiex_private *priv;
486 int i;
487
488 if (disconnect_on_suspend) {
489 for (i = 0; i < adapter->priv_num; i++) {
490 priv = adapter->priv[i];
491 if (priv)
492 mwifiex_deauthenticate(priv, NULL);
493 }
494 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700495
496 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900497 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700498 return true;
499 }
500
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700501 adapter->hs_activate_wait_q_woken = false;
502
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700503 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700504 hscfg.is_invoke_hostcmd = true;
505
Amitkumar Karwarc0dbba62014-03-25 19:01:20 -0700506 adapter->hs_enabling = true;
507 mwifiex_cancel_all_pending_cmd(adapter);
508
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700509 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700510 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700511 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
512 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700513 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
514 return false;
515 }
516
Amitkumar Karwar52250cb2014-03-20 16:23:50 -0700517 if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
518 adapter->hs_activate_wait_q_woken,
519 (10 * HZ)) <= 0) {
Bing Zhao9c969d82013-01-02 16:07:35 -0800520 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
521 return false;
522 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700523
524 return true;
525}
526EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
527
528/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700529 * IOCTL request handler to get BSS information.
530 *
531 * This function collates the information from different driver structures
532 * to send to the user.
533 */
534int mwifiex_get_bss_info(struct mwifiex_private *priv,
535 struct mwifiex_bss_info *info)
536{
537 struct mwifiex_adapter *adapter = priv->adapter;
538 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700539
540 if (!info)
541 return -1;
542
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543 bss_desc = &priv->curr_bss_params.bss_descriptor;
544
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700545 info->bss_mode = priv->bss_mode;
546
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800547 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
550
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700551 info->bss_chan = bss_desc->channel;
552
Avinash Patil67fdf392012-05-08 18:30:17 -0700553 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700554 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700556 info->media_connected = priv->media_connected;
557
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700558 info->max_power_level = priv->max_tx_power_level;
559 info->min_power_level = priv->min_tx_power_level;
560
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700561 info->adhoc_state = priv->adhoc_state;
562
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 info->bcn_nf_last = priv->bcn_nf_last;
564
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800565 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700566 info->wep_status = true;
567 else
568 info->wep_status = false;
569
570 info->is_hs_configured = adapter->is_hs_configured;
571 info->is_deep_sleep = adapter->is_deep_sleep;
572
573 return 0;
574}
575
576/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700577 * The function disables auto deep sleep mode.
578 */
579int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
580{
581 struct mwifiex_ds_auto_ds auto_ds;
582
583 auto_ds.auto_ds = DEEP_SLEEP_OFF;
584
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800585 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
586 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
Amitkumar Karwara0490932011-07-13 20:51:59 -0700587}
588EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
589
590/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700591 * Sends IOCTL request to get the data rate.
592 *
593 * This function allocates the IOCTL request buffer, fills it
594 * with requisite parameters and calls the IOCTL handler.
595 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700596int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700597{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700598 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700599
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800600 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
601 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700604 if (priv->is_data_rate_auto)
605 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
606 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300607 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700608 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700609 }
610
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700611 return ret;
612}
613
614/*
615 * IOCTL request handler to set tx power configuration.
616 *
617 * This function prepares the correct firmware command and
618 * issues it.
619 *
620 * For non-auto power mode, all the following power groups are set -
621 * - Modulation class HR/DSSS
622 * - Modulation class OFDM
623 * - Modulation class HTBW20
624 * - Modulation class HTBW40
625 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700626int mwifiex_set_tx_power(struct mwifiex_private *priv,
627 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700628{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700629 int ret;
630 struct host_cmd_ds_txpwr_cfg *txp_cfg;
631 struct mwifiex_types_power_group *pg_tlv;
632 struct mwifiex_power_group *pg;
633 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700634 u16 dbm = 0;
635
636 if (!power_cfg->is_power_auto) {
637 dbm = (u16) power_cfg->power_level;
638 if ((dbm < priv->min_tx_power_level) ||
639 (dbm > priv->max_tx_power_level)) {
640 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700641 " is out of range (%d dBm-%d dBm)\n",
642 dbm, priv->min_tx_power_level,
643 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700644 return -1;
645 }
646 }
647 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000648 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200649 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700650
651 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
652 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
653 if (!power_cfg->is_power_auto) {
654 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700655 pg_tlv = (struct mwifiex_types_power_group *)
656 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700657 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
658 pg_tlv->length =
659 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700660 pg = (struct mwifiex_power_group *)
661 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
662 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700663 /* Power group for modulation class HR/DSSS */
664 pg->first_rate_code = 0x00;
665 pg->last_rate_code = 0x03;
666 pg->modulation_class = MOD_CLASS_HR_DSSS;
667 pg->power_step = 0;
668 pg->power_min = (s8) dbm;
669 pg->power_max = (s8) dbm;
670 pg++;
671 /* Power group for modulation class OFDM */
672 pg->first_rate_code = 0x00;
673 pg->last_rate_code = 0x07;
674 pg->modulation_class = MOD_CLASS_OFDM;
675 pg->power_step = 0;
676 pg->power_min = (s8) dbm;
677 pg->power_max = (s8) dbm;
678 pg++;
679 /* Power group for modulation class HTBW20 */
680 pg->first_rate_code = 0x00;
681 pg->last_rate_code = 0x20;
682 pg->modulation_class = MOD_CLASS_HT;
683 pg->power_step = 0;
684 pg->power_min = (s8) dbm;
685 pg->power_max = (s8) dbm;
686 pg->ht_bandwidth = HT_BW_20;
687 pg++;
688 /* Power group for modulation class HTBW40 */
689 pg->first_rate_code = 0x00;
690 pg->last_rate_code = 0x20;
691 pg->modulation_class = MOD_CLASS_HT;
692 pg->power_step = 0;
693 pg->power_min = (s8) dbm;
694 pg->power_max = (s8) dbm;
695 pg->ht_bandwidth = HT_BW_40;
696 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800697 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
698 HostCmd_ACT_GEN_SET, 0, buf, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700699
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700700 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700701 return ret;
702}
703
704/*
705 * IOCTL request handler to get power save mode.
706 *
707 * This function prepares the correct firmware command and
708 * issues it.
709 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700710int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700711{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700712 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700713 struct mwifiex_adapter *adapter = priv->adapter;
714 u16 sub_cmd;
715
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700716 if (*ps_mode)
717 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
718 else
719 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
720 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800721 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
722 sub_cmd, BITMAP_STA_PS, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700723 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800724 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
725 GET_PS, 0, NULL, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726
727 return ret;
728}
729
730/*
731 * IOCTL request handler to set/reset WPA IE.
732 *
733 * The supplied WPA IE is treated as a opaque buffer. Only the first field
734 * is checked to determine WPA version. If buffer length is zero, the existing
735 * WPA IE is reset.
736 */
737static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
738 u8 *ie_data_ptr, u16 ie_len)
739{
740 if (ie_len) {
741 if (ie_len > sizeof(priv->wpa_ie)) {
742 dev_err(priv->adapter->dev,
743 "failed to copy WPA IE, too big\n");
744 return -1;
745 }
746 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
747 priv->wpa_ie_len = (u8) ie_len;
748 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700749 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700750
Arend van Spriel04b23122012-10-12 12:28:14 +0200751 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700752 priv->sec_info.wpa_enabled = true;
753 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
754 priv->sec_info.wpa2_enabled = true;
755 } else {
756 priv->sec_info.wpa_enabled = false;
757 priv->sec_info.wpa2_enabled = false;
758 }
759 } else {
760 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
761 priv->wpa_ie_len = 0;
762 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
763 priv->wpa_ie_len, priv->wpa_ie[0]);
764 priv->sec_info.wpa_enabled = false;
765 priv->sec_info.wpa2_enabled = false;
766 }
767
768 return 0;
769}
770
771/*
772 * IOCTL request handler to set/reset WAPI IE.
773 *
774 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
775 * is checked to internally enable WAPI. If buffer length is zero, the existing
776 * WAPI IE is reset.
777 */
778static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
779 u8 *ie_data_ptr, u16 ie_len)
780{
781 if (ie_len) {
782 if (ie_len > sizeof(priv->wapi_ie)) {
783 dev_dbg(priv->adapter->dev,
784 "info: failed to copy WAPI IE, too big\n");
785 return -1;
786 }
787 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
788 priv->wapi_ie_len = ie_len;
789 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700790 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700791
792 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
793 priv->sec_info.wapi_enabled = true;
794 } else {
795 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
796 priv->wapi_ie_len = ie_len;
797 dev_dbg(priv->adapter->dev,
798 "info: Reset wapi_ie_len=%d IE=%#x\n",
799 priv->wapi_ie_len, priv->wapi_ie[0]);
800 priv->sec_info.wapi_enabled = false;
801 }
802 return 0;
803}
804
805/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700806 * IOCTL request handler to set/reset WPS IE.
807 *
808 * The supplied WPS IE is treated as a opaque buffer. Only the first field
809 * is checked to internally enable WPS. If buffer length is zero, the existing
810 * WPS IE is reset.
811 */
812static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
813 u8 *ie_data_ptr, u16 ie_len)
814{
815 if (ie_len) {
Avinash Patil8795ca62013-07-22 19:17:46 -0700816 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
817 dev_dbg(priv->adapter->dev,
818 "info: failed to copy WPS IE, too big\n");
819 return -1;
820 }
821
Avinash Patil13d7ba782012-04-09 20:06:56 -0700822 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
823 if (!priv->wps_ie)
824 return -ENOMEM;
Avinash Patil8795ca62013-07-22 19:17:46 -0700825
Avinash Patil13d7ba782012-04-09 20:06:56 -0700826 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
827 priv->wps_ie_len = ie_len;
828 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
829 priv->wps_ie_len, priv->wps_ie[0]);
830 } else {
831 kfree(priv->wps_ie);
832 priv->wps_ie_len = ie_len;
833 dev_dbg(priv->adapter->dev,
834 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
835 }
836 return 0;
837}
838
839/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700840 * IOCTL request handler to set WAPI key.
841 *
842 * This function prepares the correct firmware command and
843 * issues it.
844 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700845static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700846 struct mwifiex_ds_encrypt_key *encrypt_key)
847{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700848
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800849 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
850 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
851 encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700852}
853
854/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700855 * IOCTL request handler to set WEP network key.
856 *
857 * This function prepares the correct firmware command and
858 * issues it, after validation checks.
859 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700860static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 struct mwifiex_ds_encrypt_key *encrypt_key)
862{
Avinash Patile57f1732014-02-07 16:32:35 -0800863 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700864 int ret;
865 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700866 int index;
867
868 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
869 priv->wep_key_curr_index = 0;
870 wep_key = &priv->wep_key[priv->wep_key_curr_index];
871 index = encrypt_key->key_index;
872 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800873 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874 } else if (!encrypt_key->key_len) {
875 /* Copy the required key as the current key */
876 wep_key = &priv->wep_key[index];
877 if (!wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800878 dev_err(adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700879 "key not set, so cannot enable it\n");
880 return -1;
881 }
Avinash Patile57f1732014-02-07 16:32:35 -0800882
Amitkumar Karwar4b9fede2014-08-19 08:24:25 -0400883 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2) {
Avinash Patile57f1732014-02-07 16:32:35 -0800884 memcpy(encrypt_key->key_material,
885 wep_key->key_material, wep_key->key_length);
886 encrypt_key->key_len = wep_key->key_length;
887 }
888
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700889 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800890 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700891 } else {
892 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700893 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
894 /* Copy the key in the driver */
895 memcpy(wep_key->key_material,
896 encrypt_key->key_material,
897 encrypt_key->key_len);
898 wep_key->key_index = index;
899 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800900 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700901 }
902 if (wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800903 void *enc_key;
904
905 if (encrypt_key->key_disable)
906 memset(&priv->wep_key[index], 0,
907 sizeof(struct mwifiex_wep_key));
908
Amitkumar Karwar4b9fede2014-08-19 08:24:25 -0400909 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
Avinash Patile57f1732014-02-07 16:32:35 -0800910 enc_key = encrypt_key;
911 else
912 enc_key = NULL;
913
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700914 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800915 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
916 HostCmd_ACT_GEN_SET, 0, enc_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700917 if (ret)
918 return ret;
919 }
Avinash Patile57f1732014-02-07 16:32:35 -0800920
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800921 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700922 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
923 else
924 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
925
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800926 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
927 HostCmd_ACT_GEN_SET, 0,
928 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700929
930 return ret;
931}
932
933/*
934 * IOCTL request handler to set WPA key.
935 *
936 * This function prepares the correct firmware command and
937 * issues it, after validation checks.
938 *
939 * Current driver only supports key length of up to 32 bytes.
940 *
941 * This function can also be used to disable a currently set key.
942 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700943static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700944 struct mwifiex_ds_encrypt_key *encrypt_key)
945{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700946 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700947 u8 remove_key = false;
948 struct host_cmd_ds_802_11_key_material *ibss_key;
949
950 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700951 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700952 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700953 return -1;
954 }
955
Bing Zhaoeecd8252011-03-28 17:55:41 -0700956 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700957 /*
958 * IBSS/WPA-None uses only one key (Group) for both receiving
959 * and sending unicast and multicast packets.
960 */
961 /* Send the key as PTK to firmware */
962 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800963 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
964 HostCmd_ACT_GEN_SET,
965 KEY_INFO_ENABLED, encrypt_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700966 if (ret)
967 return ret;
968
969 ibss_key = &priv->aes_key;
970 memset(ibss_key, 0,
971 sizeof(struct host_cmd_ds_802_11_key_material));
972 /* Copy the key in the driver */
973 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
974 encrypt_key->key_len);
975 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
976 sizeof(ibss_key->key_param_set.key_len));
977 ibss_key->key_param_set.key_type_id
978 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700979 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700980
981 /* Send the key as GTK to firmware */
982 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
983 }
984
985 if (!encrypt_key->key_index)
986 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
987
988 if (remove_key)
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800989 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
990 HostCmd_ACT_GEN_SET,
991 !KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700992 else
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800993 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
994 HostCmd_ACT_GEN_SET,
995 KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700996
997 return ret;
998}
999
1000/*
1001 * IOCTL request handler to set/get network keys.
1002 *
1003 * This is a generic key handling function which supports WEP, WPA
1004 * and WAPI.
1005 */
1006static int
1007mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001008 struct mwifiex_ds_encrypt_key *encrypt_key)
1009{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001010 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001011
1012 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001013 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001014 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001015 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001017 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001018 return status;
1019}
1020
1021/*
1022 * This function returns the driver version.
1023 */
1024int
1025mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1026 int max_len)
1027{
1028 union {
Amitkumar Karwar0d4b5c72014-11-07 02:14:52 -08001029 __le32 l;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001030 u8 c[4];
1031 } ver;
1032 char fw_ver[32];
1033
Amitkumar Karwar0d4b5c72014-11-07 02:14:52 -08001034 ver.l = cpu_to_le32(adapter->fw_release_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001035 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1036
1037 snprintf(version, max_len, driver_version, fw_ver);
1038
1039 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1040
1041 return 0;
1042}
1043
1044/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001045 * Sends IOCTL request to set encoding parameters.
1046 *
1047 * This function allocates the IOCTL request buffer, fills it
1048 * with requisite parameters and calls the IOCTL handler.
1049 */
Ying Luo53b11232012-08-03 18:06:13 -07001050int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1051 const u8 *key, int key_len, u8 key_index,
1052 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001053{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001054 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001055
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001056 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1057 encrypt_key.key_len = key_len;
Avinash Patile57f1732014-02-07 16:32:35 -08001058 encrypt_key.key_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -07001059
1060 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1061 encrypt_key.is_igtk_key = true;
1062
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001063 if (!disable) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001064 if (key_len)
1065 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001066 else
1067 encrypt_key.is_current_wep_key = true;
1068
Avinash Patil75edd2c2012-05-08 18:30:18 -07001069 if (mac_addr)
1070 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Avinash Patile57f1732014-02-07 16:32:35 -08001071 if (kp && kp->seq && kp->seq_len) {
Ying Luo53b11232012-08-03 18:06:13 -07001072 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001073 encrypt_key.pn_len = kp->seq_len;
1074 encrypt_key.is_rx_seq_valid = true;
1075 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001076 } else {
Avinash Patile57f1732014-02-07 16:32:35 -08001077 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
1078 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001079 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001080 if (mac_addr)
1081 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001082 }
1083
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001084 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001085}
1086
1087/*
1088 * Sends IOCTL request to get extended version.
1089 *
1090 * This function allocates the IOCTL request buffer, fills it
1091 * with requisite parameters and calls the IOCTL handler.
1092 */
1093int
1094mwifiex_get_ver_ext(struct mwifiex_private *priv)
1095{
1096 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001097
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001098 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001099 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1100 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001101 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001102
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001103 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001104}
1105
Stone Piao7feb4c42012-09-25 20:23:36 -07001106int
1107mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1108 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001109 unsigned int duration)
1110{
1111 struct host_cmd_ds_remain_on_chan roc_cfg;
1112 u8 sc;
1113
1114 memset(&roc_cfg, 0, sizeof(roc_cfg));
1115 roc_cfg.action = cpu_to_le16(action);
1116 if (action == HostCmd_ACT_GEN_SET) {
1117 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001118 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001119 roc_cfg.band_cfg |= (sc << 2);
1120
1121 roc_cfg.channel =
1122 ieee80211_frequency_to_channel(chan->center_freq);
1123 roc_cfg.duration = cpu_to_le32(duration);
1124 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001125 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1126 action, 0, &roc_cfg, true)) {
Stone Piao7feb4c42012-09-25 20:23:36 -07001127 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1128 return -1;
1129 }
1130
1131 return roc_cfg.status;
1132}
1133
Stone Piao9197ab92012-09-25 20:23:42 -07001134int
1135mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1136{
1137 if (GET_BSS_ROLE(priv) == bss_role) {
1138 dev_dbg(priv->adapter->dev,
1139 "info: already in the desired role.\n");
1140 return 0;
1141 }
1142
1143 mwifiex_free_priv(priv);
1144 mwifiex_init_priv(priv);
1145
1146 priv->bss_role = bss_role;
1147 switch (bss_role) {
1148 case MWIFIEX_BSS_ROLE_UAP:
1149 priv->bss_mode = NL80211_IFTYPE_AP;
1150 break;
1151 case MWIFIEX_BSS_ROLE_STA:
1152 case MWIFIEX_BSS_ROLE_ANY:
1153 default:
1154 priv->bss_mode = NL80211_IFTYPE_STATION;
1155 break;
1156 }
1157
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001158 mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1159 HostCmd_ACT_GEN_SET, 0, NULL, true);
Stone Piao9197ab92012-09-25 20:23:42 -07001160
1161 return mwifiex_sta_init_cmd(priv, false);
1162}
1163
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001164/*
1165 * Sends IOCTL request to get statistics information.
1166 *
1167 * This function allocates the IOCTL request buffer, fills it
1168 * with requisite parameters and calls the IOCTL handler.
1169 */
1170int
1171mwifiex_get_stats_info(struct mwifiex_private *priv,
1172 struct mwifiex_ds_get_stats *log)
1173{
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001174 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1175 HostCmd_ACT_GEN_GET, 0, log, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001176}
1177
1178/*
1179 * IOCTL request handler to read/write register.
1180 *
1181 * This function prepares the correct firmware command and
1182 * issues it.
1183 *
1184 * Access to the following registers are supported -
1185 * - MAC
1186 * - BBP
1187 * - RF
1188 * - PMIC
1189 * - CAU
1190 */
1191static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001192 struct mwifiex_ds_reg_rw *reg_rw,
1193 u16 action)
1194{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001195 u16 cmd_no;
1196
1197 switch (le32_to_cpu(reg_rw->type)) {
1198 case MWIFIEX_REG_MAC:
1199 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1200 break;
1201 case MWIFIEX_REG_BBP:
1202 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1203 break;
1204 case MWIFIEX_REG_RF:
1205 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1206 break;
1207 case MWIFIEX_REG_PMIC:
1208 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1209 break;
1210 case MWIFIEX_REG_CAU:
1211 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1212 break;
1213 default:
1214 return -1;
1215 }
1216
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001217 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001218}
1219
1220/*
1221 * Sends IOCTL request to write to a register.
1222 *
1223 * This function allocates the IOCTL request buffer, fills it
1224 * with requisite parameters and calls the IOCTL handler.
1225 */
1226int
1227mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1228 u32 reg_offset, u32 reg_value)
1229{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001230 struct mwifiex_ds_reg_rw reg_rw;
1231
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232 reg_rw.type = cpu_to_le32(reg_type);
1233 reg_rw.offset = cpu_to_le32(reg_offset);
1234 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001235
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001236 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001237}
1238
1239/*
1240 * Sends IOCTL request to read from a register.
1241 *
1242 * This function allocates the IOCTL request buffer, fills it
1243 * with requisite parameters and calls the IOCTL handler.
1244 */
1245int
1246mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1247 u32 reg_offset, u32 *value)
1248{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001249 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001250 struct mwifiex_ds_reg_rw reg_rw;
1251
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001252 reg_rw.type = cpu_to_le32(reg_type);
1253 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001254 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001256 if (ret)
1257 goto done;
1258
1259 *value = le32_to_cpu(reg_rw.value);
1260
1261done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001262 return ret;
1263}
1264
1265/*
1266 * Sends IOCTL request to read from EEPROM.
1267 *
1268 * This function allocates the IOCTL request buffer, fills it
1269 * with requisite parameters and calls the IOCTL handler.
1270 */
1271int
1272mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1273 u8 *value)
1274{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001275 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001276 struct mwifiex_ds_read_eeprom rd_eeprom;
1277
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001278 rd_eeprom.offset = cpu_to_le16((u16) offset);
1279 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001280
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001281 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001282 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1283 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001284
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001285 if (!ret)
1286 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001287 return ret;
1288}
1289
1290/*
1291 * This function sets a generic IE. In addition to generic IE, it can
1292 * also handle WPA, WPA2 and WAPI IEs.
1293 */
1294static int
1295mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1296 u16 ie_len)
1297{
1298 int ret = 0;
1299 struct ieee_types_vendor_header *pvendor_ie;
1300 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1301 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1302
1303 /* If the passed length is zero, reset the buffer */
1304 if (!ie_len) {
1305 priv->gen_ie_buf_len = 0;
1306 priv->wps.session_enable = false;
1307
1308 return 0;
1309 } else if (!ie_data_ptr) {
1310 return -1;
1311 }
1312 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1313 /* 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 +02001314 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001315 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1316 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001317
1318 /* IE is a WPA/WPA2 IE so call set_wpa function */
1319 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1320 priv->wps.session_enable = false;
1321
1322 return ret;
1323 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1324 /* IE is a WAPI IE so call set_wapi function */
1325 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1326
1327 return ret;
1328 }
1329 /*
1330 * Verify that the passed length is not larger than the
1331 * available space remaining in the buffer
1332 */
1333 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1334
1335 /* Test to see if it is a WPS IE, if so, enable
1336 * wps session flag
1337 */
1338 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001339 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1340 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001341 priv->wps.session_enable = true;
1342 dev_dbg(priv->adapter->dev,
1343 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001344 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001345 }
1346
1347 /* Append the passed data to the end of the
1348 genIeBuffer */
1349 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001350 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001351 /* Increment the stored buffer length by the
1352 size passed */
1353 priv->gen_ie_buf_len += ie_len;
1354 } else {
1355 /* Passed data does not fit in the remaining
1356 buffer space */
1357 ret = -1;
1358 }
1359
1360 /* Return 0, or -1 for error case */
1361 return ret;
1362}
1363
1364/*
1365 * IOCTL request handler to set/get generic IE.
1366 *
1367 * In addition to various generic IEs, this function can also be
1368 * used to set the ARP filter.
1369 */
1370static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1371 struct mwifiex_ds_misc_gen_ie *gen_ie,
1372 u16 action)
1373{
1374 struct mwifiex_adapter *adapter = priv->adapter;
1375
1376 switch (gen_ie->type) {
1377 case MWIFIEX_IE_TYPE_GEN_IE:
1378 if (action == HostCmd_ACT_GEN_GET) {
1379 gen_ie->len = priv->wpa_ie_len;
1380 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1381 } else {
1382 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1383 (u16) gen_ie->len);
1384 }
1385 break;
1386 case MWIFIEX_IE_TYPE_ARP_FILTER:
1387 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1388 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1389 adapter->arp_filter_size = 0;
1390 dev_err(adapter->dev, "invalid ARP filter size\n");
1391 return -1;
1392 } else {
1393 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001394 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001395 adapter->arp_filter_size = gen_ie->len;
1396 }
1397 break;
1398 default:
1399 dev_err(adapter->dev, "invalid IE type\n");
1400 return -1;
1401 }
1402 return 0;
1403}
1404
1405/*
1406 * Sends IOCTL request to set a generic IE.
1407 *
1408 * This function allocates the IOCTL request buffer, fills it
1409 * with requisite parameters and calls the IOCTL handler.
1410 */
1411int
Johannes Berg4b5800f2014-01-15 14:55:59 +01001412mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001413{
1414 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001415
Bing Zhao67a50032011-07-13 18:38:34 -07001416 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001417 return -EFAULT;
1418
1419 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1420 gen_ie.len = ie_len;
1421 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001422 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001423 return -EFAULT;
1424
1425 return 0;
1426}