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