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