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