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