blob: 210b257aad6bdc2e4950ce1103d4d16f1f3fb602 [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) {
Dmitry Torokhov4e0ff942015-04-30 16:52:02 -070067 if (status == 0)
68 status = -ETIMEDOUT;
Andreas Fenkartc5bc15f2015-07-17 09:13:06 +020069 mwifiex_dbg(adapter, ERROR, "cmd_wait_q terminated: %d\n",
70 status);
Amitkumar Karwar3d026d02014-03-20 16:23:49 -070071 mwifiex_cancel_all_pending_cmd(adapter);
Bing Zhao9c969d82013-01-02 16:07:35 -080072 return status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080074
75 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070076 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078 return status;
79}
80
81/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070082 * This function prepares the correct firmware command and
83 * issues it to set the multicast list.
84 *
85 * This function can be used to enable promiscuous mode, or enable all
86 * multicast packets, or to enable selective multicast.
87 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070088int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
89 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070090{
91 int ret = 0;
92 u16 old_pkt_filter;
93
94 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070095
96 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +053097 mwifiex_dbg(priv->adapter, INFO,
98 "info: Enable Promiscuous mode\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -070099 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
100 priv->curr_pkt_filter &=
101 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
102 } else {
103 /* Multicast */
104 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
Daniel Drakeccd384b2013-05-08 15:37:19 -0400105 if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530106 mwifiex_dbg(priv->adapter, INFO,
107 "info: Enabling All Multicast!\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700108 priv->curr_pkt_filter |=
109 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
110 } else {
111 priv->curr_pkt_filter &=
112 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530113 mwifiex_dbg(priv->adapter, INFO,
114 "info: Set multicast list=%d\n",
115 mcast_list->num_multicast_addr);
Daniel Drake6390d882013-06-14 15:24:24 -0400116 /* Send multicast addresses to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800117 ret = mwifiex_send_cmd(priv,
118 HostCmd_CMD_MAC_MULTICAST_ADR,
119 HostCmd_ACT_GEN_SET, 0,
120 mcast_list, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700121 }
122 }
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530123 mwifiex_dbg(priv->adapter, INFO,
124 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
125 old_pkt_filter, priv->curr_pkt_filter);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700126 if (old_pkt_filter != priv->curr_pkt_filter) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800127 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
128 HostCmd_ACT_GEN_SET,
129 0, &priv->curr_pkt_filter, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700130 }
131
132 return ret;
133}
134
135/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700136 * This function fills bss descriptor structure using provided
137 * information.
Bing Zhaod837a2a2013-04-12 10:34:17 -0700138 * beacon_ie buffer is allocated in this function. It is caller's
139 * responsibility to free the memory.
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700140 */
141int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700142 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700143 struct mwifiex_bssdescriptor *bss_desc)
144{
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700145 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500146 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700147 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100148 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700149
Johannes Berg9caf0362012-11-29 01:25:20 +0100150 rcu_read_lock();
151 ies = rcu_dereference(bss->ies);
Johannes Berg9caf0362012-11-29 01:25:20 +0100152 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
153 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100154 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100155 rcu_read_unlock();
156
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700157 if (!beacon_ie) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530158 mwifiex_dbg(priv->adapter, ERROR,
159 " failed to alloc beacon_ie\n");
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700160 return -ENOMEM;
161 }
162
163 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
164 bss_desc->rssi = bss->signal;
Bing Zhaod837a2a2013-04-12 10:34:17 -0700165 /* The caller of this function will free beacon_ie */
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700166 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100167 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700168 bss_desc->beacon_period = bss->beacon_interval;
169 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700170 bss_desc->bss_band = bss_priv->band;
171 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700172 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530173 mwifiex_dbg(priv->adapter, INFO,
174 "info: InterpretIE: AP WEP enabled\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700175 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
176 } else {
177 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
178 }
179 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
180 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
181 else
182 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
183
Bing Zhaoc43933e2013-04-12 10:34:18 -0700184 /* Disable 11ac by default. Enable it only where there
185 * exist VHT_CAP IE in AP beacon
186 */
187 bss_desc->disable_11ac = true;
188
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700189 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
190 bss_desc->sensed_11h = true;
191
Bing Zhaod837a2a2013-04-12 10:34:17 -0700192 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700193}
194
Bing Zhaob58df442014-01-08 15:45:57 -0800195void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv)
196{
197 if (priv->adapter->dt_node) {
198 char txpwr[] = {"marvell,00_txpwrlimit"};
199
200 memcpy(&txpwr[8], priv->adapter->country_code, 2);
201 mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
202 }
203}
204
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700205static int mwifiex_process_country_ie(struct mwifiex_private *priv,
206 struct cfg80211_bss *bss)
207{
Johannes Berg9caf0362012-11-29 01:25:20 +0100208 const u8 *country_ie;
209 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700210 struct mwifiex_802_11d_domain_reg *domain_info =
211 &priv->adapter->domain_reg;
212
Johannes Berg9caf0362012-11-29 01:25:20 +0100213 rcu_read_lock();
214 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
215 if (!country_ie) {
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
220 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100221 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
222 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700223 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100224 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700225
Bing Zhaodd4a9ac2013-12-13 18:32:59 -0800226 if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
227 rcu_read_unlock();
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530228 mwifiex_dbg(priv->adapter, INFO,
229 "11D: skip setting domain info in FW\n");
Bing Zhaodd4a9ac2013-12-13 18:32:59 -0800230 return 0;
231 }
232 memcpy(priv->adapter->country_code, &country_ie[2], 2);
233
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700234 domain_info->country_code[0] = country_ie[2];
235 domain_info->country_code[1] = country_ie[3];
236 domain_info->country_code[2] = ' ';
237
238 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
239
240 domain_info->no_of_triplet =
241 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
242
243 memcpy((u8 *)domain_info->triplet,
244 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
245
Johannes Berg9caf0362012-11-29 01:25:20 +0100246 rcu_read_unlock();
247
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800248 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
249 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530250 mwifiex_dbg(priv->adapter, ERROR,
251 "11D: setting domain info in FW fail\n");
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700252 return -1;
253 }
254
Bing Zhaob58df442014-01-08 15:45:57 -0800255 mwifiex_dnld_txpwr_table(priv);
Bing Zhao82efa162013-12-13 18:33:02 -0800256
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700257 return 0;
258}
259
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700260/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700261 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
262 * In both Ad-Hoc and infra mode, an deauthentication is performed
263 * first.
264 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700265int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800266 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700267{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700268 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700269 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700270 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700271
272 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700273
274 if (bss) {
Amitkumar Karwar947d3152015-12-04 06:13:05 -0800275 if (adapter->region_code == 0x00)
276 mwifiex_process_country_ie(priv, bss);
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700277
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700278 /* Allocate and fill new bss descriptor */
279 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000280 GFP_KERNEL);
281 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700282 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700283
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700284 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700285 if (ret)
286 goto done;
287 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700288
Stone Piao6621fe12013-07-29 16:32:39 -0700289 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
290 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700291 u8 config_bands;
292
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700293 if (!bss_desc)
294 return -1;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800295
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700296 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
Xinming Hua659c432014-09-12 20:08:50 +0530297 HostCmd_SCAN_RADIO_TYPE_BG) {
Bing Zhaof25b1432014-02-07 16:21:01 -0800298 config_bands = BAND_B | BAND_G | BAND_GN;
Xinming Hua659c432014-09-12 20:08:50 +0530299 } else {
300 config_bands = BAND_A | BAND_AN;
301 if (adapter->fw_bands & BAND_AAC)
302 config_bands |= BAND_AAC;
303 }
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800304
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700305 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
306 adapter->config_bands = config_bands;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800307
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700308 ret = mwifiex_check_network_compatibility(priv, bss_desc);
309 if (ret)
310 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700311
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700312 if (mwifiex_11h_get_csa_closed_channel(priv) ==
313 (u8)bss_desc->channel) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530314 mwifiex_dbg(adapter, ERROR,
315 "Attempt to reconnect on csa closed chan(%d)\n",
316 bss_desc->channel);
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700317 goto done;
318 }
319
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530320 mwifiex_dbg(adapter, INFO,
321 "info: SSID found in scan list ...\t"
322 "associating...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700323
Avinash Patil47411a02012-11-01 18:44:16 -0700324 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800325 if (netif_carrier_ok(priv->netdev))
326 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700327
328 /* Clear any past association response stored for
329 * application retrieval */
330 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700331 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800332
333 /* If auth type is auto and association fails using open mode,
334 * try to connect using shared mode */
335 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
336 priv->sec_info.is_authtype_auto &&
337 priv->sec_info.wep_enabled) {
338 priv->sec_info.authentication_mode =
339 NL80211_AUTHTYPE_SHARED_KEY;
340 ret = mwifiex_associate(priv, bss_desc);
341 }
342
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700343 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100344 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700345 } else {
346 /* Adhoc mode */
347 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700348 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700349 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
350 ssid, &bss_desc->ssid))) {
Ujjal Roy517543f2013-11-21 11:08:56 -0800351 ret = 0;
352 goto done;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700353 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700354
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355 priv->adhoc_is_link_sensed = false;
356
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700357 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700358
Avinash Patil47411a02012-11-01 18:44:16 -0700359 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800360 if (netif_carrier_ok(priv->netdev))
361 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700362
363 if (!ret) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530364 mwifiex_dbg(adapter, INFO,
365 "info: network found in scan\t"
366 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700367 ret = mwifiex_adhoc_join(priv, bss_desc);
368 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100369 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700370 } else {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530371 mwifiex_dbg(adapter, INFO,
372 "info: Network not found in\t"
373 "the list, creating adhoc with ssid = %s\n",
374 req_ssid->ssid);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700375 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700376 }
377 }
378
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700379done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700380 /* beacon_ie buffer was allocated in function
381 * mwifiex_fill_new_bss_desc(). Free it now.
382 */
383 if (bss_desc)
384 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700385 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700386 return ret;
387}
388
389/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700390 * IOCTL request handler to set host sleep configuration.
391 *
392 * This function prepares the correct firmware command and
393 * issues it.
394 */
Xinming Hu937a5042014-06-19 21:38:56 -0700395int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
396 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700397
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700398{
399 struct mwifiex_adapter *adapter = priv->adapter;
400 int status = 0;
401 u32 prev_cond = 0;
402
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700403 if (!hs_cfg)
404 return -ENOMEM;
405
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700406 switch (action) {
407 case HostCmd_ACT_GEN_SET:
408 if (adapter->pps_uapsd_mode) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530409 mwifiex_dbg(adapter, INFO,
410 "info: Host Sleep IOCTL\t"
411 "is blocked in UAPSD/PPS mode\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700412 status = -1;
413 break;
414 }
415 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800416 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700417 if (!adapter->is_hs_configured)
418 /* Already cancelled */
419 break;
420 /* Save previous condition */
421 prev_cond = le32_to_cpu(adapter->hs_cfg
422 .conditions);
423 adapter->hs_cfg.conditions =
424 cpu_to_le32(hs_cfg->conditions);
425 } else if (hs_cfg->conditions) {
426 adapter->hs_cfg.conditions =
427 cpu_to_le32(hs_cfg->conditions);
428 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
429 if (hs_cfg->gap)
430 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800431 } else if (adapter->hs_cfg.conditions ==
432 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700433 /* Return failure if no parameters for HS
434 enable */
435 status = -1;
436 break;
437 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800438
439 status = mwifiex_send_cmd(priv,
440 HostCmd_CMD_802_11_HS_CFG_ENH,
441 HostCmd_ACT_GEN_SET, 0,
442 &adapter->hs_cfg,
443 cmd_type == MWIFIEX_SYNC_CMD);
444
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800445 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700446 /* Restore previous condition */
447 adapter->hs_cfg.conditions =
448 cpu_to_le32(prev_cond);
449 } else {
450 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700451 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700452 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
453 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
454 }
455 break;
456 case HostCmd_ACT_GEN_GET:
457 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
458 hs_cfg->gpio = adapter->hs_cfg.gpio;
459 hs_cfg->gap = adapter->hs_cfg.gap;
460 break;
461 default:
462 status = -1;
463 break;
464 }
465
466 return status;
467}
468
469/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470 * Sends IOCTL request to cancel the existing Host Sleep configuration.
471 *
472 * This function allocates the IOCTL request buffer, fills it
473 * with requisite parameters and calls the IOCTL handler.
474 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700475int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700477 struct mwifiex_ds_hs_cfg hscfg;
478
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800479 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700480 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700481
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700482 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
483 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700484}
485EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
486
487/*
488 * Sends IOCTL request to cancel the existing Host Sleep configuration.
489 *
490 * This function allocates the IOCTL request buffer, fills it
491 * with requisite parameters and calls the IOCTL handler.
492 */
493int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
494{
495 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700496 struct mwifiex_private *priv;
497 int i;
498
499 if (disconnect_on_suspend) {
500 for (i = 0; i < adapter->priv_num; i++) {
501 priv = adapter->priv[i];
502 if (priv)
503 mwifiex_deauthenticate(priv, NULL);
504 }
505 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700506
507 if (adapter->hs_activated) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530508 mwifiex_dbg(adapter, CMD,
509 "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510 return true;
511 }
512
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700513 adapter->hs_activate_wait_q_woken = false;
514
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700515 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700516 hscfg.is_invoke_hostcmd = true;
517
Amitkumar Karwarc0dbba62014-03-25 19:01:20 -0700518 adapter->hs_enabling = true;
519 mwifiex_cancel_all_pending_cmd(adapter);
520
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700521 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700522 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700523 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
524 &hscfg)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530525 mwifiex_dbg(adapter, ERROR,
526 "IOCTL request HS enable failed\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700527 return false;
528 }
529
Amitkumar Karwar52250cb2014-03-20 16:23:50 -0700530 if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
531 adapter->hs_activate_wait_q_woken,
532 (10 * HZ)) <= 0) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530533 mwifiex_dbg(adapter, ERROR,
534 "hs_activate_wait_q terminated\n");
Bing Zhao9c969d82013-01-02 16:07:35 -0800535 return false;
536 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700537
538 return true;
539}
540EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
541
542/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543 * IOCTL request handler to get BSS information.
544 *
545 * This function collates the information from different driver structures
546 * to send to the user.
547 */
548int mwifiex_get_bss_info(struct mwifiex_private *priv,
549 struct mwifiex_bss_info *info)
550{
551 struct mwifiex_adapter *adapter = priv->adapter;
552 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553
554 if (!info)
555 return -1;
556
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700557 bss_desc = &priv->curr_bss_params.bss_descriptor;
558
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700559 info->bss_mode = priv->bss_mode;
560
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800561 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
564
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 info->bss_chan = bss_desc->channel;
566
Avinash Patil67fdf392012-05-08 18:30:17 -0700567 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700568 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700569
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700570 info->media_connected = priv->media_connected;
571
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700572 info->max_power_level = priv->max_tx_power_level;
573 info->min_power_level = priv->min_tx_power_level;
574
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700575 info->adhoc_state = priv->adhoc_state;
576
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700577 info->bcn_nf_last = priv->bcn_nf_last;
578
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800579 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700580 info->wep_status = true;
581 else
582 info->wep_status = false;
583
584 info->is_hs_configured = adapter->is_hs_configured;
585 info->is_deep_sleep = adapter->is_deep_sleep;
586
587 return 0;
588}
589
590/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700591 * The function disables auto deep sleep mode.
592 */
593int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
594{
595 struct mwifiex_ds_auto_ds auto_ds;
596
597 auto_ds.auto_ds = DEEP_SLEEP_OFF;
598
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800599 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
600 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
Amitkumar Karwara0490932011-07-13 20:51:59 -0700601}
602EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
603
604/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700605 * Sends IOCTL request to get the data rate.
606 *
607 * This function allocates the IOCTL request buffer, fills it
608 * with requisite parameters and calls the IOCTL handler.
609 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700610int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700611{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700612 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700613
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800614 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
615 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700616
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700617 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700618 if (priv->is_data_rate_auto)
619 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
620 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300621 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700622 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700623 }
624
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700625 return ret;
626}
627
628/*
629 * IOCTL request handler to set tx power configuration.
630 *
631 * This function prepares the correct firmware command and
632 * issues it.
633 *
634 * For non-auto power mode, all the following power groups are set -
635 * - Modulation class HR/DSSS
636 * - Modulation class OFDM
637 * - Modulation class HTBW20
638 * - Modulation class HTBW40
639 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700640int mwifiex_set_tx_power(struct mwifiex_private *priv,
641 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700642{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700643 int ret;
644 struct host_cmd_ds_txpwr_cfg *txp_cfg;
645 struct mwifiex_types_power_group *pg_tlv;
646 struct mwifiex_power_group *pg;
647 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700648 u16 dbm = 0;
649
650 if (!power_cfg->is_power_auto) {
651 dbm = (u16) power_cfg->power_level;
652 if ((dbm < priv->min_tx_power_level) ||
653 (dbm > priv->max_tx_power_level)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530654 mwifiex_dbg(priv->adapter, ERROR,
655 "txpower value %d dBm\t"
656 "is out of range (%d dBm-%d dBm)\n",
657 dbm, priv->min_tx_power_level,
658 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700659 return -1;
660 }
661 }
662 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000663 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200664 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700665
666 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
667 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
668 if (!power_cfg->is_power_auto) {
669 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700670 pg_tlv = (struct mwifiex_types_power_group *)
671 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700672 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
673 pg_tlv->length =
674 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700675 pg = (struct mwifiex_power_group *)
676 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
677 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700678 /* Power group for modulation class HR/DSSS */
679 pg->first_rate_code = 0x00;
680 pg->last_rate_code = 0x03;
681 pg->modulation_class = MOD_CLASS_HR_DSSS;
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 OFDM */
687 pg->first_rate_code = 0x00;
688 pg->last_rate_code = 0x07;
689 pg->modulation_class = MOD_CLASS_OFDM;
690 pg->power_step = 0;
691 pg->power_min = (s8) dbm;
692 pg->power_max = (s8) dbm;
693 pg++;
694 /* Power group for modulation class HTBW20 */
695 pg->first_rate_code = 0x00;
696 pg->last_rate_code = 0x20;
697 pg->modulation_class = MOD_CLASS_HT;
698 pg->power_step = 0;
699 pg->power_min = (s8) dbm;
700 pg->power_max = (s8) dbm;
701 pg->ht_bandwidth = HT_BW_20;
702 pg++;
703 /* Power group for modulation class HTBW40 */
704 pg->first_rate_code = 0x00;
705 pg->last_rate_code = 0x20;
706 pg->modulation_class = MOD_CLASS_HT;
707 pg->power_step = 0;
708 pg->power_min = (s8) dbm;
709 pg->power_max = (s8) dbm;
710 pg->ht_bandwidth = HT_BW_40;
711 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800712 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
713 HostCmd_ACT_GEN_SET, 0, buf, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700714
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700715 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700716 return ret;
717}
718
719/*
720 * IOCTL request handler to get power save mode.
721 *
722 * This function prepares the correct firmware command and
723 * issues it.
724 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700725int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700726{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700727 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700728 struct mwifiex_adapter *adapter = priv->adapter;
729 u16 sub_cmd;
730
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700731 if (*ps_mode)
732 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
733 else
734 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
735 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800736 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
737 sub_cmd, BITMAP_STA_PS, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700738 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800739 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
740 GET_PS, 0, NULL, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700741
742 return ret;
743}
744
745/*
746 * IOCTL request handler to set/reset WPA IE.
747 *
748 * The supplied WPA IE is treated as a opaque buffer. Only the first field
749 * is checked to determine WPA version. If buffer length is zero, the existing
750 * WPA IE is reset.
751 */
752static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
753 u8 *ie_data_ptr, u16 ie_len)
754{
755 if (ie_len) {
756 if (ie_len > sizeof(priv->wpa_ie)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530757 mwifiex_dbg(priv->adapter, ERROR,
758 "failed to copy WPA IE, too big\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700759 return -1;
760 }
761 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
chunfan chen1d8f5c12015-12-16 04:21:42 -0800762 priv->wpa_ie_len = ie_len;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530763 mwifiex_dbg(priv->adapter, CMD,
764 "cmd: Set Wpa_ie_len=%d IE=%#x\n",
765 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700766
Arend van Spriel04b23122012-10-12 12:28:14 +0200767 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700768 priv->sec_info.wpa_enabled = true;
769 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
770 priv->sec_info.wpa2_enabled = true;
771 } else {
772 priv->sec_info.wpa_enabled = false;
773 priv->sec_info.wpa2_enabled = false;
774 }
775 } else {
776 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
777 priv->wpa_ie_len = 0;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530778 mwifiex_dbg(priv->adapter, INFO,
779 "info: reset wpa_ie_len=%d IE=%#x\n",
780 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700781 priv->sec_info.wpa_enabled = false;
782 priv->sec_info.wpa2_enabled = false;
783 }
784
785 return 0;
786}
787
788/*
789 * IOCTL request handler to set/reset WAPI IE.
790 *
791 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
792 * is checked to internally enable WAPI. If buffer length is zero, the existing
793 * WAPI IE is reset.
794 */
795static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
796 u8 *ie_data_ptr, u16 ie_len)
797{
798 if (ie_len) {
799 if (ie_len > sizeof(priv->wapi_ie)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530800 mwifiex_dbg(priv->adapter, ERROR,
801 "info: failed to copy WAPI IE, too big\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700802 return -1;
803 }
804 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
805 priv->wapi_ie_len = ie_len;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530806 mwifiex_dbg(priv->adapter, CMD,
807 "cmd: Set wapi_ie_len=%d IE=%#x\n",
808 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700809
810 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
811 priv->sec_info.wapi_enabled = true;
812 } else {
813 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
814 priv->wapi_ie_len = ie_len;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530815 mwifiex_dbg(priv->adapter, INFO,
816 "info: Reset wapi_ie_len=%d IE=%#x\n",
817 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700818 priv->sec_info.wapi_enabled = false;
819 }
820 return 0;
821}
822
823/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700824 * IOCTL request handler to set/reset WPS IE.
825 *
826 * The supplied WPS IE is treated as a opaque buffer. Only the first field
827 * is checked to internally enable WPS. If buffer length is zero, the existing
828 * WPS IE is reset.
829 */
830static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
831 u8 *ie_data_ptr, u16 ie_len)
832{
833 if (ie_len) {
Avinash Patil8795ca62013-07-22 19:17:46 -0700834 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530835 mwifiex_dbg(priv->adapter, ERROR,
836 "info: failed to copy WPS IE, too big\n");
Avinash Patil8795ca62013-07-22 19:17:46 -0700837 return -1;
838 }
839
Avinash Patil13d7ba782012-04-09 20:06:56 -0700840 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
841 if (!priv->wps_ie)
842 return -ENOMEM;
Avinash Patil8795ca62013-07-22 19:17:46 -0700843
Avinash Patil13d7ba782012-04-09 20:06:56 -0700844 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
845 priv->wps_ie_len = ie_len;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530846 mwifiex_dbg(priv->adapter, CMD,
847 "cmd: Set wps_ie_len=%d IE=%#x\n",
848 priv->wps_ie_len, priv->wps_ie[0]);
Avinash Patil13d7ba782012-04-09 20:06:56 -0700849 } else {
850 kfree(priv->wps_ie);
851 priv->wps_ie_len = ie_len;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530852 mwifiex_dbg(priv->adapter, INFO,
853 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
Avinash Patil13d7ba782012-04-09 20:06:56 -0700854 }
855 return 0;
856}
857
858/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700859 * IOCTL request handler to set WAPI key.
860 *
861 * This function prepares the correct firmware command and
862 * issues it.
863 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700864static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700865 struct mwifiex_ds_encrypt_key *encrypt_key)
866{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800868 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
869 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
870 encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871}
872
873/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700874 * IOCTL request handler to set WEP network key.
875 *
876 * This function prepares the correct firmware command and
877 * issues it, after validation checks.
878 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700879static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700880 struct mwifiex_ds_encrypt_key *encrypt_key)
881{
Avinash Patile57f1732014-02-07 16:32:35 -0800882 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700883 int ret;
884 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885 int index;
886
887 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
888 priv->wep_key_curr_index = 0;
889 wep_key = &priv->wep_key[priv->wep_key_curr_index];
890 index = encrypt_key->key_index;
891 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800892 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700893 } else if (!encrypt_key->key_len) {
894 /* Copy the required key as the current key */
895 wep_key = &priv->wep_key[index];
896 if (!wep_key->key_length) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530897 mwifiex_dbg(adapter, ERROR,
898 "key not set, so cannot enable it\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700899 return -1;
900 }
Avinash Patile57f1732014-02-07 16:32:35 -0800901
Amitkumar Karwar4b9fede2014-08-19 08:24:25 -0400902 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2) {
Avinash Patile57f1732014-02-07 16:32:35 -0800903 memcpy(encrypt_key->key_material,
904 wep_key->key_material, wep_key->key_length);
905 encrypt_key->key_len = wep_key->key_length;
906 }
907
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700908 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800909 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700910 } else {
911 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700912 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
913 /* Copy the key in the driver */
914 memcpy(wep_key->key_material,
915 encrypt_key->key_material,
916 encrypt_key->key_len);
917 wep_key->key_index = index;
918 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800919 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700920 }
921 if (wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800922 void *enc_key;
923
Xinming Hu2ab87d52014-12-26 03:02:32 -0800924 if (encrypt_key->key_disable) {
Avinash Patile57f1732014-02-07 16:32:35 -0800925 memset(&priv->wep_key[index], 0,
926 sizeof(struct mwifiex_wep_key));
Dan Carpenter97276c12015-12-04 16:17:15 +0300927 goto done;
928 }
Avinash Patile57f1732014-02-07 16:32:35 -0800929
Amitkumar Karwar4b9fede2014-08-19 08:24:25 -0400930 if (adapter->key_api_major_ver == KEY_API_VER_MAJOR_V2)
Avinash Patile57f1732014-02-07 16:32:35 -0800931 enc_key = encrypt_key;
932 else
933 enc_key = NULL;
934
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700935 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800936 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
937 HostCmd_ACT_GEN_SET, 0, enc_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700938 if (ret)
939 return ret;
940 }
Avinash Patile57f1732014-02-07 16:32:35 -0800941
Xinming Hu2ab87d52014-12-26 03:02:32 -0800942done:
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800943 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700944 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
945 else
946 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
947
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800948 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
949 HostCmd_ACT_GEN_SET, 0,
950 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700951
952 return ret;
953}
954
955/*
956 * IOCTL request handler to set WPA key.
957 *
958 * This function prepares the correct firmware command and
959 * issues it, after validation checks.
960 *
961 * Current driver only supports key length of up to 32 bytes.
962 *
963 * This function can also be used to disable a currently set key.
964 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700965static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700966 struct mwifiex_ds_encrypt_key *encrypt_key)
967{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700968 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700969 u8 remove_key = false;
970 struct host_cmd_ds_802_11_key_material *ibss_key;
971
972 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700973 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +0530974 mwifiex_dbg(priv->adapter, ERROR,
975 "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700976 return -1;
977 }
978
Bing Zhaoeecd8252011-03-28 17:55:41 -0700979 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700980 /*
981 * IBSS/WPA-None uses only one key (Group) for both receiving
982 * and sending unicast and multicast packets.
983 */
984 /* Send the key as PTK to firmware */
985 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800986 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
987 HostCmd_ACT_GEN_SET,
988 KEY_INFO_ENABLED, encrypt_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700989 if (ret)
990 return ret;
991
992 ibss_key = &priv->aes_key;
993 memset(ibss_key, 0,
994 sizeof(struct host_cmd_ds_802_11_key_material));
995 /* Copy the key in the driver */
996 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
997 encrypt_key->key_len);
998 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
999 sizeof(ibss_key->key_param_set.key_len));
1000 ibss_key->key_param_set.key_type_id
1001 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -07001002 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001003
1004 /* Send the key as GTK to firmware */
1005 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
1006 }
1007
1008 if (!encrypt_key->key_index)
1009 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
1010
1011 if (remove_key)
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001012 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1013 HostCmd_ACT_GEN_SET,
1014 !KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015 else
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001016 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1017 HostCmd_ACT_GEN_SET,
1018 KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001019
1020 return ret;
1021}
1022
1023/*
1024 * IOCTL request handler to set/get network keys.
1025 *
1026 * This is a generic key handling function which supports WEP, WPA
1027 * and WAPI.
1028 */
1029static int
1030mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001031 struct mwifiex_ds_encrypt_key *encrypt_key)
1032{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001033 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001034
1035 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001036 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001037 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001038 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001039 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001040 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001041 return status;
1042}
1043
1044/*
1045 * This function returns the driver version.
1046 */
1047int
1048mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1049 int max_len)
1050{
1051 union {
Amitkumar Karwar0d4b5c72014-11-07 02:14:52 -08001052 __le32 l;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001053 u8 c[4];
1054 } ver;
1055 char fw_ver[32];
1056
Amitkumar Karwar0d4b5c72014-11-07 02:14:52 -08001057 ver.l = cpu_to_le32(adapter->fw_release_number);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1059
1060 snprintf(version, max_len, driver_version, fw_ver);
1061
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301062 mwifiex_dbg(adapter, MSG, "info: MWIFIEX VERSION: %s\n", version);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001063
1064 return 0;
1065}
1066
1067/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001068 * Sends IOCTL request to set encoding parameters.
1069 *
1070 * This function allocates the IOCTL request buffer, fills it
1071 * with requisite parameters and calls the IOCTL handler.
1072 */
Ying Luo53b11232012-08-03 18:06:13 -07001073int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1074 const u8 *key, int key_len, u8 key_index,
1075 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001076{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001077 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001078
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001079 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1080 encrypt_key.key_len = key_len;
Avinash Patile57f1732014-02-07 16:32:35 -08001081 encrypt_key.key_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -07001082
1083 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1084 encrypt_key.is_igtk_key = true;
1085
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001086 if (!disable) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001087 if (key_len)
1088 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001089 else
1090 encrypt_key.is_current_wep_key = true;
1091
Avinash Patil75edd2c2012-05-08 18:30:18 -07001092 if (mac_addr)
1093 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Avinash Patile57f1732014-02-07 16:32:35 -08001094 if (kp && kp->seq && kp->seq_len) {
Ying Luo53b11232012-08-03 18:06:13 -07001095 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001096 encrypt_key.pn_len = kp->seq_len;
1097 encrypt_key.is_rx_seq_valid = true;
1098 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001099 } else {
Avinash Patile57f1732014-02-07 16:32:35 -08001100 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
1101 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001102 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001103 if (mac_addr)
1104 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001105 }
1106
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001107 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001108}
1109
1110/*
1111 * Sends IOCTL request to get extended version.
1112 *
1113 * This function allocates the IOCTL request buffer, fills it
1114 * with requisite parameters and calls the IOCTL handler.
1115 */
1116int
Xinming Hu17934b62016-01-06 23:40:49 -08001117mwifiex_get_ver_ext(struct mwifiex_private *priv, u32 version_str_sel)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001118{
1119 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001120
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001121 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Xinming Hu17934b62016-01-06 23:40:49 -08001122 ver_ext.version_str_sel = version_str_sel;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001123 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1124 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001125 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001126
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001127 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001128}
1129
Stone Piao7feb4c42012-09-25 20:23:36 -07001130int
1131mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1132 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001133 unsigned int duration)
1134{
1135 struct host_cmd_ds_remain_on_chan roc_cfg;
1136 u8 sc;
1137
1138 memset(&roc_cfg, 0, sizeof(roc_cfg));
1139 roc_cfg.action = cpu_to_le16(action);
1140 if (action == HostCmd_ACT_GEN_SET) {
1141 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001142 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001143 roc_cfg.band_cfg |= (sc << 2);
1144
1145 roc_cfg.channel =
1146 ieee80211_frequency_to_channel(chan->center_freq);
1147 roc_cfg.duration = cpu_to_le32(duration);
1148 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001149 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1150 action, 0, &roc_cfg, true)) {
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301151 mwifiex_dbg(priv->adapter, ERROR,
1152 "failed to remain on channel\n");
Stone Piao7feb4c42012-09-25 20:23:36 -07001153 return -1;
1154 }
1155
1156 return roc_cfg.status;
1157}
1158
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001159/*
1160 * Sends IOCTL request to get statistics information.
1161 *
1162 * This function allocates the IOCTL request buffer, fills it
1163 * with requisite parameters and calls the IOCTL handler.
1164 */
1165int
1166mwifiex_get_stats_info(struct mwifiex_private *priv,
1167 struct mwifiex_ds_get_stats *log)
1168{
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001169 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1170 HostCmd_ACT_GEN_GET, 0, log, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001171}
1172
1173/*
1174 * IOCTL request handler to read/write register.
1175 *
1176 * This function prepares the correct firmware command and
1177 * issues it.
1178 *
1179 * Access to the following registers are supported -
1180 * - MAC
1181 * - BBP
1182 * - RF
1183 * - PMIC
1184 * - CAU
1185 */
1186static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001187 struct mwifiex_ds_reg_rw *reg_rw,
1188 u16 action)
1189{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001190 u16 cmd_no;
1191
1192 switch (le32_to_cpu(reg_rw->type)) {
1193 case MWIFIEX_REG_MAC:
1194 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1195 break;
1196 case MWIFIEX_REG_BBP:
1197 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1198 break;
1199 case MWIFIEX_REG_RF:
1200 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1201 break;
1202 case MWIFIEX_REG_PMIC:
1203 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1204 break;
1205 case MWIFIEX_REG_CAU:
1206 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1207 break;
1208 default:
1209 return -1;
1210 }
1211
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001212 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001213}
1214
1215/*
1216 * Sends IOCTL request to write to a register.
1217 *
1218 * This function allocates the IOCTL request buffer, fills it
1219 * with requisite parameters and calls the IOCTL handler.
1220 */
1221int
1222mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1223 u32 reg_offset, u32 reg_value)
1224{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001225 struct mwifiex_ds_reg_rw reg_rw;
1226
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001227 reg_rw.type = cpu_to_le32(reg_type);
1228 reg_rw.offset = cpu_to_le32(reg_offset);
1229 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001230
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001231 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001232}
1233
1234/*
1235 * Sends IOCTL request to read from a register.
1236 *
1237 * This function allocates the IOCTL request buffer, fills it
1238 * with requisite parameters and calls the IOCTL handler.
1239 */
1240int
1241mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1242 u32 reg_offset, u32 *value)
1243{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001244 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001245 struct mwifiex_ds_reg_rw reg_rw;
1246
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001247 reg_rw.type = cpu_to_le32(reg_type);
1248 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001249 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001250
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001251 if (ret)
1252 goto done;
1253
1254 *value = le32_to_cpu(reg_rw.value);
1255
1256done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 return ret;
1258}
1259
1260/*
1261 * Sends IOCTL request to read from EEPROM.
1262 *
1263 * This function allocates the IOCTL request buffer, fills it
1264 * with requisite parameters and calls the IOCTL handler.
1265 */
1266int
1267mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1268 u8 *value)
1269{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001270 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001271 struct mwifiex_ds_read_eeprom rd_eeprom;
1272
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001273 rd_eeprom.offset = cpu_to_le16((u16) offset);
1274 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001275
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001276 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001277 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1278 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001279
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001280 if (!ret)
1281 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001282 return ret;
1283}
1284
1285/*
1286 * This function sets a generic IE. In addition to generic IE, it can
1287 * also handle WPA, WPA2 and WAPI IEs.
1288 */
1289static int
1290mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1291 u16 ie_len)
1292{
1293 int ret = 0;
1294 struct ieee_types_vendor_header *pvendor_ie;
1295 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1296 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
chunfan chen84a38fb2015-12-14 04:15:15 -08001297 u16 unparsed_len = ie_len;
1298 int find_wpa_ie = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001299
1300 /* If the passed length is zero, reset the buffer */
1301 if (!ie_len) {
1302 priv->gen_ie_buf_len = 0;
1303 priv->wps.session_enable = false;
1304
1305 return 0;
1306 } else if (!ie_data_ptr) {
1307 return -1;
1308 }
1309 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001310
chunfan chen84a38fb2015-12-14 04:15:15 -08001311 while (pvendor_ie) {
1312 if (pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) {
1313 /* Test to see if it is a WPA IE, if not, then it is a
1314 * gen IE
1315 */
1316 if (!memcmp(pvendor_ie->oui, wpa_oui,
1317 sizeof(wpa_oui))) {
1318 find_wpa_ie = 1;
1319 break;
1320 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001321
chunfan chen84a38fb2015-12-14 04:15:15 -08001322 /* Test to see if it is a WPS IE, if so, enable
1323 * wps session flag
1324 */
1325 if (!memcmp(pvendor_ie->oui, wps_oui,
1326 sizeof(wps_oui))) {
1327 priv->wps.session_enable = true;
1328 mwifiex_dbg(priv->adapter, MSG,
1329 "info: WPS Session Enabled.\n");
1330 ret = mwifiex_set_wps_ie(priv,
1331 (u8 *)pvendor_ie,
1332 unparsed_len);
1333 }
1334 }
1335
1336 if (pvendor_ie->element_id == WLAN_EID_RSN) {
1337 find_wpa_ie = 1;
1338 break;
1339 }
1340
1341 if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001342 /* IE is a WAPI IE so call set_wapi function */
chunfan chen84a38fb2015-12-14 04:15:15 -08001343 ret = mwifiex_set_wapi_ie(priv, (u8 *)pvendor_ie,
1344 unparsed_len);
1345 return ret;
1346 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001347
chunfan chen84a38fb2015-12-14 04:15:15 -08001348 unparsed_len -= (pvendor_ie->len +
1349 sizeof(struct ieee_types_header));
1350
1351 if (unparsed_len <= sizeof(struct ieee_types_header))
1352 pvendor_ie = NULL;
1353 else
1354 pvendor_ie = (struct ieee_types_vendor_header *)
1355 (((u8 *)pvendor_ie) + pvendor_ie->len +
1356 sizeof(struct ieee_types_header));
1357 }
1358
1359 if (find_wpa_ie) {
1360 /* IE is a WPA/WPA2 IE so call set_wpa function */
1361 ret = mwifiex_set_wpa_ie_helper(priv, (u8 *)pvendor_ie,
1362 unparsed_len);
1363 priv->wps.session_enable = false;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001364 return ret;
1365 }
chunfan chen84a38fb2015-12-14 04:15:15 -08001366
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001367 /*
1368 * Verify that the passed length is not larger than the
1369 * available space remaining in the buffer
1370 */
1371 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1372
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001373 /* Append the passed data to the end of the
1374 genIeBuffer */
1375 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001376 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001377 /* Increment the stored buffer length by the
1378 size passed */
1379 priv->gen_ie_buf_len += ie_len;
1380 } else {
1381 /* Passed data does not fit in the remaining
1382 buffer space */
1383 ret = -1;
1384 }
1385
1386 /* Return 0, or -1 for error case */
1387 return ret;
1388}
1389
1390/*
1391 * IOCTL request handler to set/get generic IE.
1392 *
1393 * In addition to various generic IEs, this function can also be
1394 * used to set the ARP filter.
1395 */
1396static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1397 struct mwifiex_ds_misc_gen_ie *gen_ie,
1398 u16 action)
1399{
1400 struct mwifiex_adapter *adapter = priv->adapter;
1401
1402 switch (gen_ie->type) {
1403 case MWIFIEX_IE_TYPE_GEN_IE:
1404 if (action == HostCmd_ACT_GEN_GET) {
1405 gen_ie->len = priv->wpa_ie_len;
1406 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1407 } else {
1408 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1409 (u16) gen_ie->len);
1410 }
1411 break;
1412 case MWIFIEX_IE_TYPE_ARP_FILTER:
1413 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1414 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1415 adapter->arp_filter_size = 0;
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301416 mwifiex_dbg(adapter, ERROR,
1417 "invalid ARP filter size\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001418 return -1;
1419 } else {
1420 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001421 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001422 adapter->arp_filter_size = gen_ie->len;
1423 }
1424 break;
1425 default:
Zhaoyang Liuacebe8c2015-05-12 00:48:20 +05301426 mwifiex_dbg(adapter, ERROR, "invalid IE type\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001427 return -1;
1428 }
1429 return 0;
1430}
1431
1432/*
1433 * Sends IOCTL request to set a generic IE.
1434 *
1435 * This function allocates the IOCTL request buffer, fills it
1436 * with requisite parameters and calls the IOCTL handler.
1437 */
1438int
Johannes Berg4b5800f2014-01-15 14:55:59 +01001439mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001440{
1441 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001442
Bing Zhao67a50032011-07-13 18:38:34 -07001443 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001444 return -EFAULT;
1445
1446 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1447 gen_ie.len = ie_len;
1448 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001449 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001450 return -EFAULT;
1451
1452 return 0;
1453}