blob: 888f3ae9df83866bc337ca41e21732bc888702fc [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
Bing Zhao9c969d82013-01-02 16:07:35 -0800523 if (wait_event_interruptible(adapter->hs_activate_wait_q,
524 adapter->hs_activate_wait_q_woken)) {
525 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
526 return false;
527 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700528
529 return true;
530}
531EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
532
533/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700534 * IOCTL request handler to get BSS information.
535 *
536 * This function collates the information from different driver structures
537 * to send to the user.
538 */
539int mwifiex_get_bss_info(struct mwifiex_private *priv,
540 struct mwifiex_bss_info *info)
541{
542 struct mwifiex_adapter *adapter = priv->adapter;
543 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700544
545 if (!info)
546 return -1;
547
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700548 bss_desc = &priv->curr_bss_params.bss_descriptor;
549
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700550 info->bss_mode = priv->bss_mode;
551
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800552 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700554 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
555
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700556 info->bss_chan = bss_desc->channel;
557
Avinash Patil67fdf392012-05-08 18:30:17 -0700558 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700559 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700560
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700561 info->media_connected = priv->media_connected;
562
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700563 info->max_power_level = priv->max_tx_power_level;
564 info->min_power_level = priv->min_tx_power_level;
565
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700566 info->adhoc_state = priv->adhoc_state;
567
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700568 info->bcn_nf_last = priv->bcn_nf_last;
569
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800570 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700571 info->wep_status = true;
572 else
573 info->wep_status = false;
574
575 info->is_hs_configured = adapter->is_hs_configured;
576 info->is_deep_sleep = adapter->is_deep_sleep;
577
578 return 0;
579}
580
581/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700582 * The function disables auto deep sleep mode.
583 */
584int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
585{
586 struct mwifiex_ds_auto_ds auto_ds;
587
588 auto_ds.auto_ds = DEEP_SLEEP_OFF;
589
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800590 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
591 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
Amitkumar Karwara0490932011-07-13 20:51:59 -0700592}
593EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
594
595/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700596 * Sends IOCTL request to get the data rate.
597 *
598 * This function allocates the IOCTL request buffer, fills it
599 * with requisite parameters and calls the IOCTL handler.
600 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700601int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700602{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700603 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700604
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800605 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
606 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700607
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700608 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700609 if (priv->is_data_rate_auto)
610 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
611 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300612 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700613 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700614 }
615
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700616 return ret;
617}
618
619/*
620 * IOCTL request handler to set tx power configuration.
621 *
622 * This function prepares the correct firmware command and
623 * issues it.
624 *
625 * For non-auto power mode, all the following power groups are set -
626 * - Modulation class HR/DSSS
627 * - Modulation class OFDM
628 * - Modulation class HTBW20
629 * - Modulation class HTBW40
630 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700631int mwifiex_set_tx_power(struct mwifiex_private *priv,
632 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700633{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700634 int ret;
635 struct host_cmd_ds_txpwr_cfg *txp_cfg;
636 struct mwifiex_types_power_group *pg_tlv;
637 struct mwifiex_power_group *pg;
638 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700639 u16 dbm = 0;
640
641 if (!power_cfg->is_power_auto) {
642 dbm = (u16) power_cfg->power_level;
643 if ((dbm < priv->min_tx_power_level) ||
644 (dbm > priv->max_tx_power_level)) {
645 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700646 " is out of range (%d dBm-%d dBm)\n",
647 dbm, priv->min_tx_power_level,
648 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700649 return -1;
650 }
651 }
652 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000653 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200654 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700655
656 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
657 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
658 if (!power_cfg->is_power_auto) {
659 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700660 pg_tlv = (struct mwifiex_types_power_group *)
661 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700662 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
663 pg_tlv->length =
664 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700665 pg = (struct mwifiex_power_group *)
666 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
667 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700668 /* Power group for modulation class HR/DSSS */
669 pg->first_rate_code = 0x00;
670 pg->last_rate_code = 0x03;
671 pg->modulation_class = MOD_CLASS_HR_DSSS;
672 pg->power_step = 0;
673 pg->power_min = (s8) dbm;
674 pg->power_max = (s8) dbm;
675 pg++;
676 /* Power group for modulation class OFDM */
677 pg->first_rate_code = 0x00;
678 pg->last_rate_code = 0x07;
679 pg->modulation_class = MOD_CLASS_OFDM;
680 pg->power_step = 0;
681 pg->power_min = (s8) dbm;
682 pg->power_max = (s8) dbm;
683 pg++;
684 /* Power group for modulation class HTBW20 */
685 pg->first_rate_code = 0x00;
686 pg->last_rate_code = 0x20;
687 pg->modulation_class = MOD_CLASS_HT;
688 pg->power_step = 0;
689 pg->power_min = (s8) dbm;
690 pg->power_max = (s8) dbm;
691 pg->ht_bandwidth = HT_BW_20;
692 pg++;
693 /* Power group for modulation class HTBW40 */
694 pg->first_rate_code = 0x00;
695 pg->last_rate_code = 0x20;
696 pg->modulation_class = MOD_CLASS_HT;
697 pg->power_step = 0;
698 pg->power_min = (s8) dbm;
699 pg->power_max = (s8) dbm;
700 pg->ht_bandwidth = HT_BW_40;
701 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800702 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
703 HostCmd_ACT_GEN_SET, 0, buf, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700704
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700705 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700706 return ret;
707}
708
709/*
710 * IOCTL request handler to get power save mode.
711 *
712 * This function prepares the correct firmware command and
713 * issues it.
714 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700715int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700716{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700717 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700718 struct mwifiex_adapter *adapter = priv->adapter;
719 u16 sub_cmd;
720
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700721 if (*ps_mode)
722 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
723 else
724 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
725 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800726 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
727 sub_cmd, BITMAP_STA_PS, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700728 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800729 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
730 GET_PS, 0, NULL, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700731
732 return ret;
733}
734
735/*
736 * IOCTL request handler to set/reset WPA IE.
737 *
738 * The supplied WPA IE is treated as a opaque buffer. Only the first field
739 * is checked to determine WPA version. If buffer length is zero, the existing
740 * WPA IE is reset.
741 */
742static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
743 u8 *ie_data_ptr, u16 ie_len)
744{
745 if (ie_len) {
746 if (ie_len > sizeof(priv->wpa_ie)) {
747 dev_err(priv->adapter->dev,
748 "failed to copy WPA IE, too big\n");
749 return -1;
750 }
751 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
752 priv->wpa_ie_len = (u8) ie_len;
753 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700754 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700755
Arend van Spriel04b23122012-10-12 12:28:14 +0200756 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700757 priv->sec_info.wpa_enabled = true;
758 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
759 priv->sec_info.wpa2_enabled = true;
760 } else {
761 priv->sec_info.wpa_enabled = false;
762 priv->sec_info.wpa2_enabled = false;
763 }
764 } else {
765 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
766 priv->wpa_ie_len = 0;
767 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
768 priv->wpa_ie_len, priv->wpa_ie[0]);
769 priv->sec_info.wpa_enabled = false;
770 priv->sec_info.wpa2_enabled = false;
771 }
772
773 return 0;
774}
775
776/*
777 * IOCTL request handler to set/reset WAPI IE.
778 *
779 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
780 * is checked to internally enable WAPI. If buffer length is zero, the existing
781 * WAPI IE is reset.
782 */
783static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
784 u8 *ie_data_ptr, u16 ie_len)
785{
786 if (ie_len) {
787 if (ie_len > sizeof(priv->wapi_ie)) {
788 dev_dbg(priv->adapter->dev,
789 "info: failed to copy WAPI IE, too big\n");
790 return -1;
791 }
792 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
793 priv->wapi_ie_len = ie_len;
794 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700795 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700796
797 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
798 priv->sec_info.wapi_enabled = true;
799 } else {
800 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
801 priv->wapi_ie_len = ie_len;
802 dev_dbg(priv->adapter->dev,
803 "info: Reset wapi_ie_len=%d IE=%#x\n",
804 priv->wapi_ie_len, priv->wapi_ie[0]);
805 priv->sec_info.wapi_enabled = false;
806 }
807 return 0;
808}
809
810/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700811 * IOCTL request handler to set/reset WPS IE.
812 *
813 * The supplied WPS IE is treated as a opaque buffer. Only the first field
814 * is checked to internally enable WPS. If buffer length is zero, the existing
815 * WPS IE is reset.
816 */
817static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
818 u8 *ie_data_ptr, u16 ie_len)
819{
820 if (ie_len) {
Avinash Patil8795ca62013-07-22 19:17:46 -0700821 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
822 dev_dbg(priv->adapter->dev,
823 "info: failed to copy WPS IE, too big\n");
824 return -1;
825 }
826
Avinash Patil13d7ba782012-04-09 20:06:56 -0700827 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
828 if (!priv->wps_ie)
829 return -ENOMEM;
Avinash Patil8795ca62013-07-22 19:17:46 -0700830
Avinash Patil13d7ba782012-04-09 20:06:56 -0700831 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
832 priv->wps_ie_len = ie_len;
833 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
834 priv->wps_ie_len, priv->wps_ie[0]);
835 } else {
836 kfree(priv->wps_ie);
837 priv->wps_ie_len = ie_len;
838 dev_dbg(priv->adapter->dev,
839 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
840 }
841 return 0;
842}
843
844/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700845 * IOCTL request handler to set WAPI key.
846 *
847 * This function prepares the correct firmware command and
848 * issues it.
849 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700850static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700851 struct mwifiex_ds_encrypt_key *encrypt_key)
852{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700853
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800854 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
855 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
856 encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700857}
858
859/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700860 * IOCTL request handler to set WEP network key.
861 *
862 * This function prepares the correct firmware command and
863 * issues it, after validation checks.
864 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700865static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700866 struct mwifiex_ds_encrypt_key *encrypt_key)
867{
Avinash Patile57f1732014-02-07 16:32:35 -0800868 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700869 int ret;
870 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700871 int index;
872
873 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
874 priv->wep_key_curr_index = 0;
875 wep_key = &priv->wep_key[priv->wep_key_curr_index];
876 index = encrypt_key->key_index;
877 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800878 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700879 } else if (!encrypt_key->key_len) {
880 /* Copy the required key as the current key */
881 wep_key = &priv->wep_key[index];
882 if (!wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800883 dev_err(adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700884 "key not set, so cannot enable it\n");
885 return -1;
886 }
Avinash Patile57f1732014-02-07 16:32:35 -0800887
888 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2) {
889 memcpy(encrypt_key->key_material,
890 wep_key->key_material, wep_key->key_length);
891 encrypt_key->key_len = wep_key->key_length;
892 }
893
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700894 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800895 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700896 } else {
897 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700898 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
899 /* Copy the key in the driver */
900 memcpy(wep_key->key_material,
901 encrypt_key->key_material,
902 encrypt_key->key_len);
903 wep_key->key_index = index;
904 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800905 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700906 }
907 if (wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800908 void *enc_key;
909
910 if (encrypt_key->key_disable)
911 memset(&priv->wep_key[index], 0,
912 sizeof(struct mwifiex_wep_key));
913
914 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2)
915 enc_key = encrypt_key;
916 else
917 enc_key = NULL;
918
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700919 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800920 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
921 HostCmd_ACT_GEN_SET, 0, enc_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700922 if (ret)
923 return ret;
924 }
Avinash Patile57f1732014-02-07 16:32:35 -0800925
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800926 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700927 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
928 else
929 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
930
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800931 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
932 HostCmd_ACT_GEN_SET, 0,
933 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700934
935 return ret;
936}
937
938/*
939 * IOCTL request handler to set WPA key.
940 *
941 * This function prepares the correct firmware command and
942 * issues it, after validation checks.
943 *
944 * Current driver only supports key length of up to 32 bytes.
945 *
946 * This function can also be used to disable a currently set key.
947 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700948static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700949 struct mwifiex_ds_encrypt_key *encrypt_key)
950{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700951 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700952 u8 remove_key = false;
953 struct host_cmd_ds_802_11_key_material *ibss_key;
954
955 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700956 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700957 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700958 return -1;
959 }
960
Bing Zhaoeecd8252011-03-28 17:55:41 -0700961 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700962 /*
963 * IBSS/WPA-None uses only one key (Group) for both receiving
964 * and sending unicast and multicast packets.
965 */
966 /* Send the key as PTK to firmware */
967 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800968 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
969 HostCmd_ACT_GEN_SET,
970 KEY_INFO_ENABLED, encrypt_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700971 if (ret)
972 return ret;
973
974 ibss_key = &priv->aes_key;
975 memset(ibss_key, 0,
976 sizeof(struct host_cmd_ds_802_11_key_material));
977 /* Copy the key in the driver */
978 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
979 encrypt_key->key_len);
980 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
981 sizeof(ibss_key->key_param_set.key_len));
982 ibss_key->key_param_set.key_type_id
983 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700984 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700985
986 /* Send the key as GTK to firmware */
987 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
988 }
989
990 if (!encrypt_key->key_index)
991 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
992
993 if (remove_key)
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800994 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
995 HostCmd_ACT_GEN_SET,
996 !KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700997 else
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800998 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
999 HostCmd_ACT_GEN_SET,
1000 KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001001
1002 return ret;
1003}
1004
1005/*
1006 * IOCTL request handler to set/get network keys.
1007 *
1008 * This is a generic key handling function which supports WEP, WPA
1009 * and WAPI.
1010 */
1011static int
1012mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001013 struct mwifiex_ds_encrypt_key *encrypt_key)
1014{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001015 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001016
1017 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001018 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001019 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001020 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001021 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001022 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001023 return status;
1024}
1025
1026/*
1027 * This function returns the driver version.
1028 */
1029int
1030mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1031 int max_len)
1032{
1033 union {
1034 u32 l;
1035 u8 c[4];
1036 } ver;
1037 char fw_ver[32];
1038
1039 ver.l = adapter->fw_release_number;
1040 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1041
1042 snprintf(version, max_len, driver_version, fw_ver);
1043
1044 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1045
1046 return 0;
1047}
1048
1049/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001050 * Sends IOCTL request to set encoding parameters.
1051 *
1052 * This function allocates the IOCTL request buffer, fills it
1053 * with requisite parameters and calls the IOCTL handler.
1054 */
Ying Luo53b11232012-08-03 18:06:13 -07001055int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1056 const u8 *key, int key_len, u8 key_index,
1057 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001059 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001060
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001061 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1062 encrypt_key.key_len = key_len;
Avinash Patile57f1732014-02-07 16:32:35 -08001063 encrypt_key.key_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -07001064
1065 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1066 encrypt_key.is_igtk_key = true;
1067
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001068 if (!disable) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001069 if (key_len)
1070 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001071 else
1072 encrypt_key.is_current_wep_key = true;
1073
Avinash Patil75edd2c2012-05-08 18:30:18 -07001074 if (mac_addr)
1075 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Avinash Patile57f1732014-02-07 16:32:35 -08001076 if (kp && kp->seq && kp->seq_len) {
Ying Luo53b11232012-08-03 18:06:13 -07001077 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001078 encrypt_key.pn_len = kp->seq_len;
1079 encrypt_key.is_rx_seq_valid = true;
1080 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001081 } else {
Avinash Patile57f1732014-02-07 16:32:35 -08001082 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
1083 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001084 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001085 if (mac_addr)
1086 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001087 }
1088
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001089 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001090}
1091
1092/*
1093 * Sends IOCTL request to get extended version.
1094 *
1095 * This function allocates the IOCTL request buffer, fills it
1096 * with requisite parameters and calls the IOCTL handler.
1097 */
1098int
1099mwifiex_get_ver_ext(struct mwifiex_private *priv)
1100{
1101 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001102
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001103 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001104 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1105 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001106 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001107
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001108 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001109}
1110
Stone Piao7feb4c42012-09-25 20:23:36 -07001111int
1112mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1113 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001114 unsigned int duration)
1115{
1116 struct host_cmd_ds_remain_on_chan roc_cfg;
1117 u8 sc;
1118
1119 memset(&roc_cfg, 0, sizeof(roc_cfg));
1120 roc_cfg.action = cpu_to_le16(action);
1121 if (action == HostCmd_ACT_GEN_SET) {
1122 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001123 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001124 roc_cfg.band_cfg |= (sc << 2);
1125
1126 roc_cfg.channel =
1127 ieee80211_frequency_to_channel(chan->center_freq);
1128 roc_cfg.duration = cpu_to_le32(duration);
1129 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001130 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1131 action, 0, &roc_cfg, true)) {
Stone Piao7feb4c42012-09-25 20:23:36 -07001132 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1133 return -1;
1134 }
1135
1136 return roc_cfg.status;
1137}
1138
Stone Piao9197ab92012-09-25 20:23:42 -07001139int
1140mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1141{
1142 if (GET_BSS_ROLE(priv) == bss_role) {
1143 dev_dbg(priv->adapter->dev,
1144 "info: already in the desired role.\n");
1145 return 0;
1146 }
1147
1148 mwifiex_free_priv(priv);
1149 mwifiex_init_priv(priv);
1150
1151 priv->bss_role = bss_role;
1152 switch (bss_role) {
1153 case MWIFIEX_BSS_ROLE_UAP:
1154 priv->bss_mode = NL80211_IFTYPE_AP;
1155 break;
1156 case MWIFIEX_BSS_ROLE_STA:
1157 case MWIFIEX_BSS_ROLE_ANY:
1158 default:
1159 priv->bss_mode = NL80211_IFTYPE_STATION;
1160 break;
1161 }
1162
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001163 mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1164 HostCmd_ACT_GEN_SET, 0, NULL, true);
Stone Piao9197ab92012-09-25 20:23:42 -07001165
1166 return mwifiex_sta_init_cmd(priv, false);
1167}
1168
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001169/*
1170 * Sends IOCTL request to get statistics information.
1171 *
1172 * This function allocates the IOCTL request buffer, fills it
1173 * with requisite parameters and calls the IOCTL handler.
1174 */
1175int
1176mwifiex_get_stats_info(struct mwifiex_private *priv,
1177 struct mwifiex_ds_get_stats *log)
1178{
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001179 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1180 HostCmd_ACT_GEN_GET, 0, log, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001181}
1182
1183/*
1184 * IOCTL request handler to read/write register.
1185 *
1186 * This function prepares the correct firmware command and
1187 * issues it.
1188 *
1189 * Access to the following registers are supported -
1190 * - MAC
1191 * - BBP
1192 * - RF
1193 * - PMIC
1194 * - CAU
1195 */
1196static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001197 struct mwifiex_ds_reg_rw *reg_rw,
1198 u16 action)
1199{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001200 u16 cmd_no;
1201
1202 switch (le32_to_cpu(reg_rw->type)) {
1203 case MWIFIEX_REG_MAC:
1204 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1205 break;
1206 case MWIFIEX_REG_BBP:
1207 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1208 break;
1209 case MWIFIEX_REG_RF:
1210 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1211 break;
1212 case MWIFIEX_REG_PMIC:
1213 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1214 break;
1215 case MWIFIEX_REG_CAU:
1216 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1217 break;
1218 default:
1219 return -1;
1220 }
1221
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001222 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001223}
1224
1225/*
1226 * Sends IOCTL request to write to a register.
1227 *
1228 * This function allocates the IOCTL request buffer, fills it
1229 * with requisite parameters and calls the IOCTL handler.
1230 */
1231int
1232mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1233 u32 reg_offset, u32 reg_value)
1234{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001235 struct mwifiex_ds_reg_rw reg_rw;
1236
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001237 reg_rw.type = cpu_to_le32(reg_type);
1238 reg_rw.offset = cpu_to_le32(reg_offset);
1239 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001240
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001241 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001242}
1243
1244/*
1245 * Sends IOCTL request to read from a register.
1246 *
1247 * This function allocates the IOCTL request buffer, fills it
1248 * with requisite parameters and calls the IOCTL handler.
1249 */
1250int
1251mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1252 u32 reg_offset, u32 *value)
1253{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001254 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001255 struct mwifiex_ds_reg_rw reg_rw;
1256
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001257 reg_rw.type = cpu_to_le32(reg_type);
1258 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001259 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001260
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001261 if (ret)
1262 goto done;
1263
1264 *value = le32_to_cpu(reg_rw.value);
1265
1266done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001267 return ret;
1268}
1269
1270/*
1271 * Sends IOCTL request to read from EEPROM.
1272 *
1273 * This function allocates the IOCTL request buffer, fills it
1274 * with requisite parameters and calls the IOCTL handler.
1275 */
1276int
1277mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1278 u8 *value)
1279{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001280 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001281 struct mwifiex_ds_read_eeprom rd_eeprom;
1282
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001283 rd_eeprom.offset = cpu_to_le16((u16) offset);
1284 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001285
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001286 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001287 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1288 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001289
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001290 if (!ret)
1291 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001292 return ret;
1293}
1294
1295/*
1296 * This function sets a generic IE. In addition to generic IE, it can
1297 * also handle WPA, WPA2 and WAPI IEs.
1298 */
1299static int
1300mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1301 u16 ie_len)
1302{
1303 int ret = 0;
1304 struct ieee_types_vendor_header *pvendor_ie;
1305 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1306 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1307
1308 /* If the passed length is zero, reset the buffer */
1309 if (!ie_len) {
1310 priv->gen_ie_buf_len = 0;
1311 priv->wps.session_enable = false;
1312
1313 return 0;
1314 } else if (!ie_data_ptr) {
1315 return -1;
1316 }
1317 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1318 /* 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 +02001319 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001320 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1321 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001322
1323 /* IE is a WPA/WPA2 IE so call set_wpa function */
1324 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1325 priv->wps.session_enable = false;
1326
1327 return ret;
1328 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1329 /* IE is a WAPI IE so call set_wapi function */
1330 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1331
1332 return ret;
1333 }
1334 /*
1335 * Verify that the passed length is not larger than the
1336 * available space remaining in the buffer
1337 */
1338 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1339
1340 /* Test to see if it is a WPS IE, if so, enable
1341 * wps session flag
1342 */
1343 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001344 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1345 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001346 priv->wps.session_enable = true;
1347 dev_dbg(priv->adapter->dev,
1348 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001349 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001350 }
1351
1352 /* Append the passed data to the end of the
1353 genIeBuffer */
1354 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001355 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001356 /* Increment the stored buffer length by the
1357 size passed */
1358 priv->gen_ie_buf_len += ie_len;
1359 } else {
1360 /* Passed data does not fit in the remaining
1361 buffer space */
1362 ret = -1;
1363 }
1364
1365 /* Return 0, or -1 for error case */
1366 return ret;
1367}
1368
1369/*
1370 * IOCTL request handler to set/get generic IE.
1371 *
1372 * In addition to various generic IEs, this function can also be
1373 * used to set the ARP filter.
1374 */
1375static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1376 struct mwifiex_ds_misc_gen_ie *gen_ie,
1377 u16 action)
1378{
1379 struct mwifiex_adapter *adapter = priv->adapter;
1380
1381 switch (gen_ie->type) {
1382 case MWIFIEX_IE_TYPE_GEN_IE:
1383 if (action == HostCmd_ACT_GEN_GET) {
1384 gen_ie->len = priv->wpa_ie_len;
1385 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1386 } else {
1387 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1388 (u16) gen_ie->len);
1389 }
1390 break;
1391 case MWIFIEX_IE_TYPE_ARP_FILTER:
1392 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1393 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1394 adapter->arp_filter_size = 0;
1395 dev_err(adapter->dev, "invalid ARP filter size\n");
1396 return -1;
1397 } else {
1398 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001399 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001400 adapter->arp_filter_size = gen_ie->len;
1401 }
1402 break;
1403 default:
1404 dev_err(adapter->dev, "invalid IE type\n");
1405 return -1;
1406 }
1407 return 0;
1408}
1409
1410/*
1411 * Sends IOCTL request to set a generic IE.
1412 *
1413 * This function allocates the IOCTL request buffer, fills it
1414 * with requisite parameters and calls the IOCTL handler.
1415 */
1416int
Johannes Berg4b5800f2014-01-15 14:55:59 +01001417mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001418{
1419 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001420
Bing Zhao67a50032011-07-13 18:38:34 -07001421 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001422 return -EFAULT;
1423
1424 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1425 gen_ie.len = ie_len;
1426 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001427 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001428 return -EFAULT;
1429
1430 return 0;
1431}