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