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