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