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