1 /* Marvell Wireless LAN device driver: TDLS handling
3 * Copyright (C) 2014, Marvell International Ltd.
5 * This software file (the "File") is distributed by Marvell International
6 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
7 * (the "License"). You may use, redistribute and/or modify this File in
8 * accordance with the terms and conditions of the License, a copy of which
9 * is available on the worldwide web at
10 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
13 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
14 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
15 * this warranty disclaimer.
21 #include "11n_rxreorder.h"
24 #define TDLS_REQ_FIX_LEN 6
25 #define TDLS_RESP_FIX_LEN 8
26 #define TDLS_CONFIRM_FIX_LEN 6
27 #define MWIFIEX_TDLS_WMM_INFO_SIZE 7
29 static void mwifiex_restore_tdls_packets(struct mwifiex_private *priv,
30 const u8 *mac, u8 status)
32 struct mwifiex_ra_list_tbl *ra_list;
33 struct list_head *tid_list;
34 struct sk_buff *skb, *tmp;
35 struct mwifiex_txinfo *tx_info;
40 mwifiex_dbg(priv->adapter, DATA, "%s: %pM\n", __func__, mac);
41 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
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 (status == TDLS_SETUP_COMPLETE) {
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 if (!list_empty(tid_list))
59 ra_list = list_first_entry(tid_list,
60 struct mwifiex_ra_list_tbl, list);
63 tx_info->flags &= ~MWIFIEX_BUF_FLAG_TDLS_PKT;
67 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
71 skb_queue_tail(&ra_list->skb_head, skb);
73 ra_list->ba_pkt_count++;
74 ra_list->total_pkt_count++;
76 if (atomic_read(&priv->wmm.highest_queued_prio) <
77 tos_to_tid_inv[tid_down])
78 atomic_set(&priv->wmm.highest_queued_prio,
79 tos_to_tid_inv[tid_down]);
81 atomic_inc(&priv->wmm.tx_pkts_queued);
84 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
88 static void mwifiex_hold_tdls_packets(struct mwifiex_private *priv,
91 struct mwifiex_ra_list_tbl *ra_list;
92 struct list_head *ra_list_head;
93 struct sk_buff *skb, *tmp;
97 mwifiex_dbg(priv->adapter, DATA, "%s: %pM\n", __func__, mac);
98 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
100 for (i = 0; i < MAX_NUM_TID; i++) {
101 if (!list_empty(&priv->wmm.tid_tbl_ptr[i].ra_list)) {
102 ra_list_head = &priv->wmm.tid_tbl_ptr[i].ra_list;
103 list_for_each_entry(ra_list, ra_list_head, list) {
104 skb_queue_walk_safe(&ra_list->skb_head, skb,
106 if (!ether_addr_equal(mac, skb->data))
108 __skb_unlink(skb, &ra_list->skb_head);
109 atomic_dec(&priv->wmm.tx_pkts_queued);
110 ra_list->total_pkt_count--;
111 skb_queue_tail(&priv->tdls_txq, skb);
117 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
121 /* This function appends rate TLV to scan config command. */
123 mwifiex_tdls_append_rates_ie(struct mwifiex_private *priv,
126 u8 rates[MWIFIEX_SUPPORTED_RATES], *pos;
127 u16 rates_size, supp_rates_size, ext_rates_size;
129 memset(rates, 0, sizeof(rates));
130 rates_size = mwifiex_get_supported_rates(priv, rates);
132 supp_rates_size = min_t(u16, rates_size, MWIFIEX_TDLS_SUPPORTED_RATES);
134 if (skb_tailroom(skb) < rates_size + 4) {
135 mwifiex_dbg(priv->adapter, ERROR,
136 "Insuffient space while adding rates\n");
140 pos = skb_put(skb, supp_rates_size + 2);
141 *pos++ = WLAN_EID_SUPP_RATES;
142 *pos++ = supp_rates_size;
143 memcpy(pos, rates, supp_rates_size);
145 if (rates_size > MWIFIEX_TDLS_SUPPORTED_RATES) {
146 ext_rates_size = rates_size - MWIFIEX_TDLS_SUPPORTED_RATES;
147 pos = skb_put(skb, ext_rates_size + 2);
148 *pos++ = WLAN_EID_EXT_SUPP_RATES;
149 *pos++ = ext_rates_size;
150 memcpy(pos, rates + MWIFIEX_TDLS_SUPPORTED_RATES,
157 static void mwifiex_tdls_add_aid(struct mwifiex_private *priv,
160 struct ieee_types_assoc_rsp *assoc_rsp;
163 assoc_rsp = (struct ieee_types_assoc_rsp *)&priv->assoc_rsp_buf;
164 pos = (void *)skb_put(skb, 4);
165 *pos++ = WLAN_EID_AID;
167 *pos++ = le16_to_cpu(assoc_rsp->a_id);
172 static int mwifiex_tdls_add_vht_capab(struct mwifiex_private *priv,
175 struct ieee80211_vht_cap vht_cap;
178 pos = (void *)skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
179 *pos++ = WLAN_EID_VHT_CAPABILITY;
180 *pos++ = sizeof(struct ieee80211_vht_cap);
182 memset(&vht_cap, 0, sizeof(struct ieee80211_vht_cap));
184 mwifiex_fill_vht_cap_tlv(priv, &vht_cap, priv->curr_bss_params.band);
185 memcpy(pos, &vht_cap, sizeof(vht_cap));
191 mwifiex_tdls_add_ht_oper(struct mwifiex_private *priv, const u8 *mac,
192 u8 vht_enabled, struct sk_buff *skb)
194 struct ieee80211_ht_operation *ht_oper;
195 struct mwifiex_sta_node *sta_ptr;
196 struct mwifiex_bssdescriptor *bss_desc =
197 &priv->curr_bss_params.bss_descriptor;
200 sta_ptr = mwifiex_get_sta_entry(priv, mac);
201 if (unlikely(!sta_ptr)) {
202 mwifiex_dbg(priv->adapter, ERROR,
203 "TDLS peer station not found in list\n");
207 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_operation) + 2);
208 *pos++ = WLAN_EID_HT_OPERATION;
209 *pos++ = sizeof(struct ieee80211_ht_operation);
210 ht_oper = (void *)pos;
212 ht_oper->primary_chan = bss_desc->channel;
214 /* follow AP's channel bandwidth */
215 if (ISSUPP_CHANWIDTH40(priv->adapter->hw_dot_11n_dev_cap) &&
216 bss_desc->bcn_ht_cap &&
217 ISALLOWED_CHANWIDTH40(bss_desc->bcn_ht_oper->ht_param))
218 ht_oper->ht_param = bss_desc->bcn_ht_oper->ht_param;
222 mwifiex_get_sec_chan_offset(bss_desc->channel);
223 ht_oper->ht_param |= BIT(2);
226 memcpy(&sta_ptr->tdls_cap.ht_oper, ht_oper,
227 sizeof(struct ieee80211_ht_operation));
232 static int mwifiex_tdls_add_vht_oper(struct mwifiex_private *priv,
233 const u8 *mac, struct sk_buff *skb)
235 struct mwifiex_bssdescriptor *bss_desc;
236 struct ieee80211_vht_operation *vht_oper;
237 struct ieee80211_vht_cap *vht_cap, *ap_vht_cap = NULL;
238 struct mwifiex_sta_node *sta_ptr;
239 struct mwifiex_adapter *adapter = priv->adapter;
240 u8 supp_chwd_set, peer_supp_chwd_set;
241 u8 *pos, ap_supp_chwd_set, chan_bw;
242 u16 mcs_map_user, mcs_map_resp, mcs_map_result;
243 u16 mcs_user, mcs_resp, nss;
244 u32 usr_vht_cap_info;
246 bss_desc = &priv->curr_bss_params.bss_descriptor;
248 sta_ptr = mwifiex_get_sta_entry(priv, mac);
249 if (unlikely(!sta_ptr)) {
250 mwifiex_dbg(adapter, ERROR,
251 "TDLS peer station not found in list\n");
255 if (!mwifiex_is_bss_in_11ac_mode(priv)) {
256 if (sta_ptr->tdls_cap.extcap.ext_capab[7] &
257 WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
258 mwifiex_dbg(adapter, WARN,
259 "TDLS peer doesn't support wider bandwidth\n");
263 ap_vht_cap = bss_desc->bcn_vht_cap;
266 pos = (void *)skb_put(skb, sizeof(struct ieee80211_vht_operation) + 2);
267 *pos++ = WLAN_EID_VHT_OPERATION;
268 *pos++ = sizeof(struct ieee80211_vht_operation);
269 vht_oper = (struct ieee80211_vht_operation *)pos;
271 if (bss_desc->bss_band & BAND_A)
272 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
274 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
276 /* find the minmum bandwith between AP/TDLS peers */
277 vht_cap = &sta_ptr->tdls_cap.vhtcap;
278 supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
280 GET_VHTCAP_CHWDSET(le32_to_cpu(vht_cap->vht_cap_info));
281 supp_chwd_set = min_t(u8, supp_chwd_set, peer_supp_chwd_set);
283 /* We need check AP's bandwidth when TDLS_WIDER_BANDWIDTH is off */
285 if (ap_vht_cap && sta_ptr->tdls_cap.extcap.ext_capab[7] &
286 WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
288 GET_VHTCAP_CHWDSET(le32_to_cpu(ap_vht_cap->vht_cap_info));
289 supp_chwd_set = min_t(u8, supp_chwd_set, ap_supp_chwd_set);
292 switch (supp_chwd_set) {
293 case IEEE80211_VHT_CHANWIDTH_80MHZ:
294 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
296 case IEEE80211_VHT_CHANWIDTH_160MHZ:
297 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_160MHZ;
299 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
300 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
303 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
307 mcs_map_user = GET_DEVRXMCSMAP(adapter->usr_dot_11ac_mcs_support);
308 mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.rx_mcs_map);
311 for (nss = 1; nss <= 8; nss++) {
312 mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
313 mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
315 if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
316 (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
317 SET_VHTNSSMCS(mcs_map_result, nss,
318 IEEE80211_VHT_MCS_NOT_SUPPORTED);
320 SET_VHTNSSMCS(mcs_map_result, nss,
321 min_t(u16, mcs_user, mcs_resp));
324 vht_oper->basic_mcs_set = cpu_to_le16(mcs_map_result);
326 switch (vht_oper->chan_width) {
327 case IEEE80211_VHT_CHANWIDTH_80MHZ:
328 chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
330 case IEEE80211_VHT_CHANWIDTH_160MHZ:
331 chan_bw = IEEE80211_VHT_CHANWIDTH_160MHZ;
333 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
334 chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
337 chan_bw = IEEE80211_VHT_CHANWIDTH_USE_HT;
340 vht_oper->center_freq_seg1_idx =
341 mwifiex_get_center_freq_index(priv, BAND_AAC,
348 static void mwifiex_tdls_add_ext_capab(struct mwifiex_private *priv,
351 struct ieee_types_extcap *extcap;
353 extcap = (void *)skb_put(skb, sizeof(struct ieee_types_extcap));
354 extcap->ieee_hdr.element_id = WLAN_EID_EXT_CAPABILITY;
355 extcap->ieee_hdr.len = 8;
356 memset(extcap->ext_capab, 0, 8);
357 extcap->ext_capab[4] |= WLAN_EXT_CAPA5_TDLS_ENABLED;
358 extcap->ext_capab[3] |= WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH;
360 if (priv->adapter->is_hw_11ac_capable)
361 extcap->ext_capab[7] |= WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED;
364 static void mwifiex_tdls_add_qos_capab(struct sk_buff *skb)
366 u8 *pos = (void *)skb_put(skb, 3);
368 *pos++ = WLAN_EID_QOS_CAPA;
370 *pos++ = MWIFIEX_TDLS_DEF_QOS_CAPAB;
374 mwifiex_tdls_add_wmm_param_ie(struct mwifiex_private *priv, struct sk_buff *skb)
376 struct ieee80211_wmm_param_ie *wmm;
377 u8 ac_vi[] = {0x42, 0x43, 0x5e, 0x00};
378 u8 ac_vo[] = {0x62, 0x32, 0x2f, 0x00};
379 u8 ac_be[] = {0x03, 0xa4, 0x00, 0x00};
380 u8 ac_bk[] = {0x27, 0xa4, 0x00, 0x00};
382 wmm = (void *)skb_put(skb, sizeof(*wmm));
383 memset(wmm, 0, sizeof(*wmm));
385 wmm->element_id = WLAN_EID_VENDOR_SPECIFIC;
386 wmm->len = sizeof(*wmm) - 2;
387 wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */
390 wmm->oui_type = 2; /* WME */
391 wmm->oui_subtype = 1; /* WME param */
392 wmm->version = 1; /* WME ver */
393 wmm->qos_info = 0; /* U-APSD not in use */
395 /* use default WMM AC parameters for TDLS link*/
396 memcpy(&wmm->ac[0], ac_be, sizeof(ac_be));
397 memcpy(&wmm->ac[1], ac_bk, sizeof(ac_bk));
398 memcpy(&wmm->ac[2], ac_vi, sizeof(ac_vi));
399 memcpy(&wmm->ac[3], ac_vo, sizeof(ac_vo));
403 mwifiex_add_wmm_info_ie(struct mwifiex_private *priv, struct sk_buff *skb,
408 buf = (void *)skb_put(skb, MWIFIEX_TDLS_WMM_INFO_SIZE +
409 sizeof(struct ieee_types_header));
411 *buf++ = WLAN_EID_VENDOR_SPECIFIC;
412 *buf++ = 7; /* len */
413 *buf++ = 0x00; /* Microsoft OUI 00:50:F2 */
416 *buf++ = 2; /* WME */
417 *buf++ = 0; /* WME info */
418 *buf++ = 1; /* WME ver */
419 *buf++ = qosinfo; /* U-APSD no in use */
422 static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
423 const u8 *peer, u8 action_code,
425 u16 status_code, struct sk_buff *skb)
427 struct ieee80211_tdls_data *tf;
430 struct ieee80211_ht_cap *ht_cap;
433 capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
435 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
436 memcpy(tf->da, peer, ETH_ALEN);
437 memcpy(tf->sa, priv->curr_addr, ETH_ALEN);
438 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
439 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
441 switch (action_code) {
442 case WLAN_TDLS_SETUP_REQUEST:
443 tf->category = WLAN_CATEGORY_TDLS;
444 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
445 skb_put(skb, sizeof(tf->u.setup_req));
446 tf->u.setup_req.dialog_token = dialog_token;
447 tf->u.setup_req.capability = cpu_to_le16(capab);
448 ret = mwifiex_tdls_append_rates_ie(priv, skb);
450 dev_kfree_skb_any(skb);
454 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
455 *pos++ = WLAN_EID_HT_CAPABILITY;
456 *pos++ = sizeof(struct ieee80211_ht_cap);
457 ht_cap = (void *)pos;
458 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
459 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
461 dev_kfree_skb_any(skb);
465 if (priv->adapter->is_hw_11ac_capable) {
466 ret = mwifiex_tdls_add_vht_capab(priv, skb);
468 dev_kfree_skb_any(skb);
471 mwifiex_tdls_add_aid(priv, skb);
474 mwifiex_tdls_add_ext_capab(priv, skb);
475 mwifiex_tdls_add_qos_capab(skb);
476 mwifiex_add_wmm_info_ie(priv, skb, 0);
479 case WLAN_TDLS_SETUP_RESPONSE:
480 tf->category = WLAN_CATEGORY_TDLS;
481 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
482 skb_put(skb, sizeof(tf->u.setup_resp));
483 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
484 tf->u.setup_resp.dialog_token = dialog_token;
485 tf->u.setup_resp.capability = cpu_to_le16(capab);
486 ret = mwifiex_tdls_append_rates_ie(priv, skb);
488 dev_kfree_skb_any(skb);
492 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
493 *pos++ = WLAN_EID_HT_CAPABILITY;
494 *pos++ = sizeof(struct ieee80211_ht_cap);
495 ht_cap = (void *)pos;
496 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
497 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
499 dev_kfree_skb_any(skb);
503 if (priv->adapter->is_hw_11ac_capable) {
504 ret = mwifiex_tdls_add_vht_capab(priv, skb);
506 dev_kfree_skb_any(skb);
509 mwifiex_tdls_add_aid(priv, skb);
512 mwifiex_tdls_add_ext_capab(priv, skb);
513 mwifiex_tdls_add_qos_capab(skb);
514 mwifiex_add_wmm_info_ie(priv, skb, 0);
517 case WLAN_TDLS_SETUP_CONFIRM:
518 tf->category = WLAN_CATEGORY_TDLS;
519 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
520 skb_put(skb, sizeof(tf->u.setup_cfm));
521 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
522 tf->u.setup_cfm.dialog_token = dialog_token;
524 mwifiex_tdls_add_wmm_param_ie(priv, skb);
525 if (priv->adapter->is_hw_11ac_capable) {
526 ret = mwifiex_tdls_add_vht_oper(priv, peer, skb);
528 dev_kfree_skb_any(skb);
531 ret = mwifiex_tdls_add_ht_oper(priv, peer, 1, skb);
533 dev_kfree_skb_any(skb);
537 ret = mwifiex_tdls_add_ht_oper(priv, peer, 0, skb);
539 dev_kfree_skb_any(skb);
545 case WLAN_TDLS_TEARDOWN:
546 tf->category = WLAN_CATEGORY_TDLS;
547 tf->action_code = WLAN_TDLS_TEARDOWN;
548 skb_put(skb, sizeof(tf->u.teardown));
549 tf->u.teardown.reason_code = cpu_to_le16(status_code);
552 case WLAN_TDLS_DISCOVERY_REQUEST:
553 tf->category = WLAN_CATEGORY_TDLS;
554 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
555 skb_put(skb, sizeof(tf->u.discover_req));
556 tf->u.discover_req.dialog_token = dialog_token;
559 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS frame type.\n");
567 mwifiex_tdls_add_link_ie(struct sk_buff *skb, const u8 *src_addr,
568 const u8 *peer, const u8 *bssid)
570 struct ieee80211_tdls_lnkie *lnkid;
572 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
573 lnkid->ie_type = WLAN_EID_LINK_ID;
574 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) -
575 sizeof(struct ieee_types_header);
577 memcpy(lnkid->bssid, bssid, ETH_ALEN);
578 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
579 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
582 int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
583 u8 action_code, u8 dialog_token,
584 u16 status_code, const u8 *extra_ies,
585 size_t extra_ies_len)
588 struct mwifiex_txinfo *tx_info;
592 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
593 max(sizeof(struct ieee80211_mgmt),
594 sizeof(struct ieee80211_tdls_data)) +
595 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
596 MWIFIEX_SUPPORTED_RATES +
598 sizeof(struct ieee_types_extcap) +
599 sizeof(struct ieee80211_ht_cap) +
600 sizeof(struct ieee_types_bss_co_2040) +
601 sizeof(struct ieee80211_ht_operation) +
602 sizeof(struct ieee80211_tdls_lnkie) +
603 sizeof(struct ieee80211_wmm_param_ie) +
606 if (priv->adapter->is_hw_11ac_capable)
607 skb_len += sizeof(struct ieee_types_vht_cap) +
608 sizeof(struct ieee_types_vht_oper) +
609 sizeof(struct ieee_types_aid);
611 skb = dev_alloc_skb(skb_len);
613 mwifiex_dbg(priv->adapter, ERROR,
614 "allocate skb failed for management frame\n");
617 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
619 switch (action_code) {
620 case WLAN_TDLS_SETUP_REQUEST:
621 case WLAN_TDLS_SETUP_CONFIRM:
622 case WLAN_TDLS_TEARDOWN:
623 case WLAN_TDLS_DISCOVERY_REQUEST:
624 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
625 dialog_token, status_code,
628 dev_kfree_skb_any(skb);
632 memcpy(skb_put(skb, extra_ies_len), extra_ies,
634 mwifiex_tdls_add_link_ie(skb, priv->curr_addr, peer,
637 case WLAN_TDLS_SETUP_RESPONSE:
638 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
639 dialog_token, status_code,
642 dev_kfree_skb_any(skb);
646 memcpy(skb_put(skb, extra_ies_len), extra_ies,
648 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
653 switch (action_code) {
654 case WLAN_TDLS_SETUP_REQUEST:
655 case WLAN_TDLS_SETUP_RESPONSE:
656 skb->priority = MWIFIEX_PRIO_BK;
659 skb->priority = MWIFIEX_PRIO_VI;
663 tx_info = MWIFIEX_SKB_TXCB(skb);
664 memset(tx_info, 0, sizeof(*tx_info));
665 tx_info->bss_num = priv->bss_num;
666 tx_info->bss_type = priv->bss_type;
668 __net_timestamp(skb);
669 mwifiex_queue_tx_pkt(priv, skb);
675 mwifiex_construct_tdls_action_frame(struct mwifiex_private *priv,
677 u8 action_code, u8 dialog_token,
678 u16 status_code, struct sk_buff *skb)
680 struct ieee80211_mgmt *mgmt;
681 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
684 struct ieee80211_ht_cap *ht_cap;
687 capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
689 mgmt = (void *)skb_put(skb, offsetof(struct ieee80211_mgmt, u));
692 memcpy(mgmt->da, peer, ETH_ALEN);
693 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
694 memcpy(mgmt->bssid, priv->cfg_bssid, ETH_ALEN);
695 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
696 IEEE80211_STYPE_ACTION);
699 pos = skb_put(skb, ETH_ALEN);
701 switch (action_code) {
702 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
703 skb_put(skb, sizeof(mgmt->u.action.u.tdls_discover_resp) + 1);
704 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
705 mgmt->u.action.u.tdls_discover_resp.action_code =
706 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
707 mgmt->u.action.u.tdls_discover_resp.dialog_token =
709 mgmt->u.action.u.tdls_discover_resp.capability =
711 /* move back for addr4 */
712 memmove(pos + ETH_ALEN, &mgmt->u.action.category,
713 sizeof(mgmt->u.action.u.tdls_discover_resp));
715 memcpy(pos, bc_addr, ETH_ALEN);
717 ret = mwifiex_tdls_append_rates_ie(priv, skb);
719 dev_kfree_skb_any(skb);
723 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
724 *pos++ = WLAN_EID_HT_CAPABILITY;
725 *pos++ = sizeof(struct ieee80211_ht_cap);
726 ht_cap = (void *)pos;
727 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
728 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
730 dev_kfree_skb_any(skb);
734 if (priv->adapter->is_hw_11ac_capable) {
735 ret = mwifiex_tdls_add_vht_capab(priv, skb);
737 dev_kfree_skb_any(skb);
740 mwifiex_tdls_add_aid(priv, skb);
743 mwifiex_tdls_add_ext_capab(priv, skb);
744 mwifiex_tdls_add_qos_capab(skb);
747 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS action frame type\n");
754 int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
755 u8 action_code, u8 dialog_token,
756 u16 status_code, const u8 *extra_ies,
757 size_t extra_ies_len)
760 struct mwifiex_txinfo *tx_info;
762 u32 pkt_type, tx_control;
763 u16 pkt_len, skb_len;
765 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
766 max(sizeof(struct ieee80211_mgmt),
767 sizeof(struct ieee80211_tdls_data)) +
768 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
769 MWIFIEX_SUPPORTED_RATES +
770 sizeof(struct ieee_types_extcap) +
771 sizeof(struct ieee80211_ht_cap) +
772 sizeof(struct ieee_types_bss_co_2040) +
773 sizeof(struct ieee80211_ht_operation) +
774 sizeof(struct ieee80211_tdls_lnkie) +
777 ETH_ALEN; /* Address4 */
779 if (priv->adapter->is_hw_11ac_capable)
780 skb_len += sizeof(struct ieee_types_vht_cap) +
781 sizeof(struct ieee_types_vht_oper) +
782 sizeof(struct ieee_types_aid);
784 skb = dev_alloc_skb(skb_len);
786 mwifiex_dbg(priv->adapter, ERROR,
787 "allocate skb failed for management frame\n");
791 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
793 pkt_type = PKT_TYPE_MGMT;
795 pos = skb_put(skb, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
796 memset(pos, 0, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
797 memcpy(pos, &pkt_type, sizeof(pkt_type));
798 memcpy(pos + sizeof(pkt_type), &tx_control, sizeof(tx_control));
800 if (mwifiex_construct_tdls_action_frame(priv, peer, action_code,
801 dialog_token, status_code,
803 dev_kfree_skb_any(skb);
808 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
810 /* the TDLS link IE is always added last we are the responder */
812 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
815 skb->priority = MWIFIEX_PRIO_VI;
817 tx_info = MWIFIEX_SKB_TXCB(skb);
818 memset(tx_info, 0, sizeof(*tx_info));
819 tx_info->bss_num = priv->bss_num;
820 tx_info->bss_type = priv->bss_type;
821 tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
823 pkt_len = skb->len - MWIFIEX_MGMT_FRAME_HEADER_SIZE - sizeof(pkt_len);
824 memcpy(skb->data + MWIFIEX_MGMT_FRAME_HEADER_SIZE, &pkt_len,
826 __net_timestamp(skb);
827 mwifiex_queue_tx_pkt(priv, skb);
832 /* This function process tdls action frame from peer.
833 * Peer capabilities are stored into station node structure.
835 void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
838 struct mwifiex_sta_node *sta_ptr;
839 u8 *peer, *pos, *end;
844 if (len < (sizeof(struct ethhdr) + 3))
846 if (*(buf + sizeof(struct ethhdr)) != WLAN_TDLS_SNAP_RFTYPE)
848 if (*(buf + sizeof(struct ethhdr) + 1) != WLAN_CATEGORY_TDLS)
851 peer = buf + ETH_ALEN;
852 action = *(buf + sizeof(struct ethhdr) + 2);
853 mwifiex_dbg(priv->adapter, DATA,
854 "rx:tdls action: peer=%pM, action=%d\n", peer, action);
857 case WLAN_TDLS_SETUP_REQUEST:
858 if (len < (sizeof(struct ethhdr) + TDLS_REQ_FIX_LEN))
861 pos = buf + sizeof(struct ethhdr) + 4;
862 /* payload 1+ category 1 + action 1 + dialog 1 */
863 cap = cpu_to_le16(*(u16 *)pos);
864 ie_len = len - sizeof(struct ethhdr) - TDLS_REQ_FIX_LEN;
868 case WLAN_TDLS_SETUP_RESPONSE:
869 if (len < (sizeof(struct ethhdr) + TDLS_RESP_FIX_LEN))
871 /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
872 pos = buf + sizeof(struct ethhdr) + 6;
873 cap = cpu_to_le16(*(u16 *)pos);
874 ie_len = len - sizeof(struct ethhdr) - TDLS_RESP_FIX_LEN;
878 case WLAN_TDLS_SETUP_CONFIRM:
879 if (len < (sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN))
881 pos = buf + sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN;
882 ie_len = len - sizeof(struct ethhdr) - TDLS_CONFIRM_FIX_LEN;
885 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS frame type.\n");
889 sta_ptr = mwifiex_add_sta_entry(priv, peer);
893 sta_ptr->tdls_cap.capab = cap;
895 for (end = pos + ie_len; pos + 1 < end; pos += 2 + pos[1]) {
896 if (pos + 2 + pos[1] > end)
900 case WLAN_EID_SUPP_RATES:
901 sta_ptr->tdls_cap.rates_len = pos[1];
902 for (i = 0; i < pos[1]; i++)
903 sta_ptr->tdls_cap.rates[i] = pos[i + 2];
906 case WLAN_EID_EXT_SUPP_RATES:
907 basic = sta_ptr->tdls_cap.rates_len;
908 for (i = 0; i < pos[1]; i++)
909 sta_ptr->tdls_cap.rates[basic + i] = pos[i + 2];
910 sta_ptr->tdls_cap.rates_len += pos[1];
912 case WLAN_EID_HT_CAPABILITY:
913 memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos,
914 sizeof(struct ieee80211_ht_cap));
915 sta_ptr->is_11n_enabled = 1;
917 case WLAN_EID_HT_OPERATION:
918 memcpy(&sta_ptr->tdls_cap.ht_oper, pos,
919 sizeof(struct ieee80211_ht_operation));
921 case WLAN_EID_BSS_COEX_2040:
922 sta_ptr->tdls_cap.coex_2040 = pos[2];
924 case WLAN_EID_EXT_CAPABILITY:
925 memcpy((u8 *)&sta_ptr->tdls_cap.extcap, pos,
926 sizeof(struct ieee_types_header) +
927 min_t(u8, pos[1], 8));
930 memcpy((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,
931 sizeof(struct ieee_types_header) +
932 min_t(u8, pos[1], IEEE_MAX_IE_SIZE -
933 sizeof(struct ieee_types_header)));
935 case WLAN_EID_QOS_CAPA:
936 sta_ptr->tdls_cap.qos_info = pos[2];
938 case WLAN_EID_VHT_OPERATION:
939 if (priv->adapter->is_hw_11ac_capable)
940 memcpy(&sta_ptr->tdls_cap.vhtoper, pos,
941 sizeof(struct ieee80211_vht_operation));
943 case WLAN_EID_VHT_CAPABILITY:
944 if (priv->adapter->is_hw_11ac_capable) {
945 memcpy((u8 *)&sta_ptr->tdls_cap.vhtcap, pos,
946 sizeof(struct ieee80211_vht_cap));
947 sta_ptr->is_11ac_enabled = 1;
951 if (priv->adapter->is_hw_11ac_capable)
952 sta_ptr->tdls_cap.aid =
953 le16_to_cpu(*(__le16 *)(pos + 2));
963 mwifiex_tdls_process_config_link(struct mwifiex_private *priv, const u8 *peer)
965 struct mwifiex_sta_node *sta_ptr;
966 struct mwifiex_ds_tdls_oper tdls_oper;
968 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
969 sta_ptr = mwifiex_get_sta_entry(priv, peer);
971 if (!sta_ptr || sta_ptr->tdls_status == TDLS_SETUP_FAILURE) {
972 mwifiex_dbg(priv->adapter, ERROR,
973 "link absent for peer %pM; cannot config\n", peer);
977 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
978 tdls_oper.tdls_action = MWIFIEX_TDLS_CONFIG_LINK;
979 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
980 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
984 mwifiex_tdls_process_create_link(struct mwifiex_private *priv, const u8 *peer)
986 struct mwifiex_sta_node *sta_ptr;
987 struct mwifiex_ds_tdls_oper tdls_oper;
989 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
990 sta_ptr = mwifiex_get_sta_entry(priv, peer);
992 if (sta_ptr && sta_ptr->tdls_status == TDLS_SETUP_INPROGRESS) {
993 mwifiex_dbg(priv->adapter, WARN,
994 "Setup already in progress for peer %pM\n", peer);
998 sta_ptr = mwifiex_add_sta_entry(priv, peer);
1002 sta_ptr->tdls_status = TDLS_SETUP_INPROGRESS;
1003 mwifiex_hold_tdls_packets(priv, peer);
1004 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
1005 tdls_oper.tdls_action = MWIFIEX_TDLS_CREATE_LINK;
1006 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1007 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
1011 mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
1013 struct mwifiex_sta_node *sta_ptr;
1014 struct mwifiex_ds_tdls_oper tdls_oper;
1015 unsigned long flags;
1017 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
1018 sta_ptr = mwifiex_get_sta_entry(priv, peer);
1021 if (sta_ptr->is_11n_enabled) {
1022 mwifiex_11n_cleanup_reorder_tbl(priv);
1023 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1025 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1026 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1029 mwifiex_del_sta_entry(priv, peer);
1032 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1033 mwifiex_auto_tdls_update_peer_status(priv, peer, TDLS_NOT_SETUP);
1034 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
1035 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
1036 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1037 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
1041 mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
1043 struct mwifiex_sta_node *sta_ptr;
1044 struct ieee80211_mcs_info mcs;
1045 unsigned long flags;
1048 sta_ptr = mwifiex_get_sta_entry(priv, peer);
1050 if (sta_ptr && (sta_ptr->tdls_status != TDLS_SETUP_FAILURE)) {
1051 mwifiex_dbg(priv->adapter, MSG,
1052 "tdls: enable link %pM success\n", peer);
1054 sta_ptr->tdls_status = TDLS_SETUP_COMPLETE;
1056 mcs = sta_ptr->tdls_cap.ht_capb.mcs;
1057 if (mcs.rx_mask[0] != 0xff)
1058 sta_ptr->is_11n_enabled = true;
1059 if (sta_ptr->is_11n_enabled) {
1060 if (le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info) &
1061 IEEE80211_HT_CAP_MAX_AMSDU)
1062 sta_ptr->max_amsdu =
1063 MWIFIEX_TX_DATA_BUF_SIZE_8K;
1065 sta_ptr->max_amsdu =
1066 MWIFIEX_TX_DATA_BUF_SIZE_4K;
1068 for (i = 0; i < MAX_NUM_TID; i++)
1069 sta_ptr->ampdu_sta[i] =
1070 priv->aggr_prio_tbl[i].ampdu_user;
1072 for (i = 0; i < MAX_NUM_TID; i++)
1073 sta_ptr->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
1075 if (sta_ptr->tdls_cap.extcap.ext_capab[3] &
1076 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) {
1077 mwifiex_config_tdls_enable(priv);
1078 mwifiex_config_tdls_cs_params(priv);
1081 memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
1082 mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
1083 mwifiex_auto_tdls_update_peer_status(priv, peer,
1084 TDLS_SETUP_COMPLETE);
1086 mwifiex_dbg(priv->adapter, ERROR,
1087 "tdls: enable link %pM failed\n", peer);
1089 mwifiex_11n_cleanup_reorder_tbl(priv);
1090 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1092 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1093 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1095 mwifiex_del_sta_entry(priv, peer);
1097 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1098 mwifiex_auto_tdls_update_peer_status(priv, peer,
1107 int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action)
1110 case MWIFIEX_TDLS_ENABLE_LINK:
1111 return mwifiex_tdls_process_enable_link(priv, peer);
1112 case MWIFIEX_TDLS_DISABLE_LINK:
1113 return mwifiex_tdls_process_disable_link(priv, peer);
1114 case MWIFIEX_TDLS_CREATE_LINK:
1115 return mwifiex_tdls_process_create_link(priv, peer);
1116 case MWIFIEX_TDLS_CONFIG_LINK:
1117 return mwifiex_tdls_process_config_link(priv, peer);
1122 int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac)
1124 struct mwifiex_sta_node *sta_ptr;
1126 sta_ptr = mwifiex_get_sta_entry(priv, mac);
1128 return sta_ptr->tdls_status;
1130 return TDLS_NOT_SETUP;
1133 int mwifiex_get_tdls_list(struct mwifiex_private *priv,
1134 struct tdls_peer_info *buf)
1136 struct mwifiex_sta_node *sta_ptr;
1137 struct tdls_peer_info *peer = buf;
1139 unsigned long flags;
1141 if (!ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
1144 /* make sure we are in station mode and connected */
1145 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
1148 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1149 list_for_each_entry(sta_ptr, &priv->sta_list, list) {
1150 if (sta_ptr->tdls_status == TDLS_SETUP_COMPLETE) {
1151 ether_addr_copy(peer->peer_addr, sta_ptr->mac_addr);
1154 if (count >= MWIFIEX_MAX_TDLS_PEER_SUPPORTED)
1158 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1163 void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
1165 struct mwifiex_sta_node *sta_ptr;
1166 struct mwifiex_ds_tdls_oper tdls_oper;
1167 unsigned long flags;
1169 if (list_empty(&priv->sta_list))
1172 list_for_each_entry(sta_ptr, &priv->sta_list, list) {
1173 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
1175 if (sta_ptr->is_11n_enabled) {
1176 mwifiex_11n_cleanup_reorder_tbl(priv);
1177 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1179 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1180 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1184 mwifiex_restore_tdls_packets(priv, sta_ptr->mac_addr,
1185 TDLS_LINK_TEARDOWN);
1186 memcpy(&tdls_oper.peer_mac, sta_ptr->mac_addr, ETH_ALEN);
1187 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
1188 if (mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1189 HostCmd_ACT_GEN_SET, 0, &tdls_oper, false))
1190 mwifiex_dbg(priv->adapter, ERROR,
1191 "Disable link failed for TDLS peer %pM",
1195 mwifiex_del_all_sta_list(priv);
1198 int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb)
1200 struct mwifiex_auto_tdls_peer *peer;
1201 unsigned long flags;
1204 ether_addr_copy(mac, skb->data);
1206 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1207 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1208 if (!memcmp(mac, peer->mac_addr, ETH_ALEN)) {
1209 if (peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
1210 peer->tdls_status == TDLS_NOT_SETUP &&
1211 (peer->failure_count <
1212 MWIFIEX_TDLS_MAX_FAIL_COUNT)) {
1213 peer->tdls_status = TDLS_SETUP_INPROGRESS;
1214 mwifiex_dbg(priv->adapter, INFO,
1215 "setup TDLS link, peer=%pM rssi=%d\n",
1216 peer->mac_addr, peer->rssi);
1218 cfg80211_tdls_oper_request(priv->netdev,
1222 peer->do_setup = false;
1223 priv->check_tdls_tx = false;
1224 } else if (peer->failure_count <
1225 MWIFIEX_TDLS_MAX_FAIL_COUNT &&
1226 peer->do_discover) {
1227 mwifiex_send_tdls_data_frame(priv,
1229 WLAN_TDLS_DISCOVERY_REQUEST,
1231 peer->do_discover = false;
1235 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1240 void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv)
1242 struct mwifiex_auto_tdls_peer *peer, *tmp_node;
1243 unsigned long flags;
1245 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1246 list_for_each_entry_safe(peer, tmp_node, &priv->auto_tdls_list, list) {
1247 list_del(&peer->list);
1251 INIT_LIST_HEAD(&priv->auto_tdls_list);
1252 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1253 priv->check_tdls_tx = false;
1256 void mwifiex_add_auto_tdls_peer(struct mwifiex_private *priv, const u8 *mac)
1258 struct mwifiex_auto_tdls_peer *tdls_peer;
1259 unsigned long flags;
1261 if (!priv->adapter->auto_tdls)
1264 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1265 list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
1266 if (!memcmp(tdls_peer->mac_addr, mac, ETH_ALEN)) {
1267 tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
1268 tdls_peer->rssi_jiffies = jiffies;
1269 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1274 /* create new TDLS peer */
1275 tdls_peer = kzalloc(sizeof(*tdls_peer), GFP_ATOMIC);
1277 ether_addr_copy(tdls_peer->mac_addr, mac);
1278 tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
1279 tdls_peer->rssi_jiffies = jiffies;
1280 INIT_LIST_HEAD(&tdls_peer->list);
1281 list_add_tail(&tdls_peer->list, &priv->auto_tdls_list);
1282 mwifiex_dbg(priv->adapter, INFO,
1283 "Add auto TDLS peer= %pM to list\n", mac);
1286 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1289 void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,
1290 const u8 *mac, u8 link_status)
1292 struct mwifiex_auto_tdls_peer *peer;
1293 unsigned long flags;
1295 if (!priv->adapter->auto_tdls)
1298 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1299 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1300 if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
1301 if ((link_status == TDLS_NOT_SETUP) &&
1302 (peer->tdls_status == TDLS_SETUP_INPROGRESS))
1303 peer->failure_count++;
1304 else if (link_status == TDLS_SETUP_COMPLETE)
1305 peer->failure_count = 0;
1307 peer->tdls_status = link_status;
1311 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1314 void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private *priv,
1315 u8 *mac, s8 snr, s8 nflr)
1317 struct mwifiex_auto_tdls_peer *peer;
1318 unsigned long flags;
1320 if (!priv->adapter->auto_tdls)
1323 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1324 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1325 if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
1326 peer->rssi = nflr - snr;
1327 peer->rssi_jiffies = jiffies;
1331 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1334 void mwifiex_check_auto_tdls(unsigned long context)
1336 struct mwifiex_private *priv = (struct mwifiex_private *)context;
1337 struct mwifiex_auto_tdls_peer *tdls_peer;
1338 unsigned long flags;
1339 u16 reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED;
1341 if (WARN_ON_ONCE(!priv || !priv->adapter)) {
1342 pr_err("mwifiex: %s: adapter or private structure is NULL\n",
1347 if (unlikely(!priv->adapter->auto_tdls))
1350 if (!priv->auto_tdls_timer_active) {
1351 mwifiex_dbg(priv->adapter, INFO,
1352 "auto TDLS timer inactive; return");
1356 priv->check_tdls_tx = false;
1358 if (list_empty(&priv->auto_tdls_list)) {
1359 mod_timer(&priv->auto_tdls_timer,
1361 msecs_to_jiffies(MWIFIEX_TIMER_10S));
1365 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1366 list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
1367 if ((jiffies - tdls_peer->rssi_jiffies) >
1368 (MWIFIEX_AUTO_TDLS_IDLE_TIME * HZ)) {
1369 tdls_peer->rssi = 0;
1370 tdls_peer->do_discover = true;
1371 priv->check_tdls_tx = true;
1374 if (((tdls_peer->rssi >= MWIFIEX_TDLS_RSSI_LOW) ||
1375 !tdls_peer->rssi) &&
1376 tdls_peer->tdls_status == TDLS_SETUP_COMPLETE) {
1377 tdls_peer->tdls_status = TDLS_LINK_TEARDOWN;
1378 mwifiex_dbg(priv->adapter, MSG,
1379 "teardown TDLS link,peer=%pM rssi=%d\n",
1380 tdls_peer->mac_addr, -tdls_peer->rssi);
1381 tdls_peer->do_discover = true;
1382 priv->check_tdls_tx = true;
1383 cfg80211_tdls_oper_request(priv->netdev,
1384 tdls_peer->mac_addr,
1385 NL80211_TDLS_TEARDOWN,
1386 reason, GFP_ATOMIC);
1387 } else if (tdls_peer->rssi &&
1388 tdls_peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
1389 tdls_peer->tdls_status == TDLS_NOT_SETUP &&
1390 tdls_peer->failure_count <
1391 MWIFIEX_TDLS_MAX_FAIL_COUNT) {
1392 priv->check_tdls_tx = true;
1393 tdls_peer->do_setup = true;
1394 mwifiex_dbg(priv->adapter, INFO,
1395 "check TDLS with peer=%pM\t"
1396 "rssi=%d\n", tdls_peer->mac_addr,
1400 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1402 mod_timer(&priv->auto_tdls_timer,
1403 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
1406 void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv)
1408 setup_timer(&priv->auto_tdls_timer, mwifiex_check_auto_tdls,
1409 (unsigned long)priv);
1410 priv->auto_tdls_timer_active = true;
1411 mod_timer(&priv->auto_tdls_timer,
1412 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
1415 void mwifiex_clean_auto_tdls(struct mwifiex_private *priv)
1417 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
1418 priv->adapter->auto_tdls &&
1419 priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
1420 priv->auto_tdls_timer_active = false;
1421 del_timer(&priv->auto_tdls_timer);
1422 mwifiex_flush_auto_tdls_list(priv);
1426 static int mwifiex_config_tdls(struct mwifiex_private *priv, u8 enable)
1428 struct mwifiex_tdls_config config;
1430 config.enable = cpu_to_le16(enable);
1431 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
1432 ACT_TDLS_CS_ENABLE_CONFIG, 0, &config, true);
1435 int mwifiex_config_tdls_enable(struct mwifiex_private *priv)
1437 return mwifiex_config_tdls(priv, true);
1440 int mwifiex_config_tdls_disable(struct mwifiex_private *priv)
1442 return mwifiex_config_tdls(priv, false);
1445 int mwifiex_config_tdls_cs_params(struct mwifiex_private *priv)
1447 struct mwifiex_tdls_config_cs_params config_tdls_cs_params;
1449 config_tdls_cs_params.unit_time = MWIFIEX_DEF_CS_UNIT_TIME;
1450 config_tdls_cs_params.thr_otherlink = MWIFIEX_DEF_CS_THR_OTHERLINK;
1451 config_tdls_cs_params.thr_directlink = MWIFIEX_DEF_THR_DIRECTLINK;
1453 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
1454 ACT_TDLS_CS_PARAMS, 0,
1455 &config_tdls_cs_params, true);
1458 int mwifiex_stop_tdls_cs(struct mwifiex_private *priv, const u8 *peer_mac)
1460 struct mwifiex_tdls_stop_cs_params stop_tdls_cs_params;
1462 ether_addr_copy(stop_tdls_cs_params.peer_mac, peer_mac);
1464 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
1465 ACT_TDLS_CS_STOP, 0,
1466 &stop_tdls_cs_params, true);
1469 int mwifiex_start_tdls_cs(struct mwifiex_private *priv, const u8 *peer_mac,
1470 u8 primary_chan, u8 second_chan_offset, u8 band)
1472 struct mwifiex_tdls_init_cs_params start_tdls_cs_params;
1474 ether_addr_copy(start_tdls_cs_params.peer_mac, peer_mac);
1475 start_tdls_cs_params.primary_chan = primary_chan;
1476 start_tdls_cs_params.second_chan_offset = second_chan_offset;
1477 start_tdls_cs_params.band = band;
1479 start_tdls_cs_params.switch_time = cpu_to_le16(MWIFIEX_DEF_CS_TIME);
1480 start_tdls_cs_params.switch_timeout =
1481 cpu_to_le16(MWIFIEX_DEF_CS_TIMEOUT);
1482 start_tdls_cs_params.reg_class = MWIFIEX_DEF_CS_REG_CLASS;
1483 start_tdls_cs_params.periodicity = MWIFIEX_DEF_CS_PERIODICITY;
1485 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
1486 ACT_TDLS_CS_INIT, 0,
1487 &start_tdls_cs_params, true);