Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include <net/mac80211.h> |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 31 | #include <linux/etherdevice.h> |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 32 | #include <linux/sched.h> |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 33 | |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 34 | #include "iwl-dev.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 35 | #include "iwl-core.h" |
| 36 | #include "iwl-sta.h" |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 37 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 38 | u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr) |
| 39 | { |
| 40 | int i; |
| 41 | int start = 0; |
| 42 | int ret = IWL_INVALID_STATION; |
| 43 | unsigned long flags; |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 44 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 45 | if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) || |
| 46 | (priv->iw_mode == NL80211_IFTYPE_AP)) |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 47 | start = IWL_STA_ID; |
| 48 | |
| 49 | if (is_broadcast_ether_addr(addr)) |
| 50 | return priv->hw_params.bcast_sta_id; |
| 51 | |
| 52 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 53 | for (i = start; i < priv->hw_params.max_stations; i++) |
| 54 | if (priv->stations[i].used && |
| 55 | (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 56 | addr))) { |
| 57 | ret = i; |
| 58 | goto out; |
| 59 | } |
| 60 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 61 | IWL_DEBUG_ASSOC_LIMIT(priv, "can not find STA %pM total %d\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 62 | addr, priv->num_stations); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 63 | |
| 64 | out: |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 65 | /* |
| 66 | * It may be possible that more commands interacting with stations |
| 67 | * arrive before we completed processing the adding of |
| 68 | * station |
| 69 | */ |
| 70 | if (ret != IWL_INVALID_STATION && |
| 71 | (!(priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) || |
| 72 | ((priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) && |
| 73 | (priv->stations[ret].used & IWL_STA_UCODE_INPROGRESS)))) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 74 | IWL_ERR(priv, "Requested station info for sta %d before ready.\n", |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 75 | ret); |
| 76 | ret = IWL_INVALID_STATION; |
| 77 | } |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 78 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 79 | return ret; |
| 80 | } |
| 81 | EXPORT_SYMBOL(iwl_find_station); |
| 82 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 83 | /* priv->sta_lock must be held */ |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 84 | static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) |
| 85 | { |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 86 | |
| 87 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) |
| 88 | IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u addr %pM\n", |
| 89 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 90 | |
| 91 | if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) { |
| 92 | IWL_DEBUG_ASSOC(priv, |
| 93 | "STA id %u addr %pM already present in uCode (according to driver)\n", |
| 94 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 95 | } else { |
| 96 | priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE; |
| 97 | IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n", |
| 98 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | static void iwl_process_add_sta_resp(struct iwl_priv *priv, |
| 103 | struct iwl_addsta_cmd *addsta, |
| 104 | struct iwl_rx_packet *pkt, |
| 105 | bool sync) |
| 106 | { |
| 107 | u8 sta_id = addsta->sta.sta_id; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 108 | unsigned long flags; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 109 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 110 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 111 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 112 | pkt->hdr.flags); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", |
| 117 | sta_id); |
| 118 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 119 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 120 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 121 | switch (pkt->u.add_sta.status) { |
| 122 | case ADD_STA_SUCCESS_MSK: |
| 123 | IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n"); |
| 124 | iwl_sta_ucode_activate(priv, sta_id); |
| 125 | break; |
| 126 | case ADD_STA_NO_ROOM_IN_TABLE: |
| 127 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 128 | sta_id); |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 129 | break; |
| 130 | case ADD_STA_NO_BLOCK_ACK_RESOURCE: |
| 131 | IWL_ERR(priv, "Adding station %d failed, no block ack resource.\n", |
| 132 | sta_id); |
| 133 | break; |
| 134 | case ADD_STA_MODIFY_NON_EXIST_STA: |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 135 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 136 | sta_id); |
| 137 | break; |
| 138 | default: |
| 139 | IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n", |
| 140 | pkt->u.add_sta.status); |
| 141 | break; |
| 142 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 143 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 144 | IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n", |
| 145 | priv->stations[sta_id].sta.mode == |
| 146 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 147 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 148 | |
| 149 | /* |
| 150 | * XXX: The MAC address in the command buffer is often changed from |
| 151 | * the original sent to the device. That is, the MAC address |
| 152 | * written to the command buffer often is not the same MAC adress |
| 153 | * read from the command buffer when the command returns. This |
| 154 | * issue has not yet been resolved and this debugging is left to |
| 155 | * observe the problem. |
| 156 | */ |
| 157 | IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n", |
| 158 | priv->stations[sta_id].sta.mode == |
| 159 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 160 | addsta->sta.addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 161 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 162 | } |
| 163 | |
Johannes Berg | 5696aea | 2009-07-24 11:13:06 -0700 | [diff] [blame] | 164 | static void iwl_add_sta_callback(struct iwl_priv *priv, |
| 165 | struct iwl_device_cmd *cmd, |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 166 | struct iwl_rx_packet *pkt) |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 167 | { |
Tomas Winkler | 3257e5d | 2008-10-14 12:32:43 -0700 | [diff] [blame] | 168 | struct iwl_addsta_cmd *addsta = |
| 169 | (struct iwl_addsta_cmd *)cmd->cmd.payload; |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 170 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 171 | iwl_process_add_sta_resp(priv, addsta, pkt, false); |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 172 | |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 173 | } |
| 174 | |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 175 | int iwl_send_add_sta(struct iwl_priv *priv, |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 176 | struct iwl_addsta_cmd *sta, u8 flags) |
| 177 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 178 | struct iwl_rx_packet *pkt = NULL; |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 179 | int ret = 0; |
| 180 | u8 data[sizeof(*sta)]; |
| 181 | struct iwl_host_cmd cmd = { |
| 182 | .id = REPLY_ADD_STA, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 183 | .flags = flags, |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 184 | .data = data, |
| 185 | }; |
Reinette Chatre | f875f51 | 2010-04-05 10:43:10 -0700 | [diff] [blame] | 186 | u8 sta_id __maybe_unused = sta->sta.sta_id; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 187 | |
| 188 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", |
| 189 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 190 | |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 191 | if (flags & CMD_ASYNC) |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 192 | cmd.callback = iwl_add_sta_callback; |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 193 | else |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 194 | cmd.flags |= CMD_WANT_SKB; |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 195 | |
| 196 | cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data); |
| 197 | ret = iwl_send_cmd(priv, &cmd); |
| 198 | |
| 199 | if (ret || (flags & CMD_ASYNC)) |
| 200 | return ret; |
| 201 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 202 | if (ret == 0) { |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 203 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
| 204 | iwl_process_add_sta_resp(priv, sta, pkt, true); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 205 | } |
Zhu Yi | 64a76b5 | 2009-12-10 14:37:21 -0800 | [diff] [blame] | 206 | iwl_free_pages(priv, cmd.reply_page); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 207 | |
| 208 | return ret; |
| 209 | } |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 210 | EXPORT_SYMBOL(iwl_send_add_sta); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 211 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 212 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 213 | struct ieee80211_sta_ht_cap *sta_ht_inf) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 214 | { |
| 215 | __le32 sta_flags; |
| 216 | u8 mimo_ps_mode; |
| 217 | |
| 218 | if (!sta_ht_inf || !sta_ht_inf->ht_supported) |
| 219 | goto done; |
| 220 | |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 221 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; |
Wey-Yi Guy | 3f3e037 | 2009-10-30 14:36:17 -0700 | [diff] [blame] | 222 | IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n", |
| 223 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ? |
| 224 | "static" : |
| 225 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ? |
| 226 | "dynamic" : "disabled"); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 227 | |
| 228 | sta_flags = priv->stations[index].sta.station_flags; |
| 229 | |
| 230 | sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); |
| 231 | |
| 232 | switch (mimo_ps_mode) { |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 233 | case WLAN_HT_CAP_SM_PS_STATIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 234 | sta_flags |= STA_FLG_MIMO_DIS_MSK; |
| 235 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 236 | case WLAN_HT_CAP_SM_PS_DYNAMIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 237 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
| 238 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 239 | case WLAN_HT_CAP_SM_PS_DISABLED: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 240 | break; |
| 241 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 242 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 243 | break; |
| 244 | } |
| 245 | |
| 246 | sta_flags |= cpu_to_le32( |
| 247 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); |
| 248 | |
| 249 | sta_flags |= cpu_to_le32( |
| 250 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
| 251 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 252 | if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf)) |
| 253 | sta_flags |= STA_FLG_HT40_EN_MSK; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 254 | else |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 255 | sta_flags &= ~STA_FLG_HT40_EN_MSK; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 256 | |
| 257 | priv->stations[index].sta.station_flags = sta_flags; |
| 258 | done: |
| 259 | return; |
| 260 | } |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 261 | |
| 262 | /** |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 263 | * iwl_prep_station - Prepare station information for addition |
| 264 | * |
| 265 | * should be called with sta_lock held |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 266 | */ |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 267 | static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr, |
| 268 | bool is_ap, |
| 269 | struct ieee80211_sta_ht_cap *ht_info) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 270 | { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 271 | struct iwl_station_entry *station; |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 272 | int i; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 273 | u8 sta_id = IWL_INVALID_STATION; |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 274 | u16 rate; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 275 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 276 | if (is_ap) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 277 | sta_id = IWL_AP_ID; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 278 | else if (is_broadcast_ether_addr(addr)) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 279 | sta_id = priv->hw_params.bcast_sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 280 | else |
| 281 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
| 282 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 283 | addr)) { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 284 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 285 | break; |
| 286 | } |
| 287 | |
| 288 | if (!priv->stations[i].used && |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 289 | sta_id == IWL_INVALID_STATION) |
| 290 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 291 | } |
| 292 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 293 | /* |
| 294 | * These two conditions have the same outcome, but keep them |
| 295 | * separate |
| 296 | */ |
| 297 | if (unlikely(sta_id == IWL_INVALID_STATION)) |
| 298 | return sta_id; |
| 299 | |
| 300 | /* |
| 301 | * uCode is not able to deal with multiple requests to add a |
| 302 | * station. Keep track if one is in progress so that we do not send |
| 303 | * another. |
| 304 | */ |
| 305 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 306 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", |
| 307 | sta_id); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 308 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 309 | } |
| 310 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 311 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 312 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 313 | !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 314 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", |
| 315 | sta_id, addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 316 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 317 | } |
| 318 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 319 | station = &priv->stations[sta_id]; |
| 320 | station->used = IWL_STA_DRIVER_ACTIVE; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 321 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 322 | sta_id, addr); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 323 | priv->num_stations++; |
| 324 | |
| 325 | /* Set up the REPLY_ADD_STA command to send to device */ |
| 326 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
| 327 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 328 | station->sta.mode = 0; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 329 | station->sta.sta.sta_id = sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 330 | station->sta.station_flags = 0; |
| 331 | |
| 332 | /* BCAST station and IBSS stations do not work in HT mode */ |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 333 | if (sta_id != priv->hw_params.bcast_sta_id && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 334 | priv->iw_mode != NL80211_IFTYPE_ADHOC) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 335 | iwl_set_ht_add_station(priv, sta_id, ht_info); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 336 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 337 | /* 3945 only */ |
| 338 | rate = (priv->band == IEEE80211_BAND_5GHZ) ? |
| 339 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP; |
| 340 | /* Turn on both antennas for the station... */ |
| 341 | station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK); |
| 342 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 343 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 344 | |
| 345 | } |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 346 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 347 | #define STA_WAIT_TIMEOUT (HZ/2) |
| 348 | |
| 349 | /** |
| 350 | * iwl_add_station_common - |
| 351 | */ |
| 352 | int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, |
| 353 | bool is_ap, |
| 354 | struct ieee80211_sta_ht_cap *ht_info, |
| 355 | u8 *sta_id_r) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 356 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 357 | struct iwl_station_entry *station; |
| 358 | unsigned long flags_spin; |
| 359 | int ret = 0; |
| 360 | u8 sta_id; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 361 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 362 | *sta_id_r = 0; |
| 363 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 364 | sta_id = iwl_prep_station(priv, addr, is_ap, ht_info); |
| 365 | if (sta_id == IWL_INVALID_STATION) { |
| 366 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", |
| 367 | addr); |
| 368 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 369 | return -EINVAL; |
| 370 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 371 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 372 | /* |
| 373 | * uCode is not able to deal with multiple requests to add a |
| 374 | * station. Keep track if one is in progress so that we do not send |
| 375 | * another. |
| 376 | */ |
| 377 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 378 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", |
| 379 | sta_id); |
| 380 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 381 | return -EEXIST; |
| 382 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 383 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 384 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 385 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
| 386 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", |
| 387 | sta_id, addr); |
| 388 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 389 | return -EEXIST; |
| 390 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 391 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 392 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; |
| 393 | station = &priv->stations[sta_id]; |
| 394 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 395 | |
| 396 | /* Add station to device's station table */ |
| 397 | ret = iwl_send_add_sta(priv, &station->sta, CMD_SYNC); |
| 398 | if (ret) { |
| 399 | IWL_ERR(priv, "Adding station %pM failed.\n", station->sta.sta.addr); |
| 400 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 401 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 402 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 403 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 404 | } |
| 405 | *sta_id_r = sta_id; |
| 406 | return ret; |
| 407 | } |
| 408 | EXPORT_SYMBOL(iwl_add_station_common); |
| 409 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 410 | static struct iwl_link_quality_cmd *iwl_sta_init_lq(struct iwl_priv *priv, |
| 411 | const u8 *addr, bool is_ap) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 412 | { |
| 413 | int i, r; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 414 | struct iwl_link_quality_cmd *link_cmd; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 415 | u32 rate_flags; |
Wey-Yi Guy | 57e40d3 | 2010-03-09 15:36:10 -0800 | [diff] [blame] | 416 | int ret = 0; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 417 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 418 | link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL); |
| 419 | if (!link_cmd) { |
| 420 | IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n"); |
| 421 | return NULL; |
| 422 | } |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 423 | /* Set up the rate scaling to start at selected rate, fall back |
| 424 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
| 425 | if (is_ap) |
| 426 | r = IWL_RATE_54M_INDEX; |
| 427 | else if (priv->band == IEEE80211_BAND_5GHZ) |
| 428 | r = IWL_RATE_6M_INDEX; |
| 429 | else |
| 430 | r = IWL_RATE_1M_INDEX; |
| 431 | |
| 432 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 433 | rate_flags = 0; |
| 434 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) |
| 435 | rate_flags |= RATE_MCS_CCK_MSK; |
| 436 | |
| 437 | rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) << |
| 438 | RATE_MCS_ANT_POS; |
| 439 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 440 | link_cmd->rs_table[i].rate_n_flags = |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 441 | iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); |
| 442 | r = iwl_get_prev_ieee_rate(r); |
| 443 | } |
| 444 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 445 | link_cmd->general_params.single_stream_ant_msk = |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 446 | first_antenna(priv->hw_params.valid_tx_ant); |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 447 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 448 | link_cmd->general_params.dual_stream_ant_msk = |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 449 | priv->hw_params.valid_tx_ant & |
| 450 | ~first_antenna(priv->hw_params.valid_tx_ant); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 451 | if (!link_cmd->general_params.dual_stream_ant_msk) { |
| 452 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 453 | } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) { |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 454 | link_cmd->general_params.dual_stream_ant_msk = |
Wey-Yi Guy | 3a23d69 | 2010-04-03 16:44:39 -0700 | [diff] [blame] | 455 | priv->hw_params.valid_tx_ant; |
| 456 | } |
| 457 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 458 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
| 459 | link_cmd->agg_params.agg_time_limit = |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 460 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
| 461 | |
| 462 | /* Update the rate scaling for control frame Tx to AP */ |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 463 | link_cmd->sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 464 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 465 | ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true); |
Wey-Yi Guy | 57e40d3 | 2010-03-09 15:36:10 -0800 | [diff] [blame] | 466 | if (ret) |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 467 | IWL_ERR(priv, "Link quality command failed (%d)\n", ret); |
| 468 | |
| 469 | return link_cmd; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /* |
| 473 | * iwl_add_local_stations - Add stations not requested by mac80211 |
| 474 | * |
| 475 | * This will be either the broadcast station or the bssid station needed by |
| 476 | * ad-hoc. |
| 477 | * |
| 478 | * Function sleeps. |
| 479 | */ |
| 480 | int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs) |
| 481 | { |
| 482 | int ret; |
| 483 | u8 sta_id; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 484 | struct iwl_link_quality_cmd *link_cmd; |
| 485 | unsigned long flags; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 486 | |
| 487 | ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id); |
| 488 | if (ret) { |
| 489 | IWL_ERR(priv, "Unable to add station %pM\n", addr); |
| 490 | return ret; |
| 491 | } |
| 492 | |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 493 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 494 | priv->stations[sta_id].used |= IWL_STA_LOCAL; |
| 495 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 496 | |
| 497 | if (init_rs) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 498 | /* Set up default rate scaling table in device's station table */ |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 499 | link_cmd = iwl_sta_init_lq(priv, addr, false); |
| 500 | if (!link_cmd) { |
| 501 | IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n", |
| 502 | addr); |
| 503 | return -ENOMEM; |
| 504 | } |
| 505 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 506 | priv->stations[sta_id].lq = link_cmd; |
| 507 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 508 | } |
| 509 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 510 | return 0; |
| 511 | } |
| 512 | EXPORT_SYMBOL(iwl_add_local_station); |
| 513 | |
| 514 | /** |
| 515 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station |
| 516 | * |
| 517 | * priv->sta_lock must be held |
| 518 | */ |
| 519 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) |
| 520 | { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 521 | /* Ucode must be active and driver must be non active */ |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 522 | if ((priv->stations[sta_id].used & |
| 523 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 524 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 525 | |
| 526 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; |
| 527 | |
| 528 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 529 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 530 | } |
| 531 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 532 | static int iwl_send_remove_station(struct iwl_priv *priv, |
| 533 | struct iwl_station_entry *station) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 534 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 535 | struct iwl_rx_packet *pkt; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 536 | int ret; |
| 537 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 538 | unsigned long flags_spin; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 539 | struct iwl_rem_sta_cmd rm_sta_cmd; |
| 540 | |
| 541 | struct iwl_host_cmd cmd = { |
| 542 | .id = REPLY_REMOVE_STA, |
| 543 | .len = sizeof(struct iwl_rem_sta_cmd), |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 544 | .flags = CMD_SYNC, |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 545 | .data = &rm_sta_cmd, |
| 546 | }; |
| 547 | |
| 548 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); |
| 549 | rm_sta_cmd.num_sta = 1; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 550 | memcpy(&rm_sta_cmd.addr, &station->sta.sta.addr , ETH_ALEN); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 551 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 552 | cmd.flags |= CMD_WANT_SKB; |
| 553 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 554 | ret = iwl_send_cmd(priv, &cmd); |
| 555 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 556 | if (ret) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 557 | return ret; |
| 558 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 559 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
| 560 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 561 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 562 | pkt->hdr.flags); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 563 | ret = -EIO; |
| 564 | } |
| 565 | |
| 566 | if (!ret) { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 567 | switch (pkt->u.rem_sta.status) { |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 568 | case REM_STA_SUCCESS_MSK: |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 569 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 570 | iwl_sta_ucode_deactivate(priv, station->sta.sta.sta_id); |
| 571 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 572 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 573 | break; |
| 574 | default: |
| 575 | ret = -EIO; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 576 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 577 | break; |
| 578 | } |
| 579 | } |
Zhu Yi | 64a76b5 | 2009-12-10 14:37:21 -0800 | [diff] [blame] | 580 | iwl_free_pages(priv, cmd.reply_page); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 581 | |
| 582 | return ret; |
| 583 | } |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 584 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 585 | /** |
| 586 | * iwl_remove_station - Remove driver's knowledge of station. |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 587 | */ |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 588 | int iwl_remove_station(struct iwl_priv *priv, const u8 *addr) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 589 | { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 590 | int sta_id = IWL_INVALID_STATION; |
| 591 | int i, ret = -EINVAL; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 592 | unsigned long flags; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 593 | bool is_ap = priv->iw_mode == NL80211_IFTYPE_STATION; |
| 594 | struct iwl_station_entry *station; |
| 595 | |
| 596 | if (!iwl_is_ready(priv)) { |
| 597 | IWL_DEBUG_INFO(priv, |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 598 | "Unable to remove station %pM, device not ready.\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 599 | addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 600 | /* |
| 601 | * It is typical for stations to be removed when we are |
| 602 | * going down. Return success since device will be down |
| 603 | * soon anyway |
| 604 | */ |
| 605 | return 0; |
| 606 | } |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 607 | |
| 608 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 609 | |
| 610 | if (is_ap) |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 611 | sta_id = IWL_AP_ID; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 612 | else |
| 613 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
| 614 | if (priv->stations[i].used && |
| 615 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 616 | addr)) { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 617 | sta_id = i; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 618 | break; |
| 619 | } |
| 620 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 621 | if (unlikely(sta_id == IWL_INVALID_STATION)) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 622 | goto out; |
| 623 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 624 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 625 | sta_id, addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 626 | |
| 627 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 628 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 629 | addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 630 | goto out; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 631 | } |
| 632 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 633 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 634 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 635 | addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 636 | goto out; |
| 637 | } |
| 638 | |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 639 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { |
| 640 | kfree(priv->stations[sta_id].lq); |
| 641 | priv->stations[sta_id].lq = NULL; |
| 642 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 643 | |
| 644 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 645 | |
| 646 | priv->num_stations--; |
| 647 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 648 | BUG_ON(priv->num_stations < 0); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 649 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 650 | station = &priv->stations[sta_id]; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 651 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 652 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 653 | ret = iwl_send_remove_station(priv, station); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 654 | return ret; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 655 | out: |
| 656 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 657 | return ret; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 658 | } |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 659 | EXPORT_SYMBOL_GPL(iwl_remove_station); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 660 | |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 661 | /** |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 662 | * iwl_clear_ucode_stations() - clear entire station table driver and/or ucode |
| 663 | * @priv: |
| 664 | * @force: If set then the uCode station table needs to be cleared here. If |
| 665 | * not set then the uCode station table has already been cleared, |
| 666 | * for example after sending it a RXON command without ASSOC bit |
| 667 | * set, and we just need to change driver state here. |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 668 | */ |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 669 | void iwl_clear_ucode_stations(struct iwl_priv *priv, bool force) |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 670 | { |
Mohamed Abbas | 48676eb | 2009-03-11 11:17:59 -0700 | [diff] [blame] | 671 | int i; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 672 | unsigned long flags_spin; |
| 673 | bool cleared = false; |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 674 | |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 675 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver%s\n", |
| 676 | force ? " and ucode" : ""); |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 677 | |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 678 | if (force) { |
| 679 | if (!iwl_is_ready(priv)) { |
| 680 | /* |
| 681 | * If device is not ready at this point the station |
| 682 | * table is likely already empty (uCode not ready |
| 683 | * to receive station requests) or will soon be |
| 684 | * due to interface going down. |
| 685 | */ |
| 686 | IWL_DEBUG_INFO(priv, "Unable to remove stations from device - device not ready\n"); |
| 687 | } else { |
| 688 | iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL); |
| 689 | } |
Mohamed Abbas | 48676eb | 2009-03-11 11:17:59 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 692 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 693 | if (force) { |
| 694 | IWL_DEBUG_INFO(priv, "Clearing all station information in driver\n"); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 695 | /* |
| 696 | * The station entry contains a link to the LQ command. For |
| 697 | * all stations managed by mac80211 this memory will be |
| 698 | * managed by it also. For local stations (broadcast and |
| 699 | * bssid station when in adhoc mode) we need to maintain |
| 700 | * this lq command separately. This memory is created when |
| 701 | * these stations are added. |
| 702 | */ |
| 703 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 704 | if (priv->stations[i].used & IWL_STA_LOCAL) { |
| 705 | kfree(priv->stations[i].lq); |
| 706 | priv->stations[i].lq = NULL; |
| 707 | } |
| 708 | } |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 709 | priv->num_stations = 0; |
| 710 | memset(priv->stations, 0, sizeof(priv->stations)); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 711 | cleared = true; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 712 | } else { |
| 713 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 714 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 715 | IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 716 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
| 717 | cleared = true; |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 722 | |
| 723 | if (!cleared) |
| 724 | IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n"); |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 725 | } |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 726 | EXPORT_SYMBOL(iwl_clear_ucode_stations); |
| 727 | |
| 728 | /** |
| 729 | * iwl_restore_stations() - Restore driver known stations to device |
| 730 | * |
| 731 | * All stations considered active by driver, but not present in ucode, is |
| 732 | * restored. |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 733 | * |
| 734 | * Function sleeps. |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 735 | */ |
| 736 | void iwl_restore_stations(struct iwl_priv *priv) |
| 737 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 738 | struct iwl_station_entry *station; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 739 | unsigned long flags_spin; |
| 740 | int i; |
| 741 | bool found = false; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 742 | int ret; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 743 | |
| 744 | if (!iwl_is_ready(priv)) { |
| 745 | IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n"); |
| 746 | return; |
| 747 | } |
| 748 | |
| 749 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); |
| 750 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 751 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 752 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && |
| 753 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { |
| 754 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", |
| 755 | priv->stations[i].sta.sta.addr); |
| 756 | priv->stations[i].sta.mode = 0; |
| 757 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; |
| 758 | found = true; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | for (i = 0; i < priv->hw_params.max_stations; i++) { |
| 763 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 764 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 765 | station = &priv->stations[i]; |
| 766 | ret = iwl_send_add_sta(priv, &priv->stations[i].sta, CMD_SYNC); |
| 767 | if (ret) { |
| 768 | IWL_ERR(priv, "Adding station %pM failed.\n", |
| 769 | station->sta.sta.addr); |
| 770 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 771 | priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 772 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 773 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 774 | } |
| 775 | /* |
| 776 | * Rate scaling has already been initialized, send |
| 777 | * current LQ command |
| 778 | */ |
| 779 | if (station->lq) |
| 780 | iwl_send_lq_cmd(priv, station->lq, CMD_SYNC, true); |
| 781 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 782 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 787 | if (!found) |
| 788 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n"); |
| 789 | else |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 790 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n"); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 791 | } |
| 792 | EXPORT_SYMBOL(iwl_restore_stations); |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 793 | |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 794 | int iwl_get_free_ucode_key_index(struct iwl_priv *priv) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 795 | { |
| 796 | int i; |
| 797 | |
| 798 | for (i = 0; i < STA_KEY_MAX_NUM; i++) |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 799 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 800 | return i; |
| 801 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 802 | return WEP_INVALID_OFFSET; |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 803 | } |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 804 | EXPORT_SYMBOL(iwl_get_free_ucode_key_index); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 805 | |
Johannes Berg | 335348b | 2010-03-30 10:11:46 -0700 | [diff] [blame] | 806 | static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 807 | { |
| 808 | int i, not_empty = 0; |
| 809 | u8 buff[sizeof(struct iwl_wep_cmd) + |
| 810 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; |
| 811 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; |
| 812 | size_t cmd_size = sizeof(struct iwl_wep_cmd); |
| 813 | struct iwl_host_cmd cmd = { |
| 814 | .id = REPLY_WEPKEY, |
| 815 | .data = wep_cmd, |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 816 | .flags = CMD_SYNC, |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 817 | }; |
| 818 | |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 819 | might_sleep(); |
| 820 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 821 | memset(wep_cmd, 0, cmd_size + |
| 822 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); |
| 823 | |
| 824 | for (i = 0; i < WEP_KEYS_MAX ; i++) { |
| 825 | wep_cmd->key[i].key_index = i; |
| 826 | if (priv->wep_keys[i].key_size) { |
| 827 | wep_cmd->key[i].key_offset = i; |
| 828 | not_empty = 1; |
| 829 | } else { |
| 830 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 831 | } |
| 832 | |
| 833 | wep_cmd->key[i].key_size = priv->wep_keys[i].key_size; |
| 834 | memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key, |
| 835 | priv->wep_keys[i].key_size); |
| 836 | } |
| 837 | |
| 838 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 839 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 840 | |
| 841 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; |
| 842 | |
| 843 | cmd.len = cmd_size; |
| 844 | |
| 845 | if (not_empty || send_if_empty) |
| 846 | return iwl_send_cmd(priv, &cmd); |
| 847 | else |
| 848 | return 0; |
| 849 | } |
Johannes Berg | 335348b | 2010-03-30 10:11:46 -0700 | [diff] [blame] | 850 | |
| 851 | int iwl_restore_default_wep_keys(struct iwl_priv *priv) |
| 852 | { |
| 853 | WARN_ON(!mutex_is_locked(&priv->mutex)); |
| 854 | |
| 855 | return iwl_send_static_wepkey_cmd(priv, 0); |
| 856 | } |
| 857 | EXPORT_SYMBOL(iwl_restore_default_wep_keys); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 858 | |
| 859 | int iwl_remove_default_wep_key(struct iwl_priv *priv, |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 860 | struct ieee80211_key_conf *keyconf) |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 861 | { |
| 862 | int ret; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 863 | |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 864 | WARN_ON(!mutex_is_locked(&priv->mutex)); |
| 865 | |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 866 | IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", |
| 867 | keyconf->keyidx); |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 868 | |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 869 | memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 870 | if (iwl_is_rfkill(priv)) { |
| 871 | IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 872 | /* but keys in device are clear anyway so return success */ |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 873 | return 0; |
| 874 | } |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 875 | ret = iwl_send_static_wepkey_cmd(priv, 1); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 876 | IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 877 | keyconf->keyidx, ret); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 878 | |
| 879 | return ret; |
| 880 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 881 | EXPORT_SYMBOL(iwl_remove_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 882 | |
| 883 | int iwl_set_default_wep_key(struct iwl_priv *priv, |
| 884 | struct ieee80211_key_conf *keyconf) |
| 885 | { |
| 886 | int ret; |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 887 | |
| 888 | WARN_ON(!mutex_is_locked(&priv->mutex)); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 889 | |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 890 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
| 891 | keyconf->keylen != WEP_KEY_LEN_64) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 892 | IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen); |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 893 | return -EINVAL; |
| 894 | } |
| 895 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 896 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 897 | keyconf->hw_key_idx = HW_KEY_DEFAULT; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 898 | priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; |
| 899 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 900 | priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
| 901 | memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, |
| 902 | keyconf->keylen); |
| 903 | |
| 904 | ret = iwl_send_static_wepkey_cmd(priv, 0); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 905 | IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 906 | keyconf->keylen, keyconf->keyidx, ret); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 907 | |
| 908 | return ret; |
| 909 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 910 | EXPORT_SYMBOL(iwl_set_default_wep_key); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 911 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 912 | static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 913 | struct ieee80211_key_conf *keyconf, |
| 914 | u8 sta_id) |
| 915 | { |
| 916 | unsigned long flags; |
| 917 | __le16 key_flags = 0; |
| 918 | int ret; |
| 919 | |
| 920 | keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 921 | |
| 922 | key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK); |
| 923 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 924 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 925 | |
| 926 | if (keyconf->keylen == WEP_KEY_LEN_128) |
| 927 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
| 928 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 929 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 930 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 931 | |
| 932 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 933 | |
| 934 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 935 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 936 | priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; |
| 937 | |
| 938 | memcpy(priv->stations[sta_id].keyinfo.key, |
| 939 | keyconf->key, keyconf->keylen); |
| 940 | |
| 941 | memcpy(&priv->stations[sta_id].sta.key.key[3], |
| 942 | keyconf->key, keyconf->keylen); |
| 943 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 944 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 945 | == STA_KEY_FLG_NO_ENC) |
| 946 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 947 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 948 | /* else, we are overriding an existing key => no need to allocated room |
| 949 | * in uCode. */ |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 950 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 951 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Jiri Slaby | e724b8f | 2009-01-05 17:06:06 +0100 | [diff] [blame] | 952 | "no space for a new key"); |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 953 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 954 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 955 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 956 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 957 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 958 | ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 959 | |
| 960 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 961 | |
| 962 | return ret; |
| 963 | } |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 964 | |
| 965 | static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, |
| 966 | struct ieee80211_key_conf *keyconf, |
| 967 | u8 sta_id) |
| 968 | { |
| 969 | unsigned long flags; |
| 970 | __le16 key_flags = 0; |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 971 | int ret; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 972 | |
| 973 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); |
| 974 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 975 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 976 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 977 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 978 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 979 | |
| 980 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 981 | |
| 982 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 983 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 984 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 985 | |
| 986 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 987 | keyconf->keylen); |
| 988 | |
| 989 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 990 | keyconf->keylen); |
| 991 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 992 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 993 | == STA_KEY_FLG_NO_ENC) |
| 994 | priv->stations[sta_id].sta.key.key_offset = |
| 995 | iwl_get_free_ucode_key_index(priv); |
| 996 | /* else, we are overriding an existing key => no need to allocated room |
| 997 | * in uCode. */ |
| 998 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 999 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Jiri Slaby | e724b8f | 2009-01-05 17:06:06 +0100 | [diff] [blame] | 1000 | "no space for a new key"); |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1001 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1002 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1003 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1004 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1005 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1006 | ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 1007 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1008 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1009 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1010 | return ret; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, |
| 1014 | struct ieee80211_key_conf *keyconf, |
| 1015 | u8 sta_id) |
| 1016 | { |
| 1017 | unsigned long flags; |
| 1018 | int ret = 0; |
Reinette Chatre | 299f546 | 2009-04-30 13:56:31 -0700 | [diff] [blame] | 1019 | __le16 key_flags = 0; |
| 1020 | |
| 1021 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 1022 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1023 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1024 | |
| 1025 | if (sta_id == priv->hw_params.bcast_sta_id) |
| 1026 | key_flags |= STA_KEY_MULTICAST_MSK; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1027 | |
| 1028 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1029 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1030 | |
| 1031 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1032 | |
| 1033 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1034 | priv->stations[sta_id].keyinfo.keylen = 16; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1035 | |
| 1036 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
| 1037 | == STA_KEY_FLG_NO_ENC) |
| 1038 | priv->stations[sta_id].sta.key.key_offset = |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 1039 | iwl_get_free_ucode_key_index(priv); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1040 | /* else, we are overriding an existing key => no need to allocated room |
| 1041 | * in uCode. */ |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1042 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1043 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Jiri Slaby | e724b8f | 2009-01-05 17:06:06 +0100 | [diff] [blame] | 1044 | "no space for a new key"); |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1045 | |
Reinette Chatre | 299f546 | 2009-04-30 13:56:31 -0700 | [diff] [blame] | 1046 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1047 | |
| 1048 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1049 | /* This copy is acutally not needed: we get the key with each TX */ |
| 1050 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); |
| 1051 | |
| 1052 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16); |
| 1053 | |
| 1054 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1055 | |
| 1056 | return ret; |
| 1057 | } |
| 1058 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1059 | void iwl_update_tkip_key(struct iwl_priv *priv, |
| 1060 | struct ieee80211_key_conf *keyconf, |
| 1061 | const u8 *addr, u32 iv32, u16 *phase1key) |
| 1062 | { |
| 1063 | u8 sta_id = IWL_INVALID_STATION; |
| 1064 | unsigned long flags; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1065 | int i; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1066 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 1067 | sta_id = iwl_find_station(priv, addr); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1068 | if (sta_id == IWL_INVALID_STATION) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1069 | IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1070 | addr); |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | if (iwl_scan_cancel(priv)) { |
| 1075 | /* cancel scan failed, just live w/ bad key and rely |
| 1076 | briefly on SW decryption */ |
| 1077 | return; |
| 1078 | } |
| 1079 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1080 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1081 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1082 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 1083 | |
| 1084 | for (i = 0; i < 5; i++) |
| 1085 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 1086 | cpu_to_le16(phase1key[i]); |
| 1087 | |
| 1088 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1089 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1090 | |
| 1091 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 1092 | |
| 1093 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1094 | |
| 1095 | } |
| 1096 | EXPORT_SYMBOL(iwl_update_tkip_key); |
| 1097 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1098 | int iwl_remove_dynamic_key(struct iwl_priv *priv, |
| 1099 | struct ieee80211_key_conf *keyconf, |
| 1100 | u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1101 | { |
| 1102 | unsigned long flags; |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1103 | int ret = 0; |
| 1104 | u16 key_flags; |
| 1105 | u8 keyidx; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1106 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1107 | priv->key_mapping_key--; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1108 | |
| 1109 | spin_lock_irqsave(&priv->sta_lock, flags); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1110 | key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); |
| 1111 | keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; |
| 1112 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1113 | IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 1114 | keyconf->keyidx, sta_id); |
| 1115 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1116 | if (keyconf->keyidx != keyidx) { |
| 1117 | /* We need to remove a key with index different that the one |
| 1118 | * in the uCode. This means that the key we need to remove has |
| 1119 | * been replaced by another one with different index. |
| 1120 | * Don't do anything and return ok |
| 1121 | */ |
| 1122 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1126 | if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1127 | IWL_WARN(priv, "Removing wrong key %d 0x%x\n", |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 1128 | keyconf->keyidx, key_flags); |
| 1129 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1133 | if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, |
| 1134 | &priv->ucode_key_table)) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1135 | IWL_ERR(priv, "index %d not used in uCode key table.\n", |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1136 | priv->stations[sta_id].sta.key.key_offset); |
| 1137 | memset(&priv->stations[sta_id].keyinfo, 0, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1138 | sizeof(struct iwl_hw_key)); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1139 | memset(&priv->stations[sta_id].sta.key, 0, |
| 1140 | sizeof(struct iwl4965_keyinfo)); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1141 | priv->stations[sta_id].sta.key.key_flags = |
| 1142 | STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; |
| 1143 | priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1144 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1145 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1146 | |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 1147 | if (iwl_is_rfkill(priv)) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 1148 | IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n"); |
Reinette Chatre | 2d1bb9e | 2009-07-17 09:30:18 -0700 | [diff] [blame] | 1149 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1150 | return 0; |
| 1151 | } |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1152 | ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 1153 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1154 | return ret; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1155 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 1156 | EXPORT_SYMBOL(iwl_remove_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1157 | |
| 1158 | int iwl_set_dynamic_key(struct iwl_priv *priv, |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1159 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1160 | { |
| 1161 | int ret; |
| 1162 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1163 | priv->key_mapping_key++; |
| 1164 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1165 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1166 | switch (keyconf->alg) { |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1167 | case ALG_CCMP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1168 | ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1169 | break; |
| 1170 | case ALG_TKIP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1171 | ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1172 | break; |
| 1173 | case ALG_WEP: |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 1174 | ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1175 | break; |
| 1176 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1177 | IWL_ERR(priv, |
| 1178 | "Unknown alg: %s alg = %d\n", __func__, keyconf->alg); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1179 | ret = -EINVAL; |
| 1180 | } |
| 1181 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1182 | IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", |
Emmanuel Grumbach | 4564ce8 | 2008-06-12 09:47:09 +0800 | [diff] [blame] | 1183 | keyconf->alg, keyconf->keylen, keyconf->keyidx, |
| 1184 | sta_id, ret); |
| 1185 | |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1186 | return ret; |
| 1187 | } |
Tomas Winkler | 27aaba0 | 2008-05-05 10:22:44 +0800 | [diff] [blame] | 1188 | EXPORT_SYMBOL(iwl_set_dynamic_key); |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 1189 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1190 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1191 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 1192 | struct iwl_link_quality_cmd *lq) |
| 1193 | { |
| 1194 | int i; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1195 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); |
| 1196 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1197 | lq->general_params.single_stream_ant_msk, |
| 1198 | lq->general_params.dual_stream_ant_msk); |
| 1199 | |
| 1200 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1201 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1202 | i, lq->rs_table[i].rate_n_flags); |
| 1203 | } |
| 1204 | #else |
| 1205 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 1206 | struct iwl_link_quality_cmd *lq) |
| 1207 | { |
| 1208 | } |
| 1209 | #endif |
| 1210 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1211 | /** |
| 1212 | * iwl_send_lq_cmd() - Send link quality command |
| 1213 | * @init: This command is sent as part of station initialization right |
| 1214 | * after station has been added. |
| 1215 | * |
| 1216 | * The link quality command is sent as the last step of station creation. |
| 1217 | * This is the special case in which init is set and we call a callback in |
| 1218 | * this case to clear the state indicating that station creation is in |
| 1219 | * progress. |
| 1220 | */ |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1221 | int iwl_send_lq_cmd(struct iwl_priv *priv, |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1222 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1223 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1224 | int ret = 0; |
| 1225 | unsigned long flags_spin; |
| 1226 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1227 | struct iwl_host_cmd cmd = { |
| 1228 | .id = REPLY_TX_LINK_QUALITY_CMD, |
| 1229 | .len = sizeof(struct iwl_link_quality_cmd), |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 1230 | .flags = flags, |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1231 | .data = lq, |
| 1232 | }; |
| 1233 | |
Johannes Berg | 76c3c69 | 2010-03-30 02:46:29 -0700 | [diff] [blame] | 1234 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1235 | return -EINVAL; |
| 1236 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 1237 | iwl_dump_lq_cmd(priv, lq); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1238 | BUG_ON(init && (cmd.flags & CMD_ASYNC)); |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1239 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1240 | ret = iwl_send_cmd(priv, &cmd); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1241 | |
| 1242 | if (cmd.flags & CMD_ASYNC) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1243 | return ret; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1244 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1245 | if (init) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 1246 | IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n", |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1247 | lq->sta_id); |
| 1248 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 1249 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 1250 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 1251 | } |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1252 | return ret; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 1253 | } |
| 1254 | EXPORT_SYMBOL(iwl_send_lq_cmd); |
| 1255 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1256 | /** |
Reinette Chatre | 9a9ca65 | 2009-10-30 14:36:12 -0700 | [diff] [blame] | 1257 | * iwl_add_bcast_station - add broadcast station into station table. |
| 1258 | */ |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1259 | int iwl_add_bcast_station(struct iwl_priv *priv) |
Reinette Chatre | 9a9ca65 | 2009-10-30 14:36:12 -0700 | [diff] [blame] | 1260 | { |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1261 | IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n"); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1262 | return iwl_add_local_station(priv, iwl_bcast_addr, true); |
Reinette Chatre | 9a9ca65 | 2009-10-30 14:36:12 -0700 | [diff] [blame] | 1263 | } |
| 1264 | EXPORT_SYMBOL(iwl_add_bcast_station); |
| 1265 | |
| 1266 | /** |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1267 | * iwl3945_add_bcast_station - add broadcast station into station table. |
| 1268 | */ |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1269 | int iwl3945_add_bcast_station(struct iwl_priv *priv) |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1270 | { |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1271 | int ret; |
| 1272 | |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1273 | IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n"); |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1274 | ret = iwl_add_local_station(priv, iwl_bcast_addr, false); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1275 | /* |
| 1276 | * It is assumed that when station is added more initialization |
| 1277 | * needs to be done, but for 3945 it is not the case and we can |
| 1278 | * just release station table access right here. |
| 1279 | */ |
| 1280 | priv->stations[priv->hw_params.bcast_sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 1281 | return ret; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1282 | |
Reinette Chatre | 3459ab5 | 2010-01-22 14:22:49 -0800 | [diff] [blame] | 1283 | } |
| 1284 | EXPORT_SYMBOL(iwl3945_add_bcast_station); |
| 1285 | |
| 1286 | /** |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1287 | * iwl_get_sta_id - Find station's index within station table |
| 1288 | * |
| 1289 | * If new IBSS station, create new entry in station table |
| 1290 | */ |
| 1291 | int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) |
| 1292 | { |
| 1293 | int sta_id; |
Luis R. Rodriguez | 943ab70 | 2009-07-14 20:14:07 -0400 | [diff] [blame] | 1294 | __le16 fc = hdr->frame_control; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1295 | |
| 1296 | /* If this frame is broadcast or management, use broadcast station id */ |
Luis R. Rodriguez | 943ab70 | 2009-07-14 20:14:07 -0400 | [diff] [blame] | 1297 | if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1298 | return priv->hw_params.bcast_sta_id; |
| 1299 | |
| 1300 | switch (priv->iw_mode) { |
| 1301 | |
| 1302 | /* If we are a client station in a BSS network, use the special |
| 1303 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1304 | case NL80211_IFTYPE_STATION: |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1305 | /* |
| 1306 | * If addition of station not complete yet, which means |
| 1307 | * that rate scaling has not been initialized, then return |
| 1308 | * the broadcast station. |
| 1309 | */ |
| 1310 | if (!(priv->stations[IWL_AP_ID].used & IWL_STA_UCODE_ACTIVE)) |
| 1311 | return priv->hw_params.bcast_sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1312 | return IWL_AP_ID; |
| 1313 | |
| 1314 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1315 | case NL80211_IFTYPE_AP: |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 1316 | sta_id = iwl_find_station(priv, hdr->addr1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1317 | if (sta_id != IWL_INVALID_STATION) |
| 1318 | return sta_id; |
| 1319 | return priv->hw_params.bcast_sta_id; |
| 1320 | |
| 1321 | /* If this frame is going out to an IBSS network, find the station, |
| 1322 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1323 | case NL80211_IFTYPE_ADHOC: |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 1324 | sta_id = iwl_find_station(priv, hdr->addr1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1325 | if (sta_id != IWL_INVALID_STATION) |
| 1326 | return sta_id; |
| 1327 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1328 | IWL_DEBUG_DROP(priv, "Station %pM not in station map. " |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1329 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1330 | hdr->addr1); |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1331 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1332 | return priv->hw_params.bcast_sta_id; |
| 1333 | |
| 1334 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1335 | IWL_WARN(priv, "Unknown mode of operation: %d\n", |
| 1336 | priv->iw_mode); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1337 | return priv->hw_params.bcast_sta_id; |
| 1338 | } |
| 1339 | } |
| 1340 | EXPORT_SYMBOL(iwl_get_sta_id); |
| 1341 | |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 1342 | /** |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1343 | * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 1344 | */ |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1345 | void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid) |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 1346 | { |
| 1347 | unsigned long flags; |
| 1348 | |
| 1349 | /* Remove "disable" flag, to enable Tx for this TID */ |
| 1350 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1351 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 1352 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 1353 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1354 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1355 | |
| 1356 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 1357 | } |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1358 | EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid); |
| 1359 | |
| 1360 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, |
| 1361 | const u8 *addr, int tid, u16 ssn) |
| 1362 | { |
| 1363 | unsigned long flags; |
| 1364 | int sta_id; |
| 1365 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 1366 | sta_id = iwl_find_station(priv, addr); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1367 | if (sta_id == IWL_INVALID_STATION) |
| 1368 | return -ENXIO; |
| 1369 | |
| 1370 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1371 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 1372 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; |
| 1373 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; |
| 1374 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 1375 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1376 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1377 | |
| 1378 | return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, |
| 1379 | CMD_ASYNC); |
| 1380 | } |
| 1381 | EXPORT_SYMBOL(iwl_sta_rx_agg_start); |
| 1382 | |
| 1383 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid) |
| 1384 | { |
| 1385 | unsigned long flags; |
| 1386 | int sta_id; |
| 1387 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 1388 | sta_id = iwl_find_station(priv, addr); |
Wey-Yi Guy | a2f1cbe | 2009-03-17 21:51:52 -0700 | [diff] [blame] | 1389 | if (sta_id == IWL_INVALID_STATION) { |
| 1390 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1391 | return -ENXIO; |
Wey-Yi Guy | a2f1cbe | 2009-03-17 21:51:52 -0700 | [diff] [blame] | 1392 | } |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1393 | |
| 1394 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1395 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 1396 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; |
| 1397 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; |
| 1398 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1399 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1400 | |
| 1401 | return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, |
| 1402 | CMD_ASYNC); |
| 1403 | } |
| 1404 | EXPORT_SYMBOL(iwl_sta_rx_agg_stop); |
| 1405 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1406 | void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1407 | { |
| 1408 | unsigned long flags; |
| 1409 | |
| 1410 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1411 | priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK; |
| 1412 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 1413 | priv->stations[sta_id].sta.sta.modify_mask = 0; |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1414 | priv->stations[sta_id].sta.sleep_tx_count = 0; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1415 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1416 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1417 | |
| 1418 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 1419 | } |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1420 | EXPORT_SYMBOL(iwl_sta_modify_ps_wake); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1421 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1422 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt) |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1423 | { |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1424 | unsigned long flags; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1425 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1426 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1427 | priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK; |
| 1428 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 1429 | priv->stations[sta_id].sta.sta.modify_mask = |
| 1430 | STA_MODIFY_SLEEP_TX_COUNT_MSK; |
| 1431 | priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt); |
| 1432 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1433 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1434 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 1435 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 1436 | } |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 1437 | EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1438 | |
| 1439 | int iwl_mac_sta_remove(struct ieee80211_hw *hw, |
| 1440 | struct ieee80211_vif *vif, |
| 1441 | struct ieee80211_sta *sta) |
| 1442 | { |
| 1443 | int ret; |
| 1444 | struct iwl_priv *priv = hw->priv; |
| 1445 | IWL_DEBUG_INFO(priv, "received request to remove station %pM\n", |
| 1446 | sta->addr); |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 1447 | ret = iwl_remove_station(priv, sta->addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 1448 | if (ret) |
| 1449 | IWL_ERR(priv, "Error removing station %pM\n", |
| 1450 | sta->addr); |
| 1451 | return ret; |
| 1452 | } |
| 1453 | EXPORT_SYMBOL(iwl_mac_sta_remove); |