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 | |
| 29 | /* |
| 30 | * Copies the multicast address list from device to driver. |
| 31 | * |
| 32 | * This function does not validate the destination memory for |
| 33 | * size, and the calling function must ensure enough memory is |
| 34 | * available. |
| 35 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 36 | int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist, |
| 37 | struct net_device *dev) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 38 | { |
| 39 | int i = 0; |
| 40 | struct netdev_hw_addr *ha; |
| 41 | |
| 42 | netdev_for_each_mc_addr(ha, dev) |
| 43 | memcpy(&mlist->mac_list[i++], ha->addr, ETH_ALEN); |
| 44 | |
| 45 | return i; |
| 46 | } |
| 47 | |
| 48 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 49 | * Wait queue completion handler. |
| 50 | * |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 51 | * This function waits on a cmd wait queue. It also cancels the pending |
| 52 | * request after waking up, in case of errors. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 53 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 54 | int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 55 | { |
| 56 | bool cancel_flag = false; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 57 | int status = adapter->cmd_wait_q.status; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 58 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 59 | dev_dbg(adapter->dev, "cmd pending\n"); |
| 60 | atomic_inc(&adapter->cmd_pending); |
| 61 | |
| 62 | /* Status pending, wake up main process */ |
| 63 | queue_work(adapter->workqueue, &adapter->main_work); |
| 64 | |
| 65 | /* Wait for completion */ |
| 66 | wait_event_interruptible(adapter->cmd_wait_q.wait, |
| 67 | adapter->cmd_wait_q.condition); |
| 68 | if (!adapter->cmd_wait_q.condition) |
| 69 | cancel_flag = true; |
| 70 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 71 | if (cancel_flag) { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 72 | mwifiex_cancel_pending_ioctl(adapter); |
| 73 | dev_dbg(adapter->dev, "cmd cancel\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 74 | } |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 75 | adapter->cmd_wait_q.status = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 76 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 77 | return status; |
| 78 | } |
| 79 | |
| 80 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 81 | * This function prepares the correct firmware command and |
| 82 | * issues it to set the multicast list. |
| 83 | * |
| 84 | * This function can be used to enable promiscuous mode, or enable all |
| 85 | * multicast packets, or to enable selective multicast. |
| 86 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 87 | int mwifiex_request_set_multicast_list(struct mwifiex_private *priv, |
| 88 | struct mwifiex_multicast_list *mcast_list) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 89 | { |
| 90 | int ret = 0; |
| 91 | u16 old_pkt_filter; |
| 92 | |
| 93 | old_pkt_filter = priv->curr_pkt_filter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 94 | |
| 95 | if (mcast_list->mode == MWIFIEX_PROMISC_MODE) { |
| 96 | dev_dbg(priv->adapter->dev, "info: Enable Promiscuous mode\n"); |
| 97 | priv->curr_pkt_filter |= HostCmd_ACT_MAC_PROMISCUOUS_ENABLE; |
| 98 | priv->curr_pkt_filter &= |
| 99 | ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE; |
| 100 | } else { |
| 101 | /* Multicast */ |
| 102 | priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_PROMISCUOUS_ENABLE; |
| 103 | if (mcast_list->mode == MWIFIEX_MULTICAST_MODE) { |
| 104 | dev_dbg(priv->adapter->dev, |
| 105 | "info: Enabling All Multicast!\n"); |
| 106 | priv->curr_pkt_filter |= |
| 107 | HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE; |
| 108 | } else { |
| 109 | priv->curr_pkt_filter &= |
| 110 | ~HostCmd_ACT_MAC_ALL_MULTICAST_ENABLE; |
| 111 | if (mcast_list->num_multicast_addr) { |
| 112 | dev_dbg(priv->adapter->dev, |
| 113 | "info: Set multicast list=%d\n", |
| 114 | mcast_list->num_multicast_addr); |
| 115 | /* Set multicast addresses to firmware */ |
| 116 | if (old_pkt_filter == priv->curr_pkt_filter) { |
| 117 | /* Send request to firmware */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 118 | ret = mwifiex_send_cmd_async(priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 119 | HostCmd_CMD_MAC_MULTICAST_ADR, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 120 | HostCmd_ACT_GEN_SET, 0, |
| 121 | mcast_list); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 122 | } else { |
| 123 | /* Send request to firmware */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 124 | ret = mwifiex_send_cmd_async(priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 125 | HostCmd_CMD_MAC_MULTICAST_ADR, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 126 | HostCmd_ACT_GEN_SET, 0, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 127 | mcast_list); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | dev_dbg(priv->adapter->dev, |
| 133 | "info: old_pkt_filter=%#x, curr_pkt_filter=%#x\n", |
| 134 | old_pkt_filter, priv->curr_pkt_filter); |
| 135 | if (old_pkt_filter != priv->curr_pkt_filter) { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 136 | ret = mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL, |
| 137 | HostCmd_ACT_GEN_SET, |
| 138 | 0, &priv->curr_pkt_filter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 145 | * In Ad-Hoc mode, the IBSS is created if not found in scan list. |
| 146 | * In both Ad-Hoc and infra mode, an deauthentication is performed |
| 147 | * first. |
| 148 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 149 | int mwifiex_bss_start(struct mwifiex_private *priv, |
| 150 | struct mwifiex_ssid_bssid *ssid_bssid) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 151 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 152 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 153 | struct mwifiex_adapter *adapter = priv->adapter; |
| 154 | s32 i = -1; |
| 155 | |
| 156 | priv->scan_block = false; |
| 157 | if (!ssid_bssid) |
| 158 | return -1; |
| 159 | |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 160 | if (priv->bss_mode == NL80211_IFTYPE_STATION) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 161 | /* Infra mode */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 162 | ret = mwifiex_deauthenticate(priv, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 163 | if (ret) |
| 164 | return ret; |
| 165 | |
| 166 | /* Search for the requested SSID in the scan table */ |
| 167 | if (ssid_bssid->ssid.ssid_len) |
| 168 | i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid, |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 169 | NULL, NL80211_IFTYPE_STATION); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 170 | else |
| 171 | i = mwifiex_find_bssid_in_list(priv, |
| 172 | (u8 *) &ssid_bssid->bssid, |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 173 | NL80211_IFTYPE_STATION); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 174 | if (i < 0) |
| 175 | return -1; |
| 176 | |
| 177 | dev_dbg(adapter->dev, |
| 178 | "info: SSID found in scan list ... associating...\n"); |
| 179 | |
| 180 | /* Clear any past association response stored for |
| 181 | * application retrieval */ |
| 182 | priv->assoc_rsp_size = 0; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 183 | ret = mwifiex_associate(priv, &adapter->scan_table[i]); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 184 | if (ret) |
| 185 | return ret; |
| 186 | } else { |
| 187 | /* Adhoc mode */ |
| 188 | /* If the requested SSID matches current SSID, return */ |
| 189 | if (ssid_bssid->ssid.ssid_len && |
| 190 | (!mwifiex_ssid_cmp |
| 191 | (&priv->curr_bss_params.bss_descriptor.ssid, |
| 192 | &ssid_bssid->ssid))) |
| 193 | return 0; |
| 194 | |
| 195 | /* Exit Adhoc mode first */ |
| 196 | dev_dbg(adapter->dev, "info: Sending Adhoc Stop\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 197 | ret = mwifiex_deauthenticate(priv, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 198 | if (ret) |
| 199 | return ret; |
| 200 | |
| 201 | priv->adhoc_is_link_sensed = false; |
| 202 | |
| 203 | /* Search for the requested network in the scan table */ |
| 204 | if (ssid_bssid->ssid.ssid_len) |
| 205 | i = mwifiex_find_ssid_in_list(priv, |
| 206 | &ssid_bssid->ssid, NULL, |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 207 | NL80211_IFTYPE_ADHOC); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 208 | else |
| 209 | i = mwifiex_find_bssid_in_list(priv, |
| 210 | (u8 *)&ssid_bssid->bssid, |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 211 | NL80211_IFTYPE_ADHOC); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 212 | |
| 213 | if (i >= 0) { |
| 214 | dev_dbg(adapter->dev, "info: network found in scan" |
| 215 | " list. Joining...\n"); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 216 | ret = mwifiex_adhoc_join(priv, &adapter->scan_table[i]); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 217 | if (ret) |
| 218 | return ret; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 219 | } else { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 220 | dev_dbg(adapter->dev, "info: Network not found in " |
| 221 | "the list, creating adhoc with ssid = %s\n", |
| 222 | ssid_bssid->ssid.ssid); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 223 | ret = mwifiex_adhoc_start(priv, &ssid_bssid->ssid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 224 | if (ret) |
| 225 | return ret; |
| 226 | } |
| 227 | } |
| 228 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 229 | return ret; |
| 230 | } |
| 231 | |
| 232 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 233 | * IOCTL request handler to set host sleep configuration. |
| 234 | * |
| 235 | * This function prepares the correct firmware command and |
| 236 | * issues it. |
| 237 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 238 | int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action, |
| 239 | int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg) |
| 240 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 241 | { |
| 242 | struct mwifiex_adapter *adapter = priv->adapter; |
| 243 | int status = 0; |
| 244 | u32 prev_cond = 0; |
| 245 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 246 | if (!hs_cfg) |
| 247 | return -ENOMEM; |
| 248 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 249 | switch (action) { |
| 250 | case HostCmd_ACT_GEN_SET: |
| 251 | if (adapter->pps_uapsd_mode) { |
| 252 | dev_dbg(adapter->dev, "info: Host Sleep IOCTL" |
| 253 | " is blocked in UAPSD/PPS mode\n"); |
| 254 | status = -1; |
| 255 | break; |
| 256 | } |
| 257 | if (hs_cfg->is_invoke_hostcmd) { |
| 258 | if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) { |
| 259 | if (!adapter->is_hs_configured) |
| 260 | /* Already cancelled */ |
| 261 | break; |
| 262 | /* Save previous condition */ |
| 263 | prev_cond = le32_to_cpu(adapter->hs_cfg |
| 264 | .conditions); |
| 265 | adapter->hs_cfg.conditions = |
| 266 | cpu_to_le32(hs_cfg->conditions); |
| 267 | } else if (hs_cfg->conditions) { |
| 268 | adapter->hs_cfg.conditions = |
| 269 | cpu_to_le32(hs_cfg->conditions); |
| 270 | adapter->hs_cfg.gpio = (u8)hs_cfg->gpio; |
| 271 | if (hs_cfg->gap) |
| 272 | adapter->hs_cfg.gap = (u8)hs_cfg->gap; |
| 273 | } else if (adapter->hs_cfg.conditions == |
| 274 | cpu_to_le32( |
| 275 | HOST_SLEEP_CFG_CANCEL)) { |
| 276 | /* Return failure if no parameters for HS |
| 277 | enable */ |
| 278 | status = -1; |
| 279 | break; |
| 280 | } |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 281 | if (cmd_type == MWIFIEX_SYNC_CMD) |
| 282 | status = mwifiex_send_cmd_sync(priv, |
| 283 | HostCmd_CMD_802_11_HS_CFG_ENH, |
| 284 | HostCmd_ACT_GEN_SET, 0, |
| 285 | &adapter->hs_cfg); |
| 286 | else |
| 287 | status = mwifiex_send_cmd_async(priv, |
| 288 | HostCmd_CMD_802_11_HS_CFG_ENH, |
| 289 | HostCmd_ACT_GEN_SET, 0, |
| 290 | &adapter->hs_cfg); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 291 | if (hs_cfg->conditions == HOST_SLEEP_CFG_CANCEL) |
| 292 | /* Restore previous condition */ |
| 293 | adapter->hs_cfg.conditions = |
| 294 | cpu_to_le32(prev_cond); |
| 295 | } else { |
| 296 | adapter->hs_cfg.conditions = |
| 297 | cpu_to_le32(hs_cfg->conditions); |
| 298 | adapter->hs_cfg.gpio = (u8)hs_cfg->gpio; |
| 299 | adapter->hs_cfg.gap = (u8)hs_cfg->gap; |
| 300 | } |
| 301 | break; |
| 302 | case HostCmd_ACT_GEN_GET: |
| 303 | hs_cfg->conditions = le32_to_cpu(adapter->hs_cfg.conditions); |
| 304 | hs_cfg->gpio = adapter->hs_cfg.gpio; |
| 305 | hs_cfg->gap = adapter->hs_cfg.gap; |
| 306 | break; |
| 307 | default: |
| 308 | status = -1; |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | return status; |
| 313 | } |
| 314 | |
| 315 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 316 | * Sends IOCTL request to cancel the existing Host Sleep configuration. |
| 317 | * |
| 318 | * This function allocates the IOCTL request buffer, fills it |
| 319 | * with requisite parameters and calls the IOCTL handler. |
| 320 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 321 | int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 322 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 323 | struct mwifiex_ds_hs_cfg hscfg; |
| 324 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 325 | hscfg.conditions = HOST_SLEEP_CFG_CANCEL; |
| 326 | hscfg.is_invoke_hostcmd = true; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 327 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 328 | return mwifiex_set_hs_params(priv, HostCmd_ACT_GEN_SET, |
| 329 | cmd_type, &hscfg); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 330 | } |
| 331 | EXPORT_SYMBOL_GPL(mwifiex_cancel_hs); |
| 332 | |
| 333 | /* |
| 334 | * Sends IOCTL request to cancel the existing Host Sleep configuration. |
| 335 | * |
| 336 | * This function allocates the IOCTL request buffer, fills it |
| 337 | * with requisite parameters and calls the IOCTL handler. |
| 338 | */ |
| 339 | int mwifiex_enable_hs(struct mwifiex_adapter *adapter) |
| 340 | { |
| 341 | struct mwifiex_ds_hs_cfg hscfg; |
| 342 | |
| 343 | if (adapter->hs_activated) { |
| 344 | dev_dbg(adapter->dev, "cmd: HS Already actived\n"); |
| 345 | return true; |
| 346 | } |
| 347 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 348 | adapter->hs_activate_wait_q_woken = false; |
| 349 | |
| 350 | memset(&hscfg, 0, sizeof(struct mwifiex_hs_config_param)); |
| 351 | hscfg.is_invoke_hostcmd = true; |
| 352 | |
| 353 | if (mwifiex_set_hs_params(mwifiex_get_priv(adapter, |
| 354 | MWIFIEX_BSS_ROLE_STA), |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 355 | HostCmd_ACT_GEN_SET, MWIFIEX_SYNC_CMD, |
| 356 | &hscfg)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 357 | dev_err(adapter->dev, "IOCTL request HS enable failed\n"); |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | wait_event_interruptible(adapter->hs_activate_wait_q, |
| 362 | adapter->hs_activate_wait_q_woken); |
| 363 | |
| 364 | return true; |
| 365 | } |
| 366 | EXPORT_SYMBOL_GPL(mwifiex_enable_hs); |
| 367 | |
| 368 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 369 | * IOCTL request handler to get BSS information. |
| 370 | * |
| 371 | * This function collates the information from different driver structures |
| 372 | * to send to the user. |
| 373 | */ |
| 374 | int mwifiex_get_bss_info(struct mwifiex_private *priv, |
| 375 | struct mwifiex_bss_info *info) |
| 376 | { |
| 377 | struct mwifiex_adapter *adapter = priv->adapter; |
| 378 | struct mwifiex_bssdescriptor *bss_desc; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 379 | s32 tbl_idx; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 380 | |
| 381 | if (!info) |
| 382 | return -1; |
| 383 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 384 | bss_desc = &priv->curr_bss_params.bss_descriptor; |
| 385 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 386 | info->bss_mode = priv->bss_mode; |
| 387 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 388 | memcpy(&info->ssid, &bss_desc->ssid, |
| 389 | sizeof(struct mwifiex_802_11_ssid)); |
| 390 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 391 | memcpy(&info->bssid, &bss_desc->mac_address, ETH_ALEN); |
| 392 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 393 | info->bss_chan = bss_desc->channel; |
| 394 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 395 | info->region_code = adapter->region_code; |
| 396 | |
| 397 | /* Scan table index if connected */ |
| 398 | info->scan_table_idx = 0; |
| 399 | if (priv->media_connected) { |
| 400 | tbl_idx = |
| 401 | mwifiex_find_ssid_in_list(priv, &bss_desc->ssid, |
| 402 | bss_desc->mac_address, |
| 403 | priv->bss_mode); |
| 404 | if (tbl_idx >= 0) |
| 405 | info->scan_table_idx = tbl_idx; |
| 406 | } |
| 407 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 408 | info->media_connected = priv->media_connected; |
| 409 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 410 | info->max_power_level = priv->max_tx_power_level; |
| 411 | info->min_power_level = priv->min_tx_power_level; |
| 412 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 413 | info->adhoc_state = priv->adhoc_state; |
| 414 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 415 | info->bcn_nf_last = priv->bcn_nf_last; |
| 416 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 417 | if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED) |
| 418 | info->wep_status = true; |
| 419 | else |
| 420 | info->wep_status = false; |
| 421 | |
| 422 | info->is_hs_configured = adapter->is_hs_configured; |
| 423 | info->is_deep_sleep = adapter->is_deep_sleep; |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /* |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 429 | * The function sets band configurations. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 430 | * |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 431 | * it performs extra checks to make sure the Ad-Hoc |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 432 | * band and channel are compatible. Otherwise it returns an error. |
| 433 | * |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 434 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 435 | int mwifiex_set_radio_band_cfg(struct mwifiex_private *priv, |
| 436 | struct mwifiex_ds_band_cfg *radio_cfg) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 437 | { |
| 438 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 439 | u8 infra_band, adhoc_band; |
| 440 | u32 adhoc_channel; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 441 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 442 | infra_band = (u8) radio_cfg->config_bands; |
| 443 | adhoc_band = (u8) radio_cfg->adhoc_start_band; |
| 444 | adhoc_channel = radio_cfg->adhoc_channel; |
| 445 | |
| 446 | /* SET Infra band */ |
| 447 | if ((infra_band | adapter->fw_bands) & ~adapter->fw_bands) |
| 448 | return -1; |
| 449 | |
| 450 | adapter->config_bands = infra_band; |
| 451 | |
| 452 | /* SET Ad-hoc Band */ |
| 453 | if ((adhoc_band | adapter->fw_bands) & ~adapter->fw_bands) |
| 454 | return -1; |
| 455 | |
| 456 | if (adhoc_band) |
| 457 | adapter->adhoc_start_band = adhoc_band; |
| 458 | adapter->chan_offset = (u8) radio_cfg->sec_chan_offset; |
| 459 | /* |
| 460 | * If no adhoc_channel is supplied verify if the existing adhoc |
| 461 | * channel compiles with new adhoc_band |
| 462 | */ |
| 463 | if (!adhoc_channel) { |
| 464 | if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211 |
| 465 | (priv, adapter->adhoc_start_band, |
| 466 | priv->adhoc_channel)) { |
| 467 | /* Pass back the default channel */ |
| 468 | radio_cfg->adhoc_channel = DEFAULT_AD_HOC_CHANNEL; |
| 469 | if ((adapter->adhoc_start_band & BAND_A) |
| 470 | || (adapter->adhoc_start_band & BAND_AN)) |
| 471 | radio_cfg->adhoc_channel = |
| 472 | DEFAULT_AD_HOC_CHANNEL_A; |
| 473 | } |
| 474 | } else { /* Retrurn error if adhoc_band and |
| 475 | adhoc_channel combination is invalid */ |
| 476 | if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211 |
| 477 | (priv, adapter->adhoc_start_band, (u16) adhoc_channel)) |
| 478 | return -1; |
| 479 | priv->adhoc_channel = (u8) adhoc_channel; |
| 480 | } |
| 481 | if ((adhoc_band & BAND_GN) || (adhoc_band & BAND_AN)) |
| 482 | adapter->adhoc_11n_enabled = true; |
| 483 | else |
| 484 | adapter->adhoc_11n_enabled = false; |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | /* |
Amitkumar Karwar | a049093 | 2011-07-13 20:51:59 -0700 | [diff] [blame] | 490 | * The function disables auto deep sleep mode. |
| 491 | */ |
| 492 | int mwifiex_disable_auto_ds(struct mwifiex_private *priv) |
| 493 | { |
| 494 | struct mwifiex_ds_auto_ds auto_ds; |
| 495 | |
| 496 | auto_ds.auto_ds = DEEP_SLEEP_OFF; |
| 497 | |
| 498 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH, |
| 499 | DIS_AUTO_PS, BITMAP_AUTO_DS, &auto_ds); |
| 500 | } |
| 501 | EXPORT_SYMBOL_GPL(mwifiex_disable_auto_ds); |
| 502 | |
| 503 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 504 | * IOCTL request handler to set/get active channel. |
| 505 | * |
| 506 | * This function performs validity checking on channel/frequency |
| 507 | * compatibility and returns failure if not valid. |
| 508 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 509 | int mwifiex_bss_set_channel(struct mwifiex_private *priv, |
| 510 | struct mwifiex_chan_freq_power *chan) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 511 | { |
| 512 | struct mwifiex_adapter *adapter = priv->adapter; |
| 513 | struct mwifiex_chan_freq_power *cfp = NULL; |
| 514 | |
| 515 | if (!chan) |
| 516 | return -1; |
| 517 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 518 | if (!chan->channel && !chan->freq) |
| 519 | return -1; |
| 520 | if (adapter->adhoc_start_band & BAND_AN) |
| 521 | adapter->adhoc_start_band = BAND_G | BAND_B | BAND_GN; |
| 522 | else if (adapter->adhoc_start_band & BAND_A) |
| 523 | adapter->adhoc_start_band = BAND_G | BAND_B; |
| 524 | if (chan->channel) { |
| 525 | if (chan->channel <= MAX_CHANNEL_BAND_BG) |
| 526 | cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211 |
| 527 | (priv, 0, (u16) chan->channel); |
| 528 | if (!cfp) { |
| 529 | cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211 |
| 530 | (priv, BAND_A, (u16) chan->channel); |
| 531 | if (cfp) { |
| 532 | if (adapter->adhoc_11n_enabled) |
| 533 | adapter->adhoc_start_band = BAND_A |
| 534 | | BAND_AN; |
| 535 | else |
| 536 | adapter->adhoc_start_band = BAND_A; |
| 537 | } |
| 538 | } |
| 539 | } else { |
| 540 | if (chan->freq <= MAX_FREQUENCY_BAND_BG) |
| 541 | cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211( |
| 542 | priv, 0, chan->freq); |
| 543 | if (!cfp) { |
| 544 | cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211 |
| 545 | (priv, BAND_A, chan->freq); |
| 546 | if (cfp) { |
| 547 | if (adapter->adhoc_11n_enabled) |
| 548 | adapter->adhoc_start_band = BAND_A |
| 549 | | BAND_AN; |
| 550 | else |
| 551 | adapter->adhoc_start_band = BAND_A; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | if (!cfp || !cfp->channel) { |
| 556 | dev_err(adapter->dev, "invalid channel/freq\n"); |
| 557 | return -1; |
| 558 | } |
| 559 | priv->adhoc_channel = (u8) cfp->channel; |
| 560 | chan->channel = cfp->channel; |
| 561 | chan->freq = cfp->freq; |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 567 | * IOCTL request handler to set/get Ad-Hoc channel. |
| 568 | * |
| 569 | * This function prepares the correct firmware command and |
| 570 | * issues it to set or get the ad-hoc channel. |
| 571 | */ |
| 572 | static int mwifiex_bss_ioctl_ibss_channel(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 573 | u16 action, u16 *channel) |
| 574 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 575 | if (action == HostCmd_ACT_GEN_GET) { |
| 576 | if (!priv->media_connected) { |
| 577 | *channel = priv->adhoc_channel; |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 578 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 579 | } |
| 580 | } else { |
| 581 | priv->adhoc_channel = (u8) *channel; |
| 582 | } |
| 583 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 584 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_RF_CHANNEL, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 585 | action, 0, channel); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* |
| 589 | * IOCTL request handler to find a particular BSS. |
| 590 | * |
| 591 | * The BSS can be searched with either a BSSID or a SSID. If none of |
| 592 | * these are provided, just the best BSS (best RSSI) is returned. |
| 593 | */ |
| 594 | int mwifiex_bss_ioctl_find_bss(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 595 | struct mwifiex_ssid_bssid *ssid_bssid) |
| 596 | { |
| 597 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 598 | struct mwifiex_bssdescriptor *bss_desc; |
| 599 | u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; |
| 600 | u8 mac[ETH_ALEN]; |
| 601 | int i = 0; |
| 602 | |
| 603 | if (memcmp(ssid_bssid->bssid, zero_mac, sizeof(zero_mac))) { |
| 604 | i = mwifiex_find_bssid_in_list(priv, |
| 605 | (u8 *) ssid_bssid->bssid, |
| 606 | priv->bss_mode); |
| 607 | if (i < 0) { |
| 608 | memcpy(mac, ssid_bssid->bssid, sizeof(mac)); |
| 609 | dev_err(adapter->dev, "cannot find bssid %pM\n", mac); |
| 610 | return -1; |
| 611 | } |
| 612 | bss_desc = &adapter->scan_table[i]; |
| 613 | memcpy(&ssid_bssid->ssid, &bss_desc->ssid, |
| 614 | sizeof(struct mwifiex_802_11_ssid)); |
| 615 | } else if (ssid_bssid->ssid.ssid_len) { |
| 616 | i = mwifiex_find_ssid_in_list(priv, &ssid_bssid->ssid, NULL, |
| 617 | priv->bss_mode); |
| 618 | if (i < 0) { |
| 619 | dev_err(adapter->dev, "cannot find ssid %s\n", |
| 620 | ssid_bssid->ssid.ssid); |
| 621 | return -1; |
| 622 | } |
| 623 | bss_desc = &adapter->scan_table[i]; |
| 624 | memcpy(ssid_bssid->bssid, bss_desc->mac_address, ETH_ALEN); |
| 625 | } else { |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 626 | return mwifiex_find_best_network(priv, ssid_bssid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 629 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /* |
| 633 | * IOCTL request handler to change Ad-Hoc channel. |
| 634 | * |
| 635 | * This function allocates the IOCTL request buffer, fills it |
| 636 | * with requisite parameters and calls the IOCTL handler. |
| 637 | * |
| 638 | * The function follows the following steps to perform the change - |
| 639 | * - Get current IBSS information |
| 640 | * - Get current channel |
| 641 | * - If no change is required, return |
| 642 | * - If not connected, change channel and return |
| 643 | * - If connected, |
| 644 | * - Disconnect |
| 645 | * - Change channel |
| 646 | * - Perform specific SSID scan with same SSID |
| 647 | * - Start/Join the IBSS |
| 648 | */ |
| 649 | int |
| 650 | mwifiex_drv_change_adhoc_chan(struct mwifiex_private *priv, int channel) |
| 651 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 652 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 653 | struct mwifiex_bss_info bss_info; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 654 | struct mwifiex_ssid_bssid ssid_bssid; |
| 655 | u16 curr_chan = 0; |
| 656 | |
| 657 | memset(&bss_info, 0, sizeof(bss_info)); |
| 658 | |
| 659 | /* Get BSS information */ |
| 660 | if (mwifiex_get_bss_info(priv, &bss_info)) |
| 661 | return -1; |
| 662 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 663 | /* Get current channel */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 664 | ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_GET, |
| 665 | &curr_chan); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 666 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 667 | if (curr_chan == channel) { |
| 668 | ret = 0; |
| 669 | goto done; |
| 670 | } |
| 671 | dev_dbg(priv->adapter->dev, "cmd: updating channel from %d to %d\n", |
| 672 | curr_chan, channel); |
| 673 | |
| 674 | if (!bss_info.media_connected) { |
| 675 | ret = 0; |
| 676 | goto done; |
| 677 | } |
| 678 | |
| 679 | /* Do disonnect */ |
| 680 | memset(&ssid_bssid, 0, ETH_ALEN); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 681 | ret = mwifiex_deauthenticate(priv, ssid_bssid.bssid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 682 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 683 | ret = mwifiex_bss_ioctl_ibss_channel(priv, HostCmd_ACT_GEN_SET, |
| 684 | (u16 *) &channel); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 685 | |
| 686 | /* Do specific SSID scanning */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 687 | if (mwifiex_request_scan(priv, &bss_info.ssid)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 688 | ret = -1; |
| 689 | goto done; |
| 690 | } |
| 691 | /* Start/Join Adhoc network */ |
| 692 | memset(&ssid_bssid, 0, sizeof(struct mwifiex_ssid_bssid)); |
| 693 | memcpy(&ssid_bssid.ssid, &bss_info.ssid, |
| 694 | sizeof(struct mwifiex_802_11_ssid)); |
| 695 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 696 | ret = mwifiex_bss_start(priv, &ssid_bssid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 697 | done: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 702 | * IOCTL request handler to get rate. |
| 703 | * |
| 704 | * This function prepares the correct firmware command and |
| 705 | * issues it to get the current rate if it is connected, |
| 706 | * otherwise, the function returns the lowest supported rate |
| 707 | * for the band. |
| 708 | */ |
| 709 | static int mwifiex_rate_ioctl_get_rate_value(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 710 | struct mwifiex_rate_cfg *rate_cfg) |
| 711 | { |
| 712 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 713 | |
| 714 | rate_cfg->is_rate_auto = priv->is_data_rate_auto; |
| 715 | if (!priv->media_connected) { |
| 716 | switch (adapter->config_bands) { |
| 717 | case BAND_B: |
| 718 | /* Return the lowest supported rate for B band */ |
| 719 | rate_cfg->rate = supported_rates_b[0] & 0x7f; |
| 720 | break; |
| 721 | case BAND_G: |
| 722 | case BAND_G | BAND_GN: |
| 723 | /* Return the lowest supported rate for G band */ |
| 724 | rate_cfg->rate = supported_rates_g[0] & 0x7f; |
| 725 | break; |
| 726 | case BAND_B | BAND_G: |
| 727 | case BAND_A | BAND_B | BAND_G: |
| 728 | case BAND_A | BAND_B: |
| 729 | case BAND_A | BAND_B | BAND_G | BAND_AN | BAND_GN: |
| 730 | case BAND_B | BAND_G | BAND_GN: |
| 731 | /* Return the lowest supported rate for BG band */ |
| 732 | rate_cfg->rate = supported_rates_bg[0] & 0x7f; |
| 733 | break; |
| 734 | case BAND_A: |
| 735 | case BAND_A | BAND_G: |
| 736 | case BAND_A | BAND_G | BAND_AN | BAND_GN: |
| 737 | case BAND_A | BAND_AN: |
| 738 | /* Return the lowest supported rate for A band */ |
| 739 | rate_cfg->rate = supported_rates_a[0] & 0x7f; |
| 740 | break; |
| 741 | case BAND_GN: |
| 742 | /* Return the lowest supported rate for N band */ |
| 743 | rate_cfg->rate = supported_rates_n[0] & 0x7f; |
| 744 | break; |
| 745 | default: |
| 746 | dev_warn(adapter->dev, "invalid band %#x\n", |
| 747 | adapter->config_bands); |
| 748 | break; |
| 749 | } |
| 750 | } else { |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 751 | return mwifiex_send_cmd_sync(priv, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 752 | HostCmd_CMD_802_11_TX_RATE_QUERY, |
| 753 | HostCmd_ACT_GEN_GET, 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 756 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /* |
| 760 | * IOCTL request handler to set rate. |
| 761 | * |
| 762 | * This function prepares the correct firmware command and |
| 763 | * issues it to set the current rate. |
| 764 | * |
| 765 | * The function also performs validation checking on the supplied value. |
| 766 | */ |
| 767 | static int mwifiex_rate_ioctl_set_rate_value(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 768 | struct mwifiex_rate_cfg *rate_cfg) |
| 769 | { |
| 770 | u8 rates[MWIFIEX_SUPPORTED_RATES]; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 771 | u8 *rate; |
| 772 | int rate_index, ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 773 | u16 bitmap_rates[MAX_BITMAP_RATES_SIZE]; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 774 | u32 i; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 775 | struct mwifiex_adapter *adapter = priv->adapter; |
| 776 | |
| 777 | if (rate_cfg->is_rate_auto) { |
| 778 | memset(bitmap_rates, 0, sizeof(bitmap_rates)); |
| 779 | /* Support all HR/DSSS rates */ |
| 780 | bitmap_rates[0] = 0x000F; |
| 781 | /* Support all OFDM rates */ |
| 782 | bitmap_rates[1] = 0x00FF; |
| 783 | /* Support all HT-MCSs rate */ |
| 784 | for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates) - 3; i++) |
| 785 | bitmap_rates[i + 2] = 0xFFFF; |
| 786 | bitmap_rates[9] = 0x3FFF; |
| 787 | } else { |
| 788 | memset(rates, 0, sizeof(rates)); |
| 789 | mwifiex_get_active_data_rates(priv, rates); |
| 790 | rate = rates; |
| 791 | for (i = 0; (rate[i] && i < MWIFIEX_SUPPORTED_RATES); i++) { |
| 792 | dev_dbg(adapter->dev, "info: rate=%#x wanted=%#x\n", |
| 793 | rate[i], rate_cfg->rate); |
| 794 | if ((rate[i] & 0x7f) == (rate_cfg->rate & 0x7f)) |
| 795 | break; |
| 796 | } |
| 797 | if (!rate[i] || (i == MWIFIEX_SUPPORTED_RATES)) { |
| 798 | dev_err(adapter->dev, "fixed data rate %#x is out " |
| 799 | "of range\n", rate_cfg->rate); |
| 800 | return -1; |
| 801 | } |
| 802 | memset(bitmap_rates, 0, sizeof(bitmap_rates)); |
| 803 | |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 804 | rate_index = mwifiex_data_rate_to_index(rate_cfg->rate); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 805 | |
| 806 | /* Only allow b/g rates to be set */ |
| 807 | if (rate_index >= MWIFIEX_RATE_INDEX_HRDSSS0 && |
| 808 | rate_index <= MWIFIEX_RATE_INDEX_HRDSSS3) { |
| 809 | bitmap_rates[0] = 1 << rate_index; |
| 810 | } else { |
| 811 | rate_index -= 1; /* There is a 0x00 in the table */ |
| 812 | if (rate_index >= MWIFIEX_RATE_INDEX_OFDM0 && |
| 813 | rate_index <= MWIFIEX_RATE_INDEX_OFDM7) |
| 814 | bitmap_rates[1] = 1 << (rate_index - |
| 815 | MWIFIEX_RATE_INDEX_OFDM0); |
| 816 | } |
| 817 | } |
| 818 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 819 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TX_RATE_CFG, |
| 820 | HostCmd_ACT_GEN_SET, 0, bitmap_rates); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 821 | |
| 822 | return ret; |
| 823 | } |
| 824 | |
| 825 | /* |
| 826 | * IOCTL request handler to set/get rate. |
| 827 | * |
| 828 | * This function can be used to set/get either the rate value or the |
| 829 | * rate index. |
| 830 | */ |
| 831 | static int mwifiex_rate_ioctl_cfg(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 832 | struct mwifiex_rate_cfg *rate_cfg) |
| 833 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 834 | int status; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 835 | |
| 836 | if (!rate_cfg) |
| 837 | return -1; |
| 838 | |
| 839 | if (rate_cfg->action == HostCmd_ACT_GEN_GET) |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 840 | status = mwifiex_rate_ioctl_get_rate_value(priv, rate_cfg); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 841 | else |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 842 | status = mwifiex_rate_ioctl_set_rate_value(priv, rate_cfg); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 843 | |
| 844 | return status; |
| 845 | } |
| 846 | |
| 847 | /* |
| 848 | * Sends IOCTL request to get the data rate. |
| 849 | * |
| 850 | * This function allocates the IOCTL request buffer, fills it |
| 851 | * with requisite parameters and calls the IOCTL handler. |
| 852 | */ |
| 853 | int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, |
| 854 | struct mwifiex_rate_cfg *rate) |
| 855 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 856 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 857 | |
| 858 | memset(rate, 0, sizeof(struct mwifiex_rate_cfg)); |
| 859 | rate->action = HostCmd_ACT_GEN_GET; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 860 | ret = mwifiex_rate_ioctl_cfg(priv, rate); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 861 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 862 | if (!ret) { |
| 863 | if (rate && rate->is_rate_auto) |
Amitkumar Karwar | 572e8f3 | 2011-04-13 17:27:08 -0700 | [diff] [blame] | 864 | rate->rate = mwifiex_index_to_data_rate(priv->tx_rate, |
| 865 | priv->tx_htinfo); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 866 | else if (rate) |
| 867 | rate->rate = priv->data_rate; |
| 868 | } else { |
| 869 | ret = -1; |
| 870 | } |
| 871 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 872 | return ret; |
| 873 | } |
| 874 | |
| 875 | /* |
| 876 | * IOCTL request handler to set tx power configuration. |
| 877 | * |
| 878 | * This function prepares the correct firmware command and |
| 879 | * issues it. |
| 880 | * |
| 881 | * For non-auto power mode, all the following power groups are set - |
| 882 | * - Modulation class HR/DSSS |
| 883 | * - Modulation class OFDM |
| 884 | * - Modulation class HTBW20 |
| 885 | * - Modulation class HTBW40 |
| 886 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 887 | int mwifiex_set_tx_power(struct mwifiex_private *priv, |
| 888 | struct mwifiex_power_cfg *power_cfg) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 889 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 890 | int ret; |
| 891 | struct host_cmd_ds_txpwr_cfg *txp_cfg; |
| 892 | struct mwifiex_types_power_group *pg_tlv; |
| 893 | struct mwifiex_power_group *pg; |
| 894 | u8 *buf; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 895 | u16 dbm = 0; |
| 896 | |
| 897 | if (!power_cfg->is_power_auto) { |
| 898 | dbm = (u16) power_cfg->power_level; |
| 899 | if ((dbm < priv->min_tx_power_level) || |
| 900 | (dbm > priv->max_tx_power_level)) { |
| 901 | dev_err(priv->adapter->dev, "txpower value %d dBm" |
| 902 | " is out of range (%d dBm-%d dBm)\n", |
| 903 | dbm, priv->min_tx_power_level, |
| 904 | priv->max_tx_power_level); |
| 905 | return -1; |
| 906 | } |
| 907 | } |
| 908 | buf = kzalloc(MWIFIEX_SIZE_OF_CMD_BUFFER, GFP_KERNEL); |
| 909 | if (!buf) { |
| 910 | dev_err(priv->adapter->dev, "%s: failed to alloc cmd buffer\n", |
| 911 | __func__); |
Christoph Fritz | b53575e | 2011-05-08 22:50:09 +0200 | [diff] [blame] | 912 | return -ENOMEM; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf; |
| 916 | txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET); |
| 917 | if (!power_cfg->is_power_auto) { |
| 918 | txp_cfg->mode = cpu_to_le32(1); |
| 919 | pg_tlv = (struct mwifiex_types_power_group *) (buf + |
| 920 | sizeof(struct host_cmd_ds_txpwr_cfg)); |
| 921 | pg_tlv->type = TLV_TYPE_POWER_GROUP; |
| 922 | pg_tlv->length = 4 * sizeof(struct mwifiex_power_group); |
| 923 | pg = (struct mwifiex_power_group *) (buf + |
| 924 | sizeof(struct host_cmd_ds_txpwr_cfg) + |
| 925 | sizeof(struct mwifiex_types_power_group)); |
| 926 | /* Power group for modulation class HR/DSSS */ |
| 927 | pg->first_rate_code = 0x00; |
| 928 | pg->last_rate_code = 0x03; |
| 929 | pg->modulation_class = MOD_CLASS_HR_DSSS; |
| 930 | pg->power_step = 0; |
| 931 | pg->power_min = (s8) dbm; |
| 932 | pg->power_max = (s8) dbm; |
| 933 | pg++; |
| 934 | /* Power group for modulation class OFDM */ |
| 935 | pg->first_rate_code = 0x00; |
| 936 | pg->last_rate_code = 0x07; |
| 937 | pg->modulation_class = MOD_CLASS_OFDM; |
| 938 | pg->power_step = 0; |
| 939 | pg->power_min = (s8) dbm; |
| 940 | pg->power_max = (s8) dbm; |
| 941 | pg++; |
| 942 | /* Power group for modulation class HTBW20 */ |
| 943 | pg->first_rate_code = 0x00; |
| 944 | pg->last_rate_code = 0x20; |
| 945 | pg->modulation_class = MOD_CLASS_HT; |
| 946 | pg->power_step = 0; |
| 947 | pg->power_min = (s8) dbm; |
| 948 | pg->power_max = (s8) dbm; |
| 949 | pg->ht_bandwidth = HT_BW_20; |
| 950 | pg++; |
| 951 | /* Power group for modulation class HTBW40 */ |
| 952 | pg->first_rate_code = 0x00; |
| 953 | pg->last_rate_code = 0x20; |
| 954 | pg->modulation_class = MOD_CLASS_HT; |
| 955 | pg->power_step = 0; |
| 956 | pg->power_min = (s8) dbm; |
| 957 | pg->power_max = (s8) dbm; |
| 958 | pg->ht_bandwidth = HT_BW_40; |
| 959 | } |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 960 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_TXPWR_CFG, |
| 961 | HostCmd_ACT_GEN_SET, 0, buf); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 962 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 963 | kfree(buf); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 964 | return ret; |
| 965 | } |
| 966 | |
| 967 | /* |
| 968 | * IOCTL request handler to get power save mode. |
| 969 | * |
| 970 | * This function prepares the correct firmware command and |
| 971 | * issues it. |
| 972 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 973 | int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 974 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 975 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 976 | struct mwifiex_adapter *adapter = priv->adapter; |
| 977 | u16 sub_cmd; |
| 978 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 979 | if (*ps_mode) |
| 980 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_PSP; |
| 981 | else |
| 982 | adapter->ps_mode = MWIFIEX_802_11_POWER_MODE_CAM; |
| 983 | sub_cmd = (*ps_mode) ? EN_AUTO_PS : DIS_AUTO_PS; |
| 984 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_PS_MODE_ENH, |
| 985 | sub_cmd, BITMAP_STA_PS, NULL); |
| 986 | if ((!ret) && (sub_cmd == DIS_AUTO_PS)) |
| 987 | ret = mwifiex_send_cmd_async(priv, |
| 988 | HostCmd_CMD_802_11_PS_MODE_ENH, GET_PS, |
| 989 | 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 990 | |
| 991 | return ret; |
| 992 | } |
| 993 | |
| 994 | /* |
| 995 | * IOCTL request handler to set/reset WPA IE. |
| 996 | * |
| 997 | * The supplied WPA IE is treated as a opaque buffer. Only the first field |
| 998 | * is checked to determine WPA version. If buffer length is zero, the existing |
| 999 | * WPA IE is reset. |
| 1000 | */ |
| 1001 | static int mwifiex_set_wpa_ie_helper(struct mwifiex_private *priv, |
| 1002 | u8 *ie_data_ptr, u16 ie_len) |
| 1003 | { |
| 1004 | if (ie_len) { |
| 1005 | if (ie_len > sizeof(priv->wpa_ie)) { |
| 1006 | dev_err(priv->adapter->dev, |
| 1007 | "failed to copy WPA IE, too big\n"); |
| 1008 | return -1; |
| 1009 | } |
| 1010 | memcpy(priv->wpa_ie, ie_data_ptr, ie_len); |
| 1011 | priv->wpa_ie_len = (u8) ie_len; |
| 1012 | dev_dbg(priv->adapter->dev, "cmd: Set Wpa_ie_len=%d IE=%#x\n", |
| 1013 | priv->wpa_ie_len, priv->wpa_ie[0]); |
| 1014 | |
| 1015 | if (priv->wpa_ie[0] == WLAN_EID_WPA) { |
| 1016 | priv->sec_info.wpa_enabled = true; |
| 1017 | } else if (priv->wpa_ie[0] == WLAN_EID_RSN) { |
| 1018 | priv->sec_info.wpa2_enabled = true; |
| 1019 | } else { |
| 1020 | priv->sec_info.wpa_enabled = false; |
| 1021 | priv->sec_info.wpa2_enabled = false; |
| 1022 | } |
| 1023 | } else { |
| 1024 | memset(priv->wpa_ie, 0, sizeof(priv->wpa_ie)); |
| 1025 | priv->wpa_ie_len = 0; |
| 1026 | dev_dbg(priv->adapter->dev, "info: reset wpa_ie_len=%d IE=%#x\n", |
| 1027 | priv->wpa_ie_len, priv->wpa_ie[0]); |
| 1028 | priv->sec_info.wpa_enabled = false; |
| 1029 | priv->sec_info.wpa2_enabled = false; |
| 1030 | } |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * IOCTL request handler to set/reset WAPI IE. |
| 1037 | * |
| 1038 | * The supplied WAPI IE is treated as a opaque buffer. Only the first field |
| 1039 | * is checked to internally enable WAPI. If buffer length is zero, the existing |
| 1040 | * WAPI IE is reset. |
| 1041 | */ |
| 1042 | static int mwifiex_set_wapi_ie(struct mwifiex_private *priv, |
| 1043 | u8 *ie_data_ptr, u16 ie_len) |
| 1044 | { |
| 1045 | if (ie_len) { |
| 1046 | if (ie_len > sizeof(priv->wapi_ie)) { |
| 1047 | dev_dbg(priv->adapter->dev, |
| 1048 | "info: failed to copy WAPI IE, too big\n"); |
| 1049 | return -1; |
| 1050 | } |
| 1051 | memcpy(priv->wapi_ie, ie_data_ptr, ie_len); |
| 1052 | priv->wapi_ie_len = ie_len; |
| 1053 | dev_dbg(priv->adapter->dev, "cmd: Set wapi_ie_len=%d IE=%#x\n", |
| 1054 | priv->wapi_ie_len, priv->wapi_ie[0]); |
| 1055 | |
| 1056 | if (priv->wapi_ie[0] == WLAN_EID_BSS_AC_ACCESS_DELAY) |
| 1057 | priv->sec_info.wapi_enabled = true; |
| 1058 | } else { |
| 1059 | memset(priv->wapi_ie, 0, sizeof(priv->wapi_ie)); |
| 1060 | priv->wapi_ie_len = ie_len; |
| 1061 | dev_dbg(priv->adapter->dev, |
| 1062 | "info: Reset wapi_ie_len=%d IE=%#x\n", |
| 1063 | priv->wapi_ie_len, priv->wapi_ie[0]); |
| 1064 | priv->sec_info.wapi_enabled = false; |
| 1065 | } |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * IOCTL request handler to set WAPI key. |
| 1071 | * |
| 1072 | * This function prepares the correct firmware command and |
| 1073 | * issues it. |
| 1074 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1075 | static int mwifiex_sec_ioctl_set_wapi_key(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1076 | struct mwifiex_ds_encrypt_key *encrypt_key) |
| 1077 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1078 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1079 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_KEY_MATERIAL, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1080 | HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED, |
| 1081 | encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1085 | * IOCTL request handler to set WEP network key. |
| 1086 | * |
| 1087 | * This function prepares the correct firmware command and |
| 1088 | * issues it, after validation checks. |
| 1089 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1090 | static int mwifiex_sec_ioctl_set_wep_key(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1091 | struct mwifiex_ds_encrypt_key *encrypt_key) |
| 1092 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1093 | int ret; |
| 1094 | struct mwifiex_wep_key *wep_key; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1095 | int index; |
| 1096 | |
| 1097 | if (priv->wep_key_curr_index >= NUM_WEP_KEYS) |
| 1098 | priv->wep_key_curr_index = 0; |
| 1099 | wep_key = &priv->wep_key[priv->wep_key_curr_index]; |
| 1100 | index = encrypt_key->key_index; |
| 1101 | if (encrypt_key->key_disable) { |
| 1102 | priv->sec_info.wep_status = MWIFIEX_802_11_WEP_DISABLED; |
| 1103 | } else if (!encrypt_key->key_len) { |
| 1104 | /* Copy the required key as the current key */ |
| 1105 | wep_key = &priv->wep_key[index]; |
| 1106 | if (!wep_key->key_length) { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1107 | dev_err(priv->adapter->dev, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1108 | "key not set, so cannot enable it\n"); |
| 1109 | return -1; |
| 1110 | } |
| 1111 | priv->wep_key_curr_index = (u16) index; |
| 1112 | priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED; |
| 1113 | } else { |
| 1114 | wep_key = &priv->wep_key[index]; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1115 | memset(wep_key, 0, sizeof(struct mwifiex_wep_key)); |
| 1116 | /* Copy the key in the driver */ |
| 1117 | memcpy(wep_key->key_material, |
| 1118 | encrypt_key->key_material, |
| 1119 | encrypt_key->key_len); |
| 1120 | wep_key->key_index = index; |
| 1121 | wep_key->key_length = encrypt_key->key_len; |
| 1122 | priv->sec_info.wep_status = MWIFIEX_802_11_WEP_ENABLED; |
| 1123 | } |
| 1124 | if (wep_key->key_length) { |
| 1125 | /* Send request to firmware */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1126 | ret = mwifiex_send_cmd_async(priv, |
| 1127 | HostCmd_CMD_802_11_KEY_MATERIAL, |
| 1128 | HostCmd_ACT_GEN_SET, 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1129 | if (ret) |
| 1130 | return ret; |
| 1131 | } |
| 1132 | if (priv->sec_info.wep_status == MWIFIEX_802_11_WEP_ENABLED) |
| 1133 | priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE; |
| 1134 | else |
| 1135 | priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE; |
| 1136 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1137 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_MAC_CONTROL, |
| 1138 | HostCmd_ACT_GEN_SET, 0, |
| 1139 | &priv->curr_pkt_filter); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1140 | |
| 1141 | return ret; |
| 1142 | } |
| 1143 | |
| 1144 | /* |
| 1145 | * IOCTL request handler to set WPA key. |
| 1146 | * |
| 1147 | * This function prepares the correct firmware command and |
| 1148 | * issues it, after validation checks. |
| 1149 | * |
| 1150 | * Current driver only supports key length of up to 32 bytes. |
| 1151 | * |
| 1152 | * This function can also be used to disable a currently set key. |
| 1153 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1154 | static int mwifiex_sec_ioctl_set_wpa_key(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1155 | struct mwifiex_ds_encrypt_key *encrypt_key) |
| 1156 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1157 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1158 | u8 remove_key = false; |
| 1159 | struct host_cmd_ds_802_11_key_material *ibss_key; |
| 1160 | |
| 1161 | /* Current driver only supports key length of up to 32 bytes */ |
Amitkumar Karwar | a373165 | 2011-04-15 20:50:41 -0700 | [diff] [blame] | 1162 | if (encrypt_key->key_len > WLAN_MAX_KEY_LEN) { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1163 | dev_err(priv->adapter->dev, "key length too long\n"); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1164 | return -1; |
| 1165 | } |
| 1166 | |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 1167 | if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1168 | /* |
| 1169 | * IBSS/WPA-None uses only one key (Group) for both receiving |
| 1170 | * and sending unicast and multicast packets. |
| 1171 | */ |
| 1172 | /* Send the key as PTK to firmware */ |
| 1173 | encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1174 | ret = mwifiex_send_cmd_async(priv, |
| 1175 | HostCmd_CMD_802_11_KEY_MATERIAL, |
| 1176 | HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED, |
| 1177 | encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1178 | if (ret) |
| 1179 | return ret; |
| 1180 | |
| 1181 | ibss_key = &priv->aes_key; |
| 1182 | memset(ibss_key, 0, |
| 1183 | sizeof(struct host_cmd_ds_802_11_key_material)); |
| 1184 | /* Copy the key in the driver */ |
| 1185 | memcpy(ibss_key->key_param_set.key, encrypt_key->key_material, |
| 1186 | encrypt_key->key_len); |
| 1187 | memcpy(&ibss_key->key_param_set.key_len, &encrypt_key->key_len, |
| 1188 | sizeof(ibss_key->key_param_set.key_len)); |
| 1189 | ibss_key->key_param_set.key_type_id |
| 1190 | = cpu_to_le16(KEY_TYPE_ID_TKIP); |
Yogesh Ashok Powar | 6a35a0a | 2011-04-06 16:46:56 -0700 | [diff] [blame] | 1191 | ibss_key->key_param_set.key_info = cpu_to_le16(KEY_ENABLED); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1192 | |
| 1193 | /* Send the key as GTK to firmware */ |
| 1194 | encrypt_key->key_index = ~MWIFIEX_KEY_INDEX_UNICAST; |
| 1195 | } |
| 1196 | |
| 1197 | if (!encrypt_key->key_index) |
| 1198 | encrypt_key->key_index = MWIFIEX_KEY_INDEX_UNICAST; |
| 1199 | |
| 1200 | if (remove_key) |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1201 | ret = mwifiex_send_cmd_sync(priv, |
| 1202 | HostCmd_CMD_802_11_KEY_MATERIAL, |
| 1203 | HostCmd_ACT_GEN_SET, !(KEY_INFO_ENABLED), |
| 1204 | encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1205 | else |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1206 | ret = mwifiex_send_cmd_sync(priv, |
| 1207 | HostCmd_CMD_802_11_KEY_MATERIAL, |
| 1208 | HostCmd_ACT_GEN_SET, KEY_INFO_ENABLED, |
| 1209 | encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1210 | |
| 1211 | return ret; |
| 1212 | } |
| 1213 | |
| 1214 | /* |
| 1215 | * IOCTL request handler to set/get network keys. |
| 1216 | * |
| 1217 | * This is a generic key handling function which supports WEP, WPA |
| 1218 | * and WAPI. |
| 1219 | */ |
| 1220 | static int |
| 1221 | mwifiex_sec_ioctl_encrypt_key(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1222 | struct mwifiex_ds_encrypt_key *encrypt_key) |
| 1223 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1224 | int status; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1225 | |
| 1226 | if (encrypt_key->is_wapi_key) |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1227 | status = mwifiex_sec_ioctl_set_wapi_key(priv, encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1228 | else if (encrypt_key->key_len > WLAN_KEY_LEN_WEP104) |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1229 | status = mwifiex_sec_ioctl_set_wpa_key(priv, encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1230 | else |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1231 | status = mwifiex_sec_ioctl_set_wep_key(priv, encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1232 | return status; |
| 1233 | } |
| 1234 | |
| 1235 | /* |
| 1236 | * This function returns the driver version. |
| 1237 | */ |
| 1238 | int |
| 1239 | mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version, |
| 1240 | int max_len) |
| 1241 | { |
| 1242 | union { |
| 1243 | u32 l; |
| 1244 | u8 c[4]; |
| 1245 | } ver; |
| 1246 | char fw_ver[32]; |
| 1247 | |
| 1248 | ver.l = adapter->fw_release_number; |
| 1249 | sprintf(fw_ver, "%u.%u.%u.p%u", ver.c[2], ver.c[1], ver.c[0], ver.c[3]); |
| 1250 | |
| 1251 | snprintf(version, max_len, driver_version, fw_ver); |
| 1252 | |
| 1253 | dev_dbg(adapter->dev, "info: MWIFIEX VERSION: %s\n", version); |
| 1254 | |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
| 1258 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1259 | * Sends IOCTL request to get signal information. |
| 1260 | * |
| 1261 | * This function allocates the IOCTL request buffer, fills it |
| 1262 | * with requisite parameters and calls the IOCTL handler. |
| 1263 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1264 | int mwifiex_get_signal_info(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1265 | struct mwifiex_ds_get_signal *signal) |
| 1266 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1267 | int status; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1268 | |
Amitkumar Karwar | c4859fb | 2011-05-10 20:47:35 -0700 | [diff] [blame] | 1269 | signal->selector = ALL_RSSI_INFO_MASK; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1270 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1271 | /* Signal info can be obtained only if connected */ |
| 1272 | if (!priv->media_connected) { |
| 1273 | dev_dbg(priv->adapter->dev, |
| 1274 | "info: Can not get signal in disconnected state\n"); |
| 1275 | return -1; |
| 1276 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1277 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1278 | status = mwifiex_send_cmd_sync(priv, HostCmd_CMD_RSSI_INFO, |
| 1279 | HostCmd_ACT_GEN_GET, 0, signal); |
| 1280 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1281 | if (!status) { |
Amitkumar Karwar | c4859fb | 2011-05-10 20:47:35 -0700 | [diff] [blame] | 1282 | if (signal->selector & BCN_RSSI_AVG_MASK) |
| 1283 | priv->w_stats.qual.level = signal->bcn_rssi_avg; |
| 1284 | if (signal->selector & BCN_NF_AVG_MASK) |
| 1285 | priv->w_stats.qual.noise = signal->bcn_nf_avg; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1288 | return status; |
| 1289 | } |
| 1290 | |
| 1291 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1292 | * Sends IOCTL request to set encoding parameters. |
| 1293 | * |
| 1294 | * This function allocates the IOCTL request buffer, fills it |
| 1295 | * with requisite parameters and calls the IOCTL handler. |
| 1296 | */ |
| 1297 | int mwifiex_set_encode(struct mwifiex_private *priv, const u8 *key, |
| 1298 | int key_len, u8 key_index, int disable) |
| 1299 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1300 | struct mwifiex_ds_encrypt_key encrypt_key; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1301 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1302 | memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key)); |
| 1303 | encrypt_key.key_len = key_len; |
| 1304 | if (!disable) { |
| 1305 | encrypt_key.key_index = key_index; |
| 1306 | if (key_len) |
| 1307 | memcpy(encrypt_key.key_material, key, key_len); |
| 1308 | } else { |
| 1309 | encrypt_key.key_disable = true; |
| 1310 | } |
| 1311 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1312 | return mwifiex_sec_ioctl_encrypt_key(priv, &encrypt_key); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | /* |
| 1316 | * Sends IOCTL request to get extended version. |
| 1317 | * |
| 1318 | * This function allocates the IOCTL request buffer, fills it |
| 1319 | * with requisite parameters and calls the IOCTL handler. |
| 1320 | */ |
| 1321 | int |
| 1322 | mwifiex_get_ver_ext(struct mwifiex_private *priv) |
| 1323 | { |
| 1324 | struct mwifiex_ver_ext ver_ext; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1325 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1326 | memset(&ver_ext, 0, sizeof(struct host_cmd_ds_version_ext)); |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1327 | if (mwifiex_send_cmd_sync(priv, HostCmd_CMD_VERSION_EXT, |
| 1328 | HostCmd_ACT_GEN_GET, 0, &ver_ext)) |
| 1329 | return -1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1330 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1331 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | * Sends IOCTL request to get statistics information. |
| 1336 | * |
| 1337 | * This function allocates the IOCTL request buffer, fills it |
| 1338 | * with requisite parameters and calls the IOCTL handler. |
| 1339 | */ |
| 1340 | int |
| 1341 | mwifiex_get_stats_info(struct mwifiex_private *priv, |
| 1342 | struct mwifiex_ds_get_stats *log) |
| 1343 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1344 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1345 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1346 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_GET_LOG, |
Amitkumar Karwar | c4859fb | 2011-05-10 20:47:35 -0700 | [diff] [blame] | 1347 | HostCmd_ACT_GEN_GET, 0, log); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1348 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1349 | if (!ret) { |
Amitkumar Karwar | c4859fb | 2011-05-10 20:47:35 -0700 | [diff] [blame] | 1350 | priv->w_stats.discard.fragment = log->fcs_error; |
| 1351 | priv->w_stats.discard.retries = log->retry; |
| 1352 | priv->w_stats.discard.misc = log->ack_failure; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1355 | return ret; |
| 1356 | } |
| 1357 | |
| 1358 | /* |
| 1359 | * IOCTL request handler to read/write register. |
| 1360 | * |
| 1361 | * This function prepares the correct firmware command and |
| 1362 | * issues it. |
| 1363 | * |
| 1364 | * Access to the following registers are supported - |
| 1365 | * - MAC |
| 1366 | * - BBP |
| 1367 | * - RF |
| 1368 | * - PMIC |
| 1369 | * - CAU |
| 1370 | */ |
| 1371 | static int mwifiex_reg_mem_ioctl_reg_rw(struct mwifiex_private *priv, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1372 | struct mwifiex_ds_reg_rw *reg_rw, |
| 1373 | u16 action) |
| 1374 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1375 | u16 cmd_no; |
| 1376 | |
| 1377 | switch (le32_to_cpu(reg_rw->type)) { |
| 1378 | case MWIFIEX_REG_MAC: |
| 1379 | cmd_no = HostCmd_CMD_MAC_REG_ACCESS; |
| 1380 | break; |
| 1381 | case MWIFIEX_REG_BBP: |
| 1382 | cmd_no = HostCmd_CMD_BBP_REG_ACCESS; |
| 1383 | break; |
| 1384 | case MWIFIEX_REG_RF: |
| 1385 | cmd_no = HostCmd_CMD_RF_REG_ACCESS; |
| 1386 | break; |
| 1387 | case MWIFIEX_REG_PMIC: |
| 1388 | cmd_no = HostCmd_CMD_PMIC_REG_ACCESS; |
| 1389 | break; |
| 1390 | case MWIFIEX_REG_CAU: |
| 1391 | cmd_no = HostCmd_CMD_CAU_REG_ACCESS; |
| 1392 | break; |
| 1393 | default: |
| 1394 | return -1; |
| 1395 | } |
| 1396 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1397 | return mwifiex_send_cmd_sync(priv, cmd_no, action, 0, reg_rw); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1398 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /* |
| 1402 | * Sends IOCTL request to write to a register. |
| 1403 | * |
| 1404 | * This function allocates the IOCTL request buffer, fills it |
| 1405 | * with requisite parameters and calls the IOCTL handler. |
| 1406 | */ |
| 1407 | int |
| 1408 | mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type, |
| 1409 | u32 reg_offset, u32 reg_value) |
| 1410 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1411 | struct mwifiex_ds_reg_rw reg_rw; |
| 1412 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1413 | reg_rw.type = cpu_to_le32(reg_type); |
| 1414 | reg_rw.offset = cpu_to_le32(reg_offset); |
| 1415 | reg_rw.value = cpu_to_le32(reg_value); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1416 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1417 | 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] | 1418 | } |
| 1419 | |
| 1420 | /* |
| 1421 | * Sends IOCTL request to read from a register. |
| 1422 | * |
| 1423 | * This function allocates the IOCTL request buffer, fills it |
| 1424 | * with requisite parameters and calls the IOCTL handler. |
| 1425 | */ |
| 1426 | int |
| 1427 | mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type, |
| 1428 | u32 reg_offset, u32 *value) |
| 1429 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1430 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1431 | struct mwifiex_ds_reg_rw reg_rw; |
| 1432 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1433 | reg_rw.type = cpu_to_le32(reg_type); |
| 1434 | reg_rw.offset = cpu_to_le32(reg_offset); |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1435 | 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] | 1436 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1437 | if (ret) |
| 1438 | goto done; |
| 1439 | |
| 1440 | *value = le32_to_cpu(reg_rw.value); |
| 1441 | |
| 1442 | done: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1443 | return ret; |
| 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | * Sends IOCTL request to read from EEPROM. |
| 1448 | * |
| 1449 | * This function allocates the IOCTL request buffer, fills it |
| 1450 | * with requisite parameters and calls the IOCTL handler. |
| 1451 | */ |
| 1452 | int |
| 1453 | mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes, |
| 1454 | u8 *value) |
| 1455 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1456 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1457 | struct mwifiex_ds_read_eeprom rd_eeprom; |
| 1458 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1459 | rd_eeprom.offset = cpu_to_le16((u16) offset); |
| 1460 | rd_eeprom.byte_count = cpu_to_le16((u16) bytes); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1461 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1462 | /* Send request to firmware */ |
| 1463 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_EEPROM_ACCESS, |
| 1464 | HostCmd_ACT_GEN_GET, 0, &rd_eeprom); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1465 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1466 | if (!ret) |
| 1467 | memcpy(value, rd_eeprom.value, MAX_EEPROM_DATA); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1468 | return ret; |
| 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | * This function sets a generic IE. In addition to generic IE, it can |
| 1473 | * also handle WPA, WPA2 and WAPI IEs. |
| 1474 | */ |
| 1475 | static int |
| 1476 | mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr, |
| 1477 | u16 ie_len) |
| 1478 | { |
| 1479 | int ret = 0; |
| 1480 | struct ieee_types_vendor_header *pvendor_ie; |
| 1481 | const u8 wpa_oui[] = { 0x00, 0x50, 0xf2, 0x01 }; |
| 1482 | const u8 wps_oui[] = { 0x00, 0x50, 0xf2, 0x04 }; |
| 1483 | |
| 1484 | /* If the passed length is zero, reset the buffer */ |
| 1485 | if (!ie_len) { |
| 1486 | priv->gen_ie_buf_len = 0; |
| 1487 | priv->wps.session_enable = false; |
| 1488 | |
| 1489 | return 0; |
| 1490 | } else if (!ie_data_ptr) { |
| 1491 | return -1; |
| 1492 | } |
| 1493 | pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr; |
| 1494 | /* Test to see if it is a WPA IE, if not, then it is a gen IE */ |
| 1495 | if (((pvendor_ie->element_id == WLAN_EID_WPA) |
| 1496 | && (!memcmp(pvendor_ie->oui, wpa_oui, sizeof(wpa_oui)))) |
| 1497 | || (pvendor_ie->element_id == WLAN_EID_RSN)) { |
| 1498 | |
| 1499 | /* IE is a WPA/WPA2 IE so call set_wpa function */ |
| 1500 | ret = mwifiex_set_wpa_ie_helper(priv, ie_data_ptr, ie_len); |
| 1501 | priv->wps.session_enable = false; |
| 1502 | |
| 1503 | return ret; |
| 1504 | } else if (pvendor_ie->element_id == WLAN_EID_BSS_AC_ACCESS_DELAY) { |
| 1505 | /* IE is a WAPI IE so call set_wapi function */ |
| 1506 | ret = mwifiex_set_wapi_ie(priv, ie_data_ptr, ie_len); |
| 1507 | |
| 1508 | return ret; |
| 1509 | } |
| 1510 | /* |
| 1511 | * Verify that the passed length is not larger than the |
| 1512 | * available space remaining in the buffer |
| 1513 | */ |
| 1514 | if (ie_len < (sizeof(priv->gen_ie_buf) - priv->gen_ie_buf_len)) { |
| 1515 | |
| 1516 | /* Test to see if it is a WPS IE, if so, enable |
| 1517 | * wps session flag |
| 1518 | */ |
| 1519 | pvendor_ie = (struct ieee_types_vendor_header *) ie_data_ptr; |
| 1520 | if ((pvendor_ie->element_id == WLAN_EID_VENDOR_SPECIFIC) |
| 1521 | && (!memcmp(pvendor_ie->oui, wps_oui, |
| 1522 | sizeof(wps_oui)))) { |
| 1523 | priv->wps.session_enable = true; |
| 1524 | dev_dbg(priv->adapter->dev, |
| 1525 | "info: WPS Session Enabled.\n"); |
| 1526 | } |
| 1527 | |
| 1528 | /* Append the passed data to the end of the |
| 1529 | genIeBuffer */ |
| 1530 | memcpy(priv->gen_ie_buf + priv->gen_ie_buf_len, ie_data_ptr, |
| 1531 | ie_len); |
| 1532 | /* Increment the stored buffer length by the |
| 1533 | size passed */ |
| 1534 | priv->gen_ie_buf_len += ie_len; |
| 1535 | } else { |
| 1536 | /* Passed data does not fit in the remaining |
| 1537 | buffer space */ |
| 1538 | ret = -1; |
| 1539 | } |
| 1540 | |
| 1541 | /* Return 0, or -1 for error case */ |
| 1542 | return ret; |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * IOCTL request handler to set/get generic IE. |
| 1547 | * |
| 1548 | * In addition to various generic IEs, this function can also be |
| 1549 | * used to set the ARP filter. |
| 1550 | */ |
| 1551 | static int mwifiex_misc_ioctl_gen_ie(struct mwifiex_private *priv, |
| 1552 | struct mwifiex_ds_misc_gen_ie *gen_ie, |
| 1553 | u16 action) |
| 1554 | { |
| 1555 | struct mwifiex_adapter *adapter = priv->adapter; |
| 1556 | |
| 1557 | switch (gen_ie->type) { |
| 1558 | case MWIFIEX_IE_TYPE_GEN_IE: |
| 1559 | if (action == HostCmd_ACT_GEN_GET) { |
| 1560 | gen_ie->len = priv->wpa_ie_len; |
| 1561 | memcpy(gen_ie->ie_data, priv->wpa_ie, gen_ie->len); |
| 1562 | } else { |
| 1563 | mwifiex_set_gen_ie_helper(priv, gen_ie->ie_data, |
| 1564 | (u16) gen_ie->len); |
| 1565 | } |
| 1566 | break; |
| 1567 | case MWIFIEX_IE_TYPE_ARP_FILTER: |
| 1568 | memset(adapter->arp_filter, 0, sizeof(adapter->arp_filter)); |
| 1569 | if (gen_ie->len > ARP_FILTER_MAX_BUF_SIZE) { |
| 1570 | adapter->arp_filter_size = 0; |
| 1571 | dev_err(adapter->dev, "invalid ARP filter size\n"); |
| 1572 | return -1; |
| 1573 | } else { |
| 1574 | memcpy(adapter->arp_filter, gen_ie->ie_data, |
| 1575 | gen_ie->len); |
| 1576 | adapter->arp_filter_size = gen_ie->len; |
| 1577 | } |
| 1578 | break; |
| 1579 | default: |
| 1580 | dev_err(adapter->dev, "invalid IE type\n"); |
| 1581 | return -1; |
| 1582 | } |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
| 1586 | /* |
| 1587 | * Sends IOCTL request to set a generic IE. |
| 1588 | * |
| 1589 | * This function allocates the IOCTL request buffer, fills it |
| 1590 | * with requisite parameters and calls the IOCTL handler. |
| 1591 | */ |
| 1592 | int |
| 1593 | mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len) |
| 1594 | { |
| 1595 | struct mwifiex_ds_misc_gen_ie gen_ie; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1596 | |
| 1597 | if (ie_len > IW_CUSTOM_MAX) |
| 1598 | return -EFAULT; |
| 1599 | |
| 1600 | gen_ie.type = MWIFIEX_IE_TYPE_GEN_IE; |
| 1601 | gen_ie.len = ie_len; |
| 1602 | memcpy(gen_ie.ie_data, ie, ie_len); |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1603 | 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] | 1604 | return -EFAULT; |
| 1605 | |
| 1606 | return 0; |
| 1607 | } |