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