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