Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | 901069c | 2011-04-05 09:42:00 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include <net/mac80211.h> |
| 31 | |
| 32 | #include "iwl-dev.h" |
| 33 | #include "iwl-core.h" |
| 34 | #include "iwl-sta.h" |
| 35 | #include "iwl-agn.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 36 | #include "iwl-trans.h" |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 37 | |
Johannes Berg | c079166e | 2011-10-10 07:26:54 -0700 | [diff] [blame] | 38 | void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 39 | u8 sta_id, struct iwl_link_quality_cmd *link_cmd) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 40 | { |
| 41 | int i, r; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 42 | u32 rate_flags = 0; |
| 43 | __le32 rate_n_flags; |
| 44 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 45 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | f775aa0 | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 46 | |
Johannes Berg | c079166e | 2011-10-10 07:26:54 -0700 | [diff] [blame] | 47 | memset(link_cmd, 0, sizeof(*link_cmd)); |
| 48 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 49 | /* Set up the rate scaling to start at selected rate, fall back |
| 50 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
| 51 | if (priv->band == IEEE80211_BAND_5GHZ) |
| 52 | r = IWL_RATE_6M_INDEX; |
Johannes Berg | f775aa0 | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 53 | else if (ctx && ctx->vif && ctx->vif->p2p) |
| 54 | r = IWL_RATE_6M_INDEX; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 55 | else |
| 56 | r = IWL_RATE_1M_INDEX; |
| 57 | |
| 58 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) |
| 59 | rate_flags |= RATE_MCS_CCK_MSK; |
| 60 | |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 61 | rate_flags |= first_antenna(hw_params(priv).valid_tx_ant) << |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 62 | RATE_MCS_ANT_POS; |
| 63 | rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); |
| 64 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
| 65 | link_cmd->rs_table[i].rate_n_flags = rate_n_flags; |
| 66 | |
| 67 | link_cmd->general_params.single_stream_ant_msk = |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 68 | first_antenna(hw_params(priv).valid_tx_ant); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 69 | |
| 70 | link_cmd->general_params.dual_stream_ant_msk = |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 71 | hw_params(priv).valid_tx_ant & |
| 72 | ~first_antenna(hw_params(priv).valid_tx_ant); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 73 | if (!link_cmd->general_params.dual_stream_ant_msk) { |
| 74 | link_cmd->general_params.dual_stream_ant_msk = ANT_AB; |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 75 | } else if (num_of_ant(hw_params(priv).valid_tx_ant) == 2) { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 76 | link_cmd->general_params.dual_stream_ant_msk = |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 77 | hw_params(priv).valid_tx_ant; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; |
| 81 | link_cmd->agg_params.agg_time_limit = |
| 82 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
| 83 | |
| 84 | link_cmd->sta_id = sta_id; |
Johannes Berg | c079166e | 2011-10-10 07:26:54 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static struct iwl_link_quality_cmd * |
| 88 | iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, u8 sta_id) |
| 89 | { |
| 90 | struct iwl_link_quality_cmd *link_cmd; |
| 91 | |
| 92 | link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL); |
| 93 | if (!link_cmd) { |
| 94 | IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n"); |
| 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | iwl_sta_fill_lq(priv, ctx, sta_id, link_cmd); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 99 | |
| 100 | return link_cmd; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * iwlagn_add_bssid_station - Add the special IBSS BSSID station |
| 105 | * |
| 106 | * Function sleeps. |
| 107 | */ |
| 108 | int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 109 | const u8 *addr, u8 *sta_id_r) |
| 110 | { |
| 111 | int ret; |
| 112 | u8 sta_id; |
| 113 | struct iwl_link_quality_cmd *link_cmd; |
| 114 | unsigned long flags; |
| 115 | |
| 116 | if (sta_id_r) |
| 117 | *sta_id_r = IWL_INVALID_STATION; |
| 118 | |
| 119 | ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id); |
| 120 | if (ret) { |
| 121 | IWL_ERR(priv, "Unable to add station %pM\n", addr); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | if (sta_id_r) |
| 126 | *sta_id_r = sta_id; |
| 127 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 128 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 129 | priv->stations[sta_id].used |= IWL_STA_LOCAL; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 130 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 131 | |
| 132 | /* Set up default rate scaling table in device's station table */ |
Johannes Berg | f775aa0 | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 133 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 134 | if (!link_cmd) { |
| 135 | IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n", |
| 136 | addr); |
| 137 | return -ENOMEM; |
| 138 | } |
| 139 | |
| 140 | ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true); |
| 141 | if (ret) |
| 142 | IWL_ERR(priv, "Link quality command failed (%d)\n", ret); |
| 143 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 144 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 145 | priv->stations[sta_id].lq = link_cmd; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 146 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 151 | /* |
| 152 | * static WEP keys |
| 153 | * |
| 154 | * For each context, the device has a table of 4 static WEP keys |
| 155 | * (one for each key index) that is updated with the following |
| 156 | * commands. |
| 157 | */ |
| 158 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 159 | static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, |
| 160 | struct iwl_rxon_context *ctx, |
| 161 | bool send_if_empty) |
| 162 | { |
| 163 | int i, not_empty = 0; |
| 164 | u8 buff[sizeof(struct iwl_wep_cmd) + |
| 165 | sizeof(struct iwl_wep_key) * WEP_KEYS_MAX]; |
| 166 | struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; |
| 167 | size_t cmd_size = sizeof(struct iwl_wep_cmd); |
| 168 | struct iwl_host_cmd cmd = { |
| 169 | .id = ctx->wep_key_cmd, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 170 | .data = { wep_cmd, }, |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 171 | .flags = CMD_SYNC, |
| 172 | }; |
| 173 | |
| 174 | might_sleep(); |
| 175 | |
| 176 | memset(wep_cmd, 0, cmd_size + |
| 177 | (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); |
| 178 | |
| 179 | for (i = 0; i < WEP_KEYS_MAX ; i++) { |
| 180 | wep_cmd->key[i].key_index = i; |
| 181 | if (ctx->wep_keys[i].key_size) { |
| 182 | wep_cmd->key[i].key_offset = i; |
| 183 | not_empty = 1; |
| 184 | } else { |
| 185 | wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; |
| 186 | } |
| 187 | |
| 188 | wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size; |
| 189 | memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key, |
| 190 | ctx->wep_keys[i].key_size); |
| 191 | } |
| 192 | |
| 193 | wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; |
| 194 | wep_cmd->num_keys = WEP_KEYS_MAX; |
| 195 | |
| 196 | cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX; |
| 197 | |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 198 | cmd.len[0] = cmd_size; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 199 | |
| 200 | if (not_empty || send_if_empty) |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 201 | return iwl_trans_send_cmd(trans(priv), &cmd); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 202 | else |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | int iwl_restore_default_wep_keys(struct iwl_priv *priv, |
| 207 | struct iwl_rxon_context *ctx) |
| 208 | { |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 209 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 210 | |
| 211 | return iwl_send_static_wepkey_cmd(priv, ctx, false); |
| 212 | } |
| 213 | |
| 214 | int iwl_remove_default_wep_key(struct iwl_priv *priv, |
| 215 | struct iwl_rxon_context *ctx, |
| 216 | struct ieee80211_key_conf *keyconf) |
| 217 | { |
| 218 | int ret; |
| 219 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 220 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 221 | |
| 222 | IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", |
| 223 | keyconf->keyidx); |
| 224 | |
| 225 | memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0])); |
Emmanuel Grumbach | 845a9c0 | 2011-08-25 23:11:04 -0700 | [diff] [blame] | 226 | if (iwl_is_rfkill(priv->shrd)) { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 227 | IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); |
| 228 | /* but keys in device are clear anyway so return success */ |
| 229 | return 0; |
| 230 | } |
| 231 | ret = iwl_send_static_wepkey_cmd(priv, ctx, 1); |
| 232 | IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", |
| 233 | keyconf->keyidx, ret); |
| 234 | |
| 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | int iwl_set_default_wep_key(struct iwl_priv *priv, |
| 239 | struct iwl_rxon_context *ctx, |
| 240 | struct ieee80211_key_conf *keyconf) |
| 241 | { |
| 242 | int ret; |
| 243 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 244 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 245 | |
| 246 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
| 247 | keyconf->keylen != WEP_KEY_LEN_64) { |
| 248 | IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 252 | keyconf->hw_key_idx = IWLAGN_HW_KEY_DEFAULT; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 253 | |
| 254 | ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; |
| 255 | memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key, |
| 256 | keyconf->keylen); |
| 257 | |
| 258 | ret = iwl_send_static_wepkey_cmd(priv, ctx, false); |
| 259 | IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", |
| 260 | keyconf->keylen, keyconf->keyidx, ret); |
| 261 | |
| 262 | return ret; |
| 263 | } |
| 264 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 265 | /* |
| 266 | * dynamic (per-station) keys |
| 267 | * |
| 268 | * The dynamic keys are a little more complicated. The device has |
| 269 | * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys. |
| 270 | * These are linked to stations by a table that contains an index |
| 271 | * into the key table for each station/key index/{mcast,unicast}, |
| 272 | * i.e. it's basically an array of pointers like this: |
| 273 | * key_offset_t key_mapping[NUM_STATIONS][4][2]; |
| 274 | * (it really works differently, but you can think of it as such) |
| 275 | * |
| 276 | * The key uploading and linking happens in the same command, the |
| 277 | * add station command with STA_MODIFY_KEY_MASK. |
| 278 | */ |
| 279 | |
| 280 | static u8 iwlagn_key_sta_id(struct iwl_priv *priv, |
| 281 | struct ieee80211_vif *vif, |
| 282 | struct ieee80211_sta *sta) |
| 283 | { |
| 284 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 285 | u8 sta_id = IWL_INVALID_STATION; |
| 286 | |
| 287 | if (sta) |
| 288 | sta_id = iwl_sta_id(sta); |
| 289 | |
| 290 | /* |
| 291 | * The device expects GTKs for station interfaces to be |
| 292 | * installed as GTKs for the AP station. If we have no |
| 293 | * station ID, then use the ap_sta_id in that case. |
| 294 | */ |
| 295 | if (!sta && vif && vif_priv->ctx) { |
| 296 | switch (vif->type) { |
| 297 | case NL80211_IFTYPE_STATION: |
| 298 | sta_id = vif_priv->ctx->ap_sta_id; |
| 299 | break; |
| 300 | default: |
| 301 | /* |
| 302 | * In all other cases, the key will be |
| 303 | * used either for TX only or is bound |
| 304 | * to a station already. |
| 305 | */ |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | return sta_id; |
| 311 | } |
| 312 | |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 313 | static int iwlagn_send_sta_key(struct iwl_priv *priv, |
| 314 | struct ieee80211_key_conf *keyconf, |
| 315 | u8 sta_id, u32 tkip_iv32, u16 *tkip_p1k, |
| 316 | u32 cmd_flags) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 317 | { |
| 318 | unsigned long flags; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 319 | __le16 key_flags; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 320 | struct iwl_addsta_cmd sta_cmd; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 321 | int i; |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 322 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 323 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 324 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 325 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 326 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 327 | key_flags = cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 328 | key_flags |= STA_KEY_FLG_MAP_KEY_MSK; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 329 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 330 | switch (keyconf->cipher) { |
| 331 | case WLAN_CIPHER_SUITE_CCMP: |
| 332 | key_flags |= STA_KEY_FLG_CCMP; |
| 333 | memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen); |
| 334 | break; |
| 335 | case WLAN_CIPHER_SUITE_TKIP: |
| 336 | key_flags |= STA_KEY_FLG_TKIP; |
| 337 | sta_cmd.key.tkip_rx_tsc_byte2 = tkip_iv32; |
| 338 | for (i = 0; i < 5; i++) |
| 339 | sta_cmd.key.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
| 340 | memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen); |
| 341 | break; |
| 342 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 343 | key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 344 | /* fall through */ |
| 345 | case WLAN_CIPHER_SUITE_WEP40: |
| 346 | key_flags |= STA_KEY_FLG_WEP; |
| 347 | memcpy(&sta_cmd.key.key[3], keyconf->key, keyconf->keylen); |
| 348 | break; |
| 349 | default: |
| 350 | WARN_ON(1); |
| 351 | return -EINVAL; |
| 352 | } |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 353 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 354 | if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 355 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 356 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 357 | /* key pointer (offset) */ |
| 358 | sta_cmd.key.key_offset = keyconf->hw_key_idx; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 359 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 360 | sta_cmd.key.key_flags = key_flags; |
| 361 | sta_cmd.mode = STA_CONTROL_MODIFY_MSK; |
| 362 | sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 363 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 364 | return iwl_send_add_sta(priv, &sta_cmd, cmd_flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void iwl_update_tkip_key(struct iwl_priv *priv, |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 368 | struct ieee80211_vif *vif, |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 369 | struct ieee80211_key_conf *keyconf, |
| 370 | struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) |
| 371 | { |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 372 | u8 sta_id = iwlagn_key_sta_id(priv, vif, sta); |
| 373 | |
| 374 | if (sta_id == IWL_INVALID_STATION) |
| 375 | return; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 376 | |
| 377 | if (iwl_scan_cancel(priv)) { |
| 378 | /* cancel scan failed, just live w/ bad key and rely |
| 379 | briefly on SW decryption */ |
| 380 | return; |
| 381 | } |
| 382 | |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 383 | iwlagn_send_sta_key(priv, keyconf, sta_id, |
| 384 | iv32, phase1key, CMD_ASYNC); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | int iwl_remove_dynamic_key(struct iwl_priv *priv, |
| 388 | struct iwl_rxon_context *ctx, |
| 389 | struct ieee80211_key_conf *keyconf, |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 390 | struct ieee80211_sta *sta) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 391 | { |
| 392 | unsigned long flags; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 393 | struct iwl_addsta_cmd sta_cmd; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 394 | u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta); |
| 395 | |
| 396 | /* if station isn't there, neither is the key */ |
| 397 | if (sta_id == IWL_INVALID_STATION) |
| 398 | return -ENOENT; |
| 399 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 400 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 401 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); |
| 402 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) |
| 403 | sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 404 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 405 | |
| 406 | if (sta_id == IWL_INVALID_STATION) |
| 407 | return 0; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 408 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 409 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 410 | |
| 411 | ctx->key_mapping_keys--; |
| 412 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 413 | IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n", |
| 414 | keyconf->keyidx, sta_id); |
| 415 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 416 | if (!test_and_clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table)) |
| 417 | IWL_ERR(priv, "offset %d not used in uCode key table.\n", |
| 418 | keyconf->hw_key_idx); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 419 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 420 | sta_cmd.key.key_flags = STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID; |
| 421 | sta_cmd.key.key_offset = WEP_INVALID_OFFSET; |
| 422 | sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 423 | sta_cmd.mode = STA_CONTROL_MODIFY_MSK; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 424 | |
| 425 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 426 | } |
| 427 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 428 | int iwl_set_dynamic_key(struct iwl_priv *priv, |
| 429 | struct iwl_rxon_context *ctx, |
| 430 | struct ieee80211_key_conf *keyconf, |
| 431 | struct ieee80211_sta *sta) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 432 | { |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 433 | struct ieee80211_key_seq seq; |
| 434 | u16 p1k[5]; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 435 | int ret; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 436 | u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta); |
| 437 | const u8 *addr; |
| 438 | |
| 439 | if (sta_id == IWL_INVALID_STATION) |
| 440 | return -EINVAL; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 441 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 442 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 443 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 444 | keyconf->hw_key_idx = iwl_get_free_ucode_key_offset(priv); |
| 445 | if (keyconf->hw_key_idx == WEP_INVALID_OFFSET) |
| 446 | return -ENOSPC; |
| 447 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 448 | ctx->key_mapping_keys++; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 449 | |
| 450 | switch (keyconf->cipher) { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 451 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 452 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 453 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 454 | |
| 455 | if (sta) |
| 456 | addr = sta->addr; |
| 457 | else /* station mode case only */ |
| 458 | addr = ctx->active.bssid_addr; |
| 459 | |
| 460 | /* pre-fill phase 1 key into device cache */ |
| 461 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 462 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 463 | ret = iwlagn_send_sta_key(priv, keyconf, sta_id, |
| 464 | seq.tkip.iv32, p1k, CMD_SYNC); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 465 | break; |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 466 | case WLAN_CIPHER_SUITE_CCMP: |
| 467 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 468 | /* fall through */ |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 469 | case WLAN_CIPHER_SUITE_WEP40: |
| 470 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | e1b1c08 | 2011-07-17 01:44:11 -0700 | [diff] [blame] | 471 | ret = iwlagn_send_sta_key(priv, keyconf, sta_id, |
| 472 | 0, NULL, CMD_SYNC); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 473 | break; |
| 474 | default: |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 475 | IWL_ERR(priv, "Unknown cipher %x\n", keyconf->cipher); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 476 | ret = -EINVAL; |
| 477 | } |
| 478 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 479 | if (ret) { |
| 480 | ctx->key_mapping_keys--; |
| 481 | clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table); |
| 482 | } |
| 483 | |
| 484 | 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] | 485 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 486 | sta ? sta->addr : NULL, ret); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 487 | |
| 488 | return ret; |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * iwlagn_alloc_bcast_station - add broadcast station into driver's station table. |
| 493 | * |
| 494 | * This adds the broadcast station into the driver's station table |
| 495 | * and marks it driver active, so that it will be restored to the |
| 496 | * device at the next best time. |
| 497 | */ |
| 498 | int iwlagn_alloc_bcast_station(struct iwl_priv *priv, |
| 499 | struct iwl_rxon_context *ctx) |
| 500 | { |
| 501 | struct iwl_link_quality_cmd *link_cmd; |
| 502 | unsigned long flags; |
| 503 | u8 sta_id; |
| 504 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 505 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 506 | sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL); |
| 507 | if (sta_id == IWL_INVALID_STATION) { |
| 508 | IWL_ERR(priv, "Unable to prepare broadcast station\n"); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 509 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 510 | |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | |
| 514 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; |
| 515 | priv->stations[sta_id].used |= IWL_STA_BCAST; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 516 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 517 | |
Johannes Berg | f775aa0 | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 518 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 519 | if (!link_cmd) { |
| 520 | IWL_ERR(priv, |
| 521 | "Unable to initialize rate scaling for bcast station.\n"); |
| 522 | return -ENOMEM; |
| 523 | } |
| 524 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 525 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 526 | priv->stations[sta_id].lq = link_cmd; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 527 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * iwl_update_bcast_station - update broadcast station's LQ command |
| 534 | * |
| 535 | * Only used by iwlagn. Placed here to have all bcast station management |
| 536 | * code together. |
| 537 | */ |
Johannes Berg | f775aa0 | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 538 | int iwl_update_bcast_station(struct iwl_priv *priv, |
| 539 | struct iwl_rxon_context *ctx) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 540 | { |
| 541 | unsigned long flags; |
| 542 | struct iwl_link_quality_cmd *link_cmd; |
| 543 | u8 sta_id = ctx->bcast_sta_id; |
| 544 | |
Johannes Berg | f775aa0 | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 545 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 546 | if (!link_cmd) { |
| 547 | IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n"); |
| 548 | return -ENOMEM; |
| 549 | } |
| 550 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 551 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 552 | if (priv->stations[sta_id].lq) |
| 553 | kfree(priv->stations[sta_id].lq); |
| 554 | else |
| 555 | IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n"); |
| 556 | priv->stations[sta_id].lq = link_cmd; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 557 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | int iwl_update_bcast_stations(struct iwl_priv *priv) |
| 563 | { |
| 564 | struct iwl_rxon_context *ctx; |
| 565 | int ret = 0; |
| 566 | |
| 567 | for_each_context(priv, ctx) { |
| 568 | ret = iwl_update_bcast_station(priv, ctx); |
| 569 | if (ret) |
| 570 | break; |
| 571 | } |
| 572 | |
| 573 | return ret; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table |
| 578 | */ |
| 579 | int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid) |
| 580 | { |
| 581 | unsigned long flags; |
| 582 | struct iwl_addsta_cmd sta_cmd; |
| 583 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 584 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 585 | |
| 586 | /* Remove "disable" flag, to enable Tx for this TID */ |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 587 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 588 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 589 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 590 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 591 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 592 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 593 | |
| 594 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 595 | } |
| 596 | |
| 597 | int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, |
| 598 | int tid, u16 ssn) |
| 599 | { |
| 600 | unsigned long flags; |
| 601 | int sta_id; |
| 602 | struct iwl_addsta_cmd sta_cmd; |
| 603 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 604 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 605 | |
| 606 | sta_id = iwl_sta_id(sta); |
| 607 | if (sta_id == IWL_INVALID_STATION) |
| 608 | return -ENXIO; |
| 609 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 610 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 611 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 612 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; |
| 613 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; |
| 614 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 615 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 616 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 617 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 618 | |
| 619 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 620 | } |
| 621 | |
| 622 | int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, |
| 623 | int tid) |
| 624 | { |
| 625 | unsigned long flags; |
| 626 | int sta_id; |
| 627 | struct iwl_addsta_cmd sta_cmd; |
| 628 | |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 629 | lockdep_assert_held(&priv->shrd->mutex); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 630 | |
| 631 | sta_id = iwl_sta_id(sta); |
| 632 | if (sta_id == IWL_INVALID_STATION) { |
| 633 | IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); |
| 634 | return -ENXIO; |
| 635 | } |
| 636 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 637 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 638 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 639 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; |
| 640 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; |
| 641 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 642 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 643 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 644 | |
| 645 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 646 | } |
| 647 | |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 648 | static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 649 | { |
| 650 | unsigned long flags; |
| 651 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 652 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 653 | priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK; |
| 654 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 655 | priv->stations[sta_id].sta.sta.modify_mask = 0; |
| 656 | priv->stations[sta_id].sta.sleep_tx_count = 0; |
| 657 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 658 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 659 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 660 | |
| 661 | } |
| 662 | |
| 663 | void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt) |
| 664 | { |
| 665 | unsigned long flags; |
| 666 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 667 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 668 | priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK; |
| 669 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 670 | priv->stations[sta_id].sta.sta.modify_mask = |
| 671 | STA_MODIFY_SLEEP_TX_COUNT_MSK; |
| 672 | priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt); |
| 673 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 674 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 675 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 676 | |
| 677 | } |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 678 | |
| 679 | void iwlagn_mac_sta_notify(struct ieee80211_hw *hw, |
| 680 | struct ieee80211_vif *vif, |
| 681 | enum sta_notify_cmd cmd, |
| 682 | struct ieee80211_sta *sta) |
| 683 | { |
| 684 | struct iwl_priv *priv = hw->priv; |
| 685 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 686 | int sta_id; |
| 687 | |
Wey-Yi Guy | 770c72c | 2011-10-10 07:27:10 -0700 | [diff] [blame^] | 688 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 689 | |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 690 | switch (cmd) { |
| 691 | case STA_NOTIFY_SLEEP: |
| 692 | WARN_ON(!sta_priv->client); |
| 693 | sta_priv->asleep = true; |
| 694 | if (atomic_read(&sta_priv->pending_frames) > 0) |
| 695 | ieee80211_sta_block_awake(hw, sta, true); |
| 696 | break; |
| 697 | case STA_NOTIFY_AWAKE: |
| 698 | WARN_ON(!sta_priv->client); |
| 699 | if (!sta_priv->asleep) |
| 700 | break; |
| 701 | sta_priv->asleep = false; |
| 702 | sta_id = iwl_sta_id(sta); |
| 703 | if (sta_id != IWL_INVALID_STATION) |
| 704 | iwl_sta_modify_ps_wake(priv, sta_id); |
| 705 | break; |
| 706 | default: |
| 707 | break; |
| 708 | } |
Wey-Yi Guy | 770c72c | 2011-10-10 07:27:10 -0700 | [diff] [blame^] | 709 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 710 | } |