blob: 2a9cfd563a07c7e1221e3d4230e14b2bd0ea939a [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);
67 return status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070068 }
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -080069
70 status = adapter->cmd_wait_q.status;
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070071 adapter->cmd_wait_q.status = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070072
Bing Zhao5e6e3a92011-03-21 18:00:50 -070073 return status;
74}
75
76/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -070077 * This function prepares the correct firmware command and
78 * issues it to set the multicast list.
79 *
80 * This function can be used to enable promiscuous mode, or enable all
81 * multicast packets, or to enable selective multicast.
82 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -070083int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
84 struct mwifiex_multicast_list *mcast_list)
Bing Zhao5e6e3a92011-03-21 18:00:50 -070085{
86 int ret = 0;
87 u16 old_pkt_filter;
88
89 old_pkt_filter = priv->curr_pkt_filter;
Bing Zhao5e6e3a92011-03-21 18:00:50 -070090
91 if (mcast_list->mode == MWIFIEX_PROMISC_MODE) {
92 dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n");
93 priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
94 priv->curr_pkt_filter &=
95 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
96 } else {
97 /* Multicast */
98 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE;
Daniel Drakeccd384b2013-05-08 15:37:19 -040099 if (mcast_list->mode == MWIFIEX_ALL_MULTI_MODE) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700100 dev_dbg(priv->adapter->dev,
101 "info: Enabling All Multicast!\n");
102 priv->curr_pkt_filter |=
103 HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
104 } else {
105 priv->curr_pkt_filter &=
106 ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE;
Daniel Drake6390d882013-06-14 15:24:24 -0400107 dev_dbg(priv->adapter->dev,
108 "info: Set multicast list=%d\n",
109 mcast_list->num_multicast_addr);
110 /* Send multicast addresses to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800111 ret = mwifiex_send_cmd(priv,
112 HostCmd_CMD_MAC_MULTICAST_ADR,
113 HostCmd_ACT_GEN_SET, 0,
114 mcast_list, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700115 }
116 }
117 dev_dbg(priv->adapter->dev,
118 "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n",
119 old_pkt_filter, priv->curr_pkt_filter);
120 if (old_pkt_filter != priv->curr_pkt_filter) {
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800121 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
122 HostCmd_ACT_GEN_SET,
123 0, &priv->curr_pkt_filter, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700124 }
125
126 return ret;
127}
128
129/*
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700130 * This function fills bss descriptor structure using provided
131 * information.
Bing Zhaod837a2a2013-04-12 10:34:17 -0700132 * beacon_ie buffer is allocated in this function. It is caller's
133 * responsibility to free the memory.
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700134 */
135int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700136 struct cfg80211_bss *bss,
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700137 struct mwifiex_bssdescriptor *bss_desc)
138{
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700139 u8 *beacon_ie;
John W. Linville403e1672012-12-06 14:58:41 -0500140 size_t beacon_ie_len;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700141 struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
Johannes Berg9caf0362012-11-29 01:25:20 +0100142 const struct cfg80211_bss_ies *ies;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700143
Johannes Berg9caf0362012-11-29 01:25:20 +0100144 rcu_read_lock();
145 ies = rcu_dereference(bss->ies);
Johannes Berg9caf0362012-11-29 01:25:20 +0100146 beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC);
147 beacon_ie_len = ies->len;
Johannes Berg8cef2c92013-02-05 16:54:31 +0100148 bss_desc->timestamp = ies->tsf;
Johannes Berg9caf0362012-11-29 01:25:20 +0100149 rcu_read_unlock();
150
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700151 if (!beacon_ie) {
152 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
153 return -ENOMEM;
154 }
155
156 memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
157 bss_desc->rssi = bss->signal;
Bing Zhaod837a2a2013-04-12 10:34:17 -0700158 /* The caller of this function will free beacon_ie */
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700159 bss_desc->beacon_buf = beacon_ie;
Johannes Berg904f1372012-11-28 21:53:45 +0100160 bss_desc->beacon_buf_size = beacon_ie_len;
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700161 bss_desc->beacon_period = bss->beacon_interval;
162 bss_desc->cap_info_bitmap = bss->capability;
Amitkumar Karwarb5abcf02012-04-16 21:36:52 -0700163 bss_desc->bss_band = bss_priv->band;
164 bss_desc->fw_tsf = bss_priv->fw_tsf;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700165 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
166 dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
167 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
168 } else {
169 bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL;
170 }
171 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS)
172 bss_desc->bss_mode = NL80211_IFTYPE_ADHOC;
173 else
174 bss_desc->bss_mode = NL80211_IFTYPE_STATION;
175
Bing Zhaoc43933e2013-04-12 10:34:18 -0700176 /* Disable 11ac by default. Enable it only where there
177 * exist VHT_CAP IE in AP beacon
178 */
179 bss_desc->disable_11ac = true;
180
Amitkumar Karwar2a7305c2013-06-19 08:49:05 -0700181 if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_SPECTRUM_MGMT)
182 bss_desc->sensed_11h = true;
183
Bing Zhaod837a2a2013-04-12 10:34:17 -0700184 return mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700185}
186
Bing Zhaob58df442014-01-08 15:45:57 -0800187void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv)
188{
189 if (priv->adapter->dt_node) {
190 char txpwr[] = {"marvell,00_txpwrlimit"};
191
192 memcpy(&txpwr[8], priv->adapter->country_code, 2);
193 mwifiex_dnld_dt_cfgdata(priv, priv->adapter->dt_node, txpwr);
194 }
195}
196
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700197static int mwifiex_process_country_ie(struct mwifiex_private *priv,
198 struct cfg80211_bss *bss)
199{
Johannes Berg9caf0362012-11-29 01:25:20 +0100200 const u8 *country_ie;
201 u8 country_ie_len;
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700202 struct mwifiex_802_11d_domain_reg *domain_info =
203 &priv->adapter->domain_reg;
204
Johannes Berg9caf0362012-11-29 01:25:20 +0100205 rcu_read_lock();
206 country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY);
207 if (!country_ie) {
208 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700209 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100210 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700211
212 country_ie_len = country_ie[1];
Johannes Berg9caf0362012-11-29 01:25:20 +0100213 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) {
214 rcu_read_unlock();
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700215 return 0;
Johannes Berg9caf0362012-11-29 01:25:20 +0100216 }
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700217
Bing Zhaodd4a9ac2013-12-13 18:32:59 -0800218 if (!strncmp(priv->adapter->country_code, &country_ie[2], 2)) {
219 rcu_read_unlock();
220 wiphy_dbg(priv->wdev->wiphy,
221 "11D: skip setting domain info in FW\n");
222 return 0;
223 }
224 memcpy(priv->adapter->country_code, &country_ie[2], 2);
225
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700226 domain_info->country_code[0] = country_ie[2];
227 domain_info->country_code[1] = country_ie[3];
228 domain_info->country_code[2] = ' ';
229
230 country_ie_len -= IEEE80211_COUNTRY_STRING_LEN;
231
232 domain_info->no_of_triplet =
233 country_ie_len / sizeof(struct ieee80211_country_ie_triplet);
234
235 memcpy((u8 *)domain_info->triplet,
236 &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len);
237
Johannes Berg9caf0362012-11-29 01:25:20 +0100238 rcu_read_unlock();
239
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800240 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO,
241 HostCmd_ACT_GEN_SET, 0, NULL, false)) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700242 wiphy_err(priv->adapter->wiphy,
243 "11D: setting domain info in FW\n");
244 return -1;
245 }
246
Bing Zhaob58df442014-01-08 15:45:57 -0800247 mwifiex_dnld_txpwr_table(priv);
Bing Zhao82efa162013-12-13 18:33:02 -0800248
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700249 return 0;
250}
251
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700252/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700253 * In Ad-Hoc mode, the IBSS is created if not found in scan list.
254 * In both Ad-Hoc and infra mode, an deauthentication is performed
255 * first.
256 */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700257int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800258 struct cfg80211_ssid *req_ssid)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700259{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700260 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700261 struct mwifiex_adapter *adapter = priv->adapter;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700262 struct mwifiex_bssdescriptor *bss_desc = NULL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700263
264 priv->scan_block = false;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700265
266 if (bss) {
Amitkumar Karware89e2da2012-09-10 18:30:45 -0700267 mwifiex_process_country_ie(priv, bss);
268
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700269 /* Allocate and fill new bss descriptor */
270 bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
Joe Perches0d2e7a52013-02-03 17:28:14 +0000271 GFP_KERNEL);
272 if (!bss_desc)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700273 return -ENOMEM;
Yogesh Ashok Powar5982b472011-08-29 13:21:10 -0700274
Amitkumar Karwar9558a402012-04-16 21:36:51 -0700275 ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700276 if (ret)
277 goto done;
278 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700279
Stone Piao6621fe12013-07-29 16:32:39 -0700280 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
281 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700282 u8 config_bands;
283
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700284 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700285 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700286 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700287
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700288 if (!bss_desc)
289 return -1;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800290
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700291 if (mwifiex_band_to_radio_type(bss_desc->bss_band) ==
292 HostCmd_SCAN_RADIO_TYPE_BG)
Bing Zhaof25b1432014-02-07 16:21:01 -0800293 config_bands = BAND_B | BAND_G | BAND_GN;
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700294 else
295 config_bands = BAND_A | BAND_AN | BAND_AAC;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800296
Amitkumar Karwarf2bbb072013-06-18 16:36:56 -0700297 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands))
298 adapter->config_bands = config_bands;
Amitkumar Karward7b9c522013-01-08 17:53:10 -0800299
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700300 ret = mwifiex_check_network_compatibility(priv, bss_desc);
301 if (ret)
302 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700303
Amitkumar Karwarb8876642013-06-18 16:36:58 -0700304 if (mwifiex_11h_get_csa_closed_channel(priv) ==
305 (u8)bss_desc->channel) {
306 dev_err(adapter->dev,
307 "Attempt to reconnect on csa closed chan(%d)\n",
308 bss_desc->channel);
309 goto done;
310 }
311
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700312 dev_dbg(adapter->dev, "info: SSID found in scan list ... "
313 "associating...\n");
314
Avinash Patil47411a02012-11-01 18:44:16 -0700315 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800316 if (netif_carrier_ok(priv->netdev))
317 netif_carrier_off(priv->netdev);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700318
319 /* Clear any past association response stored for
320 * application retrieval */
321 priv->assoc_rsp_size = 0;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700322 ret = mwifiex_associate(priv, bss_desc);
Amitkumar Karwara0f6d6c2012-02-24 21:36:05 -0800323
324 /* If auth type is auto and association fails using open mode,
325 * try to connect using shared mode */
326 if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG &&
327 priv->sec_info.is_authtype_auto &&
328 priv->sec_info.wep_enabled) {
329 priv->sec_info.authentication_mode =
330 NL80211_AUTHTYPE_SHARED_KEY;
331 ret = mwifiex_associate(priv, bss_desc);
332 }
333
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700334 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100335 cfg80211_put_bss(priv->adapter->wiphy, bss);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700336 } else {
337 /* Adhoc mode */
338 /* If the requested SSID matches current SSID, return */
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700339 if (bss_desc && bss_desc->ssid.ssid_len &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700340 (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
341 ssid, &bss_desc->ssid))) {
Ujjal Roy517543f2013-11-21 11:08:56 -0800342 ret = 0;
343 goto done;
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700344 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700345
346 /* Exit Adhoc mode first */
347 dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n");
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700348 ret = mwifiex_deauthenticate(priv, NULL);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700349 if (ret)
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700350 goto done;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700351
352 priv->adhoc_is_link_sensed = false;
353
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700354 ret = mwifiex_check_network_compatibility(priv, bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700355
Avinash Patil47411a02012-11-01 18:44:16 -0700356 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
Amitkumar Karwarb7097eb2012-02-01 20:41:43 -0800357 if (netif_carrier_ok(priv->netdev))
358 netif_carrier_off(priv->netdev);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700359
360 if (!ret) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700361 dev_dbg(adapter->dev, "info: network found in scan"
362 " list. Joining...\n");
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700363 ret = mwifiex_adhoc_join(priv, bss_desc);
364 if (bss)
Johannes Berg5b112d32013-02-01 01:49:58 +0100365 cfg80211_put_bss(priv->adapter->wiphy, bss);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700366 } else {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700367 dev_dbg(adapter->dev, "info: Network not found in "
368 "the list, creating adhoc with ssid = %s\n",
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700369 req_ssid->ssid);
370 ret = mwifiex_adhoc_start(priv, req_ssid);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700371 }
372 }
373
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700374done:
Bing Zhaod837a2a2013-04-12 10:34:17 -0700375 /* beacon_ie buffer was allocated in function
376 * mwifiex_fill_new_bss_desc(). Free it now.
377 */
378 if (bss_desc)
379 kfree(bss_desc->beacon_buf);
Amitkumar Karwar7c6fa2a2011-08-10 18:53:57 -0700380 kfree(bss_desc);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700381 return ret;
382}
383
384/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700385 * IOCTL request handler to set host sleep configuration.
386 *
387 * This function prepares the correct firmware command and
388 * issues it.
389 */
Amitkumar Karwar711825a2011-10-12 20:29:33 -0700390static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
391 int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700392
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700393{
394 struct mwifiex_adapter *adapter = priv->adapter;
395 int status = 0;
396 u32 prev_cond = 0;
397
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700398 if (!hs_cfg)
399 return -ENOMEM;
400
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700401 switch (action) {
402 case HostCmd_ACT_GEN_SET:
403 if (adapter->pps_uapsd_mode) {
404 dev_dbg(adapter->dev, "info: Host Sleep IOCTL"
405 " is blocked in UAPSD/PPS mode\n");
406 status = -1;
407 break;
408 }
409 if (hs_cfg->is_invoke_hostcmd) {
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800410 if (hs_cfg->conditions == HS_CFG_CANCEL) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700411 if (!adapter->is_hs_configured)
412 /* Already cancelled */
413 break;
414 /* Save previous condition */
415 prev_cond = le32_to_cpu(adapter->hs_cfg
416 .conditions);
417 adapter->hs_cfg.conditions =
418 cpu_to_le32(hs_cfg->conditions);
419 } else if (hs_cfg->conditions) {
420 adapter->hs_cfg.conditions =
421 cpu_to_le32(hs_cfg->conditions);
422 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
423 if (hs_cfg->gap)
424 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800425 } else if (adapter->hs_cfg.conditions ==
426 cpu_to_le32(HS_CFG_CANCEL)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700427 /* Return failure if no parameters for HS
428 enable */
429 status = -1;
430 break;
431 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800432
433 status = mwifiex_send_cmd(priv,
434 HostCmd_CMD_802_11_HS_CFG_ENH,
435 HostCmd_ACT_GEN_SET, 0,
436 &adapter->hs_cfg,
437 cmd_type == MWIFIEX_SYNC_CMD);
438
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800439 if (hs_cfg->conditions == HS_CFG_CANCEL)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700440 /* Restore previous condition */
441 adapter->hs_cfg.conditions =
442 cpu_to_le32(prev_cond);
443 } else {
444 adapter->hs_cfg.conditions =
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700445 cpu_to_le32(hs_cfg->conditions);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700446 adapter->hs_cfg.gpio = (u8)hs_cfg->gpio;
447 adapter->hs_cfg.gap = (u8)hs_cfg->gap;
448 }
449 break;
450 case HostCmd_ACT_GEN_GET:
451 hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions);
452 hs_cfg->gpio = adapter->hs_cfg.gpio;
453 hs_cfg->gap = adapter->hs_cfg.gap;
454 break;
455 default:
456 status = -1;
457 break;
458 }
459
460 return status;
461}
462
463/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700464 * Sends IOCTL request to cancel the existing Host Sleep configuration.
465 *
466 * This function allocates the IOCTL request buffer, fills it
467 * with requisite parameters and calls the IOCTL handler.
468 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700469int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700470{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700471 struct mwifiex_ds_hs_cfg hscfg;
472
Amitkumar Karwarcc0b5a62013-03-04 16:27:57 -0800473 hscfg.conditions = HS_CFG_CANCEL;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700474 hscfg.is_invoke_hostcmd = true;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700475
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -0700476 return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET,
477 cmd_type, &hscfg);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700478}
479EXPORT_SYMBOL_GPL(mwifiex_cancel_hs);
480
481/*
482 * Sends IOCTL request to cancel the existing Host Sleep configuration.
483 *
484 * This function allocates the IOCTL request buffer, fills it
485 * with requisite parameters and calls the IOCTL handler.
486 */
487int mwifiex_enable_hs(struct mwifiex_adapter *adapter)
488{
489 struct mwifiex_ds_hs_cfg hscfg;
Amitkumar Karwar22c22d22012-09-20 20:23:17 -0700490 struct mwifiex_private *priv;
491 int i;
492
493 if (disconnect_on_suspend) {
494 for (i = 0; i < adapter->priv_num; i++) {
495 priv = adapter->priv[i];
496 if (priv)
497 mwifiex_deauthenticate(priv, NULL);
498 }
499 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700500
501 if (adapter->hs_activated) {
Masanari Iida69797832012-11-30 22:08:31 +0900502 dev_dbg(adapter->dev, "cmd: HS Already activated\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700503 return true;
504 }
505
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700506 adapter->hs_activate_wait_q_woken = false;
507
Amitkumar Karwarb0938632012-03-13 19:36:49 -0700508 memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700509 hscfg.is_invoke_hostcmd = true;
510
Amitkumar Karwarc0dbba62014-03-25 19:01:20 -0700511 adapter->hs_enabling = true;
512 mwifiex_cancel_all_pending_cmd(adapter);
513
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700514 if (mwifiex_set_hs_params(mwifiex_get_priv(adapter,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700515 MWIFIEX_BSS_ROLE_STA),
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700516 HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD,
517 &hscfg)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700518 dev_err(adapter->dev, "IOCTL request HS enable failed\n");
519 return false;
520 }
521
Bing Zhao9c969d82013-01-02 16:07:35 -0800522 if (wait_event_interruptible(adapter->hs_activate_wait_q,
523 adapter->hs_activate_wait_q_woken)) {
524 dev_err(adapter->dev, "hs_activate_wait_q terminated\n");
525 return false;
526 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700527
528 return true;
529}
530EXPORT_SYMBOL_GPL(mwifiex_enable_hs);
531
532/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700533 * IOCTL request handler to get BSS information.
534 *
535 * This function collates the information from different driver structures
536 * to send to the user.
537 */
538int mwifiex_get_bss_info(struct mwifiex_private *priv,
539 struct mwifiex_bss_info *info)
540{
541 struct mwifiex_adapter *adapter = priv->adapter;
542 struct mwifiex_bssdescriptor *bss_desc;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700543
544 if (!info)
545 return -1;
546
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700547 bss_desc = &priv->curr_bss_params.bss_descriptor;
548
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700549 info->bss_mode = priv->bss_mode;
550
Amitkumar Karwarb9be5f32012-02-27 22:04:14 -0800551 memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700552
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700553 memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN);
554
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700555 info->bss_chan = bss_desc->channel;
556
Avinash Patil67fdf392012-05-08 18:30:17 -0700557 memcpy(info->country_code, adapter->country_code,
Amitkumar Karwar5e218b72012-04-09 20:06:55 -0700558 IEEE80211_COUNTRY_STRING_LEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700559
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700560 info->media_connected = priv->media_connected;
561
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700562 info->max_power_level = priv->max_tx_power_level;
563 info->min_power_level = priv->min_tx_power_level;
564
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700565 info->adhoc_state = priv->adhoc_state;
566
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700567 info->bcn_nf_last = priv->bcn_nf_last;
568
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800569 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700570 info->wep_status = true;
571 else
572 info->wep_status = false;
573
574 info->is_hs_configured = adapter->is_hs_configured;
575 info->is_deep_sleep = adapter->is_deep_sleep;
576
577 return 0;
578}
579
580/*
Amitkumar Karwara0490932011-07-13 20:51:59 -0700581 * The function disables auto deep sleep mode.
582 */
583int mwifiex_disable_auto_ds(struct mwifiex_private *priv)
584{
585 struct mwifiex_ds_auto_ds auto_ds;
586
587 auto_ds.auto_ds = DEEP_SLEEP_OFF;
588
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800589 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
590 DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds, true);
Amitkumar Karwara0490932011-07-13 20:51:59 -0700591}
592EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds);
593
594/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700595 * Sends IOCTL request to get the data rate.
596 *
597 * This function allocates the IOCTL request buffer, fills it
598 * with requisite parameters and calls the IOCTL handler.
599 */
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700600int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700601{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700602 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700603
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800604 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_TX_RATE_QUERY,
605 HostCmd_ACT_GEN_GET, 0, NULL, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700606
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700607 if (!ret) {
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700608 if (priv->is_data_rate_auto)
609 *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate,
610 priv->tx_htinfo);
Dan Carpenter49753122011-09-21 10:13:56 +0300611 else
Amitkumar Karwar006606c2012-07-13 20:09:31 -0700612 *rate = priv->data_rate;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700613 }
614
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700615 return ret;
616}
617
618/*
619 * IOCTL request handler to set tx power configuration.
620 *
621 * This function prepares the correct firmware command and
622 * issues it.
623 *
624 * For non-auto power mode, all the following power groups are set -
625 * - Modulation class HR/DSSS
626 * - Modulation class OFDM
627 * - Modulation class HTBW20
628 * - Modulation class HTBW40
629 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700630int mwifiex_set_tx_power(struct mwifiex_private *priv,
631 struct mwifiex_power_cfg *power_cfg)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700632{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700633 int ret;
634 struct host_cmd_ds_txpwr_cfg *txp_cfg;
635 struct mwifiex_types_power_group *pg_tlv;
636 struct mwifiex_power_group *pg;
637 u8 *buf;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700638 u16 dbm = 0;
639
640 if (!power_cfg->is_power_auto) {
641 dbm = (u16) power_cfg->power_level;
642 if ((dbm < priv->min_tx_power_level) ||
643 (dbm > priv->max_tx_power_level)) {
644 dev_err(priv->adapter->dev, "txpower value %d dBm"
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700645 " is out of range (%d dBm-%d dBm)\n",
646 dbm, priv->min_tx_power_level,
647 priv->max_tx_power_level);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700648 return -1;
649 }
650 }
651 buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL);
Joe Perches0d2e7a52013-02-03 17:28:14 +0000652 if (!buf)
Christoph Fritzb53575e2011-05-08 22:50:09 +0200653 return -ENOMEM;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700654
655 txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
656 txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
657 if (!power_cfg->is_power_auto) {
658 txp_cfg->mode = cpu_to_le32(1);
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700659 pg_tlv = (struct mwifiex_types_power_group *)
660 (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
Amitkumar Karwar930fd352013-10-22 15:24:43 -0700661 pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
662 pg_tlv->length =
663 cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700664 pg = (struct mwifiex_power_group *)
665 (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
666 + sizeof(struct mwifiex_types_power_group));
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700667 /* Power group for modulation class HR/DSSS */
668 pg->first_rate_code = 0x00;
669 pg->last_rate_code = 0x03;
670 pg->modulation_class = MOD_CLASS_HR_DSSS;
671 pg->power_step = 0;
672 pg->power_min = (s8) dbm;
673 pg->power_max = (s8) dbm;
674 pg++;
675 /* Power group for modulation class OFDM */
676 pg->first_rate_code = 0x00;
677 pg->last_rate_code = 0x07;
678 pg->modulation_class = MOD_CLASS_OFDM;
679 pg->power_step = 0;
680 pg->power_min = (s8) dbm;
681 pg->power_max = (s8) dbm;
682 pg++;
683 /* Power group for modulation class HTBW20 */
684 pg->first_rate_code = 0x00;
685 pg->last_rate_code = 0x20;
686 pg->modulation_class = MOD_CLASS_HT;
687 pg->power_step = 0;
688 pg->power_min = (s8) dbm;
689 pg->power_max = (s8) dbm;
690 pg->ht_bandwidth = HT_BW_20;
691 pg++;
692 /* Power group for modulation class HTBW40 */
693 pg->first_rate_code = 0x00;
694 pg->last_rate_code = 0x20;
695 pg->modulation_class = MOD_CLASS_HT;
696 pg->power_step = 0;
697 pg->power_min = (s8) dbm;
698 pg->power_max = (s8) dbm;
699 pg->ht_bandwidth = HT_BW_40;
700 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800701 ret = mwifiex_send_cmd(priv, HostCmd_CMD_TXPWR_CFG,
702 HostCmd_ACT_GEN_SET, 0, buf, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700703
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700704 kfree(buf);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700705 return ret;
706}
707
708/*
709 * IOCTL request handler to get power save mode.
710 *
711 * This function prepares the correct firmware command and
712 * issues it.
713 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700714int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700715{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700716 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700717 struct mwifiex_adapter *adapter = priv->adapter;
718 u16 sub_cmd;
719
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700720 if (*ps_mode)
721 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP;
722 else
723 adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM;
724 sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800725 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
726 sub_cmd, BITMAP_STA_PS, NULL, true);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700727 if ((!ret) && (sub_cmd == DIS_AUTO_PS))
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800728 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_PS_MODE_ENH,
729 GET_PS, 0, NULL, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700730
731 return ret;
732}
733
734/*
735 * IOCTL request handler to set/reset WPA IE.
736 *
737 * The supplied WPA IE is treated as a opaque buffer. Only the first field
738 * is checked to determine WPA version. If buffer length is zero, the existing
739 * WPA IE is reset.
740 */
741static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv,
742 u8 *ie_data_ptr, u16 ie_len)
743{
744 if (ie_len) {
745 if (ie_len > sizeof(priv->wpa_ie)) {
746 dev_err(priv->adapter->dev,
747 "failed to copy WPA IE, too big\n");
748 return -1;
749 }
750 memcpy(priv->wpa_ie, ie_data_ptr, ie_len);
751 priv->wpa_ie_len = (u8) ie_len;
752 dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700753 priv->wpa_ie_len, priv->wpa_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700754
Arend van Spriel04b23122012-10-12 12:28:14 +0200755 if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700756 priv->sec_info.wpa_enabled = true;
757 } else if (priv->wpa_ie[0] == WLAN_EID_RSN) {
758 priv->sec_info.wpa2_enabled = true;
759 } else {
760 priv->sec_info.wpa_enabled = false;
761 priv->sec_info.wpa2_enabled = false;
762 }
763 } else {
764 memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie));
765 priv->wpa_ie_len = 0;
766 dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n",
767 priv->wpa_ie_len, priv->wpa_ie[0]);
768 priv->sec_info.wpa_enabled = false;
769 priv->sec_info.wpa2_enabled = false;
770 }
771
772 return 0;
773}
774
775/*
776 * IOCTL request handler to set/reset WAPI IE.
777 *
778 * The supplied WAPI IE is treated as a opaque buffer. Only the first field
779 * is checked to internally enable WAPI. If buffer length is zero, the existing
780 * WAPI IE is reset.
781 */
782static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
783 u8 *ie_data_ptr, u16 ie_len)
784{
785 if (ie_len) {
786 if (ie_len > sizeof(priv->wapi_ie)) {
787 dev_dbg(priv->adapter->dev,
788 "info: failed to copy WAPI IE, too big\n");
789 return -1;
790 }
791 memcpy(priv->wapi_ie, ie_data_ptr, ie_len);
792 priv->wapi_ie_len = ie_len;
793 dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n",
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -0700794 priv->wapi_ie_len, priv->wapi_ie[0]);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700795
796 if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY)
797 priv->sec_info.wapi_enabled = true;
798 } else {
799 memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie));
800 priv->wapi_ie_len = ie_len;
801 dev_dbg(priv->adapter->dev,
802 "info: Reset wapi_ie_len=%d IE=%#x\n",
803 priv->wapi_ie_len, priv->wapi_ie[0]);
804 priv->sec_info.wapi_enabled = false;
805 }
806 return 0;
807}
808
809/*
Avinash Patil13d7ba782012-04-09 20:06:56 -0700810 * IOCTL request handler to set/reset WPS IE.
811 *
812 * The supplied WPS IE is treated as a opaque buffer. Only the first field
813 * is checked to internally enable WPS. If buffer length is zero, the existing
814 * WPS IE is reset.
815 */
816static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
817 u8 *ie_data_ptr, u16 ie_len)
818{
819 if (ie_len) {
Avinash Patil8795ca62013-07-22 19:17:46 -0700820 if (ie_len > MWIFIEX_MAX_VSIE_LEN) {
821 dev_dbg(priv->adapter->dev,
822 "info: failed to copy WPS IE, too big\n");
823 return -1;
824 }
825
Avinash Patil13d7ba782012-04-09 20:06:56 -0700826 priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
827 if (!priv->wps_ie)
828 return -ENOMEM;
Avinash Patil8795ca62013-07-22 19:17:46 -0700829
Avinash Patil13d7ba782012-04-09 20:06:56 -0700830 memcpy(priv->wps_ie, ie_data_ptr, ie_len);
831 priv->wps_ie_len = ie_len;
832 dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
833 priv->wps_ie_len, priv->wps_ie[0]);
834 } else {
835 kfree(priv->wps_ie);
836 priv->wps_ie_len = ie_len;
837 dev_dbg(priv->adapter->dev,
838 "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
839 }
840 return 0;
841}
842
843/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700844 * IOCTL request handler to set WAPI key.
845 *
846 * This function prepares the correct firmware command and
847 * issues it.
848 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700849static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700850 struct mwifiex_ds_encrypt_key *encrypt_key)
851{
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700852
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800853 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
854 HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED,
855 encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700856}
857
858/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700859 * IOCTL request handler to set WEP network key.
860 *
861 * This function prepares the correct firmware command and
862 * issues it, after validation checks.
863 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700864static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700865 struct mwifiex_ds_encrypt_key *encrypt_key)
866{
Avinash Patile57f1732014-02-07 16:32:35 -0800867 struct mwifiex_adapter *adapter = priv->adapter;
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700868 int ret;
869 struct mwifiex_wep_key *wep_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700870 int index;
871
872 if (priv->wep_key_curr_index >= NUM_WEP_KEYS)
873 priv->wep_key_curr_index = 0;
874 wep_key = &priv->wep_key[priv->wep_key_curr_index];
875 index = encrypt_key->key_index;
876 if (encrypt_key->key_disable) {
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800877 priv->sec_info.wep_enabled = 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700878 } else if (!encrypt_key->key_len) {
879 /* Copy the required key as the current key */
880 wep_key = &priv->wep_key[index];
881 if (!wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800882 dev_err(adapter->dev,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700883 "key not set, so cannot enable it\n");
884 return -1;
885 }
Avinash Patile57f1732014-02-07 16:32:35 -0800886
887 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2) {
888 memcpy(encrypt_key->key_material,
889 wep_key->key_material, wep_key->key_length);
890 encrypt_key->key_len = wep_key->key_length;
891 }
892
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700893 priv->wep_key_curr_index = (u16) index;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800894 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700895 } else {
896 wep_key = &priv->wep_key[index];
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700897 memset(wep_key, 0, sizeof(struct mwifiex_wep_key));
898 /* Copy the key in the driver */
899 memcpy(wep_key->key_material,
900 encrypt_key->key_material,
901 encrypt_key->key_len);
902 wep_key->key_index = index;
903 wep_key->key_length = encrypt_key->key_len;
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800904 priv->sec_info.wep_enabled = 1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700905 }
906 if (wep_key->key_length) {
Avinash Patile57f1732014-02-07 16:32:35 -0800907 void *enc_key;
908
909 if (encrypt_key->key_disable)
910 memset(&priv->wep_key[index], 0,
911 sizeof(struct mwifiex_wep_key));
912
913 if (adapter->fw_key_api_major_ver == FW_KEY_API_VER_MAJOR_V2)
914 enc_key = encrypt_key;
915 else
916 enc_key = NULL;
917
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700918 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800919 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
920 HostCmd_ACT_GEN_SET, 0, enc_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700921 if (ret)
922 return ret;
923 }
Avinash Patile57f1732014-02-07 16:32:35 -0800924
Amitkumar Karwar5eb02e42012-02-24 21:36:04 -0800925 if (priv->sec_info.wep_enabled)
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700926 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
927 else
928 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
929
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800930 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
931 HostCmd_ACT_GEN_SET, 0,
932 &priv->curr_pkt_filter, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700933
934 return ret;
935}
936
937/*
938 * IOCTL request handler to set WPA key.
939 *
940 * This function prepares the correct firmware command and
941 * issues it, after validation checks.
942 *
943 * Current driver only supports key length of up to 32 bytes.
944 *
945 * This function can also be used to disable a currently set key.
946 */
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700947static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700948 struct mwifiex_ds_encrypt_key *encrypt_key)
949{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -0700950 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700951 u8 remove_key = false;
952 struct host_cmd_ds_802_11_key_material *ibss_key;
953
954 /* Current driver only supports key length of up to 32 bytes */
Amitkumar Karwara3731652011-04-15 20:50:41 -0700955 if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) {
Amitkumar Karwar600f5d92011-04-13 17:27:06 -0700956 dev_err(priv->adapter->dev, "key length too long\n");
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700957 return -1;
958 }
959
Bing Zhaoeecd8252011-03-28 17:55:41 -0700960 if (priv->bss_mode == NL80211_IFTYPE_ADHOC) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700961 /*
962 * IBSS/WPA-None uses only one key (Group) for both receiving
963 * and sending unicast and multicast packets.
964 */
965 /* Send the key as PTK to firmware */
966 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800967 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
968 HostCmd_ACT_GEN_SET,
969 KEY_INFO_ENABLED, encrypt_key, false);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700970 if (ret)
971 return ret;
972
973 ibss_key = &priv->aes_key;
974 memset(ibss_key, 0,
975 sizeof(struct host_cmd_ds_802_11_key_material));
976 /* Copy the key in the driver */
977 memcpy(ibss_key->key_param_set.key, encrypt_key->key_material,
978 encrypt_key->key_len);
979 memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len,
980 sizeof(ibss_key->key_param_set.key_len));
981 ibss_key->key_param_set.key_type_id
982 = cpu_to_le16(KEY_TYPE_ID_TKIP);
Yogesh Ashok Powar6a35a0a2011-04-06 16:46:56 -0700983 ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700984
985 /* Send the key as GTK to firmware */
986 encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST;
987 }
988
989 if (!encrypt_key->key_index)
990 encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST;
991
992 if (remove_key)
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800993 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
994 HostCmd_ACT_GEN_SET,
995 !KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -0700996 else
Bing Zhaofa0ecbb2014-02-27 19:35:12 -0800997 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL,
998 HostCmd_ACT_GEN_SET,
999 KEY_INFO_ENABLED, encrypt_key, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001000
1001 return ret;
1002}
1003
1004/*
1005 * IOCTL request handler to set/get network keys.
1006 *
1007 * This is a generic key handling function which supports WEP, WPA
1008 * and WAPI.
1009 */
1010static int
1011mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001012 struct mwifiex_ds_encrypt_key *encrypt_key)
1013{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001014 int status;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001015
1016 if (encrypt_key->is_wapi_key)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001017 status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001018 else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104)
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001019 status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001020 else
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001021 status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001022 return status;
1023}
1024
1025/*
1026 * This function returns the driver version.
1027 */
1028int
1029mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,
1030 int max_len)
1031{
1032 union {
1033 u32 l;
1034 u8 c[4];
1035 } ver;
1036 char fw_ver[32];
1037
1038 ver.l = adapter->fw_release_number;
1039 sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
1040
1041 snprintf(version, max_len, driver_version, fw_ver);
1042
1043 dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version);
1044
1045 return 0;
1046}
1047
1048/*
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001049 * Sends IOCTL request to set encoding parameters.
1050 *
1051 * This function allocates the IOCTL request buffer, fills it
1052 * with requisite parameters and calls the IOCTL handler.
1053 */
Ying Luo53b11232012-08-03 18:06:13 -07001054int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1055 const u8 *key, int key_len, u8 key_index,
1056 const u8 *mac_addr, int disable)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001057{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001058 struct mwifiex_ds_encrypt_key encrypt_key;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001059
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001060 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key));
1061 encrypt_key.key_len = key_len;
Avinash Patile57f1732014-02-07 16:32:35 -08001062 encrypt_key.key_index = key_index;
Ying Luo53b11232012-08-03 18:06:13 -07001063
1064 if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1065 encrypt_key.is_igtk_key = true;
1066
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001067 if (!disable) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001068 if (key_len)
1069 memcpy(encrypt_key.key_material, key, key_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001070 else
1071 encrypt_key.is_current_wep_key = true;
1072
Avinash Patil75edd2c2012-05-08 18:30:18 -07001073 if (mac_addr)
1074 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Avinash Patile57f1732014-02-07 16:32:35 -08001075 if (kp && kp->seq && kp->seq_len) {
Ying Luo53b11232012-08-03 18:06:13 -07001076 memcpy(encrypt_key.pn, kp->seq, kp->seq_len);
Avinash Patile57f1732014-02-07 16:32:35 -08001077 encrypt_key.pn_len = kp->seq_len;
1078 encrypt_key.is_rx_seq_valid = true;
1079 }
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001080 } else {
Avinash Patile57f1732014-02-07 16:32:35 -08001081 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
1082 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001083 encrypt_key.key_disable = true;
Avinash Patil75edd2c2012-05-08 18:30:18 -07001084 if (mac_addr)
1085 memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001086 }
1087
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001088 return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001089}
1090
1091/*
1092 * Sends IOCTL request to get extended version.
1093 *
1094 * This function allocates the IOCTL request buffer, fills it
1095 * with requisite parameters and calls the IOCTL handler.
1096 */
1097int
1098mwifiex_get_ver_ext(struct mwifiex_private *priv)
1099{
1100 struct mwifiex_ver_ext ver_ext;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001101
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001102 memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext));
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001103 if (mwifiex_send_cmd(priv, HostCmd_CMD_VERSION_EXT,
1104 HostCmd_ACT_GEN_GET, 0, &ver_ext, true))
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001105 return -1;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001106
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001107 return 0;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001108}
1109
Stone Piao7feb4c42012-09-25 20:23:36 -07001110int
1111mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1112 struct ieee80211_channel *chan,
Stone Piao7feb4c42012-09-25 20:23:36 -07001113 unsigned int duration)
1114{
1115 struct host_cmd_ds_remain_on_chan roc_cfg;
1116 u8 sc;
1117
1118 memset(&roc_cfg, 0, sizeof(roc_cfg));
1119 roc_cfg.action = cpu_to_le16(action);
1120 if (action == HostCmd_ACT_GEN_SET) {
1121 roc_cfg.band_cfg = chan->band;
Johannes Berg42d97a52012-11-08 18:31:02 +01001122 sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT);
Stone Piao7feb4c42012-09-25 20:23:36 -07001123 roc_cfg.band_cfg |= (sc << 2);
1124
1125 roc_cfg.channel =
1126 ieee80211_frequency_to_channel(chan->center_freq);
1127 roc_cfg.duration = cpu_to_le32(duration);
1128 }
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001129 if (mwifiex_send_cmd(priv, HostCmd_CMD_REMAIN_ON_CHAN,
1130 action, 0, &roc_cfg, true)) {
Stone Piao7feb4c42012-09-25 20:23:36 -07001131 dev_err(priv->adapter->dev, "failed to remain on channel\n");
1132 return -1;
1133 }
1134
1135 return roc_cfg.status;
1136}
1137
Stone Piao9197ab92012-09-25 20:23:42 -07001138int
1139mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role)
1140{
1141 if (GET_BSS_ROLE(priv) == bss_role) {
1142 dev_dbg(priv->adapter->dev,
1143 "info: already in the desired role.\n");
1144 return 0;
1145 }
1146
1147 mwifiex_free_priv(priv);
1148 mwifiex_init_priv(priv);
1149
1150 priv->bss_role = bss_role;
1151 switch (bss_role) {
1152 case MWIFIEX_BSS_ROLE_UAP:
1153 priv->bss_mode = NL80211_IFTYPE_AP;
1154 break;
1155 case MWIFIEX_BSS_ROLE_STA:
1156 case MWIFIEX_BSS_ROLE_ANY:
1157 default:
1158 priv->bss_mode = NL80211_IFTYPE_STATION;
1159 break;
1160 }
1161
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001162 mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE,
1163 HostCmd_ACT_GEN_SET, 0, NULL, true);
Stone Piao9197ab92012-09-25 20:23:42 -07001164
1165 return mwifiex_sta_init_cmd(priv, false);
1166}
1167
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001168/*
1169 * Sends IOCTL request to get statistics information.
1170 *
1171 * This function allocates the IOCTL request buffer, fills it
1172 * with requisite parameters and calls the IOCTL handler.
1173 */
1174int
1175mwifiex_get_stats_info(struct mwifiex_private *priv,
1176 struct mwifiex_ds_get_stats *log)
1177{
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001178 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_GET_LOG,
1179 HostCmd_ACT_GEN_GET, 0, log, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001180}
1181
1182/*
1183 * IOCTL request handler to read/write register.
1184 *
1185 * This function prepares the correct firmware command and
1186 * issues it.
1187 *
1188 * Access to the following registers are supported -
1189 * - MAC
1190 * - BBP
1191 * - RF
1192 * - PMIC
1193 * - CAU
1194 */
1195static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv,
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001196 struct mwifiex_ds_reg_rw *reg_rw,
1197 u16 action)
1198{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001199 u16 cmd_no;
1200
1201 switch (le32_to_cpu(reg_rw->type)) {
1202 case MWIFIEX_REG_MAC:
1203 cmd_no = HostCmd_CMD_MAC_REG_ACCESS;
1204 break;
1205 case MWIFIEX_REG_BBP:
1206 cmd_no = HostCmd_CMD_BBP_REG_ACCESS;
1207 break;
1208 case MWIFIEX_REG_RF:
1209 cmd_no = HostCmd_CMD_RF_REG_ACCESS;
1210 break;
1211 case MWIFIEX_REG_PMIC:
1212 cmd_no = HostCmd_CMD_PMIC_REG_ACCESS;
1213 break;
1214 case MWIFIEX_REG_CAU:
1215 cmd_no = HostCmd_CMD_CAU_REG_ACCESS;
1216 break;
1217 default:
1218 return -1;
1219 }
1220
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001221 return mwifiex_send_cmd(priv, cmd_no, action, 0, reg_rw, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001222}
1223
1224/*
1225 * Sends IOCTL request to write to a register.
1226 *
1227 * This function allocates the IOCTL request buffer, fills it
1228 * with requisite parameters and calls the IOCTL handler.
1229 */
1230int
1231mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1232 u32 reg_offset, u32 reg_value)
1233{
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001234 struct mwifiex_ds_reg_rw reg_rw;
1235
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001236 reg_rw.type = cpu_to_le32(reg_type);
1237 reg_rw.offset = cpu_to_le32(reg_offset);
1238 reg_rw.value = cpu_to_le32(reg_value);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001239
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001240 return mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_SET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001241}
1242
1243/*
1244 * Sends IOCTL request to read from a register.
1245 *
1246 * This function allocates the IOCTL request buffer, fills it
1247 * with requisite parameters and calls the IOCTL handler.
1248 */
1249int
1250mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1251 u32 reg_offset, u32 *value)
1252{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001253 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001254 struct mwifiex_ds_reg_rw reg_rw;
1255
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001256 reg_rw.type = cpu_to_le32(reg_type);
1257 reg_rw.offset = cpu_to_le32(reg_offset);
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001258 ret = mwifiex_reg_mem_ioctl_reg_rw(priv, &reg_rw, HostCmd_ACT_GEN_GET);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001259
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001260 if (ret)
1261 goto done;
1262
1263 *value = le32_to_cpu(reg_rw.value);
1264
1265done:
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001266 return ret;
1267}
1268
1269/*
1270 * Sends IOCTL request to read from EEPROM.
1271 *
1272 * This function allocates the IOCTL request buffer, fills it
1273 * with requisite parameters and calls the IOCTL handler.
1274 */
1275int
1276mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1277 u8 *value)
1278{
Yogesh Ashok Powar270e58e2011-05-03 20:11:46 -07001279 int ret;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001280 struct mwifiex_ds_read_eeprom rd_eeprom;
1281
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001282 rd_eeprom.offset = cpu_to_le16((u16) offset);
1283 rd_eeprom.byte_count = cpu_to_le16((u16) bytes);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001284
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001285 /* Send request to firmware */
Bing Zhaofa0ecbb2014-02-27 19:35:12 -08001286 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_EEPROM_ACCESS,
1287 HostCmd_ACT_GEN_GET, 0, &rd_eeprom, true);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001288
Amitkumar Karwar600f5d92011-04-13 17:27:06 -07001289 if (!ret)
1290 memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001291 return ret;
1292}
1293
1294/*
1295 * This function sets a generic IE. In addition to generic IE, it can
1296 * also handle WPA, WPA2 and WAPI IEs.
1297 */
1298static int
1299mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
1300 u16 ie_len)
1301{
1302 int ret = 0;
1303 struct ieee_types_vendor_header *pvendor_ie;
1304 const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 };
1305 const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 };
1306
1307 /* If the passed length is zero, reset the buffer */
1308 if (!ie_len) {
1309 priv->gen_ie_buf_len = 0;
1310 priv->wps.session_enable = false;
1311
1312 return 0;
1313 } else if (!ie_data_ptr) {
1314 return -1;
1315 }
1316 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
1317 /* 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 +02001318 if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001319 (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) ||
1320 (pvendor_ie->element_id == WLAN_EID_RSN)) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001321
1322 /* IE is a WPA/WPA2 IE so call set_wpa function */
1323 ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len);
1324 priv->wps.session_enable = false;
1325
1326 return ret;
1327 } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) {
1328 /* IE is a WAPI IE so call set_wapi function */
1329 ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len);
1330
1331 return ret;
1332 }
1333 /*
1334 * Verify that the passed length is not larger than the
1335 * available space remaining in the buffer
1336 */
1337 if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) {
1338
1339 /* Test to see if it is a WPS IE, if so, enable
1340 * wps session flag
1341 */
1342 pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr;
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001343 if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) &&
1344 (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) {
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001345 priv->wps.session_enable = true;
1346 dev_dbg(priv->adapter->dev,
1347 "info: WPS Session Enabled.\n");
Avinash Patil13d7ba782012-04-09 20:06:56 -07001348 ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001349 }
1350
1351 /* Append the passed data to the end of the
1352 genIeBuffer */
1353 memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001354 ie_len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001355 /* Increment the stored buffer length by the
1356 size passed */
1357 priv->gen_ie_buf_len += ie_len;
1358 } else {
1359 /* Passed data does not fit in the remaining
1360 buffer space */
1361 ret = -1;
1362 }
1363
1364 /* Return 0, or -1 for error case */
1365 return ret;
1366}
1367
1368/*
1369 * IOCTL request handler to set/get generic IE.
1370 *
1371 * In addition to various generic IEs, this function can also be
1372 * used to set the ARP filter.
1373 */
1374static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv,
1375 struct mwifiex_ds_misc_gen_ie *gen_ie,
1376 u16 action)
1377{
1378 struct mwifiex_adapter *adapter = priv->adapter;
1379
1380 switch (gen_ie->type) {
1381 case MWIFIEX_IE_TYPE_GEN_IE:
1382 if (action == HostCmd_ACT_GEN_GET) {
1383 gen_ie->len = priv->wpa_ie_len;
1384 memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len);
1385 } else {
1386 mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data,
1387 (u16) gen_ie->len);
1388 }
1389 break;
1390 case MWIFIEX_IE_TYPE_ARP_FILTER:
1391 memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter));
1392 if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) {
1393 adapter->arp_filter_size = 0;
1394 dev_err(adapter->dev, "invalid ARP filter size\n");
1395 return -1;
1396 } else {
1397 memcpy(adapter->arp_filter, gen_ie->ie_data,
Yogesh Ashok Powar500f7472012-03-13 19:22:41 -07001398 gen_ie->len);
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001399 adapter->arp_filter_size = gen_ie->len;
1400 }
1401 break;
1402 default:
1403 dev_err(adapter->dev, "invalid IE type\n");
1404 return -1;
1405 }
1406 return 0;
1407}
1408
1409/*
1410 * Sends IOCTL request to set a generic IE.
1411 *
1412 * This function allocates the IOCTL request buffer, fills it
1413 * with requisite parameters and calls the IOCTL handler.
1414 */
1415int
Johannes Berg4b5800f2014-01-15 14:55:59 +01001416mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001417{
1418 struct mwifiex_ds_misc_gen_ie gen_ie;
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001419
Bing Zhao67a50032011-07-13 18:38:34 -07001420 if (ie_len > IEEE_MAX_IE_SIZE)
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001421 return -EFAULT;
1422
1423 gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE;
1424 gen_ie.len = ie_len;
1425 memcpy(gen_ie.ie_data, ie, ie_len);
Yogesh Ashok Powar636c4592011-04-15 20:50:40 -07001426 if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET))
Bing Zhao5e6e3a92011-03-21 18:00:50 -07001427 return -EFAULT;
1428
1429 return 0;
1430}