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
28 static void mwifiex_restore_tdls_packets(struct mwifiex_private *priv,
29 const u8 *mac, u8 status)
31 struct mwifiex_ra_list_tbl *ra_list;
32 struct list_head *tid_list;
33 struct sk_buff *skb, *tmp;
34 struct mwifiex_txinfo *tx_info;
39 dev_dbg(priv->adapter->dev, "%s: %pM\n", __func__, mac);
40 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
42 skb_queue_walk_safe(&priv->tdls_txq, skb, tmp) {
43 if (!ether_addr_equal(mac, skb->data))
46 __skb_unlink(skb, &priv->tdls_txq);
47 tx_info = MWIFIEX_SKB_TXCB(skb);
49 tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
51 if (status == TDLS_SETUP_COMPLETE) {
52 ra_list = mwifiex_wmm_get_queue_raptr(priv, tid, mac);
53 ra_list->tdls_link = true;
54 tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
56 tid_list = &priv->wmm.tid_tbl_ptr[tid_down].ra_list;
57 if (!list_empty(tid_list))
58 ra_list = list_first_entry(tid_list,
59 struct mwifiex_ra_list_tbl, list);
62 tx_info->flags &= ~MWIFIEX_BUF_FLAG_TDLS_PKT;
66 mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
70 skb_queue_tail(&ra_list->skb_head, skb);
72 ra_list->ba_pkt_count++;
73 ra_list->total_pkt_count++;
75 if (atomic_read(&priv->wmm.highest_queued_prio) <
76 tos_to_tid_inv[tid_down])
77 atomic_set(&priv->wmm.highest_queued_prio,
78 tos_to_tid_inv[tid_down]);
80 atomic_inc(&priv->wmm.tx_pkts_queued);
83 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
87 static void mwifiex_hold_tdls_packets(struct mwifiex_private *priv,
90 struct mwifiex_ra_list_tbl *ra_list;
91 struct list_head *ra_list_head;
92 struct sk_buff *skb, *tmp;
96 dev_dbg(priv->adapter->dev, "%s: %pM\n", __func__, mac);
97 spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
99 for (i = 0; i < MAX_NUM_TID; i++) {
100 if (!list_empty(&priv->wmm.tid_tbl_ptr[i].ra_list)) {
101 ra_list_head = &priv->wmm.tid_tbl_ptr[i].ra_list;
102 list_for_each_entry(ra_list, ra_list_head, list) {
103 skb_queue_walk_safe(&ra_list->skb_head, skb,
105 if (!ether_addr_equal(mac, skb->data))
107 __skb_unlink(skb, &ra_list->skb_head);
108 atomic_dec(&priv->wmm.tx_pkts_queued);
109 ra_list->total_pkt_count--;
110 skb_queue_tail(&priv->tdls_txq, skb);
116 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
120 /* This function appends rate TLV to scan config command. */
122 mwifiex_tdls_append_rates_ie(struct mwifiex_private *priv,
125 u8 rates[MWIFIEX_SUPPORTED_RATES], *pos;
126 u16 rates_size, supp_rates_size, ext_rates_size;
128 memset(rates, 0, sizeof(rates));
129 rates_size = mwifiex_get_supported_rates(priv, rates);
131 supp_rates_size = min_t(u16, rates_size, MWIFIEX_TDLS_SUPPORTED_RATES);
133 if (skb_tailroom(skb) < rates_size + 4) {
134 dev_err(priv->adapter->dev,
135 "Insuffient space while adding rates\n");
139 pos = skb_put(skb, supp_rates_size + 2);
140 *pos++ = WLAN_EID_SUPP_RATES;
141 *pos++ = supp_rates_size;
142 memcpy(pos, rates, supp_rates_size);
144 if (rates_size > MWIFIEX_TDLS_SUPPORTED_RATES) {
145 ext_rates_size = rates_size - MWIFIEX_TDLS_SUPPORTED_RATES;
146 pos = skb_put(skb, ext_rates_size + 2);
147 *pos++ = WLAN_EID_EXT_SUPP_RATES;
148 *pos++ = ext_rates_size;
149 memcpy(pos, rates + MWIFIEX_TDLS_SUPPORTED_RATES,
156 static void mwifiex_tdls_add_aid(struct mwifiex_private *priv,
159 struct ieee_types_assoc_rsp *assoc_rsp;
162 assoc_rsp = (struct ieee_types_assoc_rsp *)&priv->assoc_rsp_buf;
163 pos = (void *)skb_put(skb, 4);
164 *pos++ = WLAN_EID_AID;
166 *pos++ = le16_to_cpu(assoc_rsp->a_id);
171 static int mwifiex_tdls_add_vht_capab(struct mwifiex_private *priv,
174 struct ieee80211_vht_cap vht_cap;
177 pos = (void *)skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
178 *pos++ = WLAN_EID_VHT_CAPABILITY;
179 *pos++ = sizeof(struct ieee80211_vht_cap);
181 memset(&vht_cap, 0, sizeof(struct ieee80211_vht_cap));
183 mwifiex_fill_vht_cap_tlv(priv, &vht_cap, priv->curr_bss_params.band);
184 memcpy(pos, &vht_cap, sizeof(vht_cap));
190 mwifiex_tdls_add_ht_oper(struct mwifiex_private *priv, const u8 *mac,
191 u8 vht_enabled, struct sk_buff *skb)
193 struct ieee80211_ht_operation *ht_oper;
194 struct mwifiex_sta_node *sta_ptr;
195 struct mwifiex_bssdescriptor *bss_desc =
196 &priv->curr_bss_params.bss_descriptor;
199 sta_ptr = mwifiex_get_sta_entry(priv, mac);
200 if (unlikely(!sta_ptr)) {
201 dev_warn(priv->adapter->dev,
202 "TDLS peer station not found in list\n");
206 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_operation) + 2);
207 *pos++ = WLAN_EID_HT_OPERATION;
208 *pos++ = sizeof(struct ieee80211_ht_operation);
209 ht_oper = (void *)pos;
211 ht_oper->primary_chan = bss_desc->channel;
213 /* follow AP's channel bandwidth */
214 if (ISSUPP_CHANWIDTH40(priv->adapter->hw_dot_11n_dev_cap) &&
215 bss_desc->bcn_ht_cap &&
216 ISALLOWED_CHANWIDTH40(bss_desc->bcn_ht_oper->ht_param))
217 ht_oper->ht_param = bss_desc->bcn_ht_oper->ht_param;
221 mwifiex_get_sec_chan_offset(bss_desc->channel);
222 ht_oper->ht_param |= BIT(2);
225 memcpy(&sta_ptr->tdls_cap.ht_oper, ht_oper,
226 sizeof(struct ieee80211_ht_operation));
231 static int mwifiex_tdls_add_vht_oper(struct mwifiex_private *priv,
232 const u8 *mac, struct sk_buff *skb)
234 struct mwifiex_bssdescriptor *bss_desc;
235 struct ieee80211_vht_operation *vht_oper;
236 struct ieee80211_vht_cap *vht_cap, *ap_vht_cap = NULL;
237 struct mwifiex_sta_node *sta_ptr;
238 struct mwifiex_adapter *adapter = priv->adapter;
239 u8 supp_chwd_set, peer_supp_chwd_set;
240 u8 *pos, ap_supp_chwd_set, chan_bw;
241 u16 mcs_map_user, mcs_map_resp, mcs_map_result;
242 u16 mcs_user, mcs_resp, nss;
243 u32 usr_vht_cap_info;
245 bss_desc = &priv->curr_bss_params.bss_descriptor;
247 sta_ptr = mwifiex_get_sta_entry(priv, mac);
248 if (unlikely(!sta_ptr)) {
249 dev_warn(adapter->dev, "TDLS peer station not found in list\n");
253 if (!mwifiex_is_bss_in_11ac_mode(priv)) {
254 if (sta_ptr->tdls_cap.extcap.ext_capab[7] &
255 WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
256 dev_dbg(adapter->dev,
257 "TDLS peer doesn't support wider bandwitdh\n");
261 ap_vht_cap = bss_desc->bcn_vht_cap;
264 pos = (void *)skb_put(skb, sizeof(struct ieee80211_vht_operation) + 2);
265 *pos++ = WLAN_EID_VHT_OPERATION;
266 *pos++ = sizeof(struct ieee80211_vht_operation);
267 vht_oper = (struct ieee80211_vht_operation *)pos;
269 if (bss_desc->bss_band & BAND_A)
270 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
272 usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
274 /* find the minmum bandwith between AP/TDLS peers */
275 vht_cap = &sta_ptr->tdls_cap.vhtcap;
276 supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
278 GET_VHTCAP_CHWDSET(le32_to_cpu(vht_cap->vht_cap_info));
279 supp_chwd_set = min_t(u8, supp_chwd_set, peer_supp_chwd_set);
281 /* We need check AP's bandwidth when TDLS_WIDER_BANDWIDTH is off */
283 if (ap_vht_cap && sta_ptr->tdls_cap.extcap.ext_capab[7] &
284 WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
286 GET_VHTCAP_CHWDSET(le32_to_cpu(ap_vht_cap->vht_cap_info));
287 supp_chwd_set = min_t(u8, supp_chwd_set, ap_supp_chwd_set);
290 switch (supp_chwd_set) {
291 case IEEE80211_VHT_CHANWIDTH_80MHZ:
292 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
294 case IEEE80211_VHT_CHANWIDTH_160MHZ:
295 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_160MHZ;
297 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
298 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
301 vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
305 mcs_map_user = GET_DEVRXMCSMAP(adapter->usr_dot_11ac_mcs_support);
306 mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.rx_mcs_map);
309 for (nss = 1; nss <= 8; nss++) {
310 mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
311 mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
313 if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
314 (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
315 SET_VHTNSSMCS(mcs_map_result, nss,
316 IEEE80211_VHT_MCS_NOT_SUPPORTED);
318 SET_VHTNSSMCS(mcs_map_result, nss,
319 min_t(u16, mcs_user, mcs_resp));
322 vht_oper->basic_mcs_set = cpu_to_le16(mcs_map_result);
324 switch (vht_oper->chan_width) {
325 case IEEE80211_VHT_CHANWIDTH_80MHZ:
326 chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
328 case IEEE80211_VHT_CHANWIDTH_160MHZ:
329 chan_bw = IEEE80211_VHT_CHANWIDTH_160MHZ;
331 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
332 chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
335 chan_bw = IEEE80211_VHT_CHANWIDTH_USE_HT;
338 vht_oper->center_freq_seg1_idx =
339 mwifiex_get_center_freq_index(priv, BAND_AAC,
346 static void mwifiex_tdls_add_ext_capab(struct mwifiex_private *priv,
349 struct ieee_types_extcap *extcap;
351 extcap = (void *)skb_put(skb, sizeof(struct ieee_types_extcap));
352 extcap->ieee_hdr.element_id = WLAN_EID_EXT_CAPABILITY;
353 extcap->ieee_hdr.len = 8;
354 memset(extcap->ext_capab, 0, 8);
355 extcap->ext_capab[4] |= WLAN_EXT_CAPA5_TDLS_ENABLED;
357 if (priv->adapter->is_hw_11ac_capable)
358 extcap->ext_capab[7] |= WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED;
361 static void mwifiex_tdls_add_qos_capab(struct sk_buff *skb)
363 u8 *pos = (void *)skb_put(skb, 3);
365 *pos++ = WLAN_EID_QOS_CAPA;
367 *pos++ = MWIFIEX_TDLS_DEF_QOS_CAPAB;
370 static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
371 const u8 *peer, u8 action_code,
373 u16 status_code, struct sk_buff *skb)
375 struct ieee80211_tdls_data *tf;
378 struct ieee80211_ht_cap *ht_cap;
381 capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
383 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
384 memcpy(tf->da, peer, ETH_ALEN);
385 memcpy(tf->sa, priv->curr_addr, ETH_ALEN);
386 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
387 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
389 switch (action_code) {
390 case WLAN_TDLS_SETUP_REQUEST:
391 tf->category = WLAN_CATEGORY_TDLS;
392 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
393 skb_put(skb, sizeof(tf->u.setup_req));
394 tf->u.setup_req.dialog_token = dialog_token;
395 tf->u.setup_req.capability = cpu_to_le16(capab);
396 ret = mwifiex_tdls_append_rates_ie(priv, skb);
398 dev_kfree_skb_any(skb);
402 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
403 *pos++ = WLAN_EID_HT_CAPABILITY;
404 *pos++ = sizeof(struct ieee80211_ht_cap);
405 ht_cap = (void *)pos;
406 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
407 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
409 dev_kfree_skb_any(skb);
413 if (priv->adapter->is_hw_11ac_capable) {
414 ret = mwifiex_tdls_add_vht_capab(priv, skb);
416 dev_kfree_skb_any(skb);
419 mwifiex_tdls_add_aid(priv, skb);
422 mwifiex_tdls_add_ext_capab(priv, skb);
423 mwifiex_tdls_add_qos_capab(skb);
426 case WLAN_TDLS_SETUP_RESPONSE:
427 tf->category = WLAN_CATEGORY_TDLS;
428 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
429 skb_put(skb, sizeof(tf->u.setup_resp));
430 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
431 tf->u.setup_resp.dialog_token = dialog_token;
432 tf->u.setup_resp.capability = cpu_to_le16(capab);
433 ret = mwifiex_tdls_append_rates_ie(priv, skb);
435 dev_kfree_skb_any(skb);
439 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
440 *pos++ = WLAN_EID_HT_CAPABILITY;
441 *pos++ = sizeof(struct ieee80211_ht_cap);
442 ht_cap = (void *)pos;
443 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
444 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
446 dev_kfree_skb_any(skb);
450 if (priv->adapter->is_hw_11ac_capable) {
451 ret = mwifiex_tdls_add_vht_capab(priv, skb);
453 dev_kfree_skb_any(skb);
456 mwifiex_tdls_add_aid(priv, skb);
459 mwifiex_tdls_add_ext_capab(priv, skb);
460 mwifiex_tdls_add_qos_capab(skb);
463 case WLAN_TDLS_SETUP_CONFIRM:
464 tf->category = WLAN_CATEGORY_TDLS;
465 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
466 skb_put(skb, sizeof(tf->u.setup_cfm));
467 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
468 tf->u.setup_cfm.dialog_token = dialog_token;
469 if (priv->adapter->is_hw_11ac_capable) {
470 ret = mwifiex_tdls_add_vht_oper(priv, peer, skb);
472 dev_kfree_skb_any(skb);
475 ret = mwifiex_tdls_add_ht_oper(priv, peer, 1, skb);
477 dev_kfree_skb_any(skb);
481 ret = mwifiex_tdls_add_ht_oper(priv, peer, 0, skb);
483 dev_kfree_skb_any(skb);
489 case WLAN_TDLS_TEARDOWN:
490 tf->category = WLAN_CATEGORY_TDLS;
491 tf->action_code = WLAN_TDLS_TEARDOWN;
492 skb_put(skb, sizeof(tf->u.teardown));
493 tf->u.teardown.reason_code = cpu_to_le16(status_code);
496 case WLAN_TDLS_DISCOVERY_REQUEST:
497 tf->category = WLAN_CATEGORY_TDLS;
498 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
499 skb_put(skb, sizeof(tf->u.discover_req));
500 tf->u.discover_req.dialog_token = dialog_token;
503 dev_err(priv->adapter->dev, "Unknown TDLS frame type.\n");
511 mwifiex_tdls_add_link_ie(struct sk_buff *skb, const u8 *src_addr,
512 const u8 *peer, const u8 *bssid)
514 struct ieee80211_tdls_lnkie *lnkid;
516 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
517 lnkid->ie_type = WLAN_EID_LINK_ID;
518 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) -
519 sizeof(struct ieee_types_header);
521 memcpy(lnkid->bssid, bssid, ETH_ALEN);
522 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
523 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
526 int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
527 u8 action_code, u8 dialog_token,
528 u16 status_code, const u8 *extra_ies,
529 size_t extra_ies_len)
532 struct mwifiex_txinfo *tx_info;
536 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
537 max(sizeof(struct ieee80211_mgmt),
538 sizeof(struct ieee80211_tdls_data)) +
539 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
540 MWIFIEX_SUPPORTED_RATES +
542 sizeof(struct ieee_types_extcap) +
543 sizeof(struct ieee80211_ht_cap) +
544 sizeof(struct ieee_types_bss_co_2040) +
545 sizeof(struct ieee80211_ht_operation) +
546 sizeof(struct ieee80211_tdls_lnkie) +
549 if (priv->adapter->is_hw_11ac_capable)
550 skb_len += sizeof(struct ieee_types_vht_cap) +
551 sizeof(struct ieee_types_vht_oper) +
552 sizeof(struct ieee_types_aid);
554 skb = dev_alloc_skb(skb_len);
556 dev_err(priv->adapter->dev,
557 "allocate skb failed for management frame\n");
560 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
562 switch (action_code) {
563 case WLAN_TDLS_SETUP_REQUEST:
564 case WLAN_TDLS_SETUP_CONFIRM:
565 case WLAN_TDLS_TEARDOWN:
566 case WLAN_TDLS_DISCOVERY_REQUEST:
567 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
568 dialog_token, status_code,
571 dev_kfree_skb_any(skb);
575 memcpy(skb_put(skb, extra_ies_len), extra_ies,
577 mwifiex_tdls_add_link_ie(skb, priv->curr_addr, peer,
580 case WLAN_TDLS_SETUP_RESPONSE:
581 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
582 dialog_token, status_code,
585 dev_kfree_skb_any(skb);
589 memcpy(skb_put(skb, extra_ies_len), extra_ies,
591 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
596 switch (action_code) {
597 case WLAN_TDLS_SETUP_REQUEST:
598 case WLAN_TDLS_SETUP_RESPONSE:
599 skb->priority = MWIFIEX_PRIO_BK;
602 skb->priority = MWIFIEX_PRIO_VI;
606 tx_info = MWIFIEX_SKB_TXCB(skb);
607 memset(tx_info, 0, sizeof(*tx_info));
608 tx_info->bss_num = priv->bss_num;
609 tx_info->bss_type = priv->bss_type;
611 __net_timestamp(skb);
612 mwifiex_queue_tx_pkt(priv, skb);
618 mwifiex_construct_tdls_action_frame(struct mwifiex_private *priv,
620 u8 action_code, u8 dialog_token,
621 u16 status_code, struct sk_buff *skb)
623 struct ieee80211_mgmt *mgmt;
624 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
627 struct ieee80211_ht_cap *ht_cap;
630 capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
632 mgmt = (void *)skb_put(skb, offsetof(struct ieee80211_mgmt, u));
635 memcpy(mgmt->da, peer, ETH_ALEN);
636 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
637 memcpy(mgmt->bssid, priv->cfg_bssid, ETH_ALEN);
638 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
639 IEEE80211_STYPE_ACTION);
642 pos = skb_put(skb, ETH_ALEN);
644 switch (action_code) {
645 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
646 skb_put(skb, sizeof(mgmt->u.action.u.tdls_discover_resp) + 1);
647 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
648 mgmt->u.action.u.tdls_discover_resp.action_code =
649 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
650 mgmt->u.action.u.tdls_discover_resp.dialog_token =
652 mgmt->u.action.u.tdls_discover_resp.capability =
654 /* move back for addr4 */
655 memmove(pos + ETH_ALEN, &mgmt->u.action.category,
656 sizeof(mgmt->u.action.u.tdls_discover_resp));
658 memcpy(pos, bc_addr, ETH_ALEN);
660 ret = mwifiex_tdls_append_rates_ie(priv, skb);
662 dev_kfree_skb_any(skb);
666 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
667 *pos++ = WLAN_EID_HT_CAPABILITY;
668 *pos++ = sizeof(struct ieee80211_ht_cap);
669 ht_cap = (void *)pos;
670 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
671 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
673 dev_kfree_skb_any(skb);
677 if (priv->adapter->is_hw_11ac_capable) {
678 ret = mwifiex_tdls_add_vht_capab(priv, skb);
680 dev_kfree_skb_any(skb);
683 mwifiex_tdls_add_aid(priv, skb);
686 mwifiex_tdls_add_ext_capab(priv, skb);
687 mwifiex_tdls_add_qos_capab(skb);
690 dev_err(priv->adapter->dev, "Unknown TDLS action frame type\n");
697 int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
698 u8 action_code, u8 dialog_token,
699 u16 status_code, const u8 *extra_ies,
700 size_t extra_ies_len)
703 struct mwifiex_txinfo *tx_info;
705 u32 pkt_type, tx_control;
706 u16 pkt_len, skb_len;
708 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
709 max(sizeof(struct ieee80211_mgmt),
710 sizeof(struct ieee80211_tdls_data)) +
711 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
712 MWIFIEX_SUPPORTED_RATES +
713 sizeof(struct ieee_types_extcap) +
714 sizeof(struct ieee80211_ht_cap) +
715 sizeof(struct ieee_types_bss_co_2040) +
716 sizeof(struct ieee80211_ht_operation) +
717 sizeof(struct ieee80211_tdls_lnkie) +
720 ETH_ALEN; /* Address4 */
722 if (priv->adapter->is_hw_11ac_capable)
723 skb_len += sizeof(struct ieee_types_vht_cap) +
724 sizeof(struct ieee_types_vht_oper) +
725 sizeof(struct ieee_types_aid);
727 skb = dev_alloc_skb(skb_len);
729 dev_err(priv->adapter->dev,
730 "allocate skb failed for management frame\n");
734 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
736 pkt_type = PKT_TYPE_MGMT;
738 pos = skb_put(skb, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
739 memset(pos, 0, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
740 memcpy(pos, &pkt_type, sizeof(pkt_type));
741 memcpy(pos + sizeof(pkt_type), &tx_control, sizeof(tx_control));
743 if (mwifiex_construct_tdls_action_frame(priv, peer, action_code,
744 dialog_token, status_code,
746 dev_kfree_skb_any(skb);
751 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
753 /* the TDLS link IE is always added last we are the responder */
755 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
758 skb->priority = MWIFIEX_PRIO_VI;
760 tx_info = MWIFIEX_SKB_TXCB(skb);
761 memset(tx_info, 0, sizeof(*tx_info));
762 tx_info->bss_num = priv->bss_num;
763 tx_info->bss_type = priv->bss_type;
764 tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
766 pkt_len = skb->len - MWIFIEX_MGMT_FRAME_HEADER_SIZE - sizeof(pkt_len);
767 memcpy(skb->data + MWIFIEX_MGMT_FRAME_HEADER_SIZE, &pkt_len,
769 __net_timestamp(skb);
770 mwifiex_queue_tx_pkt(priv, skb);
775 /* This function process tdls action frame from peer.
776 * Peer capabilities are stored into station node structure.
778 void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
781 struct mwifiex_sta_node *sta_ptr;
782 u8 *peer, *pos, *end;
787 if (len < (sizeof(struct ethhdr) + 3))
789 if (*(buf + sizeof(struct ethhdr)) != WLAN_TDLS_SNAP_RFTYPE)
791 if (*(buf + sizeof(struct ethhdr) + 1) != WLAN_CATEGORY_TDLS)
794 peer = buf + ETH_ALEN;
795 action = *(buf + sizeof(struct ethhdr) + 2);
796 dev_dbg(priv->adapter->dev,
797 "rx:tdls action: peer=%pM, action=%d\n", peer, action);
800 case WLAN_TDLS_SETUP_REQUEST:
801 if (len < (sizeof(struct ethhdr) + TDLS_REQ_FIX_LEN))
804 pos = buf + sizeof(struct ethhdr) + 4;
805 /* payload 1+ category 1 + action 1 + dialog 1 */
806 cap = cpu_to_le16(*(u16 *)pos);
807 ie_len = len - sizeof(struct ethhdr) - TDLS_REQ_FIX_LEN;
811 case WLAN_TDLS_SETUP_RESPONSE:
812 if (len < (sizeof(struct ethhdr) + TDLS_RESP_FIX_LEN))
814 /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
815 pos = buf + sizeof(struct ethhdr) + 6;
816 cap = cpu_to_le16(*(u16 *)pos);
817 ie_len = len - sizeof(struct ethhdr) - TDLS_RESP_FIX_LEN;
821 case WLAN_TDLS_SETUP_CONFIRM:
822 if (len < (sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN))
824 pos = buf + sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN;
825 ie_len = len - sizeof(struct ethhdr) - TDLS_CONFIRM_FIX_LEN;
828 dev_dbg(priv->adapter->dev, "Unknown TDLS frame type.\n");
832 sta_ptr = mwifiex_add_sta_entry(priv, peer);
836 sta_ptr->tdls_cap.capab = cap;
838 for (end = pos + ie_len; pos + 1 < end; pos += 2 + pos[1]) {
839 if (pos + 2 + pos[1] > end)
843 case WLAN_EID_SUPP_RATES:
844 sta_ptr->tdls_cap.rates_len = pos[1];
845 for (i = 0; i < pos[1]; i++)
846 sta_ptr->tdls_cap.rates[i] = pos[i + 2];
849 case WLAN_EID_EXT_SUPP_RATES:
850 basic = sta_ptr->tdls_cap.rates_len;
851 for (i = 0; i < pos[1]; i++)
852 sta_ptr->tdls_cap.rates[basic + i] = pos[i + 2];
853 sta_ptr->tdls_cap.rates_len += pos[1];
855 case WLAN_EID_HT_CAPABILITY:
856 memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos,
857 sizeof(struct ieee80211_ht_cap));
858 sta_ptr->is_11n_enabled = 1;
860 case WLAN_EID_HT_OPERATION:
861 memcpy(&sta_ptr->tdls_cap.ht_oper, pos,
862 sizeof(struct ieee80211_ht_operation));
864 case WLAN_EID_BSS_COEX_2040:
865 sta_ptr->tdls_cap.coex_2040 = pos[2];
867 case WLAN_EID_EXT_CAPABILITY:
868 memcpy((u8 *)&sta_ptr->tdls_cap.extcap, pos,
869 sizeof(struct ieee_types_header) +
870 min_t(u8, pos[1], 8));
873 memcpy((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,
874 sizeof(struct ieee_types_header) +
875 min_t(u8, pos[1], IEEE_MAX_IE_SIZE -
876 sizeof(struct ieee_types_header)));
878 case WLAN_EID_QOS_CAPA:
879 sta_ptr->tdls_cap.qos_info = pos[2];
881 case WLAN_EID_VHT_OPERATION:
882 if (priv->adapter->is_hw_11ac_capable)
883 memcpy(&sta_ptr->tdls_cap.vhtoper, pos,
884 sizeof(struct ieee80211_vht_operation));
886 case WLAN_EID_VHT_CAPABILITY:
887 if (priv->adapter->is_hw_11ac_capable) {
888 memcpy((u8 *)&sta_ptr->tdls_cap.vhtcap, pos,
889 sizeof(struct ieee80211_vht_cap));
890 sta_ptr->is_11ac_enabled = 1;
894 if (priv->adapter->is_hw_11ac_capable)
895 sta_ptr->tdls_cap.aid =
896 le16_to_cpu(*(__le16 *)(pos + 2));
906 mwifiex_tdls_process_config_link(struct mwifiex_private *priv, const u8 *peer)
908 struct mwifiex_sta_node *sta_ptr;
909 struct mwifiex_ds_tdls_oper tdls_oper;
911 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
912 sta_ptr = mwifiex_get_sta_entry(priv, peer);
914 if (!sta_ptr || sta_ptr->tdls_status == TDLS_SETUP_FAILURE) {
915 dev_err(priv->adapter->dev,
916 "link absent for peer %pM; cannot config\n", peer);
920 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
921 tdls_oper.tdls_action = MWIFIEX_TDLS_CONFIG_LINK;
922 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
923 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
927 mwifiex_tdls_process_create_link(struct mwifiex_private *priv, const u8 *peer)
929 struct mwifiex_sta_node *sta_ptr;
930 struct mwifiex_ds_tdls_oper tdls_oper;
932 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
933 sta_ptr = mwifiex_get_sta_entry(priv, peer);
935 if (sta_ptr && sta_ptr->tdls_status == TDLS_SETUP_INPROGRESS) {
936 dev_dbg(priv->adapter->dev,
937 "Setup already in progress for peer %pM\n", peer);
941 sta_ptr = mwifiex_add_sta_entry(priv, peer);
945 sta_ptr->tdls_status = TDLS_SETUP_INPROGRESS;
946 mwifiex_hold_tdls_packets(priv, peer);
947 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
948 tdls_oper.tdls_action = MWIFIEX_TDLS_CREATE_LINK;
949 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
950 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
954 mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
956 struct mwifiex_sta_node *sta_ptr;
957 struct mwifiex_ds_tdls_oper tdls_oper;
960 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
961 sta_ptr = mwifiex_get_sta_entry(priv, peer);
964 if (sta_ptr->is_11n_enabled) {
965 mwifiex_11n_cleanup_reorder_tbl(priv);
966 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
968 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
969 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
972 mwifiex_del_sta_entry(priv, peer);
975 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
976 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
977 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
978 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
979 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
983 mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
985 struct mwifiex_sta_node *sta_ptr;
986 struct ieee80211_mcs_info mcs;
990 sta_ptr = mwifiex_get_sta_entry(priv, peer);
992 if (sta_ptr && (sta_ptr->tdls_status != TDLS_SETUP_FAILURE)) {
993 dev_dbg(priv->adapter->dev,
994 "tdls: enable link %pM success\n", peer);
996 sta_ptr->tdls_status = TDLS_SETUP_COMPLETE;
998 mcs = sta_ptr->tdls_cap.ht_capb.mcs;
999 if (mcs.rx_mask[0] != 0xff)
1000 sta_ptr->is_11n_enabled = true;
1001 if (sta_ptr->is_11n_enabled) {
1002 if (le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info) &
1003 IEEE80211_HT_CAP_MAX_AMSDU)
1004 sta_ptr->max_amsdu =
1005 MWIFIEX_TX_DATA_BUF_SIZE_8K;
1007 sta_ptr->max_amsdu =
1008 MWIFIEX_TX_DATA_BUF_SIZE_4K;
1010 for (i = 0; i < MAX_NUM_TID; i++)
1011 sta_ptr->ampdu_sta[i] =
1012 priv->aggr_prio_tbl[i].ampdu_user;
1014 for (i = 0; i < MAX_NUM_TID; i++)
1015 sta_ptr->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
1018 memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
1019 mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
1021 dev_dbg(priv->adapter->dev,
1022 "tdls: enable link %pM failed\n", peer);
1024 mwifiex_11n_cleanup_reorder_tbl(priv);
1025 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1027 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1028 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1030 mwifiex_del_sta_entry(priv, peer);
1032 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1040 int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action)
1043 case MWIFIEX_TDLS_ENABLE_LINK:
1044 return mwifiex_tdls_process_enable_link(priv, peer);
1045 case MWIFIEX_TDLS_DISABLE_LINK:
1046 return mwifiex_tdls_process_disable_link(priv, peer);
1047 case MWIFIEX_TDLS_CREATE_LINK:
1048 return mwifiex_tdls_process_create_link(priv, peer);
1049 case MWIFIEX_TDLS_CONFIG_LINK:
1050 return mwifiex_tdls_process_config_link(priv, peer);
1055 int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac)
1057 struct mwifiex_sta_node *sta_ptr;
1059 sta_ptr = mwifiex_get_sta_entry(priv, mac);
1061 return sta_ptr->tdls_status;
1063 return TDLS_NOT_SETUP;
1066 void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
1068 struct mwifiex_sta_node *sta_ptr;
1069 struct mwifiex_ds_tdls_oper tdls_oper;
1070 unsigned long flags;
1072 if (list_empty(&priv->sta_list))
1075 list_for_each_entry(sta_ptr, &priv->sta_list, list) {
1076 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
1078 if (sta_ptr->is_11n_enabled) {
1079 mwifiex_11n_cleanup_reorder_tbl(priv);
1080 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1082 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1083 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1087 mwifiex_restore_tdls_packets(priv, sta_ptr->mac_addr,
1088 TDLS_LINK_TEARDOWN);
1089 memcpy(&tdls_oper.peer_mac, sta_ptr->mac_addr, ETH_ALEN);
1090 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
1091 if (mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1092 HostCmd_ACT_GEN_SET, 0, &tdls_oper, false))
1093 dev_warn(priv->adapter->dev,
1094 "Disable link failed for TDLS peer %pM",
1098 mwifiex_del_all_sta_list(priv);