[RFC 10/13] TDLS: add peer as new STA when enabling TDLS link

Arik Nemtsov arik at wizery.com
Thu Sep 15 06:22:28 EDT 2011


Before enabling a TDLS link, add the remote peer as a new STA.
Mark the new STA with a flag to indicate it is a TDLS peer.

Translate the flag to an appropriate nl80211 STA flag in driver_nl80211.

Signed-off-by: Arik Nemtsov <arik at wizery.com>
Cc: Kalyan C Gaddam <chakkal at iit.edu>
---
 src/drivers/driver.h         |    1 +
 src/drivers/driver_nl80211.c |    5 +++++
 src/rsn_supp/tdls.c          |    3 +++
 src/rsn_supp/wpa.h           |    2 ++
 src/rsn_supp/wpa_i.h         |   10 ++++++++++
 wpa_supplicant/wpas_glue.c   |   21 +++++++++++++++++++++
 6 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 3e9c132..6b2e3ce 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -812,6 +812,7 @@ struct wpa_bss_params {
 #define WPA_STA_WMM BIT(1)
 #define WPA_STA_SHORT_PREAMBLE BIT(2)
 #define WPA_STA_MFP BIT(3)
+#define WPA_STA_TDLS_PEER BIT(4)
 
 /**
  * struct p2p_params - P2P parameters for driver-based P2P management
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 5e8abde..03ffa13 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -4113,6 +4113,8 @@ static u32 sta_flags_nl80211(int flags)
 		f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
 	if (flags & WPA_STA_MFP)
 		f |= BIT(NL80211_STA_FLAG_MFP);
+	if (flags & WPA_STA_TDLS_PEER)
+		f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
 
 	return f;
 }
@@ -4829,6 +4831,9 @@ static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
 	if (total_flags & WPA_STA_MFP)
 		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
 
+	if (total_flags & WPA_STA_TDLS_PEER)
+		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_TDLS_PEER);
+
 	if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
 		goto nla_put_failure;
 
diff --git a/src/rsn_supp/tdls.c b/src/rsn_supp/tdls.c
index a438a53..853a387 100644
--- a/src/rsn_supp/tdls.c
+++ b/src/rsn_supp/tdls.c
@@ -1647,6 +1647,9 @@ static void wpa_tdls_enable_link(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
 	}
 #endif /* CONFIG_TDLS_TESTING */
 	}
+
+	wpa_sm_tdls_sta_add(sm, peer->addr, peer->capability, peer->supp_rates,
+			    peer->supp_rates_len);
 	wpa_sm_tdls_oper(sm, TDLS_ENABLE_LINK, peer->addr);
 }
 
diff --git a/src/rsn_supp/wpa.h b/src/rsn_supp/wpa.h
index f2a4704..3f309ec 100644
--- a/src/rsn_supp/wpa.h
+++ b/src/rsn_supp/wpa.h
@@ -60,6 +60,8 @@ struct wpa_sm_ctx {
 			      u8 action_code, u8 dialog_token,
 			      u16 status_code, const u8 *buf, size_t len);
 	int (*tdls_oper)(void *ctx, int oper, const u8 *peer);
+	int (*tdls_sta_add)(void *ctx, const u8 *addr, u16 capability,
+			    const u8 *supp_rates, size_t supp_rates_len);
 #endif /* CONFIG_TDLS */
 	void (*set_rekey_offload)(void *ctx, const u8 *kek, const u8 *kck,
 				  const u8 *replay_ctr);
diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
index ebe73ca..f46f2ee 100644
--- a/src/rsn_supp/wpa_i.h
+++ b/src/rsn_supp/wpa_i.h
@@ -272,6 +272,16 @@ static inline int wpa_sm_tdls_oper(struct wpa_sm *sm, int oper,
 		return sm->ctx->tdls_oper(sm->ctx->ctx, oper, peer);
 	return -1;
 }
+
+static inline int wpa_sm_tdls_sta_add(struct wpa_sm *sm, const u8 *addr,
+				      u16 capability, const u8 *supp_rates,
+				      size_t supp_rates_len)
+{
+	if (sm->ctx->tdls_sta_add)
+		return sm->ctx->tdls_sta_add(sm->ctx->ctx, addr, capability,
+					     supp_rates, supp_rates_len);
+	return -1;
+}
 #endif /* CONFIG_TDLS */
 
 void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
diff --git a/wpa_supplicant/wpas_glue.c b/wpa_supplicant/wpas_glue.c
index 98b082c..74e2272 100644
--- a/wpa_supplicant/wpas_glue.c
+++ b/wpa_supplicant/wpas_glue.c
@@ -555,6 +555,26 @@ static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
 	return wpa_drv_tdls_oper(wpa_s, oper, peer);
 }
 
+
+static int wpa_supplicant_tdls_sta_add(void *ctx, const u8 *peer,
+				       u16 capability, const u8 *supp_rates,
+				       size_t supp_rates_len)
+{
+	struct wpa_supplicant *wpa_s = ctx;
+	struct hostapd_sta_add_params params;
+
+	params.addr = peer;
+	params.aid = 1;
+	params.capability = capability;
+	params.flags = WPA_STA_TDLS_PEER;
+	params.ht_capabilities = NULL;
+	params.listen_interval = 0;
+	params.supp_rates = supp_rates;
+	params.supp_rates_len = supp_rates_len;
+
+	return wpa_drv_sta_add(wpa_s, &params);
+}
+
 #endif /* CONFIG_TDLS */
 
 
@@ -715,6 +735,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
 #ifdef CONFIG_TDLS
 	ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
 	ctx->tdls_oper = wpa_supplicant_tdls_oper;
+	ctx->tdls_sta_add = wpa_supplicant_tdls_sta_add;
 #endif /* CONFIG_TDLS */
 	ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
 
-- 
1.7.4.1



More information about the HostAP mailing list