[PATCH 03/14] nl80211: implement TDLS callback functions and propagate capabilities

Arik Nemtsov arik
Mon Sep 26 03:55:24 PDT 2011


Allow passing high-level TDLS commands and TDLS frames to kernel
via new nl80211 commands.

Propagate TDLS related nl80211 capability flags from kernel and add them
as driver capability flags.

Signed-off-by: Arik Nemtsov <arik at wizery.com>
Cc: Kalyan C Gaddam <chakkal at iit.edu>
---
 src/drivers/driver.h         |    4 ++
 src/drivers/driver_nl80211.c |  118 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 08623e7..5d76ae8 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -689,6 +689,10 @@ struct wpa_driver_capa {
 #define WPA_DRIVER_FLAGS_EAPOL_TX_STATUS		0x00010000
 /* Driver indicates TX status events for Deauth/Disassoc frames */
 #define WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS		0x00020000
+/* Driver supports operating as a TDLS peer */
+#define WPA_DRIVER_FLAGS_TDLS_SUPPORT			0x00040000
+/* Driver requires external TDLS setup/teardown/discovery */
+#define WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP		0x00080000
 	unsigned int flags;
 
 	int max_scan_ssids;
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index eaafae7..9c8c0e2 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1688,6 +1688,8 @@ struct wiphy_info_data {
 	int connect_supported;
 	int offchan_tx_supported;
 	int max_remain_on_chan;
+	int tdls_supported;
+	int tdls_external_setup;
 };
 
 
@@ -1815,6 +1817,13 @@ broken_combination:
 		info->max_remain_on_chan =
 			nla_get_u32(tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]);
 
+	if (tb[NL80211_ATTR_TDLS_SUPPORT]) {
+		info->tdls_supported = 1;
+
+		if (tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP])
+			info->tdls_external_setup = 1;
+	}
+
 	return NL_SKIP;
 }
 
@@ -1884,6 +1893,16 @@ static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv)
 		drv->capa.flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
 	}
 
+	if (info.tdls_supported) {
+		wpa_printf(MSG_DEBUG, "nl80211: TDLS supported");
+		drv->capa.flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT;
+
+		if (info.tdls_external_setup) {
+			wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup");
+			drv->capa.flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
+		}
+	}
+
 	drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES;
 	drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE;
 	if (info.p2p_supported)
@@ -7144,6 +7163,101 @@ static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck,
 }
 
 
+#ifdef CONFIG_TDLS
+static enum nl80211_tdls_operation nl80211_tdls_get_oper(enum tdls_oper oper)
+{
+	switch (oper) {
+	case TDLS_DISCOVERY_REQ:
+		return NL80211_TDLS_DISCOVERY_REQ;
+	case TDLS_SETUP:
+		return NL80211_TDLS_SETUP;
+	case TDLS_TEARDOWN:
+		return NL80211_TDLS_TEARDOWN;
+	case TDLS_ENABLE_LINK:
+		return NL80211_TDLS_ENABLE_LINK;
+	case TDLS_DISABLE_LINK:
+		return NL80211_TDLS_DISABLE_LINK;
+	case TDLS_ENABLE:
+		return NL80211_TDLS_ENABLE;
+	case TDLS_DISABLE:
+		return NL80211_TDLS_DISABLE;
+	}
+
+	return -1;
+}
+
+
+static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
+				  u8 dialog_token, u16 status_code,
+				  const u8 *buf, size_t len)
+{
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
+	struct nl_msg *msg;
+
+	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
+		return -ENOTSUP;
+
+	if (!dst)
+		return -EINVAL;
+
+	msg = nlmsg_alloc();
+	if (!msg)
+		return -ENOMEM;
+
+	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
+		    NL80211_CMD_TDLS_MGMT, 0);
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
+	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
+	NLA_PUT_U8(msg, NL80211_ATTR_TDLS_ACTION, action_code);
+	NLA_PUT_U8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token);
+	NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status_code);
+	NLA_PUT(msg, NL80211_ATTR_IE, len, buf);
+
+	return send_and_recv_msgs(drv, msg, NULL, NULL);
+
+ nla_put_failure:
+	nlmsg_free(msg);
+	return -ENOBUFS;
+}
+
+
+static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
+{
+	struct i802_bss *bss = priv;
+	struct wpa_driver_nl80211_data *drv = bss->drv;
+	struct nl_msg *msg;
+	enum nl80211_tdls_operation nl80211_oper;
+
+	if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
+		return -ENOTSUP;
+
+	nl80211_oper = nl80211_tdls_get_oper(oper);
+	if (nl80211_oper == -1) {
+		wpa_printf(MSG_DEBUG, "nl80211: Invalid TDLS oper: %d",
+			   oper);
+		return -EINVAL;
+	}
+
+	msg = nlmsg_alloc();
+	if (!msg)
+		return -ENOMEM;
+
+	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
+		    NL80211_CMD_TDLS_OPER, 0);
+	NLA_PUT_U8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper);
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
+	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
+
+	return send_and_recv_msgs(drv, msg, NULL, NULL);
+
+nla_put_failure:
+	nlmsg_free(msg);
+	return -ENOBUFS;
+}
+#endif /* CONFIG TDLS */
+
+
 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
 	.name = "nl80211",
 	.desc = "Linux nl80211/cfg80211",
@@ -7217,4 +7331,8 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
 	.remove_pmkid = nl80211_remove_pmkid,
 	.flush_pmkid = nl80211_flush_pmkid,
 	.set_rekey_info = nl80211_set_rekey_info,
+#ifdef CONFIG_TDLS
+	.send_tdls_mgmt = nl80211_send_tdls_mgmt,
+	.tdls_oper = nl80211_tdls_oper,
+#endif /* CONFIG_TDLS */
 };
-- 
1.7.4.1




More information about the Hostap mailing list