Skip to content

Commit 941c93c

Browse files
ariknemlinvjw
authored andcommitted
mac80211: data path modification for TDLS peers
Mark the STA entries of enabled TDLS peers with a new "peer authorized" flag. During link setup, allow special TDLS setup frames through the AP, but otherwise drop all packets destined to the peer. This is required by the TDLS (802.11z) specification in order to prevent reordering of MSDUs between the AP and direct paths. When setup completes and the peer is authorized, send data directly, bypassing the AP. In the Rx path, allow data to be received directly from TDLS peers. Signed-off-by: Arik Nemtsov <arik@wizery.com> Cc: Kalyan C Gaddam <chakkal@iit.edu> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 07ba55d commit 941c93c

4 files changed

Lines changed: 55 additions & 7 deletions

File tree

‎net/mac80211/cfg.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,7 @@ static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
24272427
static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
24282428
u8 *peer, enum nl80211_tdls_operation oper)
24292429
{
2430+
struct sta_info *sta;
24302431
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24312432

24322433
if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
@@ -2441,6 +2442,15 @@ static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
24412442

24422443
switch (oper) {
24432444
case NL80211_TDLS_ENABLE_LINK:
2445+
rcu_read_lock();
2446+
sta = sta_info_get(sdata, peer);
2447+
if (!sta) {
2448+
rcu_read_unlock();
2449+
return -ENOLINK;
2450+
}
2451+
2452+
set_sta_flags(sta, WLAN_STA_TDLS_PEER_AUTH);
2453+
rcu_read_unlock();
24442454
break;
24452455
case NL80211_TDLS_DISABLE_LINK:
24462456
return sta_info_destroy_addr(sdata, peer);

‎net/mac80211/sta_info.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
* station in power-save mode, reply when the driver unblocks.
4646
* @WLAN_STA_PS_DRIVER_BUF: Station has frames pending in driver internal
4747
* buffers. Automatically cleared on station wake-up.
48-
* @WLAN_STA_TDLS_PEER: station is a TDLS peer.
48+
* @WLAN_STA_TDLS_PEER: Station is a TDLS peer.
49+
* @WLAN_STA_TDLS_PEER_AUTH: This TDLS peer is authorized to send direct
50+
* packets. This means the link is enabled.
4951
*/
5052
enum ieee80211_sta_info_flags {
5153
WLAN_STA_AUTH = 1<<0,
@@ -63,6 +65,7 @@ enum ieee80211_sta_info_flags {
6365
WLAN_STA_PSPOLL = 1<<13,
6466
WLAN_STA_PS_DRIVER_BUF = 1<<14,
6567
WLAN_STA_TDLS_PEER = 1<<15,
68+
WLAN_STA_TDLS_PEER_AUTH = 1<<16,
6669
};
6770

6871
#define STA_TID_NUM 16

‎net/mac80211/tx.c‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
17261726
struct sta_info *sta = NULL;
17271727
u32 sta_flags = 0;
17281728
struct sk_buff *tmp_skb;
1729+
bool tdls_direct = false;
17291730

17301731
if (unlikely(skb->len < ETH_HLEN)) {
17311732
ret = NETDEV_TX_OK;
@@ -1837,18 +1838,51 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
18371838
break;
18381839
#endif
18391840
case NL80211_IFTYPE_STATION:
1840-
memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
1841-
if (sdata->u.mgd.use_4addr &&
1842-
cpu_to_be16(ethertype) != sdata->control_port_protocol) {
1843-
fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1841+
if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1842+
rcu_read_lock();
1843+
sta = sta_info_get(sdata, skb->data);
1844+
if (sta)
1845+
sta_flags = get_sta_flags(sta);
1846+
rcu_read_unlock();
1847+
1848+
/*
1849+
* If the TDLS link is enabled, send everything
1850+
* directly. Otherwise, allow TDLS setup frames
1851+
* to be transmitted indirectly.
1852+
*/
1853+
tdls_direct =
1854+
(sta_flags & WLAN_STA_TDLS_PEER) &&
1855+
((sta_flags & WLAN_STA_TDLS_PEER_AUTH) ||
1856+
!(ethertype == ETH_P_TDLS && skb->len > 14 &&
1857+
skb->data[14] == WLAN_TDLS_SNAP_RFTYPE));
1858+
}
1859+
1860+
if (tdls_direct) {
1861+
/* link during setup - throw out frames to peer */
1862+
if (!(sta_flags & WLAN_STA_TDLS_PEER_AUTH)) {
1863+
ret = NETDEV_TX_OK;
1864+
goto fail;
1865+
}
1866+
1867+
/* DA SA BSSID */
1868+
memcpy(hdr.addr1, skb->data, ETH_ALEN);
1869+
memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1870+
memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
1871+
hdrlen = 24;
1872+
} else if (sdata->u.mgd.use_4addr &&
1873+
cpu_to_be16(ethertype) != sdata->control_port_protocol) {
1874+
fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
1875+
IEEE80211_FCTL_TODS);
18441876
/* RA TA DA SA */
1877+
memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
18451878
memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
18461879
memcpy(hdr.addr3, skb->data, ETH_ALEN);
18471880
memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
18481881
hdrlen = 30;
18491882
} else {
18501883
fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
18511884
/* BSSID SA DA */
1885+
memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
18521886
memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
18531887
memcpy(hdr.addr3, skb->data, ETH_ALEN);
18541888
hdrlen = 24;

‎net/wireless/util.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,9 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
396396
}
397397
break;
398398
case cpu_to_le16(0):
399-
if (iftype != NL80211_IFTYPE_ADHOC)
400-
return -1;
399+
if (iftype != NL80211_IFTYPE_ADHOC &&
400+
iftype != NL80211_IFTYPE_STATION)
401+
return -1;
401402
break;
402403
}
403404

0 commit comments

Comments
 (0)