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