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