blob: 894270611f2cb6e074669f424fe66978e80e1992 [file] [log] [blame]
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001/*
2 * Marvell Wireless LAN device driver: functions for station ioctl
3 *
4 * Copyright (C) 2011, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
18 */
19
20#include "decl.h"
21#include "ioctl.h"
22#include "util.h"
23#include "fw.h"
24#include "main.h"
25#include "wmm.h"
26#include "11n.h"
27#include "cfg80211.h"
28
Amitkumar Karwar22c22d22012-09-20 20:23:17 -070029static int disconnect_on_suspend = 1;
30module_param(disconnect_on_suspend, int, 0644);
31
Bing Zhao5e6e3a92011-03-21 18:00:50 -070032/*
33 * Copies the multicast address list from device to driver.
34 *
35 * This function does not validate the destination memory for
36 * size, and the calling function must ensure enough memory is
37 * available.
38 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070039int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
40 struct net_device *dev)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070041{
42 int i = 0;
43 struct netdev_hw_addr *ha;
44
45 netdev_for_each_mc_addr(ha, dev)
46 memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN);
47
48 return i;
49}
50
51/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070052 * Wait queue completion handler.
53 *
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070054 * This function waits on a cmd wait queue. It also cancels the pending
55 * request after waking up, in case of errors.
Bing Zhao5e6e3a92011-03-21 18:00:50 -070056 */
Amitkumar Karwar00d7ea12013-03-15 18:47:05 -070057int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
58 struct cmd_ctrl_node *cmd_queued)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070059{
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080060 int status;
Amitkumar Karwarb015dbc2012-01-02 16:18:40 -080061
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070062 /* Wait for completion */
Bing Zhao9c969d82013-01-02 16:07:35 -080063 status = wait_event_interruptible(adapter->cmd_wait_q.wait,
64 *(cmd_queued->condition));
65 if (status) {
66 dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status);
Amitkumar Karwar3d026d02014-03-20 16:23:49 -070067 mwifiex_cancel_all_pending_cmd(adapter);
Bing Zhao9c969d82013-01-02 16:07:35 -080068 return status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070069 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080070
71 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070072 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073
Bing Zhao5e6e3a92011-03-21 18:00:50 -070074 return status;
75}
76
77/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070078 * This function prepares the correct firmware command and
79 * issues it to set the multicast list.
80 *
81 * This function can be used to enable promiscuous mode, or enable all
82 * multicast packets, or to enable selective multicast.
83 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070084int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
85 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070086{
87 int ret = 0;
88 u16 old_pkt_filter;
89
90 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070091
92 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
93 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
94 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
95 priv->curr_pkt_filter &=
96 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
97 } else {
98 /* Multicast */
99 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
Daniel Drakeccd384b2013-05-08 15:37:19 -0400100 if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700101 dev_dbg(priv->adapter->dev,
102 "info: Enabling All Multicast!\n");
103 priv->curr_pkt_filter |=
104 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
105 } else {
106 priv->curr_pkt_filter &=
107 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
Daniel Drake6390d882013-06-14 15:24:24 -0400108 dev_dbg(priv->adapter->dev,
109 "info: Set multicast list=%d\n",
110 mcast_list->num_multicast_addr);
111 /* Send multicast addresses to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800112 ret = mwifiex_send_cmd(priv,
113 HostCmd_CMD_MAC_MULTICAST_ADR,
114 HostCmd_ACT_GEN_SET, 0,
115 mcast_list, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700116 }
117 }
118 dev_dbg(priv->adapter->dev,
119 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
120 old_pkt_filter, priv->curr_pkt_filter);
121 if (old_pkt_filter != priv->curr_pkt_filter) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800122 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
123 HostCmd_ACT_GEN_SET,
124 0, &priv->curr_pkt_filter, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700125 }
126
127 return ret;
128}
129
130/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700131 * This function fills bss descriptor structure using provided
132 * information.
Bing Zhaod837a2a2013-04-12 10:34:17 -0700133 * beacon_ie buffer is allocated in this function. It is caller's
134 * responsibility to free the memory.
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700135 */
136int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700137 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700138 struct mwifiex_bssdescriptor *bss_desc)
139{
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700140 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500141 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700142 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100143 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700144
Johannes Berg9caf0362012-11-29 01:25:20 +0100145 rcu_read_lock();
146 ies = rcu_dereference(bss->ies);
Johannes Berg9caf0362012-11-29 01:25:20 +0100147 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
148 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100149 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100150 rcu_read_unlock();
151
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700152 if (!beacon_ie) {
153 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
154 return -ENOMEM;
155 }
156
157 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
158 bss_desc->rssi = bss->signal;
Bing Zhaod837a2a2013-04-12 10:34:17 -0700159 /* The caller of this function will free beacon_ie */
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700160 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100161 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700162 bss_desc->beacon_period = bss->beacon_interval;
163 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700164 bss_desc->bss_band = bss_priv->band;
165 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700166 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
167 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
168 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
169 } else {
170 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
171 }
172 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
173 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
174 else
175 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
176
Bing Zhaoc43933e2013-04-12 10:34:18 -0700177 /* Disable 11ac by default. Enable it only where there
178 * exist VHT_CAP IE in AP beacon
179 */
180 bss_desc->disable_11ac = true;
181
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700182 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
183 bss_desc->sensed_11h = true;
184
Bing Zhaod837a2a2013-04-12 10:34:17 -0700185 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700186}
187
Bing Zhaob58df442014-01-08 15:45:57 -0800188void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv)
189{
190 if (priv->adapter->dt_node) {
191 char txpwr[] = {"marvell,00_txpwrlimit"};
192
193 memcpy(&txpwr[8], priv->adapter->country_code, 2);
194 mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
195 }
196}
197
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700198static int mwifiex_process_country_ie(struct mwifiex_private *priv,
199 struct cfg80211_bss *bss)
200{
Johannes Berg9caf0362012-11-29 01:25:20 +0100201 const u8 *country_ie;
202 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700203 struct mwifiex_802_11d_domain_reg *domain_info =
204 &priv->adapter->domain_reg;
205
Johannes Berg9caf0362012-11-29 01:25:20 +0100206 rcu_read_lock();
207 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
208 if (!country_ie) {
209 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700210 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100211 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700212
213 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100214 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
215 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700216 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100217 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700218
Bing Zhaodd4a9ac2013-12-13 18:32:59 -0800219 if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
220 rcu_read_unlock();
221 wiphy_dbg(priv->wdev->wiphy,
222 "11D: skip setting domain info in FW\n");
223 return 0;
224 }
225 memcpy(priv->adapter->country_code, &country_ie[2], 2);
226
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700227 domain_info->country_code[0] = country_ie[2];
228 domain_info->country_code[1] = country_ie[3];
229 domain_info->country_code[2] = ' ';
230
231 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
232
233 domain_info->no_of_triplet =
234 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
235
236 memcpy((u8 *)domain_info->triplet,
237 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
238
Johannes Berg9caf0362012-11-29 01:25:20 +0100239 rcu_read_unlock();
240
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800241 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
242 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700243 wiphy_err(priv->adapter->wiphy,
244 "11D: setting domain info in FW\n");
245 return -1;
246 }
247
Bing Zhaob58df442014-01-08 15:45:57 -0800248 mwifiex_dnld_txpwr_table(priv);
Bing Zhao82efa162013-12-13 18:33:02 -0800249
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700250 return 0;
251}
252
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700253/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700254 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
255 * In both Ad-Hoc and infra mode, an deauthentication is performed
256 * first.
257 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700258int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800259 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700260{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700261 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700262 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700263 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700264
265 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700266
267 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700268 mwifiex_process_country_ie(priv, bss);
269
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700270 /* Allocate and fill new bss descriptor */
271 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000272 GFP_KERNEL);
273 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700274 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700275
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700276 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700277 if (ret)
278 goto done;
279 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700280
Stone Piao6621fe12013-07-29 16:32:39 -0700281 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
282 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700283 u8 config_bands;
284
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700285 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700286 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700287 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700288
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700289 if (!bss_desc)
290 return -1;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800291
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700292 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
293 HostCmd_SCAN_RADIO_TYPE_BG)
Bing Zhaof25b1432014-02-07 16:21:01 -0800294 config_bands = BAND_B | BAND_G | BAND_GN;
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700295 else
296 config_bands = BAND_A | BAND_AN | BAND_AAC;
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
347 /* Exit Adhoc mode first */
348 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700349 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700350 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700351 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700352
353 priv->adhoc_is_link_sensed = false;
354
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700355 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700356
Avinash Patil47411a02012-11-01 18:44:16 -0700357 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800358 if (netif_carrier_ok(priv->netdev))
359 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700360
361 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700362 dev_dbg(adapter->dev, "info: network found in scan"
363 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700364 ret = mwifiex_adhoc_join(priv, bss_desc);
365 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100366 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700367 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700368 dev_dbg(adapter->dev, "info: Network not found in "
369 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700370 req_ssid->ssid);
371 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700372 }
373 }
374
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700375done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700376 /* beacon_ie buffer was allocated in function
377 * mwifiex_fill_new_bss_desc(). Free it now.
378 */
379 if (bss_desc)
380 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700381 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700382 return ret;
383}
384
385/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700386 * IOCTL request handler to set host sleep configuration.
387 *
388 * This function prepares the correct firmware command and
389 * issues it.
390 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700391static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
392 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700393
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700394{
395 struct mwifiex_adapter *adapter = priv->adapter;
396 int status = 0;
397 u32 prev_cond = 0;
398
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700399 if (!hs_cfg)
400 return -ENOMEM;
401
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700402 switch (action) {
403 case HostCmd_ACT_GEN_SET:
404 if (adapter->pps_uapsd_mode) {
405 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
406 " is blocked in UAPSD/PPS mode\n");
407 status = -1;
408 break;
409 }
410 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800411 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700412 if (!adapter->is_hs_configured)
413 /* Already cancelled */
414 break;
415 /* Save previous condition */
416 prev_cond = le32_to_cpu(adapter->hs_cfg
417 .conditions);
418 adapter->hs_cfg.conditions =
419 cpu_to_le32(hs_cfg->conditions);
420 } else if (hs_cfg->conditions) {
421 adapter->hs_cfg.conditions =
422 cpu_to_le32(hs_cfg->conditions);
423 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
424 if (hs_cfg->gap)
425 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800426 } else if (adapter->hs_cfg.conditions ==
427 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700428 /* Return failure if no parameters for HS
429 enable */
430 status = -1;
431 break;
432 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800433
434 status = mwifiex_send_cmd(priv,
435 HostCmd_CMD_802_11_HS_CFG_ENH,
436 HostCmd_ACT_GEN_SET, 0,
437 &adapter->hs_cfg,
438 cmd_type == MWIFIEX_SYNC_CMD);
439
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800440 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700441 /* Restore previous condition */
442 adapter->hs_cfg.conditions =
443 cpu_to_le32(prev_cond);
444 } else {
445 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700446 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700447 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
448 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
449 }
450 break;
451 case HostCmd_ACT_GEN_GET:
452 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
453 hs_cfg->gpio = adapter->hs_cfg.gpio;
454 hs_cfg->gap = adapter->hs_cfg.gap;
455 break;
456 default:
457 status = -1;
458 break;
459 }
460
461 return status;
462}
463
464/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700465 * Sends IOCTL request to cancel the existing Host Sleep configuration.
466 *
467 * This function allocates the IOCTL request buffer, fills it
468 * with requisite parameters and calls the IOCTL handler.
469 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700470int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700471{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700472 struct mwifiex_ds_hs_cfg hscfg;
473
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800474 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700476
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700477 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
478 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700479}
480EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
481
482/*
483 * Sends IOCTL request to cancel the existing Host Sleep configuration.
484 *
485 * This function allocates the IOCTL request buffer, fills it
486 * with requisite parameters and calls the IOCTL handler.
487 */
488int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
489{
490 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700491 struct mwifiex_private *priv;
492 int i;
493
494 if (disconnect_on_suspend) {
495 for (i = 0; i < adapter->priv_num; i++) {
496 priv = adapter->priv[i];
497 if (priv)
498 mwifiex_deauthenticate(priv, NULL);
499 }
500 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700501
502 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900503 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700504 return true;
505 }
506
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700507 adapter->hs_activate_wait_q_woken = false;
508
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700509 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700510 hscfg.is_invoke_hostcmd = true;
511
Amitkumar Karwarc0dbba62014-03-25 19:01:20 -0700512 adapter->hs_enabling = true;
513 mwifiex_cancel_all_pending_cmd(adapter);
514
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700515 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700516 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700517 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
518 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700519 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
520 return false;
521 }
522
Amitkumar Karwar52250cb2014-03-20 16:23:50 -0700523 if (wait_event_interruptible_timeout(adapter->hs_activate_wait_q,
524 adapter->hs_activate_wait_q_woken,
525 (10 * HZ)) <= 0) {
Bing Zhao9c969d82013-01-02 16:07:35 -0800526 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
527 return false;
528 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700529
530 return true;
531}
532EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
533
534/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700535 * IOCTL request handler to get BSS information.
536 *
537 * This function collates the information from different driver structures
538 * to send to the user.
539 */
540int mwifiex_get_bss_info(struct mwifiex_private *priv,
541 struct mwifiex_bss_info *info)
542{
543 struct mwifiex_adapter *adapter = priv->adapter;
544 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700545
546 if (!info)
547 return -1;
548
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549 bss_desc = &priv->curr_bss_params.bss_descriptor;
550
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700551 info->bss_mode = priv->bss_mode;
552
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800553 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700554
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
556
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700557 info->bss_chan = bss_desc->channel;
558
Avinash Patil67fdf392012-05-08 18:30:17 -0700559 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700560 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700561
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562 info->media_connected = priv->media_connected;
563
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700564 info->max_power_level = priv->max_tx_power_level;
565 info->min_power_level = priv->min_tx_power_level;
566
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567 info->adhoc_state = priv->adhoc_state;
568
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700569 info->bcn_nf_last = priv->bcn_nf_last;
570
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800571 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700572 info->wep_status = true;
573 else
574 info->wep_status = false;
575
576 info->is_hs_configured = adapter->is_hs_configured;
577 info->is_deep_sleep = adapter->is_deep_sleep;
578
579 return 0;
580}
581
582/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700583 * The function disables auto deep sleep mode.
584 */
585int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
586{
587 struct mwifiex_ds_auto_ds auto_ds;
588
589 auto_ds.auto_ds = DEEP_SLEEP_OFF;
590
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800591 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
592 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
Amitkumar Karwara0490932011-07-13 20:51:59 -0700593}
594EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
595
596/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700597 * Sends IOCTL request to get the data rate.
598 *
599 * This function allocates the IOCTL request buffer, fills it
600 * with requisite parameters and calls the IOCTL handler.
601 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700602int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700604 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700605
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800606 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
607 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700609 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700610 if (priv->is_data_rate_auto)
611 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
612 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300613 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700614 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700615 }
616
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700617 return ret;
618}
619
620/*
621 * IOCTL request handler to set tx power configuration.
622 *
623 * This function prepares the correct firmware command and
624 * issues it.
625 *
626 * For non-auto power mode, all the following power groups are set -
627 * - Modulation class HR/DSSS
628 * - Modulation class OFDM
629 * - Modulation class HTBW20
630 * - Modulation class HTBW40
631 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700632int mwifiex_set_tx_power(struct mwifiex_private *priv,
633 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700634{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700635 int ret;
636 struct host_cmd_ds_txpwr_cfg *txp_cfg;
637 struct mwifiex_types_power_group *pg_tlv;
638 struct mwifiex_power_group *pg;
639 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700640 u16 dbm = 0;
641
642 if (!power_cfg->is_power_auto) {
643 dbm = (u16) power_cfg->power_level;
644 if ((dbm < priv->min_tx_power_level) ||
645 (dbm > priv->max_tx_power_level)) {
646 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700647 " is out of range (%d dBm-%d dBm)\n",
648 dbm, priv->min_tx_power_level,
649 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700650 return -1;
651 }
652 }
653 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000654 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200655 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700656
657 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
658 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
659 if (!power_cfg->is_power_auto) {
660 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700661 pg_tlv = (struct mwifiex_types_power_group *)
662 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700663 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
664 pg_tlv->length =
665 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700666 pg = (struct mwifiex_power_group *)
667 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
668 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700669 /* Power group for modulation class HR/DSSS */
670 pg->first_rate_code = 0x00;
671 pg->last_rate_code = 0x03;
672 pg->modulation_class = MOD_CLASS_HR_DSSS;
673 pg->power_step = 0;
674 pg->power_min = (s8) dbm;
675 pg->power_max = (s8) dbm;
676 pg++;
677 /* Power group for modulation class OFDM */
678 pg->first_rate_code = 0x00;
679 pg->last_rate_code = 0x07;
680 pg->modulation_class = MOD_CLASS_OFDM;
681 pg->power_step = 0;
682 pg->power_min = (s8) dbm;
683 pg->power_max = (s8) dbm;
684 pg++;
685 /* Power group for modulation class HTBW20 */
686 pg->first_rate_code = 0x00;
687 pg->last_rate_code = 0x20;
688 pg->modulation_class = MOD_CLASS_HT;
689 pg->power_step = 0;
690 pg->power_min = (s8) dbm;
691 pg->power_max = (s8) dbm;
692 pg->ht_bandwidth = HT_BW_20;
693 pg++;
694 /* Power group for modulation class HTBW40 */
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_40;
702 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800703 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
704 HostCmd_ACT_GEN_SET, 0, buf, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700705
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700706 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700707 return ret;
708}
709
710/*
711 * IOCTL request handler to get power save mode.
712 *
713 * This function prepares the correct firmware command and
714 * issues it.
715 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700716int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700717{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700718 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700719 struct mwifiex_adapter *adapter = priv->adapter;
720 u16 sub_cmd;
721
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700722 if (*ps_mode)
723 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
724 else
725 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
726 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800727 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
728 sub_cmd, BITMAP_STA_PS, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700729 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800730 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
731 GET_PS, 0, NULL, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700732
733 return ret;
734}
735
736/*
737 * IOCTL request handler to set/reset WPA IE.
738 *
739 * The supplied WPA IE is treated as a opaque buffer. Only the first field
740 * is checked to determine WPA version. If buffer length is zero, the existing
741 * WPA IE is reset.
742 */
743static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
744 u8 *ie_data_ptr, u16 ie_len)
745{
746 if (ie_len) {
747 if (ie_len > sizeof(priv->wpa_ie)) {
748 dev_err(priv->adapter->dev,
749 "failed to copy WPA IE, too big\n");
750 return -1;
751 }
752 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
753 priv->wpa_ie_len = (u8) ie_len;
754 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700755 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700756
Arend van Spriel04b23122012-10-12 12:28:14 +0200757 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700758 priv->sec_info.wpa_enabled = true;
759 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
760 priv->sec_info.wpa2_enabled = true;
761 } else {
762 priv->sec_info.wpa_enabled = false;
763 priv->sec_info.wpa2_enabled = false;
764 }
765 } else {
766 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
767 priv->wpa_ie_len = 0;
768 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
769 priv->wpa_ie_len, priv->wpa_ie[0]);
770 priv->sec_info.wpa_enabled = false;
771 priv->sec_info.wpa2_enabled = false;
772 }
773
774 return 0;
775}
776
777/*
778 * IOCTL request handler to set/reset WAPI IE.
779 *
780 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
781 * is checked to internally enable WAPI. If buffer length is zero, the existing
782 * WAPI IE is reset.
783 */
784static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
785 u8 *ie_data_ptr, u16 ie_len)
786{
787 if (ie_len) {
788 if (ie_len > sizeof(priv->wapi_ie)) {
789 dev_dbg(priv->adapter->dev,
790 "info: failed to copy WAPI IE, too big\n");
791 return -1;
792 }
793 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
794 priv->wapi_ie_len = ie_len;
795 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700796 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700797
798 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
799 priv->sec_info.wapi_enabled = true;
800 } else {
801 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
802 priv->wapi_ie_len = ie_len;
803 dev_dbg(priv->adapter->dev,
804 "info: Reset wapi_ie_len=%d IE=%#x\n",
805 priv->wapi_ie_len, priv->wapi_ie[0]);
806 priv->sec_info.wapi_enabled = false;
807 }
808 return 0;
809}
810
811/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700812 * IOCTL request handler to set/reset WPS IE.
813 *
814 * The supplied WPS IE is treated as a opaque buffer. Only the first field
815 * is checked to internally enable WPS. If buffer length is zero, the existing
816 * WPS IE is reset.
817 */
818static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
819 u8 *ie_data_ptr, u16 ie_len)
820{
821 if (ie_len) {
Avinash Patil8795ca62013-07-22 19:17:46 -0700822 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
823 dev_dbg(priv->adapter->dev,
824 "info: failed to copy WPS IE, too big\n");
825 return -1;
826 }
827
Avinash Patil13d7ba782012-04-09 20:06:56 -0700828 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
829 if (!priv->wps_ie)
830 return -ENOMEM;
Avinash Patil8795ca62013-07-22 19:17:46 -0700831
Avinash Patil13d7ba782012-04-09 20:06:56 -0700832 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
833 priv->wps_ie_len = ie_len;
834 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
835 priv->wps_ie_len, priv->wps_ie[0]);
836 } else {
837 kfree(priv->wps_ie);
838 priv->wps_ie_len = ie_len;
839 dev_dbg(priv->adapter->dev,
840 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
841 }
842 return 0;
843}
844
845/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700846 * IOCTL request handler to set WAPI key.
847 *
848 * This function prepares the correct firmware command and
849 * issues it.
850 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700851static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700852 struct mwifiex_ds_encrypt_key *encrypt_key)
853{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700854
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800855 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
856 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
857 encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700858}
859
860/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700861 * IOCTL request handler to set WEP network key.
862 *
863 * This function prepares the correct firmware command and
864 * issues it, after validation checks.
865 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700866static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700867 struct mwifiex_ds_encrypt_key *encrypt_key)
868{
Avinash Patile57f1732014-02-07 16:32:35 -0800869 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700870 int ret;
871 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700872 int index;
873
874 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
875 priv->wep_key_curr_index = 0;
876 wep_key = &priv->wep_key[priv->wep_key_curr_index];
877 index = encrypt_key->key_index;
878 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800879 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700880 } else if (!encrypt_key->key_len) {
881 /* Copy the required key as the current key */
882 wep_key = &priv->wep_key[index];
883 if (!wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800884 dev_err(adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700885 "key not set, so cannot enable it\n");
886 return -1;
887 }
Avinash Patile57f1732014-02-07 16:32:35 -0800888
889 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2) {
890 memcpy(encrypt_key->key_material,
891 wep_key->key_material, wep_key->key_length);
892 encrypt_key->key_len = wep_key->key_length;
893 }
894
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700895 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800896 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700897 } else {
898 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700899 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
900 /* Copy the key in the driver */
901 memcpy(wep_key->key_material,
902 encrypt_key->key_material,
903 encrypt_key->key_len);
904 wep_key->key_index = index;
905 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800906 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700907 }
908 if (wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800909 void *enc_key;
910
911 if (encrypt_key->key_disable)
912 memset(&priv->wep_key[index], 0,
913 sizeof(struct mwifiex_wep_key));
914
915 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2)
916 enc_key = encrypt_key;
917 else
918 enc_key = NULL;
919
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700920 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800921 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
922 HostCmd_ACT_GEN_SET, 0, enc_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700923 if (ret)
924 return ret;
925 }
Avinash Patile57f1732014-02-07 16:32:35 -0800926
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800927 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700928 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
929 else
930 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
931
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800932 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
933 HostCmd_ACT_GEN_SET, 0,
934 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700935
936 return ret;
937}
938
939/*
940 * IOCTL request handler to set WPA key.
941 *
942 * This function prepares the correct firmware command and
943 * issues it, after validation checks.
944 *
945 * Current driver only supports key length of up to 32 bytes.
946 *
947 * This function can also be used to disable a currently set key.
948 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700949static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700950 struct mwifiex_ds_encrypt_key *encrypt_key)
951{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700952 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700953 u8 remove_key = false;
954 struct host_cmd_ds_802_11_key_material *ibss_key;
955
956 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700957 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700958 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700959 return -1;
960 }
961
Bing Zhaoeecd8252011-03-28 17:55:41 -0700962 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700963 /*
964 * IBSS/WPA-None uses only one key (Group) for both receiving
965 * and sending unicast and multicast packets.
966 */
967 /* Send the key as PTK to firmware */
968 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800969 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
970 HostCmd_ACT_GEN_SET,
971 KEY_INFO_ENABLED, encrypt_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700972 if (ret)
973 return ret;
974
975 ibss_key = &priv->aes_key;
976 memset(ibss_key, 0,
977 sizeof(struct host_cmd_ds_802_11_key_material));
978 /* Copy the key in the driver */
979 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
980 encrypt_key->key_len);
981 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
982 sizeof(ibss_key->key_param_set.key_len));
983 ibss_key->key_param_set.key_type_id
984 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700985 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700986
987 /* Send the key as GTK to firmware */
988 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
989 }
990
991 if (!encrypt_key->key_index)
992 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
993
994 if (remove_key)
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800995 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
996 HostCmd_ACT_GEN_SET,
997 !KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700998 else
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800999 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
1000 HostCmd_ACT_GEN_SET,
1001 KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001002
1003 return ret;
1004}
1005
1006/*
1007 * IOCTL request handler to set/get network keys.
1008 *
1009 * This is a generic key handling function which supports WEP, WPA
1010 * and WAPI.
1011 */
1012static int
1013mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001014 struct mwifiex_ds_encrypt_key *encrypt_key)
1015{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001016 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001017
1018 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001019 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001020 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001021 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001023 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001024 return status;
1025}
1026
1027/*
1028 * This function returns the driver version.
1029 */
1030int
1031mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1032 int max_len)
1033{
1034 union {
1035 u32 l;
1036 u8 c[4];
1037 } ver;
1038 char fw_ver[32];
1039
1040 ver.l = adapter->fw_release_number;
1041 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1042
1043 snprintf(version, max_len, driver_version, fw_ver);
1044
1045 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1046
1047 return 0;
1048}
1049
1050/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001051 * Sends IOCTL request to set encoding parameters.
1052 *
1053 * This function allocates the IOCTL request buffer, fills it
1054 * with requisite parameters and calls the IOCTL handler.
1055 */
Ying Luo53b11232012-08-03 18:06:13 -07001056int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1057 const u8 *key, int key_len, u8 key_index,
1058 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001059{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001060 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001061
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001062 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1063 encrypt_key.key_len = key_len;
Avinash Patile57f1732014-02-07 16:32:35 -08001064 encrypt_key.key_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -07001065
1066 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1067 encrypt_key.is_igtk_key = true;
1068
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001069 if (!disable) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001070 if (key_len)
1071 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001072 else
1073 encrypt_key.is_current_wep_key = true;
1074
Avinash Patil75edd2c2012-05-08 18:30:18 -07001075 if (mac_addr)
1076 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Avinash Patile57f1732014-02-07 16:32:35 -08001077 if (kp && kp->seq && kp->seq_len) {
Ying Luo53b11232012-08-03 18:06:13 -07001078 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001079 encrypt_key.pn_len = kp->seq_len;
1080 encrypt_key.is_rx_seq_valid = true;
1081 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001082 } else {
Avinash Patile57f1732014-02-07 16:32:35 -08001083 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
1084 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001085 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001086 if (mac_addr)
1087 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001088 }
1089
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001090 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001091}
1092
1093/*
1094 * Sends IOCTL request to get extended version.
1095 *
1096 * This function allocates the IOCTL request buffer, fills it
1097 * with requisite parameters and calls the IOCTL handler.
1098 */
1099int
1100mwifiex_get_ver_ext(struct mwifiex_private *priv)
1101{
1102 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001104 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001105 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1106 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001107 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001108
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001109 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001110}
1111
Stone Piao7feb4c42012-09-25 20:23:36 -07001112int
1113mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1114 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001115 unsigned int duration)
1116{
1117 struct host_cmd_ds_remain_on_chan roc_cfg;
1118 u8 sc;
1119
1120 memset(&roc_cfg, 0, sizeof(roc_cfg));
1121 roc_cfg.action = cpu_to_le16(action);
1122 if (action == HostCmd_ACT_GEN_SET) {
1123 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001124 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001125 roc_cfg.band_cfg |= (sc << 2);
1126
1127 roc_cfg.channel =
1128 ieee80211_frequency_to_channel(chan->center_freq);
1129 roc_cfg.duration = cpu_to_le32(duration);
1130 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001131 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1132 action, 0, &roc_cfg, true)) {
Stone Piao7feb4c42012-09-25 20:23:36 -07001133 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1134 return -1;
1135 }
1136
1137 return roc_cfg.status;
1138}
1139
Stone Piao9197ab92012-09-25 20:23:42 -07001140int
1141mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1142{
1143 if (GET_BSS_ROLE(priv) == bss_role) {
1144 dev_dbg(priv->adapter->dev,
1145 "info: already in the desired role.\n");
1146 return 0;
1147 }
1148
1149 mwifiex_free_priv(priv);
1150 mwifiex_init_priv(priv);
1151
1152 priv->bss_role = bss_role;
1153 switch (bss_role) {
1154 case MWIFIEX_BSS_ROLE_UAP:
1155 priv->bss_mode = NL80211_IFTYPE_AP;
1156 break;
1157 case MWIFIEX_BSS_ROLE_STA:
1158 case MWIFIEX_BSS_ROLE_ANY:
1159 default:
1160 priv->bss_mode = NL80211_IFTYPE_STATION;
1161 break;
1162 }
1163
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001164 mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1165 HostCmd_ACT_GEN_SET, 0, NULL, true);
Stone Piao9197ab92012-09-25 20:23:42 -07001166
1167 return mwifiex_sta_init_cmd(priv, false);
1168}
1169
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001170/*
1171 * Sends IOCTL request to get statistics information.
1172 *
1173 * This function allocates the IOCTL request buffer, fills it
1174 * with requisite parameters and calls the IOCTL handler.
1175 */
1176int
1177mwifiex_get_stats_info(struct mwifiex_private *priv,
1178 struct mwifiex_ds_get_stats *log)
1179{
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001180 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1181 HostCmd_ACT_GEN_GET, 0, log, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001182}
1183
1184/*
1185 * IOCTL request handler to read/write register.
1186 *
1187 * This function prepares the correct firmware command and
1188 * issues it.
1189 *
1190 * Access to the following registers are supported -
1191 * - MAC
1192 * - BBP
1193 * - RF
1194 * - PMIC
1195 * - CAU
1196 */
1197static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001198 struct mwifiex_ds_reg_rw *reg_rw,
1199 u16 action)
1200{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001201 u16 cmd_no;
1202
1203 switch (le32_to_cpu(reg_rw->type)) {
1204 case MWIFIEX_REG_MAC:
1205 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1206 break;
1207 case MWIFIEX_REG_BBP:
1208 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1209 break;
1210 case MWIFIEX_REG_RF:
1211 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1212 break;
1213 case MWIFIEX_REG_PMIC:
1214 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1215 break;
1216 case MWIFIEX_REG_CAU:
1217 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1218 break;
1219 default:
1220 return -1;
1221 }
1222
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001223 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001224}
1225
1226/*
1227 * Sends IOCTL request to write to a register.
1228 *
1229 * This function allocates the IOCTL request buffer, fills it
1230 * with requisite parameters and calls the IOCTL handler.
1231 */
1232int
1233mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1234 u32 reg_offset, u32 reg_value)
1235{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001236 struct mwifiex_ds_reg_rw reg_rw;
1237
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001238 reg_rw.type = cpu_to_le32(reg_type);
1239 reg_rw.offset = cpu_to_le32(reg_offset);
1240 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001241
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001242 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001243}
1244
1245/*
1246 * Sends IOCTL request to read from a register.
1247 *
1248 * This function allocates the IOCTL request buffer, fills it
1249 * with requisite parameters and calls the IOCTL handler.
1250 */
1251int
1252mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1253 u32 reg_offset, u32 *value)
1254{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001255 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001256 struct mwifiex_ds_reg_rw reg_rw;
1257
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001258 reg_rw.type = cpu_to_le32(reg_type);
1259 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001260 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001262 if (ret)
1263 goto done;
1264
1265 *value = le32_to_cpu(reg_rw.value);
1266
1267done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001268 return ret;
1269}
1270
1271/*
1272 * Sends IOCTL request to read from EEPROM.
1273 *
1274 * This function allocates the IOCTL request buffer, fills it
1275 * with requisite parameters and calls the IOCTL handler.
1276 */
1277int
1278mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1279 u8 *value)
1280{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001281 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001282 struct mwifiex_ds_read_eeprom rd_eeprom;
1283
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001284 rd_eeprom.offset = cpu_to_le16((u16) offset);
1285 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001286
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001287 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001288 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1289 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001290
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001291 if (!ret)
1292 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001293 return ret;
1294}
1295
1296/*
1297 * This function sets a generic IE. In addition to generic IE, it can
1298 * also handle WPA, WPA2 and WAPI IEs.
1299 */
1300static int
1301mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1302 u16 ie_len)
1303{
1304 int ret = 0;
1305 struct ieee_types_vendor_header *pvendor_ie;
1306 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1307 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1308
1309 /* If the passed length is zero, reset the buffer */
1310 if (!ie_len) {
1311 priv->gen_ie_buf_len = 0;
1312 priv->wps.session_enable = false;
1313
1314 return 0;
1315 } else if (!ie_data_ptr) {
1316 return -1;
1317 }
1318 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1319 /* 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 +02001320 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001321 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1322 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001323
1324 /* IE is a WPA/WPA2 IE so call set_wpa function */
1325 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1326 priv->wps.session_enable = false;
1327
1328 return ret;
1329 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1330 /* IE is a WAPI IE so call set_wapi function */
1331 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1332
1333 return ret;
1334 }
1335 /*
1336 * Verify that the passed length is not larger than the
1337 * available space remaining in the buffer
1338 */
1339 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1340
1341 /* Test to see if it is a WPS IE, if so, enable
1342 * wps session flag
1343 */
1344 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001345 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1346 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001347 priv->wps.session_enable = true;
1348 dev_dbg(priv->adapter->dev,
1349 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001350 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001351 }
1352
1353 /* Append the passed data to the end of the
1354 genIeBuffer */
1355 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001356 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001357 /* Increment the stored buffer length by the
1358 size passed */
1359 priv->gen_ie_buf_len += ie_len;
1360 } else {
1361 /* Passed data does not fit in the remaining
1362 buffer space */
1363 ret = -1;
1364 }
1365
1366 /* Return 0, or -1 for error case */
1367 return ret;
1368}
1369
1370/*
1371 * IOCTL request handler to set/get generic IE.
1372 *
1373 * In addition to various generic IEs, this function can also be
1374 * used to set the ARP filter.
1375 */
1376static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1377 struct mwifiex_ds_misc_gen_ie *gen_ie,
1378 u16 action)
1379{
1380 struct mwifiex_adapter *adapter = priv->adapter;
1381
1382 switch (gen_ie->type) {
1383 case MWIFIEX_IE_TYPE_GEN_IE:
1384 if (action == HostCmd_ACT_GEN_GET) {
1385 gen_ie->len = priv->wpa_ie_len;
1386 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1387 } else {
1388 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1389 (u16) gen_ie->len);
1390 }
1391 break;
1392 case MWIFIEX_IE_TYPE_ARP_FILTER:
1393 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1394 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1395 adapter->arp_filter_size = 0;
1396 dev_err(adapter->dev, "invalid ARP filter size\n");
1397 return -1;
1398 } else {
1399 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001400 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001401 adapter->arp_filter_size = gen_ie->len;
1402 }
1403 break;
1404 default:
1405 dev_err(adapter->dev, "invalid IE type\n");
1406 return -1;
1407 }
1408 return 0;
1409}
1410
1411/*
1412 * Sends IOCTL request to set a generic IE.
1413 *
1414 * This function allocates the IOCTL request buffer, fills it
1415 * with requisite parameters and calls the IOCTL handler.
1416 */
1417int
Johannes Berg4b5800f2014-01-15 14:55:59 +01001418mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001419{
1420 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001421
Bing Zhao67a50032011-07-13 18:38:34 -07001422 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001423 return -EFAULT;
1424
1425 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1426 gen_ie.len = ie_len;
1427 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001428 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001429 return -EFAULT;
1430
1431 return 0;
1432}