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