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