2 * NXP Wireless LAN device driver: TDLS handling
4 * Copyright 2011-2020 NXP
6 * This software file (the "File") is distributed by NXP
7 * under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available on the worldwide web at
11 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
14 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
15 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
16 * this warranty disclaimer.
22 #include "11n_rxreorder.h"
25 #define TDLS_REQ_FIX_LEN 6
26 #define TDLS_RESP_FIX_LEN 8
27 #define TDLS_CONFIRM_FIX_LEN 6
28 #define MWIFIEX_TDLS_WMM_INFO_SIZE 7
30 static void mwifiex_restore_tdls_packets(struct mwifiex_private
*priv
,
31 const u8
*mac
, u8 status
)
33 struct mwifiex_ra_list_tbl
*ra_list
;
34 struct list_head
*tid_list
;
35 struct sk_buff
*skb
, *tmp
;
36 struct mwifiex_txinfo
*tx_info
;
40 mwifiex_dbg(priv
->adapter
, DATA
, "%s: %pM\n", __func__
, mac
);
41 spin_lock_bh(&priv
->wmm
.ra_list_spinlock
);
43 skb_queue_walk_safe(&priv
->tdls_txq
, skb
, tmp
) {
44 if (!ether_addr_equal(mac
, skb
->data
))
47 __skb_unlink(skb
, &priv
->tdls_txq
);
48 tx_info
= MWIFIEX_SKB_TXCB(skb
);
50 tid_down
= mwifiex_wmm_downgrade_tid(priv
, tid
);
52 if (mwifiex_is_tdls_link_setup(status
)) {
53 ra_list
= mwifiex_wmm_get_queue_raptr(priv
, tid
, mac
);
54 ra_list
->tdls_link
= true;
55 tx_info
->flags
|= MWIFIEX_BUF_FLAG_TDLS_PKT
;
57 tid_list
= &priv
->wmm
.tid_tbl_ptr
[tid_down
].ra_list
;
58 ra_list
= list_first_entry_or_null(tid_list
,
59 struct mwifiex_ra_list_tbl
, list
);
60 tx_info
->flags
&= ~MWIFIEX_BUF_FLAG_TDLS_PKT
;
64 mwifiex_write_data_complete(priv
->adapter
, skb
, 0, -1);
68 skb_queue_tail(&ra_list
->skb_head
, skb
);
70 ra_list
->ba_pkt_count
++;
71 ra_list
->total_pkt_count
++;
73 if (atomic_read(&priv
->wmm
.highest_queued_prio
) <
74 tos_to_tid_inv
[tid_down
])
75 atomic_set(&priv
->wmm
.highest_queued_prio
,
76 tos_to_tid_inv
[tid_down
]);
78 atomic_inc(&priv
->wmm
.tx_pkts_queued
);
81 spin_unlock_bh(&priv
->wmm
.ra_list_spinlock
);
85 static void mwifiex_hold_tdls_packets(struct mwifiex_private
*priv
,
88 struct mwifiex_ra_list_tbl
*ra_list
;
89 struct list_head
*ra_list_head
;
90 struct sk_buff
*skb
, *tmp
;
93 mwifiex_dbg(priv
->adapter
, DATA
, "%s: %pM\n", __func__
, mac
);
94 spin_lock_bh(&priv
->wmm
.ra_list_spinlock
);
96 for (i
= 0; i
< MAX_NUM_TID
; i
++) {
97 if (!list_empty(&priv
->wmm
.tid_tbl_ptr
[i
].ra_list
)) {
98 ra_list_head
= &priv
->wmm
.tid_tbl_ptr
[i
].ra_list
;
99 list_for_each_entry(ra_list
, ra_list_head
, list
) {
100 skb_queue_walk_safe(&ra_list
->skb_head
, skb
,
102 if (!ether_addr_equal(mac
, skb
->data
))
104 __skb_unlink(skb
, &ra_list
->skb_head
);
105 atomic_dec(&priv
->wmm
.tx_pkts_queued
);
106 ra_list
->total_pkt_count
--;
107 skb_queue_tail(&priv
->tdls_txq
, skb
);
113 spin_unlock_bh(&priv
->wmm
.ra_list_spinlock
);
117 /* This function appends rate TLV to scan config command. */
119 mwifiex_tdls_append_rates_ie(struct mwifiex_private
*priv
,
122 u8 rates
[MWIFIEX_SUPPORTED_RATES
], *pos
;
123 u16 rates_size
, supp_rates_size
, ext_rates_size
;
125 memset(rates
, 0, sizeof(rates
));
126 rates_size
= mwifiex_get_supported_rates(priv
, rates
);
128 supp_rates_size
= min_t(u16
, rates_size
, MWIFIEX_TDLS_SUPPORTED_RATES
);
130 if (skb_tailroom(skb
) < rates_size
+ 4) {
131 mwifiex_dbg(priv
->adapter
, ERROR
,
132 "Insufficient space while adding rates\n");
136 pos
= skb_put(skb
, supp_rates_size
+ 2);
137 *pos
++ = WLAN_EID_SUPP_RATES
;
138 *pos
++ = supp_rates_size
;
139 memcpy(pos
, rates
, supp_rates_size
);
141 if (rates_size
> MWIFIEX_TDLS_SUPPORTED_RATES
) {
142 ext_rates_size
= rates_size
- MWIFIEX_TDLS_SUPPORTED_RATES
;
143 pos
= skb_put(skb
, ext_rates_size
+ 2);
144 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
145 *pos
++ = ext_rates_size
;
146 memcpy(pos
, rates
+ MWIFIEX_TDLS_SUPPORTED_RATES
,
153 static void mwifiex_tdls_add_aid(struct mwifiex_private
*priv
,
156 struct ieee_types_assoc_rsp
*assoc_rsp
;
159 assoc_rsp
= (struct ieee_types_assoc_rsp
*)&priv
->assoc_rsp_buf
;
160 pos
= skb_put(skb
, 4);
161 *pos
++ = WLAN_EID_AID
;
163 memcpy(pos
, &assoc_rsp
->a_id
, sizeof(assoc_rsp
->a_id
));
168 static int mwifiex_tdls_add_vht_capab(struct mwifiex_private
*priv
,
171 struct ieee80211_vht_cap vht_cap
;
174 pos
= skb_put(skb
, sizeof(struct ieee80211_vht_cap
) + 2);
175 *pos
++ = WLAN_EID_VHT_CAPABILITY
;
176 *pos
++ = sizeof(struct ieee80211_vht_cap
);
178 memset(&vht_cap
, 0, sizeof(struct ieee80211_vht_cap
));
180 mwifiex_fill_vht_cap_tlv(priv
, &vht_cap
, priv
->curr_bss_params
.band
);
181 memcpy(pos
, &vht_cap
, sizeof(vht_cap
));
187 mwifiex_tdls_add_ht_oper(struct mwifiex_private
*priv
, const u8
*mac
,
188 u8 vht_enabled
, struct sk_buff
*skb
)
190 struct ieee80211_ht_operation
*ht_oper
;
191 struct mwifiex_sta_node
*sta_ptr
;
192 struct mwifiex_bssdescriptor
*bss_desc
=
193 &priv
->curr_bss_params
.bss_descriptor
;
196 sta_ptr
= mwifiex_get_sta_entry(priv
, mac
);
197 if (unlikely(!sta_ptr
)) {
198 mwifiex_dbg(priv
->adapter
, ERROR
,
199 "TDLS peer station not found in list\n");
203 if (!(le16_to_cpu(sta_ptr
->tdls_cap
.ht_capb
.cap_info
))) {
204 mwifiex_dbg(priv
->adapter
, WARN
,
205 "TDLS peer doesn't support ht capabilities\n");
209 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_operation
) + 2);
210 *pos
++ = WLAN_EID_HT_OPERATION
;
211 *pos
++ = sizeof(struct ieee80211_ht_operation
);
212 ht_oper
= (void *)pos
;
214 ht_oper
->primary_chan
= bss_desc
->channel
;
216 /* follow AP's channel bandwidth */
217 if (ISSUPP_CHANWIDTH40(priv
->adapter
->hw_dot_11n_dev_cap
) &&
218 bss_desc
->bcn_ht_cap
&&
219 ISALLOWED_CHANWIDTH40(bss_desc
->bcn_ht_oper
->ht_param
))
220 ht_oper
->ht_param
= bss_desc
->bcn_ht_oper
->ht_param
;
224 mwifiex_get_sec_chan_offset(bss_desc
->channel
);
225 ht_oper
->ht_param
|= BIT(2);
228 memcpy(&sta_ptr
->tdls_cap
.ht_oper
, ht_oper
,
229 sizeof(struct ieee80211_ht_operation
));
234 static int mwifiex_tdls_add_vht_oper(struct mwifiex_private
*priv
,
235 const u8
*mac
, struct sk_buff
*skb
)
237 struct mwifiex_bssdescriptor
*bss_desc
;
238 struct ieee80211_vht_operation
*vht_oper
;
239 struct ieee80211_vht_cap
*vht_cap
, *ap_vht_cap
= NULL
;
240 struct mwifiex_sta_node
*sta_ptr
;
241 struct mwifiex_adapter
*adapter
= priv
->adapter
;
242 u8 supp_chwd_set
, peer_supp_chwd_set
;
243 u8
*pos
, ap_supp_chwd_set
, chan_bw
;
244 u16 mcs_map_user
, mcs_map_resp
, mcs_map_result
;
245 u16 mcs_user
, mcs_resp
, nss
;
246 u32 usr_vht_cap_info
;
248 bss_desc
= &priv
->curr_bss_params
.bss_descriptor
;
250 sta_ptr
= mwifiex_get_sta_entry(priv
, mac
);
251 if (unlikely(!sta_ptr
)) {
252 mwifiex_dbg(adapter
, ERROR
,
253 "TDLS peer station not found in list\n");
257 if (!(le32_to_cpu(sta_ptr
->tdls_cap
.vhtcap
.vht_cap_info
))) {
258 mwifiex_dbg(adapter
, WARN
,
259 "TDLS peer doesn't support vht capabilities\n");
263 if (!mwifiex_is_bss_in_11ac_mode(priv
)) {
264 if (sta_ptr
->tdls_cap
.extcap
.ext_capab
[7] &
265 WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED
) {
266 mwifiex_dbg(adapter
, WARN
,
267 "TDLS peer doesn't support wider bandwidth\n");
271 ap_vht_cap
= bss_desc
->bcn_vht_cap
;
274 pos
= skb_put(skb
, sizeof(struct ieee80211_vht_operation
) + 2);
275 *pos
++ = WLAN_EID_VHT_OPERATION
;
276 *pos
++ = sizeof(struct ieee80211_vht_operation
);
277 vht_oper
= (struct ieee80211_vht_operation
*)pos
;
279 if (bss_desc
->bss_band
& BAND_A
)
280 usr_vht_cap_info
= adapter
->usr_dot_11ac_dev_cap_a
;
282 usr_vht_cap_info
= adapter
->usr_dot_11ac_dev_cap_bg
;
284 /* find the minimum bandwidth between AP/TDLS peers */
285 vht_cap
= &sta_ptr
->tdls_cap
.vhtcap
;
286 supp_chwd_set
= GET_VHTCAP_CHWDSET(usr_vht_cap_info
);
288 GET_VHTCAP_CHWDSET(le32_to_cpu(vht_cap
->vht_cap_info
));
289 supp_chwd_set
= min_t(u8
, supp_chwd_set
, peer_supp_chwd_set
);
291 /* We need check AP's bandwidth when TDLS_WIDER_BANDWIDTH is off */
293 if (ap_vht_cap
&& sta_ptr
->tdls_cap
.extcap
.ext_capab
[7] &
294 WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED
) {
296 GET_VHTCAP_CHWDSET(le32_to_cpu(ap_vht_cap
->vht_cap_info
));
297 supp_chwd_set
= min_t(u8
, supp_chwd_set
, ap_supp_chwd_set
);
300 switch (supp_chwd_set
) {
301 case IEEE80211_VHT_CHANWIDTH_80MHZ
:
302 vht_oper
->chan_width
= IEEE80211_VHT_CHANWIDTH_80MHZ
;
304 case IEEE80211_VHT_CHANWIDTH_160MHZ
:
305 vht_oper
->chan_width
= IEEE80211_VHT_CHANWIDTH_160MHZ
;
307 case IEEE80211_VHT_CHANWIDTH_80P80MHZ
:
308 vht_oper
->chan_width
= IEEE80211_VHT_CHANWIDTH_80P80MHZ
;
311 vht_oper
->chan_width
= IEEE80211_VHT_CHANWIDTH_USE_HT
;
315 mcs_map_user
= GET_DEVRXMCSMAP(adapter
->usr_dot_11ac_mcs_support
);
316 mcs_map_resp
= le16_to_cpu(vht_cap
->supp_mcs
.rx_mcs_map
);
319 for (nss
= 1; nss
<= 8; nss
++) {
320 mcs_user
= GET_VHTNSSMCS(mcs_map_user
, nss
);
321 mcs_resp
= GET_VHTNSSMCS(mcs_map_resp
, nss
);
323 if ((mcs_user
== IEEE80211_VHT_MCS_NOT_SUPPORTED
) ||
324 (mcs_resp
== IEEE80211_VHT_MCS_NOT_SUPPORTED
))
325 SET_VHTNSSMCS(mcs_map_result
, nss
,
326 IEEE80211_VHT_MCS_NOT_SUPPORTED
);
328 SET_VHTNSSMCS(mcs_map_result
, nss
,
329 min_t(u16
, mcs_user
, mcs_resp
));
332 vht_oper
->basic_mcs_set
= cpu_to_le16(mcs_map_result
);
334 switch (vht_oper
->chan_width
) {
335 case IEEE80211_VHT_CHANWIDTH_80MHZ
:
336 chan_bw
= IEEE80211_VHT_CHANWIDTH_80MHZ
;
338 case IEEE80211_VHT_CHANWIDTH_160MHZ
:
339 chan_bw
= IEEE80211_VHT_CHANWIDTH_160MHZ
;
341 case IEEE80211_VHT_CHANWIDTH_80P80MHZ
:
342 chan_bw
= IEEE80211_VHT_CHANWIDTH_80MHZ
;
345 chan_bw
= IEEE80211_VHT_CHANWIDTH_USE_HT
;
348 vht_oper
->center_freq_seg0_idx
=
349 mwifiex_get_center_freq_index(priv
, BAND_AAC
,
356 static void mwifiex_tdls_add_ext_capab(struct mwifiex_private
*priv
,
359 struct ieee_types_extcap
*extcap
;
361 extcap
= skb_put(skb
, sizeof(struct ieee_types_extcap
));
362 extcap
->ieee_hdr
.element_id
= WLAN_EID_EXT_CAPABILITY
;
363 extcap
->ieee_hdr
.len
= 8;
364 memset(extcap
->ext_capab
, 0, 8);
365 extcap
->ext_capab
[4] |= WLAN_EXT_CAPA5_TDLS_ENABLED
;
366 extcap
->ext_capab
[3] |= WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH
;
368 if (priv
->adapter
->is_hw_11ac_capable
)
369 extcap
->ext_capab
[7] |= WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED
;
372 static void mwifiex_tdls_add_qos_capab(struct sk_buff
*skb
)
374 u8
*pos
= skb_put(skb
, 3);
376 *pos
++ = WLAN_EID_QOS_CAPA
;
378 *pos
++ = MWIFIEX_TDLS_DEF_QOS_CAPAB
;
382 mwifiex_tdls_add_wmm_param_ie(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
384 struct ieee80211_wmm_param_ie
*wmm
;
385 u8 ac_vi
[] = {0x42, 0x43, 0x5e, 0x00};
386 u8 ac_vo
[] = {0x62, 0x32, 0x2f, 0x00};
387 u8 ac_be
[] = {0x03, 0xa4, 0x00, 0x00};
388 u8 ac_bk
[] = {0x27, 0xa4, 0x00, 0x00};
390 wmm
= skb_put_zero(skb
, sizeof(*wmm
));
392 wmm
->element_id
= WLAN_EID_VENDOR_SPECIFIC
;
393 wmm
->len
= sizeof(*wmm
) - 2;
394 wmm
->oui
[0] = 0x00; /* Microsoft OUI 00:50:F2 */
397 wmm
->oui_type
= 2; /* WME */
398 wmm
->oui_subtype
= 1; /* WME param */
399 wmm
->version
= 1; /* WME ver */
400 wmm
->qos_info
= 0; /* U-APSD not in use */
402 /* use default WMM AC parameters for TDLS link*/
403 memcpy(&wmm
->ac
[0], ac_be
, sizeof(ac_be
));
404 memcpy(&wmm
->ac
[1], ac_bk
, sizeof(ac_bk
));
405 memcpy(&wmm
->ac
[2], ac_vi
, sizeof(ac_vi
));
406 memcpy(&wmm
->ac
[3], ac_vo
, sizeof(ac_vo
));
410 mwifiex_add_wmm_info_ie(struct mwifiex_private
*priv
, struct sk_buff
*skb
,
416 MWIFIEX_TDLS_WMM_INFO_SIZE
+ sizeof(struct ieee_types_header
));
418 *buf
++ = WLAN_EID_VENDOR_SPECIFIC
;
419 *buf
++ = 7; /* len */
420 *buf
++ = 0x00; /* Microsoft OUI 00:50:F2 */
423 *buf
++ = 2; /* WME */
424 *buf
++ = 0; /* WME info */
425 *buf
++ = 1; /* WME ver */
426 *buf
++ = qosinfo
; /* U-APSD no in use */
429 static void mwifiex_tdls_add_bss_co_2040(struct sk_buff
*skb
)
431 struct ieee_types_bss_co_2040
*bssco
;
433 bssco
= skb_put(skb
, sizeof(struct ieee_types_bss_co_2040
));
434 bssco
->ieee_hdr
.element_id
= WLAN_EID_BSS_COEX_2040
;
435 bssco
->ieee_hdr
.len
= sizeof(struct ieee_types_bss_co_2040
) -
436 sizeof(struct ieee_types_header
);
437 bssco
->bss_2040co
= 0x01;
440 static void mwifiex_tdls_add_supported_chan(struct sk_buff
*skb
)
442 struct ieee_types_generic
*supp_chan
;
443 u8 chan_supp
[] = {1, 11};
445 supp_chan
= skb_put(skb
,
446 (sizeof(struct ieee_types_header
) + sizeof(chan_supp
)));
447 supp_chan
->ieee_hdr
.element_id
= WLAN_EID_SUPPORTED_CHANNELS
;
448 supp_chan
->ieee_hdr
.len
= sizeof(chan_supp
);
449 memcpy(supp_chan
->data
, chan_supp
, sizeof(chan_supp
));
452 static void mwifiex_tdls_add_oper_class(struct sk_buff
*skb
)
454 struct ieee_types_generic
*reg_class
;
456 1, 2, 3, 4, 12, 22, 23, 24, 25, 27, 28, 29, 30, 32, 33};
457 reg_class
= skb_put(skb
,
458 (sizeof(struct ieee_types_header
) + sizeof(rc_list
)));
459 reg_class
->ieee_hdr
.element_id
= WLAN_EID_SUPPORTED_REGULATORY_CLASSES
;
460 reg_class
->ieee_hdr
.len
= sizeof(rc_list
);
461 memcpy(reg_class
->data
, rc_list
, sizeof(rc_list
));
464 static int mwifiex_prep_tdls_encap_data(struct mwifiex_private
*priv
,
465 const u8
*peer
, u8 action_code
,
467 u16 status_code
, struct sk_buff
*skb
)
469 struct ieee80211_tdls_data
*tf
;
472 struct ieee80211_ht_cap
*ht_cap
;
475 capab
= priv
->curr_bss_params
.bss_descriptor
.cap_info_bitmap
;
477 tf
= skb_put(skb
, offsetof(struct ieee80211_tdls_data
, u
));
478 memcpy(tf
->da
, peer
, ETH_ALEN
);
479 memcpy(tf
->sa
, priv
->curr_addr
, ETH_ALEN
);
480 tf
->ether_type
= cpu_to_be16(ETH_P_TDLS
);
481 tf
->payload_type
= WLAN_TDLS_SNAP_RFTYPE
;
483 switch (action_code
) {
484 case WLAN_TDLS_SETUP_REQUEST
:
485 tf
->category
= WLAN_CATEGORY_TDLS
;
486 tf
->action_code
= WLAN_TDLS_SETUP_REQUEST
;
487 skb_put(skb
, sizeof(tf
->u
.setup_req
));
488 tf
->u
.setup_req
.dialog_token
= dialog_token
;
489 tf
->u
.setup_req
.capability
= cpu_to_le16(capab
);
490 ret
= mwifiex_tdls_append_rates_ie(priv
, skb
);
492 dev_kfree_skb_any(skb
);
496 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
497 *pos
++ = WLAN_EID_HT_CAPABILITY
;
498 *pos
++ = sizeof(struct ieee80211_ht_cap
);
499 ht_cap
= (void *)pos
;
500 radio
= mwifiex_band_to_radio_type(priv
->curr_bss_params
.band
);
501 ret
= mwifiex_fill_cap_info(priv
, radio
, ht_cap
);
503 dev_kfree_skb_any(skb
);
507 if (priv
->adapter
->is_hw_11ac_capable
) {
508 ret
= mwifiex_tdls_add_vht_capab(priv
, skb
);
510 dev_kfree_skb_any(skb
);
513 mwifiex_tdls_add_aid(priv
, skb
);
516 mwifiex_tdls_add_ext_capab(priv
, skb
);
517 mwifiex_tdls_add_bss_co_2040(skb
);
518 mwifiex_tdls_add_supported_chan(skb
);
519 mwifiex_tdls_add_oper_class(skb
);
520 mwifiex_add_wmm_info_ie(priv
, skb
, 0);
523 case WLAN_TDLS_SETUP_RESPONSE
:
524 tf
->category
= WLAN_CATEGORY_TDLS
;
525 tf
->action_code
= WLAN_TDLS_SETUP_RESPONSE
;
526 skb_put(skb
, sizeof(tf
->u
.setup_resp
));
527 tf
->u
.setup_resp
.status_code
= cpu_to_le16(status_code
);
528 tf
->u
.setup_resp
.dialog_token
= dialog_token
;
529 tf
->u
.setup_resp
.capability
= cpu_to_le16(capab
);
530 ret
= mwifiex_tdls_append_rates_ie(priv
, skb
);
532 dev_kfree_skb_any(skb
);
536 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
537 *pos
++ = WLAN_EID_HT_CAPABILITY
;
538 *pos
++ = sizeof(struct ieee80211_ht_cap
);
539 ht_cap
= (void *)pos
;
540 radio
= mwifiex_band_to_radio_type(priv
->curr_bss_params
.band
);
541 ret
= mwifiex_fill_cap_info(priv
, radio
, ht_cap
);
543 dev_kfree_skb_any(skb
);
547 if (priv
->adapter
->is_hw_11ac_capable
) {
548 ret
= mwifiex_tdls_add_vht_capab(priv
, skb
);
550 dev_kfree_skb_any(skb
);
553 mwifiex_tdls_add_aid(priv
, skb
);
556 mwifiex_tdls_add_ext_capab(priv
, skb
);
557 mwifiex_tdls_add_bss_co_2040(skb
);
558 mwifiex_tdls_add_supported_chan(skb
);
559 mwifiex_tdls_add_oper_class(skb
);
560 mwifiex_add_wmm_info_ie(priv
, skb
, 0);
563 case WLAN_TDLS_SETUP_CONFIRM
:
564 tf
->category
= WLAN_CATEGORY_TDLS
;
565 tf
->action_code
= WLAN_TDLS_SETUP_CONFIRM
;
566 skb_put(skb
, sizeof(tf
->u
.setup_cfm
));
567 tf
->u
.setup_cfm
.status_code
= cpu_to_le16(status_code
);
568 tf
->u
.setup_cfm
.dialog_token
= dialog_token
;
570 mwifiex_tdls_add_wmm_param_ie(priv
, skb
);
571 if (priv
->adapter
->is_hw_11ac_capable
) {
572 ret
= mwifiex_tdls_add_vht_oper(priv
, peer
, skb
);
574 dev_kfree_skb_any(skb
);
577 ret
= mwifiex_tdls_add_ht_oper(priv
, peer
, 1, skb
);
579 dev_kfree_skb_any(skb
);
583 ret
= mwifiex_tdls_add_ht_oper(priv
, peer
, 0, skb
);
585 dev_kfree_skb_any(skb
);
591 case WLAN_TDLS_TEARDOWN
:
592 tf
->category
= WLAN_CATEGORY_TDLS
;
593 tf
->action_code
= WLAN_TDLS_TEARDOWN
;
594 skb_put(skb
, sizeof(tf
->u
.teardown
));
595 tf
->u
.teardown
.reason_code
= cpu_to_le16(status_code
);
598 case WLAN_TDLS_DISCOVERY_REQUEST
:
599 tf
->category
= WLAN_CATEGORY_TDLS
;
600 tf
->action_code
= WLAN_TDLS_DISCOVERY_REQUEST
;
601 skb_put(skb
, sizeof(tf
->u
.discover_req
));
602 tf
->u
.discover_req
.dialog_token
= dialog_token
;
605 mwifiex_dbg(priv
->adapter
, ERROR
, "Unknown TDLS frame type.\n");
613 mwifiex_tdls_add_link_ie(struct sk_buff
*skb
, const u8
*src_addr
,
614 const u8
*peer
, const u8
*bssid
)
616 struct ieee80211_tdls_lnkie
*lnkid
;
618 lnkid
= skb_put(skb
, sizeof(struct ieee80211_tdls_lnkie
));
619 lnkid
->ie_type
= WLAN_EID_LINK_ID
;
620 lnkid
->ie_len
= sizeof(struct ieee80211_tdls_lnkie
) -
621 sizeof(struct ieee_types_header
);
623 memcpy(lnkid
->bssid
, bssid
, ETH_ALEN
);
624 memcpy(lnkid
->init_sta
, src_addr
, ETH_ALEN
);
625 memcpy(lnkid
->resp_sta
, peer
, ETH_ALEN
);
628 int mwifiex_send_tdls_data_frame(struct mwifiex_private
*priv
, const u8
*peer
,
629 u8 action_code
, u8 dialog_token
,
630 u16 status_code
, const u8
*extra_ies
,
631 size_t extra_ies_len
)
634 struct mwifiex_txinfo
*tx_info
;
638 skb_len
= MWIFIEX_MIN_DATA_HEADER_LEN
+
639 max(sizeof(struct ieee80211_mgmt
),
640 sizeof(struct ieee80211_tdls_data
)) +
641 MWIFIEX_MGMT_FRAME_HEADER_SIZE
+
642 MWIFIEX_SUPPORTED_RATES
+
644 sizeof(struct ieee_types_extcap
) +
645 sizeof(struct ieee80211_ht_cap
) +
646 sizeof(struct ieee_types_bss_co_2040
) +
647 sizeof(struct ieee80211_ht_operation
) +
648 sizeof(struct ieee80211_tdls_lnkie
) +
649 (2 * (sizeof(struct ieee_types_header
))) +
650 MWIFIEX_SUPPORTED_CHANNELS
+
651 MWIFIEX_OPERATING_CLASSES
+
652 sizeof(struct ieee80211_wmm_param_ie
) +
655 if (priv
->adapter
->is_hw_11ac_capable
)
656 skb_len
+= sizeof(struct ieee_types_vht_cap
) +
657 sizeof(struct ieee_types_vht_oper
) +
658 sizeof(struct ieee_types_aid
);
660 skb
= dev_alloc_skb(skb_len
);
662 mwifiex_dbg(priv
->adapter
, ERROR
,
663 "allocate skb failed for management frame\n");
666 skb_reserve(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
668 switch (action_code
) {
669 case WLAN_TDLS_SETUP_REQUEST
:
670 case WLAN_TDLS_SETUP_CONFIRM
:
671 case WLAN_TDLS_TEARDOWN
:
672 case WLAN_TDLS_DISCOVERY_REQUEST
:
673 ret
= mwifiex_prep_tdls_encap_data(priv
, peer
, action_code
,
674 dialog_token
, status_code
,
677 dev_kfree_skb_any(skb
);
681 skb_put_data(skb
, extra_ies
, extra_ies_len
);
682 mwifiex_tdls_add_link_ie(skb
, priv
->curr_addr
, peer
,
685 case WLAN_TDLS_SETUP_RESPONSE
:
686 ret
= mwifiex_prep_tdls_encap_data(priv
, peer
, action_code
,
687 dialog_token
, status_code
,
690 dev_kfree_skb_any(skb
);
694 skb_put_data(skb
, extra_ies
, extra_ies_len
);
695 mwifiex_tdls_add_link_ie(skb
, peer
, priv
->curr_addr
,
700 switch (action_code
) {
701 case WLAN_TDLS_SETUP_REQUEST
:
702 case WLAN_TDLS_SETUP_RESPONSE
:
703 skb
->priority
= MWIFIEX_PRIO_BK
;
706 skb
->priority
= MWIFIEX_PRIO_VI
;
710 tx_info
= MWIFIEX_SKB_TXCB(skb
);
711 memset(tx_info
, 0, sizeof(*tx_info
));
712 tx_info
->bss_num
= priv
->bss_num
;
713 tx_info
->bss_type
= priv
->bss_type
;
715 __net_timestamp(skb
);
716 mwifiex_queue_tx_pkt(priv
, skb
);
718 /* Delay 10ms to make sure tdls setup confirm/teardown frame
719 * is received by peer
721 if (action_code
== WLAN_TDLS_SETUP_CONFIRM
||
722 action_code
== WLAN_TDLS_TEARDOWN
)
723 msleep_interruptible(10);
729 mwifiex_construct_tdls_action_frame(struct mwifiex_private
*priv
,
731 u8 action_code
, u8 dialog_token
,
732 u16 status_code
, struct sk_buff
*skb
)
734 struct ieee80211_mgmt
*mgmt
;
737 struct ieee80211_ht_cap
*ht_cap
;
740 capab
= priv
->curr_bss_params
.bss_descriptor
.cap_info_bitmap
;
742 mgmt
= skb_put(skb
, offsetof(struct ieee80211_mgmt
, u
));
745 memcpy(mgmt
->da
, peer
, ETH_ALEN
);
746 memcpy(mgmt
->sa
, priv
->curr_addr
, ETH_ALEN
);
747 memcpy(mgmt
->bssid
, priv
->cfg_bssid
, ETH_ALEN
);
748 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
749 IEEE80211_STYPE_ACTION
);
752 pos
= skb_put(skb
, ETH_ALEN
);
754 switch (action_code
) {
755 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
756 skb_put(skb
, sizeof(mgmt
->u
.action
.u
.tdls_discover_resp
) + 1);
757 mgmt
->u
.action
.category
= WLAN_CATEGORY_PUBLIC
;
758 mgmt
->u
.action
.u
.tdls_discover_resp
.action_code
=
759 WLAN_PUB_ACTION_TDLS_DISCOVER_RES
;
760 mgmt
->u
.action
.u
.tdls_discover_resp
.dialog_token
=
762 mgmt
->u
.action
.u
.tdls_discover_resp
.capability
=
764 /* move back for addr4 */
765 memmove(pos
+ ETH_ALEN
, &mgmt
->u
.action
.category
,
766 sizeof(mgmt
->u
.action
.u
.tdls_discover_resp
));
768 eth_broadcast_addr(pos
);
770 ret
= mwifiex_tdls_append_rates_ie(priv
, skb
);
772 dev_kfree_skb_any(skb
);
776 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
777 *pos
++ = WLAN_EID_HT_CAPABILITY
;
778 *pos
++ = sizeof(struct ieee80211_ht_cap
);
779 ht_cap
= (void *)pos
;
780 radio
= mwifiex_band_to_radio_type(priv
->curr_bss_params
.band
);
781 ret
= mwifiex_fill_cap_info(priv
, radio
, ht_cap
);
783 dev_kfree_skb_any(skb
);
787 if (priv
->adapter
->is_hw_11ac_capable
) {
788 ret
= mwifiex_tdls_add_vht_capab(priv
, skb
);
790 dev_kfree_skb_any(skb
);
793 mwifiex_tdls_add_aid(priv
, skb
);
796 mwifiex_tdls_add_ext_capab(priv
, skb
);
797 mwifiex_tdls_add_bss_co_2040(skb
);
798 mwifiex_tdls_add_supported_chan(skb
);
799 mwifiex_tdls_add_qos_capab(skb
);
800 mwifiex_tdls_add_oper_class(skb
);
803 mwifiex_dbg(priv
->adapter
, ERROR
, "Unknown TDLS action frame type\n");
810 int mwifiex_send_tdls_action_frame(struct mwifiex_private
*priv
, const u8
*peer
,
811 u8 action_code
, u8 dialog_token
,
812 u16 status_code
, const u8
*extra_ies
,
813 size_t extra_ies_len
)
816 struct mwifiex_txinfo
*tx_info
;
818 u32 pkt_type
, tx_control
;
819 u16 pkt_len
, skb_len
;
821 skb_len
= MWIFIEX_MIN_DATA_HEADER_LEN
+
822 max(sizeof(struct ieee80211_mgmt
),
823 sizeof(struct ieee80211_tdls_data
)) +
824 MWIFIEX_MGMT_FRAME_HEADER_SIZE
+
825 MWIFIEX_SUPPORTED_RATES
+
826 sizeof(struct ieee_types_extcap
) +
827 sizeof(struct ieee80211_ht_cap
) +
828 sizeof(struct ieee_types_bss_co_2040
) +
829 sizeof(struct ieee80211_ht_operation
) +
830 sizeof(struct ieee80211_tdls_lnkie
) +
833 ETH_ALEN
; /* Address4 */
835 if (priv
->adapter
->is_hw_11ac_capable
)
836 skb_len
+= sizeof(struct ieee_types_vht_cap
) +
837 sizeof(struct ieee_types_vht_oper
) +
838 sizeof(struct ieee_types_aid
);
840 skb
= dev_alloc_skb(skb_len
);
842 mwifiex_dbg(priv
->adapter
, ERROR
,
843 "allocate skb failed for management frame\n");
847 skb_reserve(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
849 pkt_type
= PKT_TYPE_MGMT
;
851 pos
= skb_put_zero(skb
,
852 MWIFIEX_MGMT_FRAME_HEADER_SIZE
+ sizeof(pkt_len
));
853 memcpy(pos
, &pkt_type
, sizeof(pkt_type
));
854 memcpy(pos
+ sizeof(pkt_type
), &tx_control
, sizeof(tx_control
));
856 if (mwifiex_construct_tdls_action_frame(priv
, peer
, action_code
,
857 dialog_token
, status_code
,
859 dev_kfree_skb_any(skb
);
864 skb_put_data(skb
, extra_ies
, extra_ies_len
);
866 /* the TDLS link IE is always added last we are the responder */
868 mwifiex_tdls_add_link_ie(skb
, peer
, priv
->curr_addr
,
871 skb
->priority
= MWIFIEX_PRIO_VI
;
873 tx_info
= MWIFIEX_SKB_TXCB(skb
);
874 memset(tx_info
, 0, sizeof(*tx_info
));
875 tx_info
->bss_num
= priv
->bss_num
;
876 tx_info
->bss_type
= priv
->bss_type
;
877 tx_info
->flags
|= MWIFIEX_BUF_FLAG_TDLS_PKT
;
879 pkt_len
= skb
->len
- MWIFIEX_MGMT_FRAME_HEADER_SIZE
- sizeof(pkt_len
);
880 memcpy(skb
->data
+ MWIFIEX_MGMT_FRAME_HEADER_SIZE
, &pkt_len
,
882 __net_timestamp(skb
);
883 mwifiex_queue_tx_pkt(priv
, skb
);
888 /* This function process tdls action frame from peer.
889 * Peer capabilities are stored into station node structure.
891 void mwifiex_process_tdls_action_frame(struct mwifiex_private
*priv
,
894 struct mwifiex_sta_node
*sta_ptr
;
895 u8
*peer
, *pos
, *end
;
900 if (len
< (sizeof(struct ethhdr
) + 3))
902 if (*(buf
+ sizeof(struct ethhdr
)) != WLAN_TDLS_SNAP_RFTYPE
)
904 if (*(buf
+ sizeof(struct ethhdr
) + 1) != WLAN_CATEGORY_TDLS
)
907 peer
= buf
+ ETH_ALEN
;
908 action
= *(buf
+ sizeof(struct ethhdr
) + 2);
909 mwifiex_dbg(priv
->adapter
, DATA
,
910 "rx:tdls action: peer=%pM, action=%d\n", peer
, action
);
913 case WLAN_TDLS_SETUP_REQUEST
:
914 if (len
< (sizeof(struct ethhdr
) + TDLS_REQ_FIX_LEN
))
917 pos
= buf
+ sizeof(struct ethhdr
) + 4;
918 /* payload 1+ category 1 + action 1 + dialog 1 */
919 cap
= get_unaligned_le16(pos
);
920 ies_len
= len
- sizeof(struct ethhdr
) - TDLS_REQ_FIX_LEN
;
924 case WLAN_TDLS_SETUP_RESPONSE
:
925 if (len
< (sizeof(struct ethhdr
) + TDLS_RESP_FIX_LEN
))
927 /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
928 pos
= buf
+ sizeof(struct ethhdr
) + 6;
929 cap
= get_unaligned_le16(pos
);
930 ies_len
= len
- sizeof(struct ethhdr
) - TDLS_RESP_FIX_LEN
;
934 case WLAN_TDLS_SETUP_CONFIRM
:
935 if (len
< (sizeof(struct ethhdr
) + TDLS_CONFIRM_FIX_LEN
))
937 pos
= buf
+ sizeof(struct ethhdr
) + TDLS_CONFIRM_FIX_LEN
;
938 ies_len
= len
- sizeof(struct ethhdr
) - TDLS_CONFIRM_FIX_LEN
;
941 mwifiex_dbg(priv
->adapter
, ERROR
, "Unknown TDLS frame type.\n");
945 sta_ptr
= mwifiex_add_sta_entry(priv
, peer
);
949 sta_ptr
->tdls_cap
.capab
= cpu_to_le16(cap
);
951 for (end
= pos
+ ies_len
; pos
+ 1 < end
; pos
+= 2 + pos
[1]) {
954 if (pos
+ 2 + ie_len
> end
)
958 case WLAN_EID_SUPP_RATES
:
959 if (ie_len
> sizeof(sta_ptr
->tdls_cap
.rates
))
961 sta_ptr
->tdls_cap
.rates_len
= ie_len
;
962 for (i
= 0; i
< ie_len
; i
++)
963 sta_ptr
->tdls_cap
.rates
[i
] = pos
[i
+ 2];
966 case WLAN_EID_EXT_SUPP_RATES
:
967 if (ie_len
> sizeof(sta_ptr
->tdls_cap
.rates
))
969 basic
= sta_ptr
->tdls_cap
.rates_len
;
970 if (ie_len
> sizeof(sta_ptr
->tdls_cap
.rates
) - basic
)
972 for (i
= 0; i
< ie_len
; i
++)
973 sta_ptr
->tdls_cap
.rates
[basic
+ i
] = pos
[i
+ 2];
974 sta_ptr
->tdls_cap
.rates_len
+= ie_len
;
976 case WLAN_EID_HT_CAPABILITY
:
977 if (ie_len
!= sizeof(struct ieee80211_ht_cap
))
979 /* copy the ie's value into ht_capb*/
980 memcpy((u8
*)&sta_ptr
->tdls_cap
.ht_capb
, pos
+ 2,
981 sizeof(struct ieee80211_ht_cap
));
982 sta_ptr
->is_11n_enabled
= 1;
984 case WLAN_EID_HT_OPERATION
:
985 if (ie_len
!= sizeof(struct ieee80211_ht_operation
))
987 /* copy the ie's value into ht_oper*/
988 memcpy(&sta_ptr
->tdls_cap
.ht_oper
, pos
+ 2,
989 sizeof(struct ieee80211_ht_operation
));
991 case WLAN_EID_BSS_COEX_2040
:
992 if (ie_len
!= sizeof(pos
[2]))
994 sta_ptr
->tdls_cap
.coex_2040
= pos
[2];
996 case WLAN_EID_EXT_CAPABILITY
:
997 if (ie_len
< sizeof(struct ieee_types_header
))
1001 memcpy((u8
*)&sta_ptr
->tdls_cap
.extcap
, pos
,
1002 sizeof(struct ieee_types_header
) +
1003 min_t(u8
, ie_len
, 8));
1006 if (ie_len
< sizeof(struct ieee_types_header
))
1008 if (ie_len
> IEEE_MAX_IE_SIZE
-
1009 sizeof(struct ieee_types_header
))
1011 memcpy((u8
*)&sta_ptr
->tdls_cap
.rsn_ie
, pos
,
1012 sizeof(struct ieee_types_header
) +
1013 min_t(u8
, ie_len
, IEEE_MAX_IE_SIZE
-
1014 sizeof(struct ieee_types_header
)));
1016 case WLAN_EID_QOS_CAPA
:
1017 if (ie_len
!= sizeof(pos
[2]))
1019 sta_ptr
->tdls_cap
.qos_info
= pos
[2];
1021 case WLAN_EID_VHT_OPERATION
:
1022 if (priv
->adapter
->is_hw_11ac_capable
) {
1024 sizeof(struct ieee80211_vht_operation
))
1026 /* copy the ie's value into vhtoper*/
1027 memcpy(&sta_ptr
->tdls_cap
.vhtoper
, pos
+ 2,
1028 sizeof(struct ieee80211_vht_operation
));
1031 case WLAN_EID_VHT_CAPABILITY
:
1032 if (priv
->adapter
->is_hw_11ac_capable
) {
1033 if (ie_len
!= sizeof(struct ieee80211_vht_cap
))
1035 /* copy the ie's value into vhtcap*/
1036 memcpy((u8
*)&sta_ptr
->tdls_cap
.vhtcap
, pos
+ 2,
1037 sizeof(struct ieee80211_vht_cap
));
1038 sta_ptr
->is_11ac_enabled
= 1;
1042 if (priv
->adapter
->is_hw_11ac_capable
) {
1043 if (ie_len
!= sizeof(u16
))
1045 sta_ptr
->tdls_cap
.aid
=
1046 get_unaligned_le16((pos
+ 2));
1058 mwifiex_tdls_process_config_link(struct mwifiex_private
*priv
, const u8
*peer
)
1060 struct mwifiex_sta_node
*sta_ptr
;
1061 struct mwifiex_ds_tdls_oper tdls_oper
;
1063 memset(&tdls_oper
, 0, sizeof(struct mwifiex_ds_tdls_oper
));
1064 sta_ptr
= mwifiex_get_sta_entry(priv
, peer
);
1066 if (!sta_ptr
|| sta_ptr
->tdls_status
== TDLS_SETUP_FAILURE
) {
1067 mwifiex_dbg(priv
->adapter
, ERROR
,
1068 "link absent for peer %pM; cannot config\n", peer
);
1072 memcpy(&tdls_oper
.peer_mac
, peer
, ETH_ALEN
);
1073 tdls_oper
.tdls_action
= MWIFIEX_TDLS_CONFIG_LINK
;
1074 return mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_OPER
,
1075 HostCmd_ACT_GEN_SET
, 0, &tdls_oper
, true);
1079 mwifiex_tdls_process_create_link(struct mwifiex_private
*priv
, const u8
*peer
)
1081 struct mwifiex_sta_node
*sta_ptr
;
1082 struct mwifiex_ds_tdls_oper tdls_oper
;
1084 memset(&tdls_oper
, 0, sizeof(struct mwifiex_ds_tdls_oper
));
1085 sta_ptr
= mwifiex_get_sta_entry(priv
, peer
);
1087 if (sta_ptr
&& sta_ptr
->tdls_status
== TDLS_SETUP_INPROGRESS
) {
1088 mwifiex_dbg(priv
->adapter
, WARN
,
1089 "Setup already in progress for peer %pM\n", peer
);
1093 sta_ptr
= mwifiex_add_sta_entry(priv
, peer
);
1097 sta_ptr
->tdls_status
= TDLS_SETUP_INPROGRESS
;
1098 mwifiex_hold_tdls_packets(priv
, peer
);
1099 memcpy(&tdls_oper
.peer_mac
, peer
, ETH_ALEN
);
1100 tdls_oper
.tdls_action
= MWIFIEX_TDLS_CREATE_LINK
;
1101 return mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_OPER
,
1102 HostCmd_ACT_GEN_SET
, 0, &tdls_oper
, true);
1106 mwifiex_tdls_process_disable_link(struct mwifiex_private
*priv
, const u8
*peer
)
1108 struct mwifiex_sta_node
*sta_ptr
;
1109 struct mwifiex_ds_tdls_oper tdls_oper
;
1111 memset(&tdls_oper
, 0, sizeof(struct mwifiex_ds_tdls_oper
));
1112 sta_ptr
= mwifiex_get_sta_entry(priv
, peer
);
1115 if (sta_ptr
->is_11n_enabled
) {
1116 mwifiex_11n_cleanup_reorder_tbl(priv
);
1117 spin_lock_bh(&priv
->wmm
.ra_list_spinlock
);
1118 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv
);
1119 spin_unlock_bh(&priv
->wmm
.ra_list_spinlock
);
1121 mwifiex_del_sta_entry(priv
, peer
);
1124 mwifiex_restore_tdls_packets(priv
, peer
, TDLS_LINK_TEARDOWN
);
1125 mwifiex_auto_tdls_update_peer_status(priv
, peer
, TDLS_NOT_SETUP
);
1126 memcpy(&tdls_oper
.peer_mac
, peer
, ETH_ALEN
);
1127 tdls_oper
.tdls_action
= MWIFIEX_TDLS_DISABLE_LINK
;
1128 return mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_OPER
,
1129 HostCmd_ACT_GEN_SET
, 0, &tdls_oper
, true);
1133 mwifiex_tdls_process_enable_link(struct mwifiex_private
*priv
, const u8
*peer
)
1135 struct mwifiex_sta_node
*sta_ptr
;
1136 struct ieee80211_mcs_info mcs
;
1139 sta_ptr
= mwifiex_get_sta_entry(priv
, peer
);
1141 if (sta_ptr
&& (sta_ptr
->tdls_status
!= TDLS_SETUP_FAILURE
)) {
1142 mwifiex_dbg(priv
->adapter
, MSG
,
1143 "tdls: enable link %pM success\n", peer
);
1145 sta_ptr
->tdls_status
= TDLS_SETUP_COMPLETE
;
1147 mcs
= sta_ptr
->tdls_cap
.ht_capb
.mcs
;
1148 if (mcs
.rx_mask
[0] != 0xff)
1149 sta_ptr
->is_11n_enabled
= true;
1150 if (sta_ptr
->is_11n_enabled
) {
1151 if (le16_to_cpu(sta_ptr
->tdls_cap
.ht_capb
.cap_info
) &
1152 IEEE80211_HT_CAP_MAX_AMSDU
)
1153 sta_ptr
->max_amsdu
=
1154 MWIFIEX_TX_DATA_BUF_SIZE_8K
;
1156 sta_ptr
->max_amsdu
=
1157 MWIFIEX_TX_DATA_BUF_SIZE_4K
;
1159 for (i
= 0; i
< MAX_NUM_TID
; i
++)
1160 sta_ptr
->ampdu_sta
[i
] =
1161 priv
->aggr_prio_tbl
[i
].ampdu_user
;
1163 for (i
= 0; i
< MAX_NUM_TID
; i
++)
1164 sta_ptr
->ampdu_sta
[i
] = BA_STREAM_NOT_ALLOWED
;
1166 if (sta_ptr
->tdls_cap
.extcap
.ext_capab
[3] &
1167 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH
) {
1168 mwifiex_config_tdls_enable(priv
);
1169 mwifiex_config_tdls_cs_params(priv
);
1172 memset(sta_ptr
->rx_seq
, 0xff, sizeof(sta_ptr
->rx_seq
));
1173 mwifiex_restore_tdls_packets(priv
, peer
, TDLS_SETUP_COMPLETE
);
1174 mwifiex_auto_tdls_update_peer_status(priv
, peer
,
1175 TDLS_SETUP_COMPLETE
);
1177 mwifiex_dbg(priv
->adapter
, ERROR
,
1178 "tdls: enable link %pM failed\n", peer
);
1180 mwifiex_11n_cleanup_reorder_tbl(priv
);
1181 spin_lock_bh(&priv
->wmm
.ra_list_spinlock
);
1182 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv
);
1183 spin_unlock_bh(&priv
->wmm
.ra_list_spinlock
);
1184 mwifiex_del_sta_entry(priv
, peer
);
1186 mwifiex_restore_tdls_packets(priv
, peer
, TDLS_LINK_TEARDOWN
);
1187 mwifiex_auto_tdls_update_peer_status(priv
, peer
,
1196 int mwifiex_tdls_oper(struct mwifiex_private
*priv
, const u8
*peer
, u8 action
)
1199 case MWIFIEX_TDLS_ENABLE_LINK
:
1200 return mwifiex_tdls_process_enable_link(priv
, peer
);
1201 case MWIFIEX_TDLS_DISABLE_LINK
:
1202 return mwifiex_tdls_process_disable_link(priv
, peer
);
1203 case MWIFIEX_TDLS_CREATE_LINK
:
1204 return mwifiex_tdls_process_create_link(priv
, peer
);
1205 case MWIFIEX_TDLS_CONFIG_LINK
:
1206 return mwifiex_tdls_process_config_link(priv
, peer
);
1211 int mwifiex_get_tdls_link_status(struct mwifiex_private
*priv
, const u8
*mac
)
1213 struct mwifiex_sta_node
*sta_ptr
;
1215 sta_ptr
= mwifiex_get_sta_entry(priv
, mac
);
1217 return sta_ptr
->tdls_status
;
1219 return TDLS_NOT_SETUP
;
1222 int mwifiex_get_tdls_list(struct mwifiex_private
*priv
,
1223 struct tdls_peer_info
*buf
)
1225 struct mwifiex_sta_node
*sta_ptr
;
1226 struct tdls_peer_info
*peer
= buf
;
1229 if (!ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
))
1232 /* make sure we are in station mode and connected */
1233 if (!(priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&& priv
->media_connected
))
1236 spin_lock_bh(&priv
->sta_list_spinlock
);
1237 list_for_each_entry(sta_ptr
, &priv
->sta_list
, list
) {
1238 if (mwifiex_is_tdls_link_setup(sta_ptr
->tdls_status
)) {
1239 ether_addr_copy(peer
->peer_addr
, sta_ptr
->mac_addr
);
1242 if (count
>= MWIFIEX_MAX_TDLS_PEER_SUPPORTED
)
1246 spin_unlock_bh(&priv
->sta_list_spinlock
);
1251 void mwifiex_disable_all_tdls_links(struct mwifiex_private
*priv
)
1253 struct mwifiex_sta_node
*sta_ptr
;
1254 struct mwifiex_ds_tdls_oper tdls_oper
;
1256 if (list_empty(&priv
->sta_list
))
1259 list_for_each_entry(sta_ptr
, &priv
->sta_list
, list
) {
1260 memset(&tdls_oper
, 0, sizeof(struct mwifiex_ds_tdls_oper
));
1262 if (sta_ptr
->is_11n_enabled
) {
1263 mwifiex_11n_cleanup_reorder_tbl(priv
);
1264 spin_lock_bh(&priv
->wmm
.ra_list_spinlock
);
1265 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv
);
1266 spin_unlock_bh(&priv
->wmm
.ra_list_spinlock
);
1269 mwifiex_restore_tdls_packets(priv
, sta_ptr
->mac_addr
,
1270 TDLS_LINK_TEARDOWN
);
1271 memcpy(&tdls_oper
.peer_mac
, sta_ptr
->mac_addr
, ETH_ALEN
);
1272 tdls_oper
.tdls_action
= MWIFIEX_TDLS_DISABLE_LINK
;
1273 if (mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_OPER
,
1274 HostCmd_ACT_GEN_SET
, 0, &tdls_oper
, false))
1275 mwifiex_dbg(priv
->adapter
, ERROR
,
1276 "Disable link failed for TDLS peer %pM",
1280 mwifiex_del_all_sta_list(priv
);
1283 int mwifiex_tdls_check_tx(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
1285 struct mwifiex_auto_tdls_peer
*peer
;
1288 ether_addr_copy(mac
, skb
->data
);
1290 spin_lock_bh(&priv
->auto_tdls_lock
);
1291 list_for_each_entry(peer
, &priv
->auto_tdls_list
, list
) {
1292 if (!memcmp(mac
, peer
->mac_addr
, ETH_ALEN
)) {
1293 if (peer
->rssi
<= MWIFIEX_TDLS_RSSI_HIGH
&&
1294 peer
->tdls_status
== TDLS_NOT_SETUP
&&
1295 (peer
->failure_count
<
1296 MWIFIEX_TDLS_MAX_FAIL_COUNT
)) {
1297 peer
->tdls_status
= TDLS_SETUP_INPROGRESS
;
1298 mwifiex_dbg(priv
->adapter
, INFO
,
1299 "setup TDLS link, peer=%pM rssi=%d\n",
1300 peer
->mac_addr
, peer
->rssi
);
1302 cfg80211_tdls_oper_request(priv
->netdev
,
1306 peer
->do_setup
= false;
1307 priv
->check_tdls_tx
= false;
1308 } else if (peer
->failure_count
<
1309 MWIFIEX_TDLS_MAX_FAIL_COUNT
&&
1310 peer
->do_discover
) {
1311 mwifiex_send_tdls_data_frame(priv
,
1313 WLAN_TDLS_DISCOVERY_REQUEST
,
1315 peer
->do_discover
= false;
1319 spin_unlock_bh(&priv
->auto_tdls_lock
);
1324 void mwifiex_flush_auto_tdls_list(struct mwifiex_private
*priv
)
1326 struct mwifiex_auto_tdls_peer
*peer
, *tmp_node
;
1328 spin_lock_bh(&priv
->auto_tdls_lock
);
1329 list_for_each_entry_safe(peer
, tmp_node
, &priv
->auto_tdls_list
, list
) {
1330 list_del(&peer
->list
);
1334 INIT_LIST_HEAD(&priv
->auto_tdls_list
);
1335 spin_unlock_bh(&priv
->auto_tdls_lock
);
1336 priv
->check_tdls_tx
= false;
1339 void mwifiex_add_auto_tdls_peer(struct mwifiex_private
*priv
, const u8
*mac
)
1341 struct mwifiex_auto_tdls_peer
*tdls_peer
;
1343 if (!priv
->adapter
->auto_tdls
)
1346 spin_lock_bh(&priv
->auto_tdls_lock
);
1347 list_for_each_entry(tdls_peer
, &priv
->auto_tdls_list
, list
) {
1348 if (!memcmp(tdls_peer
->mac_addr
, mac
, ETH_ALEN
)) {
1349 tdls_peer
->tdls_status
= TDLS_SETUP_INPROGRESS
;
1350 tdls_peer
->rssi_jiffies
= jiffies
;
1351 spin_unlock_bh(&priv
->auto_tdls_lock
);
1356 /* create new TDLS peer */
1357 tdls_peer
= kzalloc(sizeof(*tdls_peer
), GFP_ATOMIC
);
1359 ether_addr_copy(tdls_peer
->mac_addr
, mac
);
1360 tdls_peer
->tdls_status
= TDLS_SETUP_INPROGRESS
;
1361 tdls_peer
->rssi_jiffies
= jiffies
;
1362 INIT_LIST_HEAD(&tdls_peer
->list
);
1363 list_add_tail(&tdls_peer
->list
, &priv
->auto_tdls_list
);
1364 mwifiex_dbg(priv
->adapter
, INFO
,
1365 "Add auto TDLS peer= %pM to list\n", mac
);
1368 spin_unlock_bh(&priv
->auto_tdls_lock
);
1371 void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private
*priv
,
1372 const u8
*mac
, u8 link_status
)
1374 struct mwifiex_auto_tdls_peer
*peer
;
1376 if (!priv
->adapter
->auto_tdls
)
1379 spin_lock_bh(&priv
->auto_tdls_lock
);
1380 list_for_each_entry(peer
, &priv
->auto_tdls_list
, list
) {
1381 if (!memcmp(peer
->mac_addr
, mac
, ETH_ALEN
)) {
1382 if ((link_status
== TDLS_NOT_SETUP
) &&
1383 (peer
->tdls_status
== TDLS_SETUP_INPROGRESS
))
1384 peer
->failure_count
++;
1385 else if (mwifiex_is_tdls_link_setup(link_status
))
1386 peer
->failure_count
= 0;
1388 peer
->tdls_status
= link_status
;
1392 spin_unlock_bh(&priv
->auto_tdls_lock
);
1395 void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private
*priv
,
1396 u8
*mac
, s8 snr
, s8 nflr
)
1398 struct mwifiex_auto_tdls_peer
*peer
;
1400 if (!priv
->adapter
->auto_tdls
)
1403 spin_lock_bh(&priv
->auto_tdls_lock
);
1404 list_for_each_entry(peer
, &priv
->auto_tdls_list
, list
) {
1405 if (!memcmp(peer
->mac_addr
, mac
, ETH_ALEN
)) {
1406 peer
->rssi
= nflr
- snr
;
1407 peer
->rssi_jiffies
= jiffies
;
1411 spin_unlock_bh(&priv
->auto_tdls_lock
);
1414 void mwifiex_check_auto_tdls(struct timer_list
*t
)
1416 struct mwifiex_private
*priv
= from_timer(priv
, t
, auto_tdls_timer
);
1417 struct mwifiex_auto_tdls_peer
*tdls_peer
;
1418 u16 reason
= WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
;
1420 if (WARN_ON_ONCE(!priv
|| !priv
->adapter
)) {
1421 pr_err("mwifiex: %s: adapter or private structure is NULL\n",
1426 if (unlikely(!priv
->adapter
->auto_tdls
))
1429 if (!priv
->auto_tdls_timer_active
) {
1430 mwifiex_dbg(priv
->adapter
, INFO
,
1431 "auto TDLS timer inactive; return");
1435 priv
->check_tdls_tx
= false;
1437 spin_lock_bh(&priv
->auto_tdls_lock
);
1438 list_for_each_entry(tdls_peer
, &priv
->auto_tdls_list
, list
) {
1439 if ((jiffies
- tdls_peer
->rssi_jiffies
) >
1440 (MWIFIEX_AUTO_TDLS_IDLE_TIME
* HZ
)) {
1441 tdls_peer
->rssi
= 0;
1442 tdls_peer
->do_discover
= true;
1443 priv
->check_tdls_tx
= true;
1446 if (((tdls_peer
->rssi
>= MWIFIEX_TDLS_RSSI_LOW
) ||
1447 !tdls_peer
->rssi
) &&
1448 mwifiex_is_tdls_link_setup(tdls_peer
->tdls_status
)) {
1449 tdls_peer
->tdls_status
= TDLS_LINK_TEARDOWN
;
1450 mwifiex_dbg(priv
->adapter
, MSG
,
1451 "teardown TDLS link,peer=%pM rssi=%d\n",
1452 tdls_peer
->mac_addr
, -tdls_peer
->rssi
);
1453 tdls_peer
->do_discover
= true;
1454 priv
->check_tdls_tx
= true;
1455 cfg80211_tdls_oper_request(priv
->netdev
,
1456 tdls_peer
->mac_addr
,
1457 NL80211_TDLS_TEARDOWN
,
1458 reason
, GFP_ATOMIC
);
1459 } else if (tdls_peer
->rssi
&&
1460 tdls_peer
->rssi
<= MWIFIEX_TDLS_RSSI_HIGH
&&
1461 tdls_peer
->tdls_status
== TDLS_NOT_SETUP
&&
1462 tdls_peer
->failure_count
<
1463 MWIFIEX_TDLS_MAX_FAIL_COUNT
) {
1464 priv
->check_tdls_tx
= true;
1465 tdls_peer
->do_setup
= true;
1466 mwifiex_dbg(priv
->adapter
, INFO
,
1467 "check TDLS with peer=%pM\t"
1468 "rssi=%d\n", tdls_peer
->mac_addr
,
1472 spin_unlock_bh(&priv
->auto_tdls_lock
);
1474 mod_timer(&priv
->auto_tdls_timer
,
1475 jiffies
+ msecs_to_jiffies(MWIFIEX_TIMER_10S
));
1478 void mwifiex_setup_auto_tdls_timer(struct mwifiex_private
*priv
)
1480 timer_setup(&priv
->auto_tdls_timer
, mwifiex_check_auto_tdls
, 0);
1481 priv
->auto_tdls_timer_active
= true;
1482 mod_timer(&priv
->auto_tdls_timer
,
1483 jiffies
+ msecs_to_jiffies(MWIFIEX_TIMER_10S
));
1486 void mwifiex_clean_auto_tdls(struct mwifiex_private
*priv
)
1488 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
1489 priv
->adapter
->auto_tdls
&&
1490 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
) {
1491 priv
->auto_tdls_timer_active
= false;
1492 del_timer(&priv
->auto_tdls_timer
);
1493 mwifiex_flush_auto_tdls_list(priv
);
1497 static int mwifiex_config_tdls(struct mwifiex_private
*priv
, u8 enable
)
1499 struct mwifiex_tdls_config config
;
1501 config
.enable
= cpu_to_le16(enable
);
1502 return mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_CONFIG
,
1503 ACT_TDLS_CS_ENABLE_CONFIG
, 0, &config
, true);
1506 int mwifiex_config_tdls_enable(struct mwifiex_private
*priv
)
1508 return mwifiex_config_tdls(priv
, true);
1511 int mwifiex_config_tdls_disable(struct mwifiex_private
*priv
)
1513 return mwifiex_config_tdls(priv
, false);
1516 int mwifiex_config_tdls_cs_params(struct mwifiex_private
*priv
)
1518 struct mwifiex_tdls_config_cs_params config_tdls_cs_params
;
1520 config_tdls_cs_params
.unit_time
= MWIFIEX_DEF_CS_UNIT_TIME
;
1521 config_tdls_cs_params
.thr_otherlink
= MWIFIEX_DEF_CS_THR_OTHERLINK
;
1522 config_tdls_cs_params
.thr_directlink
= MWIFIEX_DEF_THR_DIRECTLINK
;
1524 return mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_CONFIG
,
1525 ACT_TDLS_CS_PARAMS
, 0,
1526 &config_tdls_cs_params
, true);
1529 int mwifiex_stop_tdls_cs(struct mwifiex_private
*priv
, const u8
*peer_mac
)
1531 struct mwifiex_tdls_stop_cs_params stop_tdls_cs_params
;
1533 ether_addr_copy(stop_tdls_cs_params
.peer_mac
, peer_mac
);
1535 return mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_CONFIG
,
1536 ACT_TDLS_CS_STOP
, 0,
1537 &stop_tdls_cs_params
, true);
1540 int mwifiex_start_tdls_cs(struct mwifiex_private
*priv
, const u8
*peer_mac
,
1541 u8 primary_chan
, u8 second_chan_offset
, u8 band
)
1543 struct mwifiex_tdls_init_cs_params start_tdls_cs_params
;
1545 ether_addr_copy(start_tdls_cs_params
.peer_mac
, peer_mac
);
1546 start_tdls_cs_params
.primary_chan
= primary_chan
;
1547 start_tdls_cs_params
.second_chan_offset
= second_chan_offset
;
1548 start_tdls_cs_params
.band
= band
;
1550 start_tdls_cs_params
.switch_time
= cpu_to_le16(MWIFIEX_DEF_CS_TIME
);
1551 start_tdls_cs_params
.switch_timeout
=
1552 cpu_to_le16(MWIFIEX_DEF_CS_TIMEOUT
);
1553 start_tdls_cs_params
.reg_class
= MWIFIEX_DEF_CS_REG_CLASS
;
1554 start_tdls_cs_params
.periodicity
= MWIFIEX_DEF_CS_PERIODICITY
;
1556 return mwifiex_send_cmd(priv
, HostCmd_CMD_TDLS_CONFIG
,
1557 ACT_TDLS_CS_INIT
, 0,
1558 &start_tdls_cs_params
, true);