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;
359 if (priv->adapter->is_hw_11ac_capable)
360 extcap->ext_capab[7] |= WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED;
363 static void mwifiex_tdls_add_qos_capab(struct sk_buff *skb)
365 u8 *pos = (void *)skb_put(skb, 3);
367 *pos++ = WLAN_EID_QOS_CAPA;
369 *pos++ = MWIFIEX_TDLS_DEF_QOS_CAPAB;
373 mwifiex_tdls_add_wmm_param_ie(struct mwifiex_private *priv, struct sk_buff *skb)
375 struct ieee80211_wmm_param_ie *wmm;
376 u8 ac_vi[] = {0x42, 0x43, 0x5e, 0x00};
377 u8 ac_vo[] = {0x62, 0x32, 0x2f, 0x00};
378 u8 ac_be[] = {0x03, 0xa4, 0x00, 0x00};
379 u8 ac_bk[] = {0x27, 0xa4, 0x00, 0x00};
381 wmm = (void *)skb_put(skb, sizeof(*wmm));
382 memset(wmm, 0, sizeof(*wmm));
384 wmm->element_id = WLAN_EID_VENDOR_SPECIFIC;
385 wmm->len = sizeof(*wmm) - 2;
386 wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */
389 wmm->oui_type = 2; /* WME */
390 wmm->oui_subtype = 1; /* WME param */
391 wmm->version = 1; /* WME ver */
392 wmm->qos_info = 0; /* U-APSD not in use */
394 /* use default WMM AC parameters for TDLS link*/
395 memcpy(&wmm->ac[0], ac_be, sizeof(ac_be));
396 memcpy(&wmm->ac[1], ac_bk, sizeof(ac_bk));
397 memcpy(&wmm->ac[2], ac_vi, sizeof(ac_vi));
398 memcpy(&wmm->ac[3], ac_vo, sizeof(ac_vo));
402 mwifiex_add_wmm_info_ie(struct mwifiex_private *priv, struct sk_buff *skb,
407 buf = (void *)skb_put(skb, MWIFIEX_TDLS_WMM_INFO_SIZE +
408 sizeof(struct ieee_types_header));
410 *buf++ = WLAN_EID_VENDOR_SPECIFIC;
411 *buf++ = 7; /* len */
412 *buf++ = 0x00; /* Microsoft OUI 00:50:F2 */
415 *buf++ = 2; /* WME */
416 *buf++ = 0; /* WME info */
417 *buf++ = 1; /* WME ver */
418 *buf++ = qosinfo; /* U-APSD no in use */
421 static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
422 const u8 *peer, u8 action_code,
424 u16 status_code, struct sk_buff *skb)
426 struct ieee80211_tdls_data *tf;
429 struct ieee80211_ht_cap *ht_cap;
432 capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
434 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
435 memcpy(tf->da, peer, ETH_ALEN);
436 memcpy(tf->sa, priv->curr_addr, ETH_ALEN);
437 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
438 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
440 switch (action_code) {
441 case WLAN_TDLS_SETUP_REQUEST:
442 tf->category = WLAN_CATEGORY_TDLS;
443 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
444 skb_put(skb, sizeof(tf->u.setup_req));
445 tf->u.setup_req.dialog_token = dialog_token;
446 tf->u.setup_req.capability = cpu_to_le16(capab);
447 ret = mwifiex_tdls_append_rates_ie(priv, skb);
449 dev_kfree_skb_any(skb);
453 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
454 *pos++ = WLAN_EID_HT_CAPABILITY;
455 *pos++ = sizeof(struct ieee80211_ht_cap);
456 ht_cap = (void *)pos;
457 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
458 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
460 dev_kfree_skb_any(skb);
464 if (priv->adapter->is_hw_11ac_capable) {
465 ret = mwifiex_tdls_add_vht_capab(priv, skb);
467 dev_kfree_skb_any(skb);
470 mwifiex_tdls_add_aid(priv, skb);
473 mwifiex_tdls_add_ext_capab(priv, skb);
474 mwifiex_tdls_add_qos_capab(skb);
475 mwifiex_add_wmm_info_ie(priv, skb, 0);
478 case WLAN_TDLS_SETUP_RESPONSE:
479 tf->category = WLAN_CATEGORY_TDLS;
480 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
481 skb_put(skb, sizeof(tf->u.setup_resp));
482 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
483 tf->u.setup_resp.dialog_token = dialog_token;
484 tf->u.setup_resp.capability = cpu_to_le16(capab);
485 ret = mwifiex_tdls_append_rates_ie(priv, skb);
487 dev_kfree_skb_any(skb);
491 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
492 *pos++ = WLAN_EID_HT_CAPABILITY;
493 *pos++ = sizeof(struct ieee80211_ht_cap);
494 ht_cap = (void *)pos;
495 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
496 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
498 dev_kfree_skb_any(skb);
502 if (priv->adapter->is_hw_11ac_capable) {
503 ret = mwifiex_tdls_add_vht_capab(priv, skb);
505 dev_kfree_skb_any(skb);
508 mwifiex_tdls_add_aid(priv, skb);
511 mwifiex_tdls_add_ext_capab(priv, skb);
512 mwifiex_tdls_add_qos_capab(skb);
513 mwifiex_add_wmm_info_ie(priv, skb, 0);
516 case WLAN_TDLS_SETUP_CONFIRM:
517 tf->category = WLAN_CATEGORY_TDLS;
518 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
519 skb_put(skb, sizeof(tf->u.setup_cfm));
520 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
521 tf->u.setup_cfm.dialog_token = dialog_token;
523 mwifiex_tdls_add_wmm_param_ie(priv, skb);
524 if (priv->adapter->is_hw_11ac_capable) {
525 ret = mwifiex_tdls_add_vht_oper(priv, peer, skb);
527 dev_kfree_skb_any(skb);
530 ret = mwifiex_tdls_add_ht_oper(priv, peer, 1, skb);
532 dev_kfree_skb_any(skb);
536 ret = mwifiex_tdls_add_ht_oper(priv, peer, 0, skb);
538 dev_kfree_skb_any(skb);
544 case WLAN_TDLS_TEARDOWN:
545 tf->category = WLAN_CATEGORY_TDLS;
546 tf->action_code = WLAN_TDLS_TEARDOWN;
547 skb_put(skb, sizeof(tf->u.teardown));
548 tf->u.teardown.reason_code = cpu_to_le16(status_code);
551 case WLAN_TDLS_DISCOVERY_REQUEST:
552 tf->category = WLAN_CATEGORY_TDLS;
553 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
554 skb_put(skb, sizeof(tf->u.discover_req));
555 tf->u.discover_req.dialog_token = dialog_token;
558 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS frame type.\n");
566 mwifiex_tdls_add_link_ie(struct sk_buff *skb, const u8 *src_addr,
567 const u8 *peer, const u8 *bssid)
569 struct ieee80211_tdls_lnkie *lnkid;
571 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
572 lnkid->ie_type = WLAN_EID_LINK_ID;
573 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) -
574 sizeof(struct ieee_types_header);
576 memcpy(lnkid->bssid, bssid, ETH_ALEN);
577 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
578 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
581 int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
582 u8 action_code, u8 dialog_token,
583 u16 status_code, const u8 *extra_ies,
584 size_t extra_ies_len)
587 struct mwifiex_txinfo *tx_info;
591 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
592 max(sizeof(struct ieee80211_mgmt),
593 sizeof(struct ieee80211_tdls_data)) +
594 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
595 MWIFIEX_SUPPORTED_RATES +
597 sizeof(struct ieee_types_extcap) +
598 sizeof(struct ieee80211_ht_cap) +
599 sizeof(struct ieee_types_bss_co_2040) +
600 sizeof(struct ieee80211_ht_operation) +
601 sizeof(struct ieee80211_tdls_lnkie) +
602 sizeof(struct ieee80211_wmm_param_ie) +
605 if (priv->adapter->is_hw_11ac_capable)
606 skb_len += sizeof(struct ieee_types_vht_cap) +
607 sizeof(struct ieee_types_vht_oper) +
608 sizeof(struct ieee_types_aid);
610 skb = dev_alloc_skb(skb_len);
612 mwifiex_dbg(priv->adapter, ERROR,
613 "allocate skb failed for management frame\n");
616 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
618 switch (action_code) {
619 case WLAN_TDLS_SETUP_REQUEST:
620 case WLAN_TDLS_SETUP_CONFIRM:
621 case WLAN_TDLS_TEARDOWN:
622 case WLAN_TDLS_DISCOVERY_REQUEST:
623 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
624 dialog_token, status_code,
627 dev_kfree_skb_any(skb);
631 memcpy(skb_put(skb, extra_ies_len), extra_ies,
633 mwifiex_tdls_add_link_ie(skb, priv->curr_addr, peer,
636 case WLAN_TDLS_SETUP_RESPONSE:
637 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
638 dialog_token, status_code,
641 dev_kfree_skb_any(skb);
645 memcpy(skb_put(skb, extra_ies_len), extra_ies,
647 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
652 switch (action_code) {
653 case WLAN_TDLS_SETUP_REQUEST:
654 case WLAN_TDLS_SETUP_RESPONSE:
655 skb->priority = MWIFIEX_PRIO_BK;
658 skb->priority = MWIFIEX_PRIO_VI;
662 tx_info = MWIFIEX_SKB_TXCB(skb);
663 memset(tx_info, 0, sizeof(*tx_info));
664 tx_info->bss_num = priv->bss_num;
665 tx_info->bss_type = priv->bss_type;
667 __net_timestamp(skb);
668 mwifiex_queue_tx_pkt(priv, skb);
674 mwifiex_construct_tdls_action_frame(struct mwifiex_private *priv,
676 u8 action_code, u8 dialog_token,
677 u16 status_code, struct sk_buff *skb)
679 struct ieee80211_mgmt *mgmt;
680 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
683 struct ieee80211_ht_cap *ht_cap;
686 capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
688 mgmt = (void *)skb_put(skb, offsetof(struct ieee80211_mgmt, u));
691 memcpy(mgmt->da, peer, ETH_ALEN);
692 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
693 memcpy(mgmt->bssid, priv->cfg_bssid, ETH_ALEN);
694 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
695 IEEE80211_STYPE_ACTION);
698 pos = skb_put(skb, ETH_ALEN);
700 switch (action_code) {
701 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
702 skb_put(skb, sizeof(mgmt->u.action.u.tdls_discover_resp) + 1);
703 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
704 mgmt->u.action.u.tdls_discover_resp.action_code =
705 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
706 mgmt->u.action.u.tdls_discover_resp.dialog_token =
708 mgmt->u.action.u.tdls_discover_resp.capability =
710 /* move back for addr4 */
711 memmove(pos + ETH_ALEN, &mgmt->u.action.category,
712 sizeof(mgmt->u.action.u.tdls_discover_resp));
714 memcpy(pos, bc_addr, ETH_ALEN);
716 ret = mwifiex_tdls_append_rates_ie(priv, skb);
718 dev_kfree_skb_any(skb);
722 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
723 *pos++ = WLAN_EID_HT_CAPABILITY;
724 *pos++ = sizeof(struct ieee80211_ht_cap);
725 ht_cap = (void *)pos;
726 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
727 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
729 dev_kfree_skb_any(skb);
733 if (priv->adapter->is_hw_11ac_capable) {
734 ret = mwifiex_tdls_add_vht_capab(priv, skb);
736 dev_kfree_skb_any(skb);
739 mwifiex_tdls_add_aid(priv, skb);
742 mwifiex_tdls_add_ext_capab(priv, skb);
743 mwifiex_tdls_add_qos_capab(skb);
746 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS action frame type\n");
753 int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
754 u8 action_code, u8 dialog_token,
755 u16 status_code, const u8 *extra_ies,
756 size_t extra_ies_len)
759 struct mwifiex_txinfo *tx_info;
761 u32 pkt_type, tx_control;
762 u16 pkt_len, skb_len;
764 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
765 max(sizeof(struct ieee80211_mgmt),
766 sizeof(struct ieee80211_tdls_data)) +
767 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
768 MWIFIEX_SUPPORTED_RATES +
769 sizeof(struct ieee_types_extcap) +
770 sizeof(struct ieee80211_ht_cap) +
771 sizeof(struct ieee_types_bss_co_2040) +
772 sizeof(struct ieee80211_ht_operation) +
773 sizeof(struct ieee80211_tdls_lnkie) +
776 ETH_ALEN; /* Address4 */
778 if (priv->adapter->is_hw_11ac_capable)
779 skb_len += sizeof(struct ieee_types_vht_cap) +
780 sizeof(struct ieee_types_vht_oper) +
781 sizeof(struct ieee_types_aid);
783 skb = dev_alloc_skb(skb_len);
785 mwifiex_dbg(priv->adapter, ERROR,
786 "allocate skb failed for management frame\n");
790 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
792 pkt_type = PKT_TYPE_MGMT;
794 pos = skb_put(skb, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
795 memset(pos, 0, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
796 memcpy(pos, &pkt_type, sizeof(pkt_type));
797 memcpy(pos + sizeof(pkt_type), &tx_control, sizeof(tx_control));
799 if (mwifiex_construct_tdls_action_frame(priv, peer, action_code,
800 dialog_token, status_code,
802 dev_kfree_skb_any(skb);
807 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
809 /* the TDLS link IE is always added last we are the responder */
811 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
814 skb->priority = MWIFIEX_PRIO_VI;
816 tx_info = MWIFIEX_SKB_TXCB(skb);
817 memset(tx_info, 0, sizeof(*tx_info));
818 tx_info->bss_num = priv->bss_num;
819 tx_info->bss_type = priv->bss_type;
820 tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
822 pkt_len = skb->len - MWIFIEX_MGMT_FRAME_HEADER_SIZE - sizeof(pkt_len);
823 memcpy(skb->data + MWIFIEX_MGMT_FRAME_HEADER_SIZE, &pkt_len,
825 __net_timestamp(skb);
826 mwifiex_queue_tx_pkt(priv, skb);
831 /* This function process tdls action frame from peer.
832 * Peer capabilities are stored into station node structure.
834 void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
837 struct mwifiex_sta_node *sta_ptr;
838 u8 *peer, *pos, *end;
843 if (len < (sizeof(struct ethhdr) + 3))
845 if (*(buf + sizeof(struct ethhdr)) != WLAN_TDLS_SNAP_RFTYPE)
847 if (*(buf + sizeof(struct ethhdr) + 1) != WLAN_CATEGORY_TDLS)
850 peer = buf + ETH_ALEN;
851 action = *(buf + sizeof(struct ethhdr) + 2);
852 mwifiex_dbg(priv->adapter, DATA,
853 "rx:tdls action: peer=%pM, action=%d\n", peer, action);
856 case WLAN_TDLS_SETUP_REQUEST:
857 if (len < (sizeof(struct ethhdr) + TDLS_REQ_FIX_LEN))
860 pos = buf + sizeof(struct ethhdr) + 4;
861 /* payload 1+ category 1 + action 1 + dialog 1 */
862 cap = cpu_to_le16(*(u16 *)pos);
863 ie_len = len - sizeof(struct ethhdr) - TDLS_REQ_FIX_LEN;
867 case WLAN_TDLS_SETUP_RESPONSE:
868 if (len < (sizeof(struct ethhdr) + TDLS_RESP_FIX_LEN))
870 /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
871 pos = buf + sizeof(struct ethhdr) + 6;
872 cap = cpu_to_le16(*(u16 *)pos);
873 ie_len = len - sizeof(struct ethhdr) - TDLS_RESP_FIX_LEN;
877 case WLAN_TDLS_SETUP_CONFIRM:
878 if (len < (sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN))
880 pos = buf + sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN;
881 ie_len = len - sizeof(struct ethhdr) - TDLS_CONFIRM_FIX_LEN;
884 mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS frame type.\n");
888 sta_ptr = mwifiex_add_sta_entry(priv, peer);
892 sta_ptr->tdls_cap.capab = cap;
894 for (end = pos + ie_len; pos + 1 < end; pos += 2 + pos[1]) {
895 if (pos + 2 + pos[1] > end)
899 case WLAN_EID_SUPP_RATES:
900 sta_ptr->tdls_cap.rates_len = pos[1];
901 for (i = 0; i < pos[1]; i++)
902 sta_ptr->tdls_cap.rates[i] = pos[i + 2];
905 case WLAN_EID_EXT_SUPP_RATES:
906 basic = sta_ptr->tdls_cap.rates_len;
907 for (i = 0; i < pos[1]; i++)
908 sta_ptr->tdls_cap.rates[basic + i] = pos[i + 2];
909 sta_ptr->tdls_cap.rates_len += pos[1];
911 case WLAN_EID_HT_CAPABILITY:
912 memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos,
913 sizeof(struct ieee80211_ht_cap));
914 sta_ptr->is_11n_enabled = 1;
916 case WLAN_EID_HT_OPERATION:
917 memcpy(&sta_ptr->tdls_cap.ht_oper, pos,
918 sizeof(struct ieee80211_ht_operation));
920 case WLAN_EID_BSS_COEX_2040:
921 sta_ptr->tdls_cap.coex_2040 = pos[2];
923 case WLAN_EID_EXT_CAPABILITY:
924 memcpy((u8 *)&sta_ptr->tdls_cap.extcap, pos,
925 sizeof(struct ieee_types_header) +
926 min_t(u8, pos[1], 8));
929 memcpy((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,
930 sizeof(struct ieee_types_header) +
931 min_t(u8, pos[1], IEEE_MAX_IE_SIZE -
932 sizeof(struct ieee_types_header)));
934 case WLAN_EID_QOS_CAPA:
935 sta_ptr->tdls_cap.qos_info = pos[2];
937 case WLAN_EID_VHT_OPERATION:
938 if (priv->adapter->is_hw_11ac_capable)
939 memcpy(&sta_ptr->tdls_cap.vhtoper, pos,
940 sizeof(struct ieee80211_vht_operation));
942 case WLAN_EID_VHT_CAPABILITY:
943 if (priv->adapter->is_hw_11ac_capable) {
944 memcpy((u8 *)&sta_ptr->tdls_cap.vhtcap, pos,
945 sizeof(struct ieee80211_vht_cap));
946 sta_ptr->is_11ac_enabled = 1;
950 if (priv->adapter->is_hw_11ac_capable)
951 sta_ptr->tdls_cap.aid =
952 le16_to_cpu(*(__le16 *)(pos + 2));
962 mwifiex_tdls_process_config_link(struct mwifiex_private *priv, const u8 *peer)
964 struct mwifiex_sta_node *sta_ptr;
965 struct mwifiex_ds_tdls_oper tdls_oper;
967 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
968 sta_ptr = mwifiex_get_sta_entry(priv, peer);
970 if (!sta_ptr || sta_ptr->tdls_status == TDLS_SETUP_FAILURE) {
971 mwifiex_dbg(priv->adapter, ERROR,
972 "link absent for peer %pM; cannot config\n", peer);
976 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
977 tdls_oper.tdls_action = MWIFIEX_TDLS_CONFIG_LINK;
978 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
979 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
983 mwifiex_tdls_process_create_link(struct mwifiex_private *priv, const u8 *peer)
985 struct mwifiex_sta_node *sta_ptr;
986 struct mwifiex_ds_tdls_oper tdls_oper;
988 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
989 sta_ptr = mwifiex_get_sta_entry(priv, peer);
991 if (sta_ptr && sta_ptr->tdls_status == TDLS_SETUP_INPROGRESS) {
992 mwifiex_dbg(priv->adapter, WARN,
993 "Setup already in progress for peer %pM\n", peer);
997 sta_ptr = mwifiex_add_sta_entry(priv, peer);
1001 sta_ptr->tdls_status = TDLS_SETUP_INPROGRESS;
1002 mwifiex_hold_tdls_packets(priv, peer);
1003 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
1004 tdls_oper.tdls_action = MWIFIEX_TDLS_CREATE_LINK;
1005 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1006 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
1010 mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
1012 struct mwifiex_sta_node *sta_ptr;
1013 struct mwifiex_ds_tdls_oper tdls_oper;
1014 unsigned long flags;
1016 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
1017 sta_ptr = mwifiex_get_sta_entry(priv, peer);
1020 if (sta_ptr->is_11n_enabled) {
1021 mwifiex_11n_cleanup_reorder_tbl(priv);
1022 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1024 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1025 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1028 mwifiex_del_sta_entry(priv, peer);
1031 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1032 mwifiex_auto_tdls_update_peer_status(priv, peer, TDLS_NOT_SETUP);
1033 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
1034 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
1035 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1036 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
1040 mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
1042 struct mwifiex_sta_node *sta_ptr;
1043 struct ieee80211_mcs_info mcs;
1044 unsigned long flags;
1047 sta_ptr = mwifiex_get_sta_entry(priv, peer);
1049 if (sta_ptr && (sta_ptr->tdls_status != TDLS_SETUP_FAILURE)) {
1050 mwifiex_dbg(priv->adapter, MSG,
1051 "tdls: enable link %pM success\n", peer);
1053 sta_ptr->tdls_status = TDLS_SETUP_COMPLETE;
1055 mcs = sta_ptr->tdls_cap.ht_capb.mcs;
1056 if (mcs.rx_mask[0] != 0xff)
1057 sta_ptr->is_11n_enabled = true;
1058 if (sta_ptr->is_11n_enabled) {
1059 if (le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info) &
1060 IEEE80211_HT_CAP_MAX_AMSDU)
1061 sta_ptr->max_amsdu =
1062 MWIFIEX_TX_DATA_BUF_SIZE_8K;
1064 sta_ptr->max_amsdu =
1065 MWIFIEX_TX_DATA_BUF_SIZE_4K;
1067 for (i = 0; i < MAX_NUM_TID; i++)
1068 sta_ptr->ampdu_sta[i] =
1069 priv->aggr_prio_tbl[i].ampdu_user;
1071 for (i = 0; i < MAX_NUM_TID; i++)
1072 sta_ptr->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
1075 memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
1076 mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
1077 mwifiex_auto_tdls_update_peer_status(priv, peer,
1078 TDLS_SETUP_COMPLETE);
1080 mwifiex_dbg(priv->adapter, ERROR,
1081 "tdls: enable link %pM failed\n", peer);
1083 mwifiex_11n_cleanup_reorder_tbl(priv);
1084 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1086 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1087 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1089 mwifiex_del_sta_entry(priv, peer);
1091 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1092 mwifiex_auto_tdls_update_peer_status(priv, peer,
1101 int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action)
1104 case MWIFIEX_TDLS_ENABLE_LINK:
1105 return mwifiex_tdls_process_enable_link(priv, peer);
1106 case MWIFIEX_TDLS_DISABLE_LINK:
1107 return mwifiex_tdls_process_disable_link(priv, peer);
1108 case MWIFIEX_TDLS_CREATE_LINK:
1109 return mwifiex_tdls_process_create_link(priv, peer);
1110 case MWIFIEX_TDLS_CONFIG_LINK:
1111 return mwifiex_tdls_process_config_link(priv, peer);
1116 int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac)
1118 struct mwifiex_sta_node *sta_ptr;
1120 sta_ptr = mwifiex_get_sta_entry(priv, mac);
1122 return sta_ptr->tdls_status;
1124 return TDLS_NOT_SETUP;
1127 int mwifiex_get_tdls_list(struct mwifiex_private *priv,
1128 struct tdls_peer_info *buf)
1130 struct mwifiex_sta_node *sta_ptr;
1131 struct tdls_peer_info *peer = buf;
1133 unsigned long flags;
1135 if (!ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
1138 /* make sure we are in station mode and connected */
1139 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
1142 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
1143 list_for_each_entry(sta_ptr, &priv->sta_list, list) {
1144 if (sta_ptr->tdls_status == TDLS_SETUP_COMPLETE) {
1145 ether_addr_copy(peer->peer_addr, sta_ptr->mac_addr);
1148 if (count >= MWIFIEX_MAX_TDLS_PEER_SUPPORTED)
1152 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
1157 void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
1159 struct mwifiex_sta_node *sta_ptr;
1160 struct mwifiex_ds_tdls_oper tdls_oper;
1161 unsigned long flags;
1163 if (list_empty(&priv->sta_list))
1166 list_for_each_entry(sta_ptr, &priv->sta_list, list) {
1167 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
1169 if (sta_ptr->is_11n_enabled) {
1170 mwifiex_11n_cleanup_reorder_tbl(priv);
1171 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1173 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1174 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1178 mwifiex_restore_tdls_packets(priv, sta_ptr->mac_addr,
1179 TDLS_LINK_TEARDOWN);
1180 memcpy(&tdls_oper.peer_mac, sta_ptr->mac_addr, ETH_ALEN);
1181 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
1182 if (mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1183 HostCmd_ACT_GEN_SET, 0, &tdls_oper, false))
1184 mwifiex_dbg(priv->adapter, ERROR,
1185 "Disable link failed for TDLS peer %pM",
1189 mwifiex_del_all_sta_list(priv);
1192 int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb)
1194 struct mwifiex_auto_tdls_peer *peer;
1195 unsigned long flags;
1198 ether_addr_copy(mac, skb->data);
1200 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1201 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1202 if (!memcmp(mac, peer->mac_addr, ETH_ALEN)) {
1203 if (peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
1204 peer->tdls_status == TDLS_NOT_SETUP &&
1205 (peer->failure_count <
1206 MWIFIEX_TDLS_MAX_FAIL_COUNT)) {
1207 peer->tdls_status = TDLS_SETUP_INPROGRESS;
1208 mwifiex_dbg(priv->adapter, INFO,
1209 "setup TDLS link, peer=%pM rssi=%d\n",
1210 peer->mac_addr, peer->rssi);
1212 cfg80211_tdls_oper_request(priv->netdev,
1216 peer->do_setup = false;
1217 priv->check_tdls_tx = false;
1218 } else if (peer->failure_count <
1219 MWIFIEX_TDLS_MAX_FAIL_COUNT &&
1220 peer->do_discover) {
1221 mwifiex_send_tdls_data_frame(priv,
1223 WLAN_TDLS_DISCOVERY_REQUEST,
1225 peer->do_discover = false;
1229 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1234 void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv)
1236 struct mwifiex_auto_tdls_peer *peer, *tmp_node;
1237 unsigned long flags;
1239 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1240 list_for_each_entry_safe(peer, tmp_node, &priv->auto_tdls_list, list) {
1241 list_del(&peer->list);
1245 INIT_LIST_HEAD(&priv->auto_tdls_list);
1246 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1247 priv->check_tdls_tx = false;
1250 void mwifiex_add_auto_tdls_peer(struct mwifiex_private *priv, const u8 *mac)
1252 struct mwifiex_auto_tdls_peer *tdls_peer;
1253 unsigned long flags;
1255 if (!priv->adapter->auto_tdls)
1258 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1259 list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
1260 if (!memcmp(tdls_peer->mac_addr, mac, ETH_ALEN)) {
1261 tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
1262 tdls_peer->rssi_jiffies = jiffies;
1263 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1268 /* create new TDLS peer */
1269 tdls_peer = kzalloc(sizeof(*tdls_peer), GFP_ATOMIC);
1271 ether_addr_copy(tdls_peer->mac_addr, mac);
1272 tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
1273 tdls_peer->rssi_jiffies = jiffies;
1274 INIT_LIST_HEAD(&tdls_peer->list);
1275 list_add_tail(&tdls_peer->list, &priv->auto_tdls_list);
1276 mwifiex_dbg(priv->adapter, INFO,
1277 "Add auto TDLS peer= %pM to list\n", mac);
1280 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1283 void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,
1284 const u8 *mac, u8 link_status)
1286 struct mwifiex_auto_tdls_peer *peer;
1287 unsigned long flags;
1289 if (!priv->adapter->auto_tdls)
1292 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1293 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1294 if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
1295 if ((link_status == TDLS_NOT_SETUP) &&
1296 (peer->tdls_status == TDLS_SETUP_INPROGRESS))
1297 peer->failure_count++;
1298 else if (link_status == TDLS_SETUP_COMPLETE)
1299 peer->failure_count = 0;
1301 peer->tdls_status = link_status;
1305 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1308 void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private *priv,
1309 u8 *mac, s8 snr, s8 nflr)
1311 struct mwifiex_auto_tdls_peer *peer;
1312 unsigned long flags;
1314 if (!priv->adapter->auto_tdls)
1317 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1318 list_for_each_entry(peer, &priv->auto_tdls_list, list) {
1319 if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
1320 peer->rssi = nflr - snr;
1321 peer->rssi_jiffies = jiffies;
1325 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1328 void mwifiex_check_auto_tdls(unsigned long context)
1330 struct mwifiex_private *priv = (struct mwifiex_private *)context;
1331 struct mwifiex_auto_tdls_peer *tdls_peer;
1332 unsigned long flags;
1333 u16 reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED;
1335 if (WARN_ON_ONCE(!priv || !priv->adapter)) {
1336 pr_err("mwifiex: %s: adapter or private structure is NULL\n",
1341 if (unlikely(!priv->adapter->auto_tdls))
1344 if (!priv->auto_tdls_timer_active) {
1345 mwifiex_dbg(priv->adapter, INFO,
1346 "auto TDLS timer inactive; return");
1350 priv->check_tdls_tx = false;
1352 if (list_empty(&priv->auto_tdls_list)) {
1353 mod_timer(&priv->auto_tdls_timer,
1355 msecs_to_jiffies(MWIFIEX_TIMER_10S));
1359 spin_lock_irqsave(&priv->auto_tdls_lock, flags);
1360 list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
1361 if ((jiffies - tdls_peer->rssi_jiffies) >
1362 (MWIFIEX_AUTO_TDLS_IDLE_TIME * HZ)) {
1363 tdls_peer->rssi = 0;
1364 tdls_peer->do_discover = true;
1365 priv->check_tdls_tx = true;
1368 if (((tdls_peer->rssi >= MWIFIEX_TDLS_RSSI_LOW) ||
1369 !tdls_peer->rssi) &&
1370 tdls_peer->tdls_status == TDLS_SETUP_COMPLETE) {
1371 tdls_peer->tdls_status = TDLS_LINK_TEARDOWN;
1372 mwifiex_dbg(priv->adapter, MSG,
1373 "teardown TDLS link,peer=%pM rssi=%d\n",
1374 tdls_peer->mac_addr, -tdls_peer->rssi);
1375 tdls_peer->do_discover = true;
1376 priv->check_tdls_tx = true;
1377 cfg80211_tdls_oper_request(priv->netdev,
1378 tdls_peer->mac_addr,
1379 NL80211_TDLS_TEARDOWN,
1380 reason, GFP_ATOMIC);
1381 } else if (tdls_peer->rssi &&
1382 tdls_peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
1383 tdls_peer->tdls_status == TDLS_NOT_SETUP &&
1384 tdls_peer->failure_count <
1385 MWIFIEX_TDLS_MAX_FAIL_COUNT) {
1386 priv->check_tdls_tx = true;
1387 tdls_peer->do_setup = true;
1388 mwifiex_dbg(priv->adapter, INFO,
1389 "check TDLS with peer=%pM\t"
1390 "rssi=%d\n", tdls_peer->mac_addr,
1394 spin_unlock_irqrestore(&priv->auto_tdls_lock, flags);
1396 mod_timer(&priv->auto_tdls_timer,
1397 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
1400 void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv)
1402 setup_timer(&priv->auto_tdls_timer, mwifiex_check_auto_tdls,
1403 (unsigned long)priv);
1404 priv->auto_tdls_timer_active = true;
1405 mod_timer(&priv->auto_tdls_timer,
1406 jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
1409 void mwifiex_clean_auto_tdls(struct mwifiex_private *priv)
1411 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
1412 priv->adapter->auto_tdls &&
1413 priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
1414 priv->auto_tdls_timer_active = false;
1415 del_timer(&priv->auto_tdls_timer);
1416 mwifiex_flush_auto_tdls_list(priv);