1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2014 Intel Mobile Communications GmbH
9 * Copyright(c) 2017 Intel Deutschland GmbH
10 * Copyright(C) 2018 - 2019 Intel Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * The full GNU General Public License is included in this distribution
22 * in the file called COPYING.
24 * Contact Information:
25 * Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 * Copyright(c) 2014 Intel Mobile Communications GmbH
31 * Copyright(c) 2017 Intel Deutschland GmbH
32 * Copyright(C) 2018 - 2019 Intel Corporation
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
63 #include <linux/etherdevice.h>
65 #include "time-event.h"
69 #define TU_TO_US(x) (x * 1024)
70 #define TU_TO_MS(x) (TU_TO_US(x) / 1000)
72 void iwl_mvm_teardown_tdls_peers(struct iwl_mvm
*mvm
)
74 struct ieee80211_sta
*sta
;
75 struct iwl_mvm_sta
*mvmsta
;
78 lockdep_assert_held(&mvm
->mutex
);
80 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
81 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
82 lockdep_is_held(&mvm
->mutex
));
83 if (!sta
|| IS_ERR(sta
) || !sta
->tdls
)
86 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
87 ieee80211_tdls_oper_request(mvmsta
->vif
, sta
->addr
,
88 NL80211_TDLS_TEARDOWN
,
89 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
,
94 int iwl_mvm_tdls_sta_count(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
96 struct ieee80211_sta
*sta
;
97 struct iwl_mvm_sta
*mvmsta
;
101 lockdep_assert_held(&mvm
->mutex
);
103 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
104 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
105 lockdep_is_held(&mvm
->mutex
));
106 if (!sta
|| IS_ERR(sta
) || !sta
->tdls
)
110 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
111 if (mvmsta
->vif
!= vif
)
121 static void iwl_mvm_tdls_config(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
123 struct iwl_rx_packet
*pkt
;
124 struct iwl_tdls_config_res
*resp
;
125 struct iwl_tdls_config_cmd tdls_cfg_cmd
= {};
126 struct iwl_host_cmd cmd
= {
127 .id
= TDLS_CONFIG_CMD
,
128 .flags
= CMD_WANT_SKB
,
129 .data
= { &tdls_cfg_cmd
, },
130 .len
= { sizeof(struct iwl_tdls_config_cmd
), },
132 struct ieee80211_sta
*sta
;
134 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
136 lockdep_assert_held(&mvm
->mutex
);
138 tdls_cfg_cmd
.id_and_color
=
139 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
, mvmvif
->color
));
140 tdls_cfg_cmd
.tx_to_ap_tid
= IWL_MVM_TDLS_FW_TID
;
141 tdls_cfg_cmd
.tx_to_ap_ssn
= cpu_to_le16(0); /* not used for now */
143 /* for now the Tx cmd is empty and unused */
145 /* populate TDLS peer data */
147 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
148 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
149 lockdep_is_held(&mvm
->mutex
));
150 if (IS_ERR_OR_NULL(sta
) || !sta
->tdls
)
153 tdls_cfg_cmd
.sta_info
[cnt
].sta_id
= i
;
154 tdls_cfg_cmd
.sta_info
[cnt
].tx_to_peer_tid
=
156 tdls_cfg_cmd
.sta_info
[cnt
].tx_to_peer_ssn
= cpu_to_le16(0);
157 tdls_cfg_cmd
.sta_info
[cnt
].is_initiator
=
158 cpu_to_le32(sta
->tdls_initiator
? 1 : 0);
163 tdls_cfg_cmd
.tdls_peer_count
= cnt
;
164 IWL_DEBUG_TDLS(mvm
, "send TDLS config to FW for %d peers\n", cnt
);
166 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
167 if (WARN_ON_ONCE(ret
))
172 WARN_ON_ONCE(iwl_rx_packet_payload_len(pkt
) != sizeof(*resp
));
174 /* we don't really care about the response at this point */
179 void iwl_mvm_recalc_tdls_state(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
182 int tdls_sta_cnt
= iwl_mvm_tdls_sta_count(mvm
, vif
);
184 /* when the first peer joins, send a power update first */
185 if (tdls_sta_cnt
== 1 && sta_added
)
186 iwl_mvm_power_update_mac(mvm
);
188 /* Configure the FW with TDLS peer info only if TDLS channel switch
190 * TDLS config data is used currently only in TDLS channel switch code.
191 * Supposed to serve also TDLS buffer station which is not implemneted
193 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
194 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH
))
195 iwl_mvm_tdls_config(mvm
, vif
);
197 /* when the last peer leaves, send a power update last */
198 if (tdls_sta_cnt
== 0 && !sta_added
)
199 iwl_mvm_power_update_mac(mvm
);
202 void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw
*hw
,
203 struct ieee80211_vif
*vif
)
205 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
206 u32 duration
= 2 * vif
->bss_conf
.dtim_period
* vif
->bss_conf
.beacon_int
;
208 mutex_lock(&mvm
->mutex
);
209 /* Protect the session to hear the TDLS setup response on the channel */
210 iwl_mvm_protect_session(mvm
, vif
, duration
, duration
, 100, true);
211 mutex_unlock(&mvm
->mutex
);
215 iwl_mvm_tdls_cs_state_str(enum iwl_mvm_tdls_cs_state state
)
218 case IWL_MVM_TDLS_SW_IDLE
:
220 case IWL_MVM_TDLS_SW_REQ_SENT
:
222 case IWL_MVM_TDLS_SW_RESP_RCVD
:
223 return "RESP RECEIVED";
224 case IWL_MVM_TDLS_SW_REQ_RCVD
:
225 return "REQ RECEIVED";
226 case IWL_MVM_TDLS_SW_ACTIVE
:
233 static void iwl_mvm_tdls_update_cs_state(struct iwl_mvm
*mvm
,
234 enum iwl_mvm_tdls_cs_state state
)
236 if (mvm
->tdls_cs
.state
== state
)
239 IWL_DEBUG_TDLS(mvm
, "TDLS channel switch state: %s -> %s\n",
240 iwl_mvm_tdls_cs_state_str(mvm
->tdls_cs
.state
),
241 iwl_mvm_tdls_cs_state_str(state
));
242 mvm
->tdls_cs
.state
= state
;
244 /* we only send requests to our switching peer - update sent time */
245 if (state
== IWL_MVM_TDLS_SW_REQ_SENT
)
246 mvm
->tdls_cs
.peer
.sent_timestamp
= iwl_mvm_get_systime(mvm
);
248 if (state
== IWL_MVM_TDLS_SW_IDLE
)
249 mvm
->tdls_cs
.cur_sta_id
= IWL_MVM_INVALID_STA
;
252 void iwl_mvm_rx_tdls_notif(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
)
254 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
255 struct iwl_tdls_channel_switch_notif
*notif
= (void *)pkt
->data
;
256 struct ieee80211_sta
*sta
;
258 struct iwl_mvm_sta
*mvmsta
;
259 struct ieee80211_vif
*vif
;
260 u32 sta_id
= le32_to_cpu(notif
->sta_id
);
262 lockdep_assert_held(&mvm
->mutex
);
264 /* can fail sometimes */
265 if (!le32_to_cpu(notif
->status
)) {
266 iwl_mvm_tdls_update_cs_state(mvm
, IWL_MVM_TDLS_SW_IDLE
);
270 if (WARN_ON(sta_id
>= IWL_MVM_STATION_COUNT
))
273 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
274 lockdep_is_held(&mvm
->mutex
));
275 /* the station may not be here, but if it is, it must be a TDLS peer */
276 if (IS_ERR_OR_NULL(sta
) || WARN_ON(!sta
->tdls
))
279 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
283 * Update state and possibly switch again after this is over (DTIM).
284 * Also convert TU to msec.
286 delay
= TU_TO_MS(vif
->bss_conf
.dtim_period
* vif
->bss_conf
.beacon_int
);
287 mod_delayed_work(system_wq
, &mvm
->tdls_cs
.dwork
,
288 msecs_to_jiffies(delay
));
290 iwl_mvm_tdls_update_cs_state(mvm
, IWL_MVM_TDLS_SW_ACTIVE
);
294 iwl_mvm_tdls_check_action(struct iwl_mvm
*mvm
,
295 enum iwl_tdls_channel_switch_type type
,
296 const u8
*peer
, bool peer_initiator
, u32 timestamp
)
298 bool same_peer
= false;
301 /* get the existing peer if it's there */
302 if (mvm
->tdls_cs
.state
!= IWL_MVM_TDLS_SW_IDLE
&&
303 mvm
->tdls_cs
.cur_sta_id
!= IWL_MVM_INVALID_STA
) {
304 struct ieee80211_sta
*sta
= rcu_dereference_protected(
305 mvm
->fw_id_to_mac_id
[mvm
->tdls_cs
.cur_sta_id
],
306 lockdep_is_held(&mvm
->mutex
));
307 if (!IS_ERR_OR_NULL(sta
))
308 same_peer
= ether_addr_equal(peer
, sta
->addr
);
311 switch (mvm
->tdls_cs
.state
) {
312 case IWL_MVM_TDLS_SW_IDLE
:
314 * might be spurious packet from the peer after the switch is
317 if (type
== TDLS_MOVE_CH
)
320 case IWL_MVM_TDLS_SW_REQ_SENT
:
321 /* only allow requests from the same peer */
324 else if (type
== TDLS_SEND_CHAN_SW_RESP_AND_MOVE_CH
&&
327 * We received a ch-switch request while an outgoing
328 * one is pending. Allow it if the peer is the link
332 else if (type
== TDLS_SEND_CHAN_SW_REQ
)
333 /* wait for idle before sending another request */
335 else if (timestamp
<= mvm
->tdls_cs
.peer
.sent_timestamp
)
336 /* we got a stale response - ignore it */
339 case IWL_MVM_TDLS_SW_RESP_RCVD
:
341 * we are waiting for the FW to give an "active" notification,
342 * so ignore requests in the meantime
346 case IWL_MVM_TDLS_SW_REQ_RCVD
:
347 /* as above, allow the link initiator to proceed */
348 if (type
== TDLS_SEND_CHAN_SW_REQ
) {
351 else if (peer_initiator
) /* they are the initiator */
353 } else if (type
== TDLS_MOVE_CH
) {
357 case IWL_MVM_TDLS_SW_ACTIVE
:
359 * the only valid request when active is a request to return
360 * to the base channel by the current off-channel peer
362 if (type
!= TDLS_MOVE_CH
|| !same_peer
)
369 "Invalid TDLS action %d state %d peer %pM same_peer %d initiator %d\n",
370 type
, mvm
->tdls_cs
.state
, peer
, same_peer
,
377 iwl_mvm_tdls_config_channel_switch(struct iwl_mvm
*mvm
,
378 struct ieee80211_vif
*vif
,
379 enum iwl_tdls_channel_switch_type type
,
380 const u8
*peer
, bool peer_initiator
,
382 struct cfg80211_chan_def
*chandef
,
383 u32 timestamp
, u16 switch_time
,
384 u16 switch_timeout
, struct sk_buff
*skb
,
387 struct ieee80211_sta
*sta
;
388 struct iwl_mvm_sta
*mvmsta
;
389 struct ieee80211_tx_info
*info
;
390 struct ieee80211_hdr
*hdr
;
391 struct iwl_tdls_channel_switch_cmd cmd
= {0};
392 struct iwl_tdls_channel_switch_cmd_tail
*tail
=
393 iwl_mvm_chan_info_cmd_tail(mvm
, &cmd
.ci
);
394 u16 len
= sizeof(cmd
) - iwl_mvm_chan_info_padding(mvm
);
397 lockdep_assert_held(&mvm
->mutex
);
399 ret
= iwl_mvm_tdls_check_action(mvm
, type
, peer
, peer_initiator
,
404 if (!skb
|| WARN_ON(skb
->len
> IWL_TDLS_CH_SW_FRAME_MAX_SIZE
)) {
409 cmd
.switch_type
= type
;
410 tail
->timing
.frame_timestamp
= cpu_to_le32(timestamp
);
411 tail
->timing
.switch_time
= cpu_to_le32(switch_time
);
412 tail
->timing
.switch_timeout
= cpu_to_le32(switch_timeout
);
415 sta
= ieee80211_find_sta(vif
, peer
);
421 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
422 cmd
.peer_sta_id
= cpu_to_le32(mvmsta
->sta_id
);
425 if (mvm
->tdls_cs
.state
== IWL_MVM_TDLS_SW_REQ_SENT
&&
426 mvm
->tdls_cs
.peer
.chandef
.chan
) {
427 /* actually moving to the channel */
428 chandef
= &mvm
->tdls_cs
.peer
.chandef
;
429 } else if (mvm
->tdls_cs
.state
== IWL_MVM_TDLS_SW_ACTIVE
&&
430 type
== TDLS_MOVE_CH
) {
431 /* we need to return to base channel */
432 struct ieee80211_chanctx_conf
*chanctx
=
433 rcu_dereference(vif
->chanctx_conf
);
435 if (WARN_ON_ONCE(!chanctx
)) {
440 chandef
= &chanctx
->def
;
445 iwl_mvm_set_chan_info_chandef(mvm
, &cmd
.ci
, chandef
);
447 /* keep quota calculation simple for now - 50% of DTIM for TDLS */
448 tail
->timing
.max_offchan_duration
=
449 cpu_to_le32(TU_TO_US(vif
->bss_conf
.dtim_period
*
450 vif
->bss_conf
.beacon_int
) / 2);
452 /* Switch time is the first element in the switch-timing IE. */
453 tail
->frame
.switch_time_offset
= cpu_to_le32(ch_sw_tm_ie
+ 2);
455 info
= IEEE80211_SKB_CB(skb
);
456 hdr
= (void *)skb
->data
;
457 if (info
->control
.hw_key
) {
458 if (info
->control
.hw_key
->cipher
!= WLAN_CIPHER_SUITE_CCMP
) {
463 iwl_mvm_set_tx_cmd_ccmp(info
, &tail
->frame
.tx_cmd
);
466 iwl_mvm_set_tx_cmd(mvm
, skb
, &tail
->frame
.tx_cmd
, info
,
469 iwl_mvm_set_tx_cmd_rate(mvm
, &tail
->frame
.tx_cmd
, info
, sta
,
473 memcpy(tail
->frame
.data
, skb
->data
, skb
->len
);
475 ret
= iwl_mvm_send_cmd_pdu(mvm
, TDLS_CHANNEL_SWITCH_CMD
, 0, len
, &cmd
);
477 IWL_ERR(mvm
, "Failed to send TDLS_CHANNEL_SWITCH cmd: %d\n",
482 /* channel switch has started, update state */
483 if (type
!= TDLS_MOVE_CH
) {
484 mvm
->tdls_cs
.cur_sta_id
= mvmsta
->sta_id
;
485 iwl_mvm_tdls_update_cs_state(mvm
,
486 type
== TDLS_SEND_CHAN_SW_REQ
?
487 IWL_MVM_TDLS_SW_REQ_SENT
:
488 IWL_MVM_TDLS_SW_REQ_RCVD
);
490 iwl_mvm_tdls_update_cs_state(mvm
, IWL_MVM_TDLS_SW_RESP_RCVD
);
495 /* channel switch failed - we are idle */
497 iwl_mvm_tdls_update_cs_state(mvm
, IWL_MVM_TDLS_SW_IDLE
);
502 void iwl_mvm_tdls_ch_switch_work(struct work_struct
*work
)
505 struct ieee80211_sta
*sta
;
506 struct iwl_mvm_sta
*mvmsta
;
507 struct ieee80211_vif
*vif
;
511 mvm
= container_of(work
, struct iwl_mvm
, tdls_cs
.dwork
.work
);
512 mutex_lock(&mvm
->mutex
);
514 /* called after an active channel switch has finished or timed-out */
515 iwl_mvm_tdls_update_cs_state(mvm
, IWL_MVM_TDLS_SW_IDLE
);
517 /* station might be gone, in that case do nothing */
518 if (mvm
->tdls_cs
.peer
.sta_id
== IWL_MVM_INVALID_STA
)
521 sta
= rcu_dereference_protected(
522 mvm
->fw_id_to_mac_id
[mvm
->tdls_cs
.peer
.sta_id
],
523 lockdep_is_held(&mvm
->mutex
));
524 /* the station may not be here, but if it is, it must be a TDLS peer */
525 if (!sta
|| IS_ERR(sta
) || WARN_ON(!sta
->tdls
))
528 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
530 ret
= iwl_mvm_tdls_config_channel_switch(mvm
, vif
,
531 TDLS_SEND_CHAN_SW_REQ
,
533 mvm
->tdls_cs
.peer
.initiator
,
534 mvm
->tdls_cs
.peer
.op_class
,
535 &mvm
->tdls_cs
.peer
.chandef
,
537 mvm
->tdls_cs
.peer
.skb
,
538 mvm
->tdls_cs
.peer
.ch_sw_tm_ie
);
540 IWL_ERR(mvm
, "Not sending TDLS channel switch: %d\n", ret
);
542 /* retry after a DTIM if we failed sending now */
543 delay
= TU_TO_MS(vif
->bss_conf
.dtim_period
* vif
->bss_conf
.beacon_int
);
544 schedule_delayed_work(&mvm
->tdls_cs
.dwork
, msecs_to_jiffies(delay
));
546 mutex_unlock(&mvm
->mutex
);
550 iwl_mvm_tdls_channel_switch(struct ieee80211_hw
*hw
,
551 struct ieee80211_vif
*vif
,
552 struct ieee80211_sta
*sta
, u8 oper_class
,
553 struct cfg80211_chan_def
*chandef
,
554 struct sk_buff
*tmpl_skb
, u32 ch_sw_tm_ie
)
556 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
557 struct iwl_mvm_sta
*mvmsta
;
561 mutex_lock(&mvm
->mutex
);
563 IWL_DEBUG_TDLS(mvm
, "TDLS channel switch with %pM ch %d width %d\n",
564 sta
->addr
, chandef
->chan
->center_freq
, chandef
->width
);
566 /* we only support a single peer for channel switching */
567 if (mvm
->tdls_cs
.peer
.sta_id
!= IWL_MVM_INVALID_STA
) {
569 "Existing peer. Can't start switch with %pM\n",
575 ret
= iwl_mvm_tdls_config_channel_switch(mvm
, vif
,
576 TDLS_SEND_CHAN_SW_REQ
,
577 sta
->addr
, sta
->tdls_initiator
,
578 oper_class
, chandef
, 0, 0, 0,
579 tmpl_skb
, ch_sw_tm_ie
);
584 * Mark the peer as "in tdls switch" for this vif. We only allow a
585 * single such peer per vif.
587 mvm
->tdls_cs
.peer
.skb
= skb_copy(tmpl_skb
, GFP_KERNEL
);
588 if (!mvm
->tdls_cs
.peer
.skb
) {
593 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
594 mvm
->tdls_cs
.peer
.sta_id
= mvmsta
->sta_id
;
595 mvm
->tdls_cs
.peer
.chandef
= *chandef
;
596 mvm
->tdls_cs
.peer
.initiator
= sta
->tdls_initiator
;
597 mvm
->tdls_cs
.peer
.op_class
= oper_class
;
598 mvm
->tdls_cs
.peer
.ch_sw_tm_ie
= ch_sw_tm_ie
;
601 * Wait for 2 DTIM periods before attempting the next switch. The next
602 * switch will be made sooner if the current one completes before that.
604 delay
= 2 * TU_TO_MS(vif
->bss_conf
.dtim_period
*
605 vif
->bss_conf
.beacon_int
);
606 mod_delayed_work(system_wq
, &mvm
->tdls_cs
.dwork
,
607 msecs_to_jiffies(delay
));
610 mutex_unlock(&mvm
->mutex
);
614 void iwl_mvm_tdls_cancel_channel_switch(struct ieee80211_hw
*hw
,
615 struct ieee80211_vif
*vif
,
616 struct ieee80211_sta
*sta
)
618 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
619 struct ieee80211_sta
*cur_sta
;
620 bool wait_for_phy
= false;
622 mutex_lock(&mvm
->mutex
);
624 IWL_DEBUG_TDLS(mvm
, "TDLS cancel channel switch with %pM\n", sta
->addr
);
626 /* we only support a single peer for channel switching */
627 if (mvm
->tdls_cs
.peer
.sta_id
== IWL_MVM_INVALID_STA
) {
628 IWL_DEBUG_TDLS(mvm
, "No ch switch peer - %pM\n", sta
->addr
);
632 cur_sta
= rcu_dereference_protected(
633 mvm
->fw_id_to_mac_id
[mvm
->tdls_cs
.peer
.sta_id
],
634 lockdep_is_held(&mvm
->mutex
));
635 /* make sure it's the same peer */
640 * If we're currently in a switch because of the now canceled peer,
641 * wait a DTIM here to make sure the phy is back on the base channel.
642 * We can't otherwise force it.
644 if (mvm
->tdls_cs
.cur_sta_id
== mvm
->tdls_cs
.peer
.sta_id
&&
645 mvm
->tdls_cs
.state
!= IWL_MVM_TDLS_SW_IDLE
)
648 mvm
->tdls_cs
.peer
.sta_id
= IWL_MVM_INVALID_STA
;
649 dev_kfree_skb(mvm
->tdls_cs
.peer
.skb
);
650 mvm
->tdls_cs
.peer
.skb
= NULL
;
653 mutex_unlock(&mvm
->mutex
);
655 /* make sure the phy is on the base channel */
657 msleep(TU_TO_MS(vif
->bss_conf
.dtim_period
*
658 vif
->bss_conf
.beacon_int
));
660 /* flush the channel switch state */
661 flush_delayed_work(&mvm
->tdls_cs
.dwork
);
663 IWL_DEBUG_TDLS(mvm
, "TDLS ending channel switch with %pM\n", sta
->addr
);
667 iwl_mvm_tdls_recv_channel_switch(struct ieee80211_hw
*hw
,
668 struct ieee80211_vif
*vif
,
669 struct ieee80211_tdls_ch_sw_params
*params
)
671 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
672 enum iwl_tdls_channel_switch_type type
;
674 const char *action_str
=
675 params
->action_code
== WLAN_TDLS_CHANNEL_SWITCH_REQUEST
?
678 mutex_lock(&mvm
->mutex
);
681 "Received TDLS ch switch action %s from %pM status %d\n",
682 action_str
, params
->sta
->addr
, params
->status
);
685 * we got a non-zero status from a peer we were switching to - move to
686 * the idle state and retry again later
688 if (params
->action_code
== WLAN_TDLS_CHANNEL_SWITCH_RESPONSE
&&
689 params
->status
!= 0 &&
690 mvm
->tdls_cs
.state
== IWL_MVM_TDLS_SW_REQ_SENT
&&
691 mvm
->tdls_cs
.cur_sta_id
!= IWL_MVM_INVALID_STA
) {
692 struct ieee80211_sta
*cur_sta
;
694 /* make sure it's the same peer */
695 cur_sta
= rcu_dereference_protected(
696 mvm
->fw_id_to_mac_id
[mvm
->tdls_cs
.cur_sta_id
],
697 lockdep_is_held(&mvm
->mutex
));
698 if (cur_sta
== params
->sta
) {
699 iwl_mvm_tdls_update_cs_state(mvm
,
700 IWL_MVM_TDLS_SW_IDLE
);
705 type
= (params
->action_code
== WLAN_TDLS_CHANNEL_SWITCH_REQUEST
) ?
706 TDLS_SEND_CHAN_SW_RESP_AND_MOVE_CH
: TDLS_MOVE_CH
;
708 iwl_mvm_tdls_config_channel_switch(mvm
, vif
, type
, params
->sta
->addr
,
709 params
->sta
->tdls_initiator
, 0,
710 params
->chandef
, params
->timestamp
,
712 params
->switch_timeout
,
714 params
->ch_sw_tm_ie
);
717 /* register a timeout in case we don't succeed in switching */
718 delay
= vif
->bss_conf
.dtim_period
* vif
->bss_conf
.beacon_int
*
720 mod_delayed_work(system_wq
, &mvm
->tdls_cs
.dwork
,
721 msecs_to_jiffies(delay
));
722 mutex_unlock(&mvm
->mutex
);