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