Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Johannes Berg | 128e63e | 2013-01-21 21:39:26 +0100 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2013 Intel Corporation. All rights reserved. |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [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: |
| 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
Johannes Berg | e7a0d0c | 2012-03-06 13:31:07 -0800 | [diff] [blame] | 29 | #include <linux/etherdevice.h> |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 30 | #include <net/mac80211.h> |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 31 | #include "iwl-trans.h" |
Johannes Berg | 1023fdc | 2012-05-15 12:16:34 +0200 | [diff] [blame] | 32 | #include "dev.h" |
| 33 | #include "agn.h" |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 34 | |
Meenakshi Venkataraman | f32cadf | 2012-03-14 15:59:15 -0700 | [diff] [blame] | 35 | const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 36 | |
Wey-Yi Guy | 2da424b | 2012-01-06 13:16:28 -0800 | [diff] [blame] | 37 | static int iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 38 | { |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 39 | lockdep_assert_held(&priv->sta_lock); |
| 40 | |
Wey-Yi Guy | 2da424b | 2012-01-06 13:16:28 -0800 | [diff] [blame] | 41 | if (sta_id >= IWLAGN_STATION_COUNT) { |
| 42 | IWL_ERR(priv, "invalid sta_id %u", sta_id); |
| 43 | return -EINVAL; |
| 44 | } |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 45 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) |
| 46 | IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u " |
| 47 | "addr %pM\n", |
| 48 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 49 | |
| 50 | if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) { |
| 51 | IWL_DEBUG_ASSOC(priv, |
| 52 | "STA id %u addr %pM already present in uCode " |
| 53 | "(according to driver)\n", |
| 54 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 55 | } else { |
| 56 | priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE; |
| 57 | IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n", |
| 58 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 59 | } |
Wey-Yi Guy | 2da424b | 2012-01-06 13:16:28 -0800 | [diff] [blame] | 60 | return 0; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int iwl_process_add_sta_resp(struct iwl_priv *priv, |
| 64 | struct iwl_addsta_cmd *addsta, |
| 65 | struct iwl_rx_packet *pkt) |
| 66 | { |
Johannes Berg | f8d7c1a | 2012-03-06 13:31:02 -0800 | [diff] [blame] | 67 | struct iwl_add_sta_resp *add_sta_resp = (void *)pkt->data; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 68 | u8 sta_id = addsta->sta.sta_id; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 69 | int ret = -EIO; |
| 70 | |
| 71 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 72 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 73 | pkt->hdr.flags); |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", |
| 78 | sta_id); |
| 79 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 80 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 81 | |
Johannes Berg | f8d7c1a | 2012-03-06 13:31:02 -0800 | [diff] [blame] | 82 | switch (add_sta_resp->status) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 83 | case ADD_STA_SUCCESS_MSK: |
| 84 | IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n"); |
Wey-Yi Guy | 2da424b | 2012-01-06 13:16:28 -0800 | [diff] [blame] | 85 | ret = iwl_sta_ucode_activate(priv, sta_id); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 86 | break; |
| 87 | case ADD_STA_NO_ROOM_IN_TABLE: |
| 88 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", |
| 89 | sta_id); |
| 90 | break; |
| 91 | case ADD_STA_NO_BLOCK_ACK_RESOURCE: |
| 92 | IWL_ERR(priv, "Adding station %d failed, no block ack " |
| 93 | "resource.\n", sta_id); |
| 94 | break; |
| 95 | case ADD_STA_MODIFY_NON_EXIST_STA: |
| 96 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", |
| 97 | sta_id); |
| 98 | break; |
| 99 | default: |
| 100 | IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n", |
Johannes Berg | f8d7c1a | 2012-03-06 13:31:02 -0800 | [diff] [blame] | 101 | add_sta_resp->status); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 102 | break; |
| 103 | } |
| 104 | |
| 105 | IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n", |
| 106 | priv->stations[sta_id].sta.mode == |
| 107 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 108 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 109 | |
| 110 | /* |
| 111 | * XXX: The MAC address in the command buffer is often changed from |
| 112 | * the original sent to the device. That is, the MAC address |
| 113 | * written to the command buffer often is not the same MAC address |
| 114 | * read from the command buffer when the command returns. This |
| 115 | * issue has not yet been resolved and this debugging is left to |
| 116 | * observe the problem. |
| 117 | */ |
| 118 | IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n", |
| 119 | priv->stations[sta_id].sta.mode == |
| 120 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 121 | addsta->sta.addr); |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 122 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 123 | |
| 124 | return ret; |
| 125 | } |
| 126 | |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 127 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 128 | struct iwl_device_cmd *cmd) |
| 129 | { |
| 130 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 131 | |
Johannes Berg | 513aa3b0d | 2012-09-20 16:06:14 +0200 | [diff] [blame] | 132 | if (!cmd) |
| 133 | return 0; |
| 134 | |
| 135 | return iwl_process_add_sta_resp(priv, (void *)cmd->payload, pkt); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 138 | int iwl_send_add_sta(struct iwl_priv *priv, |
| 139 | struct iwl_addsta_cmd *sta, u8 flags) |
| 140 | { |
| 141 | int ret = 0; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 142 | struct iwl_host_cmd cmd = { |
| 143 | .id = REPLY_ADD_STA, |
| 144 | .flags = flags, |
Johannes Berg | 69b172f | 2011-12-12 04:17:44 -0800 | [diff] [blame] | 145 | .data = { sta, }, |
| 146 | .len = { sizeof(*sta), }, |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 147 | }; |
| 148 | u8 sta_id __maybe_unused = sta->sta.sta_id; |
| 149 | |
| 150 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", |
| 151 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); |
| 152 | |
| 153 | if (!(flags & CMD_ASYNC)) { |
Emmanuel Grumbach | 9679142 | 2012-07-24 01:58:32 +0300 | [diff] [blame] | 154 | cmd.flags |= CMD_WANT_SKB | CMD_WANT_HCMD; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 155 | might_sleep(); |
| 156 | } |
| 157 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 158 | ret = iwl_dvm_send_cmd(priv, &cmd); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 159 | |
| 160 | if (ret || (flags & CMD_ASYNC)) |
| 161 | return ret; |
| 162 | /*else the command was successfully sent in SYNC mode, need to free |
| 163 | * the reply page */ |
| 164 | |
Johannes Berg | 65b94a4 | 2012-03-05 11:24:38 -0800 | [diff] [blame] | 165 | iwl_free_resp(&cmd); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 166 | |
| 167 | if (cmd.handler_status) |
| 168 | IWL_ERR(priv, "%s - error in the CMD response %d", __func__, |
| 169 | cmd.handler_status); |
| 170 | |
| 171 | return cmd.handler_status; |
| 172 | } |
| 173 | |
Meenakshi Venkataraman | 5edc565d6 | 2012-03-13 16:15:09 -0700 | [diff] [blame] | 174 | bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv, |
| 175 | struct iwl_rxon_context *ctx, |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 176 | struct ieee80211_sta *sta) |
Meenakshi Venkataraman | 5edc565d6 | 2012-03-13 16:15:09 -0700 | [diff] [blame] | 177 | { |
| 178 | if (!ctx->ht.enabled || !ctx->ht.is_40mhz) |
| 179 | return false; |
| 180 | |
Meenakshi Venkataraman | 5edc565d6 | 2012-03-13 16:15:09 -0700 | [diff] [blame] | 181 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 182 | if (priv->disable_ht40) |
| 183 | return false; |
| 184 | #endif |
| 185 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 186 | /* special case for RXON */ |
| 187 | if (!sta) |
Johannes Berg | 26a7ca9 | 2012-05-21 11:55:54 +0200 | [diff] [blame] | 188 | return true; |
| 189 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 190 | return sta->bandwidth >= IEEE80211_STA_RX_BW_40; |
Meenakshi Venkataraman | 5edc565d6 | 2012-03-13 16:15:09 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 193 | static void iwl_sta_calc_ht_flags(struct iwl_priv *priv, |
| 194 | struct ieee80211_sta *sta, |
| 195 | struct iwl_rxon_context *ctx, |
| 196 | __le32 *flags, __le32 *mask) |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 197 | { |
| 198 | struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 199 | |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 200 | *mask = STA_FLG_RTS_MIMO_PROT_MSK | |
| 201 | STA_FLG_MIMO_DIS_MSK | |
| 202 | STA_FLG_HT40_EN_MSK | |
| 203 | STA_FLG_MAX_AGG_SIZE_MSK | |
| 204 | STA_FLG_AGG_MPDU_DENSITY_MSK; |
| 205 | *flags = 0; |
| 206 | |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 207 | if (!sta || !sta_ht_inf->ht_supported) |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 208 | return; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 209 | |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 210 | IWL_DEBUG_INFO(priv, "STA %pM SM PS mode: %s\n", |
Meenakshi Venkataraman | a35e270 | 2012-05-16 22:40:50 +0200 | [diff] [blame] | 211 | sta->addr, |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 212 | (sta->smps_mode == IEEE80211_SMPS_STATIC) ? |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 213 | "static" : |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 214 | (sta->smps_mode == IEEE80211_SMPS_DYNAMIC) ? |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 215 | "dynamic" : "disabled"); |
| 216 | |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 217 | switch (sta->smps_mode) { |
| 218 | case IEEE80211_SMPS_STATIC: |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 219 | *flags |= STA_FLG_MIMO_DIS_MSK; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 220 | break; |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 221 | case IEEE80211_SMPS_DYNAMIC: |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 222 | *flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 223 | break; |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 224 | case IEEE80211_SMPS_OFF: |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 225 | break; |
| 226 | default: |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 227 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", sta->smps_mode); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 228 | break; |
| 229 | } |
| 230 | |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 231 | *flags |= cpu_to_le32( |
| 232 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 233 | |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 234 | *flags |= cpu_to_le32( |
| 235 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 236 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 237 | if (iwl_is_ht40_tx_allowed(priv, ctx, sta)) |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 238 | *flags |= STA_FLG_HT40_EN_MSK; |
| 239 | } |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 240 | |
Johannes Berg | ab0bd5b | 2012-03-05 11:24:47 -0800 | [diff] [blame] | 241 | int iwl_sta_update_ht(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 242 | struct ieee80211_sta *sta) |
| 243 | { |
| 244 | u8 sta_id = iwl_sta_id(sta); |
| 245 | __le32 flags, mask; |
| 246 | struct iwl_addsta_cmd cmd; |
| 247 | |
| 248 | if (WARN_ON_ONCE(sta_id == IWL_INVALID_STATION)) |
| 249 | return -EINVAL; |
| 250 | |
| 251 | iwl_sta_calc_ht_flags(priv, sta, ctx, &flags, &mask); |
| 252 | |
| 253 | spin_lock_bh(&priv->sta_lock); |
| 254 | priv->stations[sta_id].sta.station_flags &= ~mask; |
| 255 | priv->stations[sta_id].sta.station_flags |= flags; |
| 256 | spin_unlock_bh(&priv->sta_lock); |
| 257 | |
| 258 | memset(&cmd, 0, sizeof(cmd)); |
| 259 | cmd.mode = STA_CONTROL_MODIFY_MSK; |
| 260 | cmd.station_flags_msk = mask; |
| 261 | cmd.station_flags = flags; |
| 262 | cmd.sta.sta_id = sta_id; |
| 263 | |
| 264 | return iwl_send_add_sta(priv, &cmd, CMD_SYNC); |
| 265 | } |
| 266 | |
| 267 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
| 268 | struct ieee80211_sta *sta, |
| 269 | struct iwl_rxon_context *ctx) |
| 270 | { |
| 271 | __le32 flags, mask; |
| 272 | |
| 273 | iwl_sta_calc_ht_flags(priv, sta, ctx, &flags, &mask); |
| 274 | |
| 275 | lockdep_assert_held(&priv->sta_lock); |
| 276 | priv->stations[index].sta.station_flags &= ~mask; |
| 277 | priv->stations[index].sta.station_flags |= flags; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
| 281 | * iwl_prep_station - Prepare station information for addition |
| 282 | * |
| 283 | * should be called with sta_lock held |
| 284 | */ |
| 285 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 286 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta) |
| 287 | { |
| 288 | struct iwl_station_entry *station; |
| 289 | int i; |
| 290 | u8 sta_id = IWL_INVALID_STATION; |
| 291 | |
| 292 | if (is_ap) |
| 293 | sta_id = ctx->ap_sta_id; |
| 294 | else if (is_broadcast_ether_addr(addr)) |
| 295 | sta_id = ctx->bcast_sta_id; |
| 296 | else |
| 297 | for (i = IWL_STA_ID; i < IWLAGN_STATION_COUNT; i++) { |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 298 | if (ether_addr_equal(priv->stations[i].sta.sta.addr, |
| 299 | addr)) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 300 | sta_id = i; |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | if (!priv->stations[i].used && |
| 305 | sta_id == IWL_INVALID_STATION) |
| 306 | sta_id = i; |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * These two conditions have the same outcome, but keep them |
| 311 | * separate |
| 312 | */ |
| 313 | if (unlikely(sta_id == IWL_INVALID_STATION)) |
| 314 | return sta_id; |
| 315 | |
| 316 | /* |
| 317 | * uCode is not able to deal with multiple requests to add a |
| 318 | * station. Keep track if one is in progress so that we do not send |
| 319 | * another. |
| 320 | */ |
| 321 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 322 | IWL_DEBUG_INFO(priv, "STA %d already in process of being " |
| 323 | "added.\n", sta_id); |
| 324 | return sta_id; |
| 325 | } |
| 326 | |
| 327 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 328 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 329 | ether_addr_equal(priv->stations[sta_id].sta.sta.addr, addr)) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 330 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not " |
| 331 | "adding again.\n", sta_id, addr); |
| 332 | return sta_id; |
| 333 | } |
| 334 | |
| 335 | station = &priv->stations[sta_id]; |
| 336 | station->used = IWL_STA_DRIVER_ACTIVE; |
| 337 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", |
| 338 | sta_id, addr); |
| 339 | priv->num_stations++; |
| 340 | |
| 341 | /* Set up the REPLY_ADD_STA command to send to device */ |
| 342 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
| 343 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 344 | station->sta.mode = 0; |
| 345 | station->sta.sta.sta_id = sta_id; |
| 346 | station->sta.station_flags = ctx->station_flags; |
| 347 | station->ctxid = ctx->ctxid; |
| 348 | |
| 349 | if (sta) { |
| 350 | struct iwl_station_priv *sta_priv; |
| 351 | |
| 352 | sta_priv = (void *)sta->drv_priv; |
| 353 | sta_priv->ctx = ctx; |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * OK to call unconditionally, since local stations (IBSS BSSID |
| 358 | * STA and broadcast STA) pass in a NULL sta, and mac80211 |
| 359 | * doesn't allow HT IBSS. |
| 360 | */ |
| 361 | iwl_set_ht_add_station(priv, sta_id, sta, ctx); |
| 362 | |
| 363 | return sta_id; |
| 364 | |
| 365 | } |
| 366 | |
| 367 | #define STA_WAIT_TIMEOUT (HZ/2) |
| 368 | |
| 369 | /** |
| 370 | * iwl_add_station_common - |
| 371 | */ |
| 372 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 373 | const u8 *addr, bool is_ap, |
| 374 | struct ieee80211_sta *sta, u8 *sta_id_r) |
| 375 | { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 376 | int ret = 0; |
| 377 | u8 sta_id; |
| 378 | struct iwl_addsta_cmd sta_cmd; |
| 379 | |
| 380 | *sta_id_r = 0; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 381 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 382 | sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta); |
| 383 | if (sta_id == IWL_INVALID_STATION) { |
| 384 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", |
| 385 | addr); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 386 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 387 | return -EINVAL; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * uCode is not able to deal with multiple requests to add a |
| 392 | * station. Keep track if one is in progress so that we do not send |
| 393 | * another. |
| 394 | */ |
| 395 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 396 | IWL_DEBUG_INFO(priv, "STA %d already in process of being " |
| 397 | "added.\n", sta_id); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 398 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 399 | return -EEXIST; |
| 400 | } |
| 401 | |
| 402 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 403 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
| 404 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not " |
| 405 | "adding again.\n", sta_id, addr); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 406 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 407 | return -EEXIST; |
| 408 | } |
| 409 | |
| 410 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; |
| 411 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, |
| 412 | sizeof(struct iwl_addsta_cmd)); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 413 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 414 | |
| 415 | /* Add station to device's station table */ |
| 416 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 417 | if (ret) { |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 418 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 419 | IWL_ERR(priv, "Adding station %pM failed.\n", |
| 420 | priv->stations[sta_id].sta.sta.addr); |
| 421 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 422 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 423 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 424 | } |
| 425 | *sta_id_r = sta_id; |
| 426 | return ret; |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 431 | */ |
| 432 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) |
| 433 | { |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 434 | lockdep_assert_held(&priv->sta_lock); |
| 435 | |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 436 | /* Ucode must be active and driver must be non active */ |
| 437 | if ((priv->stations[sta_id].used & |
| 438 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != |
| 439 | IWL_STA_UCODE_ACTIVE) |
| 440 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); |
| 441 | |
| 442 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; |
| 443 | |
| 444 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); |
| 445 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); |
| 446 | } |
| 447 | |
| 448 | static int iwl_send_remove_station(struct iwl_priv *priv, |
| 449 | const u8 *addr, int sta_id, |
| 450 | bool temporary) |
| 451 | { |
| 452 | struct iwl_rx_packet *pkt; |
| 453 | int ret; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 454 | struct iwl_rem_sta_cmd rm_sta_cmd; |
| 455 | |
| 456 | struct iwl_host_cmd cmd = { |
| 457 | .id = REPLY_REMOVE_STA, |
| 458 | .len = { sizeof(struct iwl_rem_sta_cmd), }, |
| 459 | .flags = CMD_SYNC, |
| 460 | .data = { &rm_sta_cmd, }, |
| 461 | }; |
| 462 | |
| 463 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); |
| 464 | rm_sta_cmd.num_sta = 1; |
| 465 | memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN); |
| 466 | |
| 467 | cmd.flags |= CMD_WANT_SKB; |
| 468 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 469 | ret = iwl_dvm_send_cmd(priv, &cmd); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 470 | |
| 471 | if (ret) |
| 472 | return ret; |
| 473 | |
Johannes Berg | 65b94a4 | 2012-03-05 11:24:38 -0800 | [diff] [blame] | 474 | pkt = cmd.resp_pkt; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 475 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 476 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", |
| 477 | pkt->hdr.flags); |
| 478 | ret = -EIO; |
| 479 | } |
| 480 | |
| 481 | if (!ret) { |
Johannes Berg | f8d7c1a | 2012-03-06 13:31:02 -0800 | [diff] [blame] | 482 | struct iwl_rem_sta_resp *rem_sta_resp = (void *)pkt->data; |
| 483 | switch (rem_sta_resp->status) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 484 | case REM_STA_SUCCESS_MSK: |
| 485 | if (!temporary) { |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 486 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 487 | iwl_sta_ucode_deactivate(priv, sta_id); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 488 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 489 | } |
| 490 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); |
| 491 | break; |
| 492 | default: |
| 493 | ret = -EIO; |
| 494 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); |
| 495 | break; |
| 496 | } |
| 497 | } |
Johannes Berg | 65b94a4 | 2012-03-05 11:24:38 -0800 | [diff] [blame] | 498 | iwl_free_resp(&cmd); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 499 | |
| 500 | return ret; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * iwl_remove_station - Remove driver's knowledge of station. |
| 505 | */ |
| 506 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, |
| 507 | const u8 *addr) |
| 508 | { |
Emmanuel Grumbach | 855c2ee | 2011-11-23 11:37:27 +0200 | [diff] [blame] | 509 | u8 tid; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 510 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 511 | if (!iwl_is_ready(priv)) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 512 | IWL_DEBUG_INFO(priv, |
| 513 | "Unable to remove station %pM, device not ready.\n", |
| 514 | addr); |
| 515 | /* |
| 516 | * It is typical for stations to be removed when we are |
| 517 | * going down. Return success since device will be down |
| 518 | * soon anyway |
| 519 | */ |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", |
| 524 | sta_id, addr); |
| 525 | |
| 526 | if (WARN_ON(sta_id == IWL_INVALID_STATION)) |
| 527 | return -EINVAL; |
| 528 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 529 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 530 | |
| 531 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
| 532 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", |
| 533 | addr); |
| 534 | goto out_err; |
| 535 | } |
| 536 | |
| 537 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
| 538 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", |
| 539 | addr); |
| 540 | goto out_err; |
| 541 | } |
| 542 | |
| 543 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { |
| 544 | kfree(priv->stations[sta_id].lq); |
| 545 | priv->stations[sta_id].lq = NULL; |
| 546 | } |
| 547 | |
Emmanuel Grumbach | 855c2ee | 2011-11-23 11:37:27 +0200 | [diff] [blame] | 548 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) |
| 549 | memset(&priv->tid_data[sta_id][tid], 0, |
| 550 | sizeof(priv->tid_data[sta_id][tid])); |
| 551 | |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 552 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 553 | |
| 554 | priv->num_stations--; |
| 555 | |
| 556 | if (WARN_ON(priv->num_stations < 0)) |
| 557 | priv->num_stations = 0; |
| 558 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 559 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 560 | |
| 561 | return iwl_send_remove_station(priv, addr, sta_id, false); |
| 562 | out_err: |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 563 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 564 | return -EINVAL; |
| 565 | } |
| 566 | |
Johannes Berg | 9742051 | 2012-03-07 09:52:42 -0800 | [diff] [blame] | 567 | void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id, |
| 568 | const u8 *addr) |
| 569 | { |
| 570 | u8 tid; |
| 571 | |
| 572 | if (!iwl_is_ready(priv)) { |
| 573 | IWL_DEBUG_INFO(priv, |
| 574 | "Unable to remove station %pM, device not ready.\n", |
| 575 | addr); |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | IWL_DEBUG_ASSOC(priv, "Deactivating STA: %pM (%d)\n", addr, sta_id); |
| 580 | |
| 581 | if (WARN_ON_ONCE(sta_id == IWL_INVALID_STATION)) |
| 582 | return; |
| 583 | |
| 584 | spin_lock_bh(&priv->sta_lock); |
| 585 | |
| 586 | WARN_ON_ONCE(!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)); |
| 587 | |
| 588 | for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) |
| 589 | memset(&priv->tid_data[sta_id][tid], 0, |
| 590 | sizeof(priv->tid_data[sta_id][tid])); |
| 591 | |
| 592 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 593 | |
| 594 | priv->num_stations--; |
| 595 | |
| 596 | if (WARN_ON_ONCE(priv->num_stations < 0)) |
| 597 | priv->num_stations = 0; |
| 598 | |
| 599 | spin_unlock_bh(&priv->sta_lock); |
| 600 | } |
| 601 | |
Johannes Berg | 4dcba6d | 2012-03-08 10:19:55 +0100 | [diff] [blame] | 602 | static void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 603 | u8 sta_id, struct iwl_link_quality_cmd *link_cmd) |
| 604 | { |
| 605 | int i, r; |
| 606 | u32 rate_flags = 0; |
| 607 | __le32 rate_n_flags; |
| 608 | |
| 609 | lockdep_assert_held(&priv->mutex); |
| 610 | |
| 611 | memset(link_cmd, 0, sizeof(*link_cmd)); |
| 612 | |
| 613 | /* Set up the rate scaling to start at selected rate, fall back |
| 614 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
| 615 | if (priv->band == IEEE80211_BAND_5GHZ) |
| 616 | r = IWL_RATE_6M_INDEX; |
| 617 | else if (ctx && ctx->vif && ctx->vif->p2p) |
| 618 | r = IWL_RATE_6M_INDEX; |
| 619 | else |
| 620 | r = IWL_RATE_1M_INDEX; |
| 621 | |
| 622 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) |
| 623 | rate_flags |= RATE_MCS_CCK_MSK; |
| 624 | |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 625 | rate_flags |= first_antenna(priv->nvm_data->valid_tx_ant) << |
Johannes Berg | 4dcba6d | 2012-03-08 10:19:55 +0100 | [diff] [blame] | 626 | RATE_MCS_ANT_POS; |
| 627 | rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); |
| 628 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
| 629 | link_cmd->rs_table[i].rate_n_flags = rate_n_flags; |
| 630 | |
| 631 | link_cmd->general_params.single_stream_ant_msk = |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 632 | first_antenna(priv->nvm_data->valid_tx_ant); |
Johannes Berg | 4dcba6d | 2012-03-08 10:19:55 +0100 | [diff] [blame] | 633 | |
| 634 | link_cmd->general_params.dual_stream_ant_msk = |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 635 | priv->nvm_data->valid_tx_ant & |
| 636 | ~first_antenna(priv->nvm_data->valid_tx_ant); |
Johannes Berg | 4dcba6d | 2012-03-08 10:19:55 +0100 | [diff] [blame] | 637 | if (!link_cmd->general_params.dual_stream_ant_msk) { |
| 638 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 639 | } else if (num_of_ant(priv->nvm_data->valid_tx_ant) == 2) { |
Johannes Berg | 4dcba6d | 2012-03-08 10:19:55 +0100 | [diff] [blame] | 640 | link_cmd->general_params.dual_stream_ant_msk = |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 641 | priv->nvm_data->valid_tx_ant; |
Johannes Berg | 4dcba6d | 2012-03-08 10:19:55 +0100 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | link_cmd->agg_params.agg_dis_start_th = |
| 645 | LINK_QUAL_AGG_DISABLE_START_DEF; |
| 646 | link_cmd->agg_params.agg_time_limit = |
| 647 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
| 648 | |
| 649 | link_cmd->sta_id = sta_id; |
| 650 | } |
| 651 | |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 652 | /** |
| 653 | * iwl_clear_ucode_stations - clear ucode station table bits |
| 654 | * |
| 655 | * This function clears all the bits in the driver indicating |
| 656 | * which stations are active in the ucode. Call when something |
| 657 | * other than explicit station management would cause this in |
| 658 | * the ucode, e.g. unassociated RXON. |
| 659 | */ |
| 660 | void iwl_clear_ucode_stations(struct iwl_priv *priv, |
| 661 | struct iwl_rxon_context *ctx) |
| 662 | { |
| 663 | int i; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 664 | bool cleared = false; |
| 665 | |
| 666 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n"); |
| 667 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 668 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 669 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { |
| 670 | if (ctx && ctx->ctxid != priv->stations[i].ctxid) |
| 671 | continue; |
| 672 | |
| 673 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { |
| 674 | IWL_DEBUG_INFO(priv, |
| 675 | "Clearing ucode active for station %d\n", i); |
| 676 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
| 677 | cleared = true; |
| 678 | } |
| 679 | } |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 680 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 681 | |
| 682 | if (!cleared) |
| 683 | IWL_DEBUG_INFO(priv, |
| 684 | "No active stations found to be cleared\n"); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * iwl_restore_stations() - Restore driver known stations to device |
| 689 | * |
| 690 | * All stations considered active by driver, but not present in ucode, is |
| 691 | * restored. |
| 692 | * |
| 693 | * Function sleeps. |
| 694 | */ |
| 695 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
| 696 | { |
| 697 | struct iwl_addsta_cmd sta_cmd; |
| 698 | struct iwl_link_quality_cmd lq; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 699 | int i; |
| 700 | bool found = false; |
| 701 | int ret; |
| 702 | bool send_lq; |
| 703 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 704 | if (!iwl_is_ready(priv)) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 705 | IWL_DEBUG_INFO(priv, |
| 706 | "Not ready yet, not restoring any stations.\n"); |
| 707 | return; |
| 708 | } |
| 709 | |
| 710 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 711 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 712 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { |
| 713 | if (ctx->ctxid != priv->stations[i].ctxid) |
| 714 | continue; |
| 715 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && |
| 716 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { |
| 717 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", |
| 718 | priv->stations[i].sta.sta.addr); |
| 719 | priv->stations[i].sta.mode = 0; |
| 720 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; |
| 721 | found = true; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { |
| 726 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { |
| 727 | memcpy(&sta_cmd, &priv->stations[i].sta, |
| 728 | sizeof(struct iwl_addsta_cmd)); |
| 729 | send_lq = false; |
| 730 | if (priv->stations[i].lq) { |
Johannes Berg | 15b86bf | 2012-03-05 11:24:36 -0800 | [diff] [blame] | 731 | if (priv->wowlan) |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 732 | iwl_sta_fill_lq(priv, ctx, i, &lq); |
| 733 | else |
| 734 | memcpy(&lq, priv->stations[i].lq, |
| 735 | sizeof(struct iwl_link_quality_cmd)); |
| 736 | send_lq = true; |
| 737 | } |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 738 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 739 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 740 | if (ret) { |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 741 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 742 | IWL_ERR(priv, "Adding station %pM failed.\n", |
| 743 | priv->stations[i].sta.sta.addr); |
| 744 | priv->stations[i].used &= |
| 745 | ~IWL_STA_DRIVER_ACTIVE; |
| 746 | priv->stations[i].used &= |
| 747 | ~IWL_STA_UCODE_INPROGRESS; |
Meenakshi Venkataraman | f4c3717 | 2012-05-16 22:49:48 +0200 | [diff] [blame] | 748 | continue; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 749 | } |
| 750 | /* |
| 751 | * Rate scaling has already been initialized, send |
| 752 | * current LQ command |
| 753 | */ |
| 754 | if (send_lq) |
| 755 | iwl_send_lq_cmd(priv, ctx, &lq, |
| 756 | CMD_SYNC, true); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 757 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 758 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 759 | } |
| 760 | } |
| 761 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 762 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 763 | if (!found) |
| 764 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... " |
| 765 | "no stations to be restored.\n"); |
| 766 | else |
| 767 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... " |
| 768 | "complete.\n"); |
| 769 | } |
| 770 | |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 771 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv) |
| 772 | { |
| 773 | int i; |
| 774 | |
| 775 | for (i = 0; i < priv->sta_key_max_num; i++) |
| 776 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
| 777 | return i; |
| 778 | |
| 779 | return WEP_INVALID_OFFSET; |
| 780 | } |
| 781 | |
| 782 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv) |
| 783 | { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 784 | int i; |
| 785 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 786 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 787 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { |
| 788 | if (!(priv->stations[i].used & IWL_STA_BCAST)) |
| 789 | continue; |
| 790 | |
| 791 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
| 792 | priv->num_stations--; |
| 793 | if (WARN_ON(priv->num_stations < 0)) |
| 794 | priv->num_stations = 0; |
| 795 | kfree(priv->stations[i].lq); |
| 796 | priv->stations[i].lq = NULL; |
| 797 | } |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 798 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 802 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 803 | struct iwl_link_quality_cmd *lq) |
| 804 | { |
| 805 | int i; |
| 806 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); |
| 807 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", |
| 808 | lq->general_params.single_stream_ant_msk, |
| 809 | lq->general_params.dual_stream_ant_msk); |
| 810 | |
| 811 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
| 812 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", |
| 813 | i, lq->rs_table[i].rate_n_flags); |
| 814 | } |
| 815 | #else |
| 816 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 817 | struct iwl_link_quality_cmd *lq) |
| 818 | { |
| 819 | } |
| 820 | #endif |
| 821 | |
| 822 | /** |
| 823 | * is_lq_table_valid() - Test one aspect of LQ cmd for validity |
| 824 | * |
| 825 | * It sometimes happens when a HT rate has been in use and we |
| 826 | * loose connectivity with AP then mac80211 will first tell us that the |
| 827 | * current channel is not HT anymore before removing the station. In such a |
| 828 | * scenario the RXON flags will be updated to indicate we are not |
| 829 | * communicating HT anymore, but the LQ command may still contain HT rates. |
| 830 | * Test for this to prevent driver from sending LQ command between the time |
| 831 | * RXON flags are updated and when LQ command is updated. |
| 832 | */ |
| 833 | static bool is_lq_table_valid(struct iwl_priv *priv, |
| 834 | struct iwl_rxon_context *ctx, |
| 835 | struct iwl_link_quality_cmd *lq) |
| 836 | { |
| 837 | int i; |
| 838 | |
| 839 | if (ctx->ht.enabled) |
| 840 | return true; |
| 841 | |
| 842 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", |
| 843 | ctx->active.channel); |
| 844 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 845 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & |
| 846 | RATE_MCS_HT_MSK) { |
| 847 | IWL_DEBUG_INFO(priv, |
| 848 | "index %d of LQ expects HT channel\n", |
| 849 | i); |
| 850 | return false; |
| 851 | } |
| 852 | } |
| 853 | return true; |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * iwl_send_lq_cmd() - Send link quality command |
| 858 | * @init: This command is sent as part of station initialization right |
| 859 | * after station has been added. |
| 860 | * |
| 861 | * The link quality command is sent as the last step of station creation. |
| 862 | * This is the special case in which init is set and we call a callback in |
| 863 | * this case to clear the state indicating that station creation is in |
| 864 | * progress. |
| 865 | */ |
| 866 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 867 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) |
| 868 | { |
| 869 | int ret = 0; |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 870 | struct iwl_host_cmd cmd = { |
| 871 | .id = REPLY_TX_LINK_QUALITY_CMD, |
| 872 | .len = { sizeof(struct iwl_link_quality_cmd), }, |
| 873 | .flags = flags, |
| 874 | .data = { lq, }, |
| 875 | }; |
| 876 | |
| 877 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) |
| 878 | return -EINVAL; |
| 879 | |
| 880 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 881 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 882 | if (!(priv->stations[lq->sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 883 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 884 | return -EINVAL; |
| 885 | } |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 886 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 887 | |
| 888 | iwl_dump_lq_cmd(priv, lq); |
| 889 | if (WARN_ON(init && (cmd.flags & CMD_ASYNC))) |
| 890 | return -EINVAL; |
| 891 | |
| 892 | if (is_lq_table_valid(priv, ctx, lq)) |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 893 | ret = iwl_dvm_send_cmd(priv, &cmd); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 894 | else |
| 895 | ret = -EINVAL; |
| 896 | |
| 897 | if (cmd.flags & CMD_ASYNC) |
| 898 | return ret; |
| 899 | |
| 900 | if (init) { |
| 901 | IWL_DEBUG_INFO(priv, "init LQ command complete, " |
| 902 | "clearing sta addition status for sta %d\n", |
| 903 | lq->sta_id); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 904 | spin_lock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 905 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 906 | spin_unlock_bh(&priv->sta_lock); |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 907 | } |
| 908 | return ret; |
| 909 | } |
| 910 | |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 911 | |
Johannes Berg | c079166e | 2011-10-10 07:26:54 -0700 | [diff] [blame] | 912 | static struct iwl_link_quality_cmd * |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 913 | iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 914 | u8 sta_id) |
Johannes Berg | c079166e | 2011-10-10 07:26:54 -0700 | [diff] [blame] | 915 | { |
| 916 | struct iwl_link_quality_cmd *link_cmd; |
| 917 | |
| 918 | link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL); |
| 919 | if (!link_cmd) { |
| 920 | IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n"); |
| 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | iwl_sta_fill_lq(priv, ctx, sta_id, link_cmd); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 925 | |
| 926 | return link_cmd; |
| 927 | } |
| 928 | |
| 929 | /* |
| 930 | * iwlagn_add_bssid_station - Add the special IBSS BSSID station |
| 931 | * |
| 932 | * Function sleeps. |
| 933 | */ |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 934 | int iwlagn_add_bssid_station(struct iwl_priv *priv, |
| 935 | struct iwl_rxon_context *ctx, |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 936 | const u8 *addr, u8 *sta_id_r) |
| 937 | { |
| 938 | int ret; |
| 939 | u8 sta_id; |
| 940 | struct iwl_link_quality_cmd *link_cmd; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 941 | |
| 942 | if (sta_id_r) |
| 943 | *sta_id_r = IWL_INVALID_STATION; |
| 944 | |
| 945 | ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id); |
| 946 | if (ret) { |
| 947 | IWL_ERR(priv, "Unable to add station %pM\n", addr); |
| 948 | return ret; |
| 949 | } |
| 950 | |
| 951 | if (sta_id_r) |
| 952 | *sta_id_r = sta_id; |
| 953 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 954 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 955 | priv->stations[sta_id].used |= IWL_STA_LOCAL; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 956 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 957 | |
| 958 | /* Set up default rate scaling table in device's station table */ |
Johannes Berg | f775aa06d | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 959 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 960 | if (!link_cmd) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 961 | IWL_ERR(priv, |
| 962 | "Unable to initialize rate scaling for station %pM.\n", |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 963 | addr); |
| 964 | return -ENOMEM; |
| 965 | } |
| 966 | |
| 967 | ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true); |
| 968 | if (ret) |
| 969 | IWL_ERR(priv, "Link quality command failed (%d)\n", ret); |
| 970 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 971 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 972 | priv->stations[sta_id].lq = link_cmd; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 973 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 974 | |
| 975 | return 0; |
| 976 | } |
| 977 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 978 | /* |
| 979 | * static WEP keys |
| 980 | * |
| 981 | * For each context, the device has a table of 4 static WEP keys |
| 982 | * (one for each key index) that is updated with the following |
| 983 | * commands. |
| 984 | */ |
| 985 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 986 | static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, |
| 987 | struct iwl_rxon_context *ctx, |
| 988 | bool send_if_empty) |
| 989 | { |
| 990 | int i, not_empty = 0; |
| 991 | u8 buff[sizeof(struct iwl_wep_cmd) + |
| 992 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; |
| 993 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; |
| 994 | size_t cmd_size = sizeof(struct iwl_wep_cmd); |
| 995 | struct iwl_host_cmd cmd = { |
| 996 | .id = ctx->wep_key_cmd, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 997 | .data = { wep_cmd, }, |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 998 | .flags = CMD_SYNC, |
| 999 | }; |
| 1000 | |
| 1001 | might_sleep(); |
| 1002 | |
| 1003 | memset(wep_cmd, 0, cmd_size + |
| 1004 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); |
| 1005 | |
| 1006 | for (i = 0; i < WEP_KEYS_MAX ; i++) { |
| 1007 | wep_cmd->key[i].key_index = i; |
| 1008 | if (ctx->wep_keys[i].key_size) { |
| 1009 | wep_cmd->key[i].key_offset = i; |
| 1010 | not_empty = 1; |
| 1011 | } else { |
| 1012 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 1013 | } |
| 1014 | |
| 1015 | wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size; |
| 1016 | memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key, |
| 1017 | ctx->wep_keys[i].key_size); |
| 1018 | } |
| 1019 | |
| 1020 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 1021 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 1022 | |
| 1023 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; |
| 1024 | |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 1025 | cmd.len[0] = cmd_size; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1026 | |
| 1027 | if (not_empty || send_if_empty) |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 1028 | return iwl_dvm_send_cmd(priv, &cmd); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1029 | else |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | int iwl_restore_default_wep_keys(struct iwl_priv *priv, |
| 1034 | struct iwl_rxon_context *ctx) |
| 1035 | { |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1036 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1037 | |
| 1038 | return iwl_send_static_wepkey_cmd(priv, ctx, false); |
| 1039 | } |
| 1040 | |
| 1041 | int iwl_remove_default_wep_key(struct iwl_priv *priv, |
| 1042 | struct iwl_rxon_context *ctx, |
| 1043 | struct ieee80211_key_conf *keyconf) |
| 1044 | { |
| 1045 | int ret; |
| 1046 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1047 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1048 | |
| 1049 | IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", |
| 1050 | keyconf->keyidx); |
| 1051 | |
| 1052 | memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0])); |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1053 | if (iwl_is_rfkill(priv)) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 1054 | IWL_DEBUG_WEP(priv, |
| 1055 | "Not sending REPLY_WEPKEY command due to RFKILL.\n"); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1056 | /* but keys in device are clear anyway so return success */ |
| 1057 | return 0; |
| 1058 | } |
| 1059 | ret = iwl_send_static_wepkey_cmd(priv, ctx, 1); |
| 1060 | IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", |
| 1061 | keyconf->keyidx, ret); |
| 1062 | |
| 1063 | return ret; |
| 1064 | } |
| 1065 | |
| 1066 | int iwl_set_default_wep_key(struct iwl_priv *priv, |
| 1067 | struct iwl_rxon_context *ctx, |
| 1068 | struct ieee80211_key_conf *keyconf) |
| 1069 | { |
| 1070 | int ret; |
| 1071 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1072 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1073 | |
| 1074 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
| 1075 | keyconf->keylen != WEP_KEY_LEN_64) { |
Wey-Yi Guy | c745f55 | 2011-10-10 07:27:12 -0700 | [diff] [blame] | 1076 | IWL_DEBUG_WEP(priv, |
| 1077 | "Bad WEP key length %d\n", keyconf->keylen); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1078 | return -EINVAL; |
| 1079 | } |
| 1080 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1081 | keyconf->hw_key_idx = IWLAGN_HW_KEY_DEFAULT; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1082 | |
| 1083 | ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
| 1084 | memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key, |
| 1085 | keyconf->keylen); |
| 1086 | |
| 1087 | ret = iwl_send_static_wepkey_cmd(priv, ctx, false); |
| 1088 | IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", |
| 1089 | keyconf->keylen, keyconf->keyidx, ret); |
| 1090 | |
| 1091 | return ret; |
| 1092 | } |
| 1093 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1094 | /* |
| 1095 | * dynamic (per-station) keys |
| 1096 | * |
| 1097 | * The dynamic keys are a little more complicated. The device has |
| 1098 | * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys. |
| 1099 | * These are linked to stations by a table that contains an index |
| 1100 | * into the key table for each station/key index/{mcast,unicast}, |
| 1101 | * i.e. it's basically an array of pointers like this: |
| 1102 | * key_offset_t key_mapping[NUM_STATIONS][4][2]; |
| 1103 | * (it really works differently, but you can think of it as such) |
| 1104 | * |
| 1105 | * The key uploading and linking happens in the same command, the |
| 1106 | * add station command with STA_MODIFY_KEY_MASK. |
| 1107 | */ |
| 1108 | |
| 1109 | static u8 iwlagn_key_sta_id(struct iwl_priv *priv, |
| 1110 | struct ieee80211_vif *vif, |
| 1111 | struct ieee80211_sta *sta) |
| 1112 | { |
| 1113 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1114 | |
| 1115 | if (sta) |
Johannes Berg | 40e4e68 | 2012-03-05 11:24:22 -0800 | [diff] [blame] | 1116 | return iwl_sta_id(sta); |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1117 | |
| 1118 | /* |
| 1119 | * The device expects GTKs for station interfaces to be |
| 1120 | * installed as GTKs for the AP station. If we have no |
| 1121 | * station ID, then use the ap_sta_id in that case. |
| 1122 | */ |
Johannes Berg | 40e4e68 | 2012-03-05 11:24:22 -0800 | [diff] [blame] | 1123 | if (vif->type == NL80211_IFTYPE_STATION && vif_priv->ctx) |
| 1124 | return vif_priv->ctx->ap_sta_id; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1125 | |
Johannes Berg | 40e4e68 | 2012-03-05 11:24:22 -0800 | [diff] [blame] | 1126 | return IWL_INVALID_STATION; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 1129 | static int iwlagn_send_sta_key(struct iwl_priv *priv, |
| 1130 | struct ieee80211_key_conf *keyconf, |
| 1131 | u8 sta_id, u32 tkip_iv32, u16 *tkip_p1k, |
| 1132 | u32 cmd_flags) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1133 | { |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1134 | __le16 key_flags; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1135 | struct iwl_addsta_cmd sta_cmd; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1136 | int i; |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 1137 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1138 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1139 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1140 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1141 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1142 | key_flags = cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1143 | key_flags |= STA_KEY_FLG_MAP_KEY_MSK; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1144 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1145 | switch (keyconf->cipher) { |
| 1146 | case WLAN_CIPHER_SUITE_CCMP: |
| 1147 | key_flags |= STA_KEY_FLG_CCMP; |
| 1148 | memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen); |
| 1149 | break; |
| 1150 | case WLAN_CIPHER_SUITE_TKIP: |
| 1151 | key_flags |= STA_KEY_FLG_TKIP; |
| 1152 | sta_cmd.key.tkip_rx_tsc_byte2 = tkip_iv32; |
| 1153 | for (i = 0; i < 5; i++) |
| 1154 | sta_cmd.key.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
| 1155 | memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen); |
| 1156 | break; |
| 1157 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1158 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1159 | /* fall through */ |
| 1160 | case WLAN_CIPHER_SUITE_WEP40: |
| 1161 | key_flags |= STA_KEY_FLG_WEP; |
| 1162 | memcpy(&sta_cmd.key.key[3], keyconf->key, keyconf->keylen); |
| 1163 | break; |
| 1164 | default: |
| 1165 | WARN_ON(1); |
| 1166 | return -EINVAL; |
| 1167 | } |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1168 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1169 | if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1170 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 1171 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1172 | /* key pointer (offset) */ |
| 1173 | sta_cmd.key.key_offset = keyconf->hw_key_idx; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1174 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1175 | sta_cmd.key.key_flags = key_flags; |
| 1176 | sta_cmd.mode = STA_CONTROL_MODIFY_MSK; |
| 1177 | sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1178 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1179 | return iwl_send_add_sta(priv, &sta_cmd, cmd_flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | void iwl_update_tkip_key(struct iwl_priv *priv, |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1183 | struct ieee80211_vif *vif, |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1184 | struct ieee80211_key_conf *keyconf, |
| 1185 | struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) |
| 1186 | { |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1187 | u8 sta_id = iwlagn_key_sta_id(priv, vif, sta); |
| 1188 | |
| 1189 | if (sta_id == IWL_INVALID_STATION) |
| 1190 | return; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1191 | |
| 1192 | if (iwl_scan_cancel(priv)) { |
| 1193 | /* cancel scan failed, just live w/ bad key and rely |
| 1194 | briefly on SW decryption */ |
| 1195 | return; |
| 1196 | } |
| 1197 | |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 1198 | iwlagn_send_sta_key(priv, keyconf, sta_id, |
| 1199 | iv32, phase1key, CMD_ASYNC); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | int iwl_remove_dynamic_key(struct iwl_priv *priv, |
| 1203 | struct iwl_rxon_context *ctx, |
| 1204 | struct ieee80211_key_conf *keyconf, |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1205 | struct ieee80211_sta *sta) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1206 | { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1207 | struct iwl_addsta_cmd sta_cmd; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1208 | u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta); |
Johannes Berg | 5dcbf48 | 2012-02-17 09:47:14 -0800 | [diff] [blame] | 1209 | __le16 key_flags; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1210 | |
| 1211 | /* if station isn't there, neither is the key */ |
| 1212 | if (sta_id == IWL_INVALID_STATION) |
| 1213 | return -ENOENT; |
| 1214 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1215 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1216 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); |
| 1217 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) |
| 1218 | sta_id = IWL_INVALID_STATION; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1219 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1220 | |
| 1221 | if (sta_id == IWL_INVALID_STATION) |
| 1222 | return 0; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1223 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1224 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1225 | |
| 1226 | ctx->key_mapping_keys--; |
| 1227 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1228 | IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n", |
| 1229 | keyconf->keyidx, sta_id); |
| 1230 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1231 | if (!test_and_clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table)) |
| 1232 | IWL_ERR(priv, "offset %d not used in uCode key table.\n", |
| 1233 | keyconf->hw_key_idx); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1234 | |
Johannes Berg | 5dcbf48 | 2012-02-17 09:47:14 -0800 | [diff] [blame] | 1235 | key_flags = cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1236 | key_flags |= STA_KEY_FLG_MAP_KEY_MSK | STA_KEY_FLG_NO_ENC | |
| 1237 | STA_KEY_FLG_INVALID; |
| 1238 | |
| 1239 | if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) |
| 1240 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 1241 | |
| 1242 | sta_cmd.key.key_flags = key_flags; |
Emmanuel Grumbach | d6ee27eb | 2012-06-06 09:13:36 +0200 | [diff] [blame] | 1243 | sta_cmd.key.key_offset = keyconf->hw_key_idx; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1244 | sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1245 | sta_cmd.mode = STA_CONTROL_MODIFY_MSK; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1246 | |
| 1247 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 1248 | } |
| 1249 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1250 | int iwl_set_dynamic_key(struct iwl_priv *priv, |
| 1251 | struct iwl_rxon_context *ctx, |
| 1252 | struct ieee80211_key_conf *keyconf, |
| 1253 | struct ieee80211_sta *sta) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1254 | { |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1255 | struct ieee80211_key_seq seq; |
| 1256 | u16 p1k[5]; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1257 | int ret; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1258 | u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta); |
| 1259 | const u8 *addr; |
| 1260 | |
| 1261 | if (sta_id == IWL_INVALID_STATION) |
| 1262 | return -EINVAL; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1263 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1264 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1265 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1266 | keyconf->hw_key_idx = iwl_get_free_ucode_key_offset(priv); |
| 1267 | if (keyconf->hw_key_idx == WEP_INVALID_OFFSET) |
| 1268 | return -ENOSPC; |
| 1269 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1270 | ctx->key_mapping_keys++; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1271 | |
| 1272 | switch (keyconf->cipher) { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1273 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1274 | if (sta) |
| 1275 | addr = sta->addr; |
| 1276 | else /* station mode case only */ |
| 1277 | addr = ctx->active.bssid_addr; |
| 1278 | |
| 1279 | /* pre-fill phase 1 key into device cache */ |
| 1280 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 1281 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 1282 | ret = iwlagn_send_sta_key(priv, keyconf, sta_id, |
| 1283 | seq.tkip.iv32, p1k, CMD_SYNC); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1284 | break; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1285 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1286 | case WLAN_CIPHER_SUITE_WEP40: |
| 1287 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 1288 | ret = iwlagn_send_sta_key(priv, keyconf, sta_id, |
| 1289 | 0, NULL, CMD_SYNC); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1290 | break; |
| 1291 | default: |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1292 | IWL_ERR(priv, "Unknown cipher %x\n", keyconf->cipher); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1293 | ret = -EINVAL; |
| 1294 | } |
| 1295 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1296 | if (ret) { |
| 1297 | ctx->key_mapping_keys--; |
| 1298 | clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table); |
| 1299 | } |
| 1300 | |
| 1301 | IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1302 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 1303 | sta ? sta->addr : NULL, ret); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1304 | |
| 1305 | return ret; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * iwlagn_alloc_bcast_station - add broadcast station into driver's station table. |
| 1310 | * |
| 1311 | * This adds the broadcast station into the driver's station table |
| 1312 | * and marks it driver active, so that it will be restored to the |
| 1313 | * device at the next best time. |
| 1314 | */ |
| 1315 | int iwlagn_alloc_bcast_station(struct iwl_priv *priv, |
| 1316 | struct iwl_rxon_context *ctx) |
| 1317 | { |
| 1318 | struct iwl_link_quality_cmd *link_cmd; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1319 | u8 sta_id; |
| 1320 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1321 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1322 | sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL); |
| 1323 | if (sta_id == IWL_INVALID_STATION) { |
| 1324 | IWL_ERR(priv, "Unable to prepare broadcast station\n"); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1325 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1326 | |
| 1327 | return -EINVAL; |
| 1328 | } |
| 1329 | |
| 1330 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; |
| 1331 | priv->stations[sta_id].used |= IWL_STA_BCAST; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1332 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1333 | |
Johannes Berg | f775aa06d | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 1334 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1335 | if (!link_cmd) { |
| 1336 | IWL_ERR(priv, |
| 1337 | "Unable to initialize rate scaling for bcast station.\n"); |
| 1338 | return -ENOMEM; |
| 1339 | } |
| 1340 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1341 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1342 | priv->stations[sta_id].lq = link_cmd; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1343 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1344 | |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * iwl_update_bcast_station - update broadcast station's LQ command |
| 1350 | * |
| 1351 | * Only used by iwlagn. Placed here to have all bcast station management |
| 1352 | * code together. |
| 1353 | */ |
Johannes Berg | f775aa06d | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 1354 | int iwl_update_bcast_station(struct iwl_priv *priv, |
| 1355 | struct iwl_rxon_context *ctx) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1356 | { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1357 | struct iwl_link_quality_cmd *link_cmd; |
| 1358 | u8 sta_id = ctx->bcast_sta_id; |
| 1359 | |
Johannes Berg | f775aa06d | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 1360 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1361 | if (!link_cmd) { |
| 1362 | IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n"); |
| 1363 | return -ENOMEM; |
| 1364 | } |
| 1365 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1366 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1367 | if (priv->stations[sta_id].lq) |
| 1368 | kfree(priv->stations[sta_id].lq); |
| 1369 | else |
| 1370 | IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n"); |
| 1371 | priv->stations[sta_id].lq = link_cmd; |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1372 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1373 | |
| 1374 | return 0; |
| 1375 | } |
| 1376 | |
| 1377 | int iwl_update_bcast_stations(struct iwl_priv *priv) |
| 1378 | { |
| 1379 | struct iwl_rxon_context *ctx; |
| 1380 | int ret = 0; |
| 1381 | |
| 1382 | for_each_context(priv, ctx) { |
| 1383 | ret = iwl_update_bcast_station(priv, ctx); |
| 1384 | if (ret) |
| 1385 | break; |
| 1386 | } |
| 1387 | |
| 1388 | return ret; |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table |
| 1393 | */ |
| 1394 | int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid) |
| 1395 | { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1396 | struct iwl_addsta_cmd sta_cmd; |
| 1397 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1398 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1399 | |
| 1400 | /* Remove "disable" flag, to enable Tx for this TID */ |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1401 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1402 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 1403 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 1404 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1405 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1406 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1407 | |
| 1408 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 1409 | } |
| 1410 | |
| 1411 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, |
| 1412 | int tid, u16 ssn) |
| 1413 | { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1414 | int sta_id; |
| 1415 | struct iwl_addsta_cmd sta_cmd; |
| 1416 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1417 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1418 | |
| 1419 | sta_id = iwl_sta_id(sta); |
| 1420 | if (sta_id == IWL_INVALID_STATION) |
| 1421 | return -ENXIO; |
| 1422 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1423 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1424 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 1425 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; |
| 1426 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; |
| 1427 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 1428 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1429 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1430 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1431 | |
| 1432 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 1433 | } |
| 1434 | |
| 1435 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, |
| 1436 | int tid) |
| 1437 | { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1438 | int sta_id; |
| 1439 | struct iwl_addsta_cmd sta_cmd; |
| 1440 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1441 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1442 | |
| 1443 | sta_id = iwl_sta_id(sta); |
| 1444 | if (sta_id == IWL_INVALID_STATION) { |
| 1445 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); |
| 1446 | return -ENXIO; |
| 1447 | } |
| 1448 | |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1449 | spin_lock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1450 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 1451 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; |
| 1452 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; |
| 1453 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1454 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Johannes Berg | fa23cb0 | 2012-03-05 11:24:25 -0800 | [diff] [blame] | 1455 | spin_unlock_bh(&priv->sta_lock); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1456 | |
| 1457 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 1458 | } |
| 1459 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1460 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1461 | |
| 1462 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt) |
| 1463 | { |
Johannes Berg | 9451ca1 | 2012-03-05 11:24:23 -0800 | [diff] [blame] | 1464 | struct iwl_addsta_cmd cmd = { |
| 1465 | .mode = STA_CONTROL_MODIFY_MSK, |
| 1466 | .station_flags = STA_FLG_PWR_SAVE_MSK, |
| 1467 | .station_flags_msk = STA_FLG_PWR_SAVE_MSK, |
| 1468 | .sta.sta_id = sta_id, |
| 1469 | .sta.modify_mask = STA_MODIFY_SLEEP_TX_COUNT_MSK, |
| 1470 | .sleep_tx_count = cpu_to_le16(cnt), |
| 1471 | }; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1472 | |
Johannes Berg | 9451ca1 | 2012-03-05 11:24:23 -0800 | [diff] [blame] | 1473 | iwl_send_add_sta(priv, &cmd, CMD_ASYNC); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1474 | } |