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