Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | fb4961d | 2012-01-06 13:16:33 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2012 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 | |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 28 | #include "iwl-dev.h" |
| 29 | #include "iwl-agn.h" |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 30 | #include "iwl-agn-calib.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 31 | #include "iwl-trans.h" |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 32 | #include "iwl-modparams.h" |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 33 | |
Meenakshi Venkataraman | 47042ac | 2012-03-13 17:07:48 -0700 | [diff] [blame] | 34 | /* |
| 35 | * initialize rxon structure with default values from eeprom |
| 36 | */ |
| 37 | void iwl_connection_init_rx_config(struct iwl_priv *priv, |
| 38 | struct iwl_rxon_context *ctx) |
| 39 | { |
| 40 | const struct iwl_channel_info *ch_info; |
| 41 | |
| 42 | memset(&ctx->staging, 0, sizeof(ctx->staging)); |
| 43 | |
| 44 | if (!ctx->vif) { |
| 45 | ctx->staging.dev_type = ctx->unused_devtype; |
| 46 | } else |
| 47 | switch (ctx->vif->type) { |
| 48 | case NL80211_IFTYPE_AP: |
| 49 | ctx->staging.dev_type = ctx->ap_devtype; |
| 50 | break; |
| 51 | |
| 52 | case NL80211_IFTYPE_STATION: |
| 53 | ctx->staging.dev_type = ctx->station_devtype; |
| 54 | ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 55 | break; |
| 56 | |
| 57 | case NL80211_IFTYPE_ADHOC: |
| 58 | ctx->staging.dev_type = ctx->ibss_devtype; |
| 59 | ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 60 | ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 61 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 62 | break; |
| 63 | |
| 64 | default: |
| 65 | IWL_ERR(priv, "Unsupported interface type %d\n", |
| 66 | ctx->vif->type); |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | #if 0 |
| 71 | /* TODO: Figure out when short_preamble would be set and cache from |
| 72 | * that */ |
| 73 | if (!hw_to_local(priv->hw)->short_preamble) |
| 74 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 75 | else |
| 76 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 77 | #endif |
| 78 | |
| 79 | ch_info = iwl_get_channel_info(priv, priv->band, |
| 80 | le16_to_cpu(ctx->active.channel)); |
| 81 | |
| 82 | if (!ch_info) |
| 83 | ch_info = &priv->channel_info[0]; |
| 84 | |
| 85 | ctx->staging.channel = cpu_to_le16(ch_info->channel); |
| 86 | priv->band = ch_info->band; |
| 87 | |
| 88 | iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif); |
| 89 | |
Meenakshi Venkataraman | 47042ac | 2012-03-13 17:07:48 -0700 | [diff] [blame] | 90 | /* clear both MIX and PURE40 mode flag */ |
| 91 | ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED | |
| 92 | RXON_FLG_CHANNEL_MODE_PURE_40); |
| 93 | if (ctx->vif) |
| 94 | memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN); |
| 95 | |
| 96 | ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff; |
| 97 | ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 98 | ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff; |
| 99 | } |
| 100 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 101 | static int iwlagn_disable_bss(struct iwl_priv *priv, |
| 102 | struct iwl_rxon_context *ctx, |
| 103 | struct iwl_rxon_cmd *send) |
| 104 | { |
| 105 | __le32 old_filter = send->filter_flags; |
| 106 | int ret; |
| 107 | |
| 108 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 109 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 110 | CMD_SYNC, sizeof(*send), send); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 111 | |
| 112 | send->filter_flags = old_filter; |
| 113 | |
| 114 | if (ret) |
Todd Previte | b36b110 | 2011-11-10 06:55:02 -0800 | [diff] [blame] | 115 | IWL_DEBUG_QUIET_RFKILL(priv, |
| 116 | "Error clearing ASSOC_MSK on BSS (%d)\n", ret); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 117 | |
| 118 | return ret; |
| 119 | } |
| 120 | |
| 121 | static int iwlagn_disable_pan(struct iwl_priv *priv, |
| 122 | struct iwl_rxon_context *ctx, |
| 123 | struct iwl_rxon_cmd *send) |
| 124 | { |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 125 | struct iwl_notification_wait disable_wait; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 126 | __le32 old_filter = send->filter_flags; |
| 127 | u8 old_dev_type = send->dev_type; |
| 128 | int ret; |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 129 | static const u8 deactivate_cmd[] = { |
| 130 | REPLY_WIPAN_DEACTIVATION_COMPLETE |
| 131 | }; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 132 | |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 133 | iwl_init_notification_wait(&priv->notif_wait, &disable_wait, |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 134 | deactivate_cmd, ARRAY_SIZE(deactivate_cmd), |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 135 | NULL, NULL); |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 136 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 137 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 138 | send->dev_type = RXON_DEV_TYPE_P2P; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 139 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 140 | CMD_SYNC, sizeof(*send), send); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 141 | |
| 142 | send->filter_flags = old_filter; |
| 143 | send->dev_type = old_dev_type; |
| 144 | |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 145 | if (ret) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 146 | IWL_ERR(priv, "Error disabling PAN (%d)\n", ret); |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 147 | iwl_remove_notification(&priv->notif_wait, &disable_wait); |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 148 | } else { |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 149 | ret = iwl_wait_notification(&priv->notif_wait, |
| 150 | &disable_wait, HZ); |
Johannes Berg | a8674a1 | 2011-04-13 03:14:48 -0700 | [diff] [blame] | 151 | if (ret) |
Johannes Berg | 311dce7 | 2011-01-04 16:22:01 -0800 | [diff] [blame] | 152 | IWL_ERR(priv, "Timed out waiting for PAN disable\n"); |
| 153 | } |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 154 | |
| 155 | return ret; |
| 156 | } |
| 157 | |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 158 | static int iwlagn_disconn_pan(struct iwl_priv *priv, |
| 159 | struct iwl_rxon_context *ctx, |
| 160 | struct iwl_rxon_cmd *send) |
| 161 | { |
| 162 | __le32 old_filter = send->filter_flags; |
| 163 | int ret; |
| 164 | |
| 165 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 166 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 167 | sizeof(*send), send); |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 168 | |
| 169 | send->filter_flags = old_filter; |
| 170 | |
| 171 | return ret; |
| 172 | } |
| 173 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 174 | void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 175 | { |
| 176 | int ret; |
| 177 | |
| 178 | if (!ctx->is_active) |
| 179 | return; |
| 180 | |
| 181 | ctx->qos_data.def_qos_parm.qos_flags = 0; |
| 182 | |
| 183 | if (ctx->qos_data.qos_active) |
| 184 | ctx->qos_data.def_qos_parm.qos_flags |= |
| 185 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 186 | |
| 187 | if (ctx->ht.enabled) |
| 188 | ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; |
| 189 | |
Emmanuel Grumbach | 0dcf50c | 2011-11-10 06:55:23 -0800 | [diff] [blame] | 190 | IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 191 | ctx->qos_data.qos_active, |
| 192 | ctx->qos_data.def_qos_parm.qos_flags); |
| 193 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 194 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC, |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 195 | sizeof(struct iwl_qosparam_cmd), |
| 196 | &ctx->qos_data.def_qos_parm); |
| 197 | if (ret) |
Todd Previte | b36b110 | 2011-11-10 06:55:02 -0800 | [diff] [blame] | 198 | IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n"); |
Shanyu Zhao | f4115d4 | 2010-11-10 18:25:58 -0800 | [diff] [blame] | 199 | } |
| 200 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 201 | int iwlagn_update_beacon(struct iwl_priv *priv, |
| 202 | struct ieee80211_vif *vif) |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 203 | { |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 204 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 205 | |
| 206 | dev_kfree_skb(priv->beacon_skb); |
| 207 | priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif); |
| 208 | if (!priv->beacon_skb) |
| 209 | return -ENOMEM; |
| 210 | return iwlagn_send_beacon_cmd(priv); |
| 211 | } |
| 212 | |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 213 | static int iwlagn_send_rxon_assoc(struct iwl_priv *priv, |
| 214 | struct iwl_rxon_context *ctx) |
| 215 | { |
| 216 | int ret = 0; |
Wey-Yi Guy | 89e746b | 2011-04-19 16:52:58 -0700 | [diff] [blame] | 217 | struct iwl_rxon_assoc_cmd rxon_assoc; |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 218 | const struct iwl_rxon_cmd *rxon1 = &ctx->staging; |
| 219 | const struct iwl_rxon_cmd *rxon2 = &ctx->active; |
| 220 | |
| 221 | if ((rxon1->flags == rxon2->flags) && |
| 222 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 223 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 224 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 225 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 226 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 227 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 228 | (rxon1->ofdm_ht_triple_stream_basic_rates == |
| 229 | rxon2->ofdm_ht_triple_stream_basic_rates) && |
| 230 | (rxon1->acquisition_data == rxon2->acquisition_data) && |
| 231 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 232 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 233 | IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n"); |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | rxon_assoc.flags = ctx->staging.flags; |
| 238 | rxon_assoc.filter_flags = ctx->staging.filter_flags; |
| 239 | rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates; |
| 240 | rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates; |
| 241 | rxon_assoc.reserved1 = 0; |
| 242 | rxon_assoc.reserved2 = 0; |
| 243 | rxon_assoc.reserved3 = 0; |
| 244 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 245 | ctx->staging.ofdm_ht_single_stream_basic_rates; |
| 246 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 247 | ctx->staging.ofdm_ht_dual_stream_basic_rates; |
| 248 | rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain; |
| 249 | rxon_assoc.ofdm_ht_triple_stream_basic_rates = |
| 250 | ctx->staging.ofdm_ht_triple_stream_basic_rates; |
| 251 | rxon_assoc.acquisition_data = ctx->staging.acquisition_data; |
| 252 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 253 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 254 | CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc); |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 255 | return ret; |
| 256 | } |
| 257 | |
Meenakshi Venkataraman | dff96c1 | 2012-03-15 13:26:59 -0700 | [diff] [blame] | 258 | static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val) |
| 259 | { |
| 260 | u16 new_val; |
| 261 | u16 beacon_factor; |
| 262 | |
| 263 | /* |
| 264 | * If mac80211 hasn't given us a beacon interval, program |
| 265 | * the default into the device (not checking this here |
| 266 | * would cause the adjustment below to return the maximum |
| 267 | * value, which may break PAN.) |
| 268 | */ |
| 269 | if (!beacon_val) |
| 270 | return DEFAULT_BEACON_INTERVAL; |
| 271 | |
| 272 | /* |
| 273 | * If the beacon interval we obtained from the peer |
| 274 | * is too large, we'll have to wake up more often |
| 275 | * (and in IBSS case, we'll beacon too much) |
| 276 | * |
| 277 | * For example, if max_beacon_val is 4096, and the |
| 278 | * requested beacon interval is 7000, we'll have to |
| 279 | * use 3500 to be able to wake up on the beacons. |
| 280 | * |
| 281 | * This could badly influence beacon detection stats. |
| 282 | */ |
| 283 | |
| 284 | beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val; |
| 285 | new_val = beacon_val / beacon_factor; |
| 286 | |
| 287 | if (!new_val) |
| 288 | new_val = max_beacon_val; |
| 289 | |
| 290 | return new_val; |
| 291 | } |
| 292 | |
| 293 | static int iwl_send_rxon_timing(struct iwl_priv *priv, |
| 294 | struct iwl_rxon_context *ctx) |
| 295 | { |
| 296 | u64 tsf; |
| 297 | s32 interval_tm, rem; |
| 298 | struct ieee80211_conf *conf = NULL; |
| 299 | u16 beacon_int; |
| 300 | struct ieee80211_vif *vif = ctx->vif; |
| 301 | |
| 302 | conf = &priv->hw->conf; |
| 303 | |
| 304 | lockdep_assert_held(&priv->mutex); |
| 305 | |
| 306 | memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
| 307 | |
| 308 | ctx->timing.timestamp = cpu_to_le64(priv->timestamp); |
| 309 | ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval); |
| 310 | |
| 311 | beacon_int = vif ? vif->bss_conf.beacon_int : 0; |
| 312 | |
| 313 | /* |
| 314 | * TODO: For IBSS we need to get atim_window from mac80211, |
| 315 | * for now just always use 0 |
| 316 | */ |
| 317 | ctx->timing.atim_window = 0; |
| 318 | |
| 319 | if (ctx->ctxid == IWL_RXON_CTX_PAN && |
| 320 | (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) && |
| 321 | iwl_is_associated(priv, IWL_RXON_CTX_BSS) && |
| 322 | priv->contexts[IWL_RXON_CTX_BSS].vif && |
| 323 | priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) { |
| 324 | ctx->timing.beacon_interval = |
| 325 | priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval; |
| 326 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); |
| 327 | } else if (ctx->ctxid == IWL_RXON_CTX_BSS && |
| 328 | iwl_is_associated(priv, IWL_RXON_CTX_PAN) && |
| 329 | priv->contexts[IWL_RXON_CTX_PAN].vif && |
| 330 | priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int && |
| 331 | (!iwl_is_associated_ctx(ctx) || !ctx->vif || |
| 332 | !ctx->vif->bss_conf.beacon_int)) { |
| 333 | ctx->timing.beacon_interval = |
| 334 | priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval; |
| 335 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); |
| 336 | } else { |
| 337 | beacon_int = iwl_adjust_beacon_interval(beacon_int, |
| 338 | IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT); |
| 339 | ctx->timing.beacon_interval = cpu_to_le16(beacon_int); |
| 340 | } |
| 341 | |
| 342 | ctx->beacon_int = beacon_int; |
| 343 | |
| 344 | tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */ |
| 345 | interval_tm = beacon_int * TIME_UNIT; |
| 346 | rem = do_div(tsf, interval_tm); |
| 347 | ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem); |
| 348 | |
| 349 | ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1; |
| 350 | |
| 351 | IWL_DEBUG_ASSOC(priv, |
| 352 | "beacon interval %d beacon timer %d beacon tim %d\n", |
| 353 | le16_to_cpu(ctx->timing.beacon_interval), |
| 354 | le32_to_cpu(ctx->timing.beacon_init_val), |
| 355 | le16_to_cpu(ctx->timing.atim_window)); |
| 356 | |
| 357 | return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd, |
| 358 | CMD_SYNC, sizeof(ctx->timing), &ctx->timing); |
| 359 | } |
| 360 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 361 | static int iwlagn_rxon_disconn(struct iwl_priv *priv, |
| 362 | struct iwl_rxon_context *ctx) |
| 363 | { |
| 364 | int ret; |
| 365 | struct iwl_rxon_cmd *active = (void *)&ctx->active; |
| 366 | |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 367 | if (ctx->ctxid == IWL_RXON_CTX_BSS) { |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 368 | ret = iwlagn_disable_bss(priv, ctx, &ctx->staging); |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 369 | } else { |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 370 | ret = iwlagn_disable_pan(priv, ctx, &ctx->staging); |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 371 | if (ret) |
| 372 | return ret; |
| 373 | if (ctx->vif) { |
| 374 | ret = iwl_send_rxon_timing(priv, ctx); |
| 375 | if (ret) { |
| 376 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); |
| 377 | return ret; |
| 378 | } |
| 379 | ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging); |
| 380 | } |
| 381 | } |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 382 | if (ret) |
| 383 | return ret; |
| 384 | |
| 385 | /* |
| 386 | * Un-assoc RXON clears the station table and WEP |
| 387 | * keys, so we have to restore those afterwards. |
| 388 | */ |
| 389 | iwl_clear_ucode_stations(priv, ctx); |
Johannes Berg | f775aa06d | 2011-06-22 06:34:09 -0700 | [diff] [blame] | 390 | /* update -- might need P2P now */ |
| 391 | iwl_update_bcast_station(priv, ctx); |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 392 | iwl_restore_stations(priv, ctx); |
| 393 | ret = iwl_restore_default_wep_keys(priv, ctx); |
| 394 | if (ret) { |
| 395 | IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); |
| 396 | return ret; |
| 397 | } |
| 398 | |
| 399 | memcpy(active, &ctx->staging, sizeof(*active)); |
| 400 | return 0; |
| 401 | } |
| 402 | |
Meenakshi Venkataraman | e6a62a6 | 2012-03-13 18:10:19 -0700 | [diff] [blame] | 403 | static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) |
| 404 | { |
| 405 | int ret; |
| 406 | s8 prev_tx_power; |
| 407 | bool defer; |
| 408 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 409 | |
Dor Shaish | bfb45f5 | 2012-03-26 08:20:55 -0700 | [diff] [blame] | 410 | if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED) |
| 411 | return 0; |
| 412 | |
Meenakshi Venkataraman | e6a62a6 | 2012-03-13 18:10:19 -0700 | [diff] [blame] | 413 | lockdep_assert_held(&priv->mutex); |
| 414 | |
| 415 | if (priv->tx_power_user_lmt == tx_power && !force) |
| 416 | return 0; |
| 417 | |
| 418 | if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) { |
| 419 | IWL_WARN(priv, |
| 420 | "Requested user TXPOWER %d below lower limit %d.\n", |
| 421 | tx_power, |
| 422 | IWLAGN_TX_POWER_TARGET_POWER_MIN); |
| 423 | return -EINVAL; |
| 424 | } |
| 425 | |
| 426 | if (tx_power > priv->tx_power_device_lmt) { |
| 427 | IWL_WARN(priv, |
| 428 | "Requested user TXPOWER %d above upper limit %d.\n", |
| 429 | tx_power, priv->tx_power_device_lmt); |
| 430 | return -EINVAL; |
| 431 | } |
| 432 | |
| 433 | if (!iwl_is_ready_rf(priv)) |
| 434 | return -EIO; |
| 435 | |
| 436 | /* scan complete and commit_rxon use tx_power_next value, |
| 437 | * it always need to be updated for newest request */ |
| 438 | priv->tx_power_next = tx_power; |
| 439 | |
| 440 | /* do not set tx power when scanning or channel changing */ |
| 441 | defer = test_bit(STATUS_SCANNING, &priv->status) || |
| 442 | memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)); |
| 443 | if (defer && !force) { |
| 444 | IWL_DEBUG_INFO(priv, "Deferring tx power set\n"); |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | prev_tx_power = priv->tx_power_user_lmt; |
| 449 | priv->tx_power_user_lmt = tx_power; |
| 450 | |
| 451 | ret = iwlagn_send_tx_power(priv); |
| 452 | |
| 453 | /* if fail to set tx_power, restore the orig. tx power */ |
| 454 | if (ret) { |
| 455 | priv->tx_power_user_lmt = prev_tx_power; |
| 456 | priv->tx_power_next = prev_tx_power; |
| 457 | } |
| 458 | return ret; |
| 459 | } |
| 460 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 461 | static int iwlagn_rxon_connect(struct iwl_priv *priv, |
| 462 | struct iwl_rxon_context *ctx) |
| 463 | { |
| 464 | int ret; |
| 465 | struct iwl_rxon_cmd *active = (void *)&ctx->active; |
| 466 | |
| 467 | /* RXON timing must be before associated RXON */ |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 468 | if (ctx->ctxid == IWL_RXON_CTX_BSS) { |
| 469 | ret = iwl_send_rxon_timing(priv, ctx); |
| 470 | if (ret) { |
| 471 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); |
| 472 | return ret; |
| 473 | } |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 474 | } |
| 475 | /* QoS info may be cleared by previous un-assoc RXON */ |
| 476 | iwlagn_update_qos(priv, ctx); |
| 477 | |
| 478 | /* |
| 479 | * We'll run into this code path when beaconing is |
| 480 | * enabled, but then we also need to send the beacon |
| 481 | * to the device. |
| 482 | */ |
| 483 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) { |
| 484 | ret = iwlagn_update_beacon(priv, ctx->vif); |
| 485 | if (ret) { |
| 486 | IWL_ERR(priv, |
| 487 | "Error sending required beacon (%d)!\n", |
| 488 | ret); |
| 489 | return ret; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | priv->start_calib = 0; |
| 494 | /* |
| 495 | * Apply the new configuration. |
| 496 | * |
| 497 | * Associated RXON doesn't clear the station table in uCode, |
| 498 | * so we don't need to restore stations etc. after this. |
| 499 | */ |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 500 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 501 | sizeof(struct iwl_rxon_cmd), &ctx->staging); |
| 502 | if (ret) { |
| 503 | IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); |
| 504 | return ret; |
| 505 | } |
| 506 | memcpy(active, &ctx->staging, sizeof(*active)); |
| 507 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 508 | /* IBSS beacon needs to be sent after setting assoc */ |
| 509 | if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC)) |
| 510 | if (iwlagn_update_beacon(priv, ctx->vif)) |
| 511 | IWL_ERR(priv, "Error sending IBSS beacon\n"); |
| 512 | iwl_init_sensitivity(priv); |
| 513 | |
| 514 | /* |
| 515 | * If we issue a new RXON command which required a tune then |
| 516 | * we must send a new TXPOWER command or we won't be able to |
| 517 | * Tx any frames. |
| 518 | * |
| 519 | * It's expected we set power here if channel is changing. |
| 520 | */ |
| 521 | ret = iwl_set_tx_power(priv, priv->tx_power_next, true); |
| 522 | if (ret) { |
| 523 | IWL_ERR(priv, "Error sending TX power (%d)\n", ret); |
| 524 | return ret; |
| 525 | } |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 526 | |
Stanislaw Gruszka | 107ef97 | 2011-10-12 10:16:35 +0200 | [diff] [blame] | 527 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION && |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 528 | priv->cfg->ht_params && priv->cfg->ht_params->smps_mode) |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 529 | ieee80211_request_smps(ctx->vif, |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 530 | priv->cfg->ht_params->smps_mode); |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 531 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 532 | return 0; |
| 533 | } |
| 534 | |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 535 | int iwlagn_set_pan_params(struct iwl_priv *priv) |
| 536 | { |
| 537 | struct iwl_wipan_params_cmd cmd; |
| 538 | struct iwl_rxon_context *ctx_bss, *ctx_pan; |
| 539 | int slot0 = 300, slot1 = 0; |
| 540 | int ret; |
| 541 | |
Johannes Berg | a18f61b | 2012-03-15 13:26:53 -0700 | [diff] [blame] | 542 | if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS)) |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 543 | return 0; |
| 544 | |
| 545 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 546 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 547 | lockdep_assert_held(&priv->mutex); |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 548 | |
| 549 | ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 550 | ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN]; |
| 551 | |
| 552 | /* |
| 553 | * If the PAN context is inactive, then we don't need |
| 554 | * to update the PAN parameters, the last thing we'll |
| 555 | * have done before it goes inactive is making the PAN |
| 556 | * parameters be WLAN-only. |
| 557 | */ |
| 558 | if (!ctx_pan->is_active) |
| 559 | return 0; |
| 560 | |
| 561 | memset(&cmd, 0, sizeof(cmd)); |
| 562 | |
| 563 | /* only 2 slots are currently allowed */ |
| 564 | cmd.num_slots = 2; |
| 565 | |
| 566 | cmd.slots[0].type = 0; /* BSS */ |
| 567 | cmd.slots[1].type = 1; /* PAN */ |
| 568 | |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 569 | if (priv->hw_roc_setup) { |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 570 | /* both contexts must be used for this to happen */ |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 571 | slot1 = IWL_MIN_SLOT_TIME; |
| 572 | slot0 = 3000; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 573 | } else if (ctx_bss->vif && ctx_pan->vif) { |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 574 | int bcnint = ctx_pan->beacon_int; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 575 | int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1; |
| 576 | |
| 577 | /* should be set, but seems unused?? */ |
| 578 | cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE); |
| 579 | |
| 580 | if (ctx_pan->vif->type == NL80211_IFTYPE_AP && |
| 581 | bcnint && |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 582 | bcnint != ctx_bss->beacon_int) { |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 583 | IWL_ERR(priv, |
| 584 | "beacon intervals don't match (%d, %d)\n", |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 585 | ctx_bss->beacon_int, ctx_pan->beacon_int); |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 586 | } else |
| 587 | bcnint = max_t(int, bcnint, |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 588 | ctx_bss->beacon_int); |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 589 | if (!bcnint) |
| 590 | bcnint = DEFAULT_BEACON_INTERVAL; |
| 591 | slot0 = bcnint / 2; |
| 592 | slot1 = bcnint - slot0; |
| 593 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 594 | if (test_bit(STATUS_SCAN_HW, &priv->status) || |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 595 | (!ctx_bss->vif->bss_conf.idle && |
| 596 | !ctx_bss->vif->bss_conf.assoc)) { |
| 597 | slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; |
| 598 | slot1 = IWL_MIN_SLOT_TIME; |
| 599 | } else if (!ctx_pan->vif->bss_conf.idle && |
| 600 | !ctx_pan->vif->bss_conf.assoc) { |
Johannes Berg | 325a7dd | 2011-09-22 15:14:55 -0700 | [diff] [blame] | 601 | slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 602 | slot0 = IWL_MIN_SLOT_TIME; |
| 603 | } |
| 604 | } else if (ctx_pan->vif) { |
| 605 | slot0 = 0; |
| 606 | slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) * |
Johannes Berg | bbb05cb | 2011-07-18 01:59:22 -0700 | [diff] [blame] | 607 | ctx_pan->beacon_int; |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 608 | slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1); |
| 609 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 610 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 611 | slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME; |
| 612 | slot1 = IWL_MIN_SLOT_TIME; |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | cmd.slots[0].width = cpu_to_le16(slot0); |
| 617 | cmd.slots[1].width = cpu_to_le16(slot1); |
| 618 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 619 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC, |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 620 | sizeof(cmd), &cmd); |
| 621 | if (ret) |
| 622 | IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret); |
| 623 | |
| 624 | return ret; |
| 625 | } |
| 626 | |
Meenakshi Venkataraman | dd64173 | 2012-03-13 16:25:38 -0700 | [diff] [blame] | 627 | static void _iwl_set_rxon_ht(struct iwl_priv *priv, |
| 628 | struct iwl_ht_config *ht_conf, |
| 629 | struct iwl_rxon_context *ctx) |
| 630 | { |
| 631 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 632 | |
| 633 | if (!ctx->ht.enabled) { |
| 634 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
| 635 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | |
| 636 | RXON_FLG_HT40_PROT_MSK | |
| 637 | RXON_FLG_HT_PROT_MSK); |
| 638 | return; |
| 639 | } |
| 640 | |
| 641 | /* FIXME: if the definition of ht.protection changed, the "translation" |
| 642 | * will be needed for rxon->flags |
| 643 | */ |
| 644 | rxon->flags |= cpu_to_le32(ctx->ht.protection << |
| 645 | RXON_FLG_HT_OPERATING_MODE_POS); |
| 646 | |
| 647 | /* Set up channel bandwidth: |
| 648 | * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */ |
| 649 | /* clear the HT channel mode before set the mode */ |
| 650 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | |
| 651 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); |
| 652 | if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) { |
| 653 | /* pure ht40 */ |
| 654 | if (ctx->ht.protection == |
| 655 | IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) { |
| 656 | rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40; |
| 657 | /* |
| 658 | * Note: control channel is opposite of extension |
| 659 | * channel |
| 660 | */ |
| 661 | switch (ctx->ht.extension_chan_offset) { |
| 662 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 663 | rxon->flags &= |
| 664 | ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 665 | break; |
| 666 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 667 | rxon->flags |= |
| 668 | RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 669 | break; |
| 670 | } |
| 671 | } else { |
| 672 | /* |
| 673 | * Note: control channel is opposite of extension |
| 674 | * channel |
| 675 | */ |
| 676 | switch (ctx->ht.extension_chan_offset) { |
| 677 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 678 | rxon->flags &= |
| 679 | ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); |
| 680 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; |
| 681 | break; |
| 682 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 683 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 684 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; |
| 685 | break; |
| 686 | case IEEE80211_HT_PARAM_CHA_SEC_NONE: |
| 687 | default: |
| 688 | /* |
| 689 | * channel location only valid if in Mixed |
| 690 | * mode |
| 691 | */ |
| 692 | IWL_ERR(priv, |
| 693 | "invalid extension channel offset\n"); |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | } else { |
| 698 | rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY; |
| 699 | } |
| 700 | |
| 701 | iwlagn_set_rxon_chain(priv, ctx); |
| 702 | |
| 703 | IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X " |
| 704 | "extension channel offset 0x%x\n", |
| 705 | le32_to_cpu(rxon->flags), ctx->ht.protection, |
| 706 | ctx->ht.extension_chan_offset); |
| 707 | } |
| 708 | |
| 709 | void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf) |
| 710 | { |
| 711 | struct iwl_rxon_context *ctx; |
| 712 | |
| 713 | for_each_context(priv, ctx) |
| 714 | _iwl_set_rxon_ht(priv, ht_conf, ctx); |
| 715 | } |
| 716 | |
Meenakshi Venkataraman | fedfa87 | 2012-03-13 16:31:34 -0700 | [diff] [blame] | 717 | /** |
| 718 | * iwl_set_rxon_channel - Set the band and channel values in staging RXON |
| 719 | * @ch: requested channel as a pointer to struct ieee80211_channel |
| 720 | |
| 721 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 722 | * in the staging RXON flag structure based on the ch->band |
| 723 | */ |
| 724 | void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch, |
| 725 | struct iwl_rxon_context *ctx) |
| 726 | { |
| 727 | enum ieee80211_band band = ch->band; |
| 728 | u16 channel = ch->hw_value; |
| 729 | |
| 730 | if ((le16_to_cpu(ctx->staging.channel) == channel) && |
| 731 | (priv->band == band)) |
| 732 | return; |
| 733 | |
| 734 | ctx->staging.channel = cpu_to_le16(channel); |
| 735 | if (band == IEEE80211_BAND_5GHZ) |
| 736 | ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 737 | else |
| 738 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
| 739 | |
| 740 | priv->band = band; |
| 741 | |
| 742 | IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band); |
| 743 | |
| 744 | } |
| 745 | |
Meenakshi Venkataraman | 50319f7 | 2012-03-13 16:45:00 -0700 | [diff] [blame] | 746 | void iwl_set_flags_for_band(struct iwl_priv *priv, |
| 747 | struct iwl_rxon_context *ctx, |
| 748 | enum ieee80211_band band, |
| 749 | struct ieee80211_vif *vif) |
| 750 | { |
| 751 | if (band == IEEE80211_BAND_5GHZ) { |
| 752 | ctx->staging.flags &= |
| 753 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 754 | | RXON_FLG_CCK_MSK); |
| 755 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 756 | } else { |
| 757 | /* Copied from iwl_post_associate() */ |
| 758 | if (vif && vif->bss_conf.use_short_slot) |
| 759 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 760 | else |
| 761 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 762 | |
| 763 | ctx->staging.flags |= RXON_FLG_BAND_24G_MSK; |
| 764 | ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 765 | ctx->staging.flags &= ~RXON_FLG_CCK_MSK; |
| 766 | } |
| 767 | } |
| 768 | |
Meenakshi Venkataraman | 354a453 | 2012-03-15 13:27:00 -0700 | [diff] [blame] | 769 | static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, |
| 770 | struct iwl_rxon_context *ctx, int hw_decrypt) |
| 771 | { |
| 772 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 773 | |
| 774 | if (hw_decrypt) |
| 775 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 776 | else |
| 777 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 778 | |
| 779 | } |
| 780 | |
Meenakshi Venkataraman | 8931b57 | 2012-03-15 13:27:01 -0700 | [diff] [blame] | 781 | /* validate RXON structure is valid */ |
| 782 | static int iwl_check_rxon_cmd(struct iwl_priv *priv, |
| 783 | struct iwl_rxon_context *ctx) |
| 784 | { |
| 785 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 786 | u32 errors = 0; |
| 787 | |
| 788 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 789 | if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) { |
| 790 | IWL_WARN(priv, "check 2.4G: wrong narrow\n"); |
| 791 | errors |= BIT(0); |
| 792 | } |
| 793 | if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) { |
| 794 | IWL_WARN(priv, "check 2.4G: wrong radar\n"); |
| 795 | errors |= BIT(1); |
| 796 | } |
| 797 | } else { |
| 798 | if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 799 | IWL_WARN(priv, "check 5.2G: not short slot!\n"); |
| 800 | errors |= BIT(2); |
| 801 | } |
| 802 | if (rxon->flags & RXON_FLG_CCK_MSK) { |
| 803 | IWL_WARN(priv, "check 5.2G: CCK!\n"); |
| 804 | errors |= BIT(3); |
| 805 | } |
| 806 | } |
| 807 | if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) { |
| 808 | IWL_WARN(priv, "mac/bssid mcast!\n"); |
| 809 | errors |= BIT(4); |
| 810 | } |
| 811 | |
| 812 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 813 | if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 && |
| 814 | (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) { |
| 815 | IWL_WARN(priv, "neither 1 nor 6 are basic\n"); |
| 816 | errors |= BIT(5); |
| 817 | } |
| 818 | |
| 819 | if (le16_to_cpu(rxon->assoc_id) > 2007) { |
| 820 | IWL_WARN(priv, "aid > 2007\n"); |
| 821 | errors |= BIT(6); |
| 822 | } |
| 823 | |
| 824 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 825 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) { |
| 826 | IWL_WARN(priv, "CCK and short slot\n"); |
| 827 | errors |= BIT(7); |
| 828 | } |
| 829 | |
| 830 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 831 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) { |
| 832 | IWL_WARN(priv, "CCK and auto detect"); |
| 833 | errors |= BIT(8); |
| 834 | } |
| 835 | |
| 836 | if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 837 | RXON_FLG_TGG_PROTECT_MSK)) == |
| 838 | RXON_FLG_TGG_PROTECT_MSK) { |
| 839 | IWL_WARN(priv, "TGg but no auto-detect\n"); |
| 840 | errors |= BIT(9); |
| 841 | } |
| 842 | |
| 843 | if (rxon->channel == 0) { |
| 844 | IWL_WARN(priv, "zero channel is invalid\n"); |
| 845 | errors |= BIT(10); |
| 846 | } |
| 847 | |
| 848 | WARN(errors, "Invalid RXON (%#x), channel %d", |
| 849 | errors, le16_to_cpu(rxon->channel)); |
| 850 | |
| 851 | return errors ? -EINVAL : 0; |
| 852 | } |
| 853 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 854 | /** |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 855 | * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed |
| 856 | * @priv: staging_rxon is compared to active_rxon |
| 857 | * |
| 858 | * If the RXON structure is changing enough to require a new tune, |
| 859 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 860 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. |
| 861 | */ |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 862 | int iwl_full_rxon_required(struct iwl_priv *priv, |
| 863 | struct iwl_rxon_context *ctx) |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 864 | { |
| 865 | const struct iwl_rxon_cmd *staging = &ctx->staging; |
| 866 | const struct iwl_rxon_cmd *active = &ctx->active; |
| 867 | |
| 868 | #define CHK(cond) \ |
| 869 | if ((cond)) { \ |
| 870 | IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \ |
| 871 | return 1; \ |
| 872 | } |
| 873 | |
| 874 | #define CHK_NEQ(c1, c2) \ |
| 875 | if ((c1) != (c2)) { \ |
| 876 | IWL_DEBUG_INFO(priv, "need full RXON - " \ |
| 877 | #c1 " != " #c2 " - %d != %d\n", \ |
| 878 | (c1), (c2)); \ |
| 879 | return 1; \ |
| 880 | } |
| 881 | |
| 882 | /* These items are only settable from the full RXON command */ |
| 883 | CHK(!iwl_is_associated_ctx(ctx)); |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame^] | 884 | CHK(!ether_addr_equal(staging->bssid_addr, active->bssid_addr)); |
| 885 | CHK(!ether_addr_equal(staging->node_addr, active->node_addr)); |
| 886 | CHK(!ether_addr_equal(staging->wlap_bssid_addr, |
| 887 | active->wlap_bssid_addr)); |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 888 | CHK_NEQ(staging->dev_type, active->dev_type); |
| 889 | CHK_NEQ(staging->channel, active->channel); |
| 890 | CHK_NEQ(staging->air_propagation, active->air_propagation); |
| 891 | CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates, |
| 892 | active->ofdm_ht_single_stream_basic_rates); |
| 893 | CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates, |
| 894 | active->ofdm_ht_dual_stream_basic_rates); |
| 895 | CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates, |
| 896 | active->ofdm_ht_triple_stream_basic_rates); |
| 897 | CHK_NEQ(staging->assoc_id, active->assoc_id); |
| 898 | |
| 899 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 900 | * be updated with the RXON_ASSOC command -- however only some |
| 901 | * flag transitions are allowed using RXON_ASSOC */ |
| 902 | |
| 903 | /* Check if we are not switching bands */ |
| 904 | CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK, |
| 905 | active->flags & RXON_FLG_BAND_24G_MSK); |
| 906 | |
| 907 | /* Check if we are switching association toggle */ |
| 908 | CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK, |
| 909 | active->filter_flags & RXON_FILTER_ASSOC_MSK); |
| 910 | |
| 911 | #undef CHK |
| 912 | #undef CHK_NEQ |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | |
Meenakshi Venkataraman | 4d323ac | 2012-03-14 15:15:33 -0700 | [diff] [blame] | 917 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 918 | void iwl_print_rx_config_cmd(struct iwl_priv *priv, |
| 919 | enum iwl_rxon_context_id ctxid) |
| 920 | { |
| 921 | struct iwl_rxon_context *ctx = &priv->contexts[ctxid]; |
| 922 | struct iwl_rxon_cmd *rxon = &ctx->staging; |
| 923 | |
| 924 | IWL_DEBUG_RADIO(priv, "RX CONFIG:\n"); |
| 925 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
| 926 | IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", |
| 927 | le16_to_cpu(rxon->channel)); |
| 928 | IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", |
| 929 | le32_to_cpu(rxon->flags)); |
| 930 | IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n", |
| 931 | le32_to_cpu(rxon->filter_flags)); |
| 932 | IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type); |
| 933 | IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n", |
| 934 | rxon->ofdm_basic_rates); |
| 935 | IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", |
| 936 | rxon->cck_basic_rates); |
| 937 | IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr); |
| 938 | IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
| 939 | IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", |
| 940 | le16_to_cpu(rxon->assoc_id)); |
| 941 | } |
| 942 | #endif |
| 943 | |
Johannes Berg | 9543c5f | 2012-03-08 09:37:53 +0100 | [diff] [blame] | 944 | static void iwl_calc_basic_rates(struct iwl_priv *priv, |
| 945 | struct iwl_rxon_context *ctx) |
| 946 | { |
| 947 | int lowest_present_ofdm = 100; |
| 948 | int lowest_present_cck = 100; |
| 949 | u8 cck = 0; |
| 950 | u8 ofdm = 0; |
| 951 | |
| 952 | if (ctx->vif) { |
| 953 | struct ieee80211_supported_band *sband; |
| 954 | unsigned long basic = ctx->vif->bss_conf.basic_rates; |
| 955 | int i; |
| 956 | |
| 957 | sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band]; |
| 958 | |
| 959 | for_each_set_bit(i, &basic, BITS_PER_LONG) { |
| 960 | int hw = sband->bitrates[i].hw_value; |
| 961 | if (hw >= IWL_FIRST_OFDM_RATE) { |
| 962 | ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE); |
| 963 | if (lowest_present_ofdm > hw) |
| 964 | lowest_present_ofdm = hw; |
| 965 | } else { |
| 966 | BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0); |
| 967 | |
| 968 | cck |= BIT(hw); |
| 969 | if (lowest_present_cck > hw) |
| 970 | lowest_present_cck = hw; |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /* |
| 976 | * Now we've got the basic rates as bitmaps in the ofdm and cck |
| 977 | * variables. This isn't sufficient though, as there might not |
| 978 | * be all the right rates in the bitmap. E.g. if the only basic |
| 979 | * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps |
| 980 | * and 6 Mbps because the 802.11-2007 standard says in 9.6: |
| 981 | * |
| 982 | * [...] a STA responding to a received frame shall transmit |
| 983 | * its Control Response frame [...] at the highest rate in the |
| 984 | * BSSBasicRateSet parameter that is less than or equal to the |
| 985 | * rate of the immediately previous frame in the frame exchange |
| 986 | * sequence ([...]) and that is of the same modulation class |
| 987 | * ([...]) as the received frame. If no rate contained in the |
| 988 | * BSSBasicRateSet parameter meets these conditions, then the |
| 989 | * control frame sent in response to a received frame shall be |
| 990 | * transmitted at the highest mandatory rate of the PHY that is |
| 991 | * less than or equal to the rate of the received frame, and |
| 992 | * that is of the same modulation class as the received frame. |
| 993 | * |
| 994 | * As a consequence, we need to add all mandatory rates that are |
| 995 | * lower than all of the basic rates to these bitmaps. |
| 996 | */ |
| 997 | |
| 998 | if (IWL_RATE_24M_INDEX < lowest_present_ofdm) |
| 999 | ofdm |= IWL_RATE_24M_MASK >> IWL_FIRST_OFDM_RATE; |
| 1000 | if (IWL_RATE_12M_INDEX < lowest_present_ofdm) |
| 1001 | ofdm |= IWL_RATE_12M_MASK >> IWL_FIRST_OFDM_RATE; |
| 1002 | /* 6M already there or needed so always add */ |
| 1003 | ofdm |= IWL_RATE_6M_MASK >> IWL_FIRST_OFDM_RATE; |
| 1004 | |
| 1005 | /* |
| 1006 | * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP. |
| 1007 | * Note, however: |
| 1008 | * - if no CCK rates are basic, it must be ERP since there must |
| 1009 | * be some basic rates at all, so they're OFDM => ERP PHY |
| 1010 | * (or we're in 5 GHz, and the cck bitmap will never be used) |
| 1011 | * - if 11M is a basic rate, it must be ERP as well, so add 5.5M |
| 1012 | * - if 5.5M is basic, 1M and 2M are mandatory |
| 1013 | * - if 2M is basic, 1M is mandatory |
| 1014 | * - if 1M is basic, that's the only valid ACK rate. |
| 1015 | * As a consequence, it's not as complicated as it sounds, just add |
| 1016 | * any lower rates to the ACK rate bitmap. |
| 1017 | */ |
| 1018 | if (IWL_RATE_11M_INDEX < lowest_present_ofdm) |
| 1019 | ofdm |= IWL_RATE_11M_MASK >> IWL_FIRST_CCK_RATE; |
| 1020 | if (IWL_RATE_5M_INDEX < lowest_present_ofdm) |
| 1021 | ofdm |= IWL_RATE_5M_MASK >> IWL_FIRST_CCK_RATE; |
| 1022 | if (IWL_RATE_2M_INDEX < lowest_present_ofdm) |
| 1023 | ofdm |= IWL_RATE_2M_MASK >> IWL_FIRST_CCK_RATE; |
| 1024 | /* 1M already there or needed so always add */ |
| 1025 | cck |= IWL_RATE_1M_MASK >> IWL_FIRST_CCK_RATE; |
| 1026 | |
| 1027 | IWL_DEBUG_RATE(priv, "Set basic rates cck:0x%.2x ofdm:0x%.2x\n", |
| 1028 | cck, ofdm); |
| 1029 | |
| 1030 | /* "basic_rates" is a misnomer here -- should be called ACK rates */ |
| 1031 | ctx->staging.cck_basic_rates = cck; |
| 1032 | ctx->staging.ofdm_basic_rates = ofdm; |
| 1033 | } |
| 1034 | |
Meenakshi Venkataraman | 5562092 | 2012-03-15 13:27:02 -0700 | [diff] [blame] | 1035 | /** |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1036 | * iwlagn_commit_rxon - commit staging_rxon to hardware |
| 1037 | * |
| 1038 | * The RXON command in staging_rxon is committed to the hardware and |
| 1039 | * the active_rxon structure is updated with the new data. This |
| 1040 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1041 | * a HW tune is required based on the RXON structure changes. |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 1042 | * |
| 1043 | * The connect/disconnect flow should be as the following: |
| 1044 | * |
| 1045 | * 1. make sure send RXON command with association bit unset if not connect |
| 1046 | * this should include the channel and the band for the candidate |
| 1047 | * to be connected to |
| 1048 | * 2. Add Station before RXON association with the AP |
| 1049 | * 3. RXON_timing has to send before RXON for connection |
| 1050 | * 4. full RXON command - associated bit set |
| 1051 | * 5. use RXON_ASSOC command to update any flags changes |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1052 | */ |
| 1053 | int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
| 1054 | { |
| 1055 | /* cast away the const for active_rxon in this function */ |
| 1056 | struct iwl_rxon_cmd *active = (void *)&ctx->active; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1057 | bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); |
| 1058 | int ret; |
| 1059 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1060 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1061 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1062 | if (!iwl_is_alive(priv)) |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1063 | return -EBUSY; |
| 1064 | |
| 1065 | /* This function hardcodes a bunch of dual-mode assumptions */ |
| 1066 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 1067 | |
| 1068 | if (!ctx->is_active) |
| 1069 | return 0; |
| 1070 | |
| 1071 | /* always get timestamp with Rx frame */ |
| 1072 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1073 | |
Johannes Berg | 9543c5f | 2012-03-08 09:37:53 +0100 | [diff] [blame] | 1074 | /* recalculate basic rates */ |
| 1075 | iwl_calc_basic_rates(priv, ctx); |
| 1076 | |
Stanislaw Gruszka | 42b70a5 | 2011-05-26 17:14:22 +0200 | [diff] [blame] | 1077 | /* |
| 1078 | * force CTS-to-self frames protection if RTS-CTS is not preferred |
| 1079 | * one aggregation protection method |
| 1080 | */ |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 1081 | if (!priv->hw_params.use_rts_for_aggregation) |
Stanislaw Gruszka | 42b70a5 | 2011-05-26 17:14:22 +0200 | [diff] [blame] | 1082 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; |
| 1083 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1084 | if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) || |
| 1085 | !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK)) |
| 1086 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1087 | else |
| 1088 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1089 | |
Emmanuel Grumbach | 522376d | 2011-09-06 09:31:19 -0700 | [diff] [blame] | 1090 | iwl_print_rx_config_cmd(priv, ctx->ctxid); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1091 | ret = iwl_check_rxon_cmd(priv, ctx); |
| 1092 | if (ret) { |
| 1093 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
| 1094 | return -EINVAL; |
| 1095 | } |
| 1096 | |
| 1097 | /* |
| 1098 | * receive commit_rxon request |
| 1099 | * abort any previous channel switch if still in process |
| 1100 | */ |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1101 | if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) && |
Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 1102 | (priv->switch_channel != ctx->staging.channel)) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1103 | IWL_DEBUG_11H(priv, "abort channel switch on %d\n", |
Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 1104 | le16_to_cpu(priv->switch_channel)); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1105 | iwl_chswitch_done(priv, false); |
| 1106 | } |
| 1107 | |
| 1108 | /* |
| 1109 | * If we don't need to send a full RXON, we can use |
| 1110 | * iwl_rxon_assoc_cmd which is used to reconfigure filter |
| 1111 | * and other flags for the current radio configuration. |
| 1112 | */ |
| 1113 | if (!iwl_full_rxon_required(priv, ctx)) { |
Wey-Yi Guy | c3f6e9c | 2011-04-19 16:52:57 -0700 | [diff] [blame] | 1114 | ret = iwlagn_send_rxon_assoc(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1115 | if (ret) { |
| 1116 | IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret); |
| 1117 | return ret; |
| 1118 | } |
| 1119 | |
| 1120 | memcpy(active, &ctx->staging, sizeof(*active)); |
Wey-Yi Guy | 891db88 | 2011-05-27 08:40:24 -0700 | [diff] [blame] | 1121 | /* |
| 1122 | * We do not commit tx power settings while channel changing, |
| 1123 | * do it now if after settings changed. |
| 1124 | */ |
| 1125 | iwl_set_tx_power(priv, priv->tx_power_next, false); |
Wey-Yi Guy | 15b3f3b | 2011-06-03 07:54:13 -0700 | [diff] [blame] | 1126 | |
| 1127 | /* make sure we are in the right PS state */ |
| 1128 | iwl_power_update_mode(priv, true); |
| 1129 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1130 | return 0; |
| 1131 | } |
| 1132 | |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1133 | iwl_set_rxon_hwcrypto(priv, ctx, !iwlwifi_mod_params.sw_crypto); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1134 | |
| 1135 | IWL_DEBUG_INFO(priv, |
| 1136 | "Going to commit RXON\n" |
| 1137 | " * with%s RXON_FILTER_ASSOC_MSK\n" |
| 1138 | " * channel = %d\n" |
| 1139 | " * bssid = %pM\n", |
| 1140 | (new_assoc ? "" : "out"), |
| 1141 | le16_to_cpu(ctx->staging.channel), |
| 1142 | ctx->staging.bssid_addr); |
| 1143 | |
| 1144 | /* |
Johannes Berg | 52d980c | 2010-11-10 09:56:45 -0800 | [diff] [blame] | 1145 | * Always clear associated first, but with the correct config. |
| 1146 | * This is required as for example station addition for the |
| 1147 | * AP station must be done after the BSSID is set to correctly |
| 1148 | * set up filters in the device. |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1149 | */ |
Wey-Yi Guy | 3083d03 | 2011-05-06 17:06:44 -0700 | [diff] [blame] | 1150 | ret = iwlagn_rxon_disconn(priv, ctx); |
| 1151 | if (ret) |
| 1152 | return ret; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1153 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1154 | ret = iwlagn_set_pan_params(priv); |
| 1155 | if (ret) |
| 1156 | return ret; |
Johannes Berg | 2b9253d | 2011-05-27 08:40:26 -0700 | [diff] [blame] | 1157 | |
Wey-Yi Guy | c1821c9 | 2011-04-19 16:52:59 -0700 | [diff] [blame] | 1158 | if (new_assoc) |
| 1159 | return iwlagn_rxon_connect(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
Wey-Yi Guy | 34a5b4b | 2011-12-02 08:19:18 -0800 | [diff] [blame] | 1164 | void iwlagn_config_ht40(struct ieee80211_conf *conf, |
| 1165 | struct iwl_rxon_context *ctx) |
| 1166 | { |
| 1167 | if (conf_is_ht40_minus(conf)) { |
| 1168 | ctx->ht.extension_chan_offset = |
| 1169 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
| 1170 | ctx->ht.is_40mhz = true; |
| 1171 | } else if (conf_is_ht40_plus(conf)) { |
| 1172 | ctx->ht.extension_chan_offset = |
| 1173 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
| 1174 | ctx->ht.is_40mhz = true; |
| 1175 | } else { |
| 1176 | ctx->ht.extension_chan_offset = |
| 1177 | IEEE80211_HT_PARAM_CHA_SEC_NONE; |
| 1178 | ctx->ht.is_40mhz = false; |
| 1179 | } |
| 1180 | } |
| 1181 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1182 | int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed) |
| 1183 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1184 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1185 | struct iwl_rxon_context *ctx; |
| 1186 | struct ieee80211_conf *conf = &hw->conf; |
| 1187 | struct ieee80211_channel *channel = conf->channel; |
| 1188 | const struct iwl_channel_info *ch_info; |
| 1189 | int ret = 0; |
| 1190 | |
Johannes Berg | 0ca24da | 2012-03-15 13:26:46 -0700 | [diff] [blame] | 1191 | IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1192 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1193 | mutex_lock(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1194 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1195 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1196 | IWL_DEBUG_MAC80211(priv, "leave - scanning\n"); |
| 1197 | goto out; |
| 1198 | } |
| 1199 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1200 | if (!iwl_is_ready(priv)) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1201 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
| 1202 | goto out; |
| 1203 | } |
| 1204 | |
| 1205 | if (changed & (IEEE80211_CONF_CHANGE_SMPS | |
| 1206 | IEEE80211_CONF_CHANGE_CHANNEL)) { |
| 1207 | /* mac80211 uses static for non-HT which is what we want */ |
| 1208 | priv->current_ht_config.smps = conf->smps_mode; |
| 1209 | |
| 1210 | /* |
| 1211 | * Recalculate chain counts. |
| 1212 | * |
| 1213 | * If monitor mode is enabled then mac80211 will |
| 1214 | * set up the SM PS mode to OFF if an HT channel is |
| 1215 | * configured. |
| 1216 | */ |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1217 | for_each_context(priv, ctx) |
| 1218 | iwlagn_set_rxon_chain(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1222 | ch_info = iwl_get_channel_info(priv, channel->band, |
| 1223 | channel->hw_value); |
| 1224 | if (!is_channel_valid(ch_info)) { |
| 1225 | IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n"); |
| 1226 | ret = -EINVAL; |
| 1227 | goto out; |
| 1228 | } |
| 1229 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1230 | for_each_context(priv, ctx) { |
| 1231 | /* Configure HT40 channels */ |
Daniel Halperin | 7caa231 | 2011-04-06 12:47:25 -0700 | [diff] [blame] | 1232 | if (ctx->ht.enabled != conf_is_ht(conf)) |
Wey-Yi Guy | 35a6eb3 | 2010-11-10 09:56:43 -0800 | [diff] [blame] | 1233 | ctx->ht.enabled = conf_is_ht(conf); |
Wey-Yi Guy | 35a6eb3 | 2010-11-10 09:56:43 -0800 | [diff] [blame] | 1234 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1235 | if (ctx->ht.enabled) { |
Wey-Yi Guy | 34a5b4b | 2011-12-02 08:19:18 -0800 | [diff] [blame] | 1236 | /* if HT40 is used, it should not change |
| 1237 | * after associated except channel switch */ |
Wey-Yi Guy | 78feb35 | 2011-12-14 08:22:36 -0800 | [diff] [blame] | 1238 | if (!ctx->ht.is_40mhz || |
| 1239 | !iwl_is_associated_ctx(ctx)) |
Wey-Yi Guy | 34a5b4b | 2011-12-02 08:19:18 -0800 | [diff] [blame] | 1240 | iwlagn_config_ht40(conf, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1241 | } else |
| 1242 | ctx->ht.is_40mhz = false; |
| 1243 | |
| 1244 | /* |
| 1245 | * Default to no protection. Protection mode will |
| 1246 | * later be set from BSS config in iwl_ht_conf |
| 1247 | */ |
| 1248 | ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE; |
| 1249 | |
| 1250 | /* if we are switching from ht to 2.4 clear flags |
| 1251 | * from any ht related info since 2.4 does not |
| 1252 | * support ht */ |
| 1253 | if (le16_to_cpu(ctx->staging.channel) != |
| 1254 | channel->hw_value) |
| 1255 | ctx->staging.flags = 0; |
| 1256 | |
| 1257 | iwl_set_rxon_channel(priv, channel, ctx); |
| 1258 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
| 1259 | |
| 1260 | iwl_set_flags_for_band(priv, ctx, channel->band, |
| 1261 | ctx->vif); |
| 1262 | } |
| 1263 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1264 | iwl_update_bcast_stations(priv); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | if (changed & (IEEE80211_CONF_CHANGE_PS | |
| 1268 | IEEE80211_CONF_CHANGE_IDLE)) { |
| 1269 | ret = iwl_power_update_mode(priv, false); |
| 1270 | if (ret) |
| 1271 | IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n"); |
| 1272 | } |
| 1273 | |
| 1274 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 1275 | IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n", |
| 1276 | priv->tx_power_user_lmt, conf->power_level); |
| 1277 | |
| 1278 | iwl_set_tx_power(priv, conf->power_level, false); |
| 1279 | } |
| 1280 | |
| 1281 | for_each_context(priv, ctx) { |
| 1282 | if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 1283 | continue; |
| 1284 | iwlagn_commit_rxon(priv, ctx); |
| 1285 | } |
| 1286 | out: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1287 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | 770c72c | 2011-10-10 07:27:10 -0700 | [diff] [blame] | 1288 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 1289 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1290 | return ret; |
| 1291 | } |
| 1292 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1293 | void iwlagn_check_needed_chains(struct iwl_priv *priv, |
| 1294 | struct iwl_rxon_context *ctx, |
| 1295 | struct ieee80211_bss_conf *bss_conf) |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1296 | { |
| 1297 | struct ieee80211_vif *vif = ctx->vif; |
| 1298 | struct iwl_rxon_context *tmp; |
| 1299 | struct ieee80211_sta *sta; |
| 1300 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1301 | struct ieee80211_sta_ht_cap *ht_cap; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1302 | bool need_multiple; |
| 1303 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1304 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1305 | |
| 1306 | switch (vif->type) { |
| 1307 | case NL80211_IFTYPE_STATION: |
| 1308 | rcu_read_lock(); |
| 1309 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1310 | if (!sta) { |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1311 | /* |
| 1312 | * If at all, this can only happen through a race |
| 1313 | * when the AP disconnects us while we're still |
| 1314 | * setting up the connection, in that case mac80211 |
| 1315 | * will soon tell us about that. |
| 1316 | */ |
| 1317 | need_multiple = false; |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1318 | rcu_read_unlock(); |
| 1319 | break; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1320 | } |
Johannes Berg | 850bedc | 2011-02-25 12:24:11 +0100 | [diff] [blame] | 1321 | |
| 1322 | ht_cap = &sta->ht_cap; |
| 1323 | |
| 1324 | need_multiple = true; |
| 1325 | |
| 1326 | /* |
| 1327 | * If the peer advertises no support for receiving 2 and 3 |
| 1328 | * stream MCS rates, it can't be transmitting them either. |
| 1329 | */ |
| 1330 | if (ht_cap->mcs.rx_mask[1] == 0 && |
| 1331 | ht_cap->mcs.rx_mask[2] == 0) { |
| 1332 | need_multiple = false; |
| 1333 | } else if (!(ht_cap->mcs.tx_params & |
| 1334 | IEEE80211_HT_MCS_TX_DEFINED)) { |
| 1335 | /* If it can't TX MCS at all ... */ |
| 1336 | need_multiple = false; |
| 1337 | } else if (ht_cap->mcs.tx_params & |
| 1338 | IEEE80211_HT_MCS_TX_RX_DIFF) { |
| 1339 | int maxstreams; |
| 1340 | |
| 1341 | /* |
| 1342 | * But if it can receive them, it might still not |
| 1343 | * be able to transmit them, which is what we need |
| 1344 | * to check here -- so check the number of streams |
| 1345 | * it advertises for TX (if different from RX). |
| 1346 | */ |
| 1347 | |
| 1348 | maxstreams = (ht_cap->mcs.tx_params & |
| 1349 | IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK); |
| 1350 | maxstreams >>= |
| 1351 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; |
| 1352 | maxstreams += 1; |
| 1353 | |
| 1354 | if (maxstreams <= 1) |
| 1355 | need_multiple = false; |
| 1356 | } |
| 1357 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1358 | rcu_read_unlock(); |
| 1359 | break; |
| 1360 | case NL80211_IFTYPE_ADHOC: |
| 1361 | /* currently */ |
| 1362 | need_multiple = false; |
| 1363 | break; |
| 1364 | default: |
| 1365 | /* only AP really */ |
| 1366 | need_multiple = true; |
| 1367 | break; |
| 1368 | } |
| 1369 | |
| 1370 | ctx->ht_need_multiple_chains = need_multiple; |
| 1371 | |
| 1372 | if (!need_multiple) { |
| 1373 | /* check all contexts */ |
| 1374 | for_each_context(priv, tmp) { |
| 1375 | if (!tmp->vif) |
| 1376 | continue; |
| 1377 | if (tmp->ht_need_multiple_chains) { |
| 1378 | need_multiple = true; |
| 1379 | break; |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | ht_conf->single_chain_sufficient = !need_multiple; |
| 1385 | } |
| 1386 | |
David Spinadel | 50c1e9a | 2012-04-16 14:43:30 -0700 | [diff] [blame] | 1387 | void iwlagn_chain_noise_reset(struct iwl_priv *priv) |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 1388 | { |
| 1389 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; |
| 1390 | int ret; |
| 1391 | |
Dor Shaish | bfb45f5 | 2012-03-26 08:20:55 -0700 | [diff] [blame] | 1392 | if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED)) |
| 1393 | return; |
| 1394 | |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 1395 | if ((data->state == IWL_CHAIN_NOISE_ALIVE) && |
| 1396 | iwl_is_any_associated(priv)) { |
| 1397 | struct iwl_calib_chain_noise_reset_cmd cmd; |
| 1398 | |
| 1399 | /* clear data for chain noise calibration algorithm */ |
| 1400 | data->chain_noise_a = 0; |
| 1401 | data->chain_noise_b = 0; |
| 1402 | data->chain_noise_c = 0; |
| 1403 | data->chain_signal_a = 0; |
| 1404 | data->chain_signal_b = 0; |
| 1405 | data->chain_signal_c = 0; |
| 1406 | data->beacon_count = 0; |
| 1407 | |
| 1408 | memset(&cmd, 0, sizeof(cmd)); |
| 1409 | iwl_set_calib_hdr(&cmd.hdr, |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 1410 | priv->phy_calib_chain_noise_reset_cmd); |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 1411 | ret = iwl_dvm_send_cmd_pdu(priv, |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 1412 | REPLY_PHY_CALIBRATION_CMD, |
| 1413 | CMD_SYNC, sizeof(cmd), &cmd); |
| 1414 | if (ret) |
| 1415 | IWL_ERR(priv, |
| 1416 | "Could not send REPLY_PHY_CALIBRATION_CMD\n"); |
| 1417 | data->state = IWL_CHAIN_NOISE_ACCUMULATE; |
| 1418 | IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n"); |
| 1419 | } |
| 1420 | } |
| 1421 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1422 | void iwlagn_bss_info_changed(struct ieee80211_hw *hw, |
| 1423 | struct ieee80211_vif *vif, |
| 1424 | struct ieee80211_bss_conf *bss_conf, |
| 1425 | u32 changes) |
| 1426 | { |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 1427 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1428 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
| 1429 | int ret; |
| 1430 | bool force = false; |
| 1431 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1432 | mutex_lock(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1433 | |
Don Fry | 8362640 | 2012-03-07 09:52:37 -0800 | [diff] [blame] | 1434 | if (unlikely(!iwl_is_ready(priv))) { |
Wey-Yi Guy | 14a085e | 2010-12-14 07:38:58 -0800 | [diff] [blame] | 1435 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1436 | mutex_unlock(&priv->mutex); |
Shanyu Zhao | ae0b693 | 2010-12-02 11:02:28 -0800 | [diff] [blame] | 1437 | return; |
| 1438 | } |
| 1439 | |
| 1440 | if (unlikely(!ctx->vif)) { |
| 1441 | IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n"); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1442 | mutex_unlock(&priv->mutex); |
Johannes Berg | 893654d | 2010-11-10 18:25:47 -0800 | [diff] [blame] | 1443 | return; |
| 1444 | } |
| 1445 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1446 | if (changes & BSS_CHANGED_BEACON_INT) |
| 1447 | force = true; |
| 1448 | |
| 1449 | if (changes & BSS_CHANGED_QOS) { |
| 1450 | ctx->qos_data.qos_active = bss_conf->qos; |
| 1451 | iwlagn_update_qos(priv, ctx); |
| 1452 | } |
| 1453 | |
| 1454 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); |
| 1455 | if (vif->bss_conf.use_short_preamble) |
| 1456 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1457 | else |
| 1458 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1459 | |
| 1460 | if (changes & BSS_CHANGED_ASSOC) { |
| 1461 | if (bss_conf->assoc) { |
Johannes Berg | e9ac074 | 2012-03-13 14:29:30 +0100 | [diff] [blame] | 1462 | priv->timestamp = bss_conf->last_tsf; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1463 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1464 | } else { |
Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 1465 | /* |
| 1466 | * If we disassociate while there are pending |
| 1467 | * frames, just wake up the queues and let the |
| 1468 | * frames "escape" ... This shouldn't really |
| 1469 | * be happening to start with, but we should |
| 1470 | * not get stuck in this case either since it |
| 1471 | * can happen if userspace gets confused. |
| 1472 | */ |
Johannes Berg | e755f88 | 2012-03-07 09:52:16 -0800 | [diff] [blame] | 1473 | iwlagn_lift_passive_no_rx(priv); |
| 1474 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1475 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 1476 | |
| 1477 | if (ctx->ctxid == IWL_RXON_CTX_BSS) |
| 1478 | priv->have_rekey_data = false; |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1479 | } |
Meenakshi Venkataraman | 207ecc5 | 2011-07-08 08:46:23 -0700 | [diff] [blame] | 1480 | |
| 1481 | iwlagn_bt_coex_rssi_monitor(priv); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | if (ctx->ht.enabled) { |
| 1485 | ctx->ht.protection = bss_conf->ht_operation_mode & |
| 1486 | IEEE80211_HT_OP_MODE_PROTECTION; |
| 1487 | ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode & |
| 1488 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); |
| 1489 | iwlagn_check_needed_chains(priv, ctx, bss_conf); |
Johannes Berg | b2769b8 | 2010-11-10 09:56:47 -0800 | [diff] [blame] | 1490 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1493 | iwlagn_set_rxon_chain(priv, ctx); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1494 | |
| 1495 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
| 1496 | ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 1497 | else |
| 1498 | ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 1499 | |
| 1500 | if (bss_conf->use_cts_prot) |
| 1501 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; |
| 1502 | else |
| 1503 | ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN; |
| 1504 | |
| 1505 | memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN); |
| 1506 | |
| 1507 | if (vif->type == NL80211_IFTYPE_AP || |
| 1508 | vif->type == NL80211_IFTYPE_ADHOC) { |
| 1509 | if (vif->bss_conf.enable_beacon) { |
| 1510 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1511 | priv->beacon_ctx = ctx; |
| 1512 | } else { |
| 1513 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1514 | priv->beacon_ctx = NULL; |
| 1515 | } |
| 1516 | } |
| 1517 | |
Meenakshi Venkataraman | 758f555 | 2012-02-08 12:04:41 -0800 | [diff] [blame] | 1518 | /* |
| 1519 | * If the ucode decides to do beacon filtering before |
| 1520 | * association, it will lose beacons that are needed |
| 1521 | * before sending frames out on passive channels. This |
| 1522 | * causes association failures on those channels. Enable |
| 1523 | * receiving beacons in such cases. |
| 1524 | */ |
| 1525 | |
| 1526 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 1527 | if (!bss_conf->assoc) |
| 1528 | ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK; |
| 1529 | else |
| 1530 | ctx->staging.filter_flags &= |
| 1531 | ~RXON_FILTER_BCON_AWARE_MSK; |
| 1532 | } |
| 1533 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1534 | if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 1535 | iwlagn_commit_rxon(priv, ctx); |
| 1536 | |
Johannes Berg | 8da8e62 | 2010-11-10 09:56:46 -0800 | [diff] [blame] | 1537 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { |
| 1538 | /* |
| 1539 | * The chain noise calibration will enable PM upon |
| 1540 | * completion. If calibration has already been run |
| 1541 | * then we need to enable power management here. |
| 1542 | */ |
| 1543 | if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE) |
| 1544 | iwl_power_update_mode(priv, false); |
| 1545 | |
| 1546 | /* Enable RX differential gain and sensitivity calibrations */ |
Dor Shaish | bfb45f5 | 2012-03-26 08:20:55 -0700 | [diff] [blame] | 1547 | iwlagn_chain_noise_reset(priv); |
Johannes Berg | 8da8e62 | 2010-11-10 09:56:46 -0800 | [diff] [blame] | 1548 | priv->start_calib = 1; |
| 1549 | } |
| 1550 | |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1551 | if (changes & BSS_CHANGED_IBSS) { |
| 1552 | ret = iwlagn_manage_ibss_station(priv, vif, |
| 1553 | bss_conf->ibss_joined); |
| 1554 | if (ret) |
| 1555 | IWL_ERR(priv, "failed to %s IBSS station %pM\n", |
| 1556 | bss_conf->ibss_joined ? "add" : "remove", |
| 1557 | bss_conf->bssid); |
| 1558 | } |
| 1559 | |
Johannes Berg | bd50a8ab | 2010-10-23 09:15:42 -0700 | [diff] [blame] | 1560 | if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC && |
| 1561 | priv->beacon_ctx) { |
| 1562 | if (iwlagn_update_beacon(priv, vif)) |
| 1563 | IWL_ERR(priv, "Error sending IBSS beacon\n"); |
| 1564 | } |
| 1565 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 1566 | mutex_unlock(&priv->mutex); |
Johannes Berg | 2295c66 | 2010-10-23 09:15:41 -0700 | [diff] [blame] | 1567 | } |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 1568 | |
| 1569 | void iwlagn_post_scan(struct iwl_priv *priv) |
| 1570 | { |
| 1571 | struct iwl_rxon_context *ctx; |
| 1572 | |
| 1573 | /* |
Wey-Yi Guy | c2b821d | 2011-06-03 07:54:14 -0700 | [diff] [blame] | 1574 | * We do not commit power settings while scan is pending, |
| 1575 | * do it now if the settings changed. |
| 1576 | */ |
| 1577 | iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false); |
| 1578 | iwl_set_tx_power(priv, priv->tx_power_next, false); |
| 1579 | |
| 1580 | /* |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 1581 | * Since setting the RXON may have been deferred while |
| 1582 | * performing the scan, fire one off if needed |
| 1583 | */ |
| 1584 | for_each_context(priv, ctx) |
| 1585 | if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
| 1586 | iwlagn_commit_rxon(priv, ctx); |
| 1587 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 1588 | iwlagn_set_pan_params(priv); |
Johannes Berg | ae79d23 | 2010-11-10 09:56:38 -0800 | [diff] [blame] | 1589 | } |