Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [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 | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | *****************************************************************************/ |
| 26 | |
| 27 | #include "iwl-dev.h" |
| 28 | #include "iwl-agn.h" |
| 29 | #include "iwl-sta.h" |
| 30 | #include "iwl-core.h" |
| 31 | #include "iwl-agn-calib.h" |
Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame^] | 32 | #include "iwl-helpers.h" |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 33 | |
| 34 | static int iwlagn_disable_bss(struct iwl_priv *priv, |
| 35 | struct iwl_rxon_context *ctx, |
| 36 | struct iwl_rxon_cmd *send) |
| 37 | { |
| 38 | __le32 old_filter = send->filter_flags; |
| 39 | int ret; |
| 40 | |
| 41 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 42 | ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send); |
| 43 | |
| 44 | send->filter_flags = old_filter; |
| 45 | |
| 46 | if (ret) |
| 47 | IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret); |
| 48 | |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | static int iwlagn_disable_pan(struct iwl_priv *priv, |
| 53 | struct iwl_rxon_context *ctx, |
| 54 | struct iwl_rxon_cmd *send) |
| 55 | { |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 56 | struct iwl_notification_wait disable_wait; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 57 | __le32 old_filter = send->filter_flags; |
| 58 | u8 old_dev_type = send->dev_type; |
| 59 | int ret; |
| 60 | |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 61 | iwlagn_init_notification_wait(priv, &disable_wait, NULL, |
| 62 | REPLY_WIPAN_DEACTIVATION_COMPLETE); |
| 63 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 64 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 65 | send->dev_type = RXON_DEV_TYPE_P2P; |
| 66 | ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send); |
| 67 | |
| 68 | send->filter_flags = old_filter; |
| 69 | send->dev_type = old_dev_type; |
| 70 | |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 71 | if (ret) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 72 | IWL_ERR(priv, "Error disabling PAN (%d)\n", ret); |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 73 | iwlagn_remove_notification(priv, &disable_wait); |
| 74 | } else { |
| 75 | signed long wait_res; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 76 | |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 77 | wait_res = iwlagn_wait_notification(priv, &disable_wait, HZ); |
Johannes Berg | 2a1a78d | 2011-01-04 16:22:02 -0800 | [diff] [blame] | 78 | if (wait_res == 0) { |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 79 | IWL_ERR(priv, "Timed out waiting for PAN disable\n"); |
Johannes Berg | 2a1a78d | 2011-01-04 16:22:02 -0800 | [diff] [blame] | 80 | ret = -EIO; |
| 81 | } |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 82 | } |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 83 | |
| 84 | return ret; |
| 85 | } |
| 86 | |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 87 | static void iwlagn_update_qos(struct iwl_priv *priv, |
| 88 | struct iwl_rxon_context *ctx) |
| 89 | { |
| 90 | int ret; |
| 91 | |
| 92 | if (!ctx->is_active) |
| 93 | return; |
| 94 | |
| 95 | ctx->qos_data.def_qos_parm.qos_flags = 0; |
| 96 | |
| 97 | if (ctx->qos_data.qos_active) |
| 98 | ctx->qos_data.def_qos_parm.qos_flags |= |
| 99 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 100 | |
| 101 | if (ctx->ht.enabled) |
| 102 | ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; |
| 103 | |
| 104 | IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 105 | ctx->qos_data.qos_active, |
| 106 | ctx->qos_data.def_qos_parm.qos_flags); |
| 107 | |
| 108 | ret = iwl_send_cmd_pdu(priv, ctx->qos_cmd, |
| 109 | sizeof(struct iwl_qosparam_cmd), |
| 110 | &ctx->qos_data.def_qos_parm); |
| 111 | if (ret) |
| 112 | IWL_ERR(priv, "Failed to update QoS\n"); |
| 113 | } |
| 114 | |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 115 | static int iwlagn_update_beacon(struct iwl_priv *priv, |
| 116 | struct ieee80211_vif *vif) |
| 117 | { |
| 118 | lockdep_assert_held(&priv->mutex); |
| 119 | |
| 120 | dev_kfree_skb(priv->beacon_skb); |
| 121 | priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif); |
| 122 | if (!priv->beacon_skb) |
| 123 | return -ENOMEM; |
| 124 | return iwlagn_send_beacon_cmd(priv); |
| 125 | } |
| 126 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 127 | /** |
| 128 | * iwlagn_commit_rxon - commit staging_rxon to hardware |
| 129 | * |
| 130 | * The RXON command in staging_rxon is committed to the hardware and |
| 131 | * the active_rxon structure is updated with the new data. This |
| 132 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 133 | * a HW tune is required based on the RXON structure changes. |
| 134 | */ |
| 135 | int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
| 136 | { |
| 137 | /* cast away the const for active_rxon in this function */ |
| 138 | struct iwl_rxon_cmd *active = (void *)&ctx->active; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 139 | bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 140 | bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 141 | int ret; |
| 142 | |
| 143 | lockdep_assert_held(&priv->mutex); |
| 144 | |
Wey-Yi Guy | adb90a0 | 2010-11-26 11:09:42 -0800 | [diff] [blame] | 145 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 146 | return -EINVAL; |
| 147 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 148 | if (!iwl_is_alive(priv)) |
| 149 | return -EBUSY; |
| 150 | |
| 151 | /* This function hardcodes a bunch of dual-mode assumptions */ |
| 152 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 153 | |
| 154 | if (!ctx->is_active) |
| 155 | return 0; |
| 156 | |
| 157 | /* always get timestamp with Rx frame */ |
| 158 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; |
| 159 | |
Johannes Berg | 9b9190d | 2011-01-06 08:07:10 -0800 | [diff] [blame] | 160 | if (ctx->ctxid == IWL_RXON_CTX_PAN && priv->_agn.hw_roc_channel) { |
| 161 | struct ieee80211_channel *chan = priv->_agn.hw_roc_channel; |
| 162 | |
| 163 | iwl_set_rxon_channel(priv, chan, ctx); |
| 164 | iwl_set_flags_for_band(priv, ctx, chan->band, NULL); |
| 165 | ctx->staging.filter_flags |= |
| 166 | RXON_FILTER_ASSOC_MSK | |
| 167 | RXON_FILTER_PROMISC_MSK | |
| 168 | RXON_FILTER_CTL2HOST_MSK; |
| 169 | ctx->staging.dev_type = RXON_DEV_TYPE_P2P; |
| 170 | new_assoc = true; |
| 171 | |
| 172 | if (memcmp(&ctx->staging, &ctx->active, |
| 173 | sizeof(ctx->staging)) == 0) |
| 174 | return 0; |
| 175 | } |
| 176 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 177 | if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) || |
| 178 | !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK)) |
| 179 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 180 | else |
| 181 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 182 | |
| 183 | ret = iwl_check_rxon_cmd(priv, ctx); |
| 184 | if (ret) { |
| 185 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
| 186 | return -EINVAL; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * receive commit_rxon request |
| 191 | * abort any previous channel switch if still in process |
| 192 | */ |
| 193 | if (priv->switch_rxon.switch_in_progress && |
| 194 | (priv->switch_rxon.channel != ctx->staging.channel)) { |
| 195 | IWL_DEBUG_11H(priv, "abort channel switch on %d\n", |
| 196 | le16_to_cpu(priv->switch_rxon.channel)); |
| 197 | iwl_chswitch_done(priv, false); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * If we don't need to send a full RXON, we can use |
| 202 | * iwl_rxon_assoc_cmd which is used to reconfigure filter |
| 203 | * and other flags for the current radio configuration. |
| 204 | */ |
| 205 | if (!iwl_full_rxon_required(priv, ctx)) { |
| 206 | ret = iwl_send_rxon_assoc(priv, ctx); |
| 207 | if (ret) { |
| 208 | IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret); |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | memcpy(active, &ctx->staging, sizeof(*active)); |
| 213 | iwl_print_rx_config_cmd(priv, ctx); |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | if (priv->cfg->ops->hcmd->set_pan_params) { |
| 218 | ret = priv->cfg->ops->hcmd->set_pan_params(priv); |
| 219 | if (ret) |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto); |
| 224 | |
| 225 | IWL_DEBUG_INFO(priv, |
| 226 | "Going to commit RXON\n" |
| 227 | " * with%s RXON_FILTER_ASSOC_MSK\n" |
| 228 | " * channel = %d\n" |
| 229 | " * bssid = %pM\n", |
| 230 | (new_assoc ? "" : "out"), |
| 231 | le16_to_cpu(ctx->staging.channel), |
| 232 | ctx->staging.bssid_addr); |
| 233 | |
| 234 | /* |
Johannes Berg | 52d980c | 2010-11-10 09:56:45 -0800 | [diff] [blame] | 235 | * Always clear associated first, but with the correct config. |
| 236 | * This is required as for example station addition for the |
| 237 | * AP station must be done after the BSSID is set to correctly |
| 238 | * set up filters in the device. |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 239 | */ |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 240 | if ((old_assoc && new_assoc) || !new_assoc) { |
| 241 | if (ctx->ctxid == IWL_RXON_CTX_BSS) |
| 242 | ret = iwlagn_disable_bss(priv, ctx, &ctx->staging); |
| 243 | else |
| 244 | ret = iwlagn_disable_pan(priv, ctx, &ctx->staging); |
| 245 | if (ret) |
| 246 | return ret; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 247 | |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 248 | memcpy(active, &ctx->staging, sizeof(*active)); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 249 | |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 250 | /* |
| 251 | * Un-assoc RXON clears the station table and WEP |
| 252 | * keys, so we have to restore those afterwards. |
| 253 | */ |
| 254 | iwl_clear_ucode_stations(priv, ctx); |
| 255 | iwl_restore_stations(priv, ctx); |
| 256 | ret = iwl_restore_default_wep_keys(priv, ctx); |
| 257 | if (ret) { |
| 258 | IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); |
| 259 | return ret; |
| 260 | } |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* RXON timing must be before associated RXON */ |
| 264 | ret = iwl_send_rxon_timing(priv, ctx); |
| 265 | if (ret) { |
| 266 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); |
| 267 | return ret; |
| 268 | } |
| 269 | |
| 270 | if (new_assoc) { |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 271 | /* QoS info may be cleared by previous un-assoc RXON */ |
| 272 | iwlagn_update_qos(priv, ctx); |
| 273 | |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 274 | /* |
| 275 | * We'll run into this code path when beaconing is |
| 276 | * enabled, but then we also need to send the beacon |
| 277 | * to the device. |
| 278 | */ |
| 279 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) { |
| 280 | ret = iwlagn_update_beacon(priv, ctx->vif); |
| 281 | if (ret) { |
| 282 | IWL_ERR(priv, |
| 283 | "Error sending required beacon (%d)!\n", |
| 284 | ret); |
| 285 | return ret; |
| 286 | } |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | priv->start_calib = 0; |
| 290 | /* |
| 291 | * Apply the new configuration. |
| 292 | * |
| 293 | * Associated RXON doesn't clear the station table in uCode, |
| 294 | * so we don't need to restore stations etc. after this. |
| 295 | */ |
| 296 | ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, |
| 297 | sizeof(struct iwl_rxon_cmd), &ctx->staging); |
| 298 | if (ret) { |
| 299 | IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); |
| 300 | return ret; |
| 301 | } |
| 302 | memcpy(active, &ctx->staging, sizeof(*active)); |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 303 | |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 304 | iwl_reprogram_ap_sta(priv, ctx); |
| 305 | |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 306 | /* IBSS beacon needs to be sent after setting assoc */ |
| 307 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC)) |
| 308 | if (iwlagn_update_beacon(priv, ctx->vif)) |
| 309 | IWL_ERR(priv, "Error sending IBSS beacon\n"); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | iwl_print_rx_config_cmd(priv, ctx); |
| 313 | |
| 314 | iwl_init_sensitivity(priv); |
| 315 | |
| 316 | /* |
| 317 | * If we issue a new RXON command which required a tune then we must |
| 318 | * send a new TXPOWER command or we won't be able to Tx any frames. |
| 319 | * |
Stanislaw Gruszka | f844a70 | 2011-01-28 16:47:44 +0100 | [diff] [blame] | 320 | * It's expected we set power here if channel is changing. |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 321 | */ |
Stanislaw Gruszka | f844a70 | 2011-01-28 16:47:44 +0100 | [diff] [blame] | 322 | ret = iwl_set_tx_power(priv, priv->tx_power_next, true); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 323 | if (ret) { |
| 324 | IWL_ERR(priv, "Error sending TX power (%d)\n", ret); |
| 325 | return ret; |
| 326 | } |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 332 | { |
| 333 | struct iwl_priv *priv = hw->priv; |
| 334 | struct iwl_rxon_context *ctx; |
| 335 | struct ieee80211_conf *conf = &hw->conf; |
| 336 | struct ieee80211_channel *channel = conf->channel; |
| 337 | const struct iwl_channel_info *ch_info; |
| 338 | int ret = 0; |
Wey-Yi Guy | 35a6eb3 | 2010-11-10 09:56:43 -0800 | [diff] [blame] | 339 | bool ht_changed[NUM_IWL_RXON_CTX] = {}; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 340 | |
| 341 | IWL_DEBUG_MAC80211(priv, "changed %#x", changed); |
| 342 | |
| 343 | mutex_lock(&priv->mutex); |
| 344 | |
| 345 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
| 346 | IWL_DEBUG_MAC80211(priv, "leave - scanning\n"); |
| 347 | goto out; |
| 348 | } |
| 349 | |
| 350 | if (!iwl_is_ready(priv)) { |
| 351 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
| 352 | goto out; |
| 353 | } |
| 354 | |
| 355 | if (changed & (IEEE80211_CONF_CHANGE_SMPS | |
| 356 | IEEE80211_CONF_CHANGE_CHANNEL)) { |
| 357 | /* mac80211 uses static for non-HT which is what we want */ |
| 358 | priv->current_ht_config.smps = conf->smps_mode; |
| 359 | |
| 360 | /* |
| 361 | * Recalculate chain counts. |
| 362 | * |
| 363 | * If monitor mode is enabled then mac80211 will |
| 364 | * set up the SM PS mode to OFF if an HT channel is |
| 365 | * configured. |
| 366 | */ |
| 367 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
| 368 | for_each_context(priv, ctx) |
| 369 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
| 370 | } |
| 371 | |
| 372 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 373 | unsigned long flags; |
| 374 | |
| 375 | ch_info = iwl_get_channel_info(priv, channel->band, |
| 376 | channel->hw_value); |
| 377 | if (!is_channel_valid(ch_info)) { |
| 378 | IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n"); |
| 379 | ret = -EINVAL; |
| 380 | goto out; |
| 381 | } |
| 382 | |
| 383 | spin_lock_irqsave(&priv->lock, flags); |
| 384 | |
| 385 | for_each_context(priv, ctx) { |
| 386 | /* Configure HT40 channels */ |
Wey-Yi Guy | 35a6eb3 | 2010-11-10 09:56:43 -0800 | [diff] [blame] | 387 | if (ctx->ht.enabled != conf_is_ht(conf)) { |
| 388 | ctx->ht.enabled = conf_is_ht(conf); |
| 389 | ht_changed[ctx->ctxid] = true; |
| 390 | } |
| 391 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 392 | if (ctx->ht.enabled) { |
| 393 | if (conf_is_ht40_minus(conf)) { |
| 394 | ctx->ht.extension_chan_offset = |
| 395 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
| 396 | ctx->ht.is_40mhz = true; |
| 397 | } else if (conf_is_ht40_plus(conf)) { |
| 398 | ctx->ht.extension_chan_offset = |
| 399 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
| 400 | ctx->ht.is_40mhz = true; |
| 401 | } else { |
| 402 | ctx->ht.extension_chan_offset = |
| 403 | IEEE80211_HT_PARAM_CHA_SEC_NONE; |
| 404 | ctx->ht.is_40mhz = false; |
| 405 | } |
| 406 | } else |
| 407 | ctx->ht.is_40mhz = false; |
| 408 | |
| 409 | /* |
| 410 | * Default to no protection. Protection mode will |
| 411 | * later be set from BSS config in iwl_ht_conf |
| 412 | */ |
| 413 | ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE; |
| 414 | |
| 415 | /* if we are switching from ht to 2.4 clear flags |
| 416 | * from any ht related info since 2.4 does not |
| 417 | * support ht */ |
| 418 | if (le16_to_cpu(ctx->staging.channel) != |
| 419 | channel->hw_value) |
| 420 | ctx->staging.flags = 0; |
| 421 | |
| 422 | iwl_set_rxon_channel(priv, channel, ctx); |
| 423 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
| 424 | |
| 425 | iwl_set_flags_for_band(priv, ctx, channel->band, |
| 426 | ctx->vif); |
| 427 | } |
| 428 | |
| 429 | spin_unlock_irqrestore(&priv->lock, flags); |
| 430 | |
| 431 | iwl_update_bcast_stations(priv); |
| 432 | |
| 433 | /* |
| 434 | * The list of supported rates and rate mask can be different |
| 435 | * for each band; since the band may have changed, reset |
| 436 | * the rate mask to what mac80211 lists. |
| 437 | */ |
| 438 | iwl_set_rate(priv); |
| 439 | } |
| 440 | |
| 441 | if (changed & (IEEE80211_CONF_CHANGE_PS | |
| 442 | IEEE80211_CONF_CHANGE_IDLE)) { |
| 443 | ret = iwl_power_update_mode(priv, false); |
| 444 | if (ret) |
| 445 | IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n"); |
| 446 | } |
| 447 | |
| 448 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 449 | IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n", |
| 450 | priv->tx_power_user_lmt, conf->power_level); |
| 451 | |
| 452 | iwl_set_tx_power(priv, conf->power_level, false); |
| 453 | } |
| 454 | |
| 455 | for_each_context(priv, ctx) { |
| 456 | if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 457 | continue; |
| 458 | iwlagn_commit_rxon(priv, ctx); |
Wey-Yi Guy | 35a6eb3 | 2010-11-10 09:56:43 -0800 | [diff] [blame] | 459 | if (ht_changed[ctx->ctxid]) |
| 460 | iwlagn_update_qos(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 461 | } |
| 462 | out: |
| 463 | mutex_unlock(&priv->mutex); |
| 464 | return ret; |
| 465 | } |
| 466 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 467 | static void iwlagn_check_needed_chains(struct iwl_priv *priv, |
| 468 | struct iwl_rxon_context *ctx, |
| 469 | struct ieee80211_bss_conf *bss_conf) |
| 470 | { |
| 471 | struct ieee80211_vif *vif = ctx->vif; |
| 472 | struct iwl_rxon_context *tmp; |
| 473 | struct ieee80211_sta *sta; |
| 474 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 475 | struct ieee80211_sta_ht_cap *ht_cap; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 476 | bool need_multiple; |
| 477 | |
| 478 | lockdep_assert_held(&priv->mutex); |
| 479 | |
| 480 | switch (vif->type) { |
| 481 | case NL80211_IFTYPE_STATION: |
| 482 | rcu_read_lock(); |
| 483 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 484 | if (!sta) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 485 | /* |
| 486 | * If at all, this can only happen through a race |
| 487 | * when the AP disconnects us while we're still |
| 488 | * setting up the connection, in that case mac80211 |
| 489 | * will soon tell us about that. |
| 490 | */ |
| 491 | need_multiple = false; |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 492 | rcu_read_unlock(); |
| 493 | break; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 494 | } |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 495 | |
| 496 | ht_cap = &sta->ht_cap; |
| 497 | |
| 498 | need_multiple = true; |
| 499 | |
| 500 | /* |
| 501 | * If the peer advertises no support for receiving 2 and 3 |
| 502 | * stream MCS rates, it can't be transmitting them either. |
| 503 | */ |
| 504 | if (ht_cap->mcs.rx_mask[1] == 0 && |
| 505 | ht_cap->mcs.rx_mask[2] == 0) { |
| 506 | need_multiple = false; |
| 507 | } else if (!(ht_cap->mcs.tx_params & |
| 508 | IEEE80211_HT_MCS_TX_DEFINED)) { |
| 509 | /* If it can't TX MCS at all ... */ |
| 510 | need_multiple = false; |
| 511 | } else if (ht_cap->mcs.tx_params & |
| 512 | IEEE80211_HT_MCS_TX_RX_DIFF) { |
| 513 | int maxstreams; |
| 514 | |
| 515 | /* |
| 516 | * But if it can receive them, it might still not |
| 517 | * be able to transmit them, which is what we need |
| 518 | * to check here -- so check the number of streams |
| 519 | * it advertises for TX (if different from RX). |
| 520 | */ |
| 521 | |
| 522 | maxstreams = (ht_cap->mcs.tx_params & |
| 523 | IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK); |
| 524 | maxstreams >>= |
| 525 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; |
| 526 | maxstreams += 1; |
| 527 | |
| 528 | if (maxstreams <= 1) |
| 529 | need_multiple = false; |
| 530 | } |
| 531 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 532 | rcu_read_unlock(); |
| 533 | break; |
| 534 | case NL80211_IFTYPE_ADHOC: |
| 535 | /* currently */ |
| 536 | need_multiple = false; |
| 537 | break; |
| 538 | default: |
| 539 | /* only AP really */ |
| 540 | need_multiple = true; |
| 541 | break; |
| 542 | } |
| 543 | |
| 544 | ctx->ht_need_multiple_chains = need_multiple; |
| 545 | |
| 546 | if (!need_multiple) { |
| 547 | /* check all contexts */ |
| 548 | for_each_context(priv, tmp) { |
| 549 | if (!tmp->vif) |
| 550 | continue; |
| 551 | if (tmp->ht_need_multiple_chains) { |
| 552 | need_multiple = true; |
| 553 | break; |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | ht_conf->single_chain_sufficient = !need_multiple; |
| 559 | } |
| 560 | |
| 561 | void iwlagn_bss_info_changed(struct ieee80211_hw *hw, |
| 562 | struct ieee80211_vif *vif, |
| 563 | struct ieee80211_bss_conf *bss_conf, |
| 564 | u32 changes) |
| 565 | { |
| 566 | struct iwl_priv *priv = hw->priv; |
| 567 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
| 568 | int ret; |
| 569 | bool force = false; |
| 570 | |
| 571 | mutex_lock(&priv->mutex); |
| 572 | |
Shanyu Zhao | ae0b693 | 2010-12-02 11:02:28 -0800 | [diff] [blame] | 573 | if (unlikely(!iwl_is_ready(priv))) { |
Wey-Yi Guy | 14a085e | 2010-12-14 07:38:58 -0800 | [diff] [blame] | 574 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
| 575 | mutex_unlock(&priv->mutex); |
Shanyu Zhao | ae0b693 | 2010-12-02 11:02:28 -0800 | [diff] [blame] | 576 | return; |
| 577 | } |
| 578 | |
| 579 | if (unlikely(!ctx->vif)) { |
| 580 | IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n"); |
Johannes Berg | 893654d | 2010-11-10 18:25:47 -0800 | [diff] [blame] | 581 | mutex_unlock(&priv->mutex); |
| 582 | return; |
| 583 | } |
| 584 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 585 | if (changes & BSS_CHANGED_BEACON_INT) |
| 586 | force = true; |
| 587 | |
| 588 | if (changes & BSS_CHANGED_QOS) { |
| 589 | ctx->qos_data.qos_active = bss_conf->qos; |
| 590 | iwlagn_update_qos(priv, ctx); |
| 591 | } |
| 592 | |
| 593 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); |
| 594 | if (vif->bss_conf.use_short_preamble) |
| 595 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 596 | else |
| 597 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 598 | |
| 599 | if (changes & BSS_CHANGED_ASSOC) { |
| 600 | if (bss_conf->assoc) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 601 | priv->timestamp = bss_conf->timestamp; |
| 602 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 603 | } else { |
Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame^] | 604 | /* |
| 605 | * If we disassociate while there are pending |
| 606 | * frames, just wake up the queues and let the |
| 607 | * frames "escape" ... This shouldn't really |
| 608 | * be happening to start with, but we should |
| 609 | * not get stuck in this case either since it |
| 610 | * can happen if userspace gets confused. |
| 611 | */ |
| 612 | if (ctx->last_tx_rejected) { |
| 613 | ctx->last_tx_rejected = false; |
| 614 | iwl_wake_any_queue(priv, ctx); |
| 615 | } |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 616 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | if (ctx->ht.enabled) { |
| 621 | ctx->ht.protection = bss_conf->ht_operation_mode & |
| 622 | IEEE80211_HT_OP_MODE_PROTECTION; |
| 623 | ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode & |
| 624 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); |
| 625 | iwlagn_check_needed_chains(priv, ctx, bss_conf); |
Johannes Berg | b2769b8 | 2010-11-10 09:56:47 -0800 | [diff] [blame] | 626 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
| 630 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
| 631 | |
| 632 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
| 633 | ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 634 | else |
| 635 | ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 636 | |
| 637 | if (bss_conf->use_cts_prot) |
| 638 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; |
| 639 | else |
| 640 | ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN; |
| 641 | |
| 642 | memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN); |
| 643 | |
| 644 | if (vif->type == NL80211_IFTYPE_AP || |
| 645 | vif->type == NL80211_IFTYPE_ADHOC) { |
| 646 | if (vif->bss_conf.enable_beacon) { |
| 647 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 648 | priv->beacon_ctx = ctx; |
| 649 | } else { |
| 650 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 651 | priv->beacon_ctx = NULL; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 656 | iwlagn_commit_rxon(priv, ctx); |
| 657 | |
Johannes Berg | 8da8e62 | 2010-11-10 09:56:46 -0800 | [diff] [blame] | 658 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { |
| 659 | /* |
| 660 | * The chain noise calibration will enable PM upon |
| 661 | * completion. If calibration has already been run |
| 662 | * then we need to enable power management here. |
| 663 | */ |
| 664 | if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE) |
| 665 | iwl_power_update_mode(priv, false); |
| 666 | |
| 667 | /* Enable RX differential gain and sensitivity calibrations */ |
| 668 | iwl_chain_noise_reset(priv); |
| 669 | priv->start_calib = 1; |
| 670 | } |
| 671 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 672 | if (changes & BSS_CHANGED_IBSS) { |
| 673 | ret = iwlagn_manage_ibss_station(priv, vif, |
| 674 | bss_conf->ibss_joined); |
| 675 | if (ret) |
| 676 | IWL_ERR(priv, "failed to %s IBSS station %pM\n", |
| 677 | bss_conf->ibss_joined ? "add" : "remove", |
| 678 | bss_conf->bssid); |
| 679 | } |
| 680 | |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 681 | if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC && |
| 682 | priv->beacon_ctx) { |
| 683 | if (iwlagn_update_beacon(priv, vif)) |
| 684 | IWL_ERR(priv, "Error sending IBSS beacon\n"); |
| 685 | } |
| 686 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 687 | mutex_unlock(&priv->mutex); |
| 688 | } |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 689 | |
| 690 | void iwlagn_post_scan(struct iwl_priv *priv) |
| 691 | { |
| 692 | struct iwl_rxon_context *ctx; |
| 693 | |
| 694 | /* |
| 695 | * Since setting the RXON may have been deferred while |
| 696 | * performing the scan, fire one off if needed |
| 697 | */ |
| 698 | for_each_context(priv, ctx) |
| 699 | if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 700 | iwlagn_commit_rxon(priv, ctx); |
| 701 | |
| 702 | if (priv->cfg->ops->hcmd->set_pan_params) |
| 703 | priv->cfg->ops->hcmd->set_pan_params(priv); |
| 704 | } |