1 /******************************************************************************
3 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
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.
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
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
30 #include "iwl-agn-calib.h"
31 #include "iwl-trans.h"
32 #include "iwl-shared.h"
34 static int iwlagn_disable_bss(struct iwl_priv
*priv
,
35 struct iwl_rxon_context
*ctx
,
36 struct iwl_rxon_cmd
*send
)
38 __le32 old_filter
= send
->filter_flags
;
41 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
42 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
43 CMD_SYNC
, sizeof(*send
), send
);
45 send
->filter_flags
= old_filter
;
48 IWL_DEBUG_QUIET_RFKILL(priv
,
49 "Error clearing ASSOC_MSK on BSS (%d)\n", ret
);
54 static int iwlagn_disable_pan(struct iwl_priv
*priv
,
55 struct iwl_rxon_context
*ctx
,
56 struct iwl_rxon_cmd
*send
)
58 struct iwl_notification_wait disable_wait
;
59 __le32 old_filter
= send
->filter_flags
;
60 u8 old_dev_type
= send
->dev_type
;
62 static const u8 deactivate_cmd
[] = {
63 REPLY_WIPAN_DEACTIVATION_COMPLETE
66 iwl_init_notification_wait(&priv
->notif_wait
, &disable_wait
,
67 deactivate_cmd
, ARRAY_SIZE(deactivate_cmd
),
70 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
71 send
->dev_type
= RXON_DEV_TYPE_P2P
;
72 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
73 CMD_SYNC
, sizeof(*send
), send
);
75 send
->filter_flags
= old_filter
;
76 send
->dev_type
= old_dev_type
;
79 IWL_ERR(priv
, "Error disabling PAN (%d)\n", ret
);
80 iwl_remove_notification(&priv
->notif_wait
, &disable_wait
);
82 ret
= iwl_wait_notification(&priv
->notif_wait
,
85 IWL_ERR(priv
, "Timed out waiting for PAN disable\n");
91 static int iwlagn_disconn_pan(struct iwl_priv
*priv
,
92 struct iwl_rxon_context
*ctx
,
93 struct iwl_rxon_cmd
*send
)
95 __le32 old_filter
= send
->filter_flags
;
98 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
99 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
, CMD_SYNC
,
100 sizeof(*send
), send
);
102 send
->filter_flags
= old_filter
;
107 static void iwlagn_update_qos(struct iwl_priv
*priv
,
108 struct iwl_rxon_context
*ctx
)
115 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
117 if (ctx
->qos_data
.qos_active
)
118 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
119 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
122 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
124 IWL_DEBUG_INFO(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
125 ctx
->qos_data
.qos_active
,
126 ctx
->qos_data
.def_qos_parm
.qos_flags
);
128 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->qos_cmd
, CMD_SYNC
,
129 sizeof(struct iwl_qosparam_cmd
),
130 &ctx
->qos_data
.def_qos_parm
);
132 IWL_DEBUG_QUIET_RFKILL(priv
, "Failed to update QoS\n");
135 static int iwlagn_update_beacon(struct iwl_priv
*priv
,
136 struct ieee80211_vif
*vif
)
138 lockdep_assert_held(&priv
->mutex
);
140 dev_kfree_skb(priv
->beacon_skb
);
141 priv
->beacon_skb
= ieee80211_beacon_get(priv
->hw
, vif
);
142 if (!priv
->beacon_skb
)
144 return iwlagn_send_beacon_cmd(priv
);
147 static int iwlagn_send_rxon_assoc(struct iwl_priv
*priv
,
148 struct iwl_rxon_context
*ctx
)
151 struct iwl_rxon_assoc_cmd rxon_assoc
;
152 const struct iwl_rxon_cmd
*rxon1
= &ctx
->staging
;
153 const struct iwl_rxon_cmd
*rxon2
= &ctx
->active
;
155 if ((rxon1
->flags
== rxon2
->flags
) &&
156 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
157 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
158 (rxon1
->ofdm_ht_single_stream_basic_rates
==
159 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
160 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
161 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
162 (rxon1
->ofdm_ht_triple_stream_basic_rates
==
163 rxon2
->ofdm_ht_triple_stream_basic_rates
) &&
164 (rxon1
->acquisition_data
== rxon2
->acquisition_data
) &&
165 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
166 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
167 IWL_DEBUG_INFO(priv
, "Using current RXON_ASSOC. Not resending.\n");
171 rxon_assoc
.flags
= ctx
->staging
.flags
;
172 rxon_assoc
.filter_flags
= ctx
->staging
.filter_flags
;
173 rxon_assoc
.ofdm_basic_rates
= ctx
->staging
.ofdm_basic_rates
;
174 rxon_assoc
.cck_basic_rates
= ctx
->staging
.cck_basic_rates
;
175 rxon_assoc
.reserved1
= 0;
176 rxon_assoc
.reserved2
= 0;
177 rxon_assoc
.reserved3
= 0;
178 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
179 ctx
->staging
.ofdm_ht_single_stream_basic_rates
;
180 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
181 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
;
182 rxon_assoc
.rx_chain_select_flags
= ctx
->staging
.rx_chain
;
183 rxon_assoc
.ofdm_ht_triple_stream_basic_rates
=
184 ctx
->staging
.ofdm_ht_triple_stream_basic_rates
;
185 rxon_assoc
.acquisition_data
= ctx
->staging
.acquisition_data
;
187 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_assoc_cmd
,
188 CMD_ASYNC
, sizeof(rxon_assoc
), &rxon_assoc
);
192 static u16
iwl_adjust_beacon_interval(u16 beacon_val
, u16 max_beacon_val
)
198 * If mac80211 hasn't given us a beacon interval, program
199 * the default into the device (not checking this here
200 * would cause the adjustment below to return the maximum
201 * value, which may break PAN.)
204 return DEFAULT_BEACON_INTERVAL
;
207 * If the beacon interval we obtained from the peer
208 * is too large, we'll have to wake up more often
209 * (and in IBSS case, we'll beacon too much)
211 * For example, if max_beacon_val is 4096, and the
212 * requested beacon interval is 7000, we'll have to
213 * use 3500 to be able to wake up on the beacons.
215 * This could badly influence beacon detection stats.
218 beacon_factor
= (beacon_val
+ max_beacon_val
) / max_beacon_val
;
219 new_val
= beacon_val
/ beacon_factor
;
222 new_val
= max_beacon_val
;
227 static int iwl_send_rxon_timing(struct iwl_priv
*priv
,
228 struct iwl_rxon_context
*ctx
)
231 s32 interval_tm
, rem
;
232 struct ieee80211_conf
*conf
= NULL
;
234 struct ieee80211_vif
*vif
= ctx
->vif
;
236 conf
= &priv
->hw
->conf
;
238 lockdep_assert_held(&priv
->mutex
);
240 memset(&ctx
->timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
242 ctx
->timing
.timestamp
= cpu_to_le64(priv
->timestamp
);
243 ctx
->timing
.listen_interval
= cpu_to_le16(conf
->listen_interval
);
245 beacon_int
= vif
? vif
->bss_conf
.beacon_int
: 0;
248 * TODO: For IBSS we need to get atim_window from mac80211,
249 * for now just always use 0
251 ctx
->timing
.atim_window
= 0;
253 if (ctx
->ctxid
== IWL_RXON_CTX_PAN
&&
254 (!ctx
->vif
|| ctx
->vif
->type
!= NL80211_IFTYPE_STATION
) &&
255 iwl_is_associated(priv
, IWL_RXON_CTX_BSS
) &&
256 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
&&
257 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
->bss_conf
.beacon_int
) {
258 ctx
->timing
.beacon_interval
=
259 priv
->contexts
[IWL_RXON_CTX_BSS
].timing
.beacon_interval
;
260 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
261 } else if (ctx
->ctxid
== IWL_RXON_CTX_BSS
&&
262 iwl_is_associated(priv
, IWL_RXON_CTX_PAN
) &&
263 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
&&
264 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
->bss_conf
.beacon_int
&&
265 (!iwl_is_associated_ctx(ctx
) || !ctx
->vif
||
266 !ctx
->vif
->bss_conf
.beacon_int
)) {
267 ctx
->timing
.beacon_interval
=
268 priv
->contexts
[IWL_RXON_CTX_PAN
].timing
.beacon_interval
;
269 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
271 beacon_int
= iwl_adjust_beacon_interval(beacon_int
,
272 IWL_MAX_UCODE_BEACON_INTERVAL
* TIME_UNIT
);
273 ctx
->timing
.beacon_interval
= cpu_to_le16(beacon_int
);
276 ctx
->beacon_int
= beacon_int
;
278 tsf
= priv
->timestamp
; /* tsf is modifed by do_div: copy it */
279 interval_tm
= beacon_int
* TIME_UNIT
;
280 rem
= do_div(tsf
, interval_tm
);
281 ctx
->timing
.beacon_init_val
= cpu_to_le32(interval_tm
- rem
);
283 ctx
->timing
.dtim_period
= vif
? (vif
->bss_conf
.dtim_period
?: 1) : 1;
285 IWL_DEBUG_ASSOC(priv
,
286 "beacon interval %d beacon timer %d beacon tim %d\n",
287 le16_to_cpu(ctx
->timing
.beacon_interval
),
288 le32_to_cpu(ctx
->timing
.beacon_init_val
),
289 le16_to_cpu(ctx
->timing
.atim_window
));
291 return iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_timing_cmd
,
292 CMD_SYNC
, sizeof(ctx
->timing
), &ctx
->timing
);
295 static int iwlagn_rxon_disconn(struct iwl_priv
*priv
,
296 struct iwl_rxon_context
*ctx
)
299 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
301 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
) {
302 ret
= iwlagn_disable_bss(priv
, ctx
, &ctx
->staging
);
304 ret
= iwlagn_disable_pan(priv
, ctx
, &ctx
->staging
);
308 ret
= iwl_send_rxon_timing(priv
, ctx
);
310 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
313 ret
= iwlagn_disconn_pan(priv
, ctx
, &ctx
->staging
);
320 * Un-assoc RXON clears the station table and WEP
321 * keys, so we have to restore those afterwards.
323 iwl_clear_ucode_stations(priv
, ctx
);
324 /* update -- might need P2P now */
325 iwl_update_bcast_station(priv
, ctx
);
326 iwl_restore_stations(priv
, ctx
);
327 ret
= iwl_restore_default_wep_keys(priv
, ctx
);
329 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
333 memcpy(active
, &ctx
->staging
, sizeof(*active
));
337 static int iwlagn_rxon_connect(struct iwl_priv
*priv
,
338 struct iwl_rxon_context
*ctx
)
341 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
343 /* RXON timing must be before associated RXON */
344 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
) {
345 ret
= iwl_send_rxon_timing(priv
, ctx
);
347 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
351 /* QoS info may be cleared by previous un-assoc RXON */
352 iwlagn_update_qos(priv
, ctx
);
355 * We'll run into this code path when beaconing is
356 * enabled, but then we also need to send the beacon
359 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_AP
)) {
360 ret
= iwlagn_update_beacon(priv
, ctx
->vif
);
363 "Error sending required beacon (%d)!\n",
369 priv
->start_calib
= 0;
371 * Apply the new configuration.
373 * Associated RXON doesn't clear the station table in uCode,
374 * so we don't need to restore stations etc. after this.
376 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
, CMD_SYNC
,
377 sizeof(struct iwl_rxon_cmd
), &ctx
->staging
);
379 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
382 memcpy(active
, &ctx
->staging
, sizeof(*active
));
384 /* IBSS beacon needs to be sent after setting assoc */
385 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_ADHOC
))
386 if (iwlagn_update_beacon(priv
, ctx
->vif
))
387 IWL_ERR(priv
, "Error sending IBSS beacon\n");
388 iwl_init_sensitivity(priv
);
391 * If we issue a new RXON command which required a tune then
392 * we must send a new TXPOWER command or we won't be able to
395 * It's expected we set power here if channel is changing.
397 ret
= iwl_set_tx_power(priv
, priv
->tx_power_next
, true);
399 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
403 if (ctx
->vif
&& ctx
->vif
->type
== NL80211_IFTYPE_STATION
&&
404 cfg(priv
)->ht_params
&& cfg(priv
)->ht_params
->smps_mode
)
405 ieee80211_request_smps(ctx
->vif
,
406 cfg(priv
)->ht_params
->smps_mode
);
411 int iwlagn_set_pan_params(struct iwl_priv
*priv
)
413 struct iwl_wipan_params_cmd cmd
;
414 struct iwl_rxon_context
*ctx_bss
, *ctx_pan
;
415 int slot0
= 300, slot1
= 0;
418 if (priv
->valid_contexts
== BIT(IWL_RXON_CTX_BSS
))
421 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
423 lockdep_assert_held(&priv
->mutex
);
425 ctx_bss
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
426 ctx_pan
= &priv
->contexts
[IWL_RXON_CTX_PAN
];
429 * If the PAN context is inactive, then we don't need
430 * to update the PAN parameters, the last thing we'll
431 * have done before it goes inactive is making the PAN
432 * parameters be WLAN-only.
434 if (!ctx_pan
->is_active
)
437 memset(&cmd
, 0, sizeof(cmd
));
439 /* only 2 slots are currently allowed */
442 cmd
.slots
[0].type
= 0; /* BSS */
443 cmd
.slots
[1].type
= 1; /* PAN */
445 if (priv
->hw_roc_setup
) {
446 /* both contexts must be used for this to happen */
447 slot1
= IWL_MIN_SLOT_TIME
;
449 } else if (ctx_bss
->vif
&& ctx_pan
->vif
) {
450 int bcnint
= ctx_pan
->beacon_int
;
451 int dtim
= ctx_pan
->vif
->bss_conf
.dtim_period
?: 1;
453 /* should be set, but seems unused?? */
454 cmd
.flags
|= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE
);
456 if (ctx_pan
->vif
->type
== NL80211_IFTYPE_AP
&&
458 bcnint
!= ctx_bss
->beacon_int
) {
460 "beacon intervals don't match (%d, %d)\n",
461 ctx_bss
->beacon_int
, ctx_pan
->beacon_int
);
463 bcnint
= max_t(int, bcnint
,
464 ctx_bss
->beacon_int
);
466 bcnint
= DEFAULT_BEACON_INTERVAL
;
468 slot1
= bcnint
- slot0
;
470 if (test_bit(STATUS_SCAN_HW
, &priv
->status
) ||
471 (!ctx_bss
->vif
->bss_conf
.idle
&&
472 !ctx_bss
->vif
->bss_conf
.assoc
)) {
473 slot0
= dtim
* bcnint
* 3 - IWL_MIN_SLOT_TIME
;
474 slot1
= IWL_MIN_SLOT_TIME
;
475 } else if (!ctx_pan
->vif
->bss_conf
.idle
&&
476 !ctx_pan
->vif
->bss_conf
.assoc
) {
477 slot1
= dtim
* bcnint
* 3 - IWL_MIN_SLOT_TIME
;
478 slot0
= IWL_MIN_SLOT_TIME
;
480 } else if (ctx_pan
->vif
) {
482 slot1
= max_t(int, 1, ctx_pan
->vif
->bss_conf
.dtim_period
) *
484 slot1
= max_t(int, DEFAULT_BEACON_INTERVAL
, slot1
);
486 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
487 slot0
= slot1
* 3 - IWL_MIN_SLOT_TIME
;
488 slot1
= IWL_MIN_SLOT_TIME
;
492 cmd
.slots
[0].width
= cpu_to_le16(slot0
);
493 cmd
.slots
[1].width
= cpu_to_le16(slot1
);
495 ret
= iwl_dvm_send_cmd_pdu(priv
, REPLY_WIPAN_PARAMS
, CMD_SYNC
,
498 IWL_ERR(priv
, "Error setting PAN parameters (%d)\n", ret
);
503 static void iwl_set_rxon_hwcrypto(struct iwl_priv
*priv
,
504 struct iwl_rxon_context
*ctx
, int hw_decrypt
)
506 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
509 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
511 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
515 /* validate RXON structure is valid */
516 static int iwl_check_rxon_cmd(struct iwl_priv
*priv
,
517 struct iwl_rxon_context
*ctx
)
519 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
522 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
523 if (rxon
->flags
& RXON_FLG_TGJ_NARROW_BAND_MSK
) {
524 IWL_WARN(priv
, "check 2.4G: wrong narrow\n");
527 if (rxon
->flags
& RXON_FLG_RADAR_DETECT_MSK
) {
528 IWL_WARN(priv
, "check 2.4G: wrong radar\n");
532 if (!(rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
533 IWL_WARN(priv
, "check 5.2G: not short slot!\n");
536 if (rxon
->flags
& RXON_FLG_CCK_MSK
) {
537 IWL_WARN(priv
, "check 5.2G: CCK!\n");
541 if ((rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1) {
542 IWL_WARN(priv
, "mac/bssid mcast!\n");
546 /* make sure basic rates 6Mbps and 1Mbps are supported */
547 if ((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0 &&
548 (rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0) {
549 IWL_WARN(priv
, "neither 1 nor 6 are basic\n");
553 if (le16_to_cpu(rxon
->assoc_id
) > 2007) {
554 IWL_WARN(priv
, "aid > 2007\n");
558 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
559 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
)) {
560 IWL_WARN(priv
, "CCK and short slot\n");
564 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
565 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
)) {
566 IWL_WARN(priv
, "CCK and auto detect");
570 if ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
571 RXON_FLG_TGG_PROTECT_MSK
)) ==
572 RXON_FLG_TGG_PROTECT_MSK
) {
573 IWL_WARN(priv
, "TGg but no auto-detect\n");
577 if (rxon
->channel
== 0) {
578 IWL_WARN(priv
, "zero channel is invalid\n");
582 WARN(errors
, "Invalid RXON (%#x), channel %d",
583 errors
, le16_to_cpu(rxon
->channel
));
585 return errors
? -EINVAL
: 0;
589 * iwlagn_commit_rxon - commit staging_rxon to hardware
591 * The RXON command in staging_rxon is committed to the hardware and
592 * the active_rxon structure is updated with the new data. This
593 * function correctly transitions out of the RXON_ASSOC_MSK state if
594 * a HW tune is required based on the RXON structure changes.
596 * The connect/disconnect flow should be as the following:
598 * 1. make sure send RXON command with association bit unset if not connect
599 * this should include the channel and the band for the candidate
601 * 2. Add Station before RXON association with the AP
602 * 3. RXON_timing has to send before RXON for connection
603 * 4. full RXON command - associated bit set
604 * 5. use RXON_ASSOC command to update any flags changes
606 int iwlagn_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
608 /* cast away the const for active_rxon in this function */
609 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
610 bool new_assoc
= !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
613 lockdep_assert_held(&priv
->mutex
);
615 if (!iwl_is_alive(priv
))
618 /* This function hardcodes a bunch of dual-mode assumptions */
619 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
624 /* always get timestamp with Rx frame */
625 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
628 * force CTS-to-self frames protection if RTS-CTS is not preferred
629 * one aggregation protection method
631 if (!hw_params(priv
).use_rts_for_aggregation
)
632 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
634 if ((ctx
->vif
&& ctx
->vif
->bss_conf
.use_short_slot
) ||
635 !(ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
))
636 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
638 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
640 iwl_print_rx_config_cmd(priv
, ctx
->ctxid
);
641 ret
= iwl_check_rxon_cmd(priv
, ctx
);
643 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
648 * receive commit_rxon request
649 * abort any previous channel switch if still in process
651 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING
, &priv
->status
) &&
652 (priv
->switch_channel
!= ctx
->staging
.channel
)) {
653 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
654 le16_to_cpu(priv
->switch_channel
));
655 iwl_chswitch_done(priv
, false);
659 * If we don't need to send a full RXON, we can use
660 * iwl_rxon_assoc_cmd which is used to reconfigure filter
661 * and other flags for the current radio configuration.
663 if (!iwl_full_rxon_required(priv
, ctx
)) {
664 ret
= iwlagn_send_rxon_assoc(priv
, ctx
);
666 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
670 memcpy(active
, &ctx
->staging
, sizeof(*active
));
672 * We do not commit tx power settings while channel changing,
673 * do it now if after settings changed.
675 iwl_set_tx_power(priv
, priv
->tx_power_next
, false);
677 /* make sure we are in the right PS state */
678 iwl_power_update_mode(priv
, true);
683 iwl_set_rxon_hwcrypto(priv
, ctx
, !iwlagn_mod_params
.sw_crypto
);
686 "Going to commit RXON\n"
687 " * with%s RXON_FILTER_ASSOC_MSK\n"
690 (new_assoc
? "" : "out"),
691 le16_to_cpu(ctx
->staging
.channel
),
692 ctx
->staging
.bssid_addr
);
695 * Always clear associated first, but with the correct config.
696 * This is required as for example station addition for the
697 * AP station must be done after the BSSID is set to correctly
698 * set up filters in the device.
700 ret
= iwlagn_rxon_disconn(priv
, ctx
);
704 ret
= iwlagn_set_pan_params(priv
);
709 return iwlagn_rxon_connect(priv
, ctx
);
714 void iwlagn_config_ht40(struct ieee80211_conf
*conf
,
715 struct iwl_rxon_context
*ctx
)
717 if (conf_is_ht40_minus(conf
)) {
718 ctx
->ht
.extension_chan_offset
=
719 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
720 ctx
->ht
.is_40mhz
= true;
721 } else if (conf_is_ht40_plus(conf
)) {
722 ctx
->ht
.extension_chan_offset
=
723 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
724 ctx
->ht
.is_40mhz
= true;
726 ctx
->ht
.extension_chan_offset
=
727 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
728 ctx
->ht
.is_40mhz
= false;
732 int iwlagn_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
734 struct iwl_priv
*priv
= IWL_MAC80211_GET_DVM(hw
);
735 struct iwl_rxon_context
*ctx
;
736 struct ieee80211_conf
*conf
= &hw
->conf
;
737 struct ieee80211_channel
*channel
= conf
->channel
;
738 const struct iwl_channel_info
*ch_info
;
741 IWL_DEBUG_MAC80211(priv
, "enter: changed %#x\n", changed
);
743 mutex_lock(&priv
->mutex
);
745 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
746 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
750 if (!iwl_is_ready(priv
)) {
751 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
755 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
756 IEEE80211_CONF_CHANGE_CHANNEL
)) {
757 /* mac80211 uses static for non-HT which is what we want */
758 priv
->current_ht_config
.smps
= conf
->smps_mode
;
761 * Recalculate chain counts.
763 * If monitor mode is enabled then mac80211 will
764 * set up the SM PS mode to OFF if an HT channel is
767 for_each_context(priv
, ctx
)
768 iwlagn_set_rxon_chain(priv
, ctx
);
771 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
772 ch_info
= iwl_get_channel_info(priv
, channel
->band
,
774 if (!is_channel_valid(ch_info
)) {
775 IWL_DEBUG_MAC80211(priv
, "leave - invalid channel\n");
780 for_each_context(priv
, ctx
) {
781 /* Configure HT40 channels */
782 if (ctx
->ht
.enabled
!= conf_is_ht(conf
))
783 ctx
->ht
.enabled
= conf_is_ht(conf
);
785 if (ctx
->ht
.enabled
) {
786 /* if HT40 is used, it should not change
787 * after associated except channel switch */
788 if (!ctx
->ht
.is_40mhz
||
789 !iwl_is_associated_ctx(ctx
))
790 iwlagn_config_ht40(conf
, ctx
);
792 ctx
->ht
.is_40mhz
= false;
795 * Default to no protection. Protection mode will
796 * later be set from BSS config in iwl_ht_conf
798 ctx
->ht
.protection
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
800 /* if we are switching from ht to 2.4 clear flags
801 * from any ht related info since 2.4 does not
803 if (le16_to_cpu(ctx
->staging
.channel
) !=
805 ctx
->staging
.flags
= 0;
807 iwl_set_rxon_channel(priv
, channel
, ctx
);
808 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
810 iwl_set_flags_for_band(priv
, ctx
, channel
->band
,
814 iwl_update_bcast_stations(priv
);
817 * The list of supported rates and rate mask can be different
818 * for each band; since the band may have changed, reset
819 * the rate mask to what mac80211 lists.
824 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
825 IEEE80211_CONF_CHANGE_IDLE
)) {
826 ret
= iwl_power_update_mode(priv
, false);
828 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
831 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
832 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
833 priv
->tx_power_user_lmt
, conf
->power_level
);
835 iwl_set_tx_power(priv
, conf
->power_level
, false);
838 for_each_context(priv
, ctx
) {
839 if (!memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
841 iwlagn_commit_rxon(priv
, ctx
);
844 mutex_unlock(&priv
->mutex
);
845 IWL_DEBUG_MAC80211(priv
, "leave\n");
850 static void iwlagn_check_needed_chains(struct iwl_priv
*priv
,
851 struct iwl_rxon_context
*ctx
,
852 struct ieee80211_bss_conf
*bss_conf
)
854 struct ieee80211_vif
*vif
= ctx
->vif
;
855 struct iwl_rxon_context
*tmp
;
856 struct ieee80211_sta
*sta
;
857 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
858 struct ieee80211_sta_ht_cap
*ht_cap
;
861 lockdep_assert_held(&priv
->mutex
);
864 case NL80211_IFTYPE_STATION
:
866 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
869 * If at all, this can only happen through a race
870 * when the AP disconnects us while we're still
871 * setting up the connection, in that case mac80211
872 * will soon tell us about that.
874 need_multiple
= false;
879 ht_cap
= &sta
->ht_cap
;
881 need_multiple
= true;
884 * If the peer advertises no support for receiving 2 and 3
885 * stream MCS rates, it can't be transmitting them either.
887 if (ht_cap
->mcs
.rx_mask
[1] == 0 &&
888 ht_cap
->mcs
.rx_mask
[2] == 0) {
889 need_multiple
= false;
890 } else if (!(ht_cap
->mcs
.tx_params
&
891 IEEE80211_HT_MCS_TX_DEFINED
)) {
892 /* If it can't TX MCS at all ... */
893 need_multiple
= false;
894 } else if (ht_cap
->mcs
.tx_params
&
895 IEEE80211_HT_MCS_TX_RX_DIFF
) {
899 * But if it can receive them, it might still not
900 * be able to transmit them, which is what we need
901 * to check here -- so check the number of streams
902 * it advertises for TX (if different from RX).
905 maxstreams
= (ht_cap
->mcs
.tx_params
&
906 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
);
908 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
912 need_multiple
= false;
917 case NL80211_IFTYPE_ADHOC
:
919 need_multiple
= false;
923 need_multiple
= true;
927 ctx
->ht_need_multiple_chains
= need_multiple
;
929 if (!need_multiple
) {
930 /* check all contexts */
931 for_each_context(priv
, tmp
) {
934 if (tmp
->ht_need_multiple_chains
) {
935 need_multiple
= true;
941 ht_conf
->single_chain_sufficient
= !need_multiple
;
944 static void iwlagn_chain_noise_reset(struct iwl_priv
*priv
)
946 struct iwl_chain_noise_data
*data
= &priv
->chain_noise_data
;
949 if ((data
->state
== IWL_CHAIN_NOISE_ALIVE
) &&
950 iwl_is_any_associated(priv
)) {
951 struct iwl_calib_chain_noise_reset_cmd cmd
;
953 /* clear data for chain noise calibration algorithm */
954 data
->chain_noise_a
= 0;
955 data
->chain_noise_b
= 0;
956 data
->chain_noise_c
= 0;
957 data
->chain_signal_a
= 0;
958 data
->chain_signal_b
= 0;
959 data
->chain_signal_c
= 0;
960 data
->beacon_count
= 0;
962 memset(&cmd
, 0, sizeof(cmd
));
963 iwl_set_calib_hdr(&cmd
.hdr
,
964 priv
->phy_calib_chain_noise_reset_cmd
);
965 ret
= iwl_dvm_send_cmd_pdu(priv
,
966 REPLY_PHY_CALIBRATION_CMD
,
967 CMD_SYNC
, sizeof(cmd
), &cmd
);
970 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
971 data
->state
= IWL_CHAIN_NOISE_ACCUMULATE
;
972 IWL_DEBUG_CALIB(priv
, "Run chain_noise_calibrate\n");
976 void iwlagn_bss_info_changed(struct ieee80211_hw
*hw
,
977 struct ieee80211_vif
*vif
,
978 struct ieee80211_bss_conf
*bss_conf
,
981 struct iwl_priv
*priv
= IWL_MAC80211_GET_DVM(hw
);
982 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
986 mutex_lock(&priv
->mutex
);
988 if (unlikely(!iwl_is_ready(priv
))) {
989 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
990 mutex_unlock(&priv
->mutex
);
994 if (unlikely(!ctx
->vif
)) {
995 IWL_DEBUG_MAC80211(priv
, "leave - vif is NULL\n");
996 mutex_unlock(&priv
->mutex
);
1000 if (changes
& BSS_CHANGED_BEACON_INT
)
1003 if (changes
& BSS_CHANGED_QOS
) {
1004 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
1005 iwlagn_update_qos(priv
, ctx
);
1008 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
1009 if (vif
->bss_conf
.use_short_preamble
)
1010 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1012 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1014 if (changes
& BSS_CHANGED_ASSOC
) {
1015 if (bss_conf
->assoc
) {
1016 priv
->timestamp
= bss_conf
->last_tsf
;
1017 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1020 * If we disassociate while there are pending
1021 * frames, just wake up the queues and let the
1022 * frames "escape" ... This shouldn't really
1023 * be happening to start with, but we should
1024 * not get stuck in this case either since it
1025 * can happen if userspace gets confused.
1027 iwlagn_lift_passive_no_rx(priv
);
1029 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1031 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
)
1032 priv
->have_rekey_data
= false;
1035 iwlagn_bt_coex_rssi_monitor(priv
);
1038 if (ctx
->ht
.enabled
) {
1039 ctx
->ht
.protection
= bss_conf
->ht_operation_mode
&
1040 IEEE80211_HT_OP_MODE_PROTECTION
;
1041 ctx
->ht
.non_gf_sta_present
= !!(bss_conf
->ht_operation_mode
&
1042 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
1043 iwlagn_check_needed_chains(priv
, ctx
, bss_conf
);
1044 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
1047 iwlagn_set_rxon_chain(priv
, ctx
);
1049 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
1050 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
1052 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
1054 if (bss_conf
->use_cts_prot
)
1055 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
1057 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
1059 memcpy(ctx
->staging
.bssid_addr
, bss_conf
->bssid
, ETH_ALEN
);
1061 if (vif
->type
== NL80211_IFTYPE_AP
||
1062 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1063 if (vif
->bss_conf
.enable_beacon
) {
1064 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1065 priv
->beacon_ctx
= ctx
;
1067 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1068 priv
->beacon_ctx
= NULL
;
1073 * If the ucode decides to do beacon filtering before
1074 * association, it will lose beacons that are needed
1075 * before sending frames out on passive channels. This
1076 * causes association failures on those channels. Enable
1077 * receiving beacons in such cases.
1080 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1081 if (!bss_conf
->assoc
)
1082 ctx
->staging
.filter_flags
|= RXON_FILTER_BCON_AWARE_MSK
;
1084 ctx
->staging
.filter_flags
&=
1085 ~RXON_FILTER_BCON_AWARE_MSK
;
1088 if (force
|| memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1089 iwlagn_commit_rxon(priv
, ctx
);
1091 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
1093 * The chain noise calibration will enable PM upon
1094 * completion. If calibration has already been run
1095 * then we need to enable power management here.
1097 if (priv
->chain_noise_data
.state
== IWL_CHAIN_NOISE_DONE
)
1098 iwl_power_update_mode(priv
, false);
1100 /* Enable RX differential gain and sensitivity calibrations */
1101 if (!priv
->disable_chain_noise_cal
)
1102 iwlagn_chain_noise_reset(priv
);
1103 priv
->start_calib
= 1;
1106 if (changes
& BSS_CHANGED_IBSS
) {
1107 ret
= iwlagn_manage_ibss_station(priv
, vif
,
1108 bss_conf
->ibss_joined
);
1110 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
1111 bss_conf
->ibss_joined
? "add" : "remove",
1115 if (changes
& BSS_CHANGED_BEACON
&& vif
->type
== NL80211_IFTYPE_ADHOC
&&
1117 if (iwlagn_update_beacon(priv
, vif
))
1118 IWL_ERR(priv
, "Error sending IBSS beacon\n");
1121 mutex_unlock(&priv
->mutex
);
1124 void iwlagn_post_scan(struct iwl_priv
*priv
)
1126 struct iwl_rxon_context
*ctx
;
1129 * We do not commit power settings while scan is pending,
1130 * do it now if the settings changed.
1132 iwl_power_set_mode(priv
, &priv
->power_data
.sleep_cmd_next
, false);
1133 iwl_set_tx_power(priv
, priv
->tx_power_next
, false);
1136 * Since setting the RXON may have been deferred while
1137 * performing the scan, fire one off if needed
1139 for_each_context(priv
, ctx
)
1140 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1141 iwlagn_commit_rxon(priv
, ctx
);
1143 iwlagn_set_pan_params(priv
);