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