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