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