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;
537 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
538 max(sizeof(struct ieee80211_mgmt),
539 sizeof(struct ieee80211_tdls_data)) +
540 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
541 MWIFIEX_SUPPORTED_RATES +
543 sizeof(struct ieee_types_extcap) +
544 sizeof(struct ieee80211_ht_cap) +
545 sizeof(struct ieee_types_bss_co_2040) +
546 sizeof(struct ieee80211_ht_operation) +
547 sizeof(struct ieee80211_tdls_lnkie) +
550 if (priv->adapter->is_hw_11ac_capable)
551 skb_len += sizeof(struct ieee_types_vht_cap) +
552 sizeof(struct ieee_types_vht_oper) +
553 sizeof(struct ieee_types_aid);
555 skb = dev_alloc_skb(skb_len);
557 dev_err(priv->adapter->dev,
558 "allocate skb failed for management frame\n");
561 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
563 switch (action_code) {
564 case WLAN_TDLS_SETUP_REQUEST:
565 case WLAN_TDLS_SETUP_CONFIRM:
566 case WLAN_TDLS_TEARDOWN:
567 case WLAN_TDLS_DISCOVERY_REQUEST:
568 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
569 dialog_token, status_code,
572 dev_kfree_skb_any(skb);
576 memcpy(skb_put(skb, extra_ies_len), extra_ies,
578 mwifiex_tdls_add_link_ie(skb, priv->curr_addr, peer,
581 case WLAN_TDLS_SETUP_RESPONSE:
582 ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
583 dialog_token, status_code,
586 dev_kfree_skb_any(skb);
590 memcpy(skb_put(skb, extra_ies_len), extra_ies,
592 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
597 switch (action_code) {
598 case WLAN_TDLS_SETUP_REQUEST:
599 case WLAN_TDLS_SETUP_RESPONSE:
600 skb->priority = MWIFIEX_PRIO_BK;
603 skb->priority = MWIFIEX_PRIO_VI;
607 tx_info = MWIFIEX_SKB_TXCB(skb);
608 memset(tx_info, 0, sizeof(*tx_info));
609 tx_info->bss_num = priv->bss_num;
610 tx_info->bss_type = priv->bss_type;
612 do_gettimeofday(&tv);
613 skb->tstamp = timeval_to_ktime(tv);
614 mwifiex_queue_tx_pkt(priv, skb);
620 mwifiex_construct_tdls_action_frame(struct mwifiex_private *priv,
622 u8 action_code, u8 dialog_token,
623 u16 status_code, struct sk_buff *skb)
625 struct ieee80211_mgmt *mgmt;
626 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
629 struct ieee80211_ht_cap *ht_cap;
632 capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
634 mgmt = (void *)skb_put(skb, offsetof(struct ieee80211_mgmt, u));
637 memcpy(mgmt->da, peer, ETH_ALEN);
638 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
639 memcpy(mgmt->bssid, priv->cfg_bssid, ETH_ALEN);
640 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
641 IEEE80211_STYPE_ACTION);
644 pos = skb_put(skb, ETH_ALEN);
646 switch (action_code) {
647 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
648 skb_put(skb, sizeof(mgmt->u.action.u.tdls_discover_resp) + 1);
649 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
650 mgmt->u.action.u.tdls_discover_resp.action_code =
651 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
652 mgmt->u.action.u.tdls_discover_resp.dialog_token =
654 mgmt->u.action.u.tdls_discover_resp.capability =
656 /* move back for addr4 */
657 memmove(pos + ETH_ALEN, &mgmt->u.action.category,
658 sizeof(mgmt->u.action.u.tdls_discover_resp));
660 memcpy(pos, bc_addr, ETH_ALEN);
662 ret = mwifiex_tdls_append_rates_ie(priv, skb);
664 dev_kfree_skb_any(skb);
668 pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
669 *pos++ = WLAN_EID_HT_CAPABILITY;
670 *pos++ = sizeof(struct ieee80211_ht_cap);
671 ht_cap = (void *)pos;
672 radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
673 ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
675 dev_kfree_skb_any(skb);
679 if (priv->adapter->is_hw_11ac_capable) {
680 ret = mwifiex_tdls_add_vht_capab(priv, skb);
682 dev_kfree_skb_any(skb);
685 mwifiex_tdls_add_aid(priv, skb);
688 mwifiex_tdls_add_ext_capab(priv, skb);
689 mwifiex_tdls_add_qos_capab(skb);
692 dev_err(priv->adapter->dev, "Unknown TDLS action frame type\n");
699 int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
700 u8 action_code, u8 dialog_token,
701 u16 status_code, const u8 *extra_ies,
702 size_t extra_ies_len)
705 struct mwifiex_txinfo *tx_info;
708 u32 pkt_type, tx_control;
709 u16 pkt_len, skb_len;
711 skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
712 max(sizeof(struct ieee80211_mgmt),
713 sizeof(struct ieee80211_tdls_data)) +
714 MWIFIEX_MGMT_FRAME_HEADER_SIZE +
715 MWIFIEX_SUPPORTED_RATES +
716 sizeof(struct ieee_types_extcap) +
717 sizeof(struct ieee80211_ht_cap) +
718 sizeof(struct ieee_types_bss_co_2040) +
719 sizeof(struct ieee80211_ht_operation) +
720 sizeof(struct ieee80211_tdls_lnkie) +
723 ETH_ALEN; /* Address4 */
725 if (priv->adapter->is_hw_11ac_capable)
726 skb_len += sizeof(struct ieee_types_vht_cap) +
727 sizeof(struct ieee_types_vht_oper) +
728 sizeof(struct ieee_types_aid);
730 skb = dev_alloc_skb(skb_len);
732 dev_err(priv->adapter->dev,
733 "allocate skb failed for management frame\n");
737 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
739 pkt_type = PKT_TYPE_MGMT;
741 pos = skb_put(skb, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
742 memset(pos, 0, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
743 memcpy(pos, &pkt_type, sizeof(pkt_type));
744 memcpy(pos + sizeof(pkt_type), &tx_control, sizeof(tx_control));
746 if (mwifiex_construct_tdls_action_frame(priv, peer, action_code,
747 dialog_token, status_code,
749 dev_kfree_skb_any(skb);
754 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
756 /* the TDLS link IE is always added last we are the responder */
758 mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
761 skb->priority = MWIFIEX_PRIO_VI;
763 tx_info = MWIFIEX_SKB_TXCB(skb);
764 memset(tx_info, 0, sizeof(*tx_info));
765 tx_info->bss_num = priv->bss_num;
766 tx_info->bss_type = priv->bss_type;
767 tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
769 pkt_len = skb->len - MWIFIEX_MGMT_FRAME_HEADER_SIZE - sizeof(pkt_len);
770 memcpy(skb->data + MWIFIEX_MGMT_FRAME_HEADER_SIZE, &pkt_len,
772 do_gettimeofday(&tv);
773 skb->tstamp = timeval_to_ktime(tv);
774 mwifiex_queue_tx_pkt(priv, skb);
779 /* This function process tdls action frame from peer.
780 * Peer capabilities are stored into station node structure.
782 void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
785 struct mwifiex_sta_node *sta_ptr;
786 u8 *peer, *pos, *end;
790 if (len < (sizeof(struct ethhdr) + 3))
792 if (*(buf + sizeof(struct ethhdr)) != WLAN_TDLS_SNAP_RFTYPE)
794 if (*(buf + sizeof(struct ethhdr) + 1) != WLAN_CATEGORY_TDLS)
797 peer = buf + ETH_ALEN;
798 action = *(buf + sizeof(struct ethhdr) + 2);
800 /* just handle TDLS setup request/response/confirm */
801 if (action > WLAN_TDLS_SETUP_CONFIRM)
804 dev_dbg(priv->adapter->dev,
805 "rx:tdls action: peer=%pM, action=%d\n", peer, action);
807 sta_ptr = mwifiex_add_sta_entry(priv, peer);
812 case WLAN_TDLS_SETUP_REQUEST:
813 if (len < (sizeof(struct ethhdr) + TDLS_REQ_FIX_LEN))
816 pos = buf + sizeof(struct ethhdr) + 4;
817 /* payload 1+ category 1 + action 1 + dialog 1 */
818 sta_ptr->tdls_cap.capab = cpu_to_le16(*(u16 *)pos);
819 ie_len = len - sizeof(struct ethhdr) - TDLS_REQ_FIX_LEN;
823 case WLAN_TDLS_SETUP_RESPONSE:
824 if (len < (sizeof(struct ethhdr) + TDLS_RESP_FIX_LEN))
826 /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
827 pos = buf + sizeof(struct ethhdr) + 6;
828 sta_ptr->tdls_cap.capab = cpu_to_le16(*(u16 *)pos);
829 ie_len = len - sizeof(struct ethhdr) - TDLS_RESP_FIX_LEN;
833 case WLAN_TDLS_SETUP_CONFIRM:
834 if (len < (sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN))
836 pos = buf + sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN;
837 ie_len = len - sizeof(struct ethhdr) - TDLS_CONFIRM_FIX_LEN;
840 dev_warn(priv->adapter->dev, "Unknown TDLS frame type.\n");
844 for (end = pos + ie_len; pos + 1 < end; pos += 2 + pos[1]) {
845 if (pos + 2 + pos[1] > end)
849 case WLAN_EID_SUPP_RATES:
852 sta_ptr->tdls_cap.rates_len = pos[1];
853 for (i = 0; i < pos[1]; i++)
854 sta_ptr->tdls_cap.rates[i] = pos[i + 2];
857 case WLAN_EID_EXT_SUPP_RATES:
860 basic = sta_ptr->tdls_cap.rates_len;
861 if (pos[1] > 32 - basic)
863 for (i = 0; i < pos[1]; i++)
864 sta_ptr->tdls_cap.rates[basic + i] = pos[i + 2];
865 sta_ptr->tdls_cap.rates_len += pos[1];
867 case WLAN_EID_HT_CAPABILITY:
868 if (pos > end - sizeof(struct ieee80211_ht_cap) - 2)
870 if (pos[1] != sizeof(struct ieee80211_ht_cap))
872 /* copy the ie's value into ht_capb*/
873 memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos + 2,
874 sizeof(struct ieee80211_ht_cap));
875 sta_ptr->is_11n_enabled = 1;
877 case WLAN_EID_HT_OPERATION:
879 sizeof(struct ieee80211_ht_operation) - 2)
881 if (pos[1] != sizeof(struct ieee80211_ht_operation))
883 /* copy the ie's value into ht_oper*/
884 memcpy(&sta_ptr->tdls_cap.ht_oper, pos + 2,
885 sizeof(struct ieee80211_ht_operation));
887 case WLAN_EID_BSS_COEX_2040:
892 sta_ptr->tdls_cap.coex_2040 = pos[2];
894 case WLAN_EID_EXT_CAPABILITY:
895 if (pos > end - sizeof(struct ieee_types_header))
897 if (pos[1] < sizeof(struct ieee_types_header))
901 memcpy((u8 *)&sta_ptr->tdls_cap.extcap, pos,
902 sizeof(struct ieee_types_header) +
903 min_t(u8, pos[1], 8));
906 if (pos > end - sizeof(struct ieee_types_header))
908 if (pos[1] < sizeof(struct ieee_types_header))
910 if (pos[1] > IEEE_MAX_IE_SIZE -
911 sizeof(struct ieee_types_header))
913 memcpy((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,
914 sizeof(struct ieee_types_header) +
915 min_t(u8, pos[1], IEEE_MAX_IE_SIZE -
916 sizeof(struct ieee_types_header)));
918 case WLAN_EID_QOS_CAPA:
923 sta_ptr->tdls_cap.qos_info = pos[2];
925 case WLAN_EID_VHT_OPERATION:
926 if (priv->adapter->is_hw_11ac_capable) {
928 sizeof(struct ieee80211_vht_operation) - 2)
931 sizeof(struct ieee80211_vht_operation))
933 /* copy the ie's value into vhtoper*/
934 memcpy(&sta_ptr->tdls_cap.vhtoper, pos + 2,
935 sizeof(struct ieee80211_vht_operation));
938 case WLAN_EID_VHT_CAPABILITY:
939 if (priv->adapter->is_hw_11ac_capable) {
941 sizeof(struct ieee80211_vht_cap) - 2)
943 if (pos[1] != sizeof(struct ieee80211_vht_cap))
945 /* copy the ie's value into vhtcap*/
946 memcpy((u8 *)&sta_ptr->tdls_cap.vhtcap, pos + 2,
947 sizeof(struct ieee80211_vht_cap));
948 sta_ptr->is_11ac_enabled = 1;
952 if (priv->adapter->is_hw_11ac_capable) {
957 sta_ptr->tdls_cap.aid =
958 le16_to_cpu(*(__le16 *)(pos + 2));
970 mwifiex_tdls_process_config_link(struct mwifiex_private *priv, const u8 *peer)
972 struct mwifiex_sta_node *sta_ptr;
973 struct mwifiex_ds_tdls_oper tdls_oper;
975 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
976 sta_ptr = mwifiex_get_sta_entry(priv, peer);
978 if (!sta_ptr || sta_ptr->tdls_status == TDLS_SETUP_FAILURE) {
979 dev_err(priv->adapter->dev,
980 "link absent for peer %pM; cannot config\n", peer);
984 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
985 tdls_oper.tdls_action = MWIFIEX_TDLS_CONFIG_LINK;
986 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
987 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
991 mwifiex_tdls_process_create_link(struct mwifiex_private *priv, const u8 *peer)
993 struct mwifiex_sta_node *sta_ptr;
994 struct mwifiex_ds_tdls_oper tdls_oper;
996 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
997 sta_ptr = mwifiex_get_sta_entry(priv, peer);
999 if (sta_ptr && sta_ptr->tdls_status == TDLS_SETUP_INPROGRESS) {
1000 dev_dbg(priv->adapter->dev,
1001 "Setup already in progress for peer %pM\n", peer);
1005 sta_ptr = mwifiex_add_sta_entry(priv, peer);
1009 sta_ptr->tdls_status = TDLS_SETUP_INPROGRESS;
1010 mwifiex_hold_tdls_packets(priv, peer);
1011 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
1012 tdls_oper.tdls_action = MWIFIEX_TDLS_CREATE_LINK;
1013 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1014 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
1018 mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
1020 struct mwifiex_sta_node *sta_ptr;
1021 struct mwifiex_ds_tdls_oper tdls_oper;
1022 unsigned long flags;
1024 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
1025 sta_ptr = mwifiex_get_sta_entry(priv, peer);
1028 if (sta_ptr->is_11n_enabled) {
1029 mwifiex_11n_cleanup_reorder_tbl(priv);
1030 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1032 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1033 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1036 mwifiex_del_sta_entry(priv, peer);
1039 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1040 memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
1041 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
1042 return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1043 HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
1047 mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
1049 struct mwifiex_sta_node *sta_ptr;
1050 struct ieee80211_mcs_info mcs;
1051 unsigned long flags;
1054 sta_ptr = mwifiex_get_sta_entry(priv, peer);
1056 if (sta_ptr && (sta_ptr->tdls_status != TDLS_SETUP_FAILURE)) {
1057 dev_dbg(priv->adapter->dev,
1058 "tdls: enable link %pM success\n", peer);
1060 sta_ptr->tdls_status = TDLS_SETUP_COMPLETE;
1062 mcs = sta_ptr->tdls_cap.ht_capb.mcs;
1063 if (mcs.rx_mask[0] != 0xff)
1064 sta_ptr->is_11n_enabled = true;
1065 if (sta_ptr->is_11n_enabled) {
1066 if (le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info) &
1067 IEEE80211_HT_CAP_MAX_AMSDU)
1068 sta_ptr->max_amsdu =
1069 MWIFIEX_TX_DATA_BUF_SIZE_8K;
1071 sta_ptr->max_amsdu =
1072 MWIFIEX_TX_DATA_BUF_SIZE_4K;
1074 for (i = 0; i < MAX_NUM_TID; i++)
1075 sta_ptr->ampdu_sta[i] =
1076 priv->aggr_prio_tbl[i].ampdu_user;
1078 for (i = 0; i < MAX_NUM_TID; i++)
1079 sta_ptr->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
1082 memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
1083 mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
1085 dev_dbg(priv->adapter->dev,
1086 "tdls: enable link %pM failed\n", peer);
1088 mwifiex_11n_cleanup_reorder_tbl(priv);
1089 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1091 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1092 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1094 mwifiex_del_sta_entry(priv, peer);
1096 mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
1104 int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action)
1107 case MWIFIEX_TDLS_ENABLE_LINK:
1108 return mwifiex_tdls_process_enable_link(priv, peer);
1109 case MWIFIEX_TDLS_DISABLE_LINK:
1110 return mwifiex_tdls_process_disable_link(priv, peer);
1111 case MWIFIEX_TDLS_CREATE_LINK:
1112 return mwifiex_tdls_process_create_link(priv, peer);
1113 case MWIFIEX_TDLS_CONFIG_LINK:
1114 return mwifiex_tdls_process_config_link(priv, peer);
1119 int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac)
1121 struct mwifiex_sta_node *sta_ptr;
1123 sta_ptr = mwifiex_get_sta_entry(priv, mac);
1125 return sta_ptr->tdls_status;
1127 return TDLS_NOT_SETUP;
1130 void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
1132 struct mwifiex_sta_node *sta_ptr;
1133 struct mwifiex_ds_tdls_oper tdls_oper;
1134 unsigned long flags;
1136 if (list_empty(&priv->sta_list))
1139 list_for_each_entry(sta_ptr, &priv->sta_list, list) {
1140 memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
1142 if (sta_ptr->is_11n_enabled) {
1143 mwifiex_11n_cleanup_reorder_tbl(priv);
1144 spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
1146 mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
1147 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
1151 mwifiex_restore_tdls_packets(priv, sta_ptr->mac_addr,
1152 TDLS_LINK_TEARDOWN);
1153 memcpy(&tdls_oper.peer_mac, sta_ptr->mac_addr, ETH_ALEN);
1154 tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
1155 if (mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
1156 HostCmd_ACT_GEN_SET, 0, &tdls_oper, false))
1157 dev_warn(priv->adapter->dev,
1158 "Disable link failed for TDLS peer %pM",
1162 mwifiex_del_all_sta_list(priv);