Commit | Line | Data |
---|---|---|
5e6e3a92 BZ |
1 | /* |
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 | ||
22c22d27 AK |
29 | static int disconnect_on_suspend = 1; |
30 | module_param(disconnect_on_suspend, int, 0644); | |
31 | ||
5e6e3a92 BZ |
32 | /* |
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 | */ | |
600f5d90 AK |
39 | int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist, |
40 | struct net_device *dev) | |
5e6e3a92 BZ |
41 | { |
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 | ||
5e6e3a92 BZ |
51 | /* |
52 | * Wait queue completion handler. | |
53 | * | |
600f5d90 AK |
54 | * This function waits on a cmd wait queue. It also cancels the pending |
55 | * request after waking up, in case of errors. | |
5e6e3a92 | 56 | */ |
600f5d90 | 57 | int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter) |
5e6e3a92 | 58 | { |
b7097eb7 | 59 | int status; |
b015dbc0 | 60 | struct cmd_ctrl_node *cmd_queued; |
5e6e3a92 | 61 | |
b015dbc0 AK |
62 | if (!adapter->cmd_queued) |
63 | return 0; | |
64 | ||
65 | cmd_queued = adapter->cmd_queued; | |
efaaa8b8 | 66 | adapter->cmd_queued = NULL; |
b015dbc0 | 67 | |
600f5d90 AK |
68 | dev_dbg(adapter->dev, "cmd pending\n"); |
69 | atomic_inc(&adapter->cmd_pending); | |
5e6e3a92 | 70 | |
600f5d90 | 71 | /* Wait for completion */ |
9c969d8c BZ |
72 | status = wait_event_interruptible(adapter->cmd_wait_q.wait, |
73 | *(cmd_queued->condition)); | |
74 | if (status) { | |
75 | dev_err(adapter->dev, "cmd_wait_q terminated: %d\n", status); | |
76 | return status; | |
5e6e3a92 | 77 | } |
b7097eb7 AK |
78 | |
79 | status = adapter->cmd_wait_q.status; | |
600f5d90 | 80 | adapter->cmd_wait_q.status = 0; |
5e6e3a92 | 81 | |
5e6e3a92 BZ |
82 | return status; |
83 | } | |
84 | ||
85 | /* | |
5e6e3a92 BZ |
86 | * This function prepares the correct firmware command and |
87 | * issues it to set the multicast list. | |
88 | * | |
89 | * This function can be used to enable promiscuous mode, or enable all | |
90 | * multicast packets, or to enable selective multicast. | |
91 | */ | |
600f5d90 AK |
92 | int mwifiex_request_set_multicast_list(struct mwifiex_private *priv, |
93 | struct mwifiex_multicast_list *mcast_list) | |
5e6e3a92 BZ |
94 | { |
95 | int ret = 0; | |
96 | u16 old_pkt_filter; | |
97 | ||
98 | old_pkt_filter = priv->curr_pkt_filter; | |
5e6e3a92 BZ |
99 | |
100 | if (mcast_list->mode == MWIFIEX_PROMISC_MODE) { | |
101 | dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n"); | |
102 | priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE; | |
103 | priv->curr_pkt_filter &= | |
104 | ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE; | |
105 | } else { | |
106 | /* Multicast */ | |
107 | priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE; | |
108 | if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) { | |
109 | dev_dbg(priv->adapter->dev, | |
110 | "info: Enabling All Multicast!\n"); | |
111 | priv->curr_pkt_filter |= | |
112 | HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE; | |
113 | } else { | |
114 | priv->curr_pkt_filter &= | |
115 | ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE; | |
116 | if (mcast_list->num_multicast_addr) { | |
117 | dev_dbg(priv->adapter->dev, | |
118 | "info: Set multicast list=%d\n", | |
119 | mcast_list->num_multicast_addr); | |
120 | /* Set multicast addresses to firmware */ | |
121 | if (old_pkt_filter == priv->curr_pkt_filter) { | |
122 | /* Send request to firmware */ | |
600f5d90 | 123 | ret = mwifiex_send_cmd_async(priv, |
5e6e3a92 | 124 | HostCmd_CMD_MAC_MULTICAST_ADR, |
600f5d90 AK |
125 | HostCmd_ACT_GEN_SET, 0, |
126 | mcast_list); | |
5e6e3a92 BZ |
127 | } else { |
128 | /* Send request to firmware */ | |
600f5d90 | 129 | ret = mwifiex_send_cmd_async(priv, |
5e6e3a92 | 130 | HostCmd_CMD_MAC_MULTICAST_ADR, |
600f5d90 | 131 | HostCmd_ACT_GEN_SET, 0, |
5e6e3a92 BZ |
132 | mcast_list); |
133 | } | |
134 | } | |
135 | } | |
136 | } | |
137 | dev_dbg(priv->adapter->dev, | |
138 | "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n", | |
139 | old_pkt_filter, priv->curr_pkt_filter); | |
140 | if (old_pkt_filter != priv->curr_pkt_filter) { | |
600f5d90 AK |
141 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL, |
142 | HostCmd_ACT_GEN_SET, | |
143 | 0, &priv->curr_pkt_filter); | |
5e6e3a92 BZ |
144 | } |
145 | ||
146 | return ret; | |
147 | } | |
148 | ||
7c6fa2a8 AK |
149 | /* |
150 | * This function fills bss descriptor structure using provided | |
151 | * information. | |
152 | */ | |
153 | int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv, | |
9558a407 | 154 | struct cfg80211_bss *bss, |
7c6fa2a8 AK |
155 | struct mwifiex_bssdescriptor *bss_desc) |
156 | { | |
157 | int ret; | |
9558a407 | 158 | u8 *beacon_ie; |
403e1673 | 159 | size_t beacon_ie_len; |
b5abcf02 | 160 | struct mwifiex_bss_priv *bss_priv = (void *)bss->priv; |
9caf0364 JB |
161 | const struct cfg80211_bss_ies *ies; |
162 | ||
163 | rcu_read_lock(); | |
164 | ies = rcu_dereference(bss->ies); | |
9caf0364 JB |
165 | beacon_ie = kmemdup(ies->data, ies->len, GFP_ATOMIC); |
166 | beacon_ie_len = ies->len; | |
8cef2c9d | 167 | bss_desc->timestamp = ies->tsf; |
9caf0364 | 168 | rcu_read_unlock(); |
7c6fa2a8 | 169 | |
9558a407 AK |
170 | if (!beacon_ie) { |
171 | dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n"); | |
172 | return -ENOMEM; | |
173 | } | |
174 | ||
175 | memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN); | |
176 | bss_desc->rssi = bss->signal; | |
177 | bss_desc->beacon_buf = beacon_ie; | |
904f137d | 178 | bss_desc->beacon_buf_size = beacon_ie_len; |
9558a407 AK |
179 | bss_desc->beacon_period = bss->beacon_interval; |
180 | bss_desc->cap_info_bitmap = bss->capability; | |
b5abcf02 AK |
181 | bss_desc->bss_band = bss_priv->band; |
182 | bss_desc->fw_tsf = bss_priv->fw_tsf; | |
7c6fa2a8 AK |
183 | if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) { |
184 | dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n"); | |
185 | bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP; | |
186 | } else { | |
187 | bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL; | |
188 | } | |
189 | if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_IBSS) | |
190 | bss_desc->bss_mode = NL80211_IFTYPE_ADHOC; | |
191 | else | |
192 | bss_desc->bss_mode = NL80211_IFTYPE_STATION; | |
193 | ||
9558a407 | 194 | ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc); |
7c6fa2a8 | 195 | |
9558a407 | 196 | kfree(beacon_ie); |
7c6fa2a8 AK |
197 | return ret; |
198 | } | |
199 | ||
e89e2da2 AK |
200 | static int mwifiex_process_country_ie(struct mwifiex_private *priv, |
201 | struct cfg80211_bss *bss) | |
202 | { | |
9caf0364 JB |
203 | const u8 *country_ie; |
204 | u8 country_ie_len; | |
e89e2da2 AK |
205 | struct mwifiex_802_11d_domain_reg *domain_info = |
206 | &priv->adapter->domain_reg; | |
207 | ||
9caf0364 JB |
208 | rcu_read_lock(); |
209 | country_ie = ieee80211_bss_get_ie(bss, WLAN_EID_COUNTRY); | |
210 | if (!country_ie) { | |
211 | rcu_read_unlock(); | |
e89e2da2 | 212 | return 0; |
9caf0364 | 213 | } |
e89e2da2 AK |
214 | |
215 | country_ie_len = country_ie[1]; | |
9caf0364 JB |
216 | if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) { |
217 | rcu_read_unlock(); | |
e89e2da2 | 218 | return 0; |
9caf0364 | 219 | } |
e89e2da2 AK |
220 | |
221 | domain_info->country_code[0] = country_ie[2]; | |
222 | domain_info->country_code[1] = country_ie[3]; | |
223 | domain_info->country_code[2] = ' '; | |
224 | ||
225 | country_ie_len -= IEEE80211_COUNTRY_STRING_LEN; | |
226 | ||
227 | domain_info->no_of_triplet = | |
228 | country_ie_len / sizeof(struct ieee80211_country_ie_triplet); | |
229 | ||
230 | memcpy((u8 *)domain_info->triplet, | |
231 | &country_ie[2] + IEEE80211_COUNTRY_STRING_LEN, country_ie_len); | |
232 | ||
9caf0364 JB |
233 | rcu_read_unlock(); |
234 | ||
e89e2da2 AK |
235 | if (mwifiex_send_cmd_async(priv, HostCmd_CMD_802_11D_DOMAIN_INFO, |
236 | HostCmd_ACT_GEN_SET, 0, NULL)) { | |
237 | wiphy_err(priv->adapter->wiphy, | |
238 | "11D: setting domain info in FW\n"); | |
239 | return -1; | |
240 | } | |
241 | ||
242 | return 0; | |
243 | } | |
244 | ||
5e6e3a92 | 245 | /* |
5e6e3a92 BZ |
246 | * In Ad-Hoc mode, the IBSS is created if not found in scan list. |
247 | * In both Ad-Hoc and infra mode, an deauthentication is performed | |
248 | * first. | |
249 | */ | |
7c6fa2a8 | 250 | int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss, |
b9be5f39 | 251 | struct cfg80211_ssid *req_ssid) |
5e6e3a92 | 252 | { |
270e58e8 | 253 | int ret; |
5e6e3a92 | 254 | struct mwifiex_adapter *adapter = priv->adapter; |
7c6fa2a8 | 255 | struct mwifiex_bssdescriptor *bss_desc = NULL; |
5e6e3a92 BZ |
256 | |
257 | priv->scan_block = false; | |
7c6fa2a8 AK |
258 | |
259 | if (bss) { | |
e89e2da2 AK |
260 | mwifiex_process_country_ie(priv, bss); |
261 | ||
7c6fa2a8 AK |
262 | /* Allocate and fill new bss descriptor */ |
263 | bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor), | |
264 | GFP_KERNEL); | |
265 | if (!bss_desc) { | |
266 | dev_err(priv->adapter->dev, " failed to alloc bss_desc\n"); | |
267 | return -ENOMEM; | |
268 | } | |
5982b47a | 269 | |
9558a407 | 270 | ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc); |
7c6fa2a8 AK |
271 | if (ret) |
272 | goto done; | |
273 | } | |
5e6e3a92 | 274 | |
eecd8250 | 275 | if (priv->bss_mode == NL80211_IFTYPE_STATION) { |
5e6e3a92 | 276 | /* Infra mode */ |
600f5d90 | 277 | ret = mwifiex_deauthenticate(priv, NULL); |
5e6e3a92 | 278 | if (ret) |
7c6fa2a8 AK |
279 | goto done; |
280 | ||
d7b9c520 AK |
281 | if (bss_desc) { |
282 | u8 config_bands = 0; | |
283 | ||
284 | if (mwifiex_band_to_radio_type((u8) bss_desc->bss_band) | |
285 | == HostCmd_SCAN_RADIO_TYPE_BG) | |
286 | config_bands = BAND_B | BAND_G | BAND_GN; | |
287 | else | |
288 | config_bands = BAND_A | BAND_AN; | |
289 | ||
290 | if (!((config_bands | adapter->fw_bands) & | |
291 | ~adapter->fw_bands)) | |
292 | adapter->config_bands = config_bands; | |
293 | } | |
294 | ||
7c6fa2a8 AK |
295 | ret = mwifiex_check_network_compatibility(priv, bss_desc); |
296 | if (ret) | |
297 | goto done; | |
5e6e3a92 | 298 | |
7c6fa2a8 AK |
299 | dev_dbg(adapter->dev, "info: SSID found in scan list ... " |
300 | "associating...\n"); | |
301 | ||
47411a06 | 302 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); |
b7097eb7 AK |
303 | if (netif_carrier_ok(priv->netdev)) |
304 | netif_carrier_off(priv->netdev); | |
5e6e3a92 BZ |
305 | |
306 | /* Clear any past association response stored for | |
307 | * application retrieval */ | |
308 | priv->assoc_rsp_size = 0; | |
7c6fa2a8 | 309 | ret = mwifiex_associate(priv, bss_desc); |
a0f6d6ca AK |
310 | |
311 | /* If auth type is auto and association fails using open mode, | |
312 | * try to connect using shared mode */ | |
313 | if (ret == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG && | |
314 | priv->sec_info.is_authtype_auto && | |
315 | priv->sec_info.wep_enabled) { | |
316 | priv->sec_info.authentication_mode = | |
317 | NL80211_AUTHTYPE_SHARED_KEY; | |
318 | ret = mwifiex_associate(priv, bss_desc); | |
319 | } | |
320 | ||
7c6fa2a8 | 321 | if (bss) |
5b112d3d | 322 | cfg80211_put_bss(priv->adapter->wiphy, bss); |
5e6e3a92 BZ |
323 | } else { |
324 | /* Adhoc mode */ | |
325 | /* If the requested SSID matches current SSID, return */ | |
7c6fa2a8 | 326 | if (bss_desc && bss_desc->ssid.ssid_len && |
500f747c YAP |
327 | (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor. |
328 | ssid, &bss_desc->ssid))) { | |
7c6fa2a8 | 329 | kfree(bss_desc); |
5e6e3a92 | 330 | return 0; |
7c6fa2a8 | 331 | } |
5e6e3a92 BZ |
332 | |
333 | /* Exit Adhoc mode first */ | |
334 | dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n"); | |
600f5d90 | 335 | ret = mwifiex_deauthenticate(priv, NULL); |
5e6e3a92 | 336 | if (ret) |
7c6fa2a8 | 337 | goto done; |
5e6e3a92 BZ |
338 | |
339 | priv->adhoc_is_link_sensed = false; | |
340 | ||
7c6fa2a8 AK |
341 | ret = mwifiex_check_network_compatibility(priv, bss_desc); |
342 | ||
47411a06 | 343 | mwifiex_stop_net_dev_queue(priv->netdev, adapter); |
b7097eb7 AK |
344 | if (netif_carrier_ok(priv->netdev)) |
345 | netif_carrier_off(priv->netdev); | |
7c6fa2a8 AK |
346 | |
347 | if (!ret) { | |
5e6e3a92 BZ |
348 | dev_dbg(adapter->dev, "info: network found in scan" |
349 | " list. Joining...\n"); | |
7c6fa2a8 AK |
350 | ret = mwifiex_adhoc_join(priv, bss_desc); |
351 | if (bss) | |
5b112d3d | 352 | cfg80211_put_bss(priv->adapter->wiphy, bss); |
636c4598 | 353 | } else { |
5e6e3a92 BZ |
354 | dev_dbg(adapter->dev, "info: Network not found in " |
355 | "the list, creating adhoc with ssid = %s\n", | |
7c6fa2a8 AK |
356 | req_ssid->ssid); |
357 | ret = mwifiex_adhoc_start(priv, req_ssid); | |
5e6e3a92 BZ |
358 | } |
359 | } | |
360 | ||
7c6fa2a8 AK |
361 | done: |
362 | kfree(bss_desc); | |
5e6e3a92 BZ |
363 | return ret; |
364 | } | |
365 | ||
5e6e3a92 BZ |
366 | /* |
367 | * IOCTL request handler to set host sleep configuration. | |
368 | * | |
369 | * This function prepares the correct firmware command and | |
370 | * issues it. | |
371 | */ | |
711825a0 AK |
372 | static int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action, |
373 | int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg) | |
600f5d90 | 374 | |
5e6e3a92 BZ |
375 | { |
376 | struct mwifiex_adapter *adapter = priv->adapter; | |
377 | int status = 0; | |
378 | u32 prev_cond = 0; | |
379 | ||
600f5d90 AK |
380 | if (!hs_cfg) |
381 | return -ENOMEM; | |
382 | ||
5e6e3a92 BZ |
383 | switch (action) { |
384 | case HostCmd_ACT_GEN_SET: | |
385 | if (adapter->pps_uapsd_mode) { | |
386 | dev_dbg(adapter->dev, "info: Host Sleep IOCTL" | |
387 | " is blocked in UAPSD/PPS mode\n"); | |
388 | status = -1; | |
389 | break; | |
390 | } | |
391 | if (hs_cfg->is_invoke_hostcmd) { | |
392 | if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) { | |
393 | if (!adapter->is_hs_configured) | |
394 | /* Already cancelled */ | |
395 | break; | |
396 | /* Save previous condition */ | |
397 | prev_cond = le32_to_cpu(adapter->hs_cfg | |
398 | .conditions); | |
399 | adapter->hs_cfg.conditions = | |
400 | cpu_to_le32(hs_cfg->conditions); | |
401 | } else if (hs_cfg->conditions) { | |
402 | adapter->hs_cfg.conditions = | |
403 | cpu_to_le32(hs_cfg->conditions); | |
404 | adapter->hs_cfg.gpio = (u8)hs_cfg->gpio; | |
405 | if (hs_cfg->gap) | |
406 | adapter->hs_cfg.gap = (u8)hs_cfg->gap; | |
500f747c YAP |
407 | } else if (adapter->hs_cfg.conditions |
408 | == cpu_to_le32(HOST_SLEEP_CFG_CANCEL)) { | |
5e6e3a92 BZ |
409 | /* Return failure if no parameters for HS |
410 | enable */ | |
411 | status = -1; | |
412 | break; | |
413 | } | |
600f5d90 AK |
414 | if (cmd_type == MWIFIEX_SYNC_CMD) |
415 | status = mwifiex_send_cmd_sync(priv, | |
416 | HostCmd_CMD_802_11_HS_CFG_ENH, | |
417 | HostCmd_ACT_GEN_SET, 0, | |
418 | &adapter->hs_cfg); | |
419 | else | |
420 | status = mwifiex_send_cmd_async(priv, | |
421 | HostCmd_CMD_802_11_HS_CFG_ENH, | |
422 | HostCmd_ACT_GEN_SET, 0, | |
423 | &adapter->hs_cfg); | |
5e6e3a92 BZ |
424 | if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) |
425 | /* Restore previous condition */ | |
426 | adapter->hs_cfg.conditions = | |
427 | cpu_to_le32(prev_cond); | |
428 | } else { | |
429 | adapter->hs_cfg.conditions = | |
500f747c | 430 | cpu_to_le32(hs_cfg->conditions); |
5e6e3a92 BZ |
431 | adapter->hs_cfg.gpio = (u8)hs_cfg->gpio; |
432 | adapter->hs_cfg.gap = (u8)hs_cfg->gap; | |
433 | } | |
434 | break; | |
435 | case HostCmd_ACT_GEN_GET: | |
436 | hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions); | |
437 | hs_cfg->gpio = adapter->hs_cfg.gpio; | |
438 | hs_cfg->gap = adapter->hs_cfg.gap; | |
439 | break; | |
440 | default: | |
441 | status = -1; | |
442 | break; | |
443 | } | |
444 | ||
445 | return status; | |
446 | } | |
447 | ||
5e6e3a92 BZ |
448 | /* |
449 | * Sends IOCTL request to cancel the existing Host Sleep configuration. | |
450 | * | |
451 | * This function allocates the IOCTL request buffer, fills it | |
452 | * with requisite parameters and calls the IOCTL handler. | |
453 | */ | |
600f5d90 | 454 | int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type) |
5e6e3a92 | 455 | { |
5e6e3a92 BZ |
456 | struct mwifiex_ds_hs_cfg hscfg; |
457 | ||
5e6e3a92 BZ |
458 | hscfg.conditions = HOST_SLEEP_CFG_CANCEL; |
459 | hscfg.is_invoke_hostcmd = true; | |
5e6e3a92 | 460 | |
636c4598 YAP |
461 | return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET, |
462 | cmd_type, &hscfg); | |
5e6e3a92 BZ |
463 | } |
464 | EXPORT_SYMBOL_GPL(mwifiex_cancel_hs); | |
465 | ||
466 | /* | |
467 | * Sends IOCTL request to cancel the existing Host Sleep configuration. | |
468 | * | |
469 | * This function allocates the IOCTL request buffer, fills it | |
470 | * with requisite parameters and calls the IOCTL handler. | |
471 | */ | |
472 | int mwifiex_enable_hs(struct mwifiex_adapter *adapter) | |
473 | { | |
474 | struct mwifiex_ds_hs_cfg hscfg; | |
22c22d27 AK |
475 | struct mwifiex_private *priv; |
476 | int i; | |
477 | ||
478 | if (disconnect_on_suspend) { | |
479 | for (i = 0; i < adapter->priv_num; i++) { | |
480 | priv = adapter->priv[i]; | |
481 | if (priv) | |
482 | mwifiex_deauthenticate(priv, NULL); | |
483 | } | |
484 | } | |
5e6e3a92 BZ |
485 | |
486 | if (adapter->hs_activated) { | |
69797838 | 487 | dev_dbg(adapter->dev, "cmd: HS Already activated\n"); |
5e6e3a92 BZ |
488 | return true; |
489 | } | |
490 | ||
5e6e3a92 BZ |
491 | adapter->hs_activate_wait_q_woken = false; |
492 | ||
b093863e | 493 | memset(&hscfg, 0, sizeof(struct mwifiex_ds_hs_cfg)); |
5e6e3a92 BZ |
494 | hscfg.is_invoke_hostcmd = true; |
495 | ||
496 | if (mwifiex_set_hs_params(mwifiex_get_priv(adapter, | |
500f747c | 497 | MWIFIEX_BSS_ROLE_STA), |
600f5d90 AK |
498 | HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD, |
499 | &hscfg)) { | |
5e6e3a92 BZ |
500 | dev_err(adapter->dev, "IOCTL request HS enable failed\n"); |
501 | return false; | |
502 | } | |
503 | ||
9c969d8c BZ |
504 | if (wait_event_interruptible(adapter->hs_activate_wait_q, |
505 | adapter->hs_activate_wait_q_woken)) { | |
506 | dev_err(adapter->dev, "hs_activate_wait_q terminated\n"); | |
507 | return false; | |
508 | } | |
5e6e3a92 BZ |
509 | |
510 | return true; | |
511 | } | |
512 | EXPORT_SYMBOL_GPL(mwifiex_enable_hs); | |
513 | ||
5e6e3a92 BZ |
514 | /* |
515 | * IOCTL request handler to get BSS information. | |
516 | * | |
517 | * This function collates the information from different driver structures | |
518 | * to send to the user. | |
519 | */ | |
520 | int mwifiex_get_bss_info(struct mwifiex_private *priv, | |
521 | struct mwifiex_bss_info *info) | |
522 | { | |
523 | struct mwifiex_adapter *adapter = priv->adapter; | |
524 | struct mwifiex_bssdescriptor *bss_desc; | |
5e6e3a92 BZ |
525 | |
526 | if (!info) | |
527 | return -1; | |
528 | ||
5e6e3a92 BZ |
529 | bss_desc = &priv->curr_bss_params.bss_descriptor; |
530 | ||
5e6e3a92 BZ |
531 | info->bss_mode = priv->bss_mode; |
532 | ||
b9be5f39 | 533 | memcpy(&info->ssid, &bss_desc->ssid, sizeof(struct cfg80211_ssid)); |
5e6e3a92 | 534 | |
5e6e3a92 BZ |
535 | memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN); |
536 | ||
5e6e3a92 BZ |
537 | info->bss_chan = bss_desc->channel; |
538 | ||
67fdf39e | 539 | memcpy(info->country_code, adapter->country_code, |
5e218b7a | 540 | IEEE80211_COUNTRY_STRING_LEN); |
5e6e3a92 | 541 | |
5e6e3a92 BZ |
542 | info->media_connected = priv->media_connected; |
543 | ||
5e6e3a92 BZ |
544 | info->max_power_level = priv->max_tx_power_level; |
545 | info->min_power_level = priv->min_tx_power_level; | |
546 | ||
5e6e3a92 BZ |
547 | info->adhoc_state = priv->adhoc_state; |
548 | ||
5e6e3a92 BZ |
549 | info->bcn_nf_last = priv->bcn_nf_last; |
550 | ||
5eb02e44 | 551 | if (priv->sec_info.wep_enabled) |
5e6e3a92 BZ |
552 | info->wep_status = true; |
553 | else | |
554 | info->wep_status = false; | |
555 | ||
556 | info->is_hs_configured = adapter->is_hs_configured; | |
557 | info->is_deep_sleep = adapter->is_deep_sleep; | |
558 | ||
559 | return 0; | |
560 | } | |
561 | ||
a0490936 AK |
562 | /* |
563 | * The function disables auto deep sleep mode. | |
564 | */ | |
565 | int mwifiex_disable_auto_ds(struct mwifiex_private *priv) | |
566 | { | |
567 | struct mwifiex_ds_auto_ds auto_ds; | |
568 | ||
569 | auto_ds.auto_ds = DEEP_SLEEP_OFF; | |
570 | ||
571 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH, | |
572 | DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds); | |
573 | } | |
574 | EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds); | |
575 | ||
5e6e3a92 BZ |
576 | /* |
577 | * Sends IOCTL request to get the data rate. | |
578 | * | |
579 | * This function allocates the IOCTL request buffer, fills it | |
580 | * with requisite parameters and calls the IOCTL handler. | |
581 | */ | |
006606c0 | 582 | int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate) |
5e6e3a92 | 583 | { |
270e58e8 | 584 | int ret; |
5e6e3a92 | 585 | |
006606c0 AK |
586 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_TX_RATE_QUERY, |
587 | HostCmd_ACT_GEN_GET, 0, NULL); | |
5e6e3a92 | 588 | |
5e6e3a92 | 589 | if (!ret) { |
006606c0 AK |
590 | if (priv->is_data_rate_auto) |
591 | *rate = mwifiex_index_to_data_rate(priv, priv->tx_rate, | |
592 | priv->tx_htinfo); | |
49753128 | 593 | else |
006606c0 | 594 | *rate = priv->data_rate; |
5e6e3a92 BZ |
595 | } |
596 | ||
5e6e3a92 BZ |
597 | return ret; |
598 | } | |
599 | ||
600 | /* | |
601 | * IOCTL request handler to set tx power configuration. | |
602 | * | |
603 | * This function prepares the correct firmware command and | |
604 | * issues it. | |
605 | * | |
606 | * For non-auto power mode, all the following power groups are set - | |
607 | * - Modulation class HR/DSSS | |
608 | * - Modulation class OFDM | |
609 | * - Modulation class HTBW20 | |
610 | * - Modulation class HTBW40 | |
611 | */ | |
600f5d90 AK |
612 | int mwifiex_set_tx_power(struct mwifiex_private *priv, |
613 | struct mwifiex_power_cfg *power_cfg) | |
5e6e3a92 | 614 | { |
270e58e8 YAP |
615 | int ret; |
616 | struct host_cmd_ds_txpwr_cfg *txp_cfg; | |
617 | struct mwifiex_types_power_group *pg_tlv; | |
618 | struct mwifiex_power_group *pg; | |
619 | u8 *buf; | |
5e6e3a92 BZ |
620 | u16 dbm = 0; |
621 | ||
622 | if (!power_cfg->is_power_auto) { | |
623 | dbm = (u16) power_cfg->power_level; | |
624 | if ((dbm < priv->min_tx_power_level) || | |
625 | (dbm > priv->max_tx_power_level)) { | |
626 | dev_err(priv->adapter->dev, "txpower value %d dBm" | |
500f747c YAP |
627 | " is out of range (%d dBm-%d dBm)\n", |
628 | dbm, priv->min_tx_power_level, | |
629 | priv->max_tx_power_level); | |
5e6e3a92 BZ |
630 | return -1; |
631 | } | |
632 | } | |
633 | buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL); | |
634 | if (!buf) { | |
635 | dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n", | |
500f747c | 636 | __func__); |
b53575ec | 637 | return -ENOMEM; |
5e6e3a92 BZ |
638 | } |
639 | ||
640 | txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf; | |
641 | txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET); | |
642 | if (!power_cfg->is_power_auto) { | |
643 | txp_cfg->mode = cpu_to_le32(1); | |
500f747c YAP |
644 | pg_tlv = (struct mwifiex_types_power_group *) |
645 | (buf + sizeof(struct host_cmd_ds_txpwr_cfg)); | |
5e6e3a92 BZ |
646 | pg_tlv->type = TLV_TYPE_POWER_GROUP; |
647 | pg_tlv->length = 4 * sizeof(struct mwifiex_power_group); | |
500f747c YAP |
648 | pg = (struct mwifiex_power_group *) |
649 | (buf + sizeof(struct host_cmd_ds_txpwr_cfg) | |
650 | + sizeof(struct mwifiex_types_power_group)); | |
5e6e3a92 BZ |
651 | /* Power group for modulation class HR/DSSS */ |
652 | pg->first_rate_code = 0x00; | |
653 | pg->last_rate_code = 0x03; | |
654 | pg->modulation_class = MOD_CLASS_HR_DSSS; | |
655 | pg->power_step = 0; | |
656 | pg->power_min = (s8) dbm; | |
657 | pg->power_max = (s8) dbm; | |
658 | pg++; | |
659 | /* Power group for modulation class OFDM */ | |
660 | pg->first_rate_code = 0x00; | |
661 | pg->last_rate_code = 0x07; | |
662 | pg->modulation_class = MOD_CLASS_OFDM; | |
663 | pg->power_step = 0; | |
664 | pg->power_min = (s8) dbm; | |
665 | pg->power_max = (s8) dbm; | |
666 | pg++; | |
667 | /* Power group for modulation class HTBW20 */ | |
668 | pg->first_rate_code = 0x00; | |
669 | pg->last_rate_code = 0x20; | |
670 | pg->modulation_class = MOD_CLASS_HT; | |
671 | pg->power_step = 0; | |
672 | pg->power_min = (s8) dbm; | |
673 | pg->power_max = (s8) dbm; | |
674 | pg->ht_bandwidth = HT_BW_20; | |
675 | pg++; | |
676 | /* Power group for modulation class HTBW40 */ | |
677 | pg->first_rate_code = 0x00; | |
678 | pg->last_rate_code = 0x20; | |
679 | pg->modulation_class = MOD_CLASS_HT; | |
680 | pg->power_step = 0; | |
681 | pg->power_min = (s8) dbm; | |
682 | pg->power_max = (s8) dbm; | |
683 | pg->ht_bandwidth = HT_BW_40; | |
684 | } | |
600f5d90 AK |
685 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG, |
686 | HostCmd_ACT_GEN_SET, 0, buf); | |
5e6e3a92 | 687 | |
600f5d90 | 688 | kfree(buf); |
5e6e3a92 BZ |
689 | return ret; |
690 | } | |
691 | ||
692 | /* | |
693 | * IOCTL request handler to get power save mode. | |
694 | * | |
695 | * This function prepares the correct firmware command and | |
696 | * issues it. | |
697 | */ | |
600f5d90 | 698 | int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode) |
5e6e3a92 | 699 | { |
270e58e8 | 700 | int ret; |
5e6e3a92 BZ |
701 | struct mwifiex_adapter *adapter = priv->adapter; |
702 | u16 sub_cmd; | |
703 | ||
600f5d90 AK |
704 | if (*ps_mode) |
705 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP; | |
706 | else | |
707 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM; | |
708 | sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS; | |
709 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH, | |
710 | sub_cmd, BITMAP_STA_PS, NULL); | |
711 | if ((!ret) && (sub_cmd == DIS_AUTO_PS)) | |
712 | ret = mwifiex_send_cmd_async(priv, | |
500f747c YAP |
713 | HostCmd_CMD_802_11_PS_MODE_ENH, |
714 | GET_PS, 0, NULL); | |
5e6e3a92 BZ |
715 | |
716 | return ret; | |
717 | } | |
718 | ||
719 | /* | |
720 | * IOCTL request handler to set/reset WPA IE. | |
721 | * | |
722 | * The supplied WPA IE is treated as a opaque buffer. Only the first field | |
723 | * is checked to determine WPA version. If buffer length is zero, the existing | |
724 | * WPA IE is reset. | |
725 | */ | |
726 | static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv, | |
727 | u8 *ie_data_ptr, u16 ie_len) | |
728 | { | |
729 | if (ie_len) { | |
730 | if (ie_len > sizeof(priv->wpa_ie)) { | |
731 | dev_err(priv->adapter->dev, | |
732 | "failed to copy WPA IE, too big\n"); | |
733 | return -1; | |
734 | } | |
735 | memcpy(priv->wpa_ie, ie_data_ptr, ie_len); | |
736 | priv->wpa_ie_len = (u8) ie_len; | |
737 | dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n", | |
500f747c | 738 | priv->wpa_ie_len, priv->wpa_ie[0]); |
5e6e3a92 | 739 | |
04b2312a | 740 | if (priv->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) { |
5e6e3a92 BZ |
741 | priv->sec_info.wpa_enabled = true; |
742 | } else if (priv->wpa_ie[0] == WLAN_EID_RSN) { | |
743 | priv->sec_info.wpa2_enabled = true; | |
744 | } else { | |
745 | priv->sec_info.wpa_enabled = false; | |
746 | priv->sec_info.wpa2_enabled = false; | |
747 | } | |
748 | } else { | |
749 | memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie)); | |
750 | priv->wpa_ie_len = 0; | |
751 | dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n", | |
752 | priv->wpa_ie_len, priv->wpa_ie[0]); | |
753 | priv->sec_info.wpa_enabled = false; | |
754 | priv->sec_info.wpa2_enabled = false; | |
755 | } | |
756 | ||
757 | return 0; | |
758 | } | |
759 | ||
760 | /* | |
761 | * IOCTL request handler to set/reset WAPI IE. | |
762 | * | |
763 | * The supplied WAPI IE is treated as a opaque buffer. Only the first field | |
764 | * is checked to internally enable WAPI. If buffer length is zero, the existing | |
765 | * WAPI IE is reset. | |
766 | */ | |
767 | static int mwifiex_set_wapi_ie(struct mwifiex_private *priv, | |
768 | u8 *ie_data_ptr, u16 ie_len) | |
769 | { | |
770 | if (ie_len) { | |
771 | if (ie_len > sizeof(priv->wapi_ie)) { | |
772 | dev_dbg(priv->adapter->dev, | |
773 | "info: failed to copy WAPI IE, too big\n"); | |
774 | return -1; | |
775 | } | |
776 | memcpy(priv->wapi_ie, ie_data_ptr, ie_len); | |
777 | priv->wapi_ie_len = ie_len; | |
778 | dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n", | |
500f747c | 779 | priv->wapi_ie_len, priv->wapi_ie[0]); |
5e6e3a92 BZ |
780 | |
781 | if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY) | |
782 | priv->sec_info.wapi_enabled = true; | |
783 | } else { | |
784 | memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie)); | |
785 | priv->wapi_ie_len = ie_len; | |
786 | dev_dbg(priv->adapter->dev, | |
787 | "info: Reset wapi_ie_len=%d IE=%#x\n", | |
788 | priv->wapi_ie_len, priv->wapi_ie[0]); | |
789 | priv->sec_info.wapi_enabled = false; | |
790 | } | |
791 | return 0; | |
792 | } | |
793 | ||
13d7ba78 AP |
794 | /* |
795 | * IOCTL request handler to set/reset WPS IE. | |
796 | * | |
797 | * The supplied WPS IE is treated as a opaque buffer. Only the first field | |
798 | * is checked to internally enable WPS. If buffer length is zero, the existing | |
799 | * WPS IE is reset. | |
800 | */ | |
801 | static int mwifiex_set_wps_ie(struct mwifiex_private *priv, | |
802 | u8 *ie_data_ptr, u16 ie_len) | |
803 | { | |
804 | if (ie_len) { | |
805 | priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL); | |
806 | if (!priv->wps_ie) | |
807 | return -ENOMEM; | |
808 | if (ie_len > sizeof(priv->wps_ie)) { | |
809 | dev_dbg(priv->adapter->dev, | |
810 | "info: failed to copy WPS IE, too big\n"); | |
811 | kfree(priv->wps_ie); | |
812 | return -1; | |
813 | } | |
814 | memcpy(priv->wps_ie, ie_data_ptr, ie_len); | |
815 | priv->wps_ie_len = ie_len; | |
816 | dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n", | |
817 | priv->wps_ie_len, priv->wps_ie[0]); | |
818 | } else { | |
819 | kfree(priv->wps_ie); | |
820 | priv->wps_ie_len = ie_len; | |
821 | dev_dbg(priv->adapter->dev, | |
822 | "info: Reset wps_ie_len=%d\n", priv->wps_ie_len); | |
823 | } | |
824 | return 0; | |
825 | } | |
826 | ||
5e6e3a92 BZ |
827 | /* |
828 | * IOCTL request handler to set WAPI key. | |
829 | * | |
830 | * This function prepares the correct firmware command and | |
831 | * issues it. | |
832 | */ | |
600f5d90 | 833 | static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv, |
5e6e3a92 BZ |
834 | struct mwifiex_ds_encrypt_key *encrypt_key) |
835 | { | |
5e6e3a92 | 836 | |
636c4598 | 837 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL, |
500f747c YAP |
838 | HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED, |
839 | encrypt_key); | |
5e6e3a92 BZ |
840 | } |
841 | ||
5e6e3a92 BZ |
842 | /* |
843 | * IOCTL request handler to set WEP network key. | |
844 | * | |
845 | * This function prepares the correct firmware command and | |
846 | * issues it, after validation checks. | |
847 | */ | |
600f5d90 | 848 | static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv, |
5e6e3a92 BZ |
849 | struct mwifiex_ds_encrypt_key *encrypt_key) |
850 | { | |
270e58e8 YAP |
851 | int ret; |
852 | struct mwifiex_wep_key *wep_key; | |
5e6e3a92 BZ |
853 | int index; |
854 | ||
855 | if (priv->wep_key_curr_index >= NUM_WEP_KEYS) | |
856 | priv->wep_key_curr_index = 0; | |
857 | wep_key = &priv->wep_key[priv->wep_key_curr_index]; | |
858 | index = encrypt_key->key_index; | |
859 | if (encrypt_key->key_disable) { | |
5eb02e44 | 860 | priv->sec_info.wep_enabled = 0; |
5e6e3a92 BZ |
861 | } else if (!encrypt_key->key_len) { |
862 | /* Copy the required key as the current key */ | |
863 | wep_key = &priv->wep_key[index]; | |
864 | if (!wep_key->key_length) { | |
600f5d90 | 865 | dev_err(priv->adapter->dev, |
5e6e3a92 BZ |
866 | "key not set, so cannot enable it\n"); |
867 | return -1; | |
868 | } | |
869 | priv->wep_key_curr_index = (u16) index; | |
5eb02e44 | 870 | priv->sec_info.wep_enabled = 1; |
5e6e3a92 BZ |
871 | } else { |
872 | wep_key = &priv->wep_key[index]; | |
5e6e3a92 BZ |
873 | memset(wep_key, 0, sizeof(struct mwifiex_wep_key)); |
874 | /* Copy the key in the driver */ | |
875 | memcpy(wep_key->key_material, | |
876 | encrypt_key->key_material, | |
877 | encrypt_key->key_len); | |
878 | wep_key->key_index = index; | |
879 | wep_key->key_length = encrypt_key->key_len; | |
5eb02e44 | 880 | priv->sec_info.wep_enabled = 1; |
5e6e3a92 BZ |
881 | } |
882 | if (wep_key->key_length) { | |
883 | /* Send request to firmware */ | |
600f5d90 AK |
884 | ret = mwifiex_send_cmd_async(priv, |
885 | HostCmd_CMD_802_11_KEY_MATERIAL, | |
886 | HostCmd_ACT_GEN_SET, 0, NULL); | |
5e6e3a92 BZ |
887 | if (ret) |
888 | return ret; | |
889 | } | |
5eb02e44 | 890 | if (priv->sec_info.wep_enabled) |
5e6e3a92 BZ |
891 | priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE; |
892 | else | |
893 | priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE; | |
894 | ||
600f5d90 AK |
895 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL, |
896 | HostCmd_ACT_GEN_SET, 0, | |
897 | &priv->curr_pkt_filter); | |
5e6e3a92 BZ |
898 | |
899 | return ret; | |
900 | } | |
901 | ||
902 | /* | |
903 | * IOCTL request handler to set WPA key. | |
904 | * | |
905 | * This function prepares the correct firmware command and | |
906 | * issues it, after validation checks. | |
907 | * | |
908 | * Current driver only supports key length of up to 32 bytes. | |
909 | * | |
910 | * This function can also be used to disable a currently set key. | |
911 | */ | |
600f5d90 | 912 | static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv, |
5e6e3a92 BZ |
913 | struct mwifiex_ds_encrypt_key *encrypt_key) |
914 | { | |
270e58e8 | 915 | int ret; |
5e6e3a92 BZ |
916 | u8 remove_key = false; |
917 | struct host_cmd_ds_802_11_key_material *ibss_key; | |
918 | ||
919 | /* Current driver only supports key length of up to 32 bytes */ | |
a3731658 | 920 | if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) { |
600f5d90 | 921 | dev_err(priv->adapter->dev, "key length too long\n"); |
5e6e3a92 BZ |
922 | return -1; |
923 | } | |
924 | ||
eecd8250 | 925 | if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { |
5e6e3a92 BZ |
926 | /* |
927 | * IBSS/WPA-None uses only one key (Group) for both receiving | |
928 | * and sending unicast and multicast packets. | |
929 | */ | |
930 | /* Send the key as PTK to firmware */ | |
931 | encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST; | |
600f5d90 | 932 | ret = mwifiex_send_cmd_async(priv, |
500f747c YAP |
933 | HostCmd_CMD_802_11_KEY_MATERIAL, |
934 | HostCmd_ACT_GEN_SET, | |
935 | KEY_INFO_ENABLED, encrypt_key); | |
5e6e3a92 BZ |
936 | if (ret) |
937 | return ret; | |
938 | ||
939 | ibss_key = &priv->aes_key; | |
940 | memset(ibss_key, 0, | |
941 | sizeof(struct host_cmd_ds_802_11_key_material)); | |
942 | /* Copy the key in the driver */ | |
943 | memcpy(ibss_key->key_param_set.key, encrypt_key->key_material, | |
944 | encrypt_key->key_len); | |
945 | memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len, | |
946 | sizeof(ibss_key->key_param_set.key_len)); | |
947 | ibss_key->key_param_set.key_type_id | |
948 | = cpu_to_le16(KEY_TYPE_ID_TKIP); | |
6a35a0ac | 949 | ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED); |
5e6e3a92 BZ |
950 | |
951 | /* Send the key as GTK to firmware */ | |
952 | encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST; | |
953 | } | |
954 | ||
955 | if (!encrypt_key->key_index) | |
956 | encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST; | |
957 | ||
958 | if (remove_key) | |
600f5d90 | 959 | ret = mwifiex_send_cmd_sync(priv, |
500f747c YAP |
960 | HostCmd_CMD_802_11_KEY_MATERIAL, |
961 | HostCmd_ACT_GEN_SET, | |
962 | !KEY_INFO_ENABLED, encrypt_key); | |
5e6e3a92 | 963 | else |
600f5d90 | 964 | ret = mwifiex_send_cmd_sync(priv, |
500f747c YAP |
965 | HostCmd_CMD_802_11_KEY_MATERIAL, |
966 | HostCmd_ACT_GEN_SET, | |
967 | KEY_INFO_ENABLED, encrypt_key); | |
5e6e3a92 BZ |
968 | |
969 | return ret; | |
970 | } | |
971 | ||
972 | /* | |
973 | * IOCTL request handler to set/get network keys. | |
974 | * | |
975 | * This is a generic key handling function which supports WEP, WPA | |
976 | * and WAPI. | |
977 | */ | |
978 | static int | |
979 | mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv, | |
5e6e3a92 BZ |
980 | struct mwifiex_ds_encrypt_key *encrypt_key) |
981 | { | |
270e58e8 | 982 | int status; |
5e6e3a92 BZ |
983 | |
984 | if (encrypt_key->is_wapi_key) | |
600f5d90 | 985 | status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key); |
5e6e3a92 | 986 | else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104) |
600f5d90 | 987 | status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key); |
5e6e3a92 | 988 | else |
600f5d90 | 989 | status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key); |
5e6e3a92 BZ |
990 | return status; |
991 | } | |
992 | ||
993 | /* | |
994 | * This function returns the driver version. | |
995 | */ | |
996 | int | |
997 | mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version, | |
998 | int max_len) | |
999 | { | |
1000 | union { | |
1001 | u32 l; | |
1002 | u8 c[4]; | |
1003 | } ver; | |
1004 | char fw_ver[32]; | |
1005 | ||
1006 | ver.l = adapter->fw_release_number; | |
1007 | sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]); | |
1008 | ||
1009 | snprintf(version, max_len, driver_version, fw_ver); | |
1010 | ||
1011 | dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version); | |
1012 | ||
1013 | return 0; | |
1014 | } | |
1015 | ||
5e6e3a92 BZ |
1016 | /* |
1017 | * Sends IOCTL request to set encoding parameters. | |
1018 | * | |
1019 | * This function allocates the IOCTL request buffer, fills it | |
1020 | * with requisite parameters and calls the IOCTL handler. | |
1021 | */ | |
53b11231 YL |
1022 | int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp, |
1023 | const u8 *key, int key_len, u8 key_index, | |
1024 | const u8 *mac_addr, int disable) | |
5e6e3a92 | 1025 | { |
5e6e3a92 | 1026 | struct mwifiex_ds_encrypt_key encrypt_key; |
5e6e3a92 | 1027 | |
5e6e3a92 BZ |
1028 | memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key)); |
1029 | encrypt_key.key_len = key_len; | |
53b11231 YL |
1030 | |
1031 | if (kp && kp->cipher == WLAN_CIPHER_SUITE_AES_CMAC) | |
1032 | encrypt_key.is_igtk_key = true; | |
1033 | ||
5e6e3a92 BZ |
1034 | if (!disable) { |
1035 | encrypt_key.key_index = key_index; | |
1036 | if (key_len) | |
1037 | memcpy(encrypt_key.key_material, key, key_len); | |
75edd2c6 AP |
1038 | if (mac_addr) |
1039 | memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN); | |
53b11231 YL |
1040 | if (kp && kp->seq && kp->seq_len) |
1041 | memcpy(encrypt_key.pn, kp->seq, kp->seq_len); | |
5e6e3a92 BZ |
1042 | } else { |
1043 | encrypt_key.key_disable = true; | |
75edd2c6 AP |
1044 | if (mac_addr) |
1045 | memcpy(encrypt_key.mac_addr, mac_addr, ETH_ALEN); | |
5e6e3a92 BZ |
1046 | } |
1047 | ||
636c4598 | 1048 | return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key); |
5e6e3a92 BZ |
1049 | } |
1050 | ||
1051 | /* | |
1052 | * Sends IOCTL request to get extended version. | |
1053 | * | |
1054 | * This function allocates the IOCTL request buffer, fills it | |
1055 | * with requisite parameters and calls the IOCTL handler. | |
1056 | */ | |
1057 | int | |
1058 | mwifiex_get_ver_ext(struct mwifiex_private *priv) | |
1059 | { | |
1060 | struct mwifiex_ver_ext ver_ext; | |
5e6e3a92 | 1061 | |
5e6e3a92 | 1062 | memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext)); |
636c4598 | 1063 | if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT, |
500f747c | 1064 | HostCmd_ACT_GEN_GET, 0, &ver_ext)) |
636c4598 | 1065 | return -1; |
5e6e3a92 | 1066 | |
636c4598 | 1067 | return 0; |
5e6e3a92 BZ |
1068 | } |
1069 | ||
7feb4c48 SP |
1070 | int |
1071 | mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action, | |
1072 | struct ieee80211_channel *chan, | |
7feb4c48 SP |
1073 | unsigned int duration) |
1074 | { | |
1075 | struct host_cmd_ds_remain_on_chan roc_cfg; | |
1076 | u8 sc; | |
1077 | ||
1078 | memset(&roc_cfg, 0, sizeof(roc_cfg)); | |
1079 | roc_cfg.action = cpu_to_le16(action); | |
1080 | if (action == HostCmd_ACT_GEN_SET) { | |
1081 | roc_cfg.band_cfg = chan->band; | |
42d97a59 | 1082 | sc = mwifiex_chan_type_to_sec_chan_offset(NL80211_CHAN_NO_HT); |
7feb4c48 SP |
1083 | roc_cfg.band_cfg |= (sc << 2); |
1084 | ||
1085 | roc_cfg.channel = | |
1086 | ieee80211_frequency_to_channel(chan->center_freq); | |
1087 | roc_cfg.duration = cpu_to_le32(duration); | |
1088 | } | |
1089 | if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_REMAIN_ON_CHAN, | |
1090 | action, 0, &roc_cfg)) { | |
1091 | dev_err(priv->adapter->dev, "failed to remain on channel\n"); | |
1092 | return -1; | |
1093 | } | |
1094 | ||
1095 | return roc_cfg.status; | |
1096 | } | |
1097 | ||
9197ab9e SP |
1098 | int |
1099 | mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role) | |
1100 | { | |
1101 | if (GET_BSS_ROLE(priv) == bss_role) { | |
1102 | dev_dbg(priv->adapter->dev, | |
1103 | "info: already in the desired role.\n"); | |
1104 | return 0; | |
1105 | } | |
1106 | ||
1107 | mwifiex_free_priv(priv); | |
1108 | mwifiex_init_priv(priv); | |
1109 | ||
1110 | priv->bss_role = bss_role; | |
1111 | switch (bss_role) { | |
1112 | case MWIFIEX_BSS_ROLE_UAP: | |
1113 | priv->bss_mode = NL80211_IFTYPE_AP; | |
1114 | break; | |
1115 | case MWIFIEX_BSS_ROLE_STA: | |
1116 | case MWIFIEX_BSS_ROLE_ANY: | |
1117 | default: | |
1118 | priv->bss_mode = NL80211_IFTYPE_STATION; | |
1119 | break; | |
1120 | } | |
1121 | ||
1122 | mwifiex_send_cmd_sync(priv, HostCmd_CMD_SET_BSS_MODE, | |
1123 | HostCmd_ACT_GEN_SET, 0, NULL); | |
1124 | ||
1125 | return mwifiex_sta_init_cmd(priv, false); | |
1126 | } | |
1127 | ||
5e6e3a92 BZ |
1128 | /* |
1129 | * Sends IOCTL request to get statistics information. | |
1130 | * | |
1131 | * This function allocates the IOCTL request buffer, fills it | |
1132 | * with requisite parameters and calls the IOCTL handler. | |
1133 | */ | |
1134 | int | |
1135 | mwifiex_get_stats_info(struct mwifiex_private *priv, | |
1136 | struct mwifiex_ds_get_stats *log) | |
1137 | { | |
67a50035 | 1138 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG, |
500f747c | 1139 | HostCmd_ACT_GEN_GET, 0, log); |
5e6e3a92 BZ |
1140 | } |
1141 | ||
1142 | /* | |
1143 | * IOCTL request handler to read/write register. | |
1144 | * | |
1145 | * This function prepares the correct firmware command and | |
1146 | * issues it. | |
1147 | * | |
1148 | * Access to the following registers are supported - | |
1149 | * - MAC | |
1150 | * - BBP | |
1151 | * - RF | |
1152 | * - PMIC | |
1153 | * - CAU | |
1154 | */ | |
1155 | static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv, | |
5e6e3a92 BZ |
1156 | struct mwifiex_ds_reg_rw *reg_rw, |
1157 | u16 action) | |
1158 | { | |
5e6e3a92 BZ |
1159 | u16 cmd_no; |
1160 | ||
1161 | switch (le32_to_cpu(reg_rw->type)) { | |
1162 | case MWIFIEX_REG_MAC: | |
1163 | cmd_no = HostCmd_CMD_MAC_REG_ACCESS; | |
1164 | break; | |
1165 | case MWIFIEX_REG_BBP: | |
1166 | cmd_no = HostCmd_CMD_BBP_REG_ACCESS; | |
1167 | break; | |
1168 | case MWIFIEX_REG_RF: | |
1169 | cmd_no = HostCmd_CMD_RF_REG_ACCESS; | |
1170 | break; | |
1171 | case MWIFIEX_REG_PMIC: | |
1172 | cmd_no = HostCmd_CMD_PMIC_REG_ACCESS; | |
1173 | break; | |
1174 | case MWIFIEX_REG_CAU: | |
1175 | cmd_no = HostCmd_CMD_CAU_REG_ACCESS; | |
1176 | break; | |
1177 | default: | |
1178 | return -1; | |
1179 | } | |
1180 | ||
636c4598 | 1181 | return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw); |
5e6e3a92 | 1182 | |
5e6e3a92 BZ |
1183 | } |
1184 | ||
1185 | /* | |
1186 | * Sends IOCTL request to write to a register. | |
1187 | * | |
1188 | * This function allocates the IOCTL request buffer, fills it | |
1189 | * with requisite parameters and calls the IOCTL handler. | |
1190 | */ | |
1191 | int | |
1192 | mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type, | |
1193 | u32 reg_offset, u32 reg_value) | |
1194 | { | |
5e6e3a92 BZ |
1195 | struct mwifiex_ds_reg_rw reg_rw; |
1196 | ||
5e6e3a92 BZ |
1197 | reg_rw.type = cpu_to_le32(reg_type); |
1198 | reg_rw.offset = cpu_to_le32(reg_offset); | |
1199 | reg_rw.value = cpu_to_le32(reg_value); | |
5e6e3a92 | 1200 | |
636c4598 | 1201 | return mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_SET); |
5e6e3a92 BZ |
1202 | } |
1203 | ||
1204 | /* | |
1205 | * Sends IOCTL request to read from a register. | |
1206 | * | |
1207 | * This function allocates the IOCTL request buffer, fills it | |
1208 | * with requisite parameters and calls the IOCTL handler. | |
1209 | */ | |
1210 | int | |
1211 | mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type, | |
1212 | u32 reg_offset, u32 *value) | |
1213 | { | |
270e58e8 | 1214 | int ret; |
5e6e3a92 BZ |
1215 | struct mwifiex_ds_reg_rw reg_rw; |
1216 | ||
5e6e3a92 BZ |
1217 | reg_rw.type = cpu_to_le32(reg_type); |
1218 | reg_rw.offset = cpu_to_le32(reg_offset); | |
600f5d90 | 1219 | ret = mwifiex_reg_mem_ioctl_reg_rw(priv, ®_rw, HostCmd_ACT_GEN_GET); |
5e6e3a92 | 1220 | |
5e6e3a92 BZ |
1221 | if (ret) |
1222 | goto done; | |
1223 | ||
1224 | *value = le32_to_cpu(reg_rw.value); | |
1225 | ||
1226 | done: | |
5e6e3a92 BZ |
1227 | return ret; |
1228 | } | |
1229 | ||
1230 | /* | |
1231 | * Sends IOCTL request to read from EEPROM. | |
1232 | * | |
1233 | * This function allocates the IOCTL request buffer, fills it | |
1234 | * with requisite parameters and calls the IOCTL handler. | |
1235 | */ | |
1236 | int | |
1237 | mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes, | |
1238 | u8 *value) | |
1239 | { | |
270e58e8 | 1240 | int ret; |
5e6e3a92 BZ |
1241 | struct mwifiex_ds_read_eeprom rd_eeprom; |
1242 | ||
5e6e3a92 BZ |
1243 | rd_eeprom.offset = cpu_to_le16((u16) offset); |
1244 | rd_eeprom.byte_count = cpu_to_le16((u16) bytes); | |
5e6e3a92 | 1245 | |
600f5d90 AK |
1246 | /* Send request to firmware */ |
1247 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS, | |
1248 | HostCmd_ACT_GEN_GET, 0, &rd_eeprom); | |
5e6e3a92 | 1249 | |
600f5d90 AK |
1250 | if (!ret) |
1251 | memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA); | |
5e6e3a92 BZ |
1252 | return ret; |
1253 | } | |
1254 | ||
1255 | /* | |
1256 | * This function sets a generic IE. In addition to generic IE, it can | |
1257 | * also handle WPA, WPA2 and WAPI IEs. | |
1258 | */ | |
1259 | static int | |
1260 | mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr, | |
1261 | u16 ie_len) | |
1262 | { | |
1263 | int ret = 0; | |
1264 | struct ieee_types_vendor_header *pvendor_ie; | |
1265 | const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 }; | |
1266 | const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 }; | |
1267 | ||
1268 | /* If the passed length is zero, reset the buffer */ | |
1269 | if (!ie_len) { | |
1270 | priv->gen_ie_buf_len = 0; | |
1271 | priv->wps.session_enable = false; | |
1272 | ||
1273 | return 0; | |
1274 | } else if (!ie_data_ptr) { | |
1275 | return -1; | |
1276 | } | |
1277 | pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr; | |
1278 | /* Test to see if it is a WPA IE, if not, then it is a gen IE */ | |
04b2312a | 1279 | if (((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) && |
500f747c YAP |
1280 | (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) || |
1281 | (pvendor_ie->element_id == WLAN_EID_RSN)) { | |
5e6e3a92 BZ |
1282 | |
1283 | /* IE is a WPA/WPA2 IE so call set_wpa function */ | |
1284 | ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len); | |
1285 | priv->wps.session_enable = false; | |
1286 | ||
1287 | return ret; | |
1288 | } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) { | |
1289 | /* IE is a WAPI IE so call set_wapi function */ | |
1290 | ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len); | |
1291 | ||
1292 | return ret; | |
1293 | } | |
1294 | /* | |
1295 | * Verify that the passed length is not larger than the | |
1296 | * available space remaining in the buffer | |
1297 | */ | |
1298 | if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) { | |
1299 | ||
1300 | /* Test to see if it is a WPS IE, if so, enable | |
1301 | * wps session flag | |
1302 | */ | |
1303 | pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr; | |
500f747c YAP |
1304 | if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) && |
1305 | (!memcmp(pvendor_ie->oui, wps_oui, sizeof(wps_oui)))) { | |
5e6e3a92 BZ |
1306 | priv->wps.session_enable = true; |
1307 | dev_dbg(priv->adapter->dev, | |
1308 | "info: WPS Session Enabled.\n"); | |
13d7ba78 | 1309 | ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len); |
5e6e3a92 BZ |
1310 | } |
1311 | ||
1312 | /* Append the passed data to the end of the | |
1313 | genIeBuffer */ | |
1314 | memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr, | |
500f747c | 1315 | ie_len); |
5e6e3a92 BZ |
1316 | /* Increment the stored buffer length by the |
1317 | size passed */ | |
1318 | priv->gen_ie_buf_len += ie_len; | |
1319 | } else { | |
1320 | /* Passed data does not fit in the remaining | |
1321 | buffer space */ | |
1322 | ret = -1; | |
1323 | } | |
1324 | ||
1325 | /* Return 0, or -1 for error case */ | |
1326 | return ret; | |
1327 | } | |
1328 | ||
1329 | /* | |
1330 | * IOCTL request handler to set/get generic IE. | |
1331 | * | |
1332 | * In addition to various generic IEs, this function can also be | |
1333 | * used to set the ARP filter. | |
1334 | */ | |
1335 | static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv, | |
1336 | struct mwifiex_ds_misc_gen_ie *gen_ie, | |
1337 | u16 action) | |
1338 | { | |
1339 | struct mwifiex_adapter *adapter = priv->adapter; | |
1340 | ||
1341 | switch (gen_ie->type) { | |
1342 | case MWIFIEX_IE_TYPE_GEN_IE: | |
1343 | if (action == HostCmd_ACT_GEN_GET) { | |
1344 | gen_ie->len = priv->wpa_ie_len; | |
1345 | memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len); | |
1346 | } else { | |
1347 | mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data, | |
1348 | (u16) gen_ie->len); | |
1349 | } | |
1350 | break; | |
1351 | case MWIFIEX_IE_TYPE_ARP_FILTER: | |
1352 | memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter)); | |
1353 | if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) { | |
1354 | adapter->arp_filter_size = 0; | |
1355 | dev_err(adapter->dev, "invalid ARP filter size\n"); | |
1356 | return -1; | |
1357 | } else { | |
1358 | memcpy(adapter->arp_filter, gen_ie->ie_data, | |
500f747c | 1359 | gen_ie->len); |
5e6e3a92 BZ |
1360 | adapter->arp_filter_size = gen_ie->len; |
1361 | } | |
1362 | break; | |
1363 | default: | |
1364 | dev_err(adapter->dev, "invalid IE type\n"); | |
1365 | return -1; | |
1366 | } | |
1367 | return 0; | |
1368 | } | |
1369 | ||
1370 | /* | |
1371 | * Sends IOCTL request to set a generic IE. | |
1372 | * | |
1373 | * This function allocates the IOCTL request buffer, fills it | |
1374 | * with requisite parameters and calls the IOCTL handler. | |
1375 | */ | |
1376 | int | |
1377 | mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len) | |
1378 | { | |
1379 | struct mwifiex_ds_misc_gen_ie gen_ie; | |
5e6e3a92 | 1380 | |
67a50035 | 1381 | if (ie_len > IEEE_MAX_IE_SIZE) |
5e6e3a92 BZ |
1382 | return -EFAULT; |
1383 | ||
1384 | gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE; | |
1385 | gen_ie.len = ie_len; | |
1386 | memcpy(gen_ie.ie_data, ie, ie_len); | |
636c4598 | 1387 | if (mwifiex_misc_ioctl_gen_ie(priv, &gen_ie, HostCmd_ACT_GEN_SET)) |
5e6e3a92 BZ |
1388 | return -EFAULT; |
1389 | ||
1390 | return 0; | |
1391 | } |