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