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