Skip to content

Commit 07ba55d

Browse files
ariknemlinvjw
authored andcommitted
nl80211/mac80211: allow adding TDLS peers as stations
When adding a TDLS peer STA, mark it with a new flag in both nl80211 and mac80211. Before adding a peer, make sure the wiphy supports TDLS and our operating mode is appropriate (managed). In addition, make sure all peers are removed on disassociation. A TDLS peer is first added just before link setup is initiated. In later setup stages we have more info about peer supported rates, capabilities, etc. This info is reported via nl80211_set_station(). 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 dfe018b commit 07ba55d

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

‎include/linux/nl80211.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,7 @@ enum nl80211_iftype {
14341434
* @NL80211_STA_FLAG_WME: station is WME/QoS capable
14351435
* @NL80211_STA_FLAG_MFP: station uses management frame protection
14361436
* @NL80211_STA_FLAG_AUTHENTICATED: station is authenticated
1437+
* @NL80211_STA_FLAG_TDLS_PEER: station is a TDLS peer
14371438
* @NL80211_STA_FLAG_MAX: highest station flag number currently defined
14381439
* @__NL80211_STA_FLAG_AFTER_LAST: internal use
14391440
*/
@@ -1444,6 +1445,7 @@ enum nl80211_sta_flags {
14441445
NL80211_STA_FLAG_WME,
14451446
NL80211_STA_FLAG_MFP,
14461447
NL80211_STA_FLAG_AUTHENTICATED,
1448+
NL80211_STA_FLAG_TDLS_PEER,
14471449

14481450
/* keep last */
14491451
__NL80211_STA_FLAG_AFTER_LAST,

‎net/mac80211/cfg.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,12 @@ static void sta_apply_parameters(struct ieee80211_local *local,
713713
if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
714714
sta->flags |= WLAN_STA_AUTH;
715715
}
716+
717+
if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
718+
sta->flags &= ~WLAN_STA_TDLS_PEER;
719+
if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
720+
sta->flags |= WLAN_STA_TDLS_PEER;
721+
}
716722
spin_unlock_irqrestore(&sta->flaglock, flags);
717723

718724
if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
@@ -813,6 +819,12 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
813819

814820
sta_apply_parameters(local, sta, params);
815821

822+
/* Only TDLS-supporting stations can add TDLS peers */
823+
if ((sta->flags & WLAN_STA_TDLS_PEER) &&
824+
!((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
825+
sdata->vif.type == NL80211_IFTYPE_STATION))
826+
return -ENOTSUPP;
827+
816828
rate_control_rate_init(sta);
817829

818830
layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
@@ -865,6 +877,14 @@ static int ieee80211_change_station(struct wiphy *wiphy,
865877
return -ENOENT;
866878
}
867879

880+
/* The TDLS bit cannot be toggled after the STA was added */
881+
if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
882+
!!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
883+
!!test_sta_flags(sta, WLAN_STA_TDLS_PEER)) {
884+
rcu_read_unlock();
885+
return -EINVAL;
886+
}
887+
868888
if (params->vlan && params->vlan != sta->sdata->dev) {
869889
vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
870890

‎net/mac80211/mlme.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,9 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
11371137
changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
11381138
ieee80211_bss_info_change_notify(sdata, changed);
11391139

1140+
/* remove AP and TDLS peers */
11401141
if (remove_sta)
1141-
sta_info_destroy_addr(sdata, bssid);
1142+
sta_info_flush(local, sdata);
11421143

11431144
del_timer_sync(&sdata->u.mgd.conn_mon_timer);
11441145
del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
@@ -2738,7 +2739,7 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
27382739
req->reason_code, cookie,
27392740
!req->local_state_change);
27402741
if (assoc_bss)
2741-
sta_info_destroy_addr(sdata, bssid);
2742+
sta_info_flush(sdata->local, sdata);
27422743

27432744
mutex_lock(&sdata->local->mtx);
27442745
ieee80211_recalc_idle(sdata->local);
@@ -2778,7 +2779,7 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
27782779
ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
27792780
IEEE80211_STYPE_DISASSOC, req->reason_code,
27802781
cookie, !req->local_state_change);
2781-
sta_info_destroy_addr(sdata, bssid);
2782+
sta_info_flush(sdata->local, sdata);
27822783

27832784
mutex_lock(&sdata->local->mtx);
27842785
ieee80211_recalc_idle(sdata->local);

‎net/mac80211/sta_info.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
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.
4849
*/
4950
enum ieee80211_sta_info_flags {
5051
WLAN_STA_AUTH = 1<<0,
@@ -61,6 +62,7 @@ enum ieee80211_sta_info_flags {
6162
WLAN_STA_PS_DRIVER = 1<<12,
6263
WLAN_STA_PSPOLL = 1<<13,
6364
WLAN_STA_PS_DRIVER_BUF = 1<<14,
65+
WLAN_STA_TDLS_PEER = 1<<15,
6466
};
6567

6668
#define STA_TID_NUM 16

‎net/wireless/nl80211.c‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,18 +2530,25 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
25302530
break;
25312531
case NL80211_IFTYPE_P2P_CLIENT:
25322532
case NL80211_IFTYPE_STATION:
2533-
/* disallow everything but AUTHORIZED flag */
2533+
/* disallow things sta doesn't support */
25342534
if (params.plink_action)
25352535
err = -EINVAL;
25362536
if (params.vlan)
25372537
err = -EINVAL;
2538-
if (params.supported_rates)
2538+
if (params.supported_rates &&
2539+
!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
25392540
err = -EINVAL;
25402541
if (params.ht_capa)
25412542
err = -EINVAL;
25422543
if (params.listen_interval >= 0)
25432544
err = -EINVAL;
2544-
if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
2545+
if (params.sta_flags_mask &
2546+
~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
2547+
BIT(NL80211_STA_FLAG_TDLS_PEER)))
2548+
err = -EINVAL;
2549+
/* can't change the TDLS bit */
2550+
if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2551+
(params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)))
25452552
err = -EINVAL;
25462553
break;
25472554
case NL80211_IFTYPE_MESH_POINT:
@@ -2662,7 +2669,18 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
26622669
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
26632670
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
26642671
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
2665-
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2672+
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO &&
2673+
dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
2674+
return -EINVAL;
2675+
2676+
/*
2677+
* Only managed stations can add TDLS peers, and only when the
2678+
* wiphy supports external TDLS setup.
2679+
*/
2680+
if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION &&
2681+
!((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
2682+
(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
2683+
(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)))
26662684
return -EINVAL;
26672685

26682686
err = get_vlan(info, rdev, &params.vlan);

0 commit comments

Comments
 (0)